1 From: Pablo Neira Ayuso <pablo@netfilter.org>
2 Date: Sun, 7 Jan 2018 01:04:22 +0100
3 Subject: [PATCH] netfilter: flow table support for the mixed IPv4/IPv6 family
5 This patch adds the IPv6 flow table type, that implements the datapath
6 flow table to forward IPv6 traffic.
8 Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 create mode 100644 net/netfilter/nf_flow_table_inet.c
12 --- a/include/net/netfilter/nf_flow_table.h
13 +++ b/include/net/netfilter/nf_flow_table.h
14 @@ -111,6 +111,11 @@ struct flow_ports {
18 +unsigned int nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb,
19 + const struct nf_hook_state *state);
20 +unsigned int nf_flow_offload_ipv6_hook(void *priv, struct sk_buff *skb,
21 + const struct nf_hook_state *state);
23 #define MODULE_ALIAS_NF_FLOWTABLE(family) \
24 MODULE_ALIAS("nf-flowtable-" __stringify(family))
26 --- a/net/ipv4/netfilter/nf_flow_table_ipv4.c
27 +++ b/net/ipv4/netfilter/nf_flow_table_ipv4.c
28 @@ -202,7 +202,7 @@ static bool nf_flow_exceeds_mtu(struct s
34 nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb,
35 const struct nf_hook_state *state)
37 @@ -254,6 +254,7 @@ nf_flow_offload_ip_hook(void *priv, stru
41 +EXPORT_SYMBOL_GPL(nf_flow_offload_ip_hook);
43 static struct nf_flowtable_type flowtable_ipv4 = {
44 .family = NFPROTO_IPV4,
45 --- a/net/ipv6/netfilter/nf_flow_table_ipv6.c
46 +++ b/net/ipv6/netfilter/nf_flow_table_ipv6.c
47 @@ -196,7 +196,7 @@ static bool nf_flow_exceeds_mtu(struct s
53 nf_flow_offload_ipv6_hook(void *priv, struct sk_buff *skb,
54 const struct nf_hook_state *state)
56 @@ -248,6 +248,7 @@ nf_flow_offload_ipv6_hook(void *priv, st
60 +EXPORT_SYMBOL_GPL(nf_flow_offload_ipv6_hook);
62 static struct nf_flowtable_type flowtable_ipv6 = {
63 .family = NFPROTO_IPV6,
64 --- a/net/netfilter/Kconfig
65 +++ b/net/netfilter/Kconfig
66 @@ -667,6 +667,14 @@ endif # NF_TABLES_NETDEV
70 +config NF_FLOW_TABLE_INET
71 + select NF_FLOW_TABLE
72 + tristate "Netfilter flow table mixed IPv4/IPv6 module"
74 + This option adds the flow table mixed IPv4/IPv6 support.
76 + To compile it as a module, choose M here.
79 tristate "Netfilter flow table module"
81 --- a/net/netfilter/Makefile
82 +++ b/net/netfilter/Makefile
83 @@ -112,6 +112,7 @@ obj-$(CONFIG_NFT_FWD_NETDEV) += nft_fwd_
85 # flow table infrastructure
86 obj-$(CONFIG_NF_FLOW_TABLE) += nf_flow_table.o
87 +obj-$(CONFIG_NF_FLOW_TABLE_INET) += nf_flow_table_inet.o
90 obj-$(CONFIG_NETFILTER_XTABLES) += x_tables.o xt_tcpudp.o
92 +++ b/net/netfilter/nf_flow_table_inet.c
94 +#include <linux/kernel.h>
95 +#include <linux/init.h>
96 +#include <linux/module.h>
97 +#include <linux/netfilter.h>
98 +#include <linux/rhashtable.h>
99 +#include <net/netfilter/nf_flow_table.h>
100 +#include <net/netfilter/nf_tables.h>
103 +nf_flow_offload_inet_hook(void *priv, struct sk_buff *skb,
104 + const struct nf_hook_state *state)
106 + switch (skb->protocol) {
107 + case htons(ETH_P_IP):
108 + return nf_flow_offload_ip_hook(priv, skb, state);
109 + case htons(ETH_P_IPV6):
110 + return nf_flow_offload_ipv6_hook(priv, skb, state);
116 +static struct nf_flowtable_type flowtable_inet = {
117 + .family = NFPROTO_INET,
118 + .params = &nf_flow_offload_rhash_params,
119 + .gc = nf_flow_offload_work_gc,
120 + .hook = nf_flow_offload_inet_hook,
121 + .owner = THIS_MODULE,
124 +static int __init nf_flow_inet_module_init(void)
126 + nft_register_flowtable_type(&flowtable_inet);
131 +static void __exit nf_flow_inet_module_exit(void)
133 + nft_unregister_flowtable_type(&flowtable_inet);
136 +module_init(nf_flow_inet_module_init);
137 +module_exit(nf_flow_inet_module_exit);
139 +MODULE_LICENSE("GPL");
140 +MODULE_AUTHOR("Pablo Neira Ayuso <pablo@netfilter.org>");
141 +MODULE_ALIAS_NF_FLOWTABLE(1); /* NFPROTO_INET */