kernel: add support for enabling hardware flow offload via iptables
[openwrt/openwrt.git] / package / network / utils / iptables / patches / 800-flowoffload_target.patch
1 --- /dev/null
2 +++ b/extensions/libxt_FLOWOFFLOAD.c
3 @@ -0,0 +1,72 @@
4 +#include <stdio.h>
5 +#include <xtables.h>
6 +#include <linux/netfilter/xt_FLOWOFFLOAD.h>
7 +
8 +enum {
9 + O_HW,
10 +};
11 +
12 +static void offload_help(void)
13 +{
14 + printf(
15 +"FLOWOFFLOAD target options:\n"
16 +" --hw Enable hardware offload\n"
17 + );
18 +}
19 +
20 +static const struct xt_option_entry offload_opts[] = {
21 + {.name = "hw", .id = O_HW, .type = XTTYPE_NONE},
22 + XTOPT_TABLEEND,
23 +};
24 +
25 +static void offload_parse(struct xt_option_call *cb)
26 +{
27 + struct xt_flowoffload_target_info *info = cb->data;
28 +
29 + xtables_option_parse(cb);
30 + switch (cb->entry->id) {
31 + case O_HW:
32 + info->flags |= XT_FLOWOFFLOAD_HW;
33 + break;
34 + }
35 +}
36 +
37 +static void offload_print(const void *ip, const struct xt_entry_target *target, int numeric)
38 +{
39 + const struct xt_flowoffload_target_info *info =
40 + (const struct xt_flowoffload_target_info *)target->data;
41 +
42 + printf(" FLOWOFFLOAD");
43 + if (info->flags & XT_FLOWOFFLOAD_HW)
44 + printf(" hw");
45 +}
46 +
47 +static void offload_save(const void *ip, const struct xt_entry_target *target)
48 +{
49 + const struct xt_flowoffload_target_info *info =
50 + (const struct xt_flowoffload_target_info *)target->data;
51 +
52 + if (info->flags & XT_FLOWOFFLOAD_HW)
53 + printf(" --hw");
54 +}
55 +
56 +static struct xtables_target offload_tg_reg[] = {
57 + {
58 + .family = NFPROTO_UNSPEC,
59 + .name = "FLOWOFFLOAD",
60 + .revision = 0,
61 + .version = XTABLES_VERSION,
62 + .size = XT_ALIGN(sizeof(struct xt_flowoffload_target_info)),
63 + .userspacesize = sizeof(struct xt_flowoffload_target_info),
64 + .help = offload_help,
65 + .print = offload_print,
66 + .save = offload_save,
67 + .x6_parse = offload_parse,
68 + .x6_options = offload_opts,
69 + },
70 +};
71 +
72 +void _init(void)
73 +{
74 + xtables_register_targets(offload_tg_reg, ARRAY_SIZE(offload_tg_reg));
75 +}
76 --- /dev/null
77 +++ b/include/linux/netfilter/xt_FLOWOFFLOAD.h
78 @@ -0,0 +1,17 @@
79 +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
80 +#ifndef _XT_FLOWOFFLOAD_H
81 +#define _XT_FLOWOFFLOAD_H
82 +
83 +#include <linux/types.h>
84 +
85 +enum {
86 + XT_FLOWOFFLOAD_HW = 1 << 0,
87 +
88 + XT_FLOWOFFLOAD_MASK = XT_FLOWOFFLOAD_HW
89 +};
90 +
91 +struct xt_flowoffload_target_info {
92 + __u32 flags;
93 +};
94 +
95 +#endif /* _XT_FLOWOFFLOAD_H */