* [PATCH net] net: selftests: fix TCP packet checksum
@ 2025-06-24 18:32 Jakub Kicinski
2025-06-24 20:53 ` Gerhard Engleder
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Jakub Kicinski @ 2025-06-24 18:32 UTC (permalink / raw)
To: davem
Cc: netdev, edumazet, pabeni, andrew+netdev, horms, Jakub Kicinski,
o.rempel, gerhard
The length in the pseudo header should be the length of the L3 payload
AKA the L4 header+payload. The selftest code builds the packet from
the lower layers up, so all the headers are pushed already when it
constructs L4. We need to subtract the lower layer headers from skb->len.
Fixes: 3e1e58d64c3d ("net: add generic selftest support")
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
CC: o.rempel@pengutronix.de
CC: gerhard@engleder-embedded.com
I changed the math from the pointers to the offsets (which is what
udp4_hwcsum() does). Oleksij, would you be willing to retest and send
your Reported-and-tested-by: tag?
---
net/core/selftests.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/net/core/selftests.c b/net/core/selftests.c
index 35f807ea9952..406faf8e5f3f 100644
--- a/net/core/selftests.c
+++ b/net/core/selftests.c
@@ -160,8 +160,9 @@ static struct sk_buff *net_test_get_skb(struct net_device *ndev,
skb->csum = 0;
skb->ip_summed = CHECKSUM_PARTIAL;
if (attr->tcp) {
- thdr->check = ~tcp_v4_check(skb->len, ihdr->saddr,
- ihdr->daddr, 0);
+ int l4len = skb->len - skb_transport_offset(skb);
+
+ thdr->check = ~tcp_v4_check(l4len, ihdr->saddr, ihdr->daddr, 0);
skb->csum_start = skb_transport_header(skb) - skb->head;
skb->csum_offset = offsetof(struct tcphdr, check);
} else {
--
2.49.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH net] net: selftests: fix TCP packet checksum
2025-06-24 18:32 [PATCH net] net: selftests: fix TCP packet checksum Jakub Kicinski
@ 2025-06-24 20:53 ` Gerhard Engleder
2025-06-25 4:30 ` Oleksij Rempel
2025-06-26 9:00 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Gerhard Engleder @ 2025-06-24 20:53 UTC (permalink / raw)
To: Jakub Kicinski
Cc: netdev, edumazet, pabeni, andrew+netdev, horms, o.rempel, davem
On 24.06.25 20:32, Jakub Kicinski wrote:
> The length in the pseudo header should be the length of the L3 payload
> AKA the L4 header+payload. The selftest code builds the packet from
> the lower layers up, so all the headers are pushed already when it
> constructs L4. We need to subtract the lower layer headers from skb->len.
>
> Fixes: 3e1e58d64c3d ("net: add generic selftest support")
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
> ---
> CC: o.rempel@pengutronix.de
> CC: gerhard@engleder-embedded.com
>
> I changed the math from the pointers to the offsets (which is what
> udp4_hwcsum() does). Oleksij, would you be willing to retest and send
> your Reported-and-tested-by: tag?
> ---
> net/core/selftests.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/net/core/selftests.c b/net/core/selftests.c
> index 35f807ea9952..406faf8e5f3f 100644
> --- a/net/core/selftests.c
> +++ b/net/core/selftests.c
> @@ -160,8 +160,9 @@ static struct sk_buff *net_test_get_skb(struct net_device *ndev,
> skb->csum = 0;
> skb->ip_summed = CHECKSUM_PARTIAL;
> if (attr->tcp) {
> - thdr->check = ~tcp_v4_check(skb->len, ihdr->saddr,
> - ihdr->daddr, 0);
> + int l4len = skb->len - skb_transport_offset(skb);
> +
> + thdr->check = ~tcp_v4_check(l4len, ihdr->saddr, ihdr->daddr, 0);
> skb->csum_start = skb_transport_header(skb) - skb->head;
> skb->csum_offset = offsetof(struct tcphdr, check);
> } else {
Reviewed-by: Gerhard Engleder <gerhard@engleder-embedded.com>
And also tested with my selftest patches for tsnep, which did not made
it into mainline. So I'm not sure if a Tested-by is allowed.
(Tested-by: Gerhard Engleder <gerhard@engleder-embedded.com>)
gerhard
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net] net: selftests: fix TCP packet checksum
2025-06-24 18:32 [PATCH net] net: selftests: fix TCP packet checksum Jakub Kicinski
2025-06-24 20:53 ` Gerhard Engleder
@ 2025-06-25 4:30 ` Oleksij Rempel
2025-06-26 9:00 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Oleksij Rempel @ 2025-06-25 4:30 UTC (permalink / raw)
To: Jakub Kicinski
Cc: davem, netdev, edumazet, pabeni, andrew+netdev, horms, gerhard
On Tue, Jun 24, 2025 at 11:32:58AM -0700, Jakub Kicinski wrote:
> The length in the pseudo header should be the length of the L3 payload
> AKA the L4 header+payload. The selftest code builds the packet from
> the lower layers up, so all the headers are pushed already when it
> constructs L4. We need to subtract the lower layer headers from skb->len.
>
> Fixes: 3e1e58d64c3d ("net: add generic selftest support")
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Reported-by: Oleksij Rempel <o.rempel@pengutronix.de>
Tested-by: Oleksij Rempel <o.rempel@pengutronix.de>
Reviewed-by: Oleksij Rempel <o.rempel@pengutronix.de>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net] net: selftests: fix TCP packet checksum
2025-06-24 18:32 [PATCH net] net: selftests: fix TCP packet checksum Jakub Kicinski
2025-06-24 20:53 ` Gerhard Engleder
2025-06-25 4:30 ` Oleksij Rempel
@ 2025-06-26 9:00 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-06-26 9:00 UTC (permalink / raw)
To: Jakub Kicinski
Cc: davem, netdev, edumazet, pabeni, andrew+netdev, horms, o.rempel,
gerhard
Hello:
This patch was applied to netdev/net.git (main)
by Paolo Abeni <pabeni@redhat.com>:
On Tue, 24 Jun 2025 11:32:58 -0700 you wrote:
> The length in the pseudo header should be the length of the L3 payload
> AKA the L4 header+payload. The selftest code builds the packet from
> the lower layers up, so all the headers are pushed already when it
> constructs L4. We need to subtract the lower layer headers from skb->len.
>
> Fixes: 3e1e58d64c3d ("net: add generic selftest support")
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
>
> [...]
Here is the summary with links:
- [net] net: selftests: fix TCP packet checksum
https://git.kernel.org/netdev/net/c/8d89661a36dd
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-06-26 8:59 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-24 18:32 [PATCH net] net: selftests: fix TCP packet checksum Jakub Kicinski
2025-06-24 20:53 ` Gerhard Engleder
2025-06-25 4:30 ` Oleksij Rempel
2025-06-26 9:00 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).