Skip to contentSkip to conversation

ipv4: Fix flushing of cached routing informations

PATCH Superseded Steffen Klassert 4 participants 6 messages Oct 18, 2012

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ipv4: Fix flushing of cached routing informations

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.

---
 net/ipv4/route.c |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)
net/ipv4/route.c +10 -6
index 432f4bb..defb98d 100644
@@ -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;
 	}
Signature · 1 line
1.7.0.4
#1 lore raw

Hello,

Quoted 15 lines · Steffen Klassert

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.

---
 net/ipv4/route.c |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)
net/ipv4/route.c +0 -0
index 432f4bb..defb98d 100644

net/ipv4/route.c static bool rt_bind_exception(struct rtable *rt, struct fib_nh_exception *fnhe, · line 1167

Quoted 6 lines
net/ipv4/route.c +2 -1
@@ -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 25 lines
net/ipv4/route.c +8 -5
+		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;
 	}
Signature · 1 line
1.7.0.4

Regards

--
Julian Anastasov <[email protected]>

#2 lore raw
Quoted 33 lines · Julian Anastasov

Hello,

Quoted 15 lines · Steffen Klassert

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.

---
 net/ipv4/route.c |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)
net/ipv4/route.c +0 -0
index 432f4bb..defb98d 100644

net/ipv4/route.c static bool rt_bind_exception(struct rtable *rt, struct fib_nh_exception *fnhe, · line 1167

Quoted 6 lines
net/ipv4/route.c +2 -1
@@ -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
Quoted 3 lines

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!

#3 lore raw

PATCH v2 1/1 ipv4: Fix flushing of cached routing informations

In reply to Julian Anastasov

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.

---
 net/ipv4/route.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)
net/ipv4/route.c +6 -3
index 432f4bb..a8c6512 100644
@@ -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);
Signature · 1 line
1.7.0.4
Acked-by on v2 1/1
#4 lore raw
Quoted 30 lines · Steffen Klassert

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.

---
 net/ipv4/route.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)
net/ipv4/route.c +6 -2
index 432f4bb..a8c6512 100644
@@ -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;

net/ipv4/route.c static bool rt_bind_exception(struct rtable *rt, struct fib_nh_exception *fnhe, · line 1190

Quoted 7 lines
net/ipv4/route.c +0 -1
@@ -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.

maintainer
#5 lore raw
In reply to Steffen Klassert

From: Steffen Klassert <[email protected]>
Date: Thu, 18 Oct 2012 09:17:44 +0200

Quoted 6 lines

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.

Applied and queued up for -stable, thanks.