Skip to contentSkip to conversation

net: ipv6: add strict RFC 4861 6.3.6 default router selection

PATCH New Florian Fainelli 1 participant 3 messages Nov 30

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

cover net: ipv6: add strict RFC 4861 6.3.6 default router selection

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
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/2 net: ipv6: add strict RFC 4861 6.3.6 default router selection

From: Angus Peng <[email protected]>

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.

[florian: commit message, comments, forward porting]
---
 Documentation/networking/ip-sysctl.rst |  29 +++++++
 include/net/netns/ipv6.h               |   1 +
 net/ipv6/route.c                       | 101 ++++++++++++++++++++++++-
 3 files changed, 129 insertions(+), 2 deletions(-)
Documentation/networking/ip-sysctl.rst +29 -0
index 671011c74e14..0ea2d7818ea2 100644
@@ -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
include/net/netns/ipv6.h +1 -0
index aefce37c04a4..e34b3f846288 100644
@@ -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;
net/ipv6/route.c +99 -2

143 lines not on this page · raw message

Signature · 1 line
2.34.1
#2 lore raw

PATCH 2/2 selftests: net: add test for ipv6 strict_router_selection

In reply to Florian Fainelli

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.

---
 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
tools/testing/selftests/net/Makefile +1 -0
index fb0a64662053..caa92d9ff0ae 100644
@@ -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 \
tools/testing/selftests/net/ipv6_strict_router_select.sh new file +507 -0

507 lines not on this page · raw message

Signature · 1 line
2.34.1