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 <litt…@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