From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.167.46 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796214986; b=n+DE166ZEyFXRCj4peA59NV8EgcI1vrlSeZRKbxrLv1dAAmtLs2339dbpGhquKyvuQEz bmUk/XtBLnhXI6+Qr7Ng5VLVxgRP/2eBDv9nYr8U/oEatmPuK/6RBl/PN7enKLNVV/OP7 vA5tV42xzlFpSEoLgikSJWwAxnmIpUvgCuDS960VuKAGVhYRCH8nuPfR0B+hfEkDq8ihR DKXzowPG6yzGf0pgVwcD5sBKvUudebh5IKxF8GMEi1QT2SrMCXMAcZQB+LB16cQohpMSD oPxhKSrAAHFwvK5sM7g5PeYPI0X5Y7wPybCqrGmttBOYQEFA865NP20GDiHNC1fl65g== 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=5r7Fp9Jw92Yb+wVUhME2+EAvGchaRgSR63e9k8khRmGJoj++wQ1WjRCcjduPvLU/x/k0 WR/upgw5+CVUpj+FYM6ZpnVurWz6fD8130qrOZpOsw6vbpa/kZ4EvResXfUYUoBUc5yY9 HBIgYb2E5wMmTRWHodj9bYMWmvBNz04+8dEJlbIIsqKfho/9h65P24xnMMm7LYB7vDaLs PD9V1CEFFU0J48V8aG1KUbt/2D587mzjTG+WGuhPBsfCJkRsTLQqjebX0aCG9tbgWBYnu O/jhXNF8o7L147bI8TmhLW1wBkwu0N70NL03LXFaXFvTu8+PWWrfjCqu7YJIdzUAejQ== 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.46 Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) (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 56DFD606A697 for ; Wed, 2 Dec 2026 12:36:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 56DFD606A697 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-f46.google.com with SMTP id 2adb3069b0e04-5be3ed646a5so8034335e87.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=mZiLXY9DUKnBIv3IC0U8dmpmHOn3hYzvxU9O08I8iwL/7g4iPoreF1qrpurxs9Vv9B XKMdGjckR04Wc4xnzHaLs5qvz4fDoRkqZI0yb3gP5/vqiQWtwuoHKe/TNOHbHw1+x3eY Ec9vxi7qAjEU86zRaNsC2iQS/ITAFqShj2w7c7pJOjSqp8k/aDOtHZtVkqDC2ruZdB6I Zs0RlAZxasGaF+CCm1JS96s6GyN4wTKxue+c0r+1J5z5MzMMYAHjnreLvaEuUU6O8+Oc jXBj7SW/VNjYmiTSCIxNrywbKW8qdF6WD8DyHNGnkP17foym7mkaXdwZ5OoXTecRgBHw CFnA== X-Forwarded-Encrypted: i=1; AL+hErHa0pNQVHTEJxEZgwEN/9Pis/nyf3gGBknOWXqEovNdGcLpTVifKJYe5TlXHOhqY4c4pR7+NrPwUpjlDHs+VYE=@vger.kernel.org X-Gm-Message-State: APuU4Z/f70YpxZomcno1Os4acNKSk71JtRp1lteVV2V4OrhEIq5GmEBq WNNU1sQAp82NngBCC7MS0ytdB9xuqHDgVktWvHjeT6IxnC3JY2yc2dDC X-Gm-Gg: AZFdTZcEgFLHCBeSjXTj1rbq2IwI61EVIgit8ILmPgV7Gu9nQp1RMagHSmT5yJIc9sn 0u3DNpIu0o434pkDQ0S5iVlOXdlgQ5As6VJR2pXpxFvgLT7vFjEVWsRqVW1/ThXWXjTFMFyxYz5 11Qo8bH3d2Kym72C03bGh8J1BPlnbQqOrt8aZR0Rj/B2sAx5iFVEjR58173rdWWVHGr0zaBVScA +zaa7SxLHCjsSEcUdbSl3o/VkKeF06dwSnasd9hHQWJ0YLGK07mBST8l27Rc1sHDRXRoQ4o549f 0xn2PCwjKvINAmAmHW+lvF1XNJY/TdV0GXFjk29PBHzdKyT0R9ea2E2vHHDV6QyH5BAsF1ToKnq fpgivy3dClfCRPTrH7YXOCg2vcAjJFbo6TVPH7NToEiSFRbGYpSFKtGFOtgC82kVSanjaKp5uoO McDjCW3J/faC5rFOxBZ7hR4+ARudwETNscQHEJuSVNEaz1LPKBw6nMBmr9Z+5qxEGo0PrzU8jCX cJjcTMqrEkCb6u4HazyIJ2mwf5bTHIGs8LaY5dT5nhyBiiYARHwTQ5bmLF4GRS7dy1nEOUhuM1R 6n5gpO7MrwUx+6lIaIocQzr+J1fzBL1hM7/QTRpSnB532DI87+yQhb+zXr9D1JfZdwMZUFTe1Gd hZUJu2Z0w4rB8OQQ= 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-kselftest@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