Skip to contentSkip to conversation

ipv6: ignore link state in gateway check

PATCH Applied Yaroslav Dudkov 5 participants 8 messages Nov 4 – Nov 10

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

v2 cover ipv6: ignore link state in gateway check

IPv6 gateway validation can reject routes in non-main tables when ignore_routes_with_linkdown is enabled and the nexthop device has no carrier, even though these routes should be added.

Fix this by ignoring link state during gateway validation and add a regression selftest covering IPv4 and IPv6 route installation.

Changes in v2:
- Fix variable ordering.
- Add a regression selftest.

v1: https://lore.kernel.org/netdev/[email protected]/

Yaroslav Dudkov (2):
ipv6: ignore link state in gateway check
selftests: fib_tests: Add carrier gateway test

 net/ipv6/route.c                         |  2 +-
 tools/testing/selftests/net/fib_tests.sh | 40 ++++++++++++++++++++++++
 2 files changed, 41 insertions(+), 1 deletion(-)
Signature · 1 line
2.54.0
#1 lore raw

PATCH v2 1/2 ipv6: ignore link state in gateway check

IPv6 route cannot be added in table when all
following conditions are true:
- gateway is not link-local address
- ignore_routes_with_linkdown=1 on device
- nexthop has no carrier
- gateway is not present or covered by any route in table already Also multipath routes addition is invalidated by kernel even if only one of added nexthops satisfies all above conditions.

Reproducer:

ip netns add t
ip -n t link add va type veth peer name vb ip -n t link set va up
ip -n t addr add fd00::1/64 dev va nodad
ip netns exec t sysctl -w \
net.ipv6.conf.va.ignore_routes_with_linkdown=1
ip -n t -6 route add 2001:db8::/64 via fd00::2 dev va

  # added
  ip -n t -6 route add 2001:db8::/64 table 100 via fd00::2 dev va
  # RTNETLINK answers: No route to host
  ip -n t -6 route show table all
  ip netns del t

Route should be added because:
- RT6_LOOKUP_F_IGNORE_LINKSTATE in commit d5d32e4b7668 ("net: ipv6: Do not consider link state for nexthop validation") was added for this
- the same route is valid in main table (when no specifying table id while adding route)
- fib6_nh_init() initializes nexthops with no carrier
- IPv4 already does this (fib_check_nh_v4_gw() ignores link state using the FIB_LOOKUP_IGNORE_LINKSTATE flag)

Before commit b2c709cce682 ("ipv6: Convert gateway validation to use fib6_info") rt6_lookup() was used for checking if nexthop is valid, rt6_lookup called rt6_device_match() which does not check the link state. After change rt6_lookup() to fib6_lookup() find_match() under fib6_lookup() started to invalidate linkdown devices, because RT6_LOOKUP_F_IGNORE_LINKSTATE is not passed to it.

Adding RT6_LOOKUP_F_IGNORE_LINKSTATE to flags for ip6_route_check_nh() solves the problem. RT6_LOOKUP_F_IGNORE_LINKSTATE is already used inside the first search ip6_nh_lookup_table() and fixes the bug in second search fib6_lookup(). Also RT6_LOOKUP_F_IGNORE_LINKSTATE isn't read inside fib6_select_path().

Fixes b2c709cce682 ("ipv6: Convert gateway validation to use fib6_info")

---
IPv4 example of this situation:
ip netns add t
ip -n t link add va type veth peer name vb
ip -n t link set va up
ip -n t addr add 192.168.0.1/24 dev va
ip netns exec t sysctl -w \
net.ipv4.conf.va.ignore_routes_with_linkdown=1
ip -n t route add 192.0.2.0/24 table 100 via 192.168.0.2 dev va

  # added
  ip -n t route show table all
  ip netns del t

Also when adding RT6_LOOKUP_F_IGNORE_LINKSTATE to flags of ip6_route_check_nh() makes adding this flag inside of ip6_nh_lookup_table() unnecessary for this call, making another call in ip6_route_check_nh_onlink() with flags=0 the only place where it is needed.

---
 net/ipv6/route.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv6/route.c +1 -1
