1 From: Felix Fietkau <nbd@nbd.name>
2 Date: Fri, 16 Feb 2018 10:57:23 +0100
3 Subject: [PATCH] netfilter: nf_flow_table: cache mtu in struct
6 Reduces the number of cache lines touched in the offload forwarding path
8 Signed-off-by: Felix Fietkau <nbd@nbd.name>
11 --- a/include/net/netfilter/nf_flow_table.h
12 +++ b/include/net/netfilter/nf_flow_table.h
13 @@ -55,6 +55,8 @@ struct flow_offload_tuple {
19 struct dst_entry *dst_cache;
22 --- a/net/ipv4/netfilter/nf_flow_table_ipv4.c
23 +++ b/net/ipv4/netfilter/nf_flow_table_ipv4.c
24 @@ -177,7 +177,7 @@ static int nf_flow_tuple_ip(struct sk_bu
27 /* Based on ip_exceeds_mtu(). */
28 -static bool __nf_flow_exceeds_mtu(const struct sk_buff *skb, unsigned int mtu)
29 +static bool nf_flow_exceeds_mtu(const struct sk_buff *skb, unsigned int mtu)
33 @@ -191,17 +191,6 @@ static bool __nf_flow_exceeds_mtu(const
37 -static bool nf_flow_exceeds_mtu(struct sk_buff *skb, const struct rtable *rt)
41 - mtu = ip_dst_mtu_maybe_forward(&rt->dst, true);
42 - if (__nf_flow_exceeds_mtu(skb, mtu))
49 nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb,
50 const struct nf_hook_state *state)
51 @@ -232,9 +221,9 @@ nf_flow_offload_ip_hook(void *priv, stru
53 dir = tuplehash->tuple.dir;
54 flow = container_of(tuplehash, struct flow_offload, tuplehash[dir]);
56 rt = (const struct rtable *)flow->tuplehash[dir].tuple.dst_cache;
57 - if (unlikely(nf_flow_exceeds_mtu(skb, rt)))
59 + if (unlikely(nf_flow_exceeds_mtu(skb, flow->tuplehash[dir].tuple.mtu)))
62 if (skb_try_make_writable(skb, sizeof(*iph)))
63 --- a/net/ipv6/netfilter/nf_flow_table_ipv6.c
64 +++ b/net/ipv6/netfilter/nf_flow_table_ipv6.c
65 @@ -173,7 +173,7 @@ static int nf_flow_tuple_ipv6(struct sk_
68 /* Based on ip_exceeds_mtu(). */
69 -static bool __nf_flow_exceeds_mtu(const struct sk_buff *skb, unsigned int mtu)
70 +static bool nf_flow_exceeds_mtu(const struct sk_buff *skb, unsigned int mtu)
74 @@ -184,17 +184,6 @@ static bool __nf_flow_exceeds_mtu(const
78 -static bool nf_flow_exceeds_mtu(struct sk_buff *skb, const struct rt6_info *rt)
82 - mtu = ip6_dst_mtu_forward(&rt->dst);
83 - if (__nf_flow_exceeds_mtu(skb, mtu))
90 nf_flow_offload_ipv6_hook(void *priv, struct sk_buff *skb,
91 const struct nf_hook_state *state)
92 @@ -225,9 +214,9 @@ nf_flow_offload_ipv6_hook(void *priv, st
94 dir = tuplehash->tuple.dir;
95 flow = container_of(tuplehash, struct flow_offload, tuplehash[dir]);
97 rt = (struct rt6_info *)flow->tuplehash[dir].tuple.dst_cache;
98 - if (unlikely(nf_flow_exceeds_mtu(skb, rt)))
100 + if (unlikely(nf_flow_exceeds_mtu(skb, flow->tuplehash[dir].tuple.mtu)))
103 if (skb_try_make_writable(skb, sizeof(*ip6h)))
104 --- a/net/netfilter/nf_flow_table.c
105 +++ b/net/netfilter/nf_flow_table.c
107 #include <linux/netfilter.h>
108 #include <linux/rhashtable.h>
109 #include <linux/netdevice.h>
111 +#include <net/ip6_route.h>
112 #include <net/netfilter/nf_tables.h>
113 #include <net/netfilter/nf_flow_table.h>
114 #include <net/netfilter/nf_conntrack.h>
115 @@ -23,6 +25,7 @@ flow_offload_fill_dir(struct flow_offloa
117 struct flow_offload_tuple *ft = &flow->tuplehash[dir].tuple;
118 struct nf_conntrack_tuple *ctt = &ct->tuplehash[dir].tuple;
119 + struct dst_entry *dst = route->tuple[dir].dst;
123 @@ -30,10 +33,12 @@ flow_offload_fill_dir(struct flow_offloa
125 ft->src_v4 = ctt->src.u3.in;
126 ft->dst_v4 = ctt->dst.u3.in;
127 + ft->mtu = ip_dst_mtu_maybe_forward(dst, true);
130 ft->src_v6 = ctt->src.u3.in6;
131 ft->dst_v6 = ctt->dst.u3.in6;
132 + ft->mtu = ip6_dst_mtu_forward(dst);
136 @@ -44,8 +49,7 @@ flow_offload_fill_dir(struct flow_offloa
138 ft->iifidx = route->tuple[dir].ifindex;
139 ft->oifidx = route->tuple[!dir].ifindex;
141 - ft->dst_cache = route->tuple[dir].dst;
142 + ft->dst_cache = dst;
145 struct flow_offload *