Skip to contentSkip to conversation

ipv6: change route cache aging logic

PATCH In review Wei Wang 4 participants 5 messages Jan 26, 2018 – Jan 29, 2018

Subsystems (3)
lore
Share & tools
lore

Wei Wang

author
#0 lore raw

PATCH 1/1 ipv6: change route cache aging logic

From: Wei Wang <[email protected]>

In current route cache aging logic, if a route has both RTF_EXPIRE and RTF_GATEWAY set, the route will only be removed if the neighbor cache has no RTN_ROUTE flag. Otherwise, even if the route has expired, it won't get deleted.
Fix this logic to always check if the route has expired first and then do the gateway neighbor cache check if previous check decide to not remove the exception entry.

Fixes 1859bac04fb6 ("ipv6: remove from fib tree aged out RTF_CACHE dst")
---
 net/ipv6/route.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)
net/ipv6/route.c +12 -8
index 0458b761f3c5..a560fb1d0230 100644
@@ -1586,12 +1586,19 @@ static void rt6_age_examine_exception(struct rt6_exception_bucket *bucket,
 	 * EXPIRES exceptions - e.g. pmtu-generated ones are pruned when
 	 * expired, independently from their aging, as per RFC 8201 section 4
 	 */
-	if (!(rt->rt6i_flags & RTF_EXPIRES) &&
-	    time_after_eq(now, rt->dst.lastuse + gc_args->timeout)) {
-		RT6_TRACE("aging clone %p\n", rt);
+	if (!(rt->rt6i_flags & RTF_EXPIRES)) {
+		if (time_after_eq(now, rt->dst.lastuse + gc_args->timeout)) {
+			RT6_TRACE("aging clone %p\n", rt);
+			rt6_remove_exception(bucket, rt6_ex);
+			return;
+		}
+	} else if (time_after(jiffies, rt->dst.expires)) {
+		RT6_TRACE("purging expired route %p\n", rt);
 		rt6_remove_exception(bucket, rt6_ex);
 		return;
-	} else if (rt->rt6i_flags & RTF_GATEWAY) {
+	}
+
+	if (rt->rt6i_flags & RTF_GATEWAY) {
 		struct neighbour *neigh;
 		__u8 neigh_flags = 0;
 
@@ -1606,11 +1613,8 @@ static void rt6_age_examine_exception(struct rt6_exception_bucket *bucket,
 			rt6_remove_exception(bucket, rt6_ex);
 			return;
 		}
-	} else if (__rt6_check_expired(rt)) {
-		RT6_TRACE("purging expired route %p\n", rt);
-		rt6_remove_exception(bucket, rt6_ex);
-		return;
 	}
+
 	gc_args->more++;
 }
 
Signature · 1 line
2.16.0.rc1.238.g530d649a79-goog
Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · Wei Wang

From: Wei Wang <[email protected]>

In current route cache aging logic, if a route has both RTF_EXPIRE and RTF_GATEWAY set, the route will only be removed if the neighbor cache has no RTN_ROUTE flag. Otherwise, even if the route has expired, it

You meant NTF_ROUTER instead of RTN_ROUTE?

Quoted 8 lines

won't get deleted.
Fix this logic to always check if the route has expired first and then do the gateway neighbor cache check if previous check decide to not remove the exception entry.

Fixes 1859bac04fb6 ("ipv6: remove from fib tree aged out RTF_CACHE dst")

Nice catch!

Quoted 48 lines
---
 net/ipv6/route.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)
