Netdev List
 help / color / mirror / Atom feed
From: willemb@google.com
To: Julius Bairaktaris <julius@bairaktaris.de>, netdev@vger.kernel.org
Cc: davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
	 pabeni@redhat.com, willemb@google.com, horms@kernel.org,
	 andrew+netdev@lunn.ch, dsahern@kernel.org, idosch@nvidia.com,
	 ncardwell@google.com, kuniyu@google.com,
	steffen.klassert@secunet.com,  herbert@gondor.apana.org.au,
	richardbgobert@gmail.com, ecree.xilinx@gmail.com,
	 andy.moreton@amd.com, alex.austin@amd.com,
	linux-net-drivers@amd.com,  saeedm@nvidia.com, tariqt@nvidia.com,
	mbloch@nvidia.com, leon@kernel.org,  linux-rdma@vger.kernel.org,
	alexei.starovoitov@gmail.com, ast@kernel.org,
	 daniel@iogearbox.net, andrii@kernel.org, eddyz87@gmail.com,
	memxor@gmail.com,  martin.lau@linux.dev, song@kernel.org,
	yonghong.song@linux.dev,  jolsa@kernel.org, emil@etsalapatis.com,
	ihor.solodrai@linux.dev,  john.fastabend@gmail.com,
	sdf@fomichev.me, izaiahsun@gmail.com,  zirajs7@gmail.com,
	corbet@lwn.net, skhan@linuxfoundation.org,
	 rdunlap@infradead.org, shuah@kernel.org, bpf@vger.kernel.org,
	 ipsec@lists.linux.dev, linux-doc@vger.kernel.org,
	 linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next v4 1/2] net: keep the TCP fixed-ID flags on the header they describe
Date: Thu, 03 Dec 2026 23:10:15 -0500	[thread overview]
Message-ID: <willemb.26a81c70aad48@google.com> (raw)
In-Reply-To: <c9ec995833aac63f552441e4a60bf420a0a52275.1795869698.git.julius@bairaktaris.de>

Julius Bairaktaris wrote:
> Commit 3271f19bf7b9 ("net: gso: restore ids of outer ip headers
> correctly") made SKB_GSO_TCP_FIXEDID describe the outermost IPv4 header
> and added SKB_GSO_TCP_FIXEDID_INNER for the inner header of an
> encapsulated packet. Every path that adds or removes a header then has to
> move the flags, and none does. A TCP stream that GRO merged with fixed
> IDs and that is forwarded into an IPIP tunnel, or into an ESP tunnel mode
> SA with crypto offload, is segmented with one outer ID for all segments
> and with incrementing inner IDs. A tunnel that decapsulates such a packet
> in iptunnel_pull_offloads() leaves the state of the removed outer header
> on the new outer one, and the inner header of a GRE or UDP tunnel, which
> segmentation reads at encap_level 0, gets the state of the outer header.

> Let SKB_GSO_TCP_FIXEDID describe the innermost IPv4 header again, as it
> did before that commit, and replace SKB_GSO_TCP_FIXEDID_INNER with
> SKB_GSO_TCP_FIXEDID_OUTER for the outermost header of an encapsulated
> packet. Where a header is added in front of a GSO packet, in
> iptunnel_handle_offloads() and in the BPF LWT encapsulation, clear the
> outer flag, so that the new header gets incrementing IDs as it does on a
> packet that was not encapsulated before. Clear it as well where
> iptunnel_pull_offloads() and bpf_skb_net_shrink() remove the outer
> header. ESP transport and BEET mode with crypto offload set
> skb->encapsulation but keep the IPv4 header and its ID, so xfrm_output()
> copies the inner flag to the outer one for them. Convert mlx5 and sfc,
> the two drivers that use the inner flag.

> GRO of an IPv6 TCP stream in an IPv4 tunnel (SIT, or VXLAN over IPv4)
> records fixed outer IDs as it does for an IPv4 stream, but
> tcp6_gro_complete() never turned that into a flag: set
> SKB_GSO_TCP_FIXEDID_OUTER there as tcp4_gro_complete() does. As for an
> IPv4 stream, a device without NETIF_F_TSO_MANGLEID then leaves such a
> packet to software segmentation.

> xfrm_output() segments a GSO packet for a tunnel mode SA with crypto
> offload before ESP when skb->inner_protocol is set, as an encapsulated
> packet, but a tunnel that decapsulated the packet leaves inner_protocol
> set, and segmentation then reads the outer flag for its only IPv4
> header. Take that path only for a packet that is still encapsulated.

> Two flags cannot describe a header between the outermost and the
> innermost one of a packet with three IPv4 headers: software segmentation
> uses SKB_GSO_TCP_FIXEDID for it, as it used SKB_GSO_TCP_FIXEDID_INNER
> before.

> Suggested-by: Alexei Starovoitov <alexei.starovoitov@gmail.com>
> Signed-off-by: Julius Bairaktaris <julius@bairaktaris.de>
> ---
> v4:
> - Set the outer flag in tcp6_gro_complete() for an IPv4 outer header
>    with fixed IDs in front of an IPv6 TCP stream (Sashiko).
> - Take xfrm_output_gso() for a tunnel mode SA only for a packet that is
>    still encapsulated; a decapsulated one kept inner_protocol (Sashiko).
> - Target net-next (Paolo), Fixes: tag dropped.
> v3:
> - Clear SKB_GSO_TCP_FIXEDID_OUTER in iptunnel_handle_offloads() and in
>    the BPF LWT encapsulation, where a header goes in front of an
>    encapsulated packet (Sashiko).
> - Copy the inner flag to the outer one in xfrm_output() for ESP transport
>    and BEET mode with crypto offload (Sashiko).
> - Name the paths that change the outer flag and the middle-header limit
>    in skbuff.h, segmentation-offloads.rst and the message; list the outer
>    flag in the bpf_skb_adjust_room() decap flags of the uAPI header
>    (Sashiko).
> - Wrap lines at 80 columns (NIPA).
> v2:  
> https://lore.kernel.org/netdev/f7d096c63c6a0b7a23a4dcea9a3de0915a48ac56.1794139176.git.julius@bairaktaris.de/
> v3:  
> https://lore.kernel.org/netdev/7c74b2076dc7dee1d481d39a135e0946d5e04145.1795284858.git.julius@bairaktaris.de/

>   .../networking/segmentation-offloads.rst       |  8 +++++---
>   .../net/ethernet/mellanox/mlx5/core/en_rx.c    |  8 ++------
>   drivers/net/ethernet/sfc/ef100_tx.c            | 12 +++---------
>   include/linux/netdevice.h                      |  2 +-
>   include/linux/skbuff.h                         | 12 +++++++++++-
>   include/net/ip_tunnels.h                       |  1 +
>   include/uapi/linux/bpf.h                       | 16 +++++++++-------
>   net/core/filter.c                              |  1 +
>   net/core/lwt_bpf.c                             |  2 ++
>   net/ipv4/af_inet.c                             |  9 ++++++---
>   net/ipv4/ip_tunnel_core.c                      |  2 ++
>   net/ipv4/tcp_offload.c                         |  7 +++++--
>   net/ipv6/tcpv6_offload.c                       |  5 ++++-
>   net/xfrm/xfrm_output.c                         | 18 +++++++++++++++++-
>   tools/include/uapi/linux/bpf.h                 | 16 +++++++++-------
>   15 files changed, 78 insertions(+), 41 deletions(-)

> diff --git a/Documentation/networking/segmentation-offloads.rst  
> b/Documentation/networking/segmentation-offloads.rst
> index 25a8b7eca847..45c1703d68b8 100644
> --- a/Documentation/networking/segmentation-offloads.rst
> +++ b/Documentation/networking/segmentation-offloads.rst
> @@ -49,9 +49,11 @@ The default behavior is to increment the IP ID with  
> every segment.  If the
>   GSO type SKB_GSO_TCP_FIXEDID is specified then we will not increment the  
> IP
>   ID and all segments will use the same IP ID.

> -For encapsulated packets, SKB_GSO_TCP_FIXEDID refers only to the outer  
> header.
> -SKB_GSO_TCP_FIXEDID_INNER can be used to specify the same for the inner  
> header.
> -Any combination of these two GSO types is allowed.
> +For encapsulated packets, SKB_GSO_TCP_FIXEDID describes the innermost  
> header
> +and SKB_GSO_TCP_FIXEDID_OUTER the outermost header. Any combination of  
> these
> +two GSO types is allowed. A header added in front of a packet gets  
> incrementing
> +IDs. A header between the outermost and the innermost one has no flag of  
> its
> +own; software segmentation uses SKB_GSO_TCP_FIXEDID for it.

>   If a device has NETIF_F_TSO_MANGLEID set then the IP ID can be ignored  
> when
>   performing TSO and we will either increment the IP ID for all frames, or  
> leave
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c  
> b/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c
> index 1586cb2404c0..e47b1232130c 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c
> @@ -1175,12 +1175,8 @@ static void  
> mlx5e_shampo_update_ipv4_tcp_hdr(struct mlx5e_rq *rq, struct iphdr *
>   	tcp->check = ~tcp_v4_check(skb->len - tcp_off, ipv4->saddr,
>   				   ipv4->daddr, 0);
>   	skb_shinfo(skb)->gso_type |= SKB_GSO_TCPV4;
> -	if (ntohs(ipv4->id) == rq->hw_gro_data->second_ip_id) {
> -		bool encap = rq->hw_gro_data->fk.control.flags &  
> FLOW_DIS_ENCAPSULATION;
> -
> -		skb_shinfo(skb)->gso_type |= encap ? SKB_GSO_TCP_FIXEDID_INNER :
> -						     SKB_GSO_TCP_FIXEDID;
> -	}
> +	if (ntohs(ipv4->id) == rq->hw_gro_data->second_ip_id)
> +		skb_shinfo(skb)->gso_type |= SKB_GSO_TCP_FIXEDID;

>   	skb->csum_start = (unsigned char *)tcp - skb->head;
>   	skb->csum_offset = offsetof(struct tcphdr, check);
> diff --git a/drivers/net/ethernet/sfc/ef100_tx.c  
> b/drivers/net/ethernet/sfc/ef100_tx.c
> index 03005757c060..162cfa54f2d0 100644
> --- a/drivers/net/ethernet/sfc/ef100_tx.c
> +++ b/drivers/net/ethernet/sfc/ef100_tx.c
> @@ -201,16 +201,10 @@ static void ef100_make_tso_desc(struct efx_nic *efx,
>   	bool outer_csum;
>   	u32 paylen;

> -	if (encap) {
> -		if (skb_shinfo(skb)->gso_type & SKB_GSO_TCP_FIXEDID_INNER)
> -			mangleid = ESE_GZ_TX_DESC_IP4_ID_NO_OP;
> -		if (skb_shinfo(skb)->gso_type & SKB_GSO_TCP_FIXEDID)
> -			mangleid_outer = ESE_GZ_TX_DESC_IP4_ID_NO_OP;
> -	} else {
> -		if (skb_shinfo(skb)->gso_type & SKB_GSO_TCP_FIXEDID)
> -			mangleid = ESE_GZ_TX_DESC_IP4_ID_NO_OP;
> +	if (skb_shinfo(skb)->gso_type & SKB_GSO_TCP_FIXEDID)
> +		mangleid = ESE_GZ_TX_DESC_IP4_ID_NO_OP;
> +	if (!encap || (skb_shinfo(skb)->gso_type & SKB_GSO_TCP_FIXEDID_OUTER))
>   		mangleid_outer = ESE_GZ_TX_DESC_IP4_ID_NO_OP;
> -	}

>   	if (efx->net_dev->features & NETIF_F_HW_VLAN_CTAG_TX)
>   		vlan_enable = skb_vlan_tag_present(skb);
> diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
> index 694b6d29f680..9e0992afbbed 100644
> --- a/include/linux/netdevice.h
> +++ b/include/linux/netdevice.h
> @@ -5545,7 +5545,7 @@ static inline bool net_gso_ok(netdev_features_t  
> features, int gso_type)
>   {
>   	netdev_features_t feature;

> -	if (gso_type & (SKB_GSO_TCP_FIXEDID | SKB_GSO_TCP_FIXEDID_INNER))
> +	if (gso_type & (SKB_GSO_TCP_FIXEDID | SKB_GSO_TCP_FIXEDID_OUTER))
>   		gso_type |= __SKB_GSO_TCP_FIXEDID;

>   	feature = ((netdev_features_t)gso_type << NETIF_F_GSO_SHIFT) &  
> NETIF_F_GSO_MASK;
> diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
> index c609cafc7a14..caf374b452ca 100644
> --- a/include/linux/skbuff.h
> +++ b/include/linux/skbuff.h
> @@ -724,9 +724,19 @@ enum {

>   	/* These indirectly map onto the same netdev feature.
>   	 * If NETIF_F_TSO_MANGLEID is set it may mangle both inner and outer  
> IDs.
> +	 * SKB_GSO_TCP_FIXEDID describes the innermost IPv4 header and
> +	 * SKB_GSO_TCP_FIXEDID_OUTER the outermost one. Adding a header in
> +	 * iptunnel_handle_offloads() or with BPF LWT clears the outer flag, and
> +	 * so does removing one in iptunnel_pull_offloads() or in
> +	 * bpf_skb_adjust_room() with a BPF_F_ADJ_ROOM_DECAP_L4_* or
> +	 * BPF_F_ADJ_ROOM_DECAP_IPXIP* flag. xfrm_output() sets it from the
> +	 * inner flag for ESP transport and BEET mode offload, which keep the
> +	 * header.
> +	 * Software segmentation uses SKB_GSO_TCP_FIXEDID for any header in
> +	 * between.
>   	 */
>   	SKB_GSO_TCP_FIXEDID = 1 << 30,
> -	SKB_GSO_TCP_FIXEDID_INNER = 1 << 31,
> +	SKB_GSO_TCP_FIXEDID_OUTER = 1 << 31,
>   };

>   #if BITS_PER_LONG > 32
> diff --git a/include/net/ip_tunnels.h b/include/net/ip_tunnels.h
> index 5cccf4c0e691..a8e1cd7021fc 100644
> --- a/include/net/ip_tunnels.h
> +++ b/include/net/ip_tunnels.h
> @@ -667,6 +667,7 @@ static inline int iptunnel_pull_offloads(struct  
> sk_buff *skb)
>   			return err;
>   		skb_shinfo(skb)->gso_type &= ~(NETIF_F_GSO_ENCAP_ALL >>
>   					       NETIF_F_GSO_SHIFT);
> +		skb_shinfo(skb)->gso_type &= ~SKB_GSO_TCP_FIXEDID_OUTER;
>   	}

>   	skb->encapsulation = 0;
> diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
> index 8d7228834305..e5aae5320af9 100644
> --- a/include/uapi/linux/bpf.h
> +++ b/include/uapi/linux/bpf.h
> @@ -3097,20 +3097,22 @@ union bpf_attr {
>    *
>    *		* **BPF_F_ADJ_ROOM_DECAP_L4_GRE**:
>    *		  Clear GRE tunnel GSO flags (SKB_GSO_GRE and SKB_GSO_GRE_CSUM)
> - *		  when decapsulating a GRE tunnel.
> + *		  and SKB_GSO_TCP_FIXEDID_OUTER when decapsulating a GRE tunnel.
>    *
>    *		* **BPF_F_ADJ_ROOM_DECAP_L4_UDP**:
>    *		  Clear UDP tunnel GSO flags (SKB_GSO_UDP_TUNNEL and
> - *		  SKB_GSO_UDP_TUNNEL_CSUM) when decapsulating a UDP tunnel.
> + *		  SKB_GSO_UDP_TUNNEL_CSUM) and SKB_GSO_TCP_FIXEDID_OUTER when
> + *		  decapsulating a UDP tunnel.
>    *
>    *		* **BPF_F_ADJ_ROOM_DECAP_IPXIP4**:
> - *		  Clear IPIP/SIT tunnel GSO flag (SKB_GSO_IPXIP4) when decapsulating
> - *		  a tunnel with an outer IPv4 header (IPv4-in-IPv4 or IPv6-in-IPv4).
> + *		  Clear IPIP/SIT tunnel GSO flag (SKB_GSO_IPXIP4) and
> + *		  SKB_GSO_TCP_FIXEDID_OUTER when decapsulating a tunnel with an
> + *		  outer IPv4 header (IPv4-in-IPv4 or IPv6-in-IPv4).
>    *
>    *		* **BPF_F_ADJ_ROOM_DECAP_IPXIP6**:
> - *		  Clear IPv6 encapsulation tunnel GSO flag (SKB_GSO_IPXIP6) when
> - *		  decapsulating a tunnel with an outer IPv6 header (IPv6-in-IPv6
> - *		  or IPv4-in-IPv6).
> + *		  Clear IPv6 encapsulation tunnel GSO flag (SKB_GSO_IPXIP6) and
> + *		  SKB_GSO_TCP_FIXEDID_OUTER when decapsulating a tunnel with an
> + *		  outer IPv6 header (IPv6-in-IPv6 or IPv4-in-IPv6).
>    *
>    *		When using the decapsulation flags above, the skb->encapsulation
>    *		flag is automatically cleared if all tunnel-specific GSO flags
> diff --git a/net/core/filter.c b/net/core/filter.c
> index d6a6dd9c9547..5a7957c21d17 100644
> --- a/net/core/filter.c
> +++ b/net/core/filter.c
> @@ -3856,6 +3856,7 @@ static int bpf_skb_net_shrink(struct sk_buff *skb,  
> u32 off, u32 len_diff,
>   		/* Clear encapsulation flag only when no tunnel GSO flags remain */
>   		if (flags & (BPF_F_ADJ_ROOM_DECAP_L4_MASK |
>   			     BPF_F_ADJ_ROOM_DECAP_IPXIP_MASK)) {
> +			shinfo->gso_type &= ~SKB_GSO_TCP_FIXEDID_OUTER;
>   			if (!(shinfo->gso_type & (SKB_GSO_UDP_TUNNEL |
>   						  SKB_GSO_UDP_TUNNEL_CSUM |
>   						  SKB_GSO_GRE |
> diff --git a/net/core/lwt_bpf.c b/net/core/lwt_bpf.c
> index 484cd3b53dea..a7d6fda69f60 100644
> --- a/net/core/lwt_bpf.c
> +++ b/net/core/lwt_bpf.c
> @@ -585,6 +585,8 @@ static int handle_gso_type(struct sk_buff *skb,  
> unsigned int gso_type,
>   	struct skb_shared_info *shinfo = skb_shinfo(skb);

>   	gso_type |= SKB_GSO_DODGY;
> +	/* The outer flag described the header below the new one. */
> +	shinfo->gso_type &= ~SKB_GSO_TCP_FIXEDID_OUTER;
>   	shinfo->gso_type |= gso_type;
>   	skb_decrease_gso_size(shinfo, encap_len);
>   	shinfo->gso_segs = 0;
> diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
> index 5d03a9149b40..c4541c924aaf 100644
> --- a/net/ipv4/af_inet.c
> +++ b/net/ipv4/af_inet.c
> @@ -1404,10 +1404,13 @@ struct sk_buff *inet_gso_segment(struct sk_buff  
> *skb,

>   	segs = ERR_PTR(-EPROTONOSUPPORT);

> -	fixedid = !!(skb_shinfo(skb)->gso_type & (SKB_GSO_TCP_FIXEDID <<  
> encap));
> -
> -	if (!skb->encapsulation || encap)
> +	if (!skb->encapsulation || encap) {
>   		udpfrag = !!(skb_shinfo(skb)->gso_type & SKB_GSO_UDP);
> +		fixedid = !!(skb_shinfo(skb)->gso_type & SKB_GSO_TCP_FIXEDID);
> +	} else {
> +		fixedid = !!(skb_shinfo(skb)->gso_type &
> +			     SKB_GSO_TCP_FIXEDID_OUTER);
> +	}

>   	ops = rcu_dereference(inet_offloads[proto]);
>   	if (likely(ops && ops->callbacks.gso_segment)) {
> diff --git a/net/ipv4/ip_tunnel_core.c b/net/ipv4/ip_tunnel_core.c
> index 6c2855adff28..dbf6bbf25114 100644
> --- a/net/ipv4/ip_tunnel_core.c
> +++ b/net/ipv4/ip_tunnel_core.c
> @@ -193,6 +193,8 @@ int iptunnel_handle_offloads(struct sk_buff *skb,
>   		err = skb_header_unclone(skb, GFP_ATOMIC);
>   		if (unlikely(err))
>   			return err;
> +		/* The outer flag described the header below the new one. */
> +		skb_shinfo(skb)->gso_type &= ~SKB_GSO_TCP_FIXEDID_OUTER;
>   		skb_shinfo(skb)->gso_type |= gso_type_mask;
>   		return 0;
>   	}
> diff --git a/net/ipv4/tcp_offload.c b/net/ipv4/tcp_offload.c
> index 7691be01da4d..93ea20b90550 100644
> --- a/net/ipv4/tcp_offload.c
> +++ b/net/ipv4/tcp_offload.c
> @@ -463,6 +463,8 @@ INDIRECT_CALLABLE_SCOPE int tcp4_gro_complete(struct  
> sk_buff *skb, int thoff)
>   {
>   	const u16 offset =  
> NAPI_GRO_CB(skb)->network_offsets[skb->encapsulation];
>   	const struct iphdr *iph = (struct iphdr *)(skb->data + offset);
> +	const u8 fixedid = NAPI_GRO_CB(skb)->ip_fixedid;
> +	const u8 encap = skb->encapsulation;
>   	struct tcphdr *th = tcp_hdr(skb);

>   	if (unlikely(NAPI_GRO_CB(skb)->is_flist)) {
> @@ -477,9 +479,10 @@ INDIRECT_CALLABLE_SCOPE int tcp4_gro_complete(struct  
> sk_buff *skb, int thoff)
>   	th->check = ~tcp_v4_check(skb->len - thoff, iph->saddr,
>   				  iph->daddr, 0);

> -	BUILD_BUG_ON(SKB_GSO_TCP_FIXEDID << 1 != SKB_GSO_TCP_FIXEDID_INNER);
> +	/* Bit 0 of ip_fixedid is the outermost header, bit 1 the inner one. */
>   	skb_shinfo(skb)->gso_type |= SKB_GSO_TCPV4 |
> -			(NAPI_GRO_CB(skb)->ip_fixedid * SKB_GSO_TCP_FIXEDID);
> +		(((fixedid >> encap) & 1) * SKB_GSO_TCP_FIXEDID) |
> +		((fixedid & encap) * SKB_GSO_TCP_FIXEDID_OUTER);

>   	tcp_gro_complete(skb);
>   	return 0;
> diff --git a/net/ipv6/tcpv6_offload.c b/net/ipv6/tcpv6_offload.c
> index 71feb92aeac2..f232d5b38bbf 100644
> --- a/net/ipv6/tcpv6_offload.c
> +++ b/net/ipv6/tcpv6_offload.c
> @@ -96,7 +96,10 @@ static __always_inline int tcp6_gro_complete(struct  
> sk_buff *skb, int thoff)

>   	th->check = ~tcp_v6_check(skb->len - thoff, &iph->saddr,
>   				  &iph->daddr, 0);
> -	skb_shinfo(skb)->gso_type |= SKB_GSO_TCPV6;
> +	/* Only an IPv4 outer header sets bit 0 of ip_fixedid. */
> +	skb_shinfo(skb)->gso_type |= SKB_GSO_TCPV6 |
> +		((NAPI_GRO_CB(skb)->ip_fixedid & skb->encapsulation) *
> +		 SKB_GSO_TCP_FIXEDID_OUTER);

>   	tcp_gro_complete(skb);
>   	return 0;
> diff --git a/net/xfrm/xfrm_output.c b/net/xfrm/xfrm_output.c
> index f1f612cd7b43..e5bcb845e9ac 100644
> --- a/net/xfrm/xfrm_output.c
> +++ b/net/xfrm/xfrm_output.c
> @@ -791,6 +791,7 @@ int xfrm_output(struct sock *sk, struct sk_buff *skb)
>   	secpath_reset(skb);

>   	if (xfrm_dev_offload_ok(skb, x)) {
> +		bool encap = skb->encapsulation;
>   		struct sec_path *sp;

>   		sp = secpath_set(skb);
> @@ -805,10 +806,25 @@ int xfrm_output(struct sock *sk, struct sk_buff  
> *skb)
>   		xfrm_state_hold(x);

>   		xfrm_get_inner_ipproto(skb, x);
> +		/*
> +		 * Transport and BEET mode keep the IPv4 header and its ID, so
> +		 * the header that SKB_GSO_TCP_FIXEDID describes is the outer
> +		 * one as well.
> +		 */
> +		if (!encap &&
> +		    (x->props.mode == XFRM_MODE_TRANSPORT ||
> +		     x->props.mode == XFRM_MODE_BEET) &&
> +		    (skb_shinfo(skb)->gso_type & SKB_GSO_TCP_FIXEDID))
> +			skb_shinfo(skb)->gso_type |= SKB_GSO_TCP_FIXEDID_OUTER;
>   		skb->encapsulation = 1;

>   		if (skb_is_gso(skb)) {
> -			if (skb->inner_protocol && x->props.mode == XFRM_MODE_TUNNEL)
> +			/*
> +			 * inner_protocol is only valid on an encapsulated skb:
> +			 * a tunnel that decapsulated the packet leaves it set.
> +			 */
> +			if (encap && skb->inner_protocol &&
> +			    x->props.mode == XFRM_MODE_TUNNEL)
>   				return xfrm_output_gso(net, sk, skb);

>   			skb_shinfo(skb)->gso_type |= SKB_GSO_ESP;

Please respond to the sashiko finding:

[Severity: Medium]
When !encap and a stale skb->inner_protocol remains from an earlier tunnel
decapsulation, does skipping xfrm_output_gso() without clearing
skb->inner_protocol cause xfrm4_tunnel_encap_add() and
xfrm6_tunnel_encap_add() to skip saving the inner header offsets?

net/xfrm/xfrm_output.c:xfrm4_tunnel_encap_add() {
	...
	if (!skb->inner_protocol) {
		skb_set_inner_network_header(skb, skb_network_offset(skb));
		skb_set_inner_transport_header(skb, skb_transport_offset(skb));
	}
	...
}

For a decapsulated SKB_GSO_FRAGLIST GRO packet (where inet_gro_complete()  
set
skb->inner_protocol, while tcp4_gro_complete() returned early on is_flist
without calling tcp_gro_complete() to set inner_transport_header),
inner_transport_header is left unset when xfrm4_tunnel_encap_add() pushes  
the
outer IP header.  qdisc_pkt_len_segs_init() then sees a negative or invalid
skb_inner_transport_offset(skb) on the offloaded SKB_GSO_ESP packet and  
drops
it with SKB_DROP_REASON_SKB_BAD_GSO.

https://lore.kernel.org/all/sashiko-outbox-239682@kernel.org/#t


  reply	other threads:[~2026-12-04  4:10 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-28 14:07 [PATCH net-next v4 0/2] net: keep the TCP fixed-ID flags on the header they describe Julius Bairaktaris
2026-11-28 14:07 ` [PATCH net-next v4 1/2] " Julius Bairaktaris
2026-12-04  4:10   ` willemb [this message]
2026-11-28 14:07 ` [PATCH net-next v4 2/2] selftests: net: check TCP IP IDs across tunnels after GRO and GSO Julius Bairaktaris

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=willemb.26a81c70aad48@google.com \
    --to=willemb@google.com \
    --cc=alex.austin@amd.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=andrii@kernel.org \
    --cc=andy.moreton@amd.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=corbet@lwn.net \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=ecree.xilinx@gmail.com \
    --cc=eddyz87@gmail.com \
    --cc=edumazet@kernel.org \
    --cc=emil@etsalapatis.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=horms@kernel.org \
    --cc=idosch@nvidia.com \
    --cc=ihor.solodrai@linux.dev \
    --cc=ipsec@lists.linux.dev \
    --cc=izaiahsun@gmail.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=julius@bairaktaris.de \
    --cc=kuba@kernel.org \
    --cc=kuniyu@google.com \
    --cc=leon@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-net-drivers@amd.com \
    --cc=linux-rdma@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=mbloch@nvidia.com \
    --cc=memxor@gmail.com \
    --cc=ncardwell@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=rdunlap@infradead.org \
    --cc=richardbgobert@gmail.com \
    --cc=saeedm@nvidia.com \
    --cc=sdf@fomichev.me \
    --cc=shuah@kernel.org \
    --cc=skhan@linuxfoundation.org \
    --cc=song@kernel.org \
    --cc=steffen.klassert@secunet.com \
    --cc=tariqt@nvidia.com \
    --cc=yonghong.song@linux.dev \
    --cc=zirajs7@gmail.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