Skip to content

Commit 7c23b62

Browse files
committed
netfilter: flow table support for the mixed IPv4/IPv6 family
This patch adds the IPv6 flow table type, that implements the datapath flow table to forward IPv6 traffic. Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 0995210 commit 7c23b62

File tree

6 files changed

+66
-2
lines changed

6 files changed

+66
-2
lines changed

include/net/netfilter/nf_flow_table.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ struct flow_ports {
111111
__be16 source, dest;
112112
};
113113

114+
unsigned int nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb,
115+
const struct nf_hook_state *state);
116+
unsigned int nf_flow_offload_ipv6_hook(void *priv, struct sk_buff *skb,
117+
const struct nf_hook_state *state);
118+
114119
#define MODULE_ALIAS_NF_FLOWTABLE(family) \
115120
MODULE_ALIAS("nf-flowtable-" __stringify(family))
116121

net/ipv4/netfilter/nf_flow_table_ipv4.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ static bool nf_flow_exceeds_mtu(struct sk_buff *skb, const struct rtable *rt)
202202
return false;
203203
}
204204

205-
static unsigned int
205+
unsigned int
206206
nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb,
207207
const struct nf_hook_state *state)
208208
{
@@ -254,6 +254,7 @@ nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb,
254254

255255
return NF_STOLEN;
256256
}
257+
EXPORT_SYMBOL_GPL(nf_flow_offload_ip_hook);
257258

258259
static struct nf_flowtable_type flowtable_ipv4 = {
259260
.family = NFPROTO_IPV4,

net/ipv6/netfilter/nf_flow_table_ipv6.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ static bool nf_flow_exceeds_mtu(struct sk_buff *skb, const struct rt6_info *rt)
196196
return false;
197197
}
198198

199-
static unsigned int
199+
unsigned int
200200
nf_flow_offload_ipv6_hook(void *priv, struct sk_buff *skb,
201201
const struct nf_hook_state *state)
202202
{
@@ -248,6 +248,7 @@ nf_flow_offload_ipv6_hook(void *priv, struct sk_buff *skb,
248248

249249
return NF_STOLEN;
250250
}
251+
EXPORT_SYMBOL_GPL(nf_flow_offload_ipv6_hook);
251252

252253
static struct nf_flowtable_type flowtable_ipv6 = {
253254
.family = NFPROTO_IPV6,

net/netfilter/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,14 @@ endif # NF_TABLES_NETDEV
657657

658658
endif # NF_TABLES
659659

660+
config NF_FLOW_TABLE_INET
661+
select NF_FLOW_TABLE
662+
tristate "Netfilter flow table mixed IPv4/IPv6 module"
663+
help
664+
This option adds the flow table mixed IPv4/IPv6 support.
665+
666+
To compile it as a module, choose M here.
667+
660668
config NF_FLOW_TABLE
661669
tristate "Netfilter flow table module"
662670
help

net/netfilter/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ obj-$(CONFIG_NFT_FWD_NETDEV) += nft_fwd_netdev.o
111111

112112
# flow table infrastructure
113113
obj-$(CONFIG_NF_FLOW_TABLE) += nf_flow_table.o
114+
obj-$(CONFIG_NF_FLOW_TABLE_INET) += nf_flow_table_inet.o
114115

115116
# generic X tables
116117
obj-$(CONFIG_NETFILTER_XTABLES) += x_tables.o xt_tcpudp.o

net/netfilter/nf_flow_table_inet.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#include <linux/kernel.h>
2+
#include <linux/init.h>
3+
#include <linux/module.h>
4+
#include <linux/netfilter.h>
5+
#include <linux/rhashtable.h>
6+
#include <net/netfilter/nf_flow_table.h>
7+
#include <net/netfilter/nf_tables.h>
8+
9+
static unsigned int
10+
nf_flow_offload_inet_hook(void *priv, struct sk_buff *skb,
11+
const struct nf_hook_state *state)
12+
{
13+
switch (skb->protocol) {
14+
case htons(ETH_P_IP):
15+
return nf_flow_offload_ip_hook(priv, skb, state);
16+
case htons(ETH_P_IPV6):
17+
return nf_flow_offload_ipv6_hook(priv, skb, state);
18+
}
19+
20+
return NF_ACCEPT;
21+
}
22+
23+
static struct nf_flowtable_type flowtable_inet = {
24+
.family = NFPROTO_INET,
25+
.params = &nf_flow_offload_rhash_params,
26+
.gc = nf_flow_offload_work_gc,
27+
.hook = nf_flow_offload_inet_hook,
28+
.owner = THIS_MODULE,
29+
};
30+
31+
static int __init nf_flow_inet_module_init(void)
32+
{
33+
nft_register_flowtable_type(&flowtable_inet);
34+
35+
return 0;
36+
}
37+
38+
static void __exit nf_flow_inet_module_exit(void)
39+
{
40+
nft_unregister_flowtable_type(&flowtable_inet);
41+
}
42+
43+
module_init(nf_flow_inet_module_init);
44+
module_exit(nf_flow_inet_module_exit);
45+
46+
MODULE_LICENSE("GPL");
47+
MODULE_AUTHOR("Pablo Neira Ayuso <[email protected]>");
48+
MODULE_ALIAS_NF_FLOWTABLE(1); /* NFPROTO_INET */

0 commit comments

Comments
 (0)