index 94e5ef1c4f83..73d8a2c95602 100644
@@ -3424,9 +3424,9 @@ static int ip6_route_check_nh(struct net *net,
 			      netdevice_tracker *dev_tracker,
 			      struct inet6_dev **idev)
 {
+	int flags = RT6_LOOKUP_F_IFACE | RT6_LOOKUP_F_IGNORE_LINKSTATE;
 	const struct in6_addr *gw_addr = &cfg->fc_gateway;
 	struct net_device *dev = _dev ? *_dev : NULL;
-	int flags = RT6_LOOKUP_F_IFACE;
 	struct fib6_result res = {};
 	int err = -EHOSTUNREACH;
 
Signature · 1 line
2.54.0
Reviewed-by on v2 1/2
#2 lore raw
Quoted 89 lines · Yaroslav Dudkov

IPv6 route cannot be added in table when all
following conditions are true:
- gateway is not link-local address
- ignore_routes_with_linkdown=1 on device
- nexthop has no carrier
- gateway is not present or covered by any route in table already Also multipath routes addition is invalidated by kernel even if only one of added nexthops satisfies all above conditions.

Reproducer:

ip netns add t
ip -n t link add va type veth peer name vb ip -n t link set va up
ip -n t addr add fd00::1/64 dev va nodad
ip netns exec t sysctl -w \
net.ipv6.conf.va.ignore_routes_with_linkdown=1
ip -n t -6 route add 2001:db8::/64 via fd00::2 dev va

  # added
  ip -n t -6 route add 2001:db8::/64 table 100 via fd00::2 dev va
  # RTNETLINK answers: No route to host
  ip -n t -6 route show table all
  ip netns del t

Route should be added because:
- RT6_LOOKUP_F_IGNORE_LINKSTATE in commit d5d32e4b7668 ("net: ipv6: Do not consider link state for nexthop validation") was added for this
- the same route is valid in main table (when no specifying table id while adding route)
- fib6_nh_init() initializes nexthops with no carrier
- IPv4 already does this (fib_check_nh_v4_gw() ignores link state using the FIB_LOOKUP_IGNORE_LINKSTATE flag)

Before commit b2c709cce682 ("ipv6: Convert gateway validation to use fib6_info") rt6_lookup() was used for checking if nexthop is valid, rt6_lookup called rt6_device_match() which does not check the link state. After change rt6_lookup() to fib6_lookup() find_match() under fib6_lookup() started to invalidate linkdown devices, because RT6_LOOKUP_F_IGNORE_LINKSTATE is not passed to it.

Adding RT6_LOOKUP_F_IGNORE_LINKSTATE to flags for ip6_route_check_nh() solves the problem. RT6_LOOKUP_F_IGNORE_LINKSTATE is already used inside the first search ip6_nh_lookup_table() and fixes the bug in second search fib6_lookup(). Also RT6_LOOKUP_F_IGNORE_LINKSTATE isn't read inside fib6_select_path().

Fixes b2c709cce682 ("ipv6: Convert gateway validation to use fib6_info")

---
IPv4 example of this situation:
ip netns add t
ip -n t link add va type veth peer name vb
ip -n t link set va up
ip -n t addr add 192.168.0.1/24 dev va
ip netns exec t sysctl -w \
net.ipv4.conf.va.ignore_routes_with_linkdown=1
ip -n t route add 192.0.2.0/24 table 100 via 192.168.0.2 dev va

  # added
  ip -n t route show table all
  ip netns del t

Also when adding RT6_LOOKUP_F_IGNORE_LINKSTATE to flags of ip6_route_check_nh() makes adding this flag inside of ip6_nh_lookup_table() unnecessary for this call, making another call in ip6_route_check_nh_onlink() with flags=0 the only place where it is needed.

---
 net/ipv6/route.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv6/route.c +1 -1
index 94e5ef1c4f83..73d8a2c95602 100644
@@ -3424,9 +3424,9 @@ static int ip6_route_check_nh(struct net *net,
 			      netdevice_tracker *dev_tracker,
 			      struct inet6_dev **idev)
 {
+	int flags = RT6_LOOKUP_F_IFACE | RT6_LOOKUP_F_IGNORE_LINKSTATE;
 	const struct in6_addr *gw_addr = &cfg->fc_gateway;
 	struct net_device *dev = _dev ? *_dev : NULL;
-	int flags = RT6_LOOKUP_F_IFACE;
 	struct fib6_result res = {};
 	int err = -EHOSTUNREACH;
 
Signature · 1 line
2.54.0
#3 lore raw

PATCH v2 2/2 selftests: fib_tests: Add carrier gateway test

In reply to Yaroslav Dudkov

Test adds routes with a gateway while the nexthop device has no carrier and ignore_routes_with_linkdown is enabled on it. The routes are added to the main table and to a non-main table, with and without a device, for both IPv4 and IPv6. Routes are expected to be accepted disregarding the link state.

Without the previous patch, the IPv6 non-main table cases fail:

Without fix:
Gateway validation with carrier down

    TEST: IPv4 route in main table                                [ OK ]
    TEST: IPv6 route in main table                                [ OK ]
    TEST: IPv4 route in non-main table                            [ OK ]
    TEST: IPv6 route in non-main table                            [FAIL]
    TEST: IPv4 route in non-main table without device             [ OK ]
    TEST: IPv6 route in non-main table without device             [FAIL]
    TEST: IPv4 linkdown flag set                                  [ OK ]
    TEST: IPv6 linkdown flag set                                  [FAIL]

With fix:
Gateway validation with carrier down

    TEST: IPv4 route in main table                                [ OK ]
    TEST: IPv6 route in main table                                [ OK ]
    TEST: IPv4 route in non-main table                            [ OK ]
    TEST: IPv6 route in non-main table                            [ OK ]
    TEST: IPv4 route in non-main table without device             [ OK ]
    TEST: IPv6 route in non-main table without device             [ OK ]
    TEST: IPv4 linkdown flag set                                  [ OK ]
    TEST: IPv6 linkdown flag set                                  [ OK ]
---
 tools/testing/selftests/net/fib_tests.sh | 40 ++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
tools/testing/selftests/net/fib_tests.sh +40 -0
index 7c47d7fe250d..d7ac3c727f70 100755
@@ -406,10 +406,50 @@ fib_carrier_unicast_test()
 	cleanup
 }
 
+fib_carrier_gw_test()
+{
+	echo
+	echo "Gateway validation with carrier down"
+
+	setup
+
+	set -e
+	$NS_EXEC sysctl -qw net.ipv4.conf.dummy0.ignore_routes_with_linkdown=1
+	$NS_EXEC sysctl -qw net.ipv6.conf.dummy0.ignore_routes_with_linkdown=1
+	$IP link set dev dummy0 carrier off
+	sleep 1
+	set +e
+
+	$IP route add 203.0.113.0/25 via 198.51.100.2 dev dummy0 &> /dev/null
+	log_test $? 0 "IPv4 route in main table"
+	$IP -6 route add 2001:db8:10::/64 via 2001:db8:1::2 dev dummy0 &> /dev/null
+	log_test $? 0 "IPv6 route in main table"
+
+	$IP route add 203.0.113.0/25 table 100 via 198.51.100.2 dev dummy0 &> /dev/null
+	log_test $? 0 "IPv4 route in non-main table"
+	$IP -6 route add 2001:db8:10::/64 table 100 via 2001:db8:1::2 dev dummy0 &> /dev/null
+	log_test $? 0 "IPv6 route in non-main table"
+
+	$IP route add 203.0.113.128/25 table 100 via 198.51.100.2 &> /dev/null
+	log_test $? 0 "IPv4 route in non-main table without device"
+	$IP -6 route add 2001:db8:11::/64 table 100 via 2001:db8:1::2 &> /dev/null
+	log_test $? 0 "IPv6 route in non-main table without device"
+
+	$IP route show table 100 203.0.113.0/25 | \
+		grep -q "linkdown"
+	log_test $? 0 "IPv4 linkdown flag set"
+	$IP -6 route show table 100 2001:db8:10::/64 | \
+		grep -q "linkdown"
+	log_test $? 0 "IPv6 linkdown flag set"
+
+	cleanup
+}
+
 fib_carrier_test()
 {
 	fib_carrier_local_test
 	fib_carrier_unicast_test
+	fib_carrier_gw_test
 }
 
 fib_rp_filter_test()
Signature · 1 line
2.54.0
Tested-by Reviewed-by on v2 2/2
#4 lore raw

Re: [PATCH net v2 2/2] selftests: fib_tests: Add carrier gateway test

Quoted 94 lines · Yaroslav Dudkov

Test adds routes with a gateway while the nexthop device has no carrier and ignore_routes_with_linkdown is enabled on it. The routes are added to the main table and to a non-main table, with and without a device, for both IPv4 and IPv6. Routes are expected to be accepted disregarding the link state.

Without the previous patch, the IPv6 non-main table cases fail:

Without fix:
Gateway validation with carrier down

    TEST: IPv4 route in main table                                [ OK ]
    TEST: IPv6 route in main table                                [ OK ]
    TEST: IPv4 route in non-main table                            [ OK ]
    TEST: IPv6 route in non-main table                            [FAIL]
    TEST: IPv4 route in non-main table without device             [ OK ]
    TEST: IPv6 route in non-main table without device             [FAIL]
    TEST: IPv4 linkdown flag set                                  [ OK ]
    TEST: IPv6 linkdown flag set                                  [FAIL]

With fix:
Gateway validation with carrier down

    TEST: IPv4 route in main table                                [ OK ]
    TEST: IPv6 route in main table                                [ OK ]
    TEST: IPv4 route in non-main table                            [ OK ]
    TEST: IPv6 route in non-main table                            [ OK ]
    TEST: IPv4 route in non-main table without device             [ OK ]
    TEST: IPv6 route in non-main table without device             [ OK ]
    TEST: IPv4 linkdown flag set                                  [ OK ]
    TEST: IPv6 linkdown flag set                                  [ OK ]
---
 tools/testing/selftests/net/fib_tests.sh | 40 ++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
tools/testing/selftests/net/fib_tests.sh +40 -0
index 7c47d7fe250d..d7ac3c727f70 100755
@@ -406,10 +406,50 @@ fib_carrier_unicast_test()
 	cleanup
 }
 
