1 From: Pablo Neira Ayuso <pablo@netfilter.org>
2 Date: Fri, 20 Nov 2020 13:49:14 +0100
3 Subject: [PATCH] netfilter: flowtable: add xmit path types
5 Add the xmit_type field that defines the two supported xmit paths in the
6 flowtable data plane, which are the neighbour and the xfrm xmit paths.
7 This patch prepares for new flowtable xmit path types to come.
9 Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 --- a/include/net/netfilter/nf_flow_table.h
13 +++ b/include/net/netfilter/nf_flow_table.h
14 @@ -89,6 +89,11 @@ enum flow_offload_tuple_dir {
15 FLOW_OFFLOAD_DIR_MAX = IP_CT_DIR_MAX
18 +enum flow_offload_xmit_type {
19 + FLOW_OFFLOAD_XMIT_NEIGH = 0,
20 + FLOW_OFFLOAD_XMIT_XFRM,
23 struct flow_offload_tuple {
25 struct in_addr src_v4;
26 @@ -111,7 +116,8 @@ struct flow_offload_tuple {
27 /* All members above are keys for lookups, see flow_offload_hash(). */
36 @@ -158,7 +164,8 @@ static inline __s32 nf_flow_timeout_delt
38 struct nf_flow_route {
40 - struct dst_entry *dst;
41 + struct dst_entry *dst;
42 + enum flow_offload_xmit_type xmit_type;
43 } tuple[FLOW_OFFLOAD_DIR_MAX];
46 --- a/net/netfilter/nf_flow_table_core.c
47 +++ b/net/netfilter/nf_flow_table_core.c
48 @@ -95,6 +95,7 @@ static int flow_offload_fill_route(struc
51 flow_tuple->iifidx = other_dst->dev->ifindex;
52 + flow_tuple->xmit_type = route->tuple[dir].xmit_type;
53 flow_tuple->dst_cache = dst;
56 --- a/net/netfilter/nf_flow_table_ip.c
57 +++ b/net/netfilter/nf_flow_table_ip.c
58 @@ -220,10 +220,20 @@ static bool nf_flow_exceeds_mtu(const st
62 -static int nf_flow_offload_dst_check(struct dst_entry *dst)
63 +static inline struct dst_entry *
64 +nft_flow_dst(struct flow_offload_tuple_rhash *tuplehash)
66 - if (unlikely(dst_xfrm(dst)))
67 + return tuplehash->tuple.dst_cache;
70 +static int nf_flow_offload_dst_check(struct flow_offload_tuple_rhash *tuplehash)
72 + struct dst_entry *dst;
74 + if (unlikely(tuplehash->tuple.xmit_type == FLOW_OFFLOAD_XMIT_XFRM)) {
75 + dst = nft_flow_dst(tuplehash);
76 return dst_check(dst, 0) ? 0 : -1;
81 @@ -265,8 +275,6 @@ nf_flow_offload_ip_hook(void *priv, stru
83 dir = tuplehash->tuple.dir;
84 flow = container_of(tuplehash, struct flow_offload, tuplehash[dir]);
85 - rt = (struct rtable *)flow->tuplehash[dir].tuple.dst_cache;
86 - outdev = rt->dst.dev;
88 if (unlikely(nf_flow_exceeds_mtu(skb, flow->tuplehash[dir].tuple.mtu)))
90 @@ -280,7 +288,7 @@ nf_flow_offload_ip_hook(void *priv, stru
92 flow_offload_refresh(flow_table, flow);
94 - if (nf_flow_offload_dst_check(&rt->dst)) {
95 + if (nf_flow_offload_dst_check(tuplehash)) {
96 flow_offload_teardown(flow);
99 @@ -295,13 +303,16 @@ nf_flow_offload_ip_hook(void *priv, stru
100 if (flow_table->flags & NF_FLOWTABLE_COUNTER)
101 nf_ct_acct_update(flow->ct, tuplehash->tuple.dir, skb->len);
103 - if (unlikely(dst_xfrm(&rt->dst))) {
104 + rt = (struct rtable *)tuplehash->tuple.dst_cache;
106 + if (unlikely(tuplehash->tuple.xmit_type == FLOW_OFFLOAD_XMIT_XFRM)) {
107 memset(skb->cb, 0, sizeof(struct inet_skb_parm));
108 IPCB(skb)->iif = skb->dev->ifindex;
109 IPCB(skb)->flags = IPSKB_FORWARDED;
110 return nf_flow_xmit_xfrm(skb, state, &rt->dst);
113 + outdev = rt->dst.dev;
115 nexthop = rt_nexthop(rt, flow->tuplehash[!dir].tuple.src_v4.s_addr);
116 skb_dst_set_noref(skb, &rt->dst);
117 @@ -506,8 +517,6 @@ nf_flow_offload_ipv6_hook(void *priv, st
119 dir = tuplehash->tuple.dir;
120 flow = container_of(tuplehash, struct flow_offload, tuplehash[dir]);
121 - rt = (struct rt6_info *)flow->tuplehash[dir].tuple.dst_cache;
122 - outdev = rt->dst.dev;
124 if (unlikely(nf_flow_exceeds_mtu(skb, flow->tuplehash[dir].tuple.mtu)))
126 @@ -518,7 +527,7 @@ nf_flow_offload_ipv6_hook(void *priv, st
128 flow_offload_refresh(flow_table, flow);
130 - if (nf_flow_offload_dst_check(&rt->dst)) {
131 + if (nf_flow_offload_dst_check(tuplehash)) {
132 flow_offload_teardown(flow);
135 @@ -536,13 +545,16 @@ nf_flow_offload_ipv6_hook(void *priv, st
136 if (flow_table->flags & NF_FLOWTABLE_COUNTER)
137 nf_ct_acct_update(flow->ct, tuplehash->tuple.dir, skb->len);
139 - if (unlikely(dst_xfrm(&rt->dst))) {
140 + rt = (struct rt6_info *)tuplehash->tuple.dst_cache;
142 + if (unlikely(tuplehash->tuple.xmit_type == FLOW_OFFLOAD_XMIT_XFRM)) {
143 memset(skb->cb, 0, sizeof(struct inet6_skb_parm));
144 IP6CB(skb)->iif = skb->dev->ifindex;
145 IP6CB(skb)->flags = IP6SKB_FORWARDED;
146 return nf_flow_xmit_xfrm(skb, state, &rt->dst);
149 + outdev = rt->dst.dev;
151 nexthop = rt6_nexthop(rt, &flow->tuplehash[!dir].tuple.src_v6);
152 skb_dst_set_noref(skb, &rt->dst);
153 --- a/net/netfilter/nft_flow_offload.c
154 +++ b/net/netfilter/nft_flow_offload.c
155 @@ -19,6 +19,22 @@ struct nft_flow_offload {
156 struct nft_flowtable *flowtable;
159 +static enum flow_offload_xmit_type nft_xmit_type(struct dst_entry *dst)
162 + return FLOW_OFFLOAD_XMIT_XFRM;
164 + return FLOW_OFFLOAD_XMIT_NEIGH;
167 +static void nft_default_forward_path(struct nf_flow_route *route,
168 + struct dst_entry *dst_cache,
169 + enum ip_conntrack_dir dir)
171 + route->tuple[dir].dst = dst_cache;
172 + route->tuple[dir].xmit_type = nft_xmit_type(dst_cache);
175 static int nft_flow_route(const struct nft_pktinfo *pkt,
176 const struct nf_conn *ct,
177 struct nf_flow_route *route,
178 @@ -44,8 +60,8 @@ static int nft_flow_route(const struct n
182 - route->tuple[dir].dst = this_dst;
183 - route->tuple[!dir].dst = other_dst;
184 + nft_default_forward_path(route, this_dst, dir);
185 + nft_default_forward_path(route, other_dst, !dir);