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 flow_offload *flow, void *data)
294 + struct xt_flowoffload_table *table = data;
295 + struct flow_offload_tuple *tuple0 = &flow->tuplehash[0].tuple;
296 + struct flow_offload_tuple *tuple1 = &flow->tuplehash[1].tuple;
297 + struct xt_flowoffload_hook *hook;
299 + spin_lock_bh(&hooks_lock);
300 + hlist_for_each_entry(hook, &table->hooks, list) {
301 + if (hook->ops.dev->ifindex != tuple0->iifidx &&
302 + hook->ops.dev->ifindex != tuple1->iifidx)
307 + spin_unlock_bh(&hooks_lock);
311 +xt_flowoffload_hook_work(struct work_struct *work)
313 + struct xt_flowoffload_table *table;
314 + struct xt_flowoffload_hook *hook;
317 + table = container_of(work, struct xt_flowoffload_table, work.work);
319 + spin_lock_bh(&hooks_lock);
320 + xt_flowoffload_register_hooks(table);
321 + hlist_for_each_entry(hook, &table->hooks, list)
322 + hook->used = false;
323 + spin_unlock_bh(&hooks_lock);
325 + err = nf_flow_table_iterate(&table->ft, xt_flowoffload_check_hook,
327 + if (err && err != -EAGAIN)
330 + if (!xt_flowoffload_cleanup_hooks(table))
334 + queue_delayed_work(system_power_efficient_wq, &table->work, HZ);
338 +xt_flowoffload_skip(struct sk_buff *skb, int family)
340 + if (skb_sec_path(skb))
343 + if (family == NFPROTO_IPV4) {
344 + const struct ip_options *opt = &(IPCB(skb)->opt);
346 + if (unlikely(opt->optlen))
353 +static enum flow_offload_xmit_type nf_xmit_type(struct dst_entry *dst)
356 + return FLOW_OFFLOAD_XMIT_XFRM;
358 + return FLOW_OFFLOAD_XMIT_NEIGH;
361 +static void nf_default_forward_path(struct nf_flow_route *route,
362 + struct dst_entry *dst_cache,
363 + enum ip_conntrack_dir dir,
364 + struct net_device **dev)
366 + dev[!dir] = dst_cache->dev;
367 + route->tuple[!dir].in.ifindex = dst_cache->dev->ifindex;
368 + route->tuple[dir].dst = dst_cache;
369 + route->tuple[dir].xmit_type = nf_xmit_type(dst_cache);
372 +static bool nf_is_valid_ether_device(const struct net_device *dev)
374 + if (!dev || (dev->flags & IFF_LOOPBACK) || dev->type != ARPHRD_ETHER ||
375 + dev->addr_len != ETH_ALEN || !is_valid_ether_addr(dev->dev_addr))
381 +static void nf_dev_path_info(const struct net_device_path_stack *stack,
382 + struct nf_forward_info *info,
385 + const struct net_device_path *path;
388 + memcpy(info->h_dest, ha, ETH_ALEN);
390 + for (i = 0; i < stack->num_paths; i++) {
391 + path = &stack->path[i];
392 + switch (path->type) {
393 + case DEV_PATH_ETHERNET:
395 + case DEV_PATH_VLAN:
396 + case DEV_PATH_PPPOE:
397 + info->indev = path->dev;
398 + if (is_zero_ether_addr(info->h_source))
399 + memcpy(info->h_source, path->dev->dev_addr, ETH_ALEN);
401 + if (path->type == DEV_PATH_ETHERNET)
403 + if (path->type == DEV_PATH_DSA) {
404 + i = stack->num_paths;
408 + /* DEV_PATH_VLAN and DEV_PATH_PPPOE */
409 + if (info->num_encaps >= NF_FLOW_TABLE_ENCAP_MAX) {
410 + info->indev = NULL;
414 + info->outdev = path->dev;
415 + info->encap[info->num_encaps].id = path->encap.id;
416 + info->encap[info->num_encaps].proto = path->encap.proto;
417 + info->num_encaps++;
418 + if (path->type == DEV_PATH_PPPOE)
419 + memcpy(info->h_dest, path->encap.h_dest, ETH_ALEN);
421 + case DEV_PATH_BRIDGE:
422 + if (is_zero_ether_addr(info->h_source))
423 + memcpy(info->h_source, path->dev->dev_addr, ETH_ALEN);
425 + switch (path->bridge.vlan_mode) {
426 + case DEV_PATH_BR_VLAN_UNTAG_HW:
427 + info->ingress_vlans |= BIT(info->num_encaps - 1);
429 + case DEV_PATH_BR_VLAN_TAG:
430 + info->encap[info->num_encaps].id = path->bridge.vlan_id;
431 + info->encap[info->num_encaps].proto = path->bridge.vlan_proto;
432 + info->num_encaps++;
434 + case DEV_PATH_BR_VLAN_UNTAG:
435 + info->num_encaps--;
437 + case DEV_PATH_BR_VLAN_KEEP:
442 + info->indev = NULL;
447 + info->outdev = info->indev;
449 + info->hw_outdev = info->indev;
451 + if (nf_is_valid_ether_device(info->indev))
452 + info->xmit_type = FLOW_OFFLOAD_XMIT_DIRECT;
455 +static int nf_dev_fill_forward_path(const struct nf_flow_route *route,
456 + const struct dst_entry *dst_cache,
457 + const struct nf_conn *ct,
458 + enum ip_conntrack_dir dir, u8 *ha,
459 + struct net_device_path_stack *stack)
461 + const void *daddr = &ct->tuplehash[!dir].tuple.src.u3;
462 + struct net_device *dev = dst_cache->dev;
463 + struct neighbour *n;
466 + if (!nf_is_valid_ether_device(dev))
469 + n = dst_neigh_lookup(dst_cache, daddr);
473 + read_lock_bh(&n->lock);
474 + nud_state = n->nud_state;
475 + ether_addr_copy(ha, n->ha);
476 + read_unlock_bh(&n->lock);
479 + if (!(nud_state & NUD_VALID))
483 + return dev_fill_forward_path(dev, ha, stack);
486 +static void nf_dev_forward_path(struct nf_flow_route *route,
487 + const struct nf_conn *ct,
488 + enum ip_conntrack_dir dir,
489 + struct net_device **devs)
491 + const struct dst_entry *dst = route->tuple[dir].dst;
492 + struct net_device_path_stack stack;
493 + struct nf_forward_info info = {};
494 + unsigned char ha[ETH_ALEN];
497 + if (nf_dev_fill_forward_path(route, dst, ct, dir, ha, &stack) >= 0)
498 + nf_dev_path_info(&stack, &info, ha);
500 + devs[!dir] = (struct net_device *)info.indev;
504 + route->tuple[!dir].in.ifindex = info.indev->ifindex;
505 + for (i = 0; i < info.num_encaps; i++) {
506 + route->tuple[!dir].in.encap[i].id = info.encap[i].id;
507 + route->tuple[!dir].in.encap[i].proto = info.encap[i].proto;
509 + route->tuple[!dir].in.num_encaps = info.num_encaps;
510 + route->tuple[!dir].in.ingress_vlans = info.ingress_vlans;
512 + if (info.xmit_type == FLOW_OFFLOAD_XMIT_DIRECT) {
513 + memcpy(route->tuple[dir].out.h_source, info.h_source, ETH_ALEN);
514 + memcpy(route->tuple[dir].out.h_dest, info.h_dest, ETH_ALEN);
515 + route->tuple[dir].out.ifindex = info.outdev->ifindex;
516 + route->tuple[dir].out.hw_ifindex = info.hw_outdev->ifindex;
517 + route->tuple[dir].xmit_type = info.xmit_type;
522 +xt_flowoffload_route(struct sk_buff *skb, const struct nf_conn *ct,
523 + const struct xt_action_param *par,
524 + struct nf_flow_route *route, enum ip_conntrack_dir dir,
525 + struct net_device **devs)
527 + struct dst_entry *this_dst = skb_dst(skb);
528 + struct dst_entry *other_dst = NULL;
531 + memset(&fl, 0, sizeof(fl));
532 + switch (xt_family(par)) {
534 + fl.u.ip4.daddr = ct->tuplehash[dir].tuple.src.u3.ip;
535 + fl.u.ip4.flowi4_oif = xt_in(par)->ifindex;
538 + fl.u.ip6.saddr = ct->tuplehash[!dir].tuple.dst.u3.in6;
539 + fl.u.ip6.daddr = ct->tuplehash[dir].tuple.src.u3.in6;
540 + fl.u.ip6.flowi6_oif = xt_in(par)->ifindex;
544 + nf_route(xt_net(par), &other_dst, &fl, false, xt_family(par));
548 + nf_default_forward_path(route, this_dst, dir, devs);
549 + nf_default_forward_path(route, other_dst, !dir, devs);
551 + if (route->tuple[dir].xmit_type == FLOW_OFFLOAD_XMIT_NEIGH &&
552 + route->tuple[!dir].xmit_type == FLOW_OFFLOAD_XMIT_NEIGH) {
553 + nf_dev_forward_path(route, ct, dir, devs);
554 + nf_dev_forward_path(route, ct, !dir, devs);
561 +flowoffload_tg(struct sk_buff *skb, const struct xt_action_param *par)
563 + struct xt_flowoffload_table *table;
564 + const struct xt_flowoffload_target_info *info = par->targinfo;
565 + struct tcphdr _tcph, *tcph = NULL;
566 + enum ip_conntrack_info ctinfo;
567 + enum ip_conntrack_dir dir;
568 + struct nf_flow_route route = {};
569 + struct flow_offload *flow = NULL;
570 + struct net_device *devs[2] = {};
571 + struct nf_conn *ct;
574 + if (xt_flowoffload_skip(skb, xt_family(par)))
575 + return XT_CONTINUE;
577 + ct = nf_ct_get(skb, &ctinfo);
579 + return XT_CONTINUE;
581 + switch (ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum) {
583 + if (ct->proto.tcp.state != TCP_CONNTRACK_ESTABLISHED)
584 + return XT_CONTINUE;
586 + tcph = skb_header_pointer(skb, par->thoff,
587 + sizeof(_tcph), &_tcph);
588 + if (unlikely(!tcph || tcph->fin || tcph->rst))
589 + return XT_CONTINUE;
594 + return XT_CONTINUE;
597 + if (nf_ct_ext_exist(ct, NF_CT_EXT_HELPER) ||
598 + ct->status & (IPS_SEQ_ADJUST | IPS_NAT_CLASH))
599 + return XT_CONTINUE;
601 + if (!nf_ct_is_confirmed(ct))
602 + return XT_CONTINUE;
604 + devs[dir] = xt_out(par);
605 + devs[!dir] = xt_in(par);
607 + if (!devs[dir] || !devs[!dir])
608 + return XT_CONTINUE;
610 + if (test_and_set_bit(IPS_OFFLOAD_BIT, &ct->status))
611 + return XT_CONTINUE;
613 + dir = CTINFO2DIR(ctinfo);
615 + if (xt_flowoffload_route(skb, ct, par, &route, dir, devs) < 0)
616 + goto err_flow_route;
618 + flow = flow_offload_alloc(ct);
620 + goto err_flow_alloc;
622 + if (flow_offload_route_init(flow, &route) < 0)
626 + ct->proto.tcp.seen[0].flags |= IP_CT_TCP_FLAG_BE_LIBERAL;
627 + ct->proto.tcp.seen[1].flags |= IP_CT_TCP_FLAG_BE_LIBERAL;
630 + table = &flowtable[!!(info->flags & XT_FLOWOFFLOAD_HW)];
632 + net = read_pnet(&table->ft.net);
634 + write_pnet(&table->ft.net, xt_net(par));
636 + if (flow_offload_add(&table->ft, flow) < 0)
639 + xt_flowoffload_check_device(table, devs[0]);
640 + xt_flowoffload_check_device(table, devs[1]);
642 + dst_release(route.tuple[!dir].dst);
644 + return XT_CONTINUE;
647 + flow_offload_free(flow);
649 + dst_release(route.tuple[!dir].dst);
651 + clear_bit(IPS_OFFLOAD_BIT, &ct->status);
653 + return XT_CONTINUE;
656 +static int flowoffload_chk(const struct xt_tgchk_param *par)
658 + struct xt_flowoffload_target_info *info = par->targinfo;
660 + if (info->flags & ~XT_FLOWOFFLOAD_MASK)
666 +static struct xt_target offload_tg_reg __read_mostly = {
667 + .family = NFPROTO_UNSPEC,
668 + .name = "FLOWOFFLOAD",
670 + .targetsize = sizeof(struct xt_flowoffload_target_info),
671 + .usersize = sizeof(struct xt_flowoffload_target_info),
672 + .checkentry = flowoffload_chk,
673 + .target = flowoffload_tg,
677 +static int flow_offload_netdev_event(struct notifier_block *this,
678 + unsigned long event, void *ptr)
680 + struct xt_flowoffload_hook *hook0, *hook1;
681 + struct net_device *dev = netdev_notifier_info_to_dev(ptr);
683 + if (event != NETDEV_UNREGISTER)
684 + return NOTIFY_DONE;
686 + spin_lock_bh(&hooks_lock);
687 + hook0 = flow_offload_lookup_hook(&flowtable[0], dev);
689 + hlist_del(&hook0->list);
691 + hook1 = flow_offload_lookup_hook(&flowtable[1], dev);
693 + hlist_del(&hook1->list);
694 + spin_unlock_bh(&hooks_lock);
697 + nf_unregister_net_hook(hook0->net, &hook0->ops);
702 + nf_unregister_net_hook(hook1->net, &hook1->ops);
706 + nf_flow_table_cleanup(dev);
708 + return NOTIFY_DONE;
711 +static struct notifier_block flow_offload_netdev_notifier = {
712 + .notifier_call = flow_offload_netdev_event,
715 +static int nf_flow_rule_route_inet(struct net *net,
716 + const struct flow_offload *flow,
717 + enum flow_offload_tuple_dir dir,
718 + struct nf_flow_rule *flow_rule)
720 + const struct flow_offload_tuple *flow_tuple = &flow->tuplehash[dir].tuple;
723 + switch (flow_tuple->l3proto) {
725 + err = nf_flow_rule_route_ipv4(net, flow, dir, flow_rule);
728 + err = nf_flow_rule_route_ipv6(net, flow, dir, flow_rule);
738 +static struct nf_flowtable_type flowtable_inet = {
739 + .family = NFPROTO_INET,
740 + .init = nf_flow_table_init,
741 + .setup = nf_flow_table_offload_setup,
742 + .action = nf_flow_rule_route_inet,
743 + .free = nf_flow_table_free,
744 + .hook = xt_flowoffload_net_hook,
745 + .owner = THIS_MODULE,
748 +static int init_flowtable(struct xt_flowoffload_table *tbl)
750 + INIT_DELAYED_WORK(&tbl->work, xt_flowoffload_hook_work);
751 + tbl->ft.type = &flowtable_inet;
753 + return nf_flow_table_init(&tbl->ft);
756 +static int __init xt_flowoffload_tg_init(void)
760 + register_netdevice_notifier(&flow_offload_netdev_notifier);
762 + ret = init_flowtable(&flowtable[0]);
766 + ret = init_flowtable(&flowtable[1]);
770 + flowtable[1].ft.flags = NF_FLOWTABLE_HW_OFFLOAD;
772 + ret = xt_register_target(&offload_tg_reg);
779 + nf_flow_table_free(&flowtable[1].ft);
781 + nf_flow_table_free(&flowtable[0].ft);
785 +static void __exit xt_flowoffload_tg_exit(void)
787 + xt_unregister_target(&offload_tg_reg);
788 + unregister_netdevice_notifier(&flow_offload_netdev_notifier);
789 + nf_flow_table_free(&flowtable[0].ft);
790 + nf_flow_table_free(&flowtable[1].ft);
793 +MODULE_LICENSE("GPL");
794 +module_init(xt_flowoffload_tg_init);
795 +module_exit(xt_flowoffload_tg_exit);
796 --- a/net/netfilter/nf_flow_table_core.c
797 +++ b/net/netfilter/nf_flow_table_core.c
799 #include <linux/netdevice.h>
801 #include <net/ip6_route.h>
802 -#include <net/netfilter/nf_tables.h>
803 #include <net/netfilter/nf_flow_table.h>
804 #include <net/netfilter/nf_conntrack.h>
805 #include <net/netfilter/nf_conntrack_core.h>
806 @@ -399,8 +398,7 @@ flow_offload_lookup(struct nf_flowtable
808 EXPORT_SYMBOL_GPL(flow_offload_lookup);
811 -nf_flow_table_iterate(struct nf_flowtable *flow_table,
812 +int nf_flow_table_iterate(struct nf_flowtable *flow_table,
813 void (*iter)(struct flow_offload *flow, void *data),
816 @@ -432,6 +430,7 @@ nf_flow_table_iterate(struct nf_flowtabl
820 +EXPORT_SYMBOL_GPL(nf_flow_table_iterate);
822 static bool flow_offload_stale_dst(struct flow_offload_tuple *tuple)
825 +++ b/include/uapi/linux/netfilter/xt_FLOWOFFLOAD.h
827 +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
828 +#ifndef _XT_FLOWOFFLOAD_H
829 +#define _XT_FLOWOFFLOAD_H
831 +#include <linux/types.h>
834 + XT_FLOWOFFLOAD_HW = 1 << 0,
836 + XT_FLOWOFFLOAD_MASK = XT_FLOWOFFLOAD_HW
839 +struct xt_flowoffload_target_info {
843 +#endif /* _XT_FLOWOFFLOAD_H */
844 --- a/include/net/netfilter/nf_flow_table.h
845 +++ b/include/net/netfilter/nf_flow_table.h
846 @@ -275,6 +275,10 @@ void nf_flow_table_free(struct nf_flowta
848 void flow_offload_teardown(struct flow_offload *flow);
850 +int nf_flow_table_iterate(struct nf_flowtable *flow_table,
851 + void (*iter)(struct flow_offload *flow, void *data),
854 void nf_flow_snat_port(const struct flow_offload *flow,
855 struct sk_buff *skb, unsigned int thoff,
856 u8 protocol, enum flow_offload_tuple_dir dir);