+fib_carrier_gw_test()
+{
+	echo
+	echo "Gateway validation with carrier down"
+
+	setup
+
+	set -e
+	$NS_EXEC sysctl -qw net.ipv4.conf.dummy0.ignore_routes_with_linkdown=1
+	$NS_EXEC sysctl -qw net.ipv6.conf.dummy0.ignore_routes_with_linkdown=1
+	$IP link set dev dummy0 carrier off
+	sleep 1
+	set +e
+
+	$IP route add 203.0.113.0/25 via 198.51.100.2 dev dummy0 &> /dev/null
+	log_test $? 0 "IPv4 route in main table"
+	$IP -6 route add 2001:db8:10::/64 via 2001:db8:1::2 dev dummy0 &> /dev/null
+	log_test $? 0 "IPv6 route in main table"
+
+	$IP route add 203.0.113.0/25 table 100 via 198.51.100.2 dev dummy0 &> /dev/null
+	log_test $? 0 "IPv4 route in non-main table"
+	$IP -6 route add 2001:db8:10::/64 table 100 via 2001:db8:1::2 dev dummy0 &> /dev/null
+	log_test $? 0 "IPv6 route in non-main table"
+
+	$IP route add 203.0.113.128/25 table 100 via 198.51.100.2 &> /dev/null
+	log_test $? 0 "IPv4 route in non-main table without device"
+	$IP -6 route add 2001:db8:11::/64 table 100 via 2001:db8:1::2 &> /dev/null
+	log_test $? 0 "IPv6 route in non-main table without device"
+
+	$IP route show table 100 203.0.113.0/25 | \
+		grep -q "linkdown"
+	log_test $? 0 "IPv4 linkdown flag set"
+	$IP -6 route show table 100 2001:db8:10::/64 | \
+		grep -q "linkdown"
+	log_test $? 0 "IPv6 linkdown flag set"
+
+	cleanup
+}
+
 fib_carrier_test()
 {
 	fib_carrier_local_test
 	fib_carrier_unicast_test
+	fib_carrier_gw_test
 }
 
 fib_rp_filter_test()
