mirror of https://lore.kernel.org/lkml/
 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 4/5] ip6_gre: go by the inner protocol behind VLAN tags in ip6erspan
Date: Tue,  1 Dec 2026 03:59:40 +0300	[thread overview]
Message-ID: <20261201005941.1536429-5-littlesmilingcloud@gmail.com> (raw)
In-Reply-To: <20261201005941.1536429-1-littlesmilingcloud@gmail.com>

ip6erspan_tunnel_xmit() picks the traffic class and the flow label to
inherit, the ERSPAN truncation bit and the ICMP error to send for a
packet that is too big by skb->protocol, and ip6_tnl_xmit() picks its
minimum MTU the same way. A VLAN-tagged frame therefore gets none of
that: its outer traffic class is 0 where ip6gretap inherits it, the
truncation bit is not set from its IP length, and an IPv4 packet behind
a tag gets an ICMPv6 Packet Too Big built from its IPv4 header.

Use the protocol that the previous patch works out on entry, behind the
tags. The header it stands for has been pulled and the network header
is on it.

Found by an AI code review agent on an earlier version of the previous
patch and confirmed in a VM on an unmodified kernel: an IPv4 packet
with TOS 0xb8 behind a VLAN tag, sent to ip6erspan v1 and v2 with
tclass inherit in each of the ways listed in the previous patch, goes
out with traffic class 0 before this patch and with 0xb8 after it;
untagged packets go out with 0xb8 before and after. The truncation
bit, the ICMP error and the minimum MTU were not measured.

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

diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
index d7d7fd478200..698cf1cdd4ab 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,7 +1132,7 @@ 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
diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
index 868c49b97a8f..8ccc90333c99 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-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 ` Anton Danilov [this message]
2026-12-01  0:59 ` [PATCH net-next v7 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=20261201005941.1536429-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

all inboxes | Powered by JetHome®