1 From: wenxu <wenxu@ucloud.cn>
2 Date: Thu, 10 Jan 2019 14:51:35 +0800
3 Subject: [PATCH] netfilter: nft_flow_offload: fix interaction with vrf slave
6 In the forward chain, the iif is changed from slave device to master vrf
7 device. Thus, flow offload does not find a match on the lower slave
10 This patch uses the cached route, ie. dst->dev, to update the iif and
11 oif fields in the flow entry.
13 After this patch, the following example works fine:
15 # ip addr add dev eth0 1.1.1.1/24
16 # ip addr add dev eth1 10.0.0.1/24
17 # ip link add user1 type vrf table 1
19 # ip l set dev eth0 master user1
20 # ip l set dev eth1 master user1
22 # nft add table firewall
23 # nft add flowtable f fb1 { hook ingress priority 0 \; devices = { eth0, eth1 } \; }
24 # nft add chain f ftb-all {type filter hook forward priority 0 \; policy accept \; }
25 # nft add rule f ftb-all ct zone 1 ip protocol tcp flow offload @fb1
26 # nft add rule f ftb-all ct zone 1 ip protocol udp flow offload @fb1
28 Signed-off-by: wenxu <wenxu@ucloud.cn>
29 Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
32 --- a/include/net/netfilter/nf_flow_table.h
33 +++ b/include/net/netfilter/nf_flow_table.h
34 @@ -84,7 +84,6 @@ struct flow_offload {
35 struct nf_flow_route {
37 struct dst_entry *dst;
39 } tuple[FLOW_OFFLOAD_DIR_MAX];
42 --- a/net/netfilter/nf_flow_table_core.c
43 +++ b/net/netfilter/nf_flow_table_core.c
44 @@ -28,6 +28,7 @@ flow_offload_fill_dir(struct flow_offloa
46 struct flow_offload_tuple *ft = &flow->tuplehash[dir].tuple;
47 struct nf_conntrack_tuple *ctt = &ct->tuplehash[dir].tuple;
48 + struct dst_entry *other_dst = route->tuple[!dir].dst;
49 struct dst_entry *dst = route->tuple[dir].dst;
52 @@ -50,8 +51,8 @@ flow_offload_fill_dir(struct flow_offloa
53 ft->src_port = ctt->src.u.tcp.port;
54 ft->dst_port = ctt->dst.u.tcp.port;
56 - ft->iifidx = route->tuple[dir].ifindex;
57 - ft->oifidx = route->tuple[!dir].ifindex;
58 + ft->iifidx = other_dst->dev->ifindex;
59 + ft->oifidx = dst->dev->ifindex;
63 --- a/net/netfilter/nft_flow_offload.c
64 +++ b/net/netfilter/nft_flow_offload.c
65 @@ -30,9 +30,11 @@ static int nft_flow_route(const struct n
66 switch (nft_pf(pkt)) {
68 fl.u.ip4.daddr = ct->tuplehash[dir].tuple.src.u3.ip;
69 + fl.u.ip4.flowi4_oif = nft_in(pkt)->ifindex;
72 fl.u.ip6.daddr = ct->tuplehash[dir].tuple.src.u3.in6;
73 + fl.u.ip6.flowi6_oif = nft_in(pkt)->ifindex;
77 @@ -41,9 +43,7 @@ static int nft_flow_route(const struct n
80 route->tuple[dir].dst = this_dst;
81 - route->tuple[dir].ifindex = nft_in(pkt)->ifindex;
82 route->tuple[!dir].dst = other_dst;
83 - route->tuple[!dir].ifindex = nft_out(pkt)->ifindex;