Signature · 1 line
2.54.0
#5 lore raw
In reply to Yaroslav Dudkov
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

Hi!

This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

- How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan.

Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account. If the series needs another revision for other reasons, please include the information in the commit messages then.

The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.

maintainer Reviewed-by on the v2 series
#6 lore raw
In reply to Yaroslav Dudkov
Quoted 4 lines · Yaroslav Dudkov

IPv6 gateway validation can reject routes in non-main tables when ignore_routes_with_linkdown is enabled and the nexthop device has no carrier, even though these routes should be added.

Quoted 8 lines

Fix this by ignoring link state during gateway validation and add a regression selftest covering IPv4 and IPv6 route installation.

Changes in v2:
- Fix variable ordering.
- Add a regression selftest.

v1: https://lore.kernel.org/netdev/[email protected]/

#7 lore raw
In reply to Yaroslav Dudkov
This series was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Wed, 4 Nov 2026 19:56:53 +0000 you wrote:

IPv6 gateway validation can reject routes in non-main tables when ignore_routes_with_linkdown is enabled and the nexthop device has no carrier, even though these routes should be added.

Fix this by ignoring link state during gateway validation and add a regression selftest covering IPv4 and IPv6 route installation.

[...]

Here is the summary with links:
- [net,v2,1/2] ipv6: ignore link state in gateway check

    https://git.kernel.org/netdev/net/c/b76bcf3fff93
  - [net,v2,2/2] selftests: fib_tests: Add carrier gateway test
    https://git.kernel.org/netdev/net/c/d1b6b27005b4

You are awesome, thank you!

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