From: Florian Fainelli <florian.fainelli@broadcom.com>
To: netdev@vger.kernel.org
Cc: Angus Peng <angus.peng@broadcom.com>,
Florian Fainelli <florian.fainelli@broadcom.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Hideaki YOSHIFUJI <yoshfuji@linux-ipv6.org>,
David Ahern <dsahern@kernel.org>, Shuah Khan <shuah@kernel.org>,
Kuniyuki Iwashima <kuniyu@google.com>,
Jiayuan Chen <jiayuan.chen@linux.dev>,
Maoyi Xie <maoyi.xie@ntu.edu.sg>,
linux-kernel@vger.kernel.org (open list),
linux-kselftest@vger.kernel.org (open list:KERNEL SELFTEST
FRAMEWORK),
bcm-kernel-feedback-list@broadcom.com
Subject: [PATCH net-next 1/2] net: ipv6: add strict RFC 4861 6.3.6 default router selection
Date: Mon, 30 Nov 2026 14:26:30 -0800 [thread overview]
Message-ID: <20261130222631.1786545-2-florian.fainelli@broadcom.com> (raw)
In-Reply-To: <20261130222631.1786545-1-florian.fainelli@broadcom.com>
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
next prev parent reply other threads:[~2026-11-30 22:27 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 22:26 [PATCH net-next 0/2] " Florian Fainelli
2026-11-30 22:26 ` Florian Fainelli [this message]
2026-11-30 22:26 ` [PATCH net-next 2/2] selftests: net: add test for ipv6 strict_router_selection Florian Fainelli
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261130222631.1786545-2-florian.fainelli@broadcom.com \
--to=florian.fainelli@broadcom.com \
--cc=angus.peng@broadcom.com \
--cc=bcm-kernel-feedback-list@broadcom.com \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=jiayuan.chen@linux.dev \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=maoyi.xie@ntu.edu.sg \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=shuah@kernel.org \
--cc=yoshfuji@linux-ipv6.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®