Netdev List
 help / color / mirror / Atom feed
From: Anton Danilov <littlesmilingcloud@gmail.com>
To: netdev@vger.kernel.org
Cc: Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	"David S. Miller" <davem@davemloft.net>,
	Simon Horman <horms@kernel.org>, David Ahern <dsahern@kernel.org>,
	Willem de Bruijn <willemb@google.com>,
	Ido Schimmel <idosch@nvidia.com>, Florian Westphal <fw@strlen.de>,
	William Tu <u9012063@gmail.com>,
	Meenakshi Vohra <mvohra@vmware.com>,
	Matthias May <matthias.may@westermo.com>,
	Mazin Al Haddad <mazin@getstate.dev>,
	Shuah Khan <shuah@kernel.org>,
	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	[thread overview]
Message-ID: <20261201005941.1536429-6-littlesmilingcloud@gmail.com> (raw)
In-Reply-To: <20261201005941.1536429-1-littlesmilingcloud@gmail.com>

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 <littlesmilingcloud@gmail.com>
---
 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


      parent reply	other threads:[~2026-12-01  0:59 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01  0:59 [PATCH net-next v7 0/5] ip6_gre, erspan: fix inner header handling for VLAN-tagged and short frames Anton Danilov
2026-12-01  0:59 ` [PATCH net-next v7 1/5] erspan: bound the VLAN tag read in erspan_build_header{,_v2}() Anton Danilov
2026-12-01  0:59 ` [PATCH net-next v7 2/5] erspan: take the COS from the mirrored frame, not from the tunnel family Anton Danilov
2026-12-01  0:59 ` [PATCH net-next v7 3/5] ip6_gre: classify the inner packet once on transmit Anton Danilov
2026-12-01  0:59 ` [PATCH net-next v7 4/5] ip6_gre: go by the inner protocol behind VLAN tags in ip6erspan Anton Danilov
2026-12-01  0:59 ` Anton Danilov [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261201005941.1536429-6-littlesmilingcloud@gmail.com \
    --to=littlesmilingcloud@gmail.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@kernel.org \
    --cc=fw@strlen.de \
    --cc=horms@kernel.org \
    --cc=idosch@nvidia.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=matthias.may@westermo.com \
    --cc=mazin@getstate.dev \
    --cc=mvohra@vmware.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=shuah@kernel.org \
    --cc=u9012063@gmail.com \
    --cc=willemb@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox