diff options
| author | Joe Damato <joe@dama.to> | 2026-07-28 09:09:29 -0700 |
|---|---|---|
| committer | Jakub Kicinski <kuba@kernel.org> | 2026-07-29 16:59:39 -0700 |
| commit | f5a445d2a2a335b2011e90558ec9cdd48ae79ada (patch) | |
| tree | e956c53ec12758208b0e1ba29358eba83a646019 | |
| parent | 2544d30c11eb3f70ffe867449f0a5721e130ae7d (diff) | |
| download | linux-next-f5a445d2a2a335b2011e90558ec9cdd48ae79ada.tar.gz linux-next-f5a445d2a2a335b2011e90558ec9cdd48ae79ada.zip | |
selftests/net: psock_snd: Verify sll_pkttype
Extend do_rx() to take an expected packet type. Existing callers pass -1
to skip the check.
Signed-off-by: Joe Damato <joe@dama.to>
Reviewed-by: Willem de Bruijn <willemb@google.com>
Link: https://patch.msgid.link/20260728160935.4128982-5-joe@dama.to
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
| -rw-r--r-- | tools/testing/selftests/net/psock_snd.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/tools/testing/selftests/net/psock_snd.c b/tools/testing/selftests/net/psock_snd.c index b2593daca603..f23877942ea3 100644 --- a/tools/testing/selftests/net/psock_snd.c +++ b/tools/testing/selftests/net/psock_snd.c @@ -310,10 +310,13 @@ static void check_aux_data(struct cmsghdr *cmsg, int expected_len) error(1, 0, "cmsg tp_snaplen != %u", expected_len); } -static void do_rx(int fd, int expected_len, char *expected, bool is_psock) +/* expected_pkttype < 0 skips the sll_pkttype check. */ +static void do_rx(int fd, int expected_len, char *expected, bool is_psock, + int expected_pkttype) { char cmsg_buf[1024] __attribute__((aligned(8))) = {}; bool aux = is_psock && cfg_aux_data; + struct sockaddr_ll saddr = {}; struct iovec iov = { .iov_base = rbuf, .iov_len = sizeof(rbuf), @@ -328,6 +331,10 @@ static void do_rx(int fd, int expected_len, char *expected, bool is_psock) msg.msg_control = cmsg_buf; msg.msg_controllen = sizeof(cmsg_buf); } + if (is_psock) { + msg.msg_name = &saddr; + msg.msg_namelen = sizeof(saddr); + } ret = recvmsg(fd, &msg, 0); if (ret == -1) @@ -341,6 +348,10 @@ static void do_rx(int fd, int expected_len, char *expected, bool is_psock) if (aux) check_aux_data(CMSG_FIRSTHDR(&msg), expected_len); + if (expected_pkttype >= 0 && saddr.sll_pkttype != expected_pkttype) + error(1, 0, "recv: sll_pkttype %d != %d", + saddr.sll_pkttype, expected_pkttype); + fprintf(stderr, "rx: %u\n", ret); } @@ -492,11 +503,11 @@ static void run_test(void) /* BPF filter accepts only this length, vlan changes MAC */ if (cfg_payload_len == DATA_LEN && !cfg_use_vlan) { do_rx(fds, total_len - sizeof(struct virtio_net_hdr), - tbuf + sizeof(struct virtio_net_hdr), true); + tbuf + sizeof(struct virtio_net_hdr), true, -1); check_packet_stats(fds, 1); } - do_rx(fdr, cfg_payload_len, tbuf + total_len - cfg_payload_len, false); + do_rx(fdr, cfg_payload_len, tbuf + total_len - cfg_payload_len, false, -1); out: if (close(fds)) |