net/ipv6/route.c +12 -8
index 0458b761f3c5..a560fb1d0230 100644
@@ -1586,12 +1586,19 @@ static void rt6_age_examine_exception(struct rt6_exception_bucket *bucket,
 	 * EXPIRES exceptions - e.g. pmtu-generated ones are pruned when
 	 * expired, independently from their aging, as per RFC 8201 section 4
 	 */
-	if (!(rt->rt6i_flags & RTF_EXPIRES) &&
-	    time_after_eq(now, rt->dst.lastuse + gc_args->timeout)) {
-		RT6_TRACE("aging clone %p\n", rt);
+	if (!(rt->rt6i_flags & RTF_EXPIRES)) {
+		if (time_after_eq(now, rt->dst.lastuse + gc_args->timeout)) {
+			RT6_TRACE("aging clone %p\n", rt);
+			rt6_remove_exception(bucket, rt6_ex);
+			return;
+		}
+	} else if (time_after(jiffies, rt->dst.expires)) {
+		RT6_TRACE("purging expired route %p\n", rt);
 		rt6_remove_exception(bucket, rt6_ex);
 		return;
-	} else if (rt->rt6i_flags & RTF_GATEWAY) {
+	}
+
+	if (rt->rt6i_flags & RTF_GATEWAY) {
 		struct neighbour *neigh;
 		__u8 neigh_flags = 0;
 
@@ -1606,11 +1613,8 @@ static void rt6_age_examine_exception(struct rt6_exception_bucket *bucket,
 			rt6_remove_exception(bucket, rt6_ex);
 			return;
 		}
-	} else if (__rt6_check_expired(rt)) {
-		RT6_TRACE("purging expired route %p\n", rt);
-		rt6_remove_exception(bucket, rt6_ex);
-		return;
 	}
+
 	gc_args->more++;
 }
 
Signature · 1 line
2.16.0.rc1.238.g530d649a79-goog
author
#2 lore raw
Quoted 8 lines · Martin KaFai Lau
Quoted 5 lines · Wei Wang

From: Wei Wang <[email protected]>

In current route cache aging logic, if a route has both RTF_EXPIRE and RTF_GATEWAY set, the route will only be removed if the neighbor cache has no RTN_ROUTE flag. Otherwise, even if the route has expired, it

You meant NTF_ROUTER instead of RTN_ROUTE?

Yes. NTF_ROUTER flag. Sorry...

Quoted 60 lines
Quoted 8 lines

won't get deleted.
Fix this logic to always check if the route has expired first and then do the gateway neighbor cache check if previous check decide to not remove the exception entry.

Fixes 1859bac04fb6 ("ipv6: remove from fib tree aged out RTF_CACHE dst")

Nice catch!

Quoted 48 lines
---
 net/ipv6/route.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)
net/ipv6/route.c +12 -9
index 0458b761f3c5..a560fb1d0230 100644
@@ -1586,12 +1586,19 @@ static void rt6_age_examine_exception(struct rt6_exception_bucket *bucket,
       * EXPIRES exceptions - e.g. pmtu-generated ones are pruned when
       * expired, independently from their aging, as per RFC 8201 section 4
       */
-     if (!(rt->rt6i_flags & RTF_EXPIRES) &&
-         time_after_eq(now, rt->dst.lastuse + gc_args->timeout)) {
-             RT6_TRACE("aging clone %p\n", rt);
+     if (!(rt->rt6i_flags & RTF_EXPIRES)) {
+             if (time_after_eq(now, rt->dst.lastuse + gc_args->timeout)) {
+                     RT6_TRACE("aging clone %p\n", rt);
+                     rt6_remove_exception(bucket, rt6_ex);
+                     return;
+             }
+     } else if (time_after(jiffies, rt->dst.expires)) {
+             RT6_TRACE("purging expired route %p\n", rt);
              rt6_remove_exception(bucket, rt6_ex);
              return;
-     } else if (rt->rt6i_flags & RTF_GATEWAY) {
+     }
+
+     if (rt->rt6i_flags & RTF_GATEWAY) {
              struct neighbour *neigh;
              __u8 neigh_flags = 0;
 
@@ -1606,11 +1613,8 @@ static void rt6_age_examine_exception(struct rt6_exception_bucket *bucket,
                      rt6_remove_exception(bucket, rt6_ex);
                      return;
              }
-     } else if (__rt6_check_expired(rt)) {
-             RT6_TRACE("purging expired route %p\n", rt);
-             rt6_remove_exception(bucket, rt6_ex);
-             return;
      }
+
      gc_args->more++;
 }
 
--

2.16.0.rc1.238.g530d649a79-goog

maintainer Acked-by on v1 1/1
#3 lore raw
In reply to Wei Wang
Quoted 10 lines · Wei Wang

From: Wei Wang <[email protected]>

In current route cache aging logic, if a route has both RTF_EXPIRE and RTF_GATEWAY set, the route will only be removed if the neighbor cache has no RTN_ROUTE flag. Otherwise, even if the route has expired, it won't get deleted.
Fix this logic to always check if the route has expired first and then do the gateway neighbor cache check if previous check decide to not remove the exception entry.

Quoted 3 lines
Fixes 1859bac04fb6 ("ipv6: remove from fib tree aged out RTF_CACHE dst")

Thank you for the fix!

LGTM

Cheers,

/P

maintainer
#4 lore raw
In reply to Wei Wang

From: Wei Wang <[email protected]>
Date: Fri, 26 Jan 2018 11:40:17 -0800

Quoted 10 lines

From: Wei Wang <[email protected]>

In current route cache aging logic, if a route has both RTF_EXPIRE and RTF_GATEWAY set, the route will only be removed if the neighbor cache has no RTN_ROUTE flag. Otherwise, even if the route has expired, it won't get deleted.
Fix this logic to always check if the route has expired first and then do the gateway neighbor cache check if previous check decide to not remove the exception entry.

Quoted 3 lines
Fixes 1859bac04fb6 ("ipv6: remove from fib tree aged out RTF_CACHE dst")

Applied and queued up for -stable, thanks.