From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.208.179 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796086793; b=2rzKP4p/cerB7JkzIPzl49U5E0vNCdZeDb8YyVG7i1pRLLj3NFvX8srpUqVL0lq6ATw+ H/wjIcpb7bFCgY5mme9jT0owcxPqRBGcjJf3dZinNkUBy96rC3y6BiQv4/tN5S9mh0EVf yzTP8U77gZCBHeZVuNa8irF1Onse/5J6MskIAQ3PB8p6RzgxuKXu3VnnaGwX+1kB9rfbc 101RIZCcvV2A4QLa+QpEeE3E76U7kMOvSBLM1QevEDJwHz57AEg00szH4o95QBHy/RlXR dyCG0IIWT63d9xICkyP70fwXw3B7IpG1iMcDtkC6zvEQoywEIzw2wzrGr5W9A/8YZhA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796086793; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: 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=ihW3EOW+qIGtLZNfp4gyCUx5u69gsfAZSUCykCDofH0=; b=cE4ZVVFavGxQBBo7GmnoYRTt/krVpnfmdvXHJ8FZ1Jx0O1q0/gfTCrm8aJSPlFt++e3m T0yAEz/2eI/nFBughD+EHKrWT4dOdWejEvQrJ6HraoM3jEbkFwurScBn1hDX1yCJY5W8l 69JCrnoYrjJMdKXvH7LbelUrkWkUls6aNATHSXY9sSMxONVceT5MvbJVbV7+rWz//9vek OoZJqZKHWXgHWCl3EkUeedv7hFc0VMnR8NGGIUzi3/cDqHJa0sSKEM4gRqDZDAeCk/NPM wPNBiLpqemmK+hyP8fuYu15elKkQtbZF7VmOatqeSJDvMZaJG2A5vXO1foZEu6zm6iw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=R4bxZGa4; arc=none smtp.remote-ip=209.85.208.179 Received: from mail-lj1-f179.google.com (mail-lj1-f179.google.com [209.85.208.179]) (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 2376860A260F for ; Tue, 1 Dec 2026 00:59:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2376860A260F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=R4bxZGa4 Received: by mail-lj1-f179.google.com with SMTP id 38308e7fff4ca-3ae25c846edso75950341fa.2 for ; Mon, 30 Nov 2026 16:59:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796086791; x=1796691591; 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=ihW3EOW+qIGtLZNfp4gyCUx5u69gsfAZSUCykCDofH0=; b=R4bxZGa4RbFlHrTsLxESyqqe1EBRVFJbFCqHAsrFFeqTdpOiE+XmaR8Sfx3K64xaTi uwX5iE30wHo0xiGhtKRG44dv943lO8ZVzmw4QozVKMnHSNPz3AiK7FLgsTuhgkTPYLKM jepd5748WxDHR9SFT6UrBk7i+rw2Ugpa4fmSPnIP1dVGNzrF/1N3M/Ph9KJ6MPCkC7w2 nVUqI7NKA18GBhKIG0lRk+9nKv44ZbG3LJkVfB9PqhFH0VObkctMVgMdPfywaM7XRrKY MfVdo6bEClOGTnb5SLYZmMrO2c35+XF10SgnkQNVVTYT2x9uR3Msiw2uvwqaB7xeCW+z l2QA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796086791; x=1796691591; 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=ihW3EOW+qIGtLZNfp4gyCUx5u69gsfAZSUCykCDofH0=; b=CcfQyEiCOBBXFxXX7HWp1OqZa1Lf6JER8RjE4iOxKimJnW0cDbraYG0Wkqn2/GuFgx CbxC/bBdFtGpFVSAeE7tK3OJ641+cqaq8MjEZrrNLQpRWBOscg7i5/Uai3WViZ3zVu2E 8cDnrIR5ou0PJdXZchoVTqnx5XQgZlKnOxmdLgEqDetsPrhfTcJZlkZOoWIUyxJLUst0 O934XoQr4o/Y3npxgkpJ4g49/Z2X2s9Y6Q9FNft7Jr655xF8RwL6zYgsAzTouuYkkyOC KoVaUvETZSyymBb8aAWfxT5iGVxeRCKHavMiwBKVJNiZTgjlR15niVRnfVRx5LSfIO9N 8ZVQ== X-Gm-Message-State: APuU4Z+xIBqQzckNnaV2jKCfrKyjacU2YUE31qf746nIN87Vx9Q9iPQK vaKpLaeMlanCJ+B3/vezWV5iOTxUzLlICbbvXCSg71sR8EneR2Vy1nAz9s/2ipqd X-Gm-Gg: AZFdTZchnHQgwSI0NppZvX13W8IjmNAA90AJDljfc/GWZ20UciuTe9uSA8QgjAtBupO kW1wxZOfgluhVnA/wijOEp5mXG0qu9yex3PPzvgn5AVoeN68oaeHGRTqzfCSEb56Fz4H7zhl+F5 girf0wInUBXrVSGzafOgKvcmEU8sR0FJqYpPURaBVblw76aOBh/mLoh6sF34+++/kOdZ7S3ccZI W6rphW0MvL+yNM01d/n/kU6/1164P7dpM6n8Ped8lDVkknetbgaLkdP/NDGxbN4/9qCzRo8AdB0 Vrsir2Fwvwdtjvn4ReVIHWUQc+YKtP9lQTFUNbWiOEzP3tczdmlEvZdoNoi0VSuCQVIFNypWYYK yEFUyVf83W3zWhOu6LKSFghtE/rO09yf5hmqScqUTRpSxFB8bCL9FvxMJcIeyURTeQ6dpRNJ0Cn CUthmWaxOXplLZYYazly7TUW54yt/GGnZzzxXlRgRHQOi5rEdyYylmXrL1x5xidgHEsxug0sstz t2GQcUOY0S88/v/EvogakpeQUZBpxJJEbUG7BNZY7ZWUgTacB4wQEB8jt0PVZo7a0NxVJVTUAk6 sXSjHdyo0D9H0hw2uEqKv0gws552l7qHsmKShmaBRIc00kw1BbIqPiMwFl90qntZKH+Vb5d2LfB Hcf8tqqwIWuOo3hw= X-Received: by 2002:a05:6512:304a:b0:5be:4d35:c4c1 with SMTP id 2adb3069b0e04-5c1bc844ba8mr10313503e87.12.1796086791058; Mon, 30 Nov 2026 16:59:51 -0800 (PST) Received: from dau-home-pc.megasoftware.org ([94.28.149.75]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5c1bd040a9bsm8895709e87.48.2026.11.30.16.59.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 16:59:50 -0800 (PST) From: Anton Danilov To: netdev@vger.kernel.org Cc: Eric Dumazet , Jakub Kicinski , Paolo Abeni , "David S. Miller" , Simon Horman , David Ahern , Willem de Bruijn , Ido Schimmel , Florian Westphal , William Tu , Meenakshi Vohra , Matthias May , Mazin Al Haddad , Shuah Khan , linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v7 5/5] selftests: net: add a test for ip6gretap and ip6erspan with VLAN tags Date: Tue, 1 Dec 2026 03:59:41 +0300 Message-ID: <20261201005941.1536429-6-littlesmilingcloud@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261201005941.1536429-1-littlesmilingcloud@gmail.com> References: <20261201005941.1536429-1-littlesmilingcloud@gmail.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 Add ip6_gre_vlan_inherit.sh. It sends IPv4 and IPv6 packets with a given TTL and TOS through ip6gretap, with and without a key, and through ip6erspan v1 and v2, directly and through a VLAN device on top of the tunnel, and checks on the receiving side that - the outer hop limit and traffic class are those of the inner packet, with a VLAN tag in front of it or without; - on ip6erspan, the COS field of the ERSPAN header is the one that the inner TOS asks for, for IPv4 and for IPv6. The outer header is matched with tc flower and the COS field with tc u32, and the packets are counted. Without the previous patches of this series 10 of the 24 checks fail: the hop limit behind a tag on ip6gretap with a key, the hop limit and traffic class behind a tag on ip6erspan, and the COS of IPv4 packets on ip6erspan. Signed-off-by: Anton Danilov --- tools/testing/selftests/net/Makefile | 1 + .../selftests/net/ip6_gre_vlan_inherit.sh | 172 ++++++++++++++++++ 2 files changed, 173 insertions(+) create mode 100755 tools/testing/selftests/net/ip6_gre_vlan_inherit.sh diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile index fb0a64662053..0d8a5ff31b17 100644 --- a/tools/testing/selftests/net/Makefile +++ b/tools/testing/selftests/net/Makefile @@ -53,6 +53,7 @@ TEST_PROGS := \ io_uring_zerocopy_tx.sh \ ioam6.sh \ ip6_gre_headroom.sh \ + ip6_gre_vlan_inherit.sh \ ip6_tunnel.sh \ ip_defrag.sh \ ip_local_port_range.sh \ diff --git a/tools/testing/selftests/net/ip6_gre_vlan_inherit.sh b/tools/testing/selftests/net/ip6_gre_vlan_inherit.sh new file mode 100755 index 000000000000..94aed82e9441 --- /dev/null +++ b/tools/testing/selftests/net/ip6_gre_vlan_inherit.sh @@ -0,0 +1,172 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# +# ip6gretap and ip6erspan can take the outer hop limit and traffic class from +# the packet they carry. Check that they do so for a packet behind a VLAN tag +# as they do for one without a tag, and that ip6erspan derives the COS field +# of the ERSPAN header from the carried packet, whether it is IPv4 or IPv6. +# +# +-------------------------------+ +---------------------------+ +# | ns1 | | ns2 | +# | | | | +# | tun.10 (VLAN 10) | | | +# | | | | | +# | tun (ip6gretap/ip6erspan) | | | +# | : | | | +# | veth1 ------------------------------------ veth2 | +# | 2001:db8:1::1/64 | | 2001:db8:1::2/64 | +# | | | ingress: tc counters | +# +-------------------------------+ +---------------------------+ +# +# The packets are sent to neighbours that only exist as static neighbour +# entries, and are counted in ns2 as they arrive, by their outer header. + +# shellcheck disable=SC2154 # ns1 and ns2 are set by setup_ns +source lib.sh + +readonly TTL=33 +readonly TOS=0xb8 # DSCP EF, which makes COS 5 +readonly COS_MATCH="0xa0 0xe0" # COS 5 in the top bits of its byte +readonly COUNT=5 +readonly LLADDR=00:00:5e:00:53:01 + +# Offset of the COS byte from the outer IPv6 header: IPv6 (40), GRE with a +# sequence number (8), then the third byte of the ERSPAN header. The tunnels +# are created with "encaplimit none", so that no extension header moves it. +readonly COS_OFF=50 + +setup() +{ + setup_ns ns1 ns2 || exit "$ksft_skip" + + ip -n "$ns1" link add veth1 type veth peer name veth2 netns "$ns2" + ip -n "$ns1" address add 2001:db8:1::1/64 dev veth1 nodad + ip -n "$ns2" address add 2001:db8:1::2/64 dev veth2 nodad + ip -n "$ns1" link set dev veth1 up + ip -n "$ns2" link set dev veth2 up + + tc -n "$ns2" qdisc add dev veth2 clsact + # Encapsulated packets with the inherited hop limit and traffic class. + # flower reads a numeric ip_proto as hexadecimal: 0x2f is GRE. + tc -n "$ns2" filter add dev veth2 ingress pref 1 handle 101 \ + protocol ipv6 flower ip_proto 0x2f \ + ip_ttl "$TTL" ip_tos "$TOS" \ + action continue + # ERSPAN packets with the expected COS. + # shellcheck disable=SC2086 # COS_MATCH is a value and a mask + tc -n "$ns2" filter add dev veth2 ingress pref 2 \ + protocol ipv6 u32 \ + match u8 47 0xff at 6 \ + match u8 $COS_MATCH at "$COS_OFF" \ + action pass +} + +tunnel_create() +{ + local kind=$1; shift + local -a args + + case "$kind" in + ip6gretap) + args=(type ip6gretap);; + ip6gretap_key) + args=(type ip6gretap key 1);; + ip6erspan_v1) + args=(type ip6erspan seq key 1 erspan_ver 1 erspan 1);; + ip6erspan_v2) + args=(type ip6erspan seq key 1 erspan_ver 2 + erspan_dir ingress erspan_hwid 1);; + esac + + ip -n "$ns1" link add tun "${args[@]}" \ + local 2001:db8:1::1 remote 2001:db8:1::2 \ + tclass inherit hoplimit inherit encaplimit none + ip -n "$ns1" link add link tun name tun.10 type vlan id 10 + ip -n "$ns1" link set dev tun up + ip -n "$ns1" link set dev tun.10 up + + ip -n "$ns1" address add 192.0.2.1/28 dev tun + ip -n "$ns1" address add 2001:db8:2::1/64 dev tun nodad + ip -n "$ns1" address add 192.0.2.17/28 dev tun.10 + ip -n "$ns1" address add 2001:db8:3::1/64 dev tun.10 nodad + + ip -n "$ns1" neigh add 192.0.2.2 lladdr "$LLADDR" dev tun + ip -n "$ns1" neigh add 2001:db8:2::2 lladdr "$LLADDR" dev tun + ip -n "$ns1" neigh add 192.0.2.18 lladdr "$LLADDR" dev tun.10 + ip -n "$ns1" neigh add 2001:db8:3::2 lladdr "$LLADDR" dev tun.10 +} + +tunnel_destroy() +{ + ip -n "$ns1" link del dev tun +} + +inherit_count() +{ + tc_rule_handle_stats_get "dev veth2 ingress" 101 ".packets" "-n $ns2" +} + +cos_count() +{ + tc -n "$ns2" -j -s filter show dev veth2 ingress pref 2 | + jq '[.[] | select(.options.actions) | + .options.actions[0].stats.packets] | add' +} + +# Send COUNT packets and check that as many arrive with the outer header +# fields that the inner header asks for. +send_and_check() +{ + local kind=$1; shift + local what=$1; shift + local dst=$1; shift + local inherit cos + + inherit=$(inherit_count) + cos=$(cos_count) + + # Nobody answers: ping sends COUNT packets and gives up. + ip netns exec "$ns1" ping -q -c "$COUNT" -i 0.01 -W 1 \ + -t "$TTL" -Q "$TOS" "$dst" &> /dev/null + + RET=0 + busywait "$BUSYWAIT_TIMEOUT" until_counter_is \ + ">= $((inherit + COUNT))" inherit_count > /dev/null + check_err $? "outer hop limit and traffic class not inherited" + log_test "$kind: $what, hop limit and traffic class" + + [[ "$kind" == ip6erspan* ]] || return 0 + + RET=0 + busywait "$BUSYWAIT_TIMEOUT" until_counter_is \ + ">= $((cos + COUNT))" cos_count > /dev/null + check_err $? "COS not taken from the inner header" + log_test "$kind: $what, ERSPAN COS" +} + +test_kind() +{ + local kind=$1; shift + + tunnel_create "$kind" + + send_and_check "$kind" "IPv4" 192.0.2.2 + send_and_check "$kind" "IPv6" 2001:db8:2::2 + send_and_check "$kind" "IPv4 in VLAN" 192.0.2.18 + send_and_check "$kind" "IPv6 in VLAN" 2001:db8:3::2 + + tunnel_destroy +} + +require_command jq + +trap cleanup_all_ns EXIT + +setup + +test_kind ip6gretap +test_kind ip6gretap_key +test_kind ip6erspan_v1 +test_kind ip6erspan_v2 + +exit "$EXIT_STATUS" -- 2.47.3