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 @@ -708,8 +708,6 @@ config NFT_REJECT_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 @@ -718,11 +716,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 @@ -1011,6 +1010,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 @@ -143,6 +143,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>
115 +#include <net/netfilter/nf_conntrack.h>
116 +#include <net/netfilter/nf_conntrack_extend.h>
117 +#include <net/netfilter/nf_conntrack_helper.h>
118 +#include <net/netfilter/nf_flow_table.h>
120 +struct xt_flowoffload_hook {
121 + struct hlist_node list;
122 + struct nf_hook_ops ops;
128 +struct xt_flowoffload_table {
129 + struct nf_flowtable ft;
130 + struct hlist_head hooks;
131 + struct delayed_work work;
134 +struct nf_forward_info {
135 + const struct net_device *indev;
136 + const struct net_device *outdev;
137 + const struct net_device *hw_outdev;
141 + } encap[NF_FLOW_TABLE_ENCAP_MAX];
144 + u8 h_source[ETH_ALEN];
145 + u8 h_dest[ETH_ALEN];
146 + enum flow_offload_xmit_type xmit_type;
149 +static DEFINE_SPINLOCK(hooks_lock);
151 +struct xt_flowoffload_table flowtable[2];
154 +xt_flowoffload_net_hook(void *priv, struct sk_buff *skb,
155 + const struct nf_hook_state *state)
157 + struct vlan_ethhdr *veth;
160 + switch (skb->protocol) {
161 + case htons(ETH_P_8021Q):
162 + veth = (struct vlan_ethhdr *)skb_mac_header(skb);
163 + proto = veth->h_vlan_encapsulated_proto;
165 + case htons(ETH_P_PPP_SES):
166 + proto = nf_flow_pppoe_proto(skb);
169 + proto = skb->protocol;
174 + case htons(ETH_P_IP):
175 + return nf_flow_offload_ip_hook(priv, skb, state);
176 + case htons(ETH_P_IPV6):
177 + return nf_flow_offload_ipv6_hook(priv, skb, state);
184 +xt_flowoffload_create_hook(struct xt_flowoffload_table *table,
185 + struct net_device *dev)
187 + struct xt_flowoffload_hook *hook;
188 + struct nf_hook_ops *ops;
190 + hook = kzalloc(sizeof(*hook), GFP_ATOMIC);
195 + ops->pf = NFPROTO_NETDEV;
196 + ops->hooknum = NF_NETDEV_INGRESS;
197 + ops->priority = 10;
198 + ops->priv = &table->ft;
199 + ops->hook = xt_flowoffload_net_hook;
202 + hlist_add_head(&hook->list, &table->hooks);
203 + mod_delayed_work(system_power_efficient_wq, &table->work, 0);
208 +static struct xt_flowoffload_hook *
209 +flow_offload_lookup_hook(struct xt_flowoffload_table *table,
210 + struct net_device *dev)
212 + struct xt_flowoffload_hook *hook;
214 + hlist_for_each_entry(hook, &table->hooks, list) {
215 + if (hook->ops.dev == dev)
223 +xt_flowoffload_check_device(struct xt_flowoffload_table *table,
224 + struct net_device *dev)
226 + struct xt_flowoffload_hook *hook;
231 + spin_lock_bh(&hooks_lock);
232 + hook = flow_offload_lookup_hook(table, dev);
236 + xt_flowoffload_create_hook(table, dev);
237 + spin_unlock_bh(&hooks_lock);
241 +xt_flowoffload_register_hooks(struct xt_flowoffload_table *table)
243 + struct xt_flowoffload_hook *hook;
246 + hlist_for_each_entry(hook, &table->hooks, list) {
247 + if (hook->registered)
250 + hook->registered = true;
251 + hook->net = dev_net(hook->ops.dev);
252 + spin_unlock_bh(&hooks_lock);
253 + nf_register_net_hook(hook->net, &hook->ops);
254 + if (table->ft.flags & NF_FLOWTABLE_HW_OFFLOAD)
255 + table->ft.type->setup(&table->ft, hook->ops.dev,
257 + spin_lock_bh(&hooks_lock);
264 +xt_flowoffload_cleanup_hooks(struct xt_flowoffload_table *table)
266 + struct xt_flowoffload_hook *hook;
267 + bool active = false;
270 + spin_lock_bh(&hooks_lock);
271 + hlist_for_each_entry(hook, &table->hooks, list) {
272 + if (hook->used || !hook->registered) {
277 + hlist_del(&hook->list);
278 + spin_unlock_bh(&hooks_lock);
279 + if (table->ft.flags & NF_FLOWTABLE_HW_OFFLOAD)
280 + table->ft.type->setup(&table->ft, hook->ops.dev,
281 + FLOW_BLOCK_UNBIND);
282 + nf_unregister_net_hook(hook->net, &hook->ops);
286 + spin_unlock_bh(&hooks_lock);
292 +xt_flowoffload_check_hook(struct nf_flowtable *flowtable,
293 + struct flow_offload *flow, void *data)
295 + struct xt_flowoffload_table *table;
296 + struct flow_offload_tuple *tuple0 = &flow->tuplehash[0].tuple;
297 + struct flow_offload_tuple *tuple1 = &flow->tuplehash[1].tuple;
298 + struct xt_flowoffload_hook *hook;
300 + table = container_of(flowtable, struct xt_flowoffload_table, ft);
302 + spin_lock_bh(&hooks_lock);
303 + hlist_for_each_entry(hook, &table->hooks, list) {
304 + if (hook->ops.dev->ifindex != tuple0->iifidx &&
305 + hook->ops.dev->ifindex != tuple1->iifidx)
310 + spin_unlock_bh(&hooks_lock);
314 +xt_flowoffload_hook_work(struct work_struct *work)
316 + struct xt_flowoffload_table *table;
317 + struct xt_flowoffload_hook *hook;
320 + table = container_of(work, struct xt_flowoffload_table, work.work);
322 + spin_lock_bh(&hooks_lock);
323 + xt_flowoffload_register_hooks(table);
324 + hlist_for_each_entry(hook, &table->hooks, list)
325 + hook->used = false;
326 + spin_unlock_bh(&hooks_lock);
328 + err = nf_flow_table_iterate(&table->ft, xt_flowoffload_check_hook,
330 + if (err && err != -EAGAIN)
333 + if (!xt_flowoffload_cleanup_hooks(table))
337 + queue_delayed_work(system_power_efficient_wq, &table->work, HZ);
341 +xt_flowoffload_skip(struct sk_buff *skb, int family)
343 + if (skb_sec_path(skb))
346 + if (family == NFPROTO_IPV4) {
347 + const struct ip_options *opt = &(IPCB(skb)->opt);
349 + if (unlikely(opt->optlen))
356 +static enum flow_offload_xmit_type nf_xmit_type(struct dst_entry *dst)
359 + return FLOW_OFFLOAD_XMIT_XFRM;
361 + return FLOW_OFFLOAD_XMIT_NEIGH;
364 +static void nf_default_forward_path(struct nf_flow_route *route,
365 + struct dst_entry *dst_cache,
366 + enum ip_conntrack_dir dir,
367 + struct net_device **dev)
369 + dev[!dir] = dst_cache->dev;
370 + route->tuple[!dir].in.ifindex = dst_cache->dev->ifindex;
371 + route->tuple[dir].dst = dst_cache;
372 + route->tuple[dir].xmit_type = nf_xmit_type(dst_cache);
375 +static bool nf_is_valid_ether_device(const struct net_device *dev)
377 + if (!dev || (dev->flags & IFF_LOOPBACK) || dev->type != ARPHRD_ETHER ||
378 + dev->addr_len != ETH_ALEN || !is_valid_ether_addr(dev->dev_addr))
384 +static void nf_dev_path_info(const struct net_device_path_stack *stack,
385 + struct nf_forward_info *info,
388 + const struct net_device_path *path;
391 + memcpy(info->h_dest, ha, ETH_ALEN);
393 + for (i = 0; i < stack->num_paths; i++) {
394 + path = &stack->path[i];
395 + switch (path->type) {
396 + case DEV_PATH_ETHERNET:
398 + case DEV_PATH_VLAN:
399 + case DEV_PATH_PPPOE:
400 + info->indev = path->dev;
401 + if (is_zero_ether_addr(info->h_source))
402 + memcpy(info->h_source, path->dev->dev_addr, ETH_ALEN);
404 + if (path->type == DEV_PATH_ETHERNET)
406 + if (path->type == DEV_PATH_DSA) {
407 + i = stack->num_paths;
411 + /* DEV_PATH_VLAN and DEV_PATH_PPPOE */
412 + if (info->num_encaps >= NF_FLOW_TABLE_ENCAP_MAX) {
413 + info->indev = NULL;
417 + info->outdev = path->dev;
418 + info->encap[info->num_encaps].id = path->encap.id;
419 + info->encap[info->num_encaps].proto = path->encap.proto;
420 + info->num_encaps++;
421 + if (path->type == DEV_PATH_PPPOE)
422 + memcpy(info->h_dest, path->encap.h_dest, ETH_ALEN);
424 + case DEV_PATH_BRIDGE:
425 + if (is_zero_ether_addr(info->h_source))
426 + memcpy(info->h_source, path->dev->dev_addr, ETH_ALEN);
428 + switch (path->bridge.vlan_mode) {
429 + case DEV_PATH_BR_VLAN_UNTAG_HW:
430 + info->ingress_vlans |= BIT(info->num_encaps - 1);
432 + case DEV_PATH_BR_VLAN_TAG:
433 + info->encap[info->num_encaps].id = path->bridge.vlan_id;
434 + info->encap[info->num_encaps].proto = path->bridge.vlan_proto;
435 + info->num_encaps++;
437 + case DEV_PATH_BR_VLAN_UNTAG:
438 + info->num_encaps--;
440 + case DEV_PATH_BR_VLAN_KEEP:
445 + info->indev = NULL;
450 + info->outdev = info->indev;
452 + info->hw_outdev = info->indev;
454 + if (nf_is_valid_ether_device(info->indev))
455 + info->xmit_type = FLOW_OFFLOAD_XMIT_DIRECT;
458 +static int nf_dev_fill_forward_path(const struct nf_flow_route *route,
459 + const struct dst_entry *dst_cache,
460 + const struct nf_conn *ct,
461 + enum ip_conntrack_dir dir, u8 *ha,
462 + struct net_device_path_stack *stack)
464 + const void *daddr = &ct->tuplehash[!dir].tuple.src.u3;
465 + struct net_device *dev = dst_cache->dev;
466 + struct neighbour *n;
469 + if (!nf_is_valid_ether_device(dev))
472 + n = dst_neigh_lookup(dst_cache, daddr);
476 + read_lock_bh(&n->lock);
477 + nud_state = n->nud_state;
478 + ether_addr_copy(ha, n->ha);
479 + read_unlock_bh(&n->lock);
482 + if (!(nud_state & NUD_VALID))
486 + return dev_fill_forward_path(dev, ha, stack);
489 +static void nf_dev_forward_path(struct nf_flow_route *route,
490 + const struct nf_conn *ct,
491 + enum ip_conntrack_dir dir,
492 + struct net_device **devs)
494 + const struct dst_entry *dst = route->tuple[dir].dst;
495 + struct net_device_path_stack stack;
496 + struct nf_forward_info info = {};
497 + unsigned char ha[ETH_ALEN];
500 + if (nf_dev_fill_forward_path(route, dst, ct, dir, ha, &stack) >= 0)
501 + nf_dev_path_info(&stack, &info, ha);
503 + devs[!dir] = (struct net_device *)info.indev;
507 + route->tuple[!dir].in.ifindex = info.indev->ifindex;
508 + for (i = 0; i < info.num_encaps; i++) {
509 + route->tuple[!dir].in.encap[i].id = info.encap[i].id;
510 + route->tuple[!dir].in.encap[i].proto = info.encap[i].proto;
512 + route->tuple[!dir].in.num_encaps = info.num_encaps;
513 + route->tuple[!dir].in.ingress_vlans = info.ingress_vlans;
515 + if (info.xmit_type == FLOW_OFFLOAD_XMIT_DIRECT) {
516 + memcpy(route->tuple[dir].out.h_source, info.h_source, ETH_ALEN);
517 + memcpy(route->tuple[dir].out.h_dest, info.h_dest, ETH_ALEN);
518 + route->tuple[dir].out.ifindex = info.outdev->ifindex;
519 + route->tuple[dir].out.hw_ifindex = info.hw_outdev->ifindex;
520 + route->tuple[dir].xmit_type = info.xmit_type;
525 +xt_flowoffload_route(struct sk_buff *skb, const struct nf_conn *ct,
526 + const struct xt_action_param *par,
527 + struct nf_flow_route *route, enum ip_conntrack_dir dir,
528 + struct net_device **devs)
530 + struct dst_entry *this_dst = skb_dst(skb);
531 + struct dst_entry *other_dst = NULL;
534 + memset(&fl, 0, sizeof(fl));
535 + switch (xt_family(par)) {
537 + fl.u.ip4.daddr = ct->tuplehash[dir].tuple.src.u3.ip;
538 + fl.u.ip4.flowi4_oif = xt_in(par)->ifindex;
541 + fl.u.ip6.saddr = ct->tuplehash[!dir].tuple.dst.u3.in6;
542 + fl.u.ip6.daddr = ct->tuplehash[dir].tuple.src.u3.in6;
543 + fl.u.ip6.flowi6_oif = xt_in(par)->ifindex;
547 + nf_route(xt_net(par), &other_dst, &fl, false, xt_family(par));
551 + nf_default_forward_path(route, this_dst, dir, devs);
552 + nf_default_forward_path(route, other_dst, !dir, devs);
554 + if (route->tuple[dir].xmit_type == FLOW_OFFLOAD_XMIT_NEIGH &&
555 + route->tuple[!dir].xmit_type == FLOW_OFFLOAD_XMIT_NEIGH) {
556 + nf_dev_forward_path(route, ct, dir, devs);
557 + nf_dev_forward_path(route, ct, !dir, devs);
564 +flowoffload_tg(struct sk_buff *skb, const struct xt_action_param *par)
566 + struct xt_flowoffload_table *table;
567 + const struct xt_flowoffload_target_info *info = par->targinfo;
568 + struct tcphdr _tcph, *tcph = NULL;
569 + enum ip_conntrack_info ctinfo;
570 + enum ip_conntrack_dir dir;
571 + struct nf_flow_route route = {};
572 + struct flow_offload *flow = NULL;
573 + struct net_device *devs[2] = {};
574 + struct nf_conn *ct;
577 + if (xt_flowoffload_skip(skb, xt_family(par)))
578 + return XT_CONTINUE;
580 + ct = nf_ct_get(skb, &ctinfo);
582 + return XT_CONTINUE;
584 + switch (ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum) {
586 + if (ct->proto.tcp.state != TCP_CONNTRACK_ESTABLISHED)
587 + return XT_CONTINUE;
589 + tcph = skb_header_pointer(skb, par->thoff,
590 + sizeof(_tcph), &_tcph);
591 + if (unlikely(!tcph || tcph->fin || tcph->rst))
592 + return XT_CONTINUE;
597 + return XT_CONTINUE;
600 + if (nf_ct_ext_exist(ct, NF_CT_EXT_HELPER) ||
601 + ct->status & (IPS_SEQ_ADJUST | IPS_NAT_CLASH))
602 + return XT_CONTINUE;
604 + if (!nf_ct_is_confirmed(ct))
605 + return XT_CONTINUE;
607 + devs[dir] = xt_out(par);
608 + devs[!dir] = xt_in(par);
610 + if (!devs[dir] || !devs[!dir])
611 + return XT_CONTINUE;
613 + if (test_and_set_bit(IPS_OFFLOAD_BIT, &ct->status))
614 + return XT_CONTINUE;
616 + dir = CTINFO2DIR(ctinfo);
618 + if (xt_flowoffload_route(skb, ct, par, &route, dir, devs) < 0)
619 + goto err_flow_route;
621 + flow = flow_offload_alloc(ct);
623 + goto err_flow_alloc;
625 + if (flow_offload_route_init(flow, &route) < 0)
629 + ct->proto.tcp.seen[0].flags |= IP_CT_TCP_FLAG_BE_LIBERAL;
630 + ct->proto.tcp.seen[1].flags |= IP_CT_TCP_FLAG_BE_LIBERAL;
633 + table = &flowtable[!!(info->flags & XT_FLOWOFFLOAD_HW)];
635 + net = read_pnet(&table->ft.net);
637 + write_pnet(&table->ft.net, xt_net(par));
639 + if (flow_offload_add(&table->ft, flow) < 0)
642 + xt_flowoffload_check_device(table, devs[0]);
643 + xt_flowoffload_check_device(table, devs[1]);
645 + dst_release(route.tuple[!dir].dst);
647 + return XT_CONTINUE;
650 + flow_offload_free(flow);
652 + dst_release(route.tuple[!dir].dst);
654 + clear_bit(IPS_OFFLOAD_BIT, &ct->status);
656 + return XT_CONTINUE;
659 +static int flowoffload_chk(const struct xt_tgchk_param *par)
661 + struct xt_flowoffload_target_info *info = par->targinfo;
663 + if (info->flags & ~XT_FLOWOFFLOAD_MASK)
669 +static struct xt_target offload_tg_reg __read_mostly = {
670 + .family = NFPROTO_UNSPEC,
671 + .name = "FLOWOFFLOAD",
673 + .targetsize = sizeof(struct xt_flowoffload_target_info),
674 + .usersize = sizeof(struct xt_flowoffload_target_info),
675 + .checkentry = flowoffload_chk,
676 + .target = flowoffload_tg,
680 +static int flow_offload_netdev_event(struct notifier_block *this,
681 + unsigned long event, void *ptr)
683 + struct xt_flowoffload_hook *hook0, *hook1;
684 + struct net_device *dev = netdev_notifier_info_to_dev(ptr);
686 + if (event != NETDEV_UNREGISTER)
687 + return NOTIFY_DONE;
689 + spin_lock_bh(&hooks_lock);
690 + hook0 = flow_offload_lookup_hook(&flowtable[0], dev);
692 + hlist_del(&hook0->list);
694 + hook1 = flow_offload_lookup_hook(&flowtable[1], dev);
696 + hlist_del(&hook1->list);
697 + spin_unlock_bh(&hooks_lock);
700 + nf_unregister_net_hook(hook0->net, &hook0->ops);
705 + nf_unregister_net_hook(hook1->net, &hook1->ops);
709 + nf_flow_table_cleanup(dev);
711 + return NOTIFY_DONE;
714 +static struct notifier_block flow_offload_netdev_notifier = {
715 + .notifier_call = flow_offload_netdev_event,
718 +static int nf_flow_rule_route_inet(struct net *net,
719 + const struct flow_offload *flow,
720 + enum flow_offload_tuple_dir dir,
721 + struct nf_flow_rule *flow_rule)
723 + const struct flow_offload_tuple *flow_tuple = &flow->tuplehash[dir].tuple;
726 + switch (flow_tuple->l3proto) {
728 + err = nf_flow_rule_route_ipv4(net, flow, dir, flow_rule);
731 + err = nf_flow_rule_route_ipv6(net, flow, dir, flow_rule);
741 +static struct nf_flowtable_type flowtable_inet = {
742 + .family = NFPROTO_INET,
743 + .init = nf_flow_table_init,
744 + .setup = nf_flow_table_offload_setup,
745 + .action = nf_flow_rule_route_inet,
746 + .free = nf_flow_table_free,
747 + .hook = xt_flowoffload_net_hook,
748 + .owner = THIS_MODULE,
751 +static int init_flowtable(struct xt_flowoffload_table *tbl)
753 + INIT_DELAYED_WORK(&tbl->work, xt_flowoffload_hook_work);
754 + tbl->ft.type = &flowtable_inet;
756 + return nf_flow_table_init(&tbl->ft);
759 +static int __init xt_flowoffload_tg_init(void)
763 + register_netdevice_notifier(&flow_offload_netdev_notifier);
765 + ret = init_flowtable(&flowtable[0]);
769 + ret = init_flowtable(&flowtable[1]);
773 + flowtable[1].ft.flags = NF_FLOWTABLE_HW_OFFLOAD;
775 + ret = xt_register_target(&offload_tg_reg);
782 + nf_flow_table_free(&flowtable[1].ft);
784 + nf_flow_table_free(&flowtable[0].ft);
788 +static void __exit xt_flowoffload_tg_exit(void)
790 + xt_unregister_target(&offload_tg_reg);
791 + unregister_netdevice_notifier(&flow_offload_netdev_notifier);
792 + nf_flow_table_free(&flowtable[0].ft);
793 + nf_flow_table_free(&flowtable[1].ft);
796 +MODULE_LICENSE("GPL");
797 +module_init(xt_flowoffload_tg_init);
798 +module_exit(xt_flowoffload_tg_exit);
799 --- a/net/netfilter/nf_flow_table_core.c
800 +++ b/net/netfilter/nf_flow_table_core.c
802 #include <linux/netdevice.h>
804 #include <net/ip6_route.h>
805 -#include <net/netfilter/nf_tables.h>
806 #include <net/netfilter/nf_flow_table.h>
807 #include <net/netfilter/nf_conntrack.h>
808 #include <net/netfilter/nf_conntrack_core.h>
809 @@ -380,8 +379,7 @@ flow_offload_lookup(struct nf_flowtable
811 EXPORT_SYMBOL_GPL(flow_offload_lookup);
814 -nf_flow_table_iterate(struct nf_flowtable *flow_table,
815 +int nf_flow_table_iterate(struct nf_flowtable *flow_table,
816 void (*iter)(struct nf_flowtable *flowtable,
817 struct flow_offload *flow, void *data),
819 @@ -435,6 +433,7 @@ static void nf_flow_offload_gc_step(stru
820 nf_flow_offload_stats(flow_table, flow);
823 +EXPORT_SYMBOL_GPL(nf_flow_table_iterate);
825 static void nf_flow_offload_work_gc(struct work_struct *work)
828 +++ b/include/uapi/linux/netfilter/xt_FLOWOFFLOAD.h
830 +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
831 +#ifndef _XT_FLOWOFFLOAD_H
832 +#define _XT_FLOWOFFLOAD_H
834 +#include <linux/types.h>
837 + XT_FLOWOFFLOAD_HW = 1 << 0,
839 + XT_FLOWOFFLOAD_MASK = XT_FLOWOFFLOAD_HW
842 +struct xt_flowoffload_target_info {
846 +#endif /* _XT_FLOWOFFLOAD_H */
847 --- a/include/net/netfilter/nf_flow_table.h
848 +++ b/include/net/netfilter/nf_flow_table.h
849 @@ -275,6 +275,11 @@ void nf_flow_table_free(struct nf_flowta
851 void flow_offload_teardown(struct flow_offload *flow);
853 +int nf_flow_table_iterate(struct nf_flowtable *flow_table,
854 + void (*iter)(struct nf_flowtable *flowtable,
855 + struct flow_offload *flow, void *data),
858 void nf_flow_snat_port(const struct flow_offload *flow,
859 struct sk_buff *skb, unsigned int thoff,
860 u8 protocol, enum flow_offload_tuple_dir dir);