seg6: fix skb checksum updates with CHECKSUM_COMPLETE
Subsystems (6)
Andrea Mayer
maintainerv2 cover seg6: fix skb checksum updates with CHECKSUM_COMPLETE
This series fixes the skb->csum updates with CHECKSUM_COMPLETE when the SRv6 code processes a received packet. In several places skb->csum is not updated correctly:
- ipv6_srh_rcv() updates skb->csum with the wrong sign for the new Segments Left and destination address, and not at all for the Hop Limit decrement.
- advance_nextseg() and seg6_next_csid_advance_arg() in seg6_local do not update skb->csum.
- The End.BPF program and seg6_bpf_has_valid_srh() can change the packet without updating skb->csum.
- In L2ENCAP and L2ENCAP_RED mode, the MAC header put back in front of the frame is not added to skb->csum.
When the packet is then delivered on the same node, the effect depends on who computed skb->csum. With skb->csum computed in software, for example by conntrack, UDP can drop the packet as a checksum error. With skb->csum computed by the device, TCP can log a "hw csum failure", as if the device had computed a wrong skb->csum. In the L2ENCAP case skb->csum can be read on local delivery, for example by a raw socket with IPV6_CHECKSUM.
The series is organized as follows:
- Patch 1/6 fixes the update_csum_diff4() and update_csum_diff16() helpers.
- Patch 2/6 updates skb->csum for the Hop Limit decrement in ipv6_srh_rcv().
It depends on patch 1/6.
- Patch 3/6 updates skb->csum when SRv6 behaviors advance to the next SID. It depends on patch 1/6.
- Patch 4/6 discards CHECKSUM_COMPLETE after the End.BPF program.
- Patch 5/6 accounts for the MAC header in skb->csum on L2 encapsulation.
- Patch 6/6 adds a selftest that uses a tc ct action to compute skb->csum. It covers the paths of patches 1/6 to 4/6, and a control datagram checks that the test detects a wrong skb->csum.
Tested with the srv6_*.sh selftests, including the new one, and with the lwt_seg6local BPF selftest. The series was also tested with a ConnectX-6 Lx NIC (mlx5) that provides CHECKSUM_COMPLETE. Without the series, TCP over the SRv6 paths of patches 1/6 to 4/6 can log "hw csum failure". The same happens for a raw socket with IPV6_CHECKSUM, on a packet delivered locally after L2ENCAP. With this series, none of this happens.
v2:
1/6, 2/6 and 3/6:
- no change, with the Reviewed-by of Hangbin Liu (Thanks Hangbin).
4/6:
- discard CHECKSUM_COMPLETE after the seg6_bpf_has_valid_srh() check
(suggested by Hangbin Liu);
- update the comment, since seg6_bpf_has_valid_srh() now runs before
it;
- add the srv6 selftests to the testing statement of the commit
message.
5/6:
- no change.
6/6:
- call log_test_expected() directly, instead of a local log_test()
wrapper (suggested by Hangbin Liu); - use require_command() of lib.sh instead of a local helper (suggested by Hangbin Liu).
v1: https://lore.kernel.org/netdev/[email protected]/
Thanks,
Andrea
Andrea Mayer (6):
seg6: fix skb checksum update helpers
seg6: update skb checksum when ipv6_srh_rcv() decrements the Hop Limit
seg6: update skb checksum when SRv6 behaviors advance to the next SID
seg6: discard CHECKSUM_COMPLETE after the End.BPF program
seg6: account for the MAC header in skb checksum on L2 encapsulation
selftests: seg6: add test for skb checksum with CHECKSUM_COMPLETE
include/net/seg6.h | 4 +- net/ipv6/exthdrs.c | 8 + net/ipv6/seg6_iptunnel.c | 2 +- net/ipv6/seg6_local.c | 24 +- tools/testing/selftests/net/Makefile | 1 + .../selftests/net/srv6_csum_complete.bpf.c | 65 ++ .../selftests/net/srv6_csum_complete_test.sh | 627 ++++++++++++++++++ 7 files changed, 727 insertions(+), 4 deletions(-) create mode 100644 tools/testing/selftests/net/srv6_csum_complete.bpf.c create mode 100755 tools/testing/selftests/net/srv6_csum_complete_test.sh
Signature · 1 line
2.43.0
Andrea Mayer
maintainerPATCH v2 1/6 seg6: fix skb checksum update helpers
With CHECKSUM_COMPLETE, ipv6_srh_rcv() updates skb->csum for the new Segments Left and destination address through seg6_update_csum(). Replacing "from" with "to" in the packet must change skb->csum (C) to C - from + to, but update_csum_diff4() and update_csum_diff16() compute:
~csum_partial({ ~from, to }, ~C) = ~(~C + ~from + to) = C + from - to
This does not affect packets forwarded by ip6_forward(), which sets ip_summed to CHECKSUM_NONE. But when the packet is delivered on the same node and skb->csum was computed in software, for instance by conntrack, UDP can drop the packet as a checksum error. With skb->csum computed by the device, TCP can instead log a "hw csum failure", as if the device had computed a wrong skb->csum.
Fix update_csum_diff4() and update_csum_diff16() to compute C - from + to.
Found by manual code inspection, while checking that the skb->csum updates in the SRv6 receive path are consistent. A following commit adds a selftest that reproduces the problem with a tc ct action. The issue was confirmed in a VM without kernel changes or error injection: with the rest of this series and without this patch, that selftest fails, as UDP drops datagrams as checksum errors. Also tested against the srv6 selftests, and with a ConnectX-6 Lx NIC (mlx5) that provides CHECKSUM_COMPLETE.
--- include/net/seg6.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
include/net/seg6.h +2 -2
@@ -19,7 +19,7 @@ static inline void update_csum_diff4(struct sk_buff *skb, __be32 from, {__be32 diff[] = { ~from, to }; - skb->csum = ~csum_partial ((char *)diff,sizeof (diff), ~skb->csum); + skb->csum =csum_partial (diff,sizeof (diff), skb->csum); } static inline void update_csum_diff16(struct sk_buff *skb, __be32 *from,
@@ -30,7 +30,7 @@ static inline void update_csum_diff16(struct sk_buff *skb, __be32 *from, to[0 ], to[1 ], to[2 ], to[3 ], }; - skb->csum = ~csum_partial ((char *)diff,sizeof (diff), ~skb->csum); + skb->csum =csum_partial (diff,sizeof (diff), skb->csum); } struct seg6_pernet_data {
Signature · 1 line
2.43.0
Andrea Mayer
maintainerPATCH v2 2/6 seg6: update skb checksum when ipv6_srh_rcv() decrements the Hop Limit
In reply to Andrea MayerWhen the next segment is a local address, ipv6_srh_rcv() processes it directly and also decrements the Hop Limit. With CHECKSUM_COMPLETE, skb->csum is not updated for this change. If the packet is then delivered on the same node and skb->csum was computed in software, for instance by conntrack, UDP can drop the packet as a checksum error. With skb->csum computed by the device, TCP can instead log a "hw csum failure", as if the device had computed a wrong skb->csum.
Update skb->csum for the Hop Limit decrement with update_csum_diff4().
Depends on patch "seg6: fix skb checksum update helpers".
Found by manual code inspection, and reproduced in a VM without kernel changes or error injection. A following commit adds a selftest that reproduces the problem with a tc ct action. With this patch, the selftest passes for the path with local SRH segments. Also tested against the srv6 selftests, and with a ConnectX-6 Lx NIC (mlx5) that provides CHECKSUM_COMPLETE.
--- net/ipv6/exthdrs.c | 8 ++++++++ 1 file changed, 8 insertions(+)
net/ipv6/exthdrs.c +8 -0
@@ -460,6 +460,10 @@ static int ipv6_srh_rcv(struct sk_buff *skb, struct inet6_dev *idev) }if (skb_dst_dev (skb)->flags &IFF_LOOPBACK ) { +/* payload_len, nexthdr and hop_limit */ +__be32 *hlim_word = (__be32 *)ipv6_hdr (skb) +1 ; +__be32 old; +if (ipv6_hdr (skb)->hop_limit <=1 ) {__IP6_INC_STATS (net, idev,IPSTATS_MIB_INHDRERRORS ); icmpv6_send(skb, ICMPV6_TIME_EXCEED,
@@ -467,8 +471,12 @@ static int ipv6_srh_rcv(struct sk_buff *skb, struct inet6_dev *idev)kfree_skb_reason (skb,SKB_DROP_REASON_IP_TTL_EXCEEDED );return -1 ; } + old = *hlim_word;ipv6_hdr (skb)->hop_limit--; +if (skb->ip_summed ==CHECKSUM_COMPLETE ) +update_csum_diff4 (skb, old, *hlim_word); +skb_pull (skb,skb_transport_offset (skb)); goto looped_back; }
Signature · 1 line
2.43.0
Andrea Mayer
maintainerPATCH v2 3/6 seg6: update skb checksum when SRv6 behaviors advance to the next SID
In reply to Andrea Mayeradvance_nextseg() decrements Segments Left and writes the next segment into the destination address, and seg6_next_csid_advance_arg() advances the NEXT-C-SID argument in the destination address.
With CHECKSUM_COMPLETE, neither updates skb->csum for these changes. The stale skb->csum is read when the packet is delivered on the same node, e.g. through End.B6.Encaps towards a local End.DT6 SID.
As a consequence, when skb->csum is computed in software, for instance by conntrack, UDP can drop the packet as a checksum error. With skb->csum computed by the device, TCP can instead log a "hw csum failure", as if the device had computed a wrong skb->csum.
Update skb->csum in both functions with update_csum_diff16() for the destination address. advance_nextseg() also uses update_csum_diff4() for Segments Left.
Depends on patch "seg6: fix skb checksum update helpers".
Found by manual code inspection while working on
commit 8ae3f4067ba4 ("seg6: ensure packet data is writable before modifying SRH and IPv6 DA"), and reproduced in a VM without kernel changes or error injection. A following commit adds a selftest that reproduces the problem with a tc ct action. With this patch, the selftest passes for the End.B6.Encaps and next-csid paths. Also tested against the srv6 selftests, and with a ConnectX-6 Lx NIC (mlx5) that provides CHECKSUM_COMPLETE.
--- net/ipv6/seg6_local.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
net/ipv6/seg6_local.c +17 -1
@@ -305,7 +305,9 @@ static struct ipv6_sr_hdr *advance_nextseg(struct sk_buff *skb,struct ipv6_sr_hdr *srh, enum skb_drop_reason *reason) { + struct in6_addr *daddr;struct in6_addr *addr; +__be32 old;int srhoff;int wlen;
@@ -323,10 +325,19 @@ static struct ipv6_sr_hdr *advance_nextseg(struct sk_buff *skb,/* skb_ensure_writable() may change skb pointers; evaluate srh again */ srh = (struct ipv6_sr_hdr *)(skb->data + srhoff); + daddr = &ipv6_hdr (skb)->daddr; +/* nexthdr, hdrlen, type and segments_left */ + old = *(__be32 *)srh; srh->segments_left--; addr = srh->segments + srh->segments_left; -ipv6_hdr (skb)->daddr = *addr; + +if (skb->ip_summed ==CHECKSUM_COMPLETE ) { +update_csum_diff4 (skb, old, *(__be32 *)srh); +update_csum_diff16 (skb, (__be32 *)daddr, (__be32 *)addr); + } + + *daddr = *addr;return srh; }
@@ -441,11 +452,13 @@ seg6_next_csid_advance_arg(struct sk_buff *skb,__u8 fnc_octects =seg6_flv_lcnode_func_octects (finfo);__u8 blk_octects =seg6_flv_lcblock_octects (finfo);struct in6_addr *addr; +struct in6_addr old;if (unlikely (skb_ensure_writable (skb,sizeof (struct ipv6hdr ))))return SKB_DROP_REASON_NOMEM ; addr = &ipv6_hdr (skb)->daddr; + old = *addr;/* advance DA.Argument */ memmove(&addr->s6_addr[blk_octects],
@@ -454,6 +467,9 @@ seg6_next_csid_advance_arg(struct sk_buff *skb,memset (&addr->s6_addr[16 - fnc_octects],0x00 , fnc_octects); +if (skb->ip_summed ==CHECKSUM_COMPLETE ) +update_csum_diff16 (skb, (__be32 *)&old, (__be32 *)addr); +return SKB_NOT_DROPPED_YET ; }
Signature · 1 line
2.43.0
Andrea Mayer
maintainerPATCH v2 4/6 seg6: discard CHECKSUM_COMPLETE after the End.BPF program
In reply to Andrea MayerThe End.BPF program can change the packet through the seg6 BPF helpers, for instance the SRH Tag with bpf_lwt_seg6_store_bytes(). After the program, seg6_bpf_has_valid_srh() can also rewrite the SRH Hdr Ext Len.
With CHECKSUM_COMPLETE, the program does not always update skb->csum for the bytes it writes, and seg6_bpf_has_valid_srh() does not either. If the packet is then delivered on the same node and skb->csum was computed in software, for instance by conntrack, UDP can drop the packet as a checksum error. With skb->csum computed by the device, TCP can instead log a "hw csum failure", as if the device had computed a wrong skb->csum.
Discard CHECKSUM_COMPLETE with skb_checksum_complete_unset() after the program, since input_action_end_bpf() does not know which bytes the program changed. The checksum is then verified in software.
Found by manual code inspection and reproduced in a VM without kernel changes or error injection: with skb->csum computed by a tc ct action, an End.BPF program that writes the SRH Tag, followed by End.B6.Encaps and a local End.DT6 SID, makes UDP drop the packet. With this patch, the packet is delivered. Also tested against the srv6 selftests, the lwt_seg6local BPF selftest, and with a ConnectX-6 Lx NIC (mlx5) that provides CHECKSUM_COMPLETE.
--- net/ipv6/seg6_local.c | 6 ++++++ 1 file changed, 6 insertions(+)
net/ipv6/seg6_local.c +6 -0
@@ -1661,6 +1661,12 @@ static int input_action_end_bpf(struct sk_buff *skb, goto drop;local_unlock_nested_bh (&seg6_bpf_srh_states.bh_lock); +/* The program may have changed the packet and seg6_bpf_has_valid_srh() +* may have rewritten the SRH Hdr Ext Len. +* skb->csum may then no longer be the checksum of the full packet. +*/ +skb_checksum_complete_unset (skb); +if (ret !=BPF_REDIRECT )seg6_lookup_nexthop (skb,NULL ,0 );
Signature · 1 line
2.43.0
Re: [PATCH net v2 4/6] seg6: discard CHECKSUM_COMPLETE after the End.BPF program
Quoted 49 lines · Andrea Mayer
The End.BPF program can change the packet through the seg6 BPF helpers, for instance the SRH Tag with
bpf_lwt_seg6_store_bytes(). After the program,seg6_bpf_has_valid_srh()can also rewrite the SRH Hdr Ext Len.With
CHECKSUM_COMPLETE, the program does not always updateskb->csumfor the bytes it writes, andseg6_bpf_has_valid_srh()does not either. If the packet is then delivered on the same node andskb->csumwas computed in software, for instance by conntrack, UDP can drop the packet as a checksum error. Withskb->csumcomputed by the device, TCP can instead log a "hw csum failure", as if the device had computed a wrongskb->csum.Discard
CHECKSUM_COMPLETEwithskb_checksum_complete_unset()after the program, sinceinput_action_end_bpf()does not know which bytes the program changed. The checksum is then verified in software.Found by manual code inspection and reproduced in a VM without kernel changes or error injection: with
skb->csumcomputed by a tc ct action, an End.BPF program that writes the SRH Tag, followed by End.B6.Encaps and a local End.DT6 SID, makes UDP drop the packet. With this patch, the packet is delivered. Also tested against the srv6 selftests, thelwt_seg6localBPF selftest, and with a ConnectX-6 Lx NIC (mlx5) that providesCHECKSUM_COMPLETE.Fixes 004d4b274e2a ("ipv6: sr: Add seg6local action End.BPF")Signed-off-by Andrea Mayer <[email protected]>--- net/ipv6/seg6_local.c | 6 ++++++ 1 file changed, 6 insertions(+)net/ipv6/seg6_local.c +6
-0@@ -1661,6 +1661,12 @@ static int input_action_end_bpf(struct sk_buff *skb, goto drop;local_unlock_nested_bh (&seg6_bpf_srh_states.bh_lock); +/* The program may have changed the packet and seg6_bpf_has_valid_srh() +* may have rewritten the SRH Hdr Ext Len. +* skb->csum may then no longer be the checksum of the full packet. +*/ +skb_checksum_complete_unset (skb); +if (ret !=BPF_REDIRECT )seg6_lookup_nexthop (skb,NULL ,0 );Signature · 1 line
2.43.0
Andrea Mayer
maintainerPATCH v2 5/6 seg6: account for the MAC header in skb checksum on L2 encapsulation
In reply to Andrea MayerIn L2ENCAP and L2ENCAP_RED mode, seg6_do_srh() puts the MAC header back in front of the frame with skb_push(), without adding it to skb->csum. The encapsulation then calls skb_postpush_rcsum() only for the outer headers. With CHECKSUM_COMPLETE the MAC header is missing from skb->csum, which no longer covers the whole packet as required.
For a forwarded packet, ip6_forward() sets ip_summed to CHECKSUM_NONE with skb_forward_csum(), and End.DX2 does the same before sending the frame. When the packet is delivered on the same node, a raw socket with IPV6_CHECKSUM still reads skb->csum. With skb->csum computed by the device, the kernel can then log a "hw csum failure", as if the device had computed a wrong skb->csum.
Use skb_push_rcsum(), which also calls skb_postpush_rcsum() for the MAC header.
Found by manual code inspection of the skb->csum updates in the SRv6 code, and observed in a VM without kernel changes or error injection: with skb->csum computed by a tc ct action, a BPF tracing program on ip6_forward() shows skb->csum missing the MAC header. With this patch, skb->csum covers it. Also tested against the srv6 selftests, and with a ConnectX-6 Lx NIC (mlx5) that provides CHECKSUM_COMPLETE.
--- net/ipv6/seg6_iptunnel.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv6/seg6_iptunnel.c +1 -1
@@ -472,7 +472,7 @@ static int seg6_do_srh(struct sk_buff *skb, struct dst_entry *cache_dst)return err;skb_mac_header_rebuild (skb); -skb_push (skb, skb->mac_len); +skb_push_rcsum (skb, skb->mac_len);if (tinfo->mode ==SEG6_IPTUN_MODE_L2ENCAP ) err = __seg6_do_srh_encap(skb, tinfo->srh,
Signature · 1 line
2.43.0
Re: [PATCH net v2 5/6] seg6: account for the MAC header in skb checksum on L2 encapsulation
Quoted 45 lines · Andrea Mayer
In L2ENCAP and
L2ENCAP_REDmode,seg6_do_srh()puts the MAC header back in front of the frame withskb_push(), without adding it toskb->csum. The encapsulation then callsskb_postpush_rcsum()only for the outer headers. WithCHECKSUM_COMPLETEthe MAC header is missing fromskb->csum, which no longer covers the whole packet as required.For a forwarded packet,
ip6_forward()setsip_summedtoCHECKSUM_NONEwithskb_forward_csum(), and End.DX2 does the same before sending the frame. When the packet is delivered on the same node, a raw socket withIPV6_CHECKSUMstill readsskb->csum. Withskb->csumcomputed by the device, the kernel can then log a "hw csum failure", as if the device had computed a wrongskb->csum.Use
skb_push_rcsum(), which also callsskb_postpush_rcsum()for the MAC header.Found by manual code inspection of the
skb->csumupdates in the SRv6 code, and observed in a VM without kernel changes or error injection: withskb->csumcomputed by a tc ct action, a BPF tracing program onip6_forward()showsskb->csummissing the MAC header. With this patch,skb->csumcovers it. Also tested against the srv6 selftests, and with a ConnectX-6 Lx NIC (mlx5) that providesCHECKSUM_COMPLETE.Fixes 38ee7f2d4756 ("ipv6: sr: add support for encapsulation of L2 frames")Signed-off-by Andrea Mayer <[email protected]>--- net/ipv6/seg6_iptunnel.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/ipv6/seg6_iptunnel.c +1
-1@@ -472,7 +472,7 @@ static int seg6_do_srh(struct sk_buff *skb, struct dst_entry *cache_dst)return err;skb_mac_header_rebuild (skb); -skb_push (skb, skb->mac_len); +skb_push_rcsum (skb, skb->mac_len);if (tinfo->mode ==SEG6_IPTUN_MODE_L2ENCAP ) err = __seg6_do_srh_encap(skb, tinfo->srh,Signature · 1 line
2.43.0
Andrea Mayer
maintainerPATCH v2 6/6 selftests: seg6: add test for skb checksum with CHECKSUM_COMPLETE
In reply to Andrea MayerAdd a selftest for received packets with CHECKSUM_COMPLETE that the SRv6 code processes before they are delivered on the same node. The test checks that, after the node changes the packet, UDP does not read a wrong skb->csum.
The test uses a host and a router connected through a veth pair. Since veth does not provide CHECKSUM_COMPLETE, a tc ct action on the router computes skb->csum in software.
The host sends a UDP datagram to the router along five paths: no SRH (the reference), an SRH with local segments, End.B6.Encaps with End.DT6, End with the next-csid flavor, and End.BPF. Each datagram is expected to be delivered, not dropped as a checksum error. Without the previous patches, every path except the reference fails. With them, every path passes.
The host also sends a control datagram. It checks that the test detects a wrong skb->csum after a change to the packet. After the ct action, a BPF program on the router changes the Flow Label of the control datagram without updating skb->csum, and UDP must drop it. If UDP accepts it, the paths above may report a false pass, and the test fails.
--- tools/testing/selftests/net/Makefile | 1 + .../selftests/net/srv6_csum_complete.bpf.c | 65 ++ .../selftests/net/srv6_csum_complete_test.sh | 627 ++++++++++++++++++ 3 files changed, 693 insertions(+) create mode 100644 tools/testing/selftests/net/srv6_csum_complete.bpf.c create mode 100755 tools/testing/selftests/net/srv6_csum_complete_test.sh
tools/testing/selftests/net/Makefile +1 -0
@@ -94,6 +94,7 @@ TEST_PROGS := \ sctp_ifwdtsn.sh \ sctp_vrf.sh \ skf_net_off.sh \ + srv6_csum_complete_test.sh \ srv6_encap_lookup_l3vpn_test.sh \ srv6_end_dt46_l3vpn_test.sh \ srv6_end_dt4_l3vpn_test.sh \
tools/testing/selftests/net/srv6_csum_complete.bpf.c new file +65 -0
65 lines not on this page · raw message
tools/testing/selftests/net/srv6_csum_complete_test.sh new file +627 -0
627 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH net v2 6/6] selftests: seg6: add test for skb checksum with CHECKSUM_COMPLETE
Hi Andrea,
Quoted 15 lines · Andrea Mayer
Add a selftest for received packets with
CHECKSUM_COMPLETEthat the SRv6 code processes before they are delivered on the same node. The test checks that, after the node changes the packet, UDP does not read a wrongskb->csum.The test uses a host and a router connected through a veth pair. Since veth does not provide
CHECKSUM_COMPLETE, a tc ct action on the router computesskb->csumin software.The host sends a UDP datagram to the router along five paths: no SRH (the reference), an SRH with local segments, End.B6.Encaps with End.DT6, End with the next-csid flavor, and End.BPF. Each datagram is expected to be delivered, not dropped as a checksum error. Without the previous patches, every path except the reference fails. With them, every path passes.
Quoted 8 lines
The host also sends a control datagram. It checks that the test detects a wrong
skb->csumafter a change to the packet. After the ct action, a BPF program on the router changes the Flow Label of the control datagram without updatingskb->csum, and UDP must drop it. If UDP accepts it, the paths above may report a false pass, and the test fails.Signed-off-by Andrea Mayer <[email protected]>---
Here are some code style comments. You can decide whether to change them or not.
tools/testing/selftests/net/srv6_csum_complete_test.sh line 183
Quoted 12 lines
tools/testing/selftests/net/srv6_csum_complete_test.sh new file +11
-0+print_log_test_results() +{ + printf "\nTests passed: %3d\n" "${nsuccess}" + printf "Tests failed: %3d\n" "${nfail}" + + # when a test fails, the value of 'ret' is set to 1 (error code). + # Conversely, when all tests are passed successfully, the 'ret' value + # is set to 0 (success code). + if [ "${ret}" -ne 1 ]; then + ret=0 + fi
Do we need to reset the "ret"? It's $ksft_skip by default. If any test failed, it is set to $ksft_fail. We can just exit with $ret at cleanup().
tools/testing/selftests/net/srv6_csum_complete_test.sh line 203
Quoted 11 lines
tools/testing/selftests/net/srv6_csum_complete_test.sh new file +11
-0+ +cleanup() +{ + cleanup_all_ns + + # check whether the setup phase was completed successfully or not. In + # case of an error during the setup phase of the testing environment, + # the selftest is considered as "skipped". + if [ "${SETUP_ERR}" -ne 0 ]; then + echo "SKIP: Setting up the testing environment failed" + exit "${ksft_skip}"
if [ "${SETUP_ERR}" -ne 0 ], the ret should be ${ksft_skip}, right? Cause we haven't run any test.
Then we can goto the following exit directly.
Quoted 5 lines
tools/testing/selftests/net/srv6_csum_complete_test.sh new file +5
-0+ fi + + exit "${ret}" +} +
[...]
Quoted 11 lines
tools/testing/selftests/net/srv6_csum_complete_test.sh new file +11
-0+test_end_bpf_or_ksft_skip() +{ + local test_netns + + setup_ns test_netns + + ip -netns "${test_netns}" link add "${DUMMY_DEVNAME}" type dummy + ip -netns "${test_netns}" link set "${DUMMY_DEVNAME}" up + + if ! ip -netns "${test_netns}" -6 route \ + add "${SID_LOCATOR}::${BPF_FUNC}/128" encap seg6local \
tools/testing/selftests/net/srv6_csum_complete_test.sh line 594
Quoted 10 lines
tools/testing/selftests/net/srv6_csum_complete_test.sh new file +10
-0+ action End.BPF endpoint obj "${BPF_FILE}" \ + sec "${BPF_END_SEC}" dev "${DUMMY_DEVNAME}" \ + 2>/dev/null; then + cleanup_ns "${test_netns}" + echo "SKIP: SRv6 End.BPF not supported" + exit "${ksft_skip}" + fi + + cleanup_ns "${test_netns}" +}
Maybe move the trap cleanup EXIT here.
Then we can just exit instead of exit "${ksft_skip}" for all the test_* functions. The cleanup_all_ns() will just do nothing when the NS_LIST is NULL.
If a command missing, or test_* function failed. The report shows
SKIP: xxx not supported
SKIP: Setting up the testing environment failed
# echo $? 4
Quoted 25 lines
tools/testing/selftests/net/srv6_csum_complete_test.sh new file +24
-0+ +if [ "$(id -u)" -ne 0 ]; then + echo "SKIP: Need root privileges" + exit "${ksft_skip}" +fi + +# required programs to carry out this selftest +require_command ip +require_command tc +require_command ethtool +require_command ping +require_command sysctl +require_command awk +require_command grep + +test_dummy_dev_or_ksft_skip +test_iproute2_supp_or_ksft_skip +test_kernel_supp_or_ksft_skip +test_veth_tx_csum_off_or_ksft_skip +test_bpf_file_or_ksft_skip +test_tc_or_ksft_skip +test_end_bpf_or_ksft_skip + +set -e
tools/testing/selftests/net/srv6_csum_complete_test.sh line 627
Quoted 10 lines
tools/testing/selftests/net/srv6_csum_complete_test.sh new file +9
-0+trap cleanup EXIT + +setup +set +e + +connectivity_tests +udp_delivery_tests + +print_log_test_results
Apart from the comments, the test looks good to me.
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 13 lines · On Wed, 18 Nov 2026 16:02:45 +0100 you wrote:
This series fixes the
skb->csumupdates withCHECKSUM_COMPLETEwhen the SRv6 code processes a received packet. In several placesskb->csumis not updated correctly:
-ipv6_srh_rcv()updatesskb->csumwith the wrong sign for the new Segments Left and destination address, and not at all for the Hop Limit decrement.
-advance_nextseg()andseg6_next_csid_advance_arg()inseg6_localdo not updateskb->csum.
- The End.BPF program andseg6_bpf_has_valid_srh()can change the packet without updatingskb->csum.
- In L2ENCAP andL2ENCAP_REDmode, the MAC header put back in front of the frame is not added toskb->csum.
Quoted 1 line
[...]
Here is the summary with links:
- [net,v2,1/6] seg6: fix skb checksum update helpers
https://git.kernel.org/netdev/net-next/c/47b2998b644c - [net,v2,2/6] seg6: update skb checksum when ipv6_srh_rcv() decrements the Hop Limit https://git.kernel.org/netdev/net-next/c/47f89dfc930b - [net,v2,3/6] seg6: update skb checksum when SRv6 behaviors advance to the next SID https://git.kernel.org/netdev/net-next/c/520989b4d32a - [net,v2,4/6] seg6: discard CHECKSUM_COMPLETE after the End.BPF program https://git.kernel.org/netdev/net-next/c/53e0a84a417d - [net,v2,5/6] seg6: account for the MAC header in skb checksum on L2 encapsulation https://git.kernel.org/netdev/net-next/c/e75bae5fcf5a - [net,v2,6/6] selftests: seg6: add test for skb checksum with CHECKSUM_COMPLETE https://git.kernel.org/netdev/net-next/c/612a37673567
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html