From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.217.97 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796077653; b=e82Q5GnQAereup1u35sDgJisvuM2Ps3r6g/1AI90yWfKyZTG5p2atcx1Bi+8n0aKPbUC QcPhK062xvbiY2v2diUjktBRWtj9RMLcASX/Tp7SysDxohIG3bjGL6p29ILOcOf6zlp/N P48lRQLPizfv66peL7B/uHORnNOVcIATZAZw44woVhI5ouyWp4lXjegaYQvqFIUldtEJc G45VJQU8TwABIJoilmFbjD0mniUnY9amN46VrBGGIYigO8F4C43AC3VJODJX39dxYPMxz qR97ORPBwoyO+hXzIMd83257RpcrhoBQ6NWro7R/odWdgYrq9WhlTataU4SePyJd6JA== 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-Forwarded-Encrypted: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:X-Relaying-Domain: X-CFilter-Loop:Received:DKIM-Signature:X-Forwarded-Encrypted: 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=iw3u0JuEufnSMWwtEgj9HNd77iqRA5VsZeU8Lw+nRo4hP9JM+MBKl+PWM7UOeZpciOzV 757U7DGB6HpLfASZeTVx6uTxMSYAVMheR+93WBqf/OzQca/ShSH3XrpaZIo450N0aTApZ VRI3qCHlXjNh3weikznsv/fGMLHua5rUoovYEsHrPb02GPkOo17QHyWeu2v9Recmlnkk7 7K5Xhkc5JDYMqCQOaIqkUUuh1B5Z0lX+kTsqyCjRn74r6FwLzGSZ8cXVLxPN/jQcAoxNr tIQkLhv0s+KQzro4NYuVddOXaJLYQIj9q9i5ijeUewc2tYsQ41EJnpI/TqzZeLfLvSw== 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.217.97 Received: from mail-vs1-f97.google.com (mail-vs1-f97.google.com [209.85.217.97]) (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 CD083606A32C for ; Mon, 30 Nov 2026 22:27:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org CD083606A32C 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-vs1-f97.google.com with SMTP id ada2fe7eead31-7d2db6408cfso6210564137.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=IeJpqAuVlztMYc4igko/6Ov6D6O4+FWmIOV7AYPKGfzJh8Xk7hEocWnEp4yVGS2mw8 xtyzW2M/Hah70MoIcnHUltbtH2jsbIvGgmZAgdjVlK/TKOLs1/Igm9Ial01F6M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dXHT8vqwlKEGTleGiSxHmAKiQ1fvHiqa S/OjsMuzjk0LLENN/XTqfdb+lB8eJbcBC2Aas5Iszz X-Received: by 2002:a05:6102:1610:b0:7d2:8dd0:2eb with SMTP id ada2fe7eead31-7d7393ff1d8mr20210337137.8.1796077651728; Mon, 30 Nov 2026 14:27:31 -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 a1e0cc1a2514c-99e6e1b27b8sm2688509241.18.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:31 -0800 (PST) X-Relaying-Domain: broadcom.com X-CFilter-Loop: Reflected Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-921246186bfso213672296d6.0 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-Forwarded-Encrypted: i=1; AL+hErHs/3xblW50smTN+pIp6DKDClhJ8IP0syByPT5kfdxY1nHB09MuYB7qoHndjrJWafcQZW8AE8eNR+OValg=@vger.kernel.org X-Received: by 2002:a05:6214:3d12:b0:921:19dd:3ccd with SMTP id 6a1803df08f44-92134a3a099mr672684416d6.18.1796077650643; 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: linux-kernel@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