Skip to contentSkip to conversation

Remove expired routes with a separated list of routes.

PATCH Applied [email protected] 4 participants 9 messages Feb 8, 2024 – Feb 23, 2024

Subsystems (4)

v6 of 8 Applied 5/5 Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v6 cover Remove expired routes with a separated list of routes.

From: Kui-Feng Lee <[email protected]>

This patchset is resent due to previous reverting. [1]

FIB6 GC walks trees of fib6_tables to remove expired routes. Walking a tree can be expensive if the number of routes in a table is big, even if most of them are permanent. Checking routes in a separated list of routes having expiration will avoid this potential issue.

Background
==========

The size of a Linux IPv6 routing table can become a big problem if not managed appropriately. Now, Linux has a garbage collector to remove expired routes periodically. However, this may lead to a situation in which the routing path is blocked for a long period due to an excessive number of routes.

For example, years ago, there is a commit c7bb4b89033b ("ipv6: tcp:
drop silly ICMPv6 packet too big messages"). The root cause is that malicious ICMPv6 packets were sent back for every small packet sent to them. These packets add routes with an expiration time that prompts the GC to periodically check all routes in the tables, including permanent ones.

Why Route Expires
=================

Users can add IPv6 routes with an expiration time manually. However, the Neighbor Discovery protocol may also generate routes that can expire. For example, Router Advertisement (RA) messages may create a default route with an expiration time. [RFC 4861] For IPv4, it is not possible to set an expiration time for a route, and there is no RA, so there is no need to worry about such issues.

Create Routes with Expires
==========================

You can create routes with expires with the command.

For example,

ip -6 route add 2001:b000:591::3 via fe80::5054:ff:fe12:3457 \
dev enp0s3 expires 30

The route that has been generated will be deleted automatically in 30 seconds.

GC of FIB6
==========

The function called fib6_run_gc() is responsible for performing garbage collection (GC) for the Linux IPv6 stack. It checks for the expiration of every route by traversing the trees of routing tables. The time taken to traverse a routing table increases with its size. Holding the routing table lock during traversal is particularly undesirable. Therefore, it is preferable to keep the lock for the shortest possible duration.

Solution
========

The cause of the issue is keeping the routing table locked during the traversal of large trees. To solve this problem, we can create a separate list of routes that have expiration. This will prevent GC from checking permanent routes.

Result
======

We conducted a test to measure the execution times of fib6_gc_timer_cb() and observed that it enhances the GC of FIB6. During the test, we added permanent routes with the following numbers: 1000, 3000, 6000, and 9000. Additionally, we added a route with an expiration time.

Here are the average execution times for the kernel without the patch.
- 120020 ns with 1000 permanent routes
- 308920 ns with 3000 ...
- 581470 ns with 6000 ...
- 855310 ns with 9000 ...

The kernel with the patch consistently takes around 14000 ns to execute, regardless of the number of permanent routes that are installed.

Majro changes from v5:

- Force syncrhonize GC before query expired routes with "sysctl -wq net.ipv6.route.flush=1".

Major changes from v4:

- Fix the comment of fib6_add_gc_list().

Major changes from v3:

- Move the checks of f6i->fib6_node to fib6_add_gc_list().

- Make spin_lock_bh() and spin_unlock_bh() stands out.

- Explain the reason of the changes in the commit message of the patch 4.

Major changes from v2:

- Refactory the boilerplate checks in the test case.

- check_rt_num() and check_rt_num_clean()

Major changes from v1:

- Reduce the numbers of routes (5) in the test cases to work with slow environments. Due to the failure on patchwork.

- Remove systemd related commands in the test case.

Major changes from the previous patchset [2]:

- Split helpers.

- fib6_set_expires() -> fib6_set_expires() and fib6_add_gc_list().

- fib6_clean_expires() -> fib6_clean_expires() and

     fib6_remove_gc_list().

- Fix rt6_add_dflt_router() to avoid racing of setting expires.

- Remove unnecessary calling to fib6_clean_expires() in ip6_route_info_create().

- Add test cases of toggling routes between permanent and temporary and handling routes from RA messages.

- Clean up routes by deleting the existing device and adding a new one.

- Fix a potential issue in modify_prefix_route().

---
[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/
v2: https://lore.kernel.org/all/[email protected]/
v3: https://lore.kernel.org/all/[email protected]/
v4: https://lore.kernel.org/all/[email protected]/
v5: https://lore.kernel.org/all/[email protected]/

Kui-Feng Lee (5):
net/ipv6: set expires in rt6_add_dflt_router().
net/ipv6: Remove unnecessary clean.
net/ipv6: Remove expired routes with a separated list of routes. net/ipv6: set expires in modify_prefix_route() if RTF_EXPIRES is set. selftests/net: Adding test cases of replacing routes and route
advertisements.

 include/net/ip6_fib.h                    |  46 ++++++-
 include/net/ip6_route.h                  |   3 +-
 net/ipv6/addrconf.c                      |  41 ++++--
 net/ipv6/ip6_fib.c                       |  60 ++++++++-
 net/ipv6/ndisc.c                         |  13 +-
 net/ipv6/route.c                         |  19 ++-
 tools/testing/selftests/net/fib_tests.sh | 151 +++++++++++++++++++----
 7 files changed, 290 insertions(+), 43 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v6 1/5 net/ipv6: set expires in rt6_add_dflt_router().

From: Kui-Feng Lee <[email protected]>

Pass the duration of a lifetime (in seconds) to the function rt6_add_dflt_router() so that it can properly set the expiration time.

The function ndisc_router_discovery() is the only one that calls rt6_add_dflt_router(), and it will later set the expiration time for the route created by rt6_add_dflt_router(). However, there is a gap of time between calling rt6_add_dflt_router() and setting the expiration time in ndisc_router_discovery(). During this period, there is a possibility that a new route may be removed from the routing table. By setting the correct expiration time in rt6_add_dflt_router(), we can prevent this from happening. The reason for setting RTF_EXPIRES in rt6_add_dflt_router() is to start the Garbage Collection (GC) timer, as it only activates when a route with RTF_EXPIRES is added to a table.

---
 include/net/ip6_route.h | 3 ++-
 net/ipv6/ndisc.c        | 3 ++-
 net/ipv6/route.c        | 4 +++-
 3 files changed, 7 insertions(+), 3 deletions(-)
include/net/ip6_route.h +2 -1
index 28b065790261..52a51c69aa9d 100644
@@ -170,7 +170,8 @@ struct fib6_info *rt6_get_dflt_router(struct net *net,
 struct fib6_info *rt6_add_dflt_router(struct net *net,
 				     const struct in6_addr *gwaddr,
 				     struct net_device *dev, unsigned int pref,
-				     u32 defrtr_usr_metric);
+				     u32 defrtr_usr_metric,
+				     int lifetime);
 
 void rt6_purge_dflt_routers(struct net *net);
 
net/ipv6/ndisc.c +2 -1
index a19999b30bc0..a68462668158 100644
@@ -1382,7 +1382,8 @@ static enum skb_drop_reason ndisc_router_discovery(struct sk_buff *skb)
 			neigh_release(neigh);
 
 		rt = rt6_add_dflt_router(net, &ipv6_hdr(skb)->saddr,
-					 skb->dev, pref, defrtr_usr_metric);
+					 skb->dev, pref, defrtr_usr_metric,
+					 lifetime);
 		if (!rt) {
 			ND_PRINTK(0, err,
 				  "RA: %s failed to add default route\n",
net/ipv6/route.c +3 -1
index 63b4c6056582..98abba8f15cd 100644
@@ -4355,7 +4355,8 @@ struct fib6_info *rt6_add_dflt_router(struct net *net,
 				     const struct in6_addr *gwaddr,
 				     struct net_device *dev,
 				     unsigned int pref,
-				     u32 defrtr_usr_metric)
+				     u32 defrtr_usr_metric,
+				     int lifetime)
 {
 	struct fib6_config cfg = {
 		.fc_table	= l3mdev_fib_table(dev) ? : RT6_TABLE_DFLT,
@@ -4368,6 +4369,7 @@ struct fib6_info *rt6_add_dflt_router(struct net *net,
 		.fc_nlinfo.portid = 0,
 		.fc_nlinfo.nlh = NULL,
 		.fc_nlinfo.nl_net = net,
+		.fc_expires = jiffies_to_clock_t(lifetime * HZ),
 	};
 
 	cfg.fc_gateway = *gwaddr;
Signature · 1 line
2.34.1
#2 lore raw

PATCH v6 2/5 net/ipv6: Remove unnecessary clean.

In reply to [email protected]

From: Kui-Feng Lee <[email protected]>

The route here is newly created. It is unnecessary to call fib6_clean_expires() on it.

---
 net/ipv6/route.c | 2 --
 1 file changed, 2 deletions(-)
net/ipv6/route.c +0 -2
index 98abba8f15cd..dd6ff5b20918 100644
@@ -3765,8 +3765,6 @@ static struct fib6_info *ip6_route_info_create(struct fib6_config *cfg,
 	if (cfg->fc_flags & RTF_EXPIRES)
 		fib6_set_expires(rt, jiffies +
 				clock_t_to_jiffies(cfg->fc_expires));
-	else
-		fib6_clean_expires(rt);
 
 	if (cfg->fc_protocol == RTPROT_UNSPEC)
 		cfg->fc_protocol = RTPROT_BOOT;
Signature · 1 line
2.34.1
#3 lore raw

PATCH v6 3/5 net/ipv6: Remove expired routes with a separated list of routes.

In reply to [email protected]

From: Kui-Feng Lee <[email protected]>

FIB6 GC walks trees of fib6_tables to remove expired routes. Walking a tree can be expensive if the number of routes in a table is big, even if most of them are permanent. Checking routes in a separated list of routes having expiration will avoid this potential issue.

---
 include/net/ip6_fib.h | 46 ++++++++++++++++++++++++++++++++-
 net/ipv6/addrconf.c   | 41 ++++++++++++++++++++++++-----
 net/ipv6/ip6_fib.c    | 60 +++++++++++++++++++++++++++++++++++++++----
 net/ipv6/ndisc.c      | 10 +++++++-
 net/ipv6/route.c      | 13 ++++++++--
 5 files changed, 154 insertions(+), 16 deletions(-)
include/net/ip6_fib.h +45 -1
index 360b12e61850..323c94f1845b 100644
@@ -173,6 +173,9 @@ struct fib6_info {
 
 	refcount_t			fib6_ref;
 	unsigned long			expires;
+
+	struct hlist_node		gc_link;
+
 	struct dst_metrics		*fib6_metrics;
 #define fib6_pmtu		fib6_metrics->metrics[RTAX_MTU-1]
 
@@ -241,12 +244,18 @@ static inline bool fib6_requires_src(const struct fib6_info *rt)
 	return rt->fib6_src.plen > 0;
 }
 
+/* The callers should hold f6i->fib6_table->tb6_lock if a route has ever
+ * been added to a table before.
+ */
 static inline void fib6_clean_expires(struct fib6_info *f6i)
 {
 	f6i->fib6_flags &= ~RTF_EXPIRES;
 	f6i->expires = 0;
 }
 
+/* The callers should hold f6i->fib6_table->tb6_lock if a route has ever
+ * been added to a table before.
+ */
 static inline void fib6_set_expires(struct fib6_info *f6i,
 				    unsigned long expires)
 {
@@ -327,8 +336,10 @@ static inline bool fib6_info_hold_safe(struct fib6_info *f6i)
 
 static inline void fib6_info_release(struct fib6_info *f6i)
 {
-	if (f6i && refcount_dec_and_test(&f6i->fib6_ref))
+	if (f6i && refcount_dec_and_test(&f6i->fib6_ref)) {
+		DEBUG_NET_WARN_ON_ONCE(!hlist_unhashed(&f6i->gc_link));
 		call_rcu(&f6i->rcu, fib6_info_destroy_rcu);
+	}
 }
 
 enum fib6_walk_state {
@@ -382,6 +393,7 @@ struct fib6_table {
 	struct inet_peer_base	tb6_peers;
 	unsigned int		flags;
 	unsigned int		fib_seq;
+	struct hlist_head       tb6_gc_hlist;	/* GC candidates */
 #define RT6_TABLE_HAS_DFLT_ROUTER	BIT(0)
 };
 
@@ -498,6 +510,38 @@ void fib6_gc_cleanup(void);
 
 int fib6_init(void);
 
+/* Add the route to the gc list if it is not already there
+ *
+ * The callers should hold f6i->fib6_table->tb6_lock.
+ */
+static inline void fib6_add_gc_list(struct fib6_info *f6i)
+{
+	/* If fib6_node is null, the f6i is not in (or removed from) the
+	 * table.
+	 *
+	 * There is a gap between finding the f6i from the table and
+	 * calling this function without the protection of the tb6_lock.
+	 * This check makes sure the f6i is not added to the gc list when
+	 * it is not on the table.
+	 */
+	if (!rcu_dereference_protected(f6i->fib6_node,
+				       lockdep_is_held(&f6i->fib6_table->tb6_lock)))
+		return;
+
+	if (hlist_unhashed(&f6i->gc_link))
+		hlist_add_head(&f6i->gc_link, &f6i->fib6_table->tb6_gc_hlist);
+}
+
+/* Remove the route from the gc list if it is on the list.
+ *
+ * The callers should hold f6i->fib6_table->tb6_lock.
+ */
+static inline void fib6_remove_gc_list(struct fib6_info *f6i)
+{
+	if (!hlist_unhashed(&f6i->gc_link))
+		hlist_del_init(&f6i->gc_link);
+}
+
 struct ipv6_route_iter {
 	struct seq_net_private p;
 	struct fib6_walker w;
net/ipv6/addrconf.c +34 -7

81 lines not on this page · raw message

net/ipv6/ip6_fib.c +55 -5

123 lines not on this page · raw message

net/ipv6/ndisc.c +9 -1
index a68462668158..73cb31afe935 100644
@@ -1237,6 +1237,7 @@ static enum skb_drop_reason ndisc_router_discovery(struct sk_buff *skb)
 	struct ndisc_options ndopts;
 	struct fib6_info *rt = NULL;
 	struct inet6_dev *in6_dev;
+	struct fib6_table *table;
 	u32 defrtr_usr_metric;
 	unsigned int pref = 0;
 	__u32 old_if_flags;
@@ -1410,8 +1411,15 @@ static enum skb_drop_reason ndisc_router_discovery(struct sk_buff *skb)
 		inet6_rt_notify(RTM_NEWROUTE, rt, &nlinfo, NLM_F_REPLACE);
 	}
 
-	if (rt)
+	if (rt) {
+		table = rt->fib6_table;
+		spin_lock_bh(&table->tb6_lock);
+
 		fib6_set_expires(rt, jiffies + (HZ * lifetime));
+		fib6_add_gc_list(rt);
+
+		spin_unlock_bh(&table->tb6_lock);
+	}
 	if (in6_dev->cnf.accept_ra_min_hop_limit < 256 &&
 	    ra_msg->icmph.icmp6_hop_limit) {
 		if (in6_dev->cnf.accept_ra_min_hop_limit <= ra_msg->icmph.icmp6_hop_limit) {
net/ipv6/route.c +11 -2
index dd6ff5b20918..707d65bc9c0e 100644
@@ -931,6 +931,7 @@ int rt6_route_rcv(struct net_device *dev, u8 *opt, int len,
 	struct net *net = dev_net(dev);
 	struct route_info *rinfo = (struct route_info *) opt;
 	struct in6_addr prefix_buf, *prefix;
+	struct fib6_table *table;
 	unsigned int pref;
 	unsigned long lifetime;
 	struct fib6_info *rt;
@@ -989,10 +990,18 @@ int rt6_route_rcv(struct net_device *dev, u8 *opt, int len,
 				 (rt->fib6_flags & ~RTF_PREF_MASK) | RTF_PREF(pref);
 
 	if (rt) {
-		if (!addrconf_finite_timeout(lifetime))
+		table = rt->fib6_table;
+		spin_lock_bh(&table->tb6_lock);
+
+		if (!addrconf_finite_timeout(lifetime)) {
 			fib6_clean_expires(rt);
-		else
+			fib6_remove_gc_list(rt);
+		} else {
 			fib6_set_expires(rt, jiffies + HZ * lifetime);
+			fib6_add_gc_list(rt);
+		}
+
+		spin_unlock_bh(&table->tb6_lock);
 
 		fib6_info_release(rt);
 	}
Signature · 1 line
2.34.1
#4 lore raw

PATCH v6 4/5 net/ipv6: set expires in modify_prefix_route() if RTF_EXPIRES is set.

In reply to [email protected]

From: Kui-Feng Lee <[email protected]>

Make the decision to set or clean the expires of a route based on the RTF_EXPIRES flag, rather than the value of the "expires" argument.

This patch doesn't make difference logically, but make inet6_addr_modify() and modify_prefix_route() consistent.

The function inet6_addr_modify() is the only caller of modify_prefix_route(), and it passes the RTF_EXPIRES flag and an expiration value. The RTF_EXPIRES flag is turned on or off based on the value of valid_lft. The RTF_EXPIRES flag is turned on if valid_lft is a finite value (not infinite, not 0xffffffff). Even if valid_lft is 0, the RTF_EXPIRES flag remains on. The expiration value being passed is equal to the valid_lft value if the flag is on. However, if the valid_lft value is infinite, the expiration value becomes 0 and the RTF_EXPIRES flag is turned off. Despite this, modify_prefix_route() decides to set the expiration value if the received expiration value is not zero. This mixing of infinite and zero cases creates an inconsistency.

---
 net/ipv6/addrconf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv6/addrconf.c +1 -1
index 0ea44563454f..ca1b719323c0 100644
@@ -4783,7 +4783,7 @@ static int modify_prefix_route(struct inet6_ifaddr *ifp,
 		table = f6i->fib6_table;
 		spin_lock_bh(&table->tb6_lock);
 
-		if (!expires) {
+		if (!(flags & RTF_EXPIRES)) {
 			fib6_clean_expires(f6i);
 			fib6_remove_gc_list(f6i);
 		} else {
Signature · 1 line
2.34.1
#5 lore raw

PATCH v6 5/5 selftests/net: Adding test cases of replacing routes and route advertisements.

In reply to [email protected]

From: Kui-Feng Lee <[email protected]>

Add tests of changing permanent routes to temporary routes and the reversed case to make sure GC working correctly in these cases. Add tests for the temporary routes from RA.

The existing device will be deleted between tests to remove all routes associated with it, so that the earlier tests don't mess up the later ones.

---
 tools/testing/selftests/net/fib_tests.sh | 151 +++++++++++++++++++----
 1 file changed, 129 insertions(+), 22 deletions(-)
tools/testing/selftests/net/fib_tests.sh +129 -22
index b3ecccbbfcd2..3ec1050e47a2 100755
@@ -743,6 +743,43 @@ fib_notify_test()
 	cleanup &> /dev/null
 }
 
+# Create a new dummy_10 to remove all associated routes.
+reset_dummy_10()
+{
+	$IP link del dev dummy_10
+
+	$IP link add dummy_10 type dummy
+	$IP link set dev dummy_10 up
+	$IP -6 address add 2001:10::1/64 dev dummy_10
+}
+
+check_rt_num()
+{
+    local expected=$1
+    local num=$2
+
+    if [ $num -ne $expected ]; then
+	echo "FAIL: Expected $expected routes, got $num"
+	ret=1
+    else
+	ret=0
+    fi
+}
+
+check_rt_num_clean()
+{
+    local expected=$1
+    local num=$2
+
+    if [ $num -ne $expected ]; then
+	log_test 1 0 "expected $expected routes, got $num"
+	set +e
+	cleanup &> /dev/null
+	return 1
+    fi
+    return 0
+}
+
 fib6_gc_test()
 {
 	setup
@@ -751,7 +788,7 @@ fib6_gc_test()
 	echo "Fib6 garbage collection test"
 	set -e
 
-	EXPIRE=3
+	EXPIRE=5
 
 	# Check expiration of routes every $EXPIRE seconds (GC)
 	$NS_EXEC sysctl -wq net.ipv6.route.gc_interval=$EXPIRE
@@ -763,44 +800,114 @@ fib6_gc_test()
 	$NS_EXEC sysctl -wq net.ipv6.route.flush=1
 
 	# Temporary routes
-	for i in $(seq 1 1000); do
+	for i in $(seq 1 5); do
 	    # Expire route after $EXPIRE seconds
 	    $IP -6 route add 2001:20::$i \
 		via 2001:10::2 dev dummy_10 expires $EXPIRE
 	done
-	sleep $(($EXPIRE * 2))
-	N_EXP_SLEEP=$($IP -6 route list |grep expires|wc -l)
-	if [ $N_EXP_SLEEP -ne 0 ]; then
-	    echo "FAIL: expected 0 routes with expires, got $N_EXP_SLEEP"
-	    ret=1
-	else
-	    ret=0
-	fi
+	sleep $(($EXPIRE * 2 + 1))
+	$NS_EXEC sysctl -wq net.ipv6.route.flush=1
+	check_rt_num 0 $($IP -6 route list |grep expires|wc -l)
+	log_test $ret 0 "ipv6 route garbage collection"
+
+	reset_dummy_10
 
 	# Permanent routes
-	for i in $(seq 1 5000); do
+	for i in $(seq 1 5); do
 	    $IP -6 route add 2001:30::$i \
 		via 2001:10::2 dev dummy_10
 	done
 	# Temporary routes
-	for i in $(seq 1 1000); do
+	for i in $(seq 1 5); do
 	    # Expire route after $EXPIRE seconds
 	    $IP -6 route add 2001:20::$i \
 		via 2001:10::2 dev dummy_10 expires $EXPIRE
 	done
-	sleep $(($EXPIRE * 2))
-	N_EXP_SLEEP=$($IP -6 route list |grep expires|wc -l)
-	if [ $N_EXP_SLEEP -ne 0 ]; then
-	    echo "FAIL: expected 0 routes with expires," \
-		 "got $N_EXP_SLEEP (5000 permanent routes)"
-	    ret=1
-	else
-	    ret=0
+	sleep $(($EXPIRE * 2 + 1))
+	check_rt_num 0 $($IP -6 route list |grep expires|wc -l)
+	log_test $ret 0 "ipv6 route garbage collection (with permanent routes)"
+
+	reset_dummy_10
+
+	# Permanent routes
+	for i in $(seq 1 5); do
+	    $IP -6 route add 2001:20::$i \
+		via 2001:10::2 dev dummy_10
+	done
+	# Replace with temporary routes
+	for i in $(seq 1 5); do
+	    # Expire route after $EXPIRE seconds
+	    $IP -6 route replace 2001:20::$i \
+		via 2001:10::2 dev dummy_10 expires $EXPIRE
+	done
+	check_rt_num_clean 5 $($IP -6 route list |grep expires|wc -l) || return
+	# Wait for GC
+	sleep $(($EXPIRE * 2 + 1))
+	$NS_EXEC sysctl -wq net.ipv6.route.flush=1
+	check_rt_num 0 $($IP -6 route list |grep expires|wc -l)
+	log_test $ret 0 "ipv6 route garbage collection (replace with expires)"
+
+	reset_dummy_10
+
+	# Temporary routes
+	for i in $(seq 1 5); do
+	    # Expire route after $EXPIRE seconds
+	    $IP -6 route add 2001:20::$i \
+		via 2001:10::2 dev dummy_10 expires $EXPIRE
+	done
+	# Replace with permanent routes
+	for i in $(seq 1 5); do
+	    $IP -6 route replace 2001:20::$i \
+		via 2001:10::2 dev dummy_10
+	done
+	check_rt_num_clean 0 $($IP -6 route list |grep expires|wc -l) || return
+
+	# Wait for GC
+	sleep $(($EXPIRE * 2 + 1))
+
+	check_rt_num 5 $($IP -6 route list |grep -v expires|grep 2001:20::|wc -l)
+	log_test $ret 0 "ipv6 route garbage collection (replace with permanent)"
+
+	# ra6 is required for the next test. (ipv6toolkit)
+	if [ ! -x "$(command -v ra6)" ]; then
+	    echo "SKIP: ra6 not found."
+	    set +e
+	    cleanup &> /dev/null
+	    return
 	fi
 
-	set +e
+	# Delete dummy_10 and remove all routes
+	$IP link del dev dummy_10
 
-	log_test $ret 0 "ipv6 route garbage collection"
+	# Create a pair of veth devices to send a RA message from one
+	# device to another.
+	$IP link add veth1 type veth peer name veth2
+	$IP link set dev veth1 up
+	$IP link set dev veth2 up
+	$IP -6 address add 2001:10::1/64 dev veth1 nodad
+	$IP -6 address add 2001:10::2/64 dev veth2 nodad
+
+	# Make veth1 ready to receive RA messages.
+	$NS_EXEC sysctl -wq net.ipv6.conf.veth1.accept_ra=2
+
+	# Send a RA message with a route from veth2 to veth1.
+	$NS_EXEC ra6 -i veth2 -d 2001:10::1 -t $EXPIRE
+
+	# Wait for the RA message.
+	sleep 1
+
+	# systemd may mess up the test.  You syould make sure that
+	# systemd-networkd.service and systemd-networkd.socket are stopped.
+	check_rt_num_clean 1 $($IP -6 route list|grep expires|wc -l) || return
+
+	# Wait for GC
+	sleep $(($EXPIRE * 2 + 1))
+
+	$NS_EXEC sysctl -wq net.ipv6.route.flush=1
+	check_rt_num 0 $($IP -6 route list |grep expires|wc -l)
+	log_test $ret 0 "ipv6 route garbage collection (RA message)"
+
+	set +e
 
 	cleanup &> /dev/null
 }
Signature · 1 line
2.34.1
#8 lore raw
In reply to [email protected]
This series was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:

Quoted 10 lines · On Thu, 8 Feb 2024 14:06:48 -0800 you wrote:

From: Kui-Feng Lee <[email protected]>

This patchset is resent due to previous reverting. [1]

FIB6 GC walks trees of fib6_tables to remove expired routes. Walking a tree can be expensive if the number of routes in a table is big, even if most of them are permanent. Checking routes in a separated list of routes having expiration will avoid this potential issue.

[...]

Here is the summary with links:
- [net-next,v6,1/5] net/ipv6: set expires in rt6_add_dflt_router().

    https://git.kernel.org/netdev/net-next/c/129e406e1811
  - [net-next,v6,2/5] net/ipv6: Remove unnecessary clean.
    https://git.kernel.org/netdev/net-next/c/60df43d3a72c
  - [net-next,v6,3/5] net/ipv6: Remove expired routes with a separated list of routes.
    https://git.kernel.org/netdev/net-next/c/5eb902b8e719
  - [net-next,v6,4/5] net/ipv6: set expires in modify_prefix_route() if RTF_EXPIRES is set.
    https://git.kernel.org/netdev/net-next/c/768e06a8bcab
  - [net-next,v6,5/5] selftests/net: Adding test cases of replacing routes and route advertisements.
    https://git.kernel.org/netdev/net-next/c/3407df8dc2de

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
maintainer
#6 lore raw

Re: [PATCH net-next v6 5/5] selftests/net: Adding test cases of replacing routes and route advertisements.

In reply to [email protected]
Quoted 14 lines · On Thu, 8 Feb 2024 14:06:53 -0800 [email protected] wrote:
tools/testing/selftests/net/fib_tests.sh +2 -3
 	# Permanent routes
-	for i in $(seq 1 5000); do
+	for i in $(seq 1 5); do
 	    $IP -6 route add 2001:30::$i \
 		via 2001:10::2 dev dummy_10
 	done
 	# Temporary routes
-	for i in $(seq 1 1000); do
+	for i in $(seq 1 5); do
 	    # Expire route after $EXPIRE seconds
 	    $IP -6 route add 2001:20::$i \
 		via 2001:10::2 dev dummy_10 expires $EXPIRE
 	done
-	sleep $(($EXPIRE * 2))

tools/testing/selftests/net/fib_tests.sh fib6_gc_test() · line 828

Quoted 10 lines
tools/testing/selftests/net/fib_tests.sh +3 -7
-	N_EXP_SLEEP=$($IP -6 route list |grep expires|wc -l)
-	if [ $N_EXP_SLEEP -ne 0 ]; then
-	    echo "FAIL: expected 0 routes with expires," \
-		 "got $N_EXP_SLEEP (5000 permanent routes)"
-	    ret=1
-	else
-	    ret=0
+	sleep $(($EXPIRE * 2 + 1))
+	check_rt_num 0 $($IP -6 route list |grep expires|wc -l)
+	log_test $ret 0 "ipv6 route garbage collection (with permanent routes)"

Looks like fib_tests.sh have gotten flaky since this got merged :(

https://netdev.bots.linux.dev/contest.html?test=fib-tests-sh&executor=vmksft-net&pass=0

# Fib6 garbage collection test
# TEST: ipv6 route garbage collection [ OK ]
# FAIL: Expected 0 routes, got 1

#     TEST: ipv6 route garbage collection (with permanent routes)         [FAIL]
#     TEST: ipv6 route garbage collection (replace with expires)          [ OK ]
#     TEST: ipv6 route garbage collection (replace with permanent)        [ OK ]

https://netdev-3.bots.linux.dev/vmksft-net/results/477081/6-fib-tests-sh/stdout

# Fib6 garbage collection test
# TEST: ipv6 route garbage collection [ OK ]
# FAIL: Expected 0 routes, got 3

#     TEST: ipv6 route garbage collection (with permanent routes)         [FAIL]
#     TEST: ipv6 route garbage collection (replace with expires)          [ OK ]
#     TEST: ipv6 route garbage collection (replace with permanent)        [ OK ]

https://netdev-3.bots.linux.dev/vmksft-net/results/467181/6-fib-tests-sh/stdout

# Fib6 garbage collection test
# TEST: ipv6 route garbage collection [ OK ]
# FAIL: Expected 0 routes, got 3

#     TEST: ipv6 route garbage collection (with permanent routes)         [FAIL]
#     TEST: ipv6 route garbage collection (replace with expires)          [ OK ]
#     TEST: ipv6 route garbage collection (replace with permanent)        [ OK ]

https://netdev-3.bots.linux.dev/vmksft-net/results/466641/18-fib-tests-sh/stdout

Could you take a look?

#7 lore raw

Re: [PATCH net-next v6 5/5] selftests/net: Adding test cases of replacing routes and route advertisements.

Quoted 19 lines · Jakub Kicinski
Quoted 18 lines · On Thu, 8 Feb 2024 14:06:53 -0800 [email protected] wrote:

# Permanent routes

tools/testing/selftests/net/fib_tests.sh +2 -7
-	for i in $(seq 1 5000); do
+	for i in $(seq 1 5); do
  	    $IP -6 route add 2001:30::$i \
  		via 2001:10::2 dev dummy_10
  	done
  	# Temporary routes
-	for i in $(seq 1 1000); do
+	for i in $(seq 1 5); do
  	    # Expire route after $EXPIRE seconds
  	    $IP -6 route add 2001:20::$i \
  		via 2001:10::2 dev dummy_10 expires $EXPIRE
  	done
-	sleep $(($EXPIRE * 2))
-	N_EXP_SLEEP=$($IP -6 route list |grep expires|wc -l)
-	if [ $N_EXP_SLEEP -ne 0 ]; then
-	    echo "FAIL: expected 0 routes with expires," \
-		 "got $N_EXP_SLEEP (5000 permanent routes)"
Quoted 8 lines

tools/testing/selftests/net/fib_tests.sh fib6_gc_test() · line 828

Quoted 6 lines
tools/testing/selftests/net/fib_tests.sh +3 -3
-	    ret=1
-	else
-	    ret=0
+	sleep $(($EXPIRE * 2 + 1))
+	check_rt_num 0 $($IP -6 route list |grep expires|wc -l)
+	log_test $ret 0 "ipv6 route garbage collection (with permanent routes)"

Looks like fib_tests.sh have gotten flaky since this got merged :(

Sure! I am looking into it.

Quoted 28 lines

https://netdev.bots.linux.dev/contest.html?test=fib-tests-sh&executor=vmksft-net&pass=0

# Fib6 garbage collection test
# TEST: ipv6 route garbage collection [ OK ]
# FAIL: Expected 0 routes, got 1

#     TEST: ipv6 route garbage collection (with permanent routes)         [FAIL]
#     TEST: ipv6 route garbage collection (replace with expires)          [ OK ]
#     TEST: ipv6 route garbage collection (replace with permanent)        [ OK ]

https://netdev-3.bots.linux.dev/vmksft-net/results/477081/6-fib-tests-sh/stdout

# Fib6 garbage collection test
# TEST: ipv6 route garbage collection [ OK ]
# FAIL: Expected 0 routes, got 3

#     TEST: ipv6 route garbage collection (with permanent routes)         [FAIL]
#     TEST: ipv6 route garbage collection (replace with expires)          [ OK ]
#     TEST: ipv6 route garbage collection (replace with permanent)        [ OK ]

https://netdev-3.bots.linux.dev/vmksft-net/results/467181/6-fib-tests-sh/stdout

# Fib6 garbage collection test
# TEST: ipv6 route garbage collection [ OK ]
# FAIL: Expected 0 routes, got 3

#     TEST: ipv6 route garbage collection (with permanent routes)         [FAIL]
#     TEST: ipv6 route garbage collection (replace with expires)          [ OK ]
#     TEST: ipv6 route garbage collection (replace with permanent)        [ OK ]

https://netdev-3.bots.linux.dev/vmksft-net/results/466641/18-fib-tests-sh/stdout

Could you take a look?