Skip to content

Commit 705f1c8

Browse files
strssndktndavem330
authored andcommitted
ipv6: remove rt6i_genid
Eric Dumazet noticed that all no-nonexthop or no-gateway routes which are already marked DST_HOST (e.g. input routes routes) will always be invalidated during sk_dst_check. Thus per-socket dst caching absolutely had no effect and early demuxing had no effect. Thus this patch removes rt6i_genid: fn_sernum already gets modified during add operations, so we only must ensure we mutate fn_sernum during ipv6 address remove operations. This is a fairly cost extensive operations, but address removal should not happen that often. Also our mtu update functions do the same and we heard no complains so far. xfrm policy changes also cause a call into fib6_flush_trees. Also plug a hole in rt6_info (no cacheline changes). I verified via tracing that this change has effect. Cc: Eric Dumazet <eric.dumazet@gmail.com> Cc: YOSHIFUJI Hideaki <hideaki@yoshifuji.org> Cc: Vlad Yasevich <vyasevich@gmail.com> Cc: Nicolas Dichtel <nicolas.dichtel@6wind.com> Cc: Martin Lau <kafai@fb.com> Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent dedb845 commit 705f1c8

6 files changed

Lines changed: 33 additions & 26 deletions

File tree

‎include/net/ip6_fib.h‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,13 @@ struct rt6_info {
114114
u32 rt6i_flags;
115115
struct rt6key rt6i_src;
116116
struct rt6key rt6i_prefsrc;
117-
u32 rt6i_metric;
118117

119118
struct inet6_dev *rt6i_idev;
120119
unsigned long _rt6i_peer;
121120

122-
u32 rt6i_genid;
123-
121+
u32 rt6i_metric;
124122
/* more non-fragment space at head required */
125123
unsigned short rt6i_nfheader_len;
126-
127124
u8 rt6i_protocol;
128125
};
129126

‎include/net/net_namespace.h‎

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -352,26 +352,12 @@ static inline void rt_genid_bump_ipv4(struct net *net)
352352
atomic_inc(&net->ipv4.rt_genid);
353353
}
354354

355-
#if IS_ENABLED(CONFIG_IPV6)
356-
static inline int rt_genid_ipv6(struct net *net)
357-
{
358-
return atomic_read(&net->ipv6.rt_genid);
359-
}
360-
361-
static inline void rt_genid_bump_ipv6(struct net *net)
362-
{
363-
atomic_inc(&net->ipv6.rt_genid);
364-
}
365-
#else
366-
static inline int rt_genid_ipv6(struct net *net)
367-
{
368-
return 0;
369-
}
370-
355+
extern void (*__fib6_flush_trees)(struct net *net);
371356
static inline void rt_genid_bump_ipv6(struct net *net)
372357
{
358+
if (__fib6_flush_trees)
359+
__fib6_flush_trees(net);
373360
}
374-
#endif
375361

376362
#if IS_ENABLED(CONFIG_IEEE802154_6LOWPAN)
377363
static inline struct netns_ieee802154_lowpan *

‎net/ipv6/addrconf.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4780,10 +4780,11 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
47804780

47814781
if (ip6_del_rt(ifp->rt))
47824782
dst_free(&ifp->rt->dst);
4783+
4784+
rt_genid_bump_ipv6(net);
47834785
break;
47844786
}
47854787
atomic_inc(&net->ipv6.dev_addr_genid);
4786-
rt_genid_bump_ipv6(net);
47874788
}
47884789

47894790
static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)

‎net/ipv6/addrconf_core.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88
#include <net/addrconf.h>
99
#include <net/ip.h>
1010

11+
/* if ipv6 module registers this function is used by xfrm to force all
12+
* sockets to relookup their nodes - this is fairly expensive, be
13+
* careful
14+
*/
15+
void (*__fib6_flush_trees)(struct net *);
16+
EXPORT_SYMBOL(__fib6_flush_trees);
17+
1118
#define IPV6_ADDR_SCOPE_TYPE(scope) ((scope) << 16)
1219

1320
static inline unsigned int ipv6_addr_scope2type(unsigned int scope)

‎net/ipv6/ip6_fib.c‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,6 +1605,24 @@ static void fib6_prune_clones(struct net *net, struct fib6_node *fn)
16051605
fib6_clean_tree(net, fn, fib6_prune_clone, 1, NULL);
16061606
}
16071607

1608+
static int fib6_update_sernum(struct rt6_info *rt, void *arg)
1609+
{
1610+
__u32 sernum = *(__u32 *)arg;
1611+
1612+
if (rt->rt6i_node &&
1613+
rt->rt6i_node->fn_sernum != sernum)
1614+
rt->rt6i_node->fn_sernum = sernum;
1615+
1616+
return 0;
1617+
}
1618+
1619+
static void fib6_flush_trees(struct net *net)
1620+
{
1621+
__u32 new_sernum = fib6_new_sernum();
1622+
1623+
fib6_clean_all(net, fib6_update_sernum, &new_sernum);
1624+
}
1625+
16081626
/*
16091627
* Garbage collection
16101628
*/
@@ -1788,6 +1806,8 @@ int __init fib6_init(void)
17881806
NULL);
17891807
if (ret)
17901808
goto out_unregister_subsys;
1809+
1810+
__fib6_flush_trees = fib6_flush_trees;
17911811
out:
17921812
return ret;
17931813

‎net/ipv6/route.c‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,6 @@ static inline struct rt6_info *ip6_dst_alloc(struct net *net,
314314

315315
memset(dst + 1, 0, sizeof(*rt) - sizeof(*dst));
316316
rt6_init_peer(rt, table ? &table->tb6_peers : net->ipv6.peers);
317-
rt->rt6i_genid = rt_genid_ipv6(net);
318317
INIT_LIST_HEAD(&rt->rt6i_siblings);
319318
}
320319
return rt;
@@ -1098,9 +1097,6 @@ static struct dst_entry *ip6_dst_check(struct dst_entry *dst, u32 cookie)
10981097
* DST_OBSOLETE_FORCE_CHK which forces validation calls down
10991098
* into this function always.
11001099
*/
1101-
if (rt->rt6i_genid != rt_genid_ipv6(dev_net(rt->dst.dev)))
1102-
return NULL;
1103-
11041100
if (!rt->rt6i_node || (rt->rt6i_node->fn_sernum != cookie))
11051101
return NULL;
11061102

0 commit comments

Comments
 (0)