aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2013-05-27 16:46:33 -0400
committerDavid S. Miller <davem@davemloft.net>2013-06-03 03:07:43 -0400
commit5aad1de5ea2c260b4cd2f70b70e146d55dbbc528 (patch)
treedbf8d674fb49a125cf547dd73726c33677d2081c
parentf016229e303c294afac721de4cd4427e634950ea (diff)
ipv4: use separate genid for next hop exceptions
commit 13d82bf5 (ipv4: Fix flushing of cached routing informations) added the support to flush learned pmtu information. However, using rt_genid is quite heavy as it is bumped on route add/change and multicast events amongst other places. These can happen quite often, especially if using dynamic routing protocols. While this is ok with routes (as they are just recreated locally), the pmtu information is learned from remote systems and the icmp notification can come with long delays. It is worthy to have separate genid to avoid excessive pmtu resets. Cc: Steffen Klassert <steffen.klassert@secunet.com> Signed-off-by: Timo Teräs <timo.teras@iki.fi> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--include/net/ip_fib.h1
-rw-r--r--include/net/net_namespace.h11
-rw-r--r--net/ipv4/route.c12
3 files changed, 22 insertions, 2 deletions
diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
index e49db91593a9..44424e9dab2a 100644
--- a/include/net/ip_fib.h
+++ b/include/net/ip_fib.h
@@ -51,6 +51,7 @@ struct rtable;
51 51
52struct fib_nh_exception { 52struct fib_nh_exception {
53 struct fib_nh_exception __rcu *fnhe_next; 53 struct fib_nh_exception __rcu *fnhe_next;
54 int fnhe_genid;
54 __be32 fnhe_daddr; 55 __be32 fnhe_daddr;
55 u32 fnhe_pmtu; 56 u32 fnhe_pmtu;
56 __be32 fnhe_gw; 57 __be32 fnhe_gw;
diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
index b17697827482..495bc57f292c 100644
--- a/include/net/net_namespace.h
+++ b/include/net/net_namespace.h
@@ -118,6 +118,7 @@ struct net {
118 struct netns_ipvs *ipvs; 118 struct netns_ipvs *ipvs;
119 struct sock *diag_nlsk; 119 struct sock *diag_nlsk;
120 atomic_t rt_genid; 120 atomic_t rt_genid;
121 atomic_t fnhe_genid;
121}; 122};
122 123
123/* 124/*
@@ -340,4 +341,14 @@ static inline void rt_genid_bump(struct net *net)
340 atomic_inc(&net->rt_genid); 341 atomic_inc(&net->rt_genid);
341} 342}
342 343
344static inline int fnhe_genid(struct net *net)
345{
346 return atomic_read(&net->fnhe_genid);
347}
348
349static inline void fnhe_genid_bump(struct net *net)
350{
351 atomic_inc(&net->fnhe_genid);
352}
353
343#endif /* __NET_NET_NAMESPACE_H */ 354#endif /* __NET_NET_NAMESPACE_H */
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index a4082be1b9b4..403e28302869 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -658,6 +658,7 @@ static void update_or_create_fnhe(struct fib_nh *nh, __be32 daddr, __be32 gw,
658 fnhe->fnhe_next = hash->chain; 658 fnhe->fnhe_next = hash->chain;
659 rcu_assign_pointer(hash->chain, fnhe); 659 rcu_assign_pointer(hash->chain, fnhe);
660 } 660 }
661 fnhe->fnhe_genid = fnhe_genid(dev_net(nh->nh_dev));
661 fnhe->fnhe_daddr = daddr; 662 fnhe->fnhe_daddr = daddr;
662 fnhe->fnhe_gw = gw; 663 fnhe->fnhe_gw = gw;
663 fnhe->fnhe_pmtu = pmtu; 664 fnhe->fnhe_pmtu = pmtu;
@@ -1236,8 +1237,11 @@ static bool rt_bind_exception(struct rtable *rt, struct fib_nh_exception *fnhe,
1236 spin_lock_bh(&fnhe_lock); 1237 spin_lock_bh(&fnhe_lock);
1237 1238
1238 if (daddr == fnhe->fnhe_daddr) { 1239 if (daddr == fnhe->fnhe_daddr) {
1240 int genid = fnhe_genid(dev_net(rt->dst.dev));
1239 struct rtable *orig = rcu_dereference(fnhe->fnhe_rth); 1241 struct rtable *orig = rcu_dereference(fnhe->fnhe_rth);
1240 if (orig && rt_is_expired(orig)) { 1242
1243 if (fnhe->fnhe_genid != genid) {
1244 fnhe->fnhe_genid = genid;
1241 fnhe->fnhe_gw = 0; 1245 fnhe->fnhe_gw = 0;
1242 fnhe->fnhe_pmtu = 0; 1246 fnhe->fnhe_pmtu = 0;
1243 fnhe->fnhe_expires = 0; 1247 fnhe->fnhe_expires = 0;
@@ -2443,8 +2447,11 @@ static int ipv4_sysctl_rtcache_flush(ctl_table *__ctl, int write,
2443 void __user *buffer, 2447 void __user *buffer,
2444 size_t *lenp, loff_t *ppos) 2448 size_t *lenp, loff_t *ppos)
2445{ 2449{
2450 struct net *net = (struct net *)__ctl->extra1;
2451
2446 if (write) { 2452 if (write) {
2447 rt_cache_flush((struct net *)__ctl->extra1); 2453 rt_cache_flush(net);
2454 fnhe_genid_bump(net);
2448 return 0; 2455 return 0;
2449 } 2456 }
2450 2457
@@ -2619,6 +2626,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
2619static __net_init int rt_genid_init(struct net *net) 2626static __net_init int rt_genid_init(struct net *net)
2620{ 2627{
2621 atomic_set(&net->rt_genid, 0); 2628 atomic_set(&net->rt_genid, 0);
2629 atomic_set(&net->fnhe_genid, 0);
2622 get_random_bytes(&net->ipv4.dev_addr_genid, 2630 get_random_bytes(&net->ipv4.dev_addr_genid,
2623 sizeof(net->ipv4.dev_addr_genid)); 2631 sizeof(net->ipv4.dev_addr_genid));
2624 return 0; 2632 return 0;