Skip to content

Commit ec6f25b

Browse files
wdebruijkuba-moo
authored andcommitted
selftests/net: skip partial checksum packets in csum test
Detect packets with ip_summed CHECKSUM_PARTIAL and skip these. These should not exist, as the test sends individual packets between two hosts. But if (HW) GRO is on, with randomized content sometimes subsequent packets can be coalesced. In this case the GSO packet checksum is converted to a pseudo checksum in anticipation of sending out as TSO/USO. So the field will not match the expected value. Do not count these as test errors. Signed-off-by: Willem de Bruijn <willemb@google.com> Link: https://lore.kernel.org/r/20240501193156.3627344-1-willemdebruijn.kernel@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent e1bb5e6 commit ec6f25b

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

  • tools/testing/selftests/net

tools/testing/selftests/net/csum.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ static int recv_verify_packet_ipv6(void *nh, int len)
682682
}
683683

684684
/* return whether auxdata includes TP_STATUS_CSUM_VALID */
685-
static bool recv_verify_packet_csum(struct msghdr *msg)
685+
static uint32_t recv_get_packet_csum_status(struct msghdr *msg)
686686
{
687687
struct tpacket_auxdata *aux = NULL;
688688
struct cmsghdr *cm;
@@ -706,7 +706,7 @@ static bool recv_verify_packet_csum(struct msghdr *msg)
706706
if (!aux)
707707
error(1, 0, "cmsg: no auxdata");
708708

709-
return aux->tp_status & TP_STATUS_CSUM_VALID;
709+
return aux->tp_status;
710710
}
711711

712712
static int recv_packet(int fd)
@@ -716,6 +716,7 @@ static int recv_packet(int fd)
716716
char ctrl[CMSG_SPACE(sizeof(struct tpacket_auxdata))];
717717
struct pkt *buf = (void *)_buf;
718718
struct msghdr msg = {0};
719+
uint32_t tp_status;
719720
struct iovec iov;
720721
int len, ret;
721722

@@ -737,6 +738,17 @@ static int recv_packet(int fd)
737738
if (len == -1)
738739
error(1, errno, "recv p");
739740

741+
tp_status = recv_get_packet_csum_status(&msg);
742+
743+
/* GRO might coalesce randomized packets. Such GSO packets are
744+
* then reinitialized for csum offload (CHECKSUM_PARTIAL), with
745+
* a pseudo csum. Do not try to validate these checksums.
746+
*/
747+
if (tp_status & TP_STATUS_CSUMNOTREADY) {
748+
fprintf(stderr, "cmsg: GSO packet has partial csum: skip\n");
749+
continue;
750+
}
751+
740752
if (cfg_family == PF_INET6)
741753
ret = recv_verify_packet_ipv6(buf, len);
742754
else
@@ -753,7 +765,7 @@ static int recv_packet(int fd)
753765
* Do not fail if kernel does not validate a good csum:
754766
* Absence of validation does not imply invalid.
755767
*/
756-
if (recv_verify_packet_csum(&msg) && cfg_bad_csum) {
768+
if (tp_status & TP_STATUS_CSUM_VALID && cfg_bad_csum) {
757769
fprintf(stderr, "cmsg: expected bad csum, pf_packet returns valid\n");
758770
bad_validations++;
759771
}

0 commit comments

Comments
 (0)