net: keep the TCP fixed-ID flags on the header they describe
Subsystems (13)
v3 cover net: keep the TCP fixed-ID flags on the header they describe
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. A header added in front of a packet that is already encapsulated clears the outer flag, and ESP transport and BEET mode with crypto offload, which keep the IPv4 header, copy the inner flag to the outer 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.
The hosted Sashiko AI review of v2 2/3 of my "ipmr: forward GSO multicast packets" series reported the issue [1], and the selftest in patch 2 reproduces it.
Tested in QEMU (KVM) with the selftest, 19 cases, 400 segments each:
- net (d5b89d55a322), 1 run: 6 cases fail. Fixed inner IDs increment after IPIP over IPv4 and IPv6 and after the ESP tunnel (390 of 400 segments carry an inner ID the sender did not use), the outer IDs repeat after GRE and VXLAN over IPv4 (10 distinct outer IDs for 400 segments), and a VXLAN stream with fixed outer IDs keeps that state after decapsulation into IPIP (10 distinct outer IDs).
- v2 of this series, 1 run: the ESP transport mode case fails (390 of 400 segments carry an ID the sender did not use).
- this series, 3 of 3 runs: 19 of 19 pass.
Changes in v3:
- Patch 1: 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; the new outermost header kept the flag of the header below it (Sashiko).
- Patch 1: copy the inner flag to the outer one in xfrm_output() for ESP transport and BEET mode with crypto offload, which set skb->encapsulation without adding an IPv4 header; v2 gave that header incrementing IDs (Sashiko).
- Patch 1: name the paths that change the outer flag and the middle header that the flags cannot describe in skbuff.h, segmentation-offloads.rst and the commit message, and list SKB_GSO_TCP_FIXEDID_OUTER in the bpf_skb_adjust_room() decap flags of the uAPI header (Sashiko).
- Patch 1: wrap lines at 80 columns (NIPA).
- Patch 2: add an ESP transport mode case.
- Patch 2: skip a run in which GRO merged nothing before the outer IDs are checked, and check that ESP tunnel mode outer IDs increment within each packet (Sashiko).
- Patch 2: delete only the netdevsim devices the test created, also from the EXIT trap, and before the namespaces (Sashiko).
- Patch 2: make the receiver's -c optional, as documented (Sashiko).
- Patch 2: use slowwait and check_gen_prog from lib.sh, and create the netdevsim devices inside their namespace, as lib.sh does, with the new_device write checked (Sashiko).
- Patch 2: report a receiver that is not bound within 10 s as such.
- Patch 2: fix shellcheck SC2016 and wrap lines at 80 columns (NIPA).
- Rebased onto net d5b89d55a322.
- v2: https://lore.kernel.org/netdev/[email protected]/
- v1: https://lore.kernel.org/netdev/[email protected]/
[1] https://lore.kernel.org/netdev/[email protected]/
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/xfrm/xfrm_output.c | 10 + 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 | 432 ++++++++++++++++++ tools/testing/selftests/net/tcp_fixedid.sh | 427 +++++++++++++++++ 18 files changed, 929 insertions(+), 39 deletions(-) create mode 100644 tools/testing/selftests/net/tcp_fixedid.c create mode 100755 tools/testing/selftests/net/tcp_fixedid.sh
base-commit: d5b89d55a322b632e2b465b392a4c1d9d338db9c
Signature · 1 line
2.53.0
PATCH v3 1/2 net: keep the TCP fixed-ID flags on the header they describe
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.
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.
---
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/
.../networking/segmentation-offloads.rst | 8 +++++--- drivers/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/xfrm/xfrm_output.c | 10 ++++++++++ tools/include/uapi/linux/bpf.h | 16 +++++++++------- 14 files changed, 67 insertions(+), 39 deletions(-)
Documentation/networking/segmentation-offloads.rst +5 -3
@@ -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
drivers/net/ethernet/mellanox/mlx5/core/en_rx.c +2 -6
@@ -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);
drivers/net/ethernet/sfc/ef100_tx.c +3 -9
@@ -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);
include/linux/netdevice.h +1 -1
@@ -5536,7 +5536,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 ;
include/linux/skbuff.h +11 -1
@@ -717,9 +717,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
include/net/ip_tunnels.h +1 -0
@@ -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 ;
include/uapi/linux/bpf.h +9 -7
@@ -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
net/core/filter.c +1 -0
@@ -3867,6 +3867,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 |
net/core/lwt_bpf.c +2 -0
@@ -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 ;
net/ipv4/af_inet.c +6 -3
@@ -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)) {
net/ipv4/ip_tunnel_core.c +2 -0
@@ -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 ; }
net/ipv4/tcp_offload.c +5 -2
@@ -459,6 +459,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)) {
@@ -473,9 +475,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 ;
net/xfrm/xfrm_output.c +10 -0
@@ -805,6 +805,16 @@ 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 (!skb->encapsulation && + (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)) {
tools/include/uapi/linux/bpf.h +9 -7
@@ -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
Signature · 1 line
2.53.0
PATCH v3 2/2 selftests: net: check TCP IP IDs across tunnels after GRO and GSO
In reply to Julius BairaktarisSend 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 send the merged packets through a tunnel that the far end decapsulates without segmenting them before it forwards them.
A test where GRO merged nothing is skipped.
---
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/
tools/testing/selftests/net/.gitignore | 1 + tools/testing/selftests/net/Makefile | 2 + tools/testing/selftests/net/tcp_fixedid.c | 432 +++++++++++++++++++++ tools/testing/selftests/net/tcp_fixedid.sh | 427 ++++++++++++++++++++ 4 files changed, 862 insertions(+) create mode 100644 tools/testing/selftests/net/tcp_fixedid.c create mode 100755 tools/testing/selftests/net/tcp_fixedid.sh
tools/testing/selftests/net/.gitignore +1 -0
@@ -48,6 +48,7 @@ so_rcv_listener stress_reuseport_listen tap tcp_fastopen_backup_key +tcp_fixedid tcp_inq tcp_mmap tcp_port_share
tools/testing/selftests/net/Makefile +2 -0
@@ -109,6 +109,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 \
@@ -173,6 +174,7 @@ TEST_GEN_FILES := \ socket \ stress_reuseport_listen \ tcp_fastopen_backup_key \ + tcp_fixedid \ tcp_inq \ tcp_mmap \ tfo \
tools/testing/selftests/net/tcp_fixedid.c new file +432 -0
432 lines not on this page · raw message
tools/testing/selftests/net/tcp_fixedid.sh new file +427 -0
427 lines not on this page · raw message
Signature · 1 line
2.53.0
[email protected]
AI reviewThis is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
Hi!
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
- What hardware the change was tested on. For driver fixes please mention the device (and if relevant firmware version) used for testing, or say that the change was not tested on real hardware.
Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account.
*IMPORTANT*: If you do repost (for other reasons) - please include the relevant info in the cover letter or commit messages.
Signature · 2 lines
The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.
[email protected]
AI reviewSashiko has reviewed this 2-patch series and found no issues.
Sashiko has reviewed this 2-patch series and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 (1) · Low: 0
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] In xfrm_output(), the new FIXEDID->OUTER copy only runs for TRANSPORT/BEET mode, but skb->encapsulation = 1 is set for every…
Pre-existing issues:
- [Medium] tcp6_gro_complete() (net/ipv6/tcpv6_offload.c:81-102) ignores NAPI_GRO_CB(skb)->ip_fixedid.
--
net: keep the TCP fixed-ID flags on the header they describe
This patch goes back to SKB_GSO_TCP_FIXEDID describing the innermost IPv4 header. It replaces SKB_GSO_TCP_FIXEDID_INNER with SKB_GSO_TCP_FIXEDID_OUTER for the outermost header of an encapsulated packet. The outer flag is cleared where tunnel and BPF paths add or remove a header, xfrm_output() sets it for ESP transport and BEET offload, and the mlx5 and sfc drivers are converted.
Quoted 4 lines
net/ipv4/tcp_offload.c +0
-0
[ ... ]
net/ipv4/tcp_offload.c INDIRECT_CALLABLE_SCOPE int tcp4_gro_complete(struct sk_buff *skb, int thoff) · line 481
Quoted 10 lines
net/ipv4/tcp_offload.c +3
-2@@ -473,9 +475,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 );
[Severity: Medium]
This is a pre-existing issue and this patch did not introduce it. Does the IPv6 counterpart need the same mapping?
Take an IPv4 outer header over an IPv6 inner TCP flow, such as 6in4/SIT or VXLAN over IPv4 carrying IPv6. For the outer IPv4 header, gro_receive_network_flush() calls inet_gro_flush() with inner=false, which records:
include/net/gro.h:inet_gro_flush() {
...
NAPI_GRO_CB(p)->ip_fixedid |= 1 << inner;
...
}The flow is then merged as fixed-ID. tcp4_gro_complete() now maps that bit to SKB_GSO_TCP_FIXEDID_OUTER, but tcp6_gro_complete() never looks at ip_fixedid:
net/ipv6/tcpv6_offload.c:tcp6_gro_complete() {
...
th->check = ~tcp_v6_check(skb->len - thoff, &iph->saddr,
&iph->daddr, 0);
skb_shinfo(skb)->gso_type |= SKB_GSO_TCPV6;
...
}So the outermost IPv4 header of such a packet never gets SKB_GSO_TCP_FIXEDID_OUTER. When the packet is forwarded and resegmented, inet_gso_segment() rewrites the fixed outer IDs as incrementing ones.
Should tcp6_gro_complete() set SKB_GSO_TCP_FIXEDID_OUTER from bit 0 when skb->encapsulation is set?
Quoted 14 lines
net/ipv4/tcp_offload.c +0
-0tcp_gro_complete (skb);return 0 ;net/xfrm/xfrm_output.c +3
-0@@ -805,6 +805,16 @@ 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
net/xfrm/xfrm_output.c int xfrm_output(struct sock *sk, struct sk_buff *skb) · line 820
Quoted 10 lines
net/xfrm/xfrm_output.c +7
-0+* one as well. +*/ +if (!skb->encapsulation && + (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)) {
[Severity: Medium]
Can a tunnel mode SA still lose the fixed IDs of the packet's only IPv4 header?
skb->encapsulation = 1 is set for every crypto offloaded SA, but the copy to SKB_GSO_TCP_FIXEDID_OUTER is skipped for tunnel mode.
A GSO packet that was decapsulated earlier keeps a stale non-zero skb->inner_protocol. inet_gro_complete() sets it for encapsulated GRO, and neither iptunnel_pull_offloads() nor skb_scrub_packet() resets it. After decap, such a packet has encapsulation=0 and SKB_GSO_TCP_FIXEDID set, and SKB_GSO_TCP_FIXEDID_OUTER has been cleared.
If the packet is forwarded into a tunnel mode SA with offload, this check just below fires:
if (skb->inner_protocol && x->props.mode == XFRM_MODE_TUNNEL) return xfrm_output_gso(net, sk, skb);
Then xfrm_output_gso()->skb_gso_segment(skb, 0)->inet_gso_segment() runs at encap_level 0, sees skb->encapsulation == 1, and takes the new else branch:
} else {
fixedid = !!(skb_shinfo(skb)->gso_type &
SKB_GSO_TCP_FIXEDID_OUTER);
}That reads 0 for the only IPv4 header, even though SKB_GSO_TCP_FIXEDID is the flag that describes it. The segments get incrementing IDs although GRO recorded fixed ones.
The baseline code was also wrong here, because it read the stale flag of the removed header. Is this a remaining variant of the "forwarded into an ESP tunnel mode SA with crypto offload" case that the commit message says is fixed?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1795284858.git.julius%40bairaktaris.de