Skip to content

Commit 8d89661

Browse files
kuba-mooPaolo Abeni
authored andcommitted
net: selftests: fix TCP packet checksum
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: 3e1e58d ("net: add generic selftest support") Signed-off-by: Jakub Kicinski <[email protected]> Reviewed-by: Gerhard Engleder <[email protected]> Reported-by: Oleksij Rempel <[email protected]> Tested-by: Oleksij Rempel <[email protected]> Reviewed-by: Oleksij Rempel <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent a433791 commit 8d89661

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

net/core/selftests.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,9 @@ static struct sk_buff *net_test_get_skb(struct net_device *ndev,
160160
skb->csum = 0;
161161
skb->ip_summed = CHECKSUM_PARTIAL;
162162
if (attr->tcp) {
163-
thdr->check = ~tcp_v4_check(skb->len, ihdr->saddr,
164-
ihdr->daddr, 0);
163+
int l4len = skb->len - skb_transport_offset(skb);
164+
165+
thdr->check = ~tcp_v4_check(l4len, ihdr->saddr, ihdr->daddr, 0);
165166
skb->csum_start = skb_transport_header(skb) - skb->head;
166167
skb->csum_offset = offsetof(struct tcphdr, check);
167168
} else {

0 commit comments

Comments
 (0)