1 From: Felix Fietkau <nbd@nbd.name>
2 Date: Tue, 20 Feb 2018 15:56:02 +0100
3 Subject: [PATCH] netfilter: add xt_FLOWOFFLOAD target
5 Signed-off-by: Felix Fietkau <nbd@nbd.name>
7 create mode 100644 net/netfilter/xt_OFFLOAD.c
9 --- a/net/ipv4/netfilter/Kconfig
10 +++ b/net/ipv4/netfilter/Kconfig
11 @@ -56,8 +56,6 @@ config NF_TABLES_ARP
13 This option enables the ARP support for nf_tables.
17 config NF_FLOW_TABLE_IPV4
18 tristate "Netfilter flow table IPv4 module"
19 depends on NF_FLOW_TABLE
20 @@ -66,6 +64,8 @@ config NF_FLOW_TABLE_IPV4
22 To compile it as a module, choose M here.
27 tristate "Netfilter IPv4 packet duplication to alternate destination"
28 depends on !NF_CONNTRACK || NF_CONNTRACK
29 --- a/net/ipv6/netfilter/Kconfig
30 +++ b/net/ipv6/netfilter/Kconfig
31 @@ -45,7 +45,6 @@ config NFT_FIB_IPV6
32 multicast or blackhole.
34 endif # NF_TABLES_IPV6
37 config NF_FLOW_TABLE_IPV6
38 tristate "Netfilter flow table IPv6 module"
39 @@ -55,6 +54,8 @@ config NF_FLOW_TABLE_IPV6
41 To compile it as a module, choose M here.
46 tristate "Netfilter IPv6 packet duplication to alternate destination"
47 depends on !NF_CONNTRACK || NF_CONNTRACK
48 --- a/net/netfilter/Kconfig
49 +++ b/net/netfilter/Kconfig
50 @@ -682,8 +682,6 @@ config NFT_FIB_NETDEV
52 endif # NF_TABLES_NETDEV
56 config NF_FLOW_TABLE_INET
57 tristate "Netfilter flow table mixed IPv4/IPv6 module"
58 depends on NF_FLOW_TABLE
59 @@ -692,11 +690,12 @@ config NF_FLOW_TABLE_INET
61 To compile it as a module, choose M here.
66 tristate "Netfilter flow table module"
67 depends on NETFILTER_INGRESS
68 depends on NF_CONNTRACK
69 - depends on NF_TABLES
71 This option adds the flow table core infrastructure.
73 @@ -976,6 +975,15 @@ config NETFILTER_XT_TARGET_NOTRACK
74 depends on NETFILTER_ADVANCED
75 select NETFILTER_XT_TARGET_CT
77 +config NETFILTER_XT_TARGET_FLOWOFFLOAD
78 + tristate '"FLOWOFFLOAD" target support'
79 + depends on NF_FLOW_TABLE
80 + depends on NETFILTER_INGRESS
82 + This option adds a `FLOWOFFLOAD' target, which uses the nf_flow_offload
83 + module to speed up processing of packets by bypassing the usual
86 config NETFILTER_XT_TARGET_RATEEST
87 tristate '"RATEEST" target support'
88 depends on NETFILTER_ADVANCED
89 --- a/net/netfilter/Makefile
90 +++ b/net/netfilter/Makefile
91 @@ -145,6 +145,7 @@ obj-$(CONFIG_NETFILTER_XT_TARGET_CLASSIF
92 obj-$(CONFIG_NETFILTER_XT_TARGET_CONNSECMARK) += xt_CONNSECMARK.o
93 obj-$(CONFIG_NETFILTER_XT_TARGET_CT) += xt_CT.o
94 obj-$(CONFIG_NETFILTER_XT_TARGET_DSCP) += xt_DSCP.o
95 +obj-$(CONFIG_NETFILTER_XT_TARGET_FLOWOFFLOAD) += xt_FLOWOFFLOAD.o
96 obj-$(CONFIG_NETFILTER_XT_TARGET_HL) += xt_HL.o
97 obj-$(CONFIG_NETFILTER_XT_TARGET_HMARK) += xt_HMARK.o
98 obj-$(CONFIG_NETFILTER_XT_TARGET_LED) += xt_LED.o
100 +++ b/net/netfilter/xt_FLOWOFFLOAD.c
103 + * Copyright (C) 2018-2021 Felix Fietkau <nbd@nbd.name>
105 + * This program is free software; you can redistribute it and/or modify
106 + * it under the terms of the GNU General Public License version 2 as
107 + * published by the Free Software Foundation.
109 +#include <linux/module.h>
110 +#include <linux/init.h>
111 +#include <linux/netfilter.h>
112 +#include <linux/netfilter/xt_FLOWOFFLOAD.h>
113 +#include <linux/if_vlan.h>
114 +#include <linux/if_pppox.h>
115 +#include <linux/ppp_defs.h>
117 +#include <net/netfilter/nf_conntrack.h>
118 +#include <net/netfilter/nf_conntrack_extend.h>
119 +#include <net/netfilter/nf_conntrack_helper.h>
120 +#include <net/netfilter/nf_flow_table.h>
122 +struct xt_flowoffload_hook {
123 + struct hlist_node list;
124 + struct nf_hook_ops ops;
130 +struct xt_flowoffload_table {
131 + struct nf_flowtable ft;
132 + struct hlist_head hooks;
133 + struct delayed_work work;
136 +struct nf_forward_info {
137 + const struct net_device *indev;
138 + const struct net_device *outdev;
139 + const struct net_device *hw_outdev;
143 + } encap[NF_FLOW_TABLE_ENCAP_MAX];
146 + u8 h_source[ETH_ALEN];
147 + u8 h_dest[ETH_ALEN];
148 + enum flow_offload_xmit_type xmit_type;
151 +static DEFINE_SPINLOCK(hooks_lock);
153 +struct xt_flowoffload_table flowtable[2];
155 +static inline __be16 nf_flow_pppoe_proto(const struct sk_buff *skb)
159 + proto = *((__be16 *)(skb_mac_header(skb) + ETH_HLEN +
160 + sizeof(struct pppoe_hdr)));
162 + case htons(PPP_IP):
163 + return htons(ETH_P_IP);
164 + case htons(PPP_IPV6):
165 + return htons(ETH_P_IPV6);
172 +xt_flowoffload_net_hook(void *priv, struct sk_buff *skb,
173 + const struct nf_hook_state *state)
175 + struct vlan_ethhdr *veth;
178 + switch (skb->protocol) {
179 + case htons(ETH_P_8021Q):
180 + veth = (struct vlan_ethhdr *)skb_mac_header(skb);
181 + proto = veth->h_vlan_encapsulated_proto;
183 + case htons(ETH_P_PPP_SES):
184 + proto = nf_flow_pppoe_proto(skb);
187 + proto = skb->protocol;
192 + case htons(ETH_P_IP):
193 + return nf_flow_offload_ip_hook(priv, skb, state);
194 + case htons(ETH_P_IPV6):
195 + return nf_flow_offload_ipv6_hook(priv, skb, state);
202 +xt_flowoffload_create_hook(struct xt_flowoffload_table *table,
203 + struct net_device *dev)
205 + struct xt_flowoffload_hook *hook;
206 + struct nf_hook_ops *ops;
208 + hook = kzalloc(sizeof(*hook), GFP_ATOMIC);
213 + ops->pf = NFPROTO_NETDEV;
214 + ops->hooknum = NF_NETDEV_INGRESS;
215 + ops->priority = 10;
216 + ops->priv = &table->ft;
217 + ops->hook = xt_flowoffload_net_hook;
220 + hlist_add_head(&hook->list, &table->hooks);
221 + mod_delayed_work(system_power_efficient_wq, &table->work, 0);
226 +static struct xt_flowoffload_hook *
227 +flow_offload_lookup_hook(struct xt_flowoffload_table *table,
228 + struct net_device *dev)
230 + struct xt_flowoffload_hook *hook;
232 + hlist_for_each_entry(hook, &table->hooks, list) {
233 + if (hook->ops.dev == dev)
241 +xt_flowoffload_check_device(struct xt_flowoffload_table *table,
242 + struct net_device *dev)
244 + struct xt_flowoffload_hook *hook;
249 + spin_lock_bh(&hooks_lock);
250 + hook = flow_offload_lookup_hook(table, dev);
254 + xt_flowoffload_create_hook(table, dev);
255 + spin_unlock_bh(&hooks_lock);
259 +xt_flowoffload_register_hooks(struct xt_flowoffload_table *table)
261 + struct xt_flowoffload_hook *hook;
264 + hlist_for_each_entry(hook, &table->hooks, list) {
265 + if (hook->registered)
268 + hook->registered = true;
269 + hook->net = dev_net(hook->ops.dev);
270 + spin_unlock_bh(&hooks_lock);
271 + nf_register_net_hook(hook->net, &hook->ops);
272 + if (table->ft.flags & NF_FLOWTABLE_HW_OFFLOAD)
273 + table->ft.type->setup(&table->ft, hook->ops.dev,
275 + spin_lock_bh(&hooks_lock);
282 +xt_flowoffload_cleanup_hooks(struct xt_flowoffload_table *table)
284 + struct xt_flowoffload_hook *hook;
285 + bool active = false;
288 + spin_lock_bh(&hooks_lock);
289 + hlist_for_each_entry(hook, &table->hooks, list) {
290 + if (hook->used || !hook->registered) {
295 + hlist_del(&hook->list);
296 + spin_unlock_bh(&hooks_lock);
297 + if (table->ft.flags & NF_FLOWTABLE_HW_OFFLOAD)
298 + table->ft.type->setup(&table->ft, hook->ops.dev,
299 + FLOW_BLOCK_UNBIND);
300 + nf_unregister_net_hook(hook->net, &hook->ops);
304 + spin_unlock_bh(&hooks_lock);
310 +xt_flowoffload_check_hook(struct flow_offload *flow, void *data)
312 + struct xt_flowoffload_table *table = data;
313 + struct flow_offload_tuple *tuple0 = &flow->tuplehash[0].tuple;
314 + struct flow_offload_tuple *tuple1 = &flow->tuplehash[1].tuple;
315 + struct xt_flowoffload_hook *hook;
317 + spin_lock_bh(&hooks_lock);
318 + hlist_for_each_entry(hook, &table->hooks, list) {
319 + if (hook->ops.dev->ifindex != tuple0->iifidx &&
320 + hook->ops.dev->ifindex != tuple1->iifidx)
325 + spin_unlock_bh(&hooks_lock);
329 +xt_flowoffload_hook_work(struct work_struct *work)
331 + struct xt_flowoffload_table *table;
332 + struct xt_flowoffload_hook *hook;
335 + table = container_of(work, struct xt_flowoffload_table, work.work);
337 + spin_lock_bh(&hooks_lock);
338 + xt_flowoffload_register_hooks(table);
339 + hlist_for_each_entry(hook, &table->hooks, list)
340 + hook->used = false;
341 + spin_unlock_bh(&hooks_lock);
343 + err = nf_flow_table_iterate(&table->ft, xt_flowoffload_check_hook,
345 + if (err && err != -EAGAIN)
348 + if (!xt_flowoffload_cleanup_hooks(table))
352 + queue_delayed_work(system_power_efficient_wq, &table->work, HZ);
356 +xt_flowoffload_skip(struct sk_buff *skb, int family)
358 + if (skb_sec_path(skb))
361 + if (family == NFPROTO_IPV4) {
362 + const struct ip_options *opt = &(IPCB(skb)->opt);
364 + if (unlikely(opt->optlen))
371 +static enum flow_offload_xmit_type nf_xmit_type(struct dst_entry *dst)
374 + return FLOW_OFFLOAD_XMIT_XFRM;
376 + return FLOW_OFFLOAD_XMIT_NEIGH;
379 +static void nf_default_forward_path(struct nf_flow_route *route,
380 + struct dst_entry *dst_cache,
381 + enum ip_conntrack_dir dir,
382 + struct net_device **dev)
384 + dev[!dir] = dst_cache->dev;
385 + route->tuple[!dir].in.ifindex = dst_cache->dev->ifindex;
386 + route->tuple[dir].dst = dst_cache;
387 + route->tuple[dir].xmit_type = nf_xmit_type(dst_cache);
390 +static bool nf_is_valid_ether_device(const struct net_device *dev)
392 + if (!dev || (dev->flags & IFF_LOOPBACK) || dev->type != ARPHRD_ETHER ||
393 + dev->addr_len != ETH_ALEN || !is_valid_ether_addr(dev->dev_addr))
399 +static void nf_dev_path_info(const struct net_device_path_stack *stack,
400 + struct nf_forward_info *info,
403 + const struct net_device_path *path;
406 + memcpy(info->h_dest, ha, ETH_ALEN);
408 + for (i = 0; i < stack->num_paths; i++) {
409 + path = &stack->path[i];
410 + switch (path->type) {
411 + case DEV_PATH_ETHERNET:
413 + case DEV_PATH_VLAN:
414 + case DEV_PATH_PPPOE:
415 + info->indev = path->dev;
416 + if (is_zero_ether_addr(info->h_source))
417 + memcpy(info->h_source, path->dev->dev_addr, ETH_ALEN);
419 + if (path->type == DEV_PATH_ETHERNET)
421 + if (path->type == DEV_PATH_DSA) {
422 + i = stack->num_paths;
426 + /* DEV_PATH_VLAN and DEV_PATH_PPPOE */
427 + if (info->num_encaps >= NF_FLOW_TABLE_ENCAP_MAX) {
428 + info->indev = NULL;
432 + info->outdev = path->dev;
433 + info->encap[info->num_encaps].id = path->encap.id;
434 + info->encap[info->num_encaps].proto = path->encap.proto;
435 + info->num_encaps++;
436 + if (path->type == DEV_PATH_PPPOE)
437 + memcpy(info->h_dest, path->encap.h_dest, ETH_ALEN);
439 + case DEV_PATH_BRIDGE:
440 + if (is_zero_ether_addr(info->h_source))
441 + memcpy(info->h_source, path->dev->dev_addr, ETH_ALEN);
443 + switch (path->bridge.vlan_mode) {
444 + case DEV_PATH_BR_VLAN_UNTAG_HW:
445 + info->ingress_vlans |= BIT(info->num_encaps - 1);
447 + case DEV_PATH_BR_VLAN_TAG:
448 + info->encap[info->num_encaps].id = path->bridge.vlan_id;
449 + info->encap[info->num_encaps].proto = path->bridge.vlan_proto;
450 + info->num_encaps++;
452 + case DEV_PATH_BR_VLAN_UNTAG:
453 + info->num_encaps--;
455 + case DEV_PATH_BR_VLAN_KEEP:
460 + info->indev = NULL;
465 + info->outdev = info->indev;
467 + info->hw_outdev = info->indev;
469 + if (nf_is_valid_ether_device(info->indev))
470 + info->xmit_type = FLOW_OFFLOAD_XMIT_DIRECT;
473 +static int nf_dev_fill_forward_path(const struct nf_flow_route *route,
474 + const struct dst_entry *dst_cache,
475 + const struct nf_conn *ct,
476 + enum ip_conntrack_dir dir, u8 *ha,
477 + struct net_device_path_stack *stack)
479 + const void *daddr = &ct->tuplehash[!dir].tuple.src.u3;
480 + struct net_device *dev = dst_cache->dev;
481 + struct neighbour *n;
484 + if (!nf_is_valid_ether_device(dev))
487 + n = dst_neigh_lookup(dst_cache, daddr);
491 + read_lock_bh(&n->lock);
492 + nud_state = n->nud_state;
493 + ether_addr_copy(ha, n->ha);
494 + read_unlock_bh(&n->lock);
497 + if (!(nud_state & NUD_VALID))
501 + return dev_fill_forward_path(dev, ha, stack);
504 +static void nf_dev_forward_path(struct nf_flow_route *route,
505 + const struct nf_conn *ct,
506 + enum ip_conntrack_dir dir,
507 + struct net_device **devs)
509 + const struct dst_entry *dst = route->tuple[dir].dst;
510 + struct net_device_path_stack stack;
511 + struct nf_forward_info info = {};
512 + unsigned char ha[ETH_ALEN];
515 + if (nf_dev_fill_forward_path(route, dst, ct, dir, ha, &stack) >= 0)
516 + nf_dev_path_info(&stack, &info, ha);
518 + devs[!dir] = (struct net_device *)info.indev;
522 + route->tuple[!dir].in.ifindex = info.indev->ifindex;
523 + for (i = 0; i < info.num_encaps; i++) {
524 + route->tuple[!dir].in.encap[i].id = info.encap[i].id;
525 + route->tuple[!dir].in.encap[i].proto = info.encap[i].proto;
527 + route->tuple[!dir].in.num_encaps = info.num_encaps;
528 + route->tuple[!dir].in.ingress_vlans = info.ingress_vlans;
530 + if (info.xmit_type == FLOW_OFFLOAD_XMIT_DIRECT) {
531 + memcpy(route->tuple[dir].out.h_source, info.h_source, ETH_ALEN);
532 + memcpy(route->tuple[dir].out.h_dest, info.h_dest, ETH_ALEN);
533 + route->tuple[dir].out.ifindex = info.outdev->ifindex;
534 + route->tuple[dir].out.hw_ifindex = info.hw_outdev->ifindex;
535 + route->tuple[dir].xmit_type = info.xmit_type;
540 +xt_flowoffload_route(struct sk_buff *skb, const struct nf_conn *ct,
541 + const struct xt_action_param *par,
542 + struct nf_flow_route *route, enum ip_conntrack_dir dir,
543 + struct net_device **devs)
545 + struct dst_entry *this_dst = skb_dst(skb);
546 + struct dst_entry *other_dst = NULL;
549 + memset(&fl, 0, sizeof(fl));
550 + switch (xt_family(par)) {
552 + fl.u.ip4.daddr = ct->tuplehash[dir].tuple.src.u3.ip;
553 + fl.u.ip4.flowi4_oif = xt_in(par)->ifindex;
556 + fl.u.ip6.saddr = ct->tuplehash[!dir].tuple.dst.u3.in6;
557 + fl.u.ip6.daddr = ct->tuplehash[dir].tuple.src.u3.in6;
558 + fl.u.ip6.flowi6_oif = xt_in(par)->ifindex;
562 + nf_route(xt_net(par), &other_dst, &fl, false, xt_family(par));
566 + nf_default_forward_path(route, this_dst, dir, devs);
567 + nf_default_forward_path(route, other_dst, !dir, devs);
569 + if (route->tuple[dir].xmit_type == FLOW_OFFLOAD_XMIT_NEIGH &&
570 + route->tuple[!dir].xmit_type == FLOW_OFFLOAD_XMIT_NEIGH) {
571 + nf_dev_forward_path(route, ct, dir, devs);
572 + nf_dev_forward_path(route, ct, !dir, devs);
579 +flowoffload_tg(struct sk_buff *skb, const struct xt_action_param *par)
581 + struct xt_flowoffload_table *table;
582 + const struct xt_flowoffload_target_info *info = par->targinfo;
583 + struct tcphdr _tcph, *tcph = NULL;
584 + enum ip_conntrack_info ctinfo;
585 + enum ip_conntrack_dir dir;
586 + struct nf_flow_route route = {};
587 + struct flow_offload *flow = NULL;
588 + struct net_device *devs[2] = {};
589 + struct nf_conn *ct;
592 + if (xt_flowoffload_skip(skb, xt_family(par)))
593 + return XT_CONTINUE;
595 + ct = nf_ct_get(skb, &ctinfo);
597 + return XT_CONTINUE;
599 + switch (ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum) {
601 + if (ct->proto.tcp.state != TCP_CONNTRACK_ESTABLISHED)
602 + return XT_CONTINUE;
604 + tcph = skb_header_pointer(skb, par->thoff,
605 + sizeof(_tcph), &_tcph);
606 + if (unlikely(!tcph || tcph->fin || tcph->rst))
607 + return XT_CONTINUE;
612 + return XT_CONTINUE;
615 + if (nf_ct_ext_exist(ct, NF_CT_EXT_HELPER) ||
616 + ct->status & (IPS_SEQ_ADJUST | IPS_NAT_CLASH))
617 + return XT_CONTINUE;
619 + if (!nf_ct_is_confirmed(ct))
620 + return XT_CONTINUE;
622 + devs[dir] = xt_out(par);
623 + devs[!dir] = xt_in(par);
625 + if (!devs[dir] || !devs[!dir])
626 + return XT_CONTINUE;
628 + if (test_and_set_bit(IPS_OFFLOAD_BIT, &ct->status))
629 + return XT_CONTINUE;
631 + dir = CTINFO2DIR(ctinfo);
633 + if (xt_flowoffload_route(skb, ct, par, &route, dir, devs) < 0)
634 + goto err_flow_route;
636 + flow = flow_offload_alloc(ct);
638 + goto err_flow_alloc;
640 + if (flow_offload_route_init(flow, &route) < 0)
644 + ct->proto.tcp.seen[0].flags |= IP_CT_TCP_FLAG_BE_LIBERAL;
645 + ct->proto.tcp.seen[1].flags |= IP_CT_TCP_FLAG_BE_LIBERAL;
648 + table = &flowtable[!!(info->flags & XT_FLOWOFFLOAD_HW)];
650 + net = read_pnet(&table->ft.net);
652 + write_pnet(&table->ft.net, xt_net(par));
654 + if (flow_offload_add(&table->ft, flow) < 0)
657 + xt_flowoffload_check_device(table, devs[0]);
658 + xt_flowoffload_check_device(table, devs[1]);
660 + dst_release(route.tuple[!dir].dst);
662 + return XT_CONTINUE;
665 + flow_offload_free(flow);
667 + dst_release(route.tuple[!dir].dst);
669 + clear_bit(IPS_OFFLOAD_BIT, &ct->status);
671 + return XT_CONTINUE;
674 +static int flowoffload_chk(const struct xt_tgchk_param *par)
676 + struct xt_flowoffload_target_info *info = par->targinfo;
678 + if (info->flags & ~XT_FLOWOFFLOAD_MASK)
684 +static struct xt_target offload_tg_reg __read_mostly = {
685 + .family = NFPROTO_UNSPEC,
686 + .name = "FLOWOFFLOAD",
688 + .targetsize = sizeof(struct xt_flowoffload_target_info),
689 + .usersize = sizeof(struct xt_flowoffload_target_info),
690 + .checkentry = flowoffload_chk,
691 + .target = flowoffload_tg,
695 +static int flow_offload_netdev_event(struct notifier_block *this,
696 + unsigned long event, void *ptr)
698 + struct xt_flowoffload_hook *hook0, *hook1;
699 + struct net_device *dev = netdev_notifier_info_to_dev(ptr);
701 + if (event != NETDEV_UNREGISTER)
702 + return NOTIFY_DONE;
704 + spin_lock_bh(&hooks_lock);
705 + hook0 = flow_offload_lookup_hook(&flowtable[0], dev);
707 + hlist_del(&hook0->list);
709 + hook1 = flow_offload_lookup_hook(&flowtable[1], dev);
711 + hlist_del(&hook1->list);
712 + spin_unlock_bh(&hooks_lock);
715 + nf_unregister_net_hook(hook0->net, &hook0->ops);
720 + nf_unregister_net_hook(hook1->net, &hook1->ops);
724 + nf_flow_table_cleanup(dev);
726 + return NOTIFY_DONE;
729 +static struct notifier_block flow_offload_netdev_notifier = {
730 + .notifier_call = flow_offload_netdev_event,
733 +static int nf_flow_rule_route_inet(struct net *net,
734 + const struct flow_offload *flow,
735 + enum flow_offload_tuple_dir dir,
736 + struct nf_flow_rule *flow_rule)
738 + const struct flow_offload_tuple *flow_tuple = &flow->tuplehash[dir].tuple;
741 + switch (flow_tuple->l3proto) {
743 + err = nf_flow_rule_route_ipv4(net, flow, dir, flow_rule);
746 + err = nf_flow_rule_route_ipv6(net, flow, dir, flow_rule);
756 +static struct nf_flowtable_type flowtable_inet = {
757 + .family = NFPROTO_INET,
758 + .init = nf_flow_table_init,
759 + .setup = nf_flow_table_offload_setup,
760 + .action = nf_flow_rule_route_inet,
761 + .free = nf_flow_table_free,
762 + .hook = xt_flowoffload_net_hook,
763 + .owner = THIS_MODULE,
766 +static int init_flowtable(struct xt_flowoffload_table *tbl)
768 + INIT_DELAYED_WORK(&tbl->work, xt_flowoffload_hook_work);
769 + tbl->ft.type = &flowtable_inet;
771 + return nf_flow_table_init(&tbl->ft);
774 +static int __init xt_flowoffload_tg_init(void)
778 + register_netdevice_notifier(&flow_offload_netdev_notifier);
780 + ret = init_flowtable(&flowtable[0]);
784 + ret = init_flowtable(&flowtable[1]);
788 + flowtable[1].ft.flags = NF_FLOWTABLE_HW_OFFLOAD;
790 + ret = xt_register_target(&offload_tg_reg);
797 + nf_flow_table_free(&flowtable[1].ft);
799 + nf_flow_table_free(&flowtable[0].ft);
803 +static void __exit xt_flowoffload_tg_exit(void)
805 + xt_unregister_target(&offload_tg_reg);
806 + unregister_netdevice_notifier(&flow_offload_netdev_notifier);
807 + nf_flow_table_free(&flowtable[0].ft);
808 + nf_flow_table_free(&flowtable[1].ft);
811 +MODULE_LICENSE("GPL");
812 +module_init(xt_flowoffload_tg_init);
813 +module_exit(xt_flowoffload_tg_exit);
814 --- a/net/netfilter/nf_flow_table_core.c
815 +++ b/net/netfilter/nf_flow_table_core.c
817 #include <linux/netdevice.h>
819 #include <net/ip6_route.h>
820 -#include <net/netfilter/nf_tables.h>
821 #include <net/netfilter/nf_flow_table.h>
822 #include <net/netfilter/nf_conntrack.h>
823 #include <net/netfilter/nf_conntrack_core.h>
824 @@ -380,8 +379,7 @@ flow_offload_lookup(struct nf_flowtable
826 EXPORT_SYMBOL_GPL(flow_offload_lookup);
829 -nf_flow_table_iterate(struct nf_flowtable *flow_table,
830 +int nf_flow_table_iterate(struct nf_flowtable *flow_table,
831 void (*iter)(struct flow_offload *flow, void *data),
834 @@ -413,6 +411,7 @@ nf_flow_table_iterate(struct nf_flowtabl
838 +EXPORT_SYMBOL_GPL(nf_flow_table_iterate);
840 static void nf_flow_offload_gc_step(struct flow_offload *flow, void *data)
843 +++ b/include/uapi/linux/netfilter/xt_FLOWOFFLOAD.h
845 +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
846 +#ifndef _XT_FLOWOFFLOAD_H
847 +#define _XT_FLOWOFFLOAD_H
849 +#include <linux/types.h>
852 + XT_FLOWOFFLOAD_HW = 1 << 0,
854 + XT_FLOWOFFLOAD_MASK = XT_FLOWOFFLOAD_HW
857 +struct xt_flowoffload_target_info {
861 +#endif /* _XT_FLOWOFFLOAD_H */
862 --- a/include/net/netfilter/nf_flow_table.h
863 +++ b/include/net/netfilter/nf_flow_table.h
864 @@ -271,6 +271,10 @@ void nf_flow_table_free(struct nf_flowta
866 void flow_offload_teardown(struct flow_offload *flow);
868 +int nf_flow_table_iterate(struct nf_flowtable *flow_table,
869 + void (*iter)(struct flow_offload *flow, void *data),
872 void nf_flow_snat_port(const struct flow_offload *flow,
873 struct sk_buff *skb, unsigned int thoff,
874 u8 protocol, enum flow_offload_tuple_dir dir);