Linux Kernel Selftest development
 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 v8 4/5] ip6_gre: go by the inner protocol behind VLAN tags in ip6erspan
Date: Wed,  2 Dec 2026 15:36:12 +0300	[thread overview]
Message-ID: <20261202123613.1708463-5-littlesmilingcloud@gmail.com> (raw)
In-Reply-To: <20261202123613.1708463-1-littlesmilingcloud@gmail.com>

ip6erspan_tunnel_xmit() uses skb->protocol to select the inner header
for traffic class and flow label inheritance, length checks and ICMP
errors. ip6_tnl_xmit() uses it to select the minimum MTU. When the
protocol is a VLAN EtherType, a tagged IPv4 packet can lose its traffic
class and take the ICMPv6 error path on -EMSGSIZE.

Use the payload protocol classified on entry to the tunnel. For IPv4
and IPv6 the classifier has pulled the header and set or preserved the
network header offset. On -EMSGSIZE, send Fragmentation Needed for
IPv4 and Packet Too Big for IPv6. Other payloads have no inner IP
source to notify, so let them take the usual transmit error path.

An AI review of an earlier version identified the traffic class issue.
In VM tests with tclass inherit, a tagged IPv4 packet with TOS 0xb8
had outer traffic class 0 on ip6erspan v1 and v2. With this change it
has traffic class 0xb8, as it does without a tag.

On native ip6erspan v1, an oversized ARP frame took the ICMPv6 error
path with the old unconditional else, both with and without an 802.1Q
tag. With the IPv6 check both frames were dropped without calling
either ICMP handler. For both tag layouts the IPv4 sender received
Fragmentation Needed and the IPv6 sender received Packet Too Big.
Each error quoted the original Echo Request and advertised MTU 1338.

Signed-off-by: Anton Danilov <littlesmilingcloud@gmail.com>
---
 net/ipv6/ip6_gre.c    | 10 +++++-----
 net/ipv6/ip6_tunnel.c |  2 +-
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
index c413e47c6ceb..0ecee2271bbd 100644
--- a/net/ipv6/ip6_gre.c
+++ b/net/ipv6/ip6_gre.c
@@ -1021,11 +1021,11 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,
 	}
 
 	nhoff = skb_network_offset(skb);
-	if (skb->protocol == htons(ETH_P_IP) &&
+	if (payload_protocol == htons(ETH_P_IP) &&
 	    (ntohs(ip_hdr(skb)->tot_len) > skb->len - nhoff))
 		truncate = true;
 
-	if (skb->protocol == htons(ETH_P_IPV6)) {
+	if (payload_protocol == htons(ETH_P_IPV6)) {
 		int thoff;
 
 		if (skb_transport_header_was_set(skb))
@@ -1087,7 +1087,7 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,
 			goto tx_err;
 		}
 	} else {
-		switch (skb->protocol) {
+		switch (payload_protocol) {
 		case htons(ETH_P_IP):
 			memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt));
 			prepare_ip6gre_xmit_ipv4(skb, dev, &fl6,
@@ -1132,10 +1132,10 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,
 	if (err != 0) {
 		/* XXX: send ICMP error even if DF is not set. */
 		if (err == -EMSGSIZE) {
-			if (skb->protocol == htons(ETH_P_IP))
+			if (payload_protocol == htons(ETH_P_IP))
 				icmp_ndo_send(skb, ICMP_DEST_UNREACH,
 					      ICMP_FRAG_NEEDED, htonl(mtu));
-			else
+			else if (payload_protocol == htons(ETH_P_IPV6))
 				icmpv6_ndo_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);
 		}
 
diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
index 931911b5e8a8..3d8b2d5851ef 100644
--- a/net/ipv6/ip6_tunnel.c
+++ b/net/ipv6/ip6_tunnel.c
@@ -1227,7 +1227,7 @@ int ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev, __u8 dsfield,
 		max_headroom += 8;
 		mtu -= 8;
 	}
-	mtu = max(mtu, skb->protocol == htons(ETH_P_IPV6) ?
+	mtu = max(mtu, payload_protocol == htons(ETH_P_IPV6) ?
 		       IPV6_MIN_MTU : IPV4_MIN_MTU);
 
 	skb_dst_update_pmtu_no_confirm(skb, mtu);
-- 
2.47.3


  parent reply	other threads:[~2026-12-02 12:36 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 12:36 [PATCH net-next v8 0/5] ip6_gre, erspan: fix inner header handling for VLAN-tagged and short frames Anton Danilov
2026-12-02 12:36 ` [PATCH net-next v8 1/5] erspan: bound the VLAN tag read in erspan_build_header{,_v2}() Anton Danilov
2026-12-02 12:36 ` [PATCH net-next v8 2/5] erspan: take the COS from the mirrored frame, not from the tunnel family Anton Danilov
2026-12-02 12:36 ` [PATCH net-next v8 3/5] ip6_gre: classify the inner packet once on transmit Anton Danilov
2026-12-02 12:36 ` Anton Danilov [this message]
2026-12-02 12:36 ` [PATCH net-next v8 5/5] selftests: net: add a test for ip6gretap and ip6erspan with VLAN tags 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=20261202123613.1708463-5-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