[PATCH] ipv4: Fix flushing of cached routing informations

Subsystems: networking [general], networking [ipv4/ipv6], the rest

STALE5115d

6 messages, 4 authors, 2012-10-18 · open the first message on its own page

[PATCH] ipv4: Fix flushing of cached routing informations

From: Steffen Klassert <steffen.klassert@secunet.com>
Date: 2012-10-18 05:27:33

Currently we can not flush cached pmtu/redirect informations via
the ipv4_sysctl_rtcache_flush sysctl. We need to check the rt_genid
of the old route and reset the nh exeption if the old route is
expired when we bind a new route to a nh exeption.

Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
---
 net/ipv4/route.c |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index 432f4bb..defb98d 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -1163,8 +1163,17 @@ static bool rt_bind_exception(struct rtable *rt, struct fib_nh_exception *fnhe,
 	spin_lock_bh(&fnhe_lock);
 
 	if (daddr == fnhe->fnhe_daddr) {
-		struct rtable *orig;
+		struct rtable *orig = rcu_dereference(fnhe->fnhe_rth);
+		rcu_assign_pointer(fnhe->fnhe_rth, rt);
 
+		if (orig) {
+			if (rt_is_expired(orig)) {
+				fnhe->fnhe_gw = 0;
+				fnhe->fnhe_pmtu = 0;
+				fnhe->fnhe_expires = 0;
+			}
+			rt_free(orig);
+		}
 		if (fnhe->fnhe_pmtu) {
 			unsigned long expires = fnhe->fnhe_expires;
 			unsigned long diff = expires - jiffies;
@@ -1181,11 +1190,6 @@ static bool rt_bind_exception(struct rtable *rt, struct fib_nh_exception *fnhe,
 		} else if (!rt->rt_gateway)
 			rt->rt_gateway = daddr;
 
-		orig = rcu_dereference(fnhe->fnhe_rth);
-		rcu_assign_pointer(fnhe->fnhe_rth, rt);
-		if (orig)
-			rt_free(orig);
-
 		fnhe->fnhe_stamp = jiffies;
 		ret = true;
 	}
-- 
1.7.0.4

Re: [PATCH] ipv4: Fix flushing of cached routing informations

From: Julian Anastasov <ja@ssi.bg>
Date: 2012-10-18 06:46:48

	Hello,

On Thu, 18 Oct 2012, Steffen Klassert wrote:
quoted hunk
Currently we can not flush cached pmtu/redirect informations via
the ipv4_sysctl_rtcache_flush sysctl. We need to check the rt_genid
of the old route and reset the nh exeption if the old route is
expired when we bind a new route to a nh exeption.

Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
---
 net/ipv4/route.c |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index 432f4bb..defb98d 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -1163,8 +1163,17 @@ static bool rt_bind_exception(struct rtable *rt, struct fib_nh_exception *fnhe,
 	spin_lock_bh(&fnhe_lock);
 
 	if (daddr == fnhe->fnhe_daddr) {
-		struct rtable *orig;
+		struct rtable *orig = rcu_dereference(fnhe->fnhe_rth);
+		rcu_assign_pointer(fnhe->fnhe_rth, rt);
	May be the above rcu_assign_pointer should be after

	... if (!rt->rt_gateway)
		rt->rt_gateway = daddr;

	part. It is possible another __mkroute_output
caller to get the cached fnhe->fnhe_rth without valid
rt->rt_gateway. rcu_assign_pointer should be after all
writes to rt.
quoted hunk
+		if (orig) {
+			if (rt_is_expired(orig)) {
+				fnhe->fnhe_gw = 0;
+				fnhe->fnhe_pmtu = 0;
+				fnhe->fnhe_expires = 0;
+			}
+			rt_free(orig);
+		}
 		if (fnhe->fnhe_pmtu) {
 			unsigned long expires = fnhe->fnhe_expires;
 			unsigned long diff = expires - jiffies;
@@ -1181,11 +1190,6 @@ static bool rt_bind_exception(struct rtable *rt, struct fib_nh_exception *fnhe,
 		} else if (!rt->rt_gateway)
 			rt->rt_gateway = daddr;
 
-		orig = rcu_dereference(fnhe->fnhe_rth);
-		rcu_assign_pointer(fnhe->fnhe_rth, rt);
-		if (orig)
-			rt_free(orig);
-
 		fnhe->fnhe_stamp = jiffies;
 		ret = true;
 	}
-- 
1.7.0.4
Regards

--
Julian Anastasov [off-list ref]

Re: [PATCH] ipv4: Fix flushing of cached routing informations

From: Steffen Klassert <steffen.klassert@secunet.com>
Date: 2012-10-18 06:54:31

On Thu, Oct 18, 2012 at 09:52:37AM +0300, Julian Anastasov wrote:
	Hello,

On Thu, 18 Oct 2012, Steffen Klassert wrote:
quoted
Currently we can not flush cached pmtu/redirect informations via
the ipv4_sysctl_rtcache_flush sysctl. We need to check the rt_genid
of the old route and reset the nh exeption if the old route is
expired when we bind a new route to a nh exeption.

Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
---
 net/ipv4/route.c |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index 432f4bb..defb98d 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -1163,8 +1163,17 @@ static bool rt_bind_exception(struct rtable *rt, struct fib_nh_exception *fnhe,
 	spin_lock_bh(&fnhe_lock);
 
 	if (daddr == fnhe->fnhe_daddr) {
-		struct rtable *orig;
+		struct rtable *orig = rcu_dereference(fnhe->fnhe_rth);
+		rcu_assign_pointer(fnhe->fnhe_rth, rt);
	May be the above rcu_assign_pointer should be after

	... if (!rt->rt_gateway)
		rt->rt_gateway = daddr;

	part. It is possible another __mkroute_output
caller to get the cached fnhe->fnhe_rth without valid
rt->rt_gateway. rcu_assign_pointer should be after all
writes to rt.
Right, I'll send an updated version.

Thanks!

[PATCH v2] ipv4: Fix flushing of cached routing informations

From: Steffen Klassert <steffen.klassert@secunet.com>
Date: 2012-10-18 07:17:51

Currently we can not flush cached pmtu/redirect informations via
the ipv4_sysctl_rtcache_flush sysctl. We need to check the rt_genid
of the old route and reset the nh exeption if the old route is
expired when we bind a new route to a nh exeption.

Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
---
 net/ipv4/route.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index 432f4bb..a8c6512 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -1163,8 +1163,12 @@ static bool rt_bind_exception(struct rtable *rt, struct fib_nh_exception *fnhe,
 	spin_lock_bh(&fnhe_lock);
 
 	if (daddr == fnhe->fnhe_daddr) {
-		struct rtable *orig;
-
+		struct rtable *orig = rcu_dereference(fnhe->fnhe_rth);
+		if (orig && rt_is_expired(orig)) {
+			fnhe->fnhe_gw = 0;
+			fnhe->fnhe_pmtu = 0;
+			fnhe->fnhe_expires = 0;
+		}
 		if (fnhe->fnhe_pmtu) {
 			unsigned long expires = fnhe->fnhe_expires;
 			unsigned long diff = expires - jiffies;
@@ -1181,7 +1185,6 @@ static bool rt_bind_exception(struct rtable *rt, struct fib_nh_exception *fnhe,
 		} else if (!rt->rt_gateway)
 			rt->rt_gateway = daddr;
 
-		orig = rcu_dereference(fnhe->fnhe_rth);
 		rcu_assign_pointer(fnhe->fnhe_rth, rt);
 		if (orig)
 			rt_free(orig);
-- 
1.7.0.4

Re: [PATCH v2] ipv4: Fix flushing of cached routing informations

From: Eric Dumazet <hidden>
Date: 2012-10-18 07:40:40

On Thu, 2012-10-18 at 09:17 +0200, Steffen Klassert wrote:
quoted hunk
Currently we can not flush cached pmtu/redirect informations via
the ipv4_sysctl_rtcache_flush sysctl. We need to check the rt_genid
of the old route and reset the nh exeption if the old route is
expired when we bind a new route to a nh exeption.

Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
---
 net/ipv4/route.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index 432f4bb..a8c6512 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -1163,8 +1163,12 @@ static bool rt_bind_exception(struct rtable *rt, struct fib_nh_exception *fnhe,
 	spin_lock_bh(&fnhe_lock);
 
 	if (daddr == fnhe->fnhe_daddr) {
-		struct rtable *orig;
-
+		struct rtable *orig = rcu_dereference(fnhe->fnhe_rth);
+		if (orig && rt_is_expired(orig)) {
+			fnhe->fnhe_gw = 0;
+			fnhe->fnhe_pmtu = 0;
+			fnhe->fnhe_expires = 0;
+		}
 		if (fnhe->fnhe_pmtu) {
 			unsigned long expires = fnhe->fnhe_expires;
 			unsigned long diff = expires - jiffies;
@@ -1181,7 +1185,6 @@ static bool rt_bind_exception(struct rtable *rt, struct fib_nh_exception *fnhe,
 		} else if (!rt->rt_gateway)
 			rt->rt_gateway = daddr;
 
-		orig = rcu_dereference(fnhe->fnhe_rth);
 		rcu_assign_pointer(fnhe->fnhe_rth, rt);
 		if (orig)
 			rt_free(orig);
Seems good to me. I'll have to rebase my patch, changing these
rcu_dereference() to rcu_dereference_protected() variant.

Acked-by: Eric Dumazet <redacted>

Re: [PATCH v2] ipv4: Fix flushing of cached routing informations

From: David Miller <davem@davemloft.net>
Date: 2012-10-18 19:35:59

From: Steffen Klassert <steffen.klassert@secunet.com>
Date: Thu, 18 Oct 2012 09:17:44 +0200
Currently we can not flush cached pmtu/redirect informations via
the ipv4_sysctl_rtcache_flush sysctl. We need to check the rt_genid
of the old route and reset the nh exeption if the old route is
expired when we bind a new route to a nh exeption.

Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
Applied and queued up for -stable, thanks.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help