From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.171 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796185945; b=lj3+iEZRtanmspdZ7Gtyf72THpd4gtJZvvPgpayeKIzwIc57L2p7C75F8ZwNX+dHiUaw TsF1oRa49aqQ6JqQiriB/mC8wbTXZ/BJFwIsBqccEp2B4W97qjAdHXnUP5t70XBTm6efm h9uhvVtSObHsexhNeZFjExfba28Vyy0EvlT1lklDjRxD+VPp1x2Ybx00M6xHX6vd7RZiu 25aYJUlvaBiKlK8mbwRdkiu32S5xAJZF2oKu1qX3AF1S+5Pf94+OmMtdKArJTMfH3CcSP MFkgn7y64erSCLT3pffChtITQjQcmHgeN9rHYMazv7HcuznNK0fvK/12bAgodhPkiNw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796185945; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=aibGGVkx2Kn/6IvuTL0H0V7rB0q+3sTIB/rdnY+QSy8=; b=zH21vDhwz7VAz2BdCgU2Ek+Il3Qr4HpUgNnpzPHPmt38+UqE6zf24w6Y74lZ4WMlWFvY K7hBBseI3hklVF4/m+hcDP+EAl1GtV6nnmtXWhIks6sLkBUYQ2HxxuPT5EEi59OMkNVEt xptoNNrMKuULVe0wWzDCC3DnMgR6y2vl+dXAYAxWuVjuHehCMgKShK0eCZb/+1G40JDpz KwRPB+GhGjvXWJ1J3Zh6TlDVpstVJoTO0jsG6Xd49n5wEsLooAgJtN92yK3ef0y62HcNa 0wcs9pZWVFdTJ23bDqDwO5vF74+TaZOb2uOGmaFPIlNP1MYuatnPCCjm5uPAzKdPB9Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=blockcast.net; spf=pass smtp.mailfrom=blockcast.net; dkim=pass header.d=blockcast.net header.i=@blockcast.net header.a=rsa-sha256 header.s=google header.b=P29H3Hvg; arc=none smtp.remote-ip=74.125.82.171 Received: from mail-dy1-f171.google.com (mail-dy1-f171.google.com [74.125.82.171]) (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 9953C606A33B for ; Wed, 2 Dec 2026 04:32:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9953C606A33B Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=blockcast.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=blockcast.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=blockcast.net header.i=@blockcast.net header.a=rsa-sha256 header.s=google header.b=P29H3Hvg Received: by mail-dy1-f171.google.com with SMTP id 5a478bee46e88-38692f62b22so1944046eec.0 for ; Tue, 01 Dec 2026 20:32:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=blockcast.net; s=google; t=1796185944; x=1796790744; 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=aibGGVkx2Kn/6IvuTL0H0V7rB0q+3sTIB/rdnY+QSy8=; b=P29H3HvgzMAuARlVvsXqQHXtbrOsnrP3wr2aXGk5zZmWehnNRR3FJlnONgRdCDVrYl dN1aY8eSfvW3pz5JCAyjqApQz1sOYAPHCpxhOsUGo04msUnmm7WY7WGRIth0LLRsma8i L92jKujE5o2c4U4G4T6LMfZw+i4gmDQF1fg/aYHQLLs6YEP1Ij/MfkQeLoQRhrgQfbcp w60neffa3oEo2ainZFKRqlj9Bdlha/GbZv0AgdZ8q24bAFhm2PXCrqkSKnq4TvFJuZH8 ko9dTvjIfiloXtv5+aDSTMB3mod9qBP+eiwcgNIxHSUHvniYFsRZTHeSdNoSyShuXtn7 ahbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796185944; x=1796790744; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=aibGGVkx2Kn/6IvuTL0H0V7rB0q+3sTIB/rdnY+QSy8=; b=Oje5C3qSCH8fxg7RD1/q18WwriY4szt/SyLLhQWtYhG/7ZQQBIXpdA8Vt0wpwLzm2i VzCY8UX04xJ+O/xWW3amEh7R9GPEq4/gwoXX625+U79j9IDs1MoJCWANVI0HEdtV43Ly pjE9iEZXOC74QQbJmCg2dtHgoJd4Qta/He8NfW3t0u4lpdZTe1BvsXfi323ik41sJY8X R0zV8MQgmLbWLoX9gOK9+aS5QYMHsrWZkqduPQequwGa8FrNAtKOa2tFHSSHQ0pAiydU xI26zT2klappUSmbwr3x2ev44V3NBWctDqSxDnfWEx6USRKAGV49XU0BTik5KQNrYK85 O5VQ== X-Forwarded-Encrypted: i=1; AL+hErFwBA+xFEpLmWVrlMBTsT4sVVZOTS/F55Wv0MHQPLyMiRHocbGxw/DaF+frMPK67HUCQ2VdKrgby5XegQI=@vger.kernel.org X-Gm-Message-State: APuU4Z/FbjZ0F+m7bnhyswGh/YaoQv3l6nhfyMnyX0yWvBC/C6GxjUN5 JXlpN4ei3GF8KUuArKUWWiUrVkVH5ft6DcGhsajznisnvEbD7Juv8NQ60kHfAU/8GPY= X-Gm-Gg: AZFdTZevVWZa/YZuaaj5kIieCc0bv3LsK++BdHgfsELHWgEE3/pk1UTsRigXiKjzv2v 1BGMARpHvGAVNEro7egh5hgHQB9/biskMgXHlitvSKYRAXWzmnZqUYkvTUkLqbgfcRVnUlXLf4S 8NVgFJQsGXPjiGeTcofndCDwqUVtQyvl+OBgM5JBGaHs3UMhx6Yhu5WHVgdH0IOuQ2n3RMANob8 NK+7rEeA9UlvWwsqTqNT3PX318ZxRpkpf4BGz0YCqeV/JNSrcZyw3hMaODguu397U/qa2j1RiFI L1SFDtV1TPgxIpvXAB/pq6y4cQX5zmA3ZROMtKKX6FkjLzrYxWm7Fr1amcBqCqSJv4HRNnwrsou vUoW2TX/leLoC1uyV3lDl9F52gSqHzEBf4QEHkfdq2Xek8YSGckP0+ZPDpHeCOT2Sw7whKzmFGx TGZrBwibDOxYjC68mJl8CvU+RBZDELPQsTYBKX3CsvZ3Qy8aP7JV+vrKWVt5rubq1Yh+EHJJBXf kfcxRicRNngyWLW/DoBYBFT5oc7EMVXDAAR/TwYkfiJwu9f1rKsfh61O7BzlzlNWhPFABciX9Kf Qb3E+sDRlhSU+BhS1jpdHuCIir4F83AjCx750VeTHWpa6Po8MYH/n+zPcIIrHhzGMAI801+5nRe opckcoJtGA06lmiWf+QNfHb26pFQ= X-Received: by 2002:a05:7300:f0c2:b0:386:688:7f25 with SMTP id 5a478bee46e88-386068880f5mr40952802eec.18.1796185943639; Tue, 01 Dec 2026 20:32:23 -0800 (PST) Received: from devbox.ts.blockcast.net ([2602:f74d:1::32]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-386d605c894sm54632028eec.2.2026.12.01.20.32.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 20:32:23 -0800 (PST) From: Omar Ramadan To: Taehee Yoo , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Shuah Khan Cc: Simon Horman , netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Willem de Bruijn , David Ahern , Ido Schimmel Subject: [PATCH net-next v6 12/12] selftests: net: add amt_gw_v6.sh for the IPv6 netlink attributes Date: Wed, 2 Dec 2026 04:32:00 +0000 Message-ID: <20261202043200.286260-13-omar@blockcast.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261202043200.286260-1-omar@blockcast.net> References: <20261202043200.286260-1-omar@blockcast.net> 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 amt_v6.sh checks the data plane with valid attributes only. The link-creation rules for IFLA_AMT_LOCAL_IP6 and IFLA_AMT_DISCOVERY_IP6 are not exercised. This adds a companion without a data plane: one netns and one dummy device. It checks that the IPv6 local and discovery addresses of a gateway, and the local address of a relay, read back through amt_fill_info(), that a relay reports no discovery address, that an IPv4 gateway still creates and reports its IPv4 discovery address, and that an IPv4 relay still accepts the IPv4 discovery address it has always ignored. It then checks each rejection: a gateway without a discovery address, a gateway whose local and discovery addresses differ in family, an IPv6 relay given a discovery address of either family, an IPv4 relay given an IPv6 one, and an unspecified, loopback, multicast or IPv4-mapped IPv6 local or discovery address. Each is matched on its extack message, so a rule that fails for the wrong reason is not a pass. The unspecified and multicast cases need iproute2 to pass those addresses on as given, which it does: ip/iplink_amt.c tests is_addrtype_inet(), true for "::" and multicast, and the IPv6 branch of the iproute2 patch adds its attribute without a test. Not covered, as iproute2 cannot express them: both `discovery ` and `discovery `, or both `local` forms, in one command, and a 16-byte IFLA_AMT_LOCAL_IP or IFLA_AMT_DISCOVERY_IP. The probe skips on an iproute2 without IPv6 AMT support: one that rejects the literal or does not know amt, or that packs the 16-byte literal into the IPv4 attribute. This kernel refuses that with "binary attribute size out of range", logged as a passing test before the skip; a kernel without that rule truncates it to an IPv4 address (`discovery 2001:db8:a::2` reads back as 32.1.13.184), and the probe skips on that readback only. It also skips on a kernel that ignores the attributes ("Local attribute is required"), has no amt ("Unknown device type") or no IPv6. Any other failure to create the probe link, and any other readback without a colon, is a FAIL. Assisted-by: LLM Signed-off-by: Omar Ramadan --- tools/testing/selftests/net/Makefile | 1 + tools/testing/selftests/net/amt_gw_v6.sh | 205 +++++++++++++++++++++++ 2 files changed, 206 insertions(+) create mode 100755 tools/testing/selftests/net/amt_gw_v6.sh diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile index a31f19e9f..bd6c08d11 100644 --- a/tools/testing/selftests/net/Makefile +++ b/tools/testing/selftests/net/Makefile @@ -9,6 +9,7 @@ CFLAGS += -I../ TEST_PROGS := \ altnames.sh \ amt.sh \ + amt_gw_v6.sh \ amt_v6.sh \ arp_ndisc_evict_nocarrier.sh \ arp_ndisc_untracked_subnets.sh \ diff --git a/tools/testing/selftests/net/amt_gw_v6.sh b/tools/testing/selftests/net/amt_gw_v6.sh new file mode 100755 index 000000000..8f18df024 --- /dev/null +++ b/tools/testing/selftests/net/amt_gw_v6.sh @@ -0,0 +1,205 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# +# Netlink coverage for IFLA_AMT_LOCAL_IP6 and IFLA_AMT_DISCOVERY_IP6 and the +# rules that validate them; amt_v6.sh covers the data plane. Not covered, as +# iproute2 cannot express them: `discovery` or `local` in both families in one +# command, and a 16-byte IFLA_AMT_LOCAL_IP or IFLA_AMT_DISCOVERY_IP. + +source lib.sh + +readonly V6_LOCAL="2001:db8:a::1" +readonly V6_DISC="2001:db8:a::2" +# What an iproute2 that packs the literal into a 4-byte attribute reads back. +readonly TRUNC_DISC="32.1.13.184" +readonly V4_LOCAL="192.168.0.1" +readonly V4_DISC="192.168.0.2" + +# add_amt : create an amt link on gw_dev, stderr in $ADD_ERR. +add_amt() +{ + local name=$1; shift + + ADD_ERR=$(ip -n "$GW" link add "$name" type amt dev gw_dev "$@" 2>&1) +} + +# amt_field : one attribute as amt_fill_info reports it. +amt_field() +{ + ip -n "$GW" -d -j link show "$1" 2>/dev/null | + jq -r ".[0].linkinfo.info_data.$2 // empty" +} + +# Probe on the readback, not only the exit code: an iproute2 without the IPv6 +# attributes may pack the literal into the 4-byte attribute, which this kernel +# refuses and an older one truncates. Skip only for missing IPv6 AMT support. +probe_v6_gateway() +{ + local got + + if ! ip link help 2>&1 | grep -q amt; then + echo "SKIP: missing amt support in iproute2" + exit "$ksft_skip" + fi + + if ! add_amt amtprobe mode gateway local "$V6_LOCAL" \ + discovery "$V6_DISC"; then + case "$ADD_ERR" in + *"binary attribute size out of range"*) + # An older iproute2: the exact attribute length refused + # the 16 bytes. + RET=0 + log_test "16-byte IPv4 address attribute is refused" + echo "SKIP: iproute2 lacks IPv6 AMT support" + exit "$ksft_skip" + ;; + *"Local attribute is required"*|*"expected rather than"*|\ + *"IPv6 support is disabled"*|*"Unknown device type"*) + echo "SKIP: no IPv6 AMT support: $ADD_ERR" + exit "$ksft_skip" + ;; + esac + echo "FAIL: cannot create an IPv6 gateway: $ADD_ERR" + exit "$ksft_fail" + fi + got=$(amt_field amtprobe discovery) + ip -n "$GW" link del amtprobe + if [[ "$got" != *:* ]]; then + # Only a truncated literal is a skip; any other readback is a + # FAIL. + if [ "$got" != "$TRUNC_DISC" ]; then + echo "FAIL: discovery read back as '$got'" + exit "$ksft_fail" + fi + echo "SKIP: iproute2 lacks IPv6 AMT support (read back '$got')" + exit "$ksft_skip" + fi +} + +test_v6_gateway_roundtrip() +{ + RET=0 + add_amt amtg6 mode gateway local "$V6_LOCAL" discovery "$V6_DISC" + check_err $? "create failed: $ADD_ERR" + [ "$(amt_field amtg6 discovery)" = "$V6_DISC" ] + check_err $? "discovery did not read back as $V6_DISC" + [ "$(amt_field amtg6 local)" = "$V6_LOCAL" ] + check_err $? "local did not read back as $V6_LOCAL" + ip -n "$GW" link del amtg6 2>/dev/null + log_test "v6 gateway: discovery round-trips through fill_info" +} + +test_v6_relay_roundtrip() +{ + RET=0 + add_amt amtr6 mode relay local "$V6_LOCAL" + check_err $? "create failed: $ADD_ERR" + [ "$(amt_field amtr6 local)" = "$V6_LOCAL" ] + check_err $? "local did not read back as $V6_LOCAL" + [ -z "$(amt_field amtr6 discovery)" ] + check_err $? "a relay reported a discovery address" + ip -n "$GW" link del amtr6 2>/dev/null + log_test "v6 relay: local round-trips, no discovery reported" +} + +test_v4_gateway_unchanged() +{ + RET=0 + add_amt amtg4 mode gateway local "$V4_LOCAL" discovery "$V4_DISC" + check_err $? "create failed: $ADD_ERR" + [ "$(amt_field amtg4 discovery)" = "$V4_DISC" ] + check_err $? "discovery did not read back as $V4_DISC" + ip -n "$GW" link del amtg4 2>/dev/null + log_test "v4 gateway still creates (no ABI change)" +} + +# An IPv4 relay has always ignored IFLA_AMT_DISCOVERY_IP, and still must. +test_v4_relay_unchanged() +{ + RET=0 + add_amt amtr4 mode relay local "$V4_LOCAL" discovery "$V4_DISC" + check_err $? "create failed: $ADD_ERR" + ip -n "$GW" link del amtr4 2>/dev/null + log_test "v4 relay still accepts a v4 discovery (no ABI change)" +} + +# expect_reject : the create must +# fail, and for the stated reason. +expect_reject() +{ + local desc=$1 want=$2; shift 2 + + RET=0 + add_amt amtbad "$@" + check_fail $? "link was created but should have been rejected" + ip -n "$GW" link del amtbad 2>/dev/null + grep -qi -- "$want" <<< "$ADD_ERR" + check_err $? "rejected for the wrong reason: $ADD_ERR" + log_test "$desc" +} + +require_command jq +if [ ! -e /proc/net/if_inet6 ]; then + echo "SKIP: the kernel has no IPv6" + exit "$ksft_skip" +fi +trap cleanup_all_ns EXIT +setup_ns GW || exit "$ksft_skip" +ip -n "$GW" link add gw_dev type dummy +ip -n "$GW" link set gw_dev up +ip -n "$GW" addr add "$V4_LOCAL/24" dev gw_dev +# nodad: only read back, never used to send. +ip -n "$GW" addr add "$V6_LOCAL/64" dev gw_dev nodad + +probe_v6_gateway + +test_v6_gateway_roundtrip +test_v6_relay_roundtrip +test_v4_gateway_unchanged +test_v4_relay_unchanged +expect_reject "gateway without discovery is rejected" \ + "Discovery attribute" \ + mode gateway local "$V6_LOCAL" +expect_reject "gateway v6 local + v4 discovery is rejected" \ + "of the local family is required" \ + mode gateway local "$V6_LOCAL" discovery "$V4_DISC" +expect_reject "gateway v4 local + v6 discovery is rejected" \ + "of the local family is required" \ + mode gateway local "$V4_LOCAL" discovery "$V6_DISC" +expect_reject "v6 discovery in relay mode is rejected" \ + "only valid in gateway mode" \ + mode relay local "$V6_LOCAL" discovery "$V6_DISC" +expect_reject "v4 discovery on a v6 relay is rejected" \ + "only valid in gateway mode" \ + mode relay local "$V6_LOCAL" discovery "$V4_DISC" +expect_reject "v6 discovery on a v4 relay is rejected" \ + "only valid in gateway mode" \ + mode relay local "$V4_LOCAL" discovery "$V6_DISC" +# iproute2 sends :: and multicast as given, so these reach amt_newlink(); the +# extack match in expect_reject() is what pins the kernel rule as the cause. +expect_reject "unspecified v6 local is rejected" \ + "Invalid Local IPv6" \ + mode relay local :: +expect_reject "v4-mapped v6 local is rejected" \ + "Invalid Local IPv6" \ + mode relay local ::ffff:192.168.0.1 +expect_reject "loopback v6 local is rejected" \ + "Invalid Local IPv6" \ + mode relay local ::1 +expect_reject "multicast v6 local is rejected" \ + "Invalid Local IPv6" \ + mode relay local ff02::1 +expect_reject "multicast v6 discovery is rejected" \ + "must be unicast" \ + mode gateway local "$V6_LOCAL" discovery ff02::1 +expect_reject "loopback v6 discovery is rejected" \ + "must be unicast" \ + mode gateway local "$V6_LOCAL" discovery ::1 +expect_reject "unspecified v6 discovery is rejected" \ + "must be unicast" \ + mode gateway local "$V6_LOCAL" discovery :: +expect_reject "v4-mapped v6 discovery is rejected" \ + "must be unicast" \ + mode gateway local "$V6_LOCAL" discovery ::ffff:192.168.0.2 + +exit "$EXIT_STATUS"