* [PATCH net-next v5 0/2] net: keep the TCP fixed-ID flags on the header they describe
@ 2026-12-04 22:45 Julius Bairaktaris
2026-12-04 22:45 ` [PATCH net-next v5 1/2] " Julius Bairaktaris
2026-12-04 22:45 ` [PATCH net-next v5 2/2] selftests: net: check TCP IP IDs across tunnels after GRO and GSO Julius Bairaktaris
0 siblings, 2 replies; 3+ messages in thread
From: Julius Bairaktaris @ 2026-12-04 22:45 UTC (permalink / raw)
To: netdev
Cc: davem, edumazet, kuba, pabeni, willemb, horms, andrew+netdev,
dsahern, idosch, ncardwell, kuniyu, steffen.klassert, herbert,
ecree.xilinx, andy.moreton, alex.austin, linux-net-drivers,
saeedm, tariqt, mbloch, leon, linux-rdma, alexei.starovoitov, ast,
daniel, andrii, eddyz87, memxor, martin.lau, song, yonghong.song,
jolsa, emil, ihor.solodrai, john.fastabend, sdf, izaiahsun,
zirajs7, corbet, skhan, rdunlap, shuah, bpf, ipsec, linux-doc,
linux-kselftest, linux-kernel
GRO sets SKB_GSO_TCP_FIXEDID for a TCP packet whose IPv4 IDs do not
change. Since commit 3271f19bf7b9 ("net: gso: restore ids of outer ip
headers correctly") the flag describes the outermost header and
SKB_GSO_TCP_FIXEDID_INNER the inner one, so every path that adds or
removes a header would have to move the flags. None does, and a TCP
stream that GRO merged and that crosses a tunnel boundary is segmented
with the fixed-ID state of the wrong header.
Patch 1 lets SKB_GSO_TCP_FIXEDID describe the innermost header again and
replaces the inner flag with SKB_GSO_TCP_FIXEDID_OUTER, as Alexei
suggested in review of v1. iptunnel_handle_offloads() and the BPF LWT
encapsulation clear the outer flag when they add a header,
iptunnel_pull_offloads() and bpf_skb_net_shrink() when they remove one,
and ESP transport and BEET mode with crypto offload, which keep the IPv4
header, copy the inner flag to the outer one. GRO of an IPv6 stream in
an IPv4 tunnel sets the outer flag as it does for an IPv4 stream, and
xfrm_output() no longer treats a decapsulated packet as an encapsulated
one. Two flags cannot describe the middle header 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. Patch 2 adds a selftest.
A host with GRO on its ingress device that forwards a TCP stream into or
out of an IPIP, GRE, VXLAN or crypto-offloaded ESP tunnel sends IPv4 IDs
that repeat across the segments of a tunnel's outer header, or that
change on a header whose IDs the sender kept fixed.
The hosted Sashiko AI review of v2 2/3 of my "ipmr: forward GSO multicast
packets" series reported the issue [1], its reviews of the later
versions the IPv6, xfrm_output() and selftest points, and the selftest
in patch 2 reproduces each.
Tested in QEMU (KVM) with the selftest, 25 cases, 400 segments each:
- net-next (d5cf954cebe4), the 6in4 and ESP cases, 1 run: 6in4 with
fixed outer IDs fails (390 outer IDs the sender did not write), the
ESP tunnel mode cases fail (390 of 400 inner IDs renumbered, or after
fraglist GRO no outer ID increments), ESP transport mode after VXLAN
decapsulation fails (390), and after fraglist GRO all 400 segments
are dropped as SKB_BAD_GSO.
- v4, the same cases, 2 runs: both ESP cases after VXLAN decapsulation
with fraglist GRO lose all 400 segments (SKB_BAD_GSO), the rest pass.
- this series, the same cases, 1 run, and the whole selftest, 3 runs:
every case passes.
Changes in v5:
- Patch 1: in xfrm_output(), clear skb->inner_protocol in the crypto
offload path for a packet that is not encapsulated, so that the tunnel
and transport mode outputs record its inner headers; after fraglist
GRO and a decapsulation v4 dropped the ESP packet as SKB_BAD_GSO
(Sashiko, Willem).
- Patch 2: check the 6in4 outer IDs against the values the sender wrote
(Sashiko); add ESP cases after VXLAN decapsulation with fraglist GRO
and in transport mode.
- Rebased onto net-next d5cf954cebe4.
- The flowtable's IPIP and IP6IP6 decapsulation keeps the encapsulation
state of the removed header, with and without this series (Sashiko);
that is a separate netfilter fix.
- v4: https://lore.kernel.org/netdev/cover.1795869698.git.julius@bairaktaris.de/
- v3: https://lore.kernel.org/netdev/cover.1795284858.git.julius@bairaktaris.de/
- v2: https://lore.kernel.org/netdev/cover.1794139176.git.julius@bairaktaris.de/
- v1: https://lore.kernel.org/netdev/cover.1792857378.git.julius@bairaktaris.de/
[1] https://lore.kernel.org/netdev/179182559332.434549.18294510093742639467@kernel.org/
I used Claude (Anthropic) to help write these patches.
Julius Bairaktaris (2):
net: keep the TCP fixed-ID flags on the header they describe
selftests: net: check TCP IP IDs across tunnels after GRO and GSO
.../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 | 20 +
tools/include/uapi/linux/bpf.h | 16 +-
tools/testing/selftests/net/.gitignore | 1 +
tools/testing/selftests/net/Makefile | 2 +
tools/testing/selftests/net/tcp_fixedid.c | 554 ++++++++++++++++++
tools/testing/selftests/net/tcp_fixedid.sh | 494 ++++++++++++++++
19 files changed, 1132 insertions(+), 40 deletions(-)
create mode 100644 tools/testing/selftests/net/tcp_fixedid.c
create mode 100755 tools/testing/selftests/net/tcp_fixedid.sh
base-commit: d5cf954cebe4f175dfd834e1dc471a3aa203ec7d
--
2.53.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH net-next v5 1/2] net: keep the TCP fixed-ID flags on the header they describe
2026-12-04 22:45 [PATCH net-next v5 0/2] net: keep the TCP fixed-ID flags on the header they describe Julius Bairaktaris
@ 2026-12-04 22:45 ` Julius Bairaktaris
2026-12-04 22:45 ` [PATCH net-next v5 2/2] selftests: net: check TCP IP IDs across tunnels after GRO and GSO Julius Bairaktaris
1 sibling, 0 replies; 3+ messages in thread
From: Julius Bairaktaris @ 2026-12-04 22:45 UTC (permalink / raw)
To: netdev
Cc: davem, edumazet, kuba, pabeni, willemb, horms, andrew+netdev,
dsahern, idosch, ncardwell, kuniyu, steffen.klassert, herbert,
ecree.xilinx, andy.moreton, alex.austin, linux-net-drivers,
saeedm, tariqt, mbloch, leon, linux-rdma, alexei.starovoitov, ast,
daniel, andrii, eddyz87, memxor, martin.lau, song, yonghong.song,
jolsa, emil, ihor.solodrai, john.fastabend, sdf, izaiahsun,
zirajs7, corbet, skhan, rdunlap, shuah, bpf, ipsec, linux-doc,
linux-kselftest, linux-kernel
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.
A tunnel that decapsulates a packet clears skb->encapsulation but leaves
skb->inner_protocol set, and xfrm_output() takes that for an
encapsulated packet. With crypto offload it segments a GSO packet for a
tunnel mode SA before ESP, and segmentation then reads the outer flag
for the only IPv4 header left. The tunnel and transport mode outputs
also keep the inner header offsets they find instead of recording the
packet's own; after fraglist GRO those were never set, and
qdisc_pkt_len_segs_init() drops the ESP packet as SKB_BAD_GSO. Clear
inner_protocol in the crypto offload path for a packet that is not
encapsulated. iptunnel_handle_offloads() leaves the same state on a
packet without offloads, whose inner headers are then also the ones the
mode output records.
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>
---
v5:
- Clear skb->inner_protocol in the crypto offload path of xfrm_output()
for a packet that is not encapsulated, so that the tunnel and
transport mode outputs record its inner headers; v4 only kept such a
packet out of xfrm_output_gso(), and after fraglist GRO and a
decapsulation the ESP packet was dropped as SKB_BAD_GSO (Sashiko,
Willem).
- Rebased onto net-next d5cf954cebe4.
- The flowtable's IPIP and IP6IP6 decapsulation, nf_flow_ip_tunnel_pop(),
removes the header without iptunnel_pull_offloads() and keeps the
encapsulation state of the removed header, with and without this
patch (Sashiko); that is a separate netfilter fix.
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/
v4: https://lore.kernel.org/netdev/c9ec995833aac63f552441e4a60bf420a0a52275.1795869698.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 | 20 +++++++++++++++++++
tools/include/uapi/linux/bpf.h | 16 ++++++++-------
15 files changed, 81 insertions(+), 40 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 87046ba50d45..9881fcf57b6c 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 6840ca5b923b..08c75e8e3fb8 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -3098,20 +3098,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 88b8604133da..4cd2e15cf439 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -3863,6 +3863,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 60ffe9549c09..00a1f69cf9cc 100644
--- a/net/xfrm/xfrm_output.c
+++ b/net/xfrm/xfrm_output.c
@@ -794,6 +794,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);
@@ -807,7 +808,26 @@ int xfrm_output(struct sock *sk, struct sk_buff *skb)
sp->xvec[sp->len++] = x;
xfrm_state_hold(x);
+ /*
+ * inner_protocol is only valid on an encapsulated skb: a tunnel
+ * that decapsulated the packet leaves it set, and so does
+ * iptunnel_handle_offloads() on a packet without offloads.
+ * Clear it, so that the mode output records this packet's
+ * inner headers.
+ */
+ if (!encap)
+ skb->inner_protocol = 0;
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)) {
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index 6840ca5b923b..08c75e8e3fb8 100644
--- a/tools/include/uapi/linux/bpf.h
+++ b/tools/include/uapi/linux/bpf.h
@@ -3098,20 +3098,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
--
2.53.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH net-next v5 2/2] selftests: net: check TCP IP IDs across tunnels after GRO and GSO
2026-12-04 22:45 [PATCH net-next v5 0/2] net: keep the TCP fixed-ID flags on the header they describe Julius Bairaktaris
2026-12-04 22:45 ` [PATCH net-next v5 1/2] " Julius Bairaktaris
@ 2026-12-04 22:45 ` Julius Bairaktaris
1 sibling, 0 replies; 3+ messages in thread
From: Julius Bairaktaris @ 2026-12-04 22:45 UTC (permalink / raw)
To: netdev
Cc: davem, edumazet, kuba, pabeni, willemb, horms, andrew+netdev,
dsahern, idosch, ncardwell, kuniyu, steffen.klassert, herbert,
ecree.xilinx, andy.moreton, alex.austin, linux-net-drivers,
saeedm, tariqt, mbloch, leon, linux-rdma, alexei.starovoitov, ast,
daniel, andrii, eddyz87, memxor, martin.lau, song, yonghong.song,
jolsa, emil, ihor.solodrai, john.fastabend, sdf, izaiahsun,
zirajs7, corbet, skhan, rdunlap, shuah, bpf, ipsec, linux-doc,
linux-kselftest, linux-kernel
Send TCP segments with fixed or incrementing IPv4 IDs from a packet
socket, let GRO on a veth merge them, forward the merged packets into
IPIP, GRE and VXLAN tunnels over IPv4 and IPv6 and into ESP tunnel and
transport mode SAs offloaded to netdevsim, with segmentation done in
software, and check that the IDs of the IPv4 header in front of TCP come
out as they went in and the IDs of a new outer IPv4 header are unique,
or for ESP tunnel mode increment within each packet. Also forward a
VXLAN stream with one header's IDs fixed after decapsulation into IPIP
and into the ESP SAs, and after fraglist GRO, which records no fixed
IDs, a VXLAN stream with incrementing IDs into the ESP SAs, forward IPv6
TCP in IPv4 (6in4) with fixed and incrementing outer IDs, which must
come out as they went in, and send the merged packets through a tunnel
that the far end decapsulates without segmenting them before it
forwards them. The receiver compares the inner IDs, and the outer IDs
of 6in4, with the values the sender wrote.
The receiver reads a packet ring with room for five times the segments
of a test, so that it loses none while it is not scheduled, and a test
fails if the socket dropped a frame. A test where GRO merged nothing is
skipped.
Signed-off-by: Julius Bairaktaris <julius@bairaktaris.de>
---
v5:
- Check the 6in4 outer IDs against the values the sender wrote, not only
their number (Sashiko).
- Add ESP tunnel and transport mode cases after VXLAN decapsulation with
fraglist GRO, and an ESP transport mode case after VXLAN
decapsulation.
v4:
- Read the frames from a PACKET_RX_RING with room for every frame of a
case, and fail a case on a socket drop; the socket buffer overflowed
on NIPA (Paolo).
- Add 6in4 cases with fixed and incrementing outer IDs, and an ESP
tunnel mode case after VXLAN decapsulation.
v3:
- Add an ESP transport mode case.
- Skip a run without GRO merging before the outer IDs are checked; check
that ESP tunnel mode outer IDs increment within each packet (Sashiko).
- Delete only the netdevsim devices the test created, also from the EXIT
trap, before the namespaces (Sashiko).
- Make the receiver's -c optional (Sashiko).
- Use slowwait and check_gen_prog from lib.sh; create the netdevsim
devices inside their namespace with the new_device write checked
(Sashiko).
- Report a receiver that is not bound within 10 s as such.
- Fix shellcheck SC2016, wrap lines at 80 columns (NIPA).
v2: https://lore.kernel.org/netdev/c4f9c977725ee51341ca84dedf2dddb9fcb4e8ea.1794139176.git.julius@bairaktaris.de/
v3: https://lore.kernel.org/netdev/2f75527eb49d7d4ffec32a61fd7dd080673dc57f.1795284858.git.julius@bairaktaris.de/
v4: https://lore.kernel.org/netdev/76a1e3c7dfde1c191c0c2aafb3e8bdee28dd0fa4.1795869698.git.julius@bairaktaris.de/
tools/testing/selftests/net/.gitignore | 1 +
tools/testing/selftests/net/Makefile | 2 +
tools/testing/selftests/net/tcp_fixedid.c | 554 +++++++++++++++++++++
tools/testing/selftests/net/tcp_fixedid.sh | 494 ++++++++++++++++++
4 files changed, 1051 insertions(+)
create mode 100644 tools/testing/selftests/net/tcp_fixedid.c
create mode 100755 tools/testing/selftests/net/tcp_fixedid.sh
diff --git a/tools/testing/selftests/net/.gitignore b/tools/testing/selftests/net/.gitignore
index 83d68e2dd4ac..79a9eb065fbd 100644
--- a/tools/testing/selftests/net/.gitignore
+++ b/tools/testing/selftests/net/.gitignore
@@ -48,6 +48,7 @@ so_rcv_listener
stress_reuseport_listen
tap
tcp_fastopen_backup_key
+tcp_fixedid
tcp_inq
tcp_mmap
tcp_port_share
diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile
index 4409ecaf0b5f..2ab9f6964d07 100644
--- a/tools/testing/selftests/net/Makefile
+++ b/tools/testing/selftests/net/Makefile
@@ -111,6 +111,7 @@ TEST_PROGS := \
stress_reuseport_listen.sh \
tcp_ecmp_failover.sh \
tcp_fastopen_backup_key.sh \
+ tcp_fixedid.sh \
test_bridge_backup_port.sh \
test_bridge_neigh_suppress.sh \
test_ingress_egress_chaining.sh \
@@ -175,6 +176,7 @@ TEST_GEN_FILES := \
socket \
stress_reuseport_listen \
tcp_fastopen_backup_key \
+ tcp_fixedid \
tcp_inq \
tcp_mmap \
tfo \
diff --git a/tools/testing/selftests/net/tcp_fixedid.c b/tools/testing/selftests/net/tcp_fixedid.c
new file mode 100644
index 000000000000..6013d4606de7
--- /dev/null
+++ b/tools/testing/selftests/net/tcp_fixedid.c
@@ -0,0 +1,554 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Send TCP segments with fixed or incrementing IPv4 IDs, optionally in
+ * VXLAN, or IPv6 TCP segments in IPv4 (6in4), and report the IP IDs of TCP
+ * segments received on a device, also inside IPIP, 6in4, GRE, VXLAN or ESP.
+ *
+ * tx: tcp_fixedid -T -i dev -M dmac -s saddr -d daddr [-f] [-n segs]
+ * [-b bursts] [-l len] [-V osaddr,odaddr -m inner_dmac [-F]]
+ * tcp_fixedid -T -i dev -M dmac -P osaddr,odaddr [-F] [-n segs]
+ * [-b bursts] [-l len]
+ * rx: tcp_fixedid -R -i dev [-f] [-F | -O] [-c segs] [-w ms] [-l len]
+ *
+ * The receiver prints "ready" once it is bound, then the number of
+ * segments, of segments with an outer IPv4 header, of distinct outer and
+ * inner IDs, of inner IDs the sender did not use (other than the fixed ID
+ * with -f, outside the -c incrementing IDs without it), of outer IDs that
+ * are the previous segment's plus one, of frames the socket dropped, and
+ * of outer IDs the sender did not write (other than the fixed ID with -F,
+ * other than the segment's own incrementing ID with -O, the segment found
+ * from its TCP sequence number).
+ * It reads from a PACKET_RX_RING with room for every frame of a run, so
+ * that nothing is dropped while it is not scheduled.
+ * The outer header is the outermost one, the inner header the IPv4 header
+ * in front of TCP; IPv6 TCP segments in 6in4 have only an outer header.
+ */
+
+#include <arpa/inet.h>
+#include <errno.h>
+#include <error.h>
+#include <linux/if_packet.h>
+#include <net/ethernet.h>
+#include <net/if.h>
+#include <netinet/ip.h>
+#include <netinet/ip6.h>
+#include <netinet/tcp.h>
+#include <netinet/udp.h>
+#include <netinet/in.h>
+#include <poll.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/mman.h>
+#include <sys/socket.h>
+#include <time.h>
+#include <unistd.h>
+
+#define TEST_PORT 9000
+#define VXLAN_PORT 4789
+#define FIXED_ID 0x1234
+#define INCR_ID 0x1000
+#define OUTER_ID 0x2000
+/* ICV length of rfc4106(gcm(aes)) with a 128 bit tag */
+#define ESP_ICV_LEN 16
+/* receive ring: five times the 400 segments of a test, 1514 byte frames */
+#define RX_FRAMES 2048
+#define RX_FRAME_SIZE 2048
+
+static const char *ifname;
+static bool fixed_id, fixed_outer, incr_outer;
+static int segs = 40, bursts = 10, len = 1000, wait_ms = 2000, stop;
+static struct in_addr saddr, daddr, osaddr, odaddr;
+static bool vxlan, sixinfour;
+/* inner addresses of the 6in4 segments */
+static const struct in6_addr saddr6 = { { { 0xfd, 0x09, [15] = 1 } } };
+static const struct in6_addr daddr6 = { { { 0xfd, 0x09, [15] = 2 } } };
+static unsigned char dmac[ETH_ALEN], inner_dmac[ETH_ALEN];
+static unsigned char *ring;
+
+static void parse_mac(const char *s, unsigned char *mac)
+{
+ if (sscanf(s, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &mac[0], &mac[1],
+ &mac[2], &mac[3], &mac[4], &mac[5]) != 6)
+ error(1, 0, "bad mac %s", s);
+}
+
+static void parse_addr(const char *s, struct in_addr *a)
+{
+ if (inet_pton(AF_INET, s, a) != 1)
+ error(1, 0, "bad address %s", s);
+}
+
+static uint32_t csum_add(uint32_t sum, const void *data, size_t n)
+{
+ const uint8_t *p = data;
+
+ while (n > 1) {
+ sum += (p[0] << 8) | p[1];
+ p += 2;
+ n -= 2;
+ }
+ if (n)
+ sum += p[0] << 8;
+ return sum;
+}
+
+static uint16_t csum_fold(uint32_t sum)
+{
+ while (sum >> 16)
+ sum = (sum & 0xffff) + (sum >> 16);
+ return htons(~sum & 0xffff);
+}
+
+static void build_ip(struct iphdr *iph, int proto, int payload, uint16_t id,
+ struct in_addr s, struct in_addr d)
+{
+ memset(iph, 0, sizeof(*iph));
+ iph->version = 4;
+ iph->ihl = 5;
+ iph->tot_len = htons(sizeof(*iph) + payload);
+ iph->id = htons(id);
+ iph->frag_off = htons(IP_DF);
+ iph->ttl = 64;
+ iph->protocol = proto;
+ iph->saddr = s.s_addr;
+ iph->daddr = d.s_addr;
+ iph->check = csum_fold(csum_add(0, iph, sizeof(*iph)));
+}
+
+static void build_eth(unsigned char *p, const unsigned char *mac)
+{
+ struct ethhdr *eth = (struct ethhdr *)p;
+
+ memcpy(eth->h_dest, mac, ETH_ALEN);
+ memset(eth->h_source, 0, ETH_ALEN);
+ eth->h_source[0] = 0x02;
+ eth->h_source[5] = 0x01;
+ eth->h_proto = htons(ETH_P_IP);
+}
+
+/* TCP header and payload of segment @i at @th, checksum not set */
+static void build_th(struct tcphdr *th, int i)
+{
+ memset(th, 0, sizeof(*th));
+ th->source = htons(TEST_PORT + 1);
+ th->dest = htons(TEST_PORT);
+ th->seq = htonl(1 + i * len);
+ th->ack_seq = htonl(1);
+ th->doff = 5;
+ th->ack = 1;
+ th->window = htons(65535);
+ memset(th + 1, 'a' + i % 26, len);
+}
+
+/* IPv4 and TCP header plus payload for segment @i at @p */
+static int build_tcp(unsigned char *p, int i, uint16_t id)
+{
+ struct iphdr *iph = (struct iphdr *)p;
+ struct tcphdr *th = (struct tcphdr *)(iph + 1);
+ struct {
+ uint32_t s, d;
+ uint8_t zero, proto;
+ uint16_t len;
+ } ph; /* 12 bytes, no padding */
+ uint32_t sum;
+
+ build_ip(iph, IPPROTO_TCP, sizeof(*th) + len, id, saddr, daddr);
+ build_th(th, i);
+
+ ph.s = iph->saddr;
+ ph.d = iph->daddr;
+ ph.zero = 0;
+ ph.proto = IPPROTO_TCP;
+ ph.len = htons(sizeof(*th) + len);
+ sum = csum_add(0, &ph, sizeof(ph));
+ th->check = csum_fold(csum_add(sum, th, sizeof(*th) + len));
+
+ return sizeof(*iph) + sizeof(*th) + len;
+}
+
+/* IPv6 and TCP header plus payload for segment @i at @p */
+static int build_tcp6(unsigned char *p, int i)
+{
+ struct ip6_hdr *ip6h = (struct ip6_hdr *)p;
+ struct tcphdr *th = (struct tcphdr *)(ip6h + 1);
+ struct {
+ struct in6_addr s, d;
+ uint32_t len;
+ uint8_t zero[3], nxt;
+ } ph; /* 40 bytes, no padding */
+ uint32_t sum;
+
+ memset(ip6h, 0, sizeof(*ip6h));
+ ip6h->ip6_flow = htonl(6 << 28);
+ ip6h->ip6_plen = htons(sizeof(*th) + len);
+ ip6h->ip6_nxt = IPPROTO_TCP;
+ ip6h->ip6_hlim = 64;
+ ip6h->ip6_src = saddr6;
+ ip6h->ip6_dst = daddr6;
+ build_th(th, i);
+
+ memset(&ph, 0, sizeof(ph));
+ ph.s = saddr6;
+ ph.d = daddr6;
+ ph.len = htonl(sizeof(*th) + len);
+ ph.nxt = IPPROTO_TCP;
+ sum = csum_add(0, &ph, sizeof(ph));
+ th->check = csum_fold(csum_add(sum, th, sizeof(*th) + len));
+
+ return sizeof(*ip6h) + sizeof(*th) + len;
+}
+
+static int do_tx(int fd, struct sockaddr_ll *sll)
+{
+ unsigned char buf[ETH_FRAME_LEN + 128];
+ struct iphdr *oiph = (struct iphdr *)(buf + sizeof(struct ethhdr));
+ int b, s, i = 0, n;
+
+ for (b = 0; b < bursts; b++) {
+ for (s = 0; s < segs; s++, i++) {
+ uint16_t id = fixed_id ? FIXED_ID : INCR_ID + i;
+ uint16_t oid = fixed_outer ? FIXED_ID : OUTER_ID + i;
+
+ build_eth(buf, dmac);
+ if (vxlan) {
+ struct udphdr *uh = (struct udphdr *)(oiph + 1);
+ uint32_t *vx = (uint32_t *)(uh + 1);
+ unsigned char *ieth = (unsigned char *)(vx + 2);
+
+ build_eth(ieth, inner_dmac);
+ n = sizeof(struct ethhdr) +
+ build_tcp(ieth + sizeof(struct ethhdr), i,
+ id);
+ memset(uh, 0, sizeof(*uh));
+ uh->source = htons(VXLAN_PORT + 1);
+ uh->dest = htons(VXLAN_PORT);
+ uh->len = htons(sizeof(*uh) + 8 + n);
+ vx[0] = htonl(0x08000000);
+ vx[1] = htonl(42 << 8);
+ n += sizeof(*uh) + 8;
+ build_ip(oiph, IPPROTO_UDP, n, oid, osaddr,
+ odaddr);
+ n += sizeof(*oiph);
+ } else if (sixinfour) {
+ n = build_tcp6((unsigned char *)(oiph + 1), i);
+ build_ip(oiph, IPPROTO_IPV6, n, oid, osaddr,
+ odaddr);
+ n += sizeof(*oiph);
+ } else {
+ n = build_tcp((unsigned char *)oiph, i, id);
+ }
+ n += sizeof(struct ethhdr);
+
+ if (sendto(fd, buf, n, 0, (struct sockaddr *)sll,
+ sizeof(*sll)) != n)
+ error(1, errno, "sendto");
+ }
+ usleep(50000);
+ }
+ return 0;
+}
+
+/*
+ * Find a TCP segment to TEST_PORT, returned in @tcp; return in @inner4 the
+ * IPv4 header in front of it, NULL for IPv6, and in @outer4 the outermost
+ * IPv4 header if that is another one.
+ */
+static bool find_tcp(const unsigned char *p, int n, const struct tcphdr **tcp,
+ const struct iphdr **inner4, const struct iphdr **outer4)
+{
+ const struct ethhdr *eth = (const struct ethhdr *)p;
+ const unsigned char *end = p + n;
+ uint16_t etype;
+ int depth;
+
+ *inner4 = NULL;
+ *outer4 = NULL;
+ if (n < (int)sizeof(*eth))
+ return false;
+ etype = eth->h_proto;
+ p += sizeof(*eth);
+
+ for (depth = 0; depth < 2; depth++) {
+ const struct iphdr *iph = NULL;
+ const unsigned char *l4;
+ int proto;
+
+ if (etype == htons(ETH_P_IP)) {
+ iph = (const struct iphdr *)p;
+ if (p + sizeof(*iph) > end)
+ return false;
+ proto = iph->protocol;
+ l4 = p + iph->ihl * 4;
+ } else if (etype == htons(ETH_P_IPV6)) {
+ const struct ip6_hdr *ip6h = (const struct ip6_hdr *)p;
+
+ if (p + sizeof(*ip6h) > end)
+ return false;
+ proto = ip6h->ip6_nxt;
+ l4 = p + sizeof(*ip6h);
+ } else {
+ return false;
+ }
+
+ if (proto == IPPROTO_ESP) {
+ /* SPI, sequence number and the 8 byte IV; netdevsim
+ * does not encrypt, so the next header field in front
+ * of the ICV can be read
+ */
+ if (l4 + 16 > end - ESP_ICV_LEN - 1)
+ return false;
+ proto = end[-ESP_ICV_LEN - 1];
+ l4 += 16;
+ }
+ if (proto == IPPROTO_TCP) {
+ const struct tcphdr *th = (const struct tcphdr *)l4;
+
+ if (l4 + sizeof(*th) > end ||
+ th->dest != htons(TEST_PORT))
+ return false;
+ *tcp = th;
+ *inner4 = iph;
+ return true;
+ }
+ if (!depth)
+ *outer4 = iph;
+
+ /* step over the tunnel header to the next IPv4 header */
+ etype = htons(ETH_P_IP);
+ if (proto == IPPROTO_IPIP) {
+ p = l4;
+ } else if (proto == IPPROTO_IPV6) {
+ etype = htons(ETH_P_IPV6);
+ p = l4;
+ } else if (proto == IPPROTO_GRE) {
+ uint16_t flags;
+
+ if (l4 + 4 > end)
+ return false;
+ flags = (l4[0] << 8) | l4[1];
+ if (((l4[2] << 8) | l4[3]) != ETH_P_IP)
+ return false;
+ p = l4 + 4 + 4 * (!!(flags & 0x8000) +
+ !!(flags & 0x2000) +
+ !!(flags & 0x1000));
+ } else if (proto == IPPROTO_UDP) {
+ const struct udphdr *uh = (const struct udphdr *)l4;
+
+ if (l4 + sizeof(*uh) + 8 + sizeof(*eth) > end ||
+ uh->dest != htons(VXLAN_PORT))
+ return false;
+ p = l4 + sizeof(*uh) + 8 + sizeof(*eth);
+ } else {
+ return false;
+ }
+ }
+ return false;
+}
+
+static void count_id(uint8_t *map, unsigned int *distinct, uint16_t id)
+{
+ if (!(map[id / 8] & (1 << (id % 8)))) {
+ map[id / 8] |= 1 << (id % 8);
+ (*distinct)++;
+ }
+}
+
+/* map a TPACKET_V2 receive ring of RX_FRAMES frames, incoming frames only */
+static void rx_setup(int fd)
+{
+ int block = getpagesize(), v = TPACKET_V2, one = 1;
+ struct tpacket_req req = {};
+
+ if (block < RX_FRAME_SIZE)
+ block = RX_FRAME_SIZE;
+ req.tp_block_size = block;
+ req.tp_frame_size = RX_FRAME_SIZE;
+ req.tp_block_nr = RX_FRAMES / (block / RX_FRAME_SIZE);
+ req.tp_frame_nr = RX_FRAMES;
+ if (setsockopt(fd, SOL_PACKET, PACKET_VERSION, &v, sizeof(v)) ||
+ setsockopt(fd, SOL_PACKET, PACKET_RX_RING, &req, sizeof(req)) ||
+ setsockopt(fd, SOL_PACKET, PACKET_IGNORE_OUTGOING, &one,
+ sizeof(one)))
+ error(1, errno, "rx ring");
+ ring = mmap(NULL, (size_t)block * req.tp_block_nr,
+ PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+ if (ring == MAP_FAILED)
+ error(1, errno, "mmap");
+}
+
+static int do_rx(int fd)
+{
+ static uint8_t outer_map[8192], inner_map[8192];
+ unsigned int frames = 0, outer4 = 0, outer_ids = 0, inner_ids = 0;
+ unsigned int inner_bad = 0, outer_bad = 0, outer_incr = 0, slot = 0;
+ uint16_t last_outer = 0;
+ struct pollfd pfd = { .fd = fd, .events = POLLIN };
+ struct tpacket_stats st = {};
+ socklen_t sl = sizeof(st);
+
+ if (stop > RX_FRAMES / 2)
+ error(1, 0, "-c %d: more than %d", stop, RX_FRAMES / 2);
+ printf("ready\n");
+ fflush(stdout);
+
+ for (;;) {
+ struct tpacket2_hdr *h = (struct tpacket2_hdr *)
+ (ring + (size_t)slot * RX_FRAME_SIZE);
+ const struct iphdr *iph, *oiph;
+ const struct tcphdr *th;
+ uint16_t id, seg;
+
+ if (!(__atomic_load_n(&h->tp_status, __ATOMIC_ACQUIRE) &
+ TP_STATUS_USER)) {
+ /* wait longer for the first segment than later */
+ if (poll(&pfd, 1, frames ? wait_ms : 10 * wait_ms) <= 0)
+ break;
+ /* the device went away (ENETDOWN) */
+ if (pfd.revents & (POLLERR | POLLHUP | POLLNVAL))
+ error(1, 0, "poll: socket error");
+ continue;
+ }
+ if (h->tp_snaplen != h->tp_len)
+ error(1, 0, "frame of %u bytes truncated", h->tp_len);
+ if (!find_tcp((unsigned char *)h + h->tp_mac, h->tp_snaplen,
+ &th, &iph, &oiph))
+ goto release;
+ frames++;
+ /* the sender's index of this segment */
+ seg = (ntohl(th->seq) - 1) / len;
+ if (iph) {
+ id = ntohs(iph->id);
+ count_id(inner_map, &inner_ids, id);
+ if (fixed_id ? id != FIXED_ID :
+ stop && (uint16_t)(id - INCR_ID) >= stop)
+ inner_bad++;
+ }
+ if (oiph) {
+ id = ntohs(oiph->id);
+ if (outer4 && id == (uint16_t)(last_outer + 1))
+ outer_incr++;
+ last_outer = id;
+ outer4++;
+ count_id(outer_map, &outer_ids, id);
+ if (fixed_outer ? id != FIXED_ID :
+ incr_outer && id != (uint16_t)(OUTER_ID + seg))
+ outer_bad++;
+ }
+release:
+ /* the slot is the kernel's again once it is read */
+ __atomic_store_n(&h->tp_status, TP_STATUS_KERNEL,
+ __ATOMIC_RELEASE);
+ slot = (slot + 1) % RX_FRAMES;
+ if (stop && frames == (unsigned int)stop)
+ break;
+ }
+
+ if (getsockopt(fd, SOL_PACKET, PACKET_STATISTICS, &st, &sl))
+ error(1, errno, "PACKET_STATISTICS");
+ printf("frames %u outer4 %u outer_ids %u inner_ids %u inner_bad %u ",
+ frames, outer4, outer_ids, inner_ids, inner_bad);
+ printf("outer_incr %u drops %u outer_bad %u\n", outer_incr, st.tp_drops,
+ outer_bad);
+ return 0;
+}
+
+int main(int argc, char **argv)
+{
+ struct sockaddr_ll sll = {};
+ bool tx = false, rx = false;
+ char *comma;
+ int c, fd;
+
+ while ((c = getopt(argc, argv,
+ "TRi:M:s:d:fn:b:l:V:P:m:FOw:c:")) != -1) {
+ switch (c) {
+ case 'T':
+ tx = true;
+ break;
+ case 'R':
+ rx = true;
+ break;
+ case 'i':
+ ifname = optarg;
+ break;
+ case 'M':
+ parse_mac(optarg, dmac);
+ break;
+ case 's':
+ parse_addr(optarg, &saddr);
+ break;
+ case 'd':
+ parse_addr(optarg, &daddr);
+ break;
+ case 'f':
+ fixed_id = true;
+ break;
+ case 'n':
+ segs = atoi(optarg);
+ break;
+ case 'b':
+ bursts = atoi(optarg);
+ break;
+ case 'l':
+ len = atoi(optarg);
+ break;
+ case 'V':
+ case 'P':
+ comma = strchr(optarg, ',');
+ if (!comma)
+ error(1, 0, "-%c needs outer saddr,daddr", c);
+ *comma = '\0';
+ parse_addr(optarg, &osaddr);
+ parse_addr(comma + 1, &odaddr);
+ if (c == 'V')
+ vxlan = true;
+ else
+ sixinfour = true;
+ break;
+ case 'm':
+ parse_mac(optarg, inner_dmac);
+ break;
+ case 'F':
+ fixed_outer = true;
+ break;
+ case 'O':
+ incr_outer = true;
+ break;
+ case 'w':
+ wait_ms = atoi(optarg);
+ break;
+ case 'c':
+ stop = atoi(optarg);
+ break;
+ default:
+ error(1, 0, "bad option");
+ }
+ }
+ if (tx == rx || !ifname || len < 1 || len > 1400 || segs < 1 ||
+ bursts < 1 || (vxlan && sixinfour) ||
+ (fixed_outer && incr_outer))
+ error(1, 0, "usage: see the comment at the top of %s",
+ __FILE__);
+
+ fd = socket(AF_PACKET, SOCK_RAW, htons(tx ? 0 : ETH_P_ALL));
+ if (fd < 0)
+ error(1, errno, "socket");
+ sll.sll_family = AF_PACKET;
+ sll.sll_protocol = htons(ETH_P_ALL);
+ sll.sll_ifindex = if_nametoindex(ifname);
+ if (!sll.sll_ifindex)
+ error(1, errno, "%s", ifname);
+ if (rx)
+ rx_setup(fd);
+ if (bind(fd, (struct sockaddr *)&sll, sizeof(sll)))
+ error(1, errno, "bind");
+ sll.sll_halen = ETH_ALEN;
+ memcpy(sll.sll_addr, dmac, ETH_ALEN);
+
+ c = tx ? do_tx(fd, &sll) : do_rx(fd);
+ close(fd);
+ return c;
+}
diff --git a/tools/testing/selftests/net/tcp_fixedid.sh b/tools/testing/selftests/net/tcp_fixedid.sh
new file mode 100755
index 000000000000..3d3045974719
--- /dev/null
+++ b/tools/testing/selftests/net/tcp_fixedid.sh
@@ -0,0 +1,494 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+#
+# Check the IPv4 IDs of a TCP stream that GRO merged and software
+# segmentation split again across a tunnel. A sender in NSRC writes
+# segments with fixed or incrementing IDs onto a veth with GRO on in
+# NRTR, which forwards the merged packets:
+#
+# encap: into an IPIP, GRE or VXLAN tunnel over IPv4 or IPv6,
+# segmented on the underlay towards NMID
+# decap: out of VXLAN, received from NSRC with one header fixed and
+# the other incrementing, into an IPIP tunnel towards NMID
+# encap+decap: into a tunnel that NMID ends without segmenting, and on
+# to NDST, segmented there
+# 6in4: IPv6 TCP in IPv4 with fixed or incrementing outer IDs,
+# forwarded without decapsulation towards NMID
+# esp: into an ESP SA in tunnel or transport mode offloaded to
+# netdevsim, which segments the packet in software and does
+# not encrypt it, also after decapsulation out of VXLAN, with
+# plain and with fraglist GRO
+#
+# The inner IDs must come out as they went in, the outer IDs of 6in4 as
+# well, and the IDs of a new outer IPv4 header must be unique, or for ESP
+# tunnel mode, whose outer IDs start at 0 for each packet with DF set,
+# increment within each packet. ESP transport mode keeps the sender's IPv4
+# header and its ID. A run in which GRO merged nothing is skipped.
+
+source lib.sh
+
+NSRC=""
+NRTR=""
+NMID=""
+NDST=""
+
+SEGS=40
+BURSTS=10
+TOTAL=$((SEGS * BURSTS))
+INNER_SRC=10.1.0.1
+INNER_DST=10.9.0.2
+VX_MAC=02:00:00:00:00:42
+TUN_MAC=02:00:00:00:00:99
+MID_MAC=02:00:00:00:00:98
+TX=tcp_fixedid
+NSIM_ID=$((RANDOM % 1024 + 1024))
+NSIM_BUS=/sys/bus/netdevsim
+NSIM_IDS=()
+
+NOSEG="tso gso tx-gre-segmentation tx-gre-csum-segmentation
+ tx-ipxip4-segmentation tx-ipxip6-segmentation
+ tx-udp_tnl-segmentation tx-udp_tnl-csum-segmentation"
+
+# nsim_add <id> <ns>: create netdevsim device <id> with one port in <ns>,
+# record <id> for nsim_del and put the port's name in NSIM_DEV
+nsim_add() {
+ NSIM_DEV=""
+ echo "$1 1" | ip netns exec "$2" tee "$NSIM_BUS/new_device" \
+ >/dev/null 2>&1 || return 1
+ NSIM_IDS+=("$1")
+ NSIM_DEV=$(ip netns exec "$2" ls "$NSIM_BUS/devices/netdevsim$1/net")
+ [ -n "$NSIM_DEV" ]
+}
+
+# nsim_del: delete the netdevsim devices that nsim_add created
+nsim_del() {
+ local id
+
+ for id in "${NSIM_IDS[@]}"; do
+ echo "$id" > "$NSIM_BUS/del_device"
+ done
+ NSIM_IDS=()
+}
+
+cleanup() {
+ nsim_del
+ cleanup_all_ns
+ rm -f "$RESULT"
+}
+
+trap cleanup EXIT
+
+# NSRC s0 - r0 NRTR r1 - m1 NMID m2 - d2 NDST
+setup() {
+ setup_ns NSRC NRTR NMID NDST || return "$ksft_skip"
+
+ ip link add s0 netns "$NSRC" type veth peer name r0 netns "$NRTR"
+ ip link add r1 netns "$NRTR" type veth peer name m1 netns "$NMID"
+ ip link add m2 netns "$NMID" type veth peer name d2 netns "$NDST"
+
+ ip -n "$NRTR" addr add 10.1.0.2/24 dev r0
+ ip -n "$NRTR" addr add 10.2.0.1/24 dev r1
+ ip -n "$NRTR" addr add fd02::1/64 dev r1 nodad
+ ip -n "$NMID" addr add 10.2.0.2/24 dev m1
+ ip -n "$NMID" addr add fd02::2/64 dev m1 nodad
+ ip -n "$NMID" addr add 10.4.0.1/24 dev m2
+ ip -n "$NDST" addr add 10.4.0.2/24 dev d2
+ ip -n "$NSRC" link set s0 up
+ ip -n "$NRTR" link set r0 up
+ ip -n "$NRTR" link set r1 up
+ ip -n "$NMID" link set m1 up
+ ip -n "$NMID" link set m2 up
+ ip -n "$NDST" link set d2 up
+
+ ip netns exec "$NRTR" sysctl -qw net.ipv4.ip_forward=1
+ ip netns exec "$NMID" sysctl -qw net.ipv4.ip_forward=1
+ for ns in "$NRTR" "$NMID"; do
+ ip netns exec "$ns" sysctl -qw net.ipv4.conf.all.rp_filter=0 \
+ net.ipv4.conf.default.rp_filter=0
+ done
+
+ # veth passes packets to GRO only if the sender does not do TSO
+ ip netns exec "$NRTR" ethtool -K r0 gro on >/dev/null ||
+ return "$ksft_skip"
+ ip netns exec "$NSRC" ethtool -K s0 tso off >/dev/null ||
+ return "$ksft_skip"
+ # release the sender's segments in bursts for GRO to merge
+ tc -n "$NSRC" qdisc add dev s0 root netem slot 20ms 20ms \
+ packets "$SEGS" || return "$ksft_skip"
+}
+
+# tunnel <ns> <name> <type> <family> <local> <remote>
+tunnel() {
+ local ns=$1 name=$2 type=$3 family=$4 local=$5 remote=$6
+
+ case "$type" in
+ ipip)
+ if [ "$family" = 4 ]; then
+ ip -n "$ns" link add "$name" type ipip \
+ local "$local" remote "$remote"
+ else
+ ip -n "$ns" link add "$name" type ip6tnl mode ipip6 \
+ local "$local" remote "$remote" encaplimit none
+ fi ;;
+ gre)
+ if [ "$family" = 4 ]; then
+ ip -n "$ns" link add "$name" type gre \
+ local "$local" remote "$remote"
+ else
+ ip -n "$ns" link add "$name" type ip6gre \
+ local "$local" remote "$remote" encaplimit none
+ fi ;;
+ vxlan)
+ ip -n "$ns" link add "$name" address "$TUN_MAC" type vxlan \
+ id 7 dstport 4789 local "$local" remote "$remote" \
+ nolearning ;;
+ esac || return 1
+ # no IPv6 link-local traffic in the tx_packets of the tunnel
+ ip netns exec "$ns" sysctl -qw "net.ipv6.conf.$name.disable_ipv6=1"
+ ip -n "$ns" link set "$name" up
+}
+
+# route_into <ns> <dev>: send INNER_DST into <dev>
+route_into() {
+ ip -n "$1" route add "$INNER_DST/32" dev "$2"
+ ip -n "$1" neigh add "$INNER_DST" lladdr "$TUN_MAC" dev "$2" \
+ 2>/dev/null
+ return 0
+}
+
+# noseg <ns> <dev>: segment everything in software before <dev>
+noseg() {
+ local f
+
+ for f in $NOSEG; do
+ ip netns exec "$1" ethtool -K "$2" "$f" off >/dev/null 2>&1
+ done
+}
+
+tx_packets() {
+ ip netns exec "$1" cat "/sys/class/net/$2/statistics/tx_packets"
+}
+
+# fwd_packets <ns>: packets forwarded, a GSO packet counting once
+fwd_packets() {
+ ip netns exec "$1" cat /proc/net/snmp | awk '/^Ip: [0-9]/ { print $7 }'
+}
+
+# check <name> <result> <want: fixed|incr|none> <outer: 0|unique|incr|fixed>
+# <sent>: <sent> is the number of packets forwarded, a GSO packet counting
+# once; want none for segments without an inner IPv4 header
+check() {
+ local name=$1 res=$2 want=$3 outer=$4 sent=$5
+ local frames outer_ids inner_ids inner_bad outer_incr drops outer_bad
+ local incr
+
+ read -r _ frames _ _ _ outer_ids _ inner_ids _ inner_bad _ outer_incr \
+ _ drops _ outer_bad <<< "$res"
+ RET=0
+ if [ -z "$outer_bad" ]; then
+ check_err 1 "no result from the receiver${res:+: $res}"
+ log_test "$name"
+ return
+ fi
+ check_err "$drops" "receiver dropped $drops frames"
+ check_err $((frames != TOTAL)) "$frames of $TOTAL segments received"
+ check_err "$inner_bad" "$inner_bad inner IDs not sent"
+ check_err "$outer_bad" "$outer_bad outer IDs not sent"
+ if [ "$want" = fixed ]; then
+ check_err $((inner_ids != 1)) "$inner_ids inner IDs, want 1"
+ elif [ "$want" = incr ]; then
+ check_err $((inner_ids != TOTAL)) \
+ "$inner_ids inner IDs, want $TOTAL"
+ fi
+ # the outer IDs of packets that GRO did not merge show nothing
+ if [ "$RET" -eq 0 ] && [ "$sent" -ge "$TOTAL" ]; then
+ ret_set_ksft_status "$ksft_skip" "GRO did not merge"
+ log_test "$name"
+ return
+ fi
+ if [ "$outer" = unique ]; then
+ check_err $((outer_ids != frames)) \
+ "$outer_ids outer IDs for $frames segments"
+ elif [ "$outer" = fixed ]; then
+ check_err $((outer_ids != 1)) "$outer_ids outer IDs, want 1"
+ elif [ "$outer" = incr ]; then
+ # all but the first segment of each packet
+ incr=$((frames - sent))
+ check_err $((outer_incr < incr)) \
+ "$outer_incr outer IDs increment, want $incr"
+ fi
+ log_test "$name"
+}
+
+# capture <ns> <dev> <want: fixed|incr> [<outer: fixed|incr>]: start the
+# receiver in the background, pid in CAP_PID, and wait until it is bound;
+# with <outer> it checks the outer IDs against those the sender wrote
+capture() {
+ local f="" o=""
+
+ [ "$3" = fixed ] && f=-f
+ [ "$4" = fixed ] && o=-F
+ [ "$4" = incr ] && o=-O
+ : > "$RESULT"
+ ip netns exec "$1" "$TX" -R -i "$2" -c "$TOTAL" -w 3000 $f $o \
+ > "$RESULT" &
+ CAP_PID=$!
+ if ! slowwait 10 grep -q ready "$RESULT"; then
+ kill "$CAP_PID" 2>/dev/null
+ echo "not bound within 10 s" > "$RESULT"
+ fi
+}
+
+run_encap() {
+ local type=$1 family=$2 want=$3
+ local r0mac t0 laddr=10.2.0.1 raddr=10.2.0.2
+ local f=""
+
+ setup || { log_test_skip "encap $type IPv$family"; return; }
+ if [ "$family" = 6 ]; then
+ laddr=fd02::1
+ raddr=fd02::2
+ fi
+ if ! tunnel "$NRTR" tun0 "$type" "$family" "$laddr" "$raddr"; then
+ log_test_skip "encap $type IPv$family"
+ cleanup_all_ns
+ return
+ fi
+ route_into "$NRTR" tun0
+ noseg "$NRTR" r1
+
+ r0mac=$(ip -n "$NRTR" -br link show r0 | awk '{ print $3 }')
+ capture "$NMID" m1 "$want"
+ t0=$(tx_packets "$NRTR" tun0)
+ [ "$want" = fixed ] && f=-f
+ ip netns exec "$NSRC" "$TX" -T -i s0 -M "$r0mac" -s "$INNER_SRC" \
+ -d "$INNER_DST" -n "$SEGS" -b "$BURSTS" $f
+ wait "$CAP_PID"
+ check "encap $type IPv$family, $want inner IDs" \
+ "$(tail -n 1 "$RESULT")" "$want" \
+ "$([ "$family" = 4 ] && echo unique || echo 0)" \
+ $(($(tx_packets "$NRTR" tun0) - t0))
+ cleanup_all_ns
+}
+
+# run_decap <fixed: inner|outer>: VXLAN from NSRC, decapsulated in NRTR
+run_decap() {
+ local fixed=$1 want=incr flags=-F
+ local r0mac t0
+
+ setup || { log_test_skip "decap"; return; }
+ ip -n "$NRTR" link add vx0 address "$VX_MAC" type vxlan id 42 \
+ dstport 4789 local 10.1.0.2 nolearning ||
+ { log_test_skip "decap"; cleanup_all_ns; return; }
+ ip -n "$NRTR" addr add 10.3.0.2/24 dev vx0
+ ip -n "$NRTR" link set vx0 up
+ if ! tunnel "$NRTR" tun0 ipip 4 10.2.0.1 10.2.0.2; then
+ log_test_skip "decap"
+ cleanup_all_ns
+ return
+ fi
+ route_into "$NRTR" tun0
+ noseg "$NRTR" r1
+
+ if [ "$fixed" = inner ]; then
+ want=fixed
+ flags=-f
+ fi
+ r0mac=$(ip -n "$NRTR" -br link show r0 | awk '{ print $3 }')
+ capture "$NMID" m1 "$want"
+ t0=$(tx_packets "$NRTR" tun0)
+ ip netns exec "$NSRC" "$TX" -T -i s0 -M "$r0mac" -s 10.3.0.1 \
+ -d "$INNER_DST" -n "$SEGS" -b "$BURSTS" \
+ -V 10.1.0.1,10.1.0.2 -m "$VX_MAC" $flags
+ wait "$CAP_PID"
+ check "decap VXLAN with fixed $fixed IDs, into IPIP" \
+ "$(tail -n 1 "$RESULT")" "$want" unique \
+ $(($(tx_packets "$NRTR" tun0) - t0))
+ cleanup_all_ns
+}
+
+# run_encap_decap <type>: NRTR encapsulates, NMID decapsulates the GSO
+# packet without segmenting it and forwards it to NDST
+run_encap_decap() {
+ local type=$1
+ local r0mac t0
+
+ setup || { log_test_skip "encap+decap $type"; return; }
+ if ! tunnel "$NRTR" tun0 "$type" 4 10.2.0.1 10.2.0.2 ||
+ ! tunnel "$NMID" tun0 "$type" 4 10.2.0.2 10.2.0.1; then
+ log_test_skip "encap+decap $type"
+ cleanup_all_ns
+ return
+ fi
+ route_into "$NRTR" tun0
+ # VXLAN drops frames from its own address as loops
+ if [ "$type" = vxlan ]; then
+ ip -n "$NMID" link set tun0 address "$MID_MAC"
+ ip -n "$NRTR" neigh replace "$INNER_DST" lladdr "$MID_MAC" \
+ dev tun0
+ fi
+ ip -n "$NMID" route add "$INNER_DST/32" via 10.4.0.2
+ ip -n "$NDST" addr add "$INNER_DST/32" dev d2
+ noseg "$NMID" m2
+
+ r0mac=$(ip -n "$NRTR" -br link show r0 | awk '{ print $3 }')
+ capture "$NDST" d2 fixed
+ t0=$(tx_packets "$NRTR" tun0)
+ ip netns exec "$NSRC" "$TX" -T -i s0 -M "$r0mac" -s "$INNER_SRC" \
+ -d "$INNER_DST" -n "$SEGS" -b "$BURSTS" -f
+ wait "$CAP_PID"
+ check "encap+decap $type, fixed inner IDs" "$(tail -n 1 "$RESULT")" \
+ fixed 0 $(($(tx_packets "$NRTR" tun0) - t0))
+ cleanup_all_ns
+}
+
+# run_6in4 <outer: fixed|incr>: NRTR forwards IPv6 TCP in IPv4 from NSRC
+# to NMID without decapsulating it
+run_6in4() {
+ local outer=$1 want=unique flags=""
+ local r0mac t0
+
+ setup || { log_test_skip "6in4"; return; }
+ noseg "$NRTR" r1
+ if [ "$outer" = fixed ]; then
+ want=fixed
+ flags=-F
+ fi
+
+ r0mac=$(ip -n "$NRTR" -br link show r0 | awk '{ print $3 }')
+ capture "$NMID" m1 none "$outer"
+ t0=$(fwd_packets "$NRTR")
+ ip netns exec "$NSRC" "$TX" -T -i s0 -M "$r0mac" -P 10.1.0.1,10.2.0.2 \
+ -n "$SEGS" -b "$BURSTS" $flags
+ wait "$CAP_PID"
+ check "6in4, $outer outer IDs" "$(tail -n 1 "$RESULT")" none "$want" \
+ $(($(fwd_packets "$NRTR") - t0))
+ cleanup_all_ns
+}
+
+# run_esp <mode> [vxlan [list]]: NRTR forwards into an ESP SA in tunnel or
+# transport mode, offloaded to a netdevsim port with TSO off and linked to
+# a netdevsim port in NMID; with vxlan the stream comes out of a VXLAN
+# tunnel that NRTR ends, with list after fraglist GRO
+run_esp() {
+ local mode=$1 via=$2 list=$3 want=fixed f=-f
+ local key=0x3132333435363738393031323334353664636261
+ local src=10.5.0.1 dst=10.5.0.2 outer=incr isrc=$INNER_SRC
+ local r0mac rdev mdev rif mif rfd mfd t0 name
+ local vxargs=()
+
+ [ "$via" = vxlan ] && isrc=10.3.0.1
+ if [ "$mode" = transport ]; then
+ src=$isrc
+ dst=$INNER_DST
+ outer=0
+ fi
+
+ name="esp $mode offload${via:+ after $via decap}${list:+, fraglist GRO}"
+ setup || { log_test_skip "$name"; return; }
+ if [ "$via" = vxlan ]; then
+ vxargs=(-V "10.1.0.1,10.1.0.2" -m "$VX_MAC")
+ ip -n "$NRTR" link add vx0 address "$VX_MAC" type vxlan id 42 \
+ dstport 4789 local 10.1.0.2 nolearning ||
+ { log_test_skip "$name"; cleanup_all_ns; return; }
+ ip -n "$NRTR" addr add 10.3.0.2/24 dev vx0
+ ip -n "$NRTR" link set vx0 up
+ fi
+ # fraglist GRO records no fixed IDs: send incrementing ones
+ if [ -n "$list" ]; then
+ want=incr
+ f=""
+ if ! ip netns exec "$NRTR" ethtool -K r0 rx-gro-list on \
+ >/dev/null; then
+ log_test_skip "$name: no fraglist GRO"
+ cleanup_all_ns
+ return
+ fi
+ fi
+ if ! modprobe -q netdevsim 2>/dev/null &&
+ [ ! -w "$NSIM_BUS/new_device" ]; then
+ log_test_skip "$name: no netdevsim"
+ cleanup_all_ns
+ return
+ fi
+ if ! nsim_add "$NSIM_ID" "$NRTR"; then
+ log_test_skip "$name: netdevsim"
+ nsim_del
+ cleanup_all_ns
+ return
+ fi
+ rdev=$NSIM_DEV
+ if ! nsim_add $((NSIM_ID + 1)) "$NMID"; then
+ log_test_skip "$name: netdevsim"
+ nsim_del
+ cleanup_all_ns
+ return
+ fi
+ mdev=$NSIM_DEV
+ rif=$(ip netns exec "$NRTR" cat "/sys/class/net/$rdev/ifindex")
+ mif=$(ip netns exec "$NMID" cat "/sys/class/net/$mdev/ifindex")
+ exec {rfd}<"/run/netns/$NRTR" {mfd}<"/run/netns/$NMID"
+ echo "$rfd:$rif $mfd:$mif" > "$NSIM_BUS/link_device"
+ exec {rfd}<&- {mfd}<&-
+
+ ip -n "$NRTR" addr add 10.5.0.1/24 dev "$rdev"
+ ip -n "$NMID" addr add 10.5.0.2/24 dev "$mdev"
+ ip -n "$NRTR" link set "$rdev" up
+ ip -n "$NMID" link set "$mdev" up
+ ip -n "$NRTR" neigh add 10.5.0.2 dev "$rdev" lladdr \
+ "$(ip -n "$NMID" -br link show "$mdev" | awk '{ print $3 }')"
+ ip -n "$NRTR" route add "$INNER_DST/32" via 10.5.0.2 dev "$rdev"
+ ip netns exec "$NRTR" ethtool -K "$rdev" tso off >/dev/null
+ if ! ip -n "$NRTR" xfrm state add src "$src" dst "$dst" \
+ proto esp spi 0x100 reqid 1 mode "$mode" \
+ aead 'rfc4106(gcm(aes))' "$key" 128 \
+ offload dev "$rdev" dir out ||
+ ! ip -n "$NRTR" xfrm policy add dir out \
+ src "$isrc/32" dst "$INNER_DST/32" \
+ tmpl src "$src" dst "$dst" proto esp reqid 1 mode "$mode"; then
+ log_test_skip "$name: no ESP offload"
+ nsim_del
+ cleanup_all_ns
+ return
+ fi
+
+ r0mac=$(ip -n "$NRTR" -br link show r0 | awk '{ print $3 }')
+ capture "$NMID" "$mdev" "$want"
+ t0=$(fwd_packets "$NRTR")
+ ip netns exec "$NSRC" "$TX" -T -i s0 -M "$r0mac" -s "$isrc" \
+ -d "$INNER_DST" -n "$SEGS" -b "$BURSTS" "${vxargs[@]}" $f
+ wait "$CAP_PID"
+ check "$name, $want inner IDs" "$(tail -n 1 "$RESULT")" \
+ "$want" "$outer" $(($(fwd_packets "$NRTR") - t0))
+ nsim_del
+ cleanup_all_ns
+}
+
+require_command ethtool
+require_command tc
+check_gen_prog "$TX"
+
+RESULT=$(mktemp)
+
+for type in ipip gre vxlan; do
+ for family in 4 6; do
+ run_encap "$type" "$family" fixed
+ run_encap "$type" "$family" incr
+ done
+done
+run_decap inner
+run_decap outer
+for type in ipip gre vxlan; do
+ run_encap_decap "$type"
+done
+run_6in4 fixed
+run_6in4 incr
+for mode in tunnel transport; do
+ run_esp "$mode"
+done
+for mode in tunnel transport; do
+ run_esp "$mode" vxlan
+ run_esp "$mode" vxlan list
+done
+
+exit "$EXIT_STATUS"
--
2.53.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-12-04 22:45 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 22:45 [PATCH net-next v5 0/2] net: keep the TCP fixed-ID flags on the header they describe Julius Bairaktaris
2026-12-04 22:45 ` [PATCH net-next v5 1/2] " Julius Bairaktaris
2026-12-04 22:45 ` [PATCH net-next v5 2/2] selftests: net: check TCP IP IDs across tunnels after GRO and GSO Julius Bairaktaris
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox