From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.215.227 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796077653; b=IcyUJPNHphoxF7n7QfCTQ+m5vQ7BrxYgnUMONb3UDoOR8QcMzJLsegIRk8uFKqbT2QUX gjoAYxUb2qenfT8zGO08ARTGRiT4iBwSfLNFP/kpqEbZAdfCP9r4YSlXFKIDb6+ZiqAgT LZ3dGmGegGHtDdegBkc2Ec33i7VYpzP8tEnr/2+f/0UT6HNm6KwJPRYR8dZ4b2WFhe7LX HuiqcDxEKGSA1BbKWzt0mjH+atbgTy1pzgv7ByGJjdL3wqVymDXN0EZ9a9uETjEbJuSLU OSM9UEJ6LvOqcD+6PKTtxx8WrV6+u6/eAj8tKFwc3Ejz4DlQ1mc+WylRenuOajetBPg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796077653; h=DMARC-Filter:Received:X-Google-DKIM-Signature:X-Gm-Message-State: X-Gm-Gg:X-Received:Received:X-Relaying-Domain:X-CFilter-Loop:Received: DKIM-Signature:X-Received:X-Received:Received:From:To:Cc:Subject:Date: Message-Id:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-DetectorID-Processed; bh=QMolIHZGGlbNbJ4NMyCKFNLnx6rGkoWye4mzJ5l/o0A=; b=br3Xfm2c96mH1DBdVZXOrrJz4pa54U7IejVtODTjo82FM8q2Ec0LUv9bi72A1Fadi16n M8dNGh0QrmtctnHI/sAVfjbI1aCvQAwwsGupCNaE4p39JCaQ5YU3FgZtr9/gtH04vd80z bu5p6ePj78Cq6lEyx3BtDlT/2mjPDgRyzWGuEOzm2RO4gU8C0VqUXhFQDKPgqGWlCWf66 +M40hI4Mj+ovi8f3eUn884pEYObE0ncqfGAGcxq3W/ucVRu/vdWjXE5/w2lQBblpew3ec hYgwLZH4nt7dPCWimijIhWE9gkH0btzSjciuvUg0MDCjQhKCY0/G0rgPTv1Bj9eTqRg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=broadcom.com; spf=fail smtp.mailfrom=broadcom.com; dkim=pass header.d=broadcom.com header.i=@broadcom.com header.a=rsa-sha256 header.s=google header.b=RnEZgC4b; arc=none smtp.remote-ip=209.85.215.227 Received: from mail-pg1-f227.google.com (mail-pg1-f227.google.com [209.85.215.227]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BAF04606A32A for ; Mon, 30 Nov 2026 22:27:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BAF04606A32A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=broadcom.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=broadcom.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.a=rsa-sha256 header.s=google header.b=RnEZgC4b Received: by mail-pg1-f227.google.com with SMTP id 41be03b00d2f7-cdb1199bfd8so5136349a12.1 for ; Mon, 30 Nov 2026 14:27:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796077652; x=1796682452; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=QMolIHZGGlbNbJ4NMyCKFNLnx6rGkoWye4mzJ5l/o0A=; b=dGkimcLlDhz4KQRQZEhivj4qBPnZfHI60ZWl7OH9VnLOV6exqdN2NBKDEdKI8AaJEA 6G8TDWMFRXXonQ7REIEIq6slcFsCMJhThTfeTZRolbJFFGpEDzSrL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SMTP id 98e67ed59e1d1-3b41c7b5dedmr32603213a91.4.1796077652015; Mon, 30 Nov 2026 14:27:32 -0800 (PST) Received: from smtp-us-east1-p01-i01-si01.dlp.protect.broadcom.com (address-144-49-247-28.dlp.protect.broadcom.com. [144.49.247.28]) by smtp-relay.gmail.com with ESMTPS id 98e67ed59e1d1-3b42005a1a1sm22609922a91.0.2026.11.30.14.27.31 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 Nov 2026 14:27:32 -0800 (PST) X-Relaying-Domain: broadcom.com X-CFilter-Loop: Reflected Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-91256a7b7b3so160784766d6.2 for ; Mon, 30 Nov 2026 14:27:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1796077651; x=1796682451; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=QMolIHZGGlbNbJ4NMyCKFNLnx6rGkoWye4mzJ5l/o0A=; b=RnEZgC4bCt2O5+G4N0wLcWGU0fwhPLGa3PuzyBUGI6CBJNgswL9xdNuyN795tToENN vme9IxqpFKUkRxza+v1/BFAObVqexNcB+d5/2sDsFdRbI+fJ7gwmOLCNVOqL7z4FjYNT jeQ9nWPPdVSsE72Ol4A1rPSplyOCNuXQuf/KE= X-Received: by 2002:a05:6214:3d12:b0:921:19dd:3ccd with SMTP id 6a1803df08f44-92134a3a099mr672684626d6.18.1796077650745; Mon, 30 Nov 2026 14:27:30 -0800 (PST) X-Received: by 2002:a05:6214:3d12:b0:921:19dd:3ccd with SMTP id 6a1803df08f44-92134a3a099mr672683746d6.18.1796077650051; Mon, 30 Nov 2026 14:27:30 -0800 (PST) Received: from stbirv-lnx-1.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-9213514d20esm308051906d6.23.2026.11.30.14.27.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 14:27:29 -0800 (PST) From: Florian Fainelli To: netdev@vger.kernel.org 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 , 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 Message-Id: <20261130222631.1786545-2-florian.fainelli@broadcom.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261130222631.1786545-1-florian.fainelli@broadcom.com> References: <20261130222631.1786545-1-florian.fainelli@broadcom.com> X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-DetectorID-Processed: b00c1d49-9d2e-4205-b15f-d015386d3d5e From: Angus Peng 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 [florian: commit message, comments, forward porting] Signed-off-by: Florian Fainelli --- 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