From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.167.48 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796214986; b=U0jIksR8En/hIU4k/1EUTOTtz9ur6KfxPHo7VSqSIE166DlP6X18M6Kh4M7+Hw9O4Qx4 0gfLLc8LQNApTGBgSCh5jH25GQ8GHRTMd1gNxObpjf5djozHA0TCDqvKZMEkBJvFa0KV6 ReNKGpo6rIgfudwDbEDqOxu3m/m2byETcgLgoINe3mUjb4+LvNtTHs/ke5FaxdNQnlFSs bz8y0Ftl9CXhSyDy4pusNpprxaWm86R6OMfXKKFPeB3vsJEN1Psd0IhzWaF8SD/nT+xcu abT1qA/YkO5gpYf26XidJUgwFrdyAUmi9sWMUwsFRUpE5WrCFqZdFHbADSh3KwrlzzA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796214986; 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=ihW3EOW+qIGtLZNfp4gyCUx5u69gsfAZSUCykCDofH0=; b=LxF/fV2eHvFttrIRFxe+ltLrKu/Iw7BZ9Hx/APnbN5PmyYR0VNyO+EJAckP7aZOfQ5Dq S+CaXnfyzPNU6AN+LSvc5oyw77RMw2qykFg04llP3MsREiHpMdni3qZ8pLo5EEVhB5kAo 5+X9sy0H3Riqsu/rWO6iE63PPCBX2mVuTpzObOyCC+VihJvtQwjQ0Oh07rA+zQeuuOIDd qf1X0O1xY2XzA0a3C7VyMOcsAXVFDOpBXMGRQ6+fpKxuW+ICGsEqa03dveiSupdOtTh6K XsrQEGQj8s3au06ajcZBEYeGVSXL4CBXMbQU0Yy5e1o34gmzVU0LUonrpepCLSb+FGA== 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=DSNUslLi; arc=none smtp.remote-ip=209.85.167.48 Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) (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 7D7B1606A6BC for ; Wed, 2 Dec 2026 12:36:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7D7B1606A6BC 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=DSNUslLi Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-5be3ed646a5so8034339e87.1 for ; Wed, 02 Dec 2026 04:36:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796214985; x=1796819785; 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=DSNUslLiHCogZPLEV4UzTUwOly2K4KOClYLIcR7cHkrFVtee+LiEZC0cpLPhOqsdzy Pjal7ZfTlsvXCqZdtSA46WYqinjaAM3fGIIk1MsBNcBOcOeDT4CnGsDpXA/Z+4uatcZO z+nFGYDnkxdHZWVHQJc5C0WOyylMVlJziOLA1wtb0ktWJruSzMfEOOWdhOj2qYY/1wY6 LjdShtGxPv/sAH7TskTsdGsfg6rQpniV0kbqERnDoxTQStUTGFVfaRyVyetQwkvY5OIS nAIZ37VmeL24r9rqTAEE45aSJi0kth883CSURaqKJh0Rz/xL+JPIrwbSGhXH7OaRr0ya MEcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796214985; x=1796819785; 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=K6WwSd6jWzzNChBWCWugubb+oNjXqsXiwaxq+3Z5mVJrvHz+TRIBzcw8NcVvMBV5wC lSg+xEkp9R0t6ipvn2LLMrBq0Q0ioJA/o4Gd3hr5keTWR677SVAEkCWk4M+ePAczNUCz nvbNrDcmQzWL15rG1rOLgumd9Ei9ijKK3TcZBxfp8L/jRoRawmNZqy6Q5eJNQxp6/EFT 8fD5fUBeXDMLZ6gPtwHEYvB1zl8zCA9V/RqSe1losaR3Yn6lH7p2ZSZvY5tvfx1lqW42 zOlaP3OtiuPEis9M6BpiiWZG5R/FbImn/b8HmwVjNApqh7AlVS4pLRV0+SyBvoZ32vQu zYBw== X-Forwarded-Encrypted: i=1; AL+hErFMBRWt+DXp8agoIUGYLj/vkMU8f7/dvgpvhB+m6fTk0k8zswwR7xg6XP/WB0nFteAGyofDgIlGSRn3Y1c=@vger.kernel.org X-Gm-Message-State: APuU4Z9sBSqUSDYO6575fT+OoGLqx/uzc/YKwUivKiA1IHBRzupdQXq/ jnnmY3TmNsl3vgoiep5WMnT4JqYXn/dLnKT/sembNoeh5dndAp6TMfZa X-Gm-Gg: AZFdTZd06InQd/l/FGr4IzGWo2AzVecQLESx2uCtTb50NWtBCC7WP04pOYKSCc4YoUf 4DxSxQHh57LWLdkBP1dYDMYYkEkQPUXPRfpwQ3NqLCmUWy7lp0TI5WcBaZm8yPAxBplI57dL9Ps h6QKNGQ6sTrB3SkmAE+P8jLS3hIEoTQQX4rrfwVUT5ei7ieVf3lLDjh71vnch5cS8bknqKcOq2T wW1/bDrca74se87b+GbKga0lPaG7Qc4uR3SRnIaS5N4BZdABVhRoVvEtVp+H1u6dG/mBp8wJym5 sMgMy99i+2v4uGnzcerb5dZ1oIB6MJVMH6bipfLY73L62ejstrFaHVFZKMYpqlyX3dbTqmsFwhJ 5uq+0OD+6cn2LDGFMex7FxCRNhe8BZaXyo11NE/2cR2FPvg8phIG4/DAgA5FzYyj3y4eYY3L0Ld Xt7mICi+0269fGflfISMhRoJvT+8mJKHcvddnhER1vEAj8t5Th0U2N4sGS1x6iLcdpX9VHIvOrk 3MMjRAYZPI04wCpMy3NTE0O14uuF/vnNE/ct2xVJyCAOygnZPNTDV0EEvhDS6y/zHpIVxkFmbKf M8ekQvzrHwMZ46tKhTd7TsC/L19oUfSoPcT3fUb53ooa0eNcB1uhylZIhEpZQ5mMt6u6gcgKSv7 MTicHg7KUHV8NUm4= X-Received: by 2002:a05:6512:110e:b0:5c1:4c0a:49d9 with SMTP id 2adb3069b0e04-5c33b809099mr7035445e87.16.1796214984642; Wed, 02 Dec 2026 04:36:24 -0800 (PST) Received: from dau-home-pc.megasoftware.org ([94.28.149.75]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5c1bd0171c7sm9529553e87.31.2026.12.02.04.36.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 04:36:24 -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 v8 5/5] selftests: net: add a test for ip6gretap and ip6erspan with VLAN tags Date: Wed, 2 Dec 2026 15:36:13 +0300 Message-ID: <20261202123613.1708463-6-littlesmilingcloud@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261202123613.1708463-1-littlesmilingcloud@gmail.com> References: <20261202123613.1708463-1-littlesmilingcloud@gmail.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 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