* [PATCH net-next 0/2] net: ipv6: add strict RFC 4861 6.3.6 default router selection
@ 2026-11-30 22:26 Florian Fainelli
2026-11-30 22:26 ` [PATCH net-next 1/2] " Florian Fainelli
2026-11-30 22:26 ` [PATCH net-next 2/2] selftests: net: add test for ipv6 strict_router_selection Florian Fainelli
0 siblings, 2 replies; 3+ messages in thread
From: Florian Fainelli @ 2026-11-30 22:26 UTC (permalink / raw)
To: netdev
Cc: Florian Fainelli, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Hideaki YOSHIFUJI, David Ahern, Shuah Khan,
Kuniyuki Iwashima, Jiayuan Chen, Angus Peng, Maoyi Xie,
open list, open list:KERNEL SELFTEST FRAMEWORK,
bcm-kernel-feedback-list
This patch series adds support for strict RFC 4861 section 6.3.6 default
router selection along with a self test to exercise the newly added
sysctl knob.
Angus Peng (1):
net: ipv6: add strict RFC 4861 6.3.6 default router selection
Florian Fainelli (1):
selftests: net: add test for ipv6 strict_router_selection
Documentation/networking/ip-sysctl.rst | 29 +
include/net/netns/ipv6.h | 1 +
net/ipv6/route.c | 101 +++-
tools/testing/selftests/net/Makefile | 1 +
.../net/ipv6_strict_router_select.sh | 507 ++++++++++++++++++
5 files changed, 637 insertions(+), 2 deletions(-)
create mode 100755 tools/testing/selftests/net/ipv6_strict_router_select.sh
--
2.34.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH net-next 1/2] net: ipv6: add strict RFC 4861 6.3.6 default router selection
2026-11-30 22:26 [PATCH net-next 0/2] net: ipv6: add strict RFC 4861 6.3.6 default router selection Florian Fainelli
@ 2026-11-30 22:26 ` Florian Fainelli
2026-11-30 22:26 ` [PATCH net-next 2/2] selftests: net: add test for ipv6 strict_router_selection Florian Fainelli
1 sibling, 0 replies; 3+ messages in thread
From: Florian Fainelli @ 2026-11-30 22:26 UTC (permalink / raw)
To: netdev
Cc: Angus Peng, Florian Fainelli, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Hideaki YOSHIFUJI, David Ahern,
Shuah Khan, Kuniyuki Iwashima, Jiayuan Chen, Maoyi Xie,
open list, open list:KERNEL SELFTEST FRAMEWORK,
bcm-kernel-feedback-list
From: Angus Peng <angus.peng@broadcom.com>
A CPE learns default routers from Router Advertisements on its WAN
and must apply RFC 4861 section 6.3.6 default router selection there.
Upstream does not, for three independent reasons:
- ip6_pol_route() only sets RT6_LOOKUP_F_REACHABLE when forwarding is
disabled, so neighbor reachability is never consulted on a router;
- with CONFIG_IPV6_ROUTER_PREF enabled, a missing or unresolved
neighbor entry is scored as reachable, so every candidate ties and
the round-robin required by 6.3.6 rule 2 never triggers;
- RT6_NUD_SUCCEED adds nothing to the route score. On the forwarding
path ip6_pol_route_input() passes flowi6_iif into the parameter
rt6_score_route() knows as oif, so it never matches the nexthop
device and the device score is zero. With no preference bonus
either (CONFIG_IPV6_ROUTER_PREF=n), a reachable nexthop ties with
an unreachable one and FIB leaf order decides.
Add net.ipv6.route.strict_router_selection, default 0, which leaves
the upstream paths bit-for-bit unchanged. When enabled,
reachability-based selection also applies with forwarding on, and
rt6_score_route() ranks candidates by neighbor state above the device
and preference scores, so preference only breaks ties between equally
reachable routers as RFC 4191 section 3 requires. RFC 4191 section
6.2.3 probing is suppressed in strict mode: soliciting a router that
was not selected is indistinguishable from address resolution, and a
CONFIG_IPV6_ROUTER_PREF=n kernel does not probe at all; unreachable
routers are recovered through round-robin and traffic-driven
resolution instead.
rt6_check_neigh() is left untouched: strict mode bypasses it and
derives both the verdict and the score from a single neighbor lookup,
so the semantics do not depend on CONFIG_IPV6_ROUTER_PREF.
Signed-off-by: Angus Peng <angus.peng@broadcom.com>
[florian: commit message, comments, forward porting]
Signed-off-by: Florian Fainelli <florian.fainelli@broadcom.com>
---
Documentation/networking/ip-sysctl.rst | 29 +++++++
include/net/netns/ipv6.h | 1 +
net/ipv6/route.c | 101 ++++++++++++++++++++++++-
3 files changed, 129 insertions(+), 2 deletions(-)
diff --git a/Documentation/networking/ip-sysctl.rst b/Documentation/networking/ip-sysctl.rst
index 671011c74e14..0ea2d7818ea2 100644
--- a/Documentation/networking/ip-sysctl.rst
+++ b/Documentation/networking/ip-sysctl.rst
@@ -2586,6 +2586,35 @@ skip_notify_on_dev_down - BOOLEAN
Default: 0 (disabled)
+route/strict_router_selection - BOOLEAN
+ Apply strict default router selection as described in RFC 4861
+ section 6.3.6.
+
+ By default, neighbour reachability is only taken into account
+ when IPv6 forwarding is disabled, and a router with no neighbour
+ entry is considered reachable when CONFIG_IPV6_ROUTER_PREF is
+ enabled. When enabled, reachability is also considered when
+ forwarding is enabled, for example on a CPE that learns its
+ default routers from Router Advertisements on the WAN.
+
+ Candidate routers are ranked by neighbour state first: routers
+ with a valid neighbour entry come first, then routers whose
+ address resolution is in progress, which stay selected until
+ resolution completes or fails. The device match and the RFC 4191
+ router preference (CONFIG_IPV6_ROUTER_PREF) only break ties
+ between routers of equal reachability. If no router is known to
+ be reachable, routers are selected in round-robin.
+
+ RFC 4191 section 6.2.3 router reachability probing is not
+ performed when enabled.
+
+ Possible values:
+
+ - 0 (disabled) - upstream default router selection
+ - 1 (enabled) - strict RFC 4861 section 6.3.6 selection
+
+ Default: 0 (disabled)
+
nexthop_compat_mode - BOOLEAN
New nexthop API provides a means for managing nexthops independent of
prefixes. Backwards compatibility with old route format is enabled by
diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
index aefce37c04a4..e34b3f846288 100644
--- a/include/net/netns/ipv6.h
+++ b/include/net/netns/ipv6.h
@@ -27,6 +27,7 @@ struct netns_sysctl_ipv6 {
int ip6_rt_gc_interval;
int ip6_rt_mtu_expires;
int ip6_rt_min_advmss;
+ u8 ip6_rt_strict_router_select;
u32 multipath_hash_fields;
u8 multipath_hash_policy;
u8 ip6_rt_gc_elasticity;
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index df843178e5ec..d1795e91602e 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -653,6 +653,61 @@ static void rt6_device_match(struct net *net, struct fib6_result *res,
res->nh = nh;
}
+/* Strict RFC 4861 6.3.6 default router selection, runtime-controlled
+ * via net.ipv6.route.strict_router_selection (default 0 = upstream
+ * behaviour, bit-for-bit). When enabled:
+ * - reachability-based selection also applies with forwarding on
+ * (a CPE learns default routers from RAs on its WAN and must
+ * behave like a host there): see ip6_pol_route(),
+ * - candidate routers are ranked strictly by neighbour state in
+ * rt6_strict_reach_rank(), replacing the rt6_check_neigh() verdict
+ * entirely; the rank sits above the device score (bit 1) and the
+ * RFC 4191 preference score (bits 2+), so preference only breaks
+ * ties between equally reachable routers (RFC 4191 sec 3). The
+ * reachability ordering itself does not depend on
+ * CONFIG_IPV6_ROUTER_PREF:
+ * NUD_VALID known/probably reachable -> highest rank
+ * NUD_INCOMPLETE resolution in progress -> middle rank; the
+ * router stays selected while its solicitations
+ * are in flight, so unrelated lookups cannot
+ * rotate away and spread NS across routers,
+ * which would consume rotation slots and defeat
+ * the rule 2 sequence below
+ * anything else not reachable -> RT6_NUD_FAIL_DO_RR
+ * round-robin per 6.3.6 rule 2
+ * - RFC 4191 6.2.3 router probing is suppressed (see rt6_probe()),
+ * since soliciting a router that was not selected is treated as
+ * address resolution.
+ */
+static bool rt6_strict_router_select(struct net *net)
+{
+ return READ_ONCE(net->ipv6.sysctl.ip6_rt_strict_router_select);
+}
+
+#define RT6_STRICT_RANK_VALID 0x200
+#define RT6_STRICT_RANK_PROBING 0x100
+#define RT6_STRICT_RANK_UNREACH 0x000
+
+static int rt6_strict_reach_rank(const struct fib6_nh *fib6_nh)
+{
+ struct neighbour *neigh;
+ int rank = RT6_STRICT_RANK_UNREACH;
+
+ rcu_read_lock();
+ neigh = __ipv6_neigh_lookup_noref(fib6_nh->fib_nh_dev,
+ &fib6_nh->fib_nh_gw6);
+ if (neigh) {
+ u8 nud_state = READ_ONCE(neigh->nud_state);
+
+ if (nud_state & NUD_VALID)
+ rank = RT6_STRICT_RANK_VALID;
+ else if (nud_state & NUD_INCOMPLETE)
+ rank = RT6_STRICT_RANK_PROBING;
+ }
+ rcu_read_unlock();
+ return rank;
+}
+
#ifdef CONFIG_IPV6_ROUTER_PREF
struct __rt6_probe_work {
struct work_struct work;
@@ -693,6 +748,12 @@ static void rt6_probe(struct fib6_nh *fib6_nh)
if (!fib6_nh->fib_nh_gw_family)
return;
+ /* See rt6_strict_router_select(): no RFC 4191 6.2.3 probing in
+ * strict RFC 4861 6.3.6 mode.
+ */
+ if (rt6_strict_router_select(dev_net(fib6_nh->fib_nh_dev)))
+ return;
+
nh_gw = &fib6_nh->fib_nh_gw6;
dev = fib6_nh->fib_nh_dev;
rcu_read_lock();
@@ -786,7 +847,28 @@ static int rt6_score_route(const struct fib6_nh *nh, u32 fib6_flags, int oif,
#endif
if ((strict & RT6_LOOKUP_F_REACHABLE) &&
!(fib6_flags & RTF_NONEXTHOP) && nh->fib_nh_gw_family) {
- int n = rt6_check_neigh(nh);
+ int n;
+
+ /* Strict mode replaces the rt6_check_neigh() verdict with a
+ * reachability rank ORed above the device and preference
+ * scores (single neighbour lookup, no state races between
+ * two reads). Rank 0 means not reachable: hand back
+ * FAIL_DO_RR so find_match() scores the candidate 0 and
+ * round-robin applies (RFC 4861 6.3.6 rule 2). A non-zero
+ * rank (VALID or INCOMPLETE) outranks every DO_RR candidate;
+ * INCOMPLETE additionally keeps selection on the router whose
+ * solicitations are in flight, so unrelated concurrent lookups
+ * cannot rotate it away before resolution completes or fails.
+ */
+ if (rt6_strict_router_select(dev_net(nh->fib_nh_dev))) {
+ int rank = rt6_strict_reach_rank(nh);
+
+ if (!rank)
+ return RT6_NUD_FAIL_DO_RR;
+ return m | rank;
+ }
+
+ n = rt6_check_neigh(nh);
if (n < 0)
return n;
}
@@ -2282,7 +2364,11 @@ struct rt6_info *ip6_pol_route(struct net *net, struct fib6_table *table,
strict |= flags & RT6_LOOKUP_F_IFACE;
strict |= flags & RT6_LOOKUP_F_IGNORE_LINKSTATE;
- if (READ_ONCE(net->ipv6.devconf_all->forwarding) == 0)
+ /* Strict mode applies reachability-based selection also with
+ * forwarding enabled, see rt6_strict_router_select().
+ */
+ if (READ_ONCE(net->ipv6.devconf_all->forwarding) == 0 ||
+ rt6_strict_router_select(net))
strict |= RT6_LOOKUP_F_REACHABLE;
rcu_read_lock();
@@ -6696,6 +6782,15 @@ static const struct ctl_table ipv6_route_table_template[] = {
.extra1 = SYSCTL_ZERO,
.extra2 = SYSCTL_ONE,
},
+ {
+ .procname = "strict_router_selection",
+ .data = &init_net.ipv6.sysctl.ip6_rt_strict_router_select,
+ .maxlen = sizeof(u8),
+ .mode = 0644,
+ .proc_handler = proc_dou8vec_minmax,
+ .extra1 = SYSCTL_ZERO,
+ .extra2 = SYSCTL_ONE,
+ },
};
struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
@@ -6719,6 +6814,7 @@ struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
table[8].data = &net->ipv6.sysctl.ip6_rt_min_advmss;
table[9].data = &net->ipv6.sysctl.ip6_rt_gc_min_interval;
table[10].data = &net->ipv6.sysctl.skip_notify_on_dev_down;
+ table[11].data = &net->ipv6.sysctl.ip6_rt_strict_router_select;
}
return table;
@@ -6795,6 +6891,7 @@ static int __net_init ip6_route_net_init(struct net *net)
net->ipv6.sysctl.ip6_rt_mtu_expires = 10*60*HZ;
net->ipv6.sysctl.ip6_rt_min_advmss = IPV6_MIN_MTU - 20 - 40;
net->ipv6.sysctl.skip_notify_on_dev_down = 0;
+ net->ipv6.sysctl.ip6_rt_strict_router_select = 0;
atomic_set(&net->ipv6.ip6_rt_gc_expire, 30*HZ);
--
2.34.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH net-next 2/2] selftests: net: add test for ipv6 strict_router_selection
2026-11-30 22:26 [PATCH net-next 0/2] net: ipv6: add strict RFC 4861 6.3.6 default router selection Florian Fainelli
2026-11-30 22:26 ` [PATCH net-next 1/2] " Florian Fainelli
@ 2026-11-30 22:26 ` Florian Fainelli
1 sibling, 0 replies; 3+ messages in thread
From: Florian Fainelli @ 2026-11-30 22:26 UTC (permalink / raw)
To: netdev
Cc: Florian Fainelli, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Hideaki YOSHIFUJI, David Ahern, Shuah Khan,
Kuniyuki Iwashima, Jiayuan Chen, Angus Peng, Maoyi Xie,
open list, open list:KERNEL SELFTEST FRAMEWORK,
bcm-kernel-feedback-list
Add a selftest for net.ipv6.route.strict_router_selection, which
enables strict RFC 4861 6.3.6 default router selection.
The test builds a single namespace with two same-metric default
routes, via fe80::1 on r1 and fe80::2 on r2, with r1 first in FIB leaf
order. Neighbour entries are set by hand, so no router needs to
answer anything. The selected router is read back with "ip route
get", both for locally generated traffic and, using "iif", for
forwarded traffic, which takes the ip6_pol_route_input() path where
the incoming ifindex is handed to route scoring as the oif.
The following is checked:
- the sysctl defaults to 0 and only accepts 0 and 1
- disabled: with forwarding on, neighbour state is ignored, FIB leaf
order decides and there is no round-robin
- enabled: a router with a valid neighbour entry beats one with a
failed or missing entry, in either leaf order, with forwarding on
and off, on the output and input paths
- enabled: unreachable routers are selected in round-robin, and a
reachable router stops the rotation
- enabled: a router whose address resolution is in progress stays
selected instead of being rotated away
- enabled: RFC 4191 preference only breaks ties between equally
reachable routers
- enabled: RFC 4191 6.2.3 router probing is suppressed, with a
positive control showing a neighbour solicitation is sent with the
sysctl off
The preference and probing tests need CONFIG_IPV6_ROUTER_PREF and are
skipped at runtime when it is not enabled.
Signed-off-by: Florian Fainelli <florian.fainelli@broadcom.com>
---
tools/testing/selftests/net/Makefile | 1 +
.../net/ipv6_strict_router_select.sh | 507 ++++++++++++++++++
2 files changed, 508 insertions(+)
create mode 100755 tools/testing/selftests/net/ipv6_strict_router_select.sh
diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile
index fb0a64662053..caa92d9ff0ae 100644
--- a/tools/testing/selftests/net/Makefile
+++ b/tools/testing/selftests/net/Makefile
@@ -59,6 +59,7 @@ TEST_PROGS := \
ipv6_flowlabel.sh \
ipv6_force_forwarding.sh \
ipv6_route_update_soft_lockup.sh \
+ ipv6_strict_router_select.sh \
ipvtap_test.sh \
l2_tos_ttl_inherit.sh \
l2tp.sh \
diff --git a/tools/testing/selftests/net/ipv6_strict_router_select.sh b/tools/testing/selftests/net/ipv6_strict_router_select.sh
new file mode 100755
index 000000000000..54500b25c967
--- /dev/null
+++ b/tools/testing/selftests/net/ipv6_strict_router_select.sh
@@ -0,0 +1,507 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+#
+# Test net.ipv6.route.strict_router_selection (strict RFC 4861 6.3.6 default
+# router selection).
+#
+# The device under test (DUT) has two default routers, fe80::1 behind r1 and
+# fe80::2 behind r2, installed as two same-metric default routes in the order
+# r1, r2 (i.e. r1 is first in FIB leaf order). Neighbour entries for the
+# routers are set up by hand, so no router has to answer anything, and the
+# selected router is read back with "ip route get", both for locally
+# generated traffic (output path) and for forwarded traffic (input path,
+# emulated with "iif").
+#
+# +---------------------------+
+# | DUT |
+# | dum0 | PEER (no IPv6, only absorbs frames)
+# | 2001:db8:100::1/64 |
+# | |
+# | r1 (gw fe80::1) ----------+--- r1p
+# | r2 (gw fe80::2) ----------+--- r2p
+# +---------------------------+
+#
+# Checked behaviour:
+# - the sysctl defaults to 0 and only accepts 0 and 1
+# - disabled: with forwarding on, neighbour state is ignored and FIB leaf
+# order decides (upstream behaviour, unchanged)
+# - enabled: a router with a valid neighbour entry beats a failed or missing
+# one, whatever the leaf order and with forwarding on or off, on the
+# output and on the input path
+# - enabled: unreachable routers are selected in round-robin
+# - enabled: a router whose resolution is in progress stays selected
+# - enabled: RFC 4191 preference only breaks ties between equally reachable
+# routers (needs CONFIG_IPV6_ROUTER_PREF)
+# - enabled: RFC 4191 6.2.3 router probing is suppressed (needs
+# CONFIG_IPV6_ROUTER_PREF)
+
+source lib.sh
+
+ALL_TESTS="
+ test_sysctl_default_range
+ test_disabled_forwarding_ignores_neigh
+ test_enabled_prefers_reachable
+ test_enabled_round_robin
+ test_enabled_incomplete_sticky
+ test_enabled_preference_tiebreak
+ test_enabled_no_probing
+"
+
+SYSCTL=net.ipv6.route.strict_router_selection
+
+GW1=fe80::1
+GW2=fe80::2
+# Used through indirect expansion in neigh_set()
+# shellcheck disable=SC2034
+LLADDR1=00:00:5e:00:53:01
+# shellcheck disable=SC2034
+LLADDR2=00:00:5e:00:53:02
+DST=2001:db8:ffff::1
+SRC_IN=2001:db8:100::2
+
+DUT=""
+PEER=""
+
+dut()
+{
+ ip netns exec "$DUT" "$@"
+}
+
+cleanup()
+{
+ # Kill any background ping before dropping the namespaces
+ [ -n "$ping_pid" ] && kill "$ping_pid" 2>/dev/null
+ cleanup_ns "$DUT" "$PEER"
+}
+
+setup()
+{
+ setup_ns DUT PEER || exit $ksft_skip
+
+ # No DAD, no RA/RS, no autoconf: the only NS sent on r1/r2 must be the
+ # ones we trigger ourselves. Shorten the router probe interval (in
+ # seconds, the smallest the sysctl allows) so that probing can be
+ # observed without waiting a minute. Set the defaults before the devices are
+ # created or moved so that they apply to them.
+ dut sysctl -qw net.ipv6.conf.default.dad_transmits=0 \
+ net.ipv6.conf.default.accept_ra=0 \
+ net.ipv6.conf.default.router_solicitations=0 \
+ net.ipv6.conf.default.autoconf=0 \
+ net.ipv6.conf.default.router_probe_interval=1 || exit $ksft_skip
+ ip netns exec "$PEER" sysctl -qw net.ipv6.conf.default.disable_ipv6=1 ||
+ exit $ksft_skip
+
+ ip -n "$DUT" link add dum0 type dummy || exit $ksft_skip
+ ip -n "$DUT" link add r1 type veth peer name r1p netns "$PEER" ||
+ exit $ksft_skip
+ ip -n "$DUT" link add r2 type veth peer name r2p netns "$PEER" ||
+ exit $ksft_skip
+
+ ip -n "$DUT" link set dum0 up
+ ip -n "$DUT" link set r1 up
+ ip -n "$DUT" link set r2 up
+ ip -n "$PEER" link set r1p up
+ ip -n "$PEER" link set r2p up
+
+ ip -n "$DUT" addr add 2001:db8:100::1/64 dev dum0 nodad
+
+ # Make sure link-local addresses are in place before routes use them
+ slowwait 5 dut_has_lladdr r1 || exit $ksft_skip
+ slowwait 5 dut_has_lladdr r2 || exit $ksft_skip
+}
+
+dut_has_lladdr()
+{
+ dut ip -6 addr show dev "$1" scope link | grep -q "inet6 fe80:.*scope link$" &&
+ ! dut ip -6 addr show dev "$1" scope link | grep -q tentative
+}
+
+# Pristine state for every test: both routes (and their fib6_nh and the
+# round-robin pointer) recreated, no neighbour entries, strict mode off and
+# forwarding on. Extra arguments are appended to the r1 and r2 routes
+# respectively, e.g. "pref low".
+reset_state()
+{
+ local r1_opts=$1
+ local r2_opts=$2
+
+ dut sysctl -qw "$SYSCTL=0" net.ipv6.conf.all.forwarding=1
+ while dut ip -6 route del default 2>/dev/null; do :; done
+ dut ip neigh del "$GW1" dev r1 2>/dev/null
+ dut ip neigh del "$GW2" dev r2 2>/dev/null
+
+ # "append" is needed to get two same-metric default routes
+ # shellcheck disable=SC2086
+ dut ip -6 route append default via "$GW1" dev r1 $r1_opts || return 1
+ # shellcheck disable=SC2086
+ dut ip -6 route append default via "$GW2" dev r2 $r2_opts || return 1
+}
+
+# neigh_set <1|2> <permanent|failed|none>
+neigh_set()
+{
+ local gw=GW$1 dev=r$1 ll=LLADDR$1
+
+ if [ "$2" = none ]; then
+ dut ip -6 neigh del "${!gw}" dev "$dev" 2>/dev/null
+ return 0
+ fi
+ dut ip -6 neigh replace "${!gw}" dev "$dev" lladdr "${!ll}" nud "$2"
+}
+
+# selected_gw <out|in>: print the gateway chosen by a single route lookup
+selected_gw()
+{
+ local path=$1
+
+ if [ "$path" = in ]; then
+ dut ip -6 route get "$DST" from "$SRC_IN" iif dum0
+ else
+ dut ip -6 route get "$DST"
+ fi | grep -o ' via [^ ]*' | head -n1 | cut -d' ' -f3
+}
+
+# selected_gws <out|in> <count>: gateways chosen by <count> lookups
+selected_gws()
+{
+ local path=$1 count=$2 i
+
+ for ((i = 0; i < count; i++)); do
+ selected_gw "$path"
+ done | tr '\n' ' '
+}
+
+# check_selected <out|in> <expected gw> <description>
+check_selected()
+{
+ local path=$1 exp=$2 desc=$3
+ local got
+
+ got=$(selected_gw "$path")
+ if [ "$got" != "$exp" ]; then
+ RET=$ksft_fail
+ retmsg="$desc: $path path selected '$got', expected '$exp'"
+ return 1
+ fi
+}
+
+# Lookup paths exercised by the tests. Output is a locally generated flow, in
+# is a forwarded flow: the input path hands the incoming ifindex to the route
+# scoring in place of the output interface, so the device score never matches.
+PATHS="out in"
+
+strict_supported()
+{
+ dut test -f /proc/sys/net/ipv6/route/strict_router_selection
+}
+
+# Preference support: build a case where only RFC 4191 preference can tell the
+# two routes apart (both valid, strict mode off, forwarding off so that
+# reachability-based selection is used) and see whether it is honoured.
+pref_supported()
+{
+ local ret=1
+
+ reset_state "pref low" "pref high" || return 1
+ neigh_set 1 permanent
+ neigh_set 2 permanent
+ dut sysctl -qw net.ipv6.conf.all.forwarding=0
+ [ "$(selected_gw out)" = "$GW2" ] && ret=0
+ reset_state
+ return $ret
+}
+
+test_sysctl_default_range()
+{
+ local val
+
+ RET=0
+
+ val=$(dut sysctl -n "$SYSCTL")
+ [ "$val" = 0 ] || {
+ RET=$ksft_fail
+ retmsg="default is '$val', expected 0"
+ }
+
+ dut sysctl -qw "$SYSCTL=1" 2>/dev/null
+ val=$(dut sysctl -n "$SYSCTL")
+ [ "$val" = 1 ] || {
+ RET=$ksft_fail
+ retmsg="could not set $SYSCTL to 1"
+ }
+
+ if dut sysctl -qw "$SYSCTL=2" 2>/dev/null; then
+ RET=$ksft_fail
+ retmsg="accepted out of range value 2"
+ fi
+
+ dut sysctl -qw "$SYSCTL=0"
+ log_test "strict_router_selection: sysctl default and range"
+}
+
+# Strict mode off: with forwarding on, reachability is not looked at at all and
+# the first route in leaf order wins even if its router is unreachable.
+test_disabled_forwarding_ignores_neigh()
+{
+ local path
+
+ RET=0
+
+ reset_state || { RET=$ksft_fail; retmsg="route setup failed"; }
+ neigh_set 1 failed
+ neigh_set 2 permanent
+ for path in $PATHS; do
+ check_selected "$path" "$GW1" "strict off, r1 failed, r2 valid"
+ done
+
+ # And no round-robin either with both routers unreachable
+ reset_state
+ local seq
+ for path in $PATHS; do
+ seq=$(selected_gws "$path" 4)
+ if [ "$seq" != "$GW1 $GW1 $GW1 $GW1 " ]; then
+ RET=$ksft_fail
+ retmsg="strict off, forwarding on: $path path rotated: $seq"
+ fi
+ done
+
+ log_test "strict_router_selection: disabled, forwarding on, neighbour state ignored"
+}
+
+test_enabled_prefers_reachable()
+{
+ local path fwd st1 st2 exp
+
+ RET=0
+
+ # <r1 state> <r2 state> <expected gw>
+ local cases=(
+ "failed permanent $GW2"
+ "none permanent $GW2"
+ "permanent failed $GW1"
+ "permanent none $GW1"
+ "permanent permanent $GW1"
+ )
+ local c
+
+ for fwd in 1 0; do
+ for c in "${cases[@]}"; do
+ read -r st1 st2 exp <<< "$c"
+
+ reset_state || { RET=$ksft_fail; retmsg="route setup failed"; }
+ dut sysctl -qw "$SYSCTL=1"
+ # Forwarding is already on after reset_state
+ [ "$fwd" = 1 ] ||
+ dut sysctl -qw net.ipv6.conf.all.forwarding=0
+ neigh_set 1 "$st1"
+ neigh_set 2 "$st2"
+ for path in $PATHS; do
+ check_selected "$path" "$exp" \
+ "forwarding $fwd, r1 $st1, r2 $st2"
+ done
+ done
+ done
+
+ log_test "strict_router_selection: enabled, reachable router preferred"
+}
+
+test_enabled_round_robin()
+{
+ local path seq
+
+ RET=0
+
+ reset_state || { RET=$ksft_fail; retmsg="route setup failed"; }
+ dut sysctl -qw "$SYSCTL=1"
+
+ # RFC 4861 6.3.6 rule 2: no router known reachable, rotate between them
+ for path in $PATHS; do
+ seq=$(selected_gws "$path" 4)
+ if [[ "$seq" != *"$GW1"* || "$seq" != *"$GW2"* ]]; then
+ RET=$ksft_fail
+ retmsg="$path path did not round-robin: $seq"
+ fi
+ done
+
+ # Same with FAILED entries
+ neigh_set 1 failed
+ neigh_set 2 failed
+ for path in $PATHS; do
+ seq=$(selected_gws "$path" 4)
+ if [[ "$seq" != *"$GW1"* || "$seq" != *"$GW2"* ]]; then
+ RET=$ksft_fail
+ retmsg="$path path did not round-robin with failed entries: $seq"
+ fi
+ done
+
+ # A known reachable router stops the rotation
+ neigh_set 2 permanent
+ for path in $PATHS; do
+ seq=$(selected_gws "$path" 4)
+ if [ "$seq" != "$GW2 $GW2 $GW2 $GW2 " ]; then
+ RET=$ksft_fail
+ retmsg="$path path kept rotating with a reachable router: $seq"
+ fi
+ done
+
+ log_test "strict_router_selection: enabled, round-robin of unreachable routers"
+}
+
+test_enabled_incomplete_sticky()
+{
+ local path seq
+
+ RET=0
+
+ reset_state || { RET=$ksft_fail; retmsg="route setup failed"; }
+ dut sysctl -qw "$SYSCTL=1"
+
+ # Stretch address resolution so that the entry stays INCOMPLETE for the
+ # whole test
+ dut sysctl -qw net.ipv6.neigh.r2.retrans_time_ms=20000
+
+ # Start resolving r2's address: NS goes out, nobody answers
+ dut ping -6 -c 1 -W 1 -I r2 "$GW2" &>/dev/null &
+ ping_pid=$!
+
+ if ! busywait "$BUSYWAIT_TIMEOUT" dut_neigh_incomplete r2 "$GW2"; then
+ kill "$ping_pid" 2>/dev/null
+ ping_pid=""
+ dut sysctl -qw net.ipv6.neigh.r2.retrans_time_ms=1000
+ log_test_skip "strict_router_selection: enabled, router being resolved stays selected" \
+ "could not get an INCOMPLETE neighbour entry"
+ return
+ fi
+
+ # r1 (first in leaf order) has no neighbour entry, r2 is being resolved:
+ # r2 must be selected every time, not rotated away.
+ for path in $PATHS; do
+ seq=$(selected_gws "$path" 4)
+ if [ "$seq" != "$GW2 $GW2 $GW2 $GW2 " ]; then
+ RET=$ksft_fail
+ retmsg="$path path rotated away from INCOMPLETE router: $seq"
+ fi
+ done
+
+ kill "$ping_pid" 2>/dev/null
+ ping_pid=""
+ dut sysctl -qw net.ipv6.neigh.r2.retrans_time_ms=1000
+
+ log_test "strict_router_selection: enabled, router being resolved stays selected"
+}
+
+dut_neigh_incomplete()
+{
+ dut ip -6 neigh show dev "$1" "$2" | grep -q INCOMPLETE
+}
+
+test_enabled_preference_tiebreak()
+{
+ local path
+
+ RET=0
+
+ if ! pref_supported; then
+ log_test_skip "strict_router_selection: enabled, preference breaks ties only" \
+ "CONFIG_IPV6_ROUTER_PREF not enabled"
+ return
+ fi
+
+ dut sysctl -qw "$SYSCTL=1"
+
+ # Equally reachable: preference decides
+ reset_state "pref low" "pref high" || { RET=$ksft_fail; retmsg="route setup failed"; }
+ dut sysctl -qw "$SYSCTL=1"
+ neigh_set 1 permanent
+ neigh_set 2 permanent
+ for path in $PATHS; do
+ check_selected "$path" "$GW2" "both valid, r2 pref high"
+ done
+
+ # Less preferred but reachable beats preferred but unreachable
+ reset_state "pref low" "pref high" || { RET=$ksft_fail; retmsg="route setup failed"; }
+ dut sysctl -qw "$SYSCTL=1"
+ neigh_set 1 permanent
+ neigh_set 2 failed
+ for path in $PATHS; do
+ check_selected "$path" "$GW1" "r1 pref low valid, r2 pref high failed"
+ done
+
+ reset_state "pref high" "pref low" || { RET=$ksft_fail; retmsg="route setup failed"; }
+ dut sysctl -qw "$SYSCTL=1"
+ neigh_set 1 none
+ neigh_set 2 permanent
+ for path in $PATHS; do
+ check_selected "$path" "$GW2" "r1 pref high missing, r2 pref low valid"
+ done
+
+ log_test "strict_router_selection: enabled, preference breaks ties only"
+}
+
+nsol_out()
+{
+ dut awk '/Icmp6OutNeighborSolicits/ { print $2 }' \
+ "/proc/net/dev_snmp6/$1"
+}
+
+test_enabled_no_probing()
+{
+ local before after
+
+ RET=0
+
+ # Positive control: without strict mode (and with reachability-based
+ # selection, i.e. forwarding off) a lookup probes the routers it has no
+ # neighbour entry for with an NS (RFC 4191 6.2.3)
+ reset_state || { RET=$ksft_fail; retmsg="route setup failed"; }
+ dut sysctl -qw net.ipv6.conf.all.forwarding=0
+ sleep 1.2 # let the (shortened) probe interval elapse
+ before=$(nsol_out r1)
+ selected_gw out > /dev/null
+ if ! slowwait 3 ns_nsol_increased r1 "$before"; then
+ log_test_skip "strict_router_selection: enabled, router probing suppressed" \
+ "router probing not available (CONFIG_IPV6_ROUTER_PREF)"
+ return
+ fi
+
+ # Same with strict mode: fresh routes (probe rate limit state is per
+ # route), no NS may leave
+ reset_state || { RET=$ksft_fail; retmsg="route setup failed"; }
+ dut sysctl -qw "$SYSCTL=1" net.ipv6.conf.all.forwarding=0
+ sleep 1.2
+ before=$(nsol_out r1)
+ selected_gw out > /dev/null
+ selected_gw in > /dev/null
+ sleep 1
+ after=$(nsol_out r1)
+ if [ "$after" != "$before" ]; then
+ RET=$ksft_fail
+ retmsg="r1 sent $((after - before)) NS in strict mode"
+ fi
+
+ log_test "strict_router_selection: enabled, router probing suppressed"
+}
+
+ns_nsol_increased()
+{
+ [ "$(nsol_out "$1")" -gt "$2" ]
+}
+
+trap cleanup EXIT
+ping_pid=""
+
+require_command ip
+require_command ping
+require_command awk
+
+setup
+if ! strict_supported; then
+ echo "SKIP: $SYSCTL not available"
+ exit $ksft_skip
+fi
+
+for t in $ALL_TESTS; do
+ $t
+done
+
+exit "$EXIT_STATUS"
--
2.34.1
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-30 22:27 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-30 22:26 [PATCH net-next 0/2] net: ipv6: add strict RFC 4861 6.3.6 default router selection Florian Fainelli
2026-11-30 22:26 ` [PATCH net-next 1/2] " Florian Fainelli
2026-11-30 22:26 ` [PATCH net-next 2/2] selftests: net: add test for ipv6 strict_router_selection Florian Fainelli
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®