]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ipv6: clean up routes when manually removing address with a lifetime
authorJakub Kicinski <kuba@kernel.org>
Thu, 13 Nov 2025 03:17:00 +0000 (19:17 -0800)
committerJakub Kicinski <kuba@kernel.org>
Sat, 15 Nov 2025 01:44:47 +0000 (17:44 -0800)
When an IPv6 address with a finite lifetime (configured with valid_lft
and preferred_lft) is manually deleted, the kernel does not clean up the
associated prefix route. This results in orphaned routes (marked "proto
kernel") remaining in the routing table even after their corresponding
address has been deleted.

This is particularly problematic on networks using combination of SLAAC
and bridges.

1. Machine comes up and performs RA on eth0.
2. User creates a bridge
   - does an ip -6 addr flush dev eth0;
   - adds the eth0 under the bridge.
3. SLAAC happens on br0.

Even tho the address has "moved" to br0 there will still be a route
pointing to eth0, but eth0 is not usable for IP any more.

Reviewed-by: David Ahern <dsahern@kernel.org>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Link: https://patch.msgid.link/20251113031700.3736285-1-kuba@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/ipv6/addrconf.c
tools/testing/selftests/net/rtnetlink.sh

index 40e9c336f6c55eedea03e0ea14aa4bd1ef785370..b66217d1b2f827873938558d710c9e43f1364cd2 100644 (file)
@@ -1324,7 +1324,7 @@ static void ipv6_del_addr(struct inet6_ifaddr *ifp)
                __in6_ifa_put(ifp);
        }
 
-       if (ifp->flags & IFA_F_PERMANENT && !(ifp->flags & IFA_F_NOPREFIXROUTE))
+       if (!(ifp->flags & IFA_F_NOPREFIXROUTE))
                action = check_cleanup_prefix_route(ifp, &expires);
 
        list_del_rcu(&ifp->if_list);
index 163a084d525d5f7f6aecf74b61830a62d7ae1e21..248c2b91fe42bc89cfda0937f9948c8715992e1a 100755 (executable)
@@ -8,6 +8,7 @@ ALL_TESTS="
        kci_test_polrouting
        kci_test_route_get
        kci_test_addrlft
+       kci_test_addrlft_route_cleanup
        kci_test_promote_secondaries
        kci_test_tc
        kci_test_gre
@@ -323,6 +324,25 @@ kci_test_addrlft()
        end_test "PASS: preferred_lft addresses have expired"
 }
 
+kci_test_addrlft_route_cleanup()
+{
+       local ret=0
+       local test_addr="2001:db8:99::1/64"
+       local test_prefix="2001:db8:99::/64"
+
+       run_cmd ip -6 addr add $test_addr dev "$devdummy" valid_lft 300 preferred_lft 300
+       run_cmd_grep "$test_prefix proto kernel" ip -6 route show dev "$devdummy"
+       run_cmd ip -6 addr del $test_addr dev "$devdummy"
+       run_cmd_grep_fail "$test_prefix" ip -6 route show dev "$devdummy"
+
+       if [ $ret -ne 0 ]; then
+               end_test "FAIL: route not cleaned up when address with valid_lft deleted"
+               return 1
+       fi
+
+       end_test "PASS: route cleaned up when address with valid_lft deleted"
+}
+
 kci_test_promote_secondaries()
 {
        run_cmd ifconfig "$devdummy"