ramips: drop support for kernel 4.14
[openwrt/staging/dedeckeh.git] / target / linux / generic / backport-4.14 / 372-netfilter-nft_flow_offload-fix-interaction-with-vrf-.patch
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
4 device
5
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
8 device.
9
10 This patch uses the cached route, ie. dst->dev, to update the iif and
11 oif fields in the flow entry.
12
13 After this patch, the following example works fine:
14
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
18 # ip l set user1 up
19 # ip l set dev eth0 master user1
20 # ip l set dev eth1 master user1
21
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
27
28 Signed-off-by: wenxu <wenxu@ucloud.cn>
29 Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
30 ---
31
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 {
36 struct {
37 struct dst_entry *dst;
38 - int ifindex;
39 } tuple[FLOW_OFFLOAD_DIR_MAX];
40 };
41
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
45 {
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;
50
51 ft->dir = dir;
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;
55
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;
60 ft->dst_cache = dst;
61 }
62
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)) {
67 case NFPROTO_IPV4:
68 fl.u.ip4.daddr = ct->tuplehash[dir].tuple.src.u3.ip;
69 + fl.u.ip4.flowi4_oif = nft_in(pkt)->ifindex;
70 break;
71 case NFPROTO_IPV6:
72 fl.u.ip6.daddr = ct->tuplehash[dir].tuple.src.u3.in6;
73 + fl.u.ip6.flowi6_oif = nft_in(pkt)->ifindex;
74 break;
75 }
76
77 @@ -41,9 +43,7 @@ static int nft_flow_route(const struct n
78 return -ENOENT;
79
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;
84
85 return 0;
86 }