From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.215.225 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796077656; b=vegqW3hhDuofEPHbJes/weB5Dtsd/2F7vGaCOArWTBv8rIlWka7ZhUGdK1f9qVWm0fkE yUJUVmXLfY7zlNa+OwLDT1HY/UunEax4CCb0sNeSEMH6itzvHMha7+Z4EwFhVEzcMa0ja BwwbWMwygrUqNqp3UupN7eV7EFTfHXsUfxiETvGsZ5pNSbSOCjkN5q11l0HNeZBcR+UJf tZJKByuxecV2/4IX0i1DtvWmxUv7vyEhTnz/la7T2v97RusECWeUT623d6UQIPDQXp3iy vg3e+C/6YZ0W2PjCxkp2ndq6ei2SULg9ucVG3g1A7GOSuCG1PiacbTaJrTtXk+ziCJg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796077656; 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=wLxrnvg0J78AlS/hdInbhMQRHEpQpqY5HBRZHe0epHg=; b=xAXliMmRFimTJJ1eLP/3IeI1H7/ynhniILWkiNoERhJ/xOwPaHvQs95nLdHXBVqcrzT6 LYeE/0HBxSDIXubUkvb/YcxIORZeQtGaDZRovbz6vqxOOLkHdeeE6+gQcj0usjBJjd7Kn G+6tkhrPJM/Qsaqf8O9FmY1ZDH2pLdmxgb2Y6wjxKGKDH78Y+EEjalCQGItDp09mVQIBC ceTXD6hcPmBN4lQ9VgDwdTFhUBF+eTDj4IkNDzu5XYa+qBkyltOCvOFTFjGrIVam7MT2C cY+x2mEcc4Ez+Jzyq9SU18cMqN8y7ysHNQ+58NYl04Ve7BtssnChgOe8Vx/Dlm/GdUA== 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=Hx8CDI8Y; arc=none smtp.remote-ip=209.85.215.225 Received: from mail-pg1-f225.google.com (mail-pg1-f225.google.com [209.85.215.225]) (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 5D884606A68E for ; Mon, 30 Nov 2026 22:27:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5D884606A68E 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=Hx8CDI8Y Received: by mail-pg1-f225.google.com with SMTP id 41be03b00d2f7-cdb75699c7cso4225977a12.2 for ; Mon, 30 Nov 2026 14:27:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796077655; x=1796682455; 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=wLxrnvg0J78AlS/hdInbhMQRHEpQpqY5HBRZHe0epHg=; b=Uq+Mk4qelVZ9rqdHIEuYaAl6lmglTjdmtPrkkFhJ/t0D4F+l+ufwG+JLPZiUYjhWMX Hcor6ZBlNujvhhOAyKNZMK4IMfkTiH7mzoXkN5vzmSTuZSdtyuQpX7nSbWFKNFuTVWco kBk2F7K7s09ycoV3zKQDOyzpNfZPmUMaT8d9S6nu6GM/xxehcYZ6emt2nqirkzqnekKB dUPjG/+hPNmSc7b+zAlegEkQgl3M9pVeCjMEllOCGXgF0WPB4GnYIBNaWx9qQANppNtM gEylwNFr1TInFTOuKudmHv4DIjO6eiB63uR4ZuCe4LOy4PWcgxVC+nwpeNWtjHMRUAXB sc7g== X-Forwarded-Encrypted: i=1; AL+hErFIkkZclNx+wffGN2NkmfCBjbbBzcfaBMFMDCYeqSrpugCCP8r+8XIUYD4LKflvTU0JGq/e/w56BVyfIkQ=@vger.kernel.org X-Gm-Message-State: APuU4Z/tldmpGHIOGgseO6htRlM0V0gdCu7c6sWrs5hRaJAH+zkRMhcZ I7Kl+ou25kESKp8Mu1s00dMDgiybwdF5wYzt6t3VS07mGUirwAMdMoYQhKH0VDfA4KjUaOgn1oo 5lWxuAMiQ6hmk2bAvG5ZucWbvumjWAWpVTqNNJomGuXm8tBmtR0UNPYPmr0fS0ma7/3F6MlROuZ LTzSPBpUO7CqYi+EmmJMWAqVFV5u1iMx6aGWXZHjJTFhK6vRP5q0AxsgEpuMFmebINOAaqoS6wS kEOhvFSIRmeTmDCFmQKEbWb X-Gm-Gg: AZFdTZeVSLMdQjiGUr0jdV2aaUdaA3I3ZMwDlgQxGO3kzUadDilSegGt9g63RXBKzUz T+Rx7emlNF6B+0tEscx4p49TCYeVVqfVXM+59qREQ4f8bq7s51czlrplI+NH8N5OJhghiSeGEb3 ut86oq3snVijZVpFC4X+R+NzvODNIc/EzBNRoKmqZqQZPsCW1ojrOvcDV6vjvlhV42xFS2sjzgX aGAoyMFV9r6JajEG08DBDG/XAl4cQWoIiIAk9Q8u4ErRm7+SqGItn18+GPoHSjCVEH6lFmEWIH7 ncItRUKL1akQjpgR5C181z6jIPMf4cKJmsShAZDtiKPFdhDhAPiRZtzxsuIfW1gCuIkAm9r/1Xv O56iaaZFzyLcTv+SwSCAzGK+93c1+jN6kjc1GAkUBjQ4o5xbY70ZG3MNzKcwu9X5kPrTnGRlz2Z 8wSwB/Y5bbd153OOWfzhuGXH9LD2VXsqm8+uc9uc+RHAk= X-Received: by 2002:a17:90b:2c86:b0:3ac:b44c:2d84 with SMTP id 98e67ed59e1d1-3b41c8d5579mr35494811a91.13.1796077654488; Mon, 30 Nov 2026 14:27:34 -0800 (PST) Received: from smtp-us-east1-p01-i01-si01.dlp.protect.broadcom.com (address-144-49-247-100.dlp.protect.broadcom.com. [144.49.247.100]) by smtp-relay.gmail.com with ESMTPS id 98e67ed59e1d1-3b41ac86baasm22036622a91.1.2026.11.30.14.27.34 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 Nov 2026 14:27:34 -0800 (PST) X-Relaying-Domain: broadcom.com X-CFilter-Loop: Reflected Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-9213659143bso140696676d6.0 for ; Mon, 30 Nov 2026 14:27:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1796077653; x=1796682453; 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=wLxrnvg0J78AlS/hdInbhMQRHEpQpqY5HBRZHe0epHg=; b=Hx8CDI8YpAuCz9lhn/6hJWkEmVRgbNJYys3tyz/ZdjlXLrEa+9A3KekDtisw1pC3K0 kiSoiHYuD3bAHLj32IIS1vKULyQl+KN8BTWYel7nLV8oC1r9VA6nq1Iw97hJTtm+fb8u CFAB0s0LzwO1OM5E9m0GCjrFqsEnPI3IjydOg= X-Forwarded-Encrypted: i=1; AL+hErFbNLvSSxgBaubEZrtfYNxrtfHZaUx3Hh06F4WdUy//4vz6/bqQpEZ4zTR8OQM1jpS8TiUCQXgESt1id7k=@vger.kernel.org X-Received: by 2002:a05:6214:2628:b0:921:1d38:7766 with SMTP id 6a1803df08f44-92134a856a8mr642013726d6.35.1796077653012; Mon, 30 Nov 2026 14:27:33 -0800 (PST) X-Received: by 2002:a05:6214:2628:b0:921:1d38:7766 with SMTP id 6a1803df08f44-92134a856a8mr642013356d6.35.1796077652377; Mon, 30 Nov 2026 14:27:32 -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.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 14:27:31 -0800 (PST) From: Florian Fainelli To: netdev@vger.kernel.org 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 , 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 2/2] selftests: net: add test for ipv6 strict_router_selection Date: Mon, 30 Nov 2026 14:26:31 -0800 Message-Id: <20261130222631.1786545-3-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 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 --- 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> +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 : 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 : gateways chosen by lookups +selected_gws() +{ + local path=$1 count=$2 i + + for ((i = 0; i < count; i++)); do + selected_gw "$path" + done | tr '\n' ' ' +} + +# check_selected +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 + + # + 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