From: Anton Danilov <littlesmilingcloud@gmail.com>
To: netdev@vger.kernel.org
Cc: "David S . Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
David Ahern <dsahern@kernel.org>, Simon Horman <horms@kernel.org>,
Shuah Khan <shuah@kernel.org>,
linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org
Subject: [PATCH net-next 07/11] selftests: net: cover the GRE specific drop reasons
Date: Tue, 1 Sep 2026 00:51:33 +0300 [thread overview]
Message-ID: <20260831215137.549324-8-littlesmilingcloud@gmail.com> (raw)
In-Reply-To: <20260831215137.549324-1-littlesmilingcloud@gmail.com>
Extend the tunnel drop reason test with the reasons added to the GRE
receive path:
- two endpoints configured with different keys make the tunnel lookup
on the receiver fail, which is reported as GRE_TUNNEL_NOT_FOUND,
- setting the routing bit of the GRE header is reported as
GRE_INVALID_HDR, and announcing GRE version 1, which has no handler
unless PPTP is built in, is reported as UNHANDLED_PROTO.
The last two corrupt the header of the received packets with tc pedit
and are skipped when the ingress qdisc or the pedit action are not
available.
SKB_DROP_REASON_GRE_CSUM is not covered: veth hands the packets over
with CHECKSUM_UNNECESSARY, so the GRE checksum is never validated and
the reason cannot be reached without crafting the packets.
Assisted-by: Claude-Code:claude-opus-5
Signed-off-by: Anton Danilov <littlesmilingcloud@gmail.com>
---
.../selftests/net/tunnel_drop_reasons.sh | 62 +++++++++++++++++++
1 file changed, 62 insertions(+)
diff --git a/tools/testing/selftests/net/tunnel_drop_reasons.sh b/tools/testing/selftests/net/tunnel_drop_reasons.sh
index eb19967ae7dd..aad003f0efe5 100755
--- a/tools/testing/selftests/net/tunnel_drop_reasons.sh
+++ b/tools/testing/selftests/net/tunnel_drop_reasons.sh
@@ -20,6 +20,17 @@
# A control case, where both endpoints agree on the options, makes sure
# that no tunnel drop reason is reported when packets are accepted.
#
+# The GRE specific reasons are checked as well:
+#
+# - a packet that matches no tunnel is reported as
+# GRE_TUNNEL_NOT_FOUND. It is triggered here by giving the two
+# endpoints different keys.
+#
+# - a header with the routing bit set is reported as GRE_INVALID_HDR,
+# and a header announcing a GRE version nobody handles is reported as
+# UNHANDLED_PROTO. Both are triggered by corrupting the GRE header
+# on ingress with tc pedit, and are skipped if that is not available.
+#
# Drop reasons are read from the skb:kfree_skb tracepoint. A dedicated
# trace instance is used so that the test does not disturb, and is not
# disturbed by, anything else using the tracing facility.
@@ -202,6 +213,47 @@ test_control()
check_reason "gre: matching configuration (control)" ""
}
+# Corrupt one field of the GRE header of every IPv4 packet received by
+# the receiver. $1 is a tc pedit munge expression, with offsets counted
+# from the start of the IPv4 header.
+corrupt_gre_header()
+{
+ ip netns exec "$NS_RCV" tc qdisc add dev veth_r ingress || return 1
+ ip netns exec "$NS_RCV" tc filter add dev veth_r ingress \
+ protocol ip matchall action pedit ex munge "$@" || return 1
+}
+
+test_tunnel_not_found()
+{
+ setup_ns_pair
+ # The two endpoints use different keys, so the lookup on the
+ # receiver finds no tunnel for the incoming packets.
+ add_gre "$NS_SND" "$SND_V4" "$RCV_V4" okey 1 ikey 1
+ add_gre "$NS_RCV" "$RCV_V4" "$SND_V4" okey 2 ikey 2
+ addr_tunnels
+
+ check_reason "gre: tunnel not found" GRE_TUNNEL_NOT_FOUND
+}
+
+# $1: test name, $2: expected reason, $3...: tc pedit munge expression
+test_corrupted_header()
+{
+ local name=$1 want=$2
+
+ shift 2
+ setup_ns_pair
+ add_gre "$NS_SND" "$SND_V4" "$RCV_V4"
+ add_gre "$NS_RCV" "$RCV_V4" "$SND_V4"
+ addr_tunnels
+
+ if ! corrupt_gre_header "$@" 2>/dev/null; then
+ log_test_skip "$name"
+ return
+ fi
+
+ check_reason "$name" "$want"
+}
+
if [ "$(id -u)" -ne 0 ]; then
echo "SKIP: need root"
exit "$ksft_skip"
@@ -217,6 +269,16 @@ test_opts_mismatch gre icsum
test_control
test_old_seq gre
+test_tunnel_not_found
+# The routing bit is the second most significant bit of the first byte
+# of the GRE header, which follows the 20 byte IPv4 header.
+test_corrupted_header "gre: routing bit set" GRE_INVALID_HDR \
+ offset 20 u8 set 0x40
+# The GRE version sits in the low bits of the next byte. Version 1 is
+# PPTP, which has no handler here.
+test_corrupted_header "gre: unhandled GRE version" UNHANDLED_PROTO \
+ offset 21 u8 set 0x01
+
if [ -e /proc/sys/net/ipv6 ]; then
test_opts_mismatch ip6gre iseq
test_old_seq ip6gre
--
2.47.3
next prev parent reply other threads:[~2026-08-31 21:52 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-31 21:51 [PATCH net-next 00/11] tunnels: add core and gre drop reasons Anton Danilov
2026-08-31 21:51 ` [PATCH net-next 01/11] ip_tunnel: add drop reasons to the generic RX path Anton Danilov
2026-09-03 1:47 ` Jakub Kicinski
2026-09-03 1:47 ` Jakub Kicinski
2026-08-31 21:51 ` [PATCH net-next 02/11] ip6_tunnel: " Anton Danilov
2026-08-31 21:51 ` [PATCH net-next 03/11] selftests: net: add a test for the tunnel RX drop reasons Anton Danilov
2026-09-03 1:45 ` Jakub Kicinski
2026-08-31 21:51 ` [PATCH net-next 04/11] gre: make gre_parse_header() report a drop reason Anton Danilov
2026-08-31 21:51 ` [PATCH net-next 05/11] ip_gre: add drop reasons to the RX path Anton Danilov
2026-08-31 21:51 ` [PATCH net-next 06/11] ip6_gre: " Anton Danilov
2026-08-31 21:51 ` Anton Danilov [this message]
2026-08-31 21:51 ` [PATCH net-next 08/11] ip_tunnel: add drop reasons to the transmit path Anton Danilov
2026-08-31 21:51 ` [PATCH net-next 09/11] ip_gre: " Anton Danilov
2026-08-31 21:51 ` [PATCH net-next 10/11] ip6_tunnel: " Anton Danilov
2026-09-03 1:43 ` Jakub Kicinski
2026-08-31 21:51 ` [PATCH net-next 11/11] selftests: net: cover the tunnel transmit drop reasons Anton Danilov
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=20260831215137.549324-8-littlesmilingcloud@gmail.com \
--to=littlesmilingcloud@gmail.com \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=shuah@kernel.org \
/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