public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [net-next 0/3] Extend packet socket selftests
@ 2026-04-02 23:21 Joe Damato
  2026-04-02 23:21 ` [net-next 1/3] selftests/net: Test PACKET_STATISTICS Joe Damato
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Joe Damato @ 2026-04-02 23:21 UTC (permalink / raw)
  To: netdev
  Cc: andrew+netdev, davem, edumazet, kuba, pabeni, horms, linux-kernel,
	willemb, Joe Damato, linux-kselftest, Shuah Khan

Greetings:

I was looking around the packet socket code and noticed there were a few
features that could be tested by extending the existing packet socket
tests.

I extended the test to test stats, drops, and auxdata and re-ran the tests.
The existing and new tests passed.

Thanks,
Joe

Joe Damato (3):
  selftests/net: Test PACKET_STATISTICS
  selftests/net: Test PACKET_STATISTICS drops
  selftests/net: Test PACKET_AUXDATA

 tools/testing/selftests/net/psock_snd.c  | 131 +++++++++++++++++++++--
 tools/testing/selftests/net/psock_snd.sh |  10 ++
 2 files changed, 133 insertions(+), 8 deletions(-)


base-commit: f35340f2d653f1003602878403c901396ab03c17
-- 
2.52.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [net-next 1/3] selftests/net: Test PACKET_STATISTICS
  2026-04-02 23:21 [net-next 0/3] Extend packet socket selftests Joe Damato
@ 2026-04-02 23:21 ` Joe Damato
  2026-04-02 23:21 ` [net-next 2/3] selftests/net: Test PACKET_STATISTICS drops Joe Damato
  2026-04-02 23:21 ` [net-next 3/3] selftests/net: Test PACKET_AUXDATA Joe Damato
  2 siblings, 0 replies; 7+ messages in thread
From: Joe Damato @ 2026-04-02 23:21 UTC (permalink / raw)
  To: netdev, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Simon Horman, Shuah Khan
  Cc: andrew+netdev, linux-kernel, willemb, Joe Damato, linux-kselftest

Update the existing packet socket test to include a test for the sockopt
PACKET_STATISTICS.

Signed-off-by: Joe Damato <joe@dama.to>
---
 tools/testing/selftests/net/psock_snd.c | 32 ++++++++++++++++++++++++-
 1 file changed, 31 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/net/psock_snd.c b/tools/testing/selftests/net/psock_snd.c
index edf1e6f80d41..5be481a3d2bd 100644
--- a/tools/testing/selftests/net/psock_snd.c
+++ b/tools/testing/selftests/net/psock_snd.c
@@ -359,6 +359,34 @@ static void parse_opts(int argc, char **argv)
 		error(1, 0, "option gso (-g) requires csum offload (-c)");
 }
 
+static void check_packet_stats(int fd)
+{
+	struct tpacket_stats st = {};
+	socklen_t len = sizeof(st);
+
+	if (getsockopt(fd, SOL_PACKET, PACKET_STATISTICS, &st, &len))
+		error(1, errno, "getsockopt packet statistics");
+
+	if (st.tp_packets != 1)
+		error(1, 0, "stats: tp_packets %u != 1", st.tp_packets);
+
+	if (st.tp_drops != 0)
+		error(1, 0, "stats: tp_drops %u != 0", st.tp_drops);
+
+	/* verify clear on read */
+	memset(&st, 0xff, sizeof(st));
+	len = sizeof(st);
+
+	if (getsockopt(fd, SOL_PACKET, PACKET_STATISTICS, &st, &len))
+		error(1, errno, "getsockopt packet statistics");
+
+	if (st.tp_packets != 0)
+		error(1, 0, "stats: tp_packets %u != 0 after clear", st.tp_packets);
+
+	if (st.tp_drops != 0)
+		error(1, 0, "stats: tp_drops %u != 0 after clear", st.tp_drops);
+}
+
 static void run_test(void)
 {
 	int fdr, fds, total_len;
@@ -369,9 +397,11 @@ static void run_test(void)
 	total_len = do_tx();
 
 	/* BPF filter accepts only this length, vlan changes MAC */
-	if (cfg_payload_len == DATA_LEN && !cfg_use_vlan)
+	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));
+		check_packet_stats(fds);
+	}
 
 	do_rx(fdr, cfg_payload_len, tbuf + total_len - cfg_payload_len);
 
-- 
2.52.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [net-next 2/3] selftests/net: Test PACKET_STATISTICS drops
  2026-04-02 23:21 [net-next 0/3] Extend packet socket selftests Joe Damato
  2026-04-02 23:21 ` [net-next 1/3] selftests/net: Test PACKET_STATISTICS Joe Damato
@ 2026-04-02 23:21 ` Joe Damato
  2026-04-03 15:26   ` Willem de Bruijn
  2026-04-02 23:21 ` [net-next 3/3] selftests/net: Test PACKET_AUXDATA Joe Damato
  2 siblings, 1 reply; 7+ messages in thread
From: Joe Damato @ 2026-04-02 23:21 UTC (permalink / raw)
  To: netdev, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Simon Horman, Shuah Khan
  Cc: andrew+netdev, linux-kernel, willemb, Joe Damato, linux-kselftest

Extend psock_snd to test drops by setting a tiny receive buffer and
sending a large burst of packets.

Signed-off-by: Joe Damato <joe@dama.to>
---
 tools/testing/selftests/net/psock_snd.c  | 52 ++++++++++++++++++++----
 tools/testing/selftests/net/psock_snd.sh |  5 +++
 2 files changed, 48 insertions(+), 9 deletions(-)

diff --git a/tools/testing/selftests/net/psock_snd.c b/tools/testing/selftests/net/psock_snd.c
index 5be481a3d2bd..7bbce274b9f0 100644
--- a/tools/testing/selftests/net/psock_snd.c
+++ b/tools/testing/selftests/net/psock_snd.c
@@ -39,6 +39,7 @@ static bool	cfg_use_gso;
 static bool	cfg_use_qdisc_bypass;
 static bool	cfg_use_vlan;
 static bool	cfg_use_vnet;
+static bool	cfg_drop;
 
 static char	*cfg_ifname = "lo";
 static int	cfg_mtu	= 1500;
@@ -49,6 +50,8 @@ static uint16_t	cfg_port = 8000;
 /* test sending up to max mtu + 1 */
 #define TEST_SZ	(sizeof(struct virtio_net_hdr) + ETH_HLEN + ETH_MAX_MTU + 1)
 
+#define BURST_CNT (1000)
+
 static char tbuf[TEST_SZ], rbuf[TEST_SZ];
 
 static unsigned long add_csum_hword(const uint16_t *start, int num_u16)
@@ -212,13 +215,14 @@ static void do_send(int fd, char *buf, int len)
 	if (ret != len)
 		error(1, 0, "write: %u %u", ret, len);
 
-	fprintf(stderr, "tx: %u\n", ret);
+	if (!cfg_drop)
+		fprintf(stderr, "tx: %u\n", ret);
 }
 
-static int do_tx(void)
+static int do_tx(bool burst)
 {
 	const int one = 1;
-	int fd, len;
+	int i, fd, len;
 
 	fd = socket(PF_PACKET, cfg_use_dgram ? SOCK_DGRAM : SOCK_RAW, 0);
 	if (fd == -1)
@@ -242,6 +246,10 @@ static int do_tx(void)
 
 	do_send(fd, tbuf, len);
 
+	if (burst)
+		for (i = 0; i < BURST_CNT; i++)
+			do_send(fd, tbuf, len);
+
 	if (close(fd))
 		error(1, errno, "close t");
 
@@ -290,6 +298,7 @@ static void do_rx(int fd, int expected_len, char *expected)
 static int setup_sniffer(void)
 {
 	struct timeval tv = { .tv_usec = 100 * 1000 };
+	const int one = 1;
 	int fd;
 
 	fd = socket(PF_PACKET, SOCK_RAW, 0);
@@ -299,6 +308,10 @@ static int setup_sniffer(void)
 	if (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)))
 		error(1, errno, "setsockopt rcv timeout");
 
+	if (cfg_drop)
+		if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &one, sizeof(one)))
+			error(1, errno, "setsockopt SO_RCVBUF");
+
 	pair_udp_setfilter(fd);
 	do_bind(fd);
 
@@ -309,7 +322,7 @@ static void parse_opts(int argc, char **argv)
 {
 	int c;
 
-	while ((c = getopt(argc, argv, "bcCdgl:qt:vV")) != -1) {
+	while ((c = getopt(argc, argv, "bcCdDgl:qt:vV")) != -1) {
 		switch (c) {
 		case 'b':
 			cfg_use_bind = true;
@@ -323,6 +336,9 @@ static void parse_opts(int argc, char **argv)
 		case 'd':
 			cfg_use_dgram = true;
 			break;
+		case 'D':
+			cfg_drop = true;
+			break;
 		case 'g':
 			cfg_use_gso = true;
 			break;
@@ -367,11 +383,23 @@ static void check_packet_stats(int fd)
 	if (getsockopt(fd, SOL_PACKET, PACKET_STATISTICS, &st, &len))
 		error(1, errno, "getsockopt packet statistics");
 
-	if (st.tp_packets != 1)
-		error(1, 0, "stats: tp_packets %u != 1", st.tp_packets);
+	if (cfg_drop) {
+		/* PACKET_STATISTICS reports all packets seen (including
+		 * drops) in tp_packets
+		 */
+		if (st.tp_packets < st.tp_drops)
+			error(1, 0, "stats: tp_packets %u < tp_drops %u",
+			      st.tp_packets, st.tp_drops);
 
-	if (st.tp_drops != 0)
-		error(1, 0, "stats: tp_drops %u != 0", st.tp_drops);
+		if (st.tp_drops == 0)
+			error(1, 0, "stats: expected drops but tp_drops == 0");
+	} else {
+		if (st.tp_packets != 1)
+			error(1, 0, "stats: tp_packets %u != 1", st.tp_packets);
+
+		if (st.tp_drops != 0)
+			error(1, 0, "stats: tp_drops %u != 0", st.tp_drops);
+	}
 
 	/* verify clear on read */
 	memset(&st, 0xff, sizeof(st));
@@ -394,7 +422,12 @@ static void run_test(void)
 	fdr = setup_rx();
 	fds = setup_sniffer();
 
-	total_len = do_tx();
+	total_len = do_tx(cfg_drop);
+
+	if (cfg_drop) {
+		check_packet_stats(fds);
+		goto out;
+	}
 
 	/* BPF filter accepts only this length, vlan changes MAC */
 	if (cfg_payload_len == DATA_LEN && !cfg_use_vlan) {
@@ -405,6 +438,7 @@ static void run_test(void)
 
 	do_rx(fdr, cfg_payload_len, tbuf + total_len - cfg_payload_len);
 
+out:
 	if (close(fds))
 		error(1, errno, "close s");
 	if (close(fdr))
diff --git a/tools/testing/selftests/net/psock_snd.sh b/tools/testing/selftests/net/psock_snd.sh
index 1cbfeb5052ec..b6ef12fad5d5 100755
--- a/tools/testing/selftests/net/psock_snd.sh
+++ b/tools/testing/selftests/net/psock_snd.sh
@@ -92,4 +92,9 @@ echo "raw gso max size"
 echo "raw gso max size + 1 (expected to fail)"
 (! ./in_netns.sh ./psock_snd -v -c -g -l "${max_mss_exceeds}")
 
+# test drops statistics
+
+echo "test drops statistics"
+./in_netns.sh ./psock_snd -D
+
 echo "OK. All tests passed"
-- 
2.52.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [net-next 3/3] selftests/net: Test PACKET_AUXDATA
  2026-04-02 23:21 [net-next 0/3] Extend packet socket selftests Joe Damato
  2026-04-02 23:21 ` [net-next 1/3] selftests/net: Test PACKET_STATISTICS Joe Damato
  2026-04-02 23:21 ` [net-next 2/3] selftests/net: Test PACKET_STATISTICS drops Joe Damato
@ 2026-04-02 23:21 ` Joe Damato
  2026-04-03 15:37   ` Willem de Bruijn
  2 siblings, 1 reply; 7+ messages in thread
From: Joe Damato @ 2026-04-02 23:21 UTC (permalink / raw)
  To: netdev, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Simon Horman, Shuah Khan
  Cc: andrew+netdev, linux-kernel, willemb, Joe Damato, linux-kselftest

Extend the packet socket selftest, adding a recvmsg path, to test
PACKET_AUXDATA. Check basic attributes of tpacket_auxdata.

Signed-off-by: Joe Damato <joe@dama.to>
---
 tools/testing/selftests/net/psock_snd.c  | 57 ++++++++++++++++++++++--
 tools/testing/selftests/net/psock_snd.sh |  5 +++
 2 files changed, 59 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/net/psock_snd.c b/tools/testing/selftests/net/psock_snd.c
index 7bbce274b9f0..682e0afe364d 100644
--- a/tools/testing/selftests/net/psock_snd.c
+++ b/tools/testing/selftests/net/psock_snd.c
@@ -40,6 +40,7 @@ static bool	cfg_use_qdisc_bypass;
 static bool	cfg_use_vlan;
 static bool	cfg_use_vnet;
 static bool	cfg_drop;
+static bool	cfg_aux_data;
 
 static char	*cfg_ifname = "lo";
 static int	cfg_mtu	= 1500;
@@ -281,9 +282,26 @@ static int setup_rx(void)
 
 static void do_rx(int fd, int expected_len, char *expected)
 {
+	char cmsg_buf[1024] = {};
+	struct msghdr msg = {};
+	struct iovec iov[1];
 	int ret;
 
-	ret = recv(fd, rbuf, sizeof(rbuf), 0);
+	if (cfg_aux_data) {
+		iov[0].iov_base = rbuf;
+		iov[0].iov_len = sizeof(rbuf);
+
+		msg.msg_iov = iov;
+		msg.msg_iovlen = 1;
+
+		msg.msg_control = cmsg_buf;
+		msg.msg_controllen = sizeof(cmsg_buf);
+
+		ret = recvmsg(fd, &msg, 0);
+	} else {
+		ret = recv(fd, rbuf, sizeof(rbuf), 0);
+	}
+
 	if (ret == -1)
 		error(1, errno, "recv");
 	if (ret != expected_len)
@@ -292,6 +310,31 @@ static void do_rx(int fd, int expected_len, char *expected)
 	if (memcmp(rbuf, expected, ret))
 		error(1, 0, "recv: data mismatch");
 
+	if (cfg_aux_data) {
+		struct cmsghdr *cmsg = CMSG_FIRSTHDR(&msg);
+		struct tpacket_auxdata *adata;
+
+		if (!cmsg)
+			error(1, 0, "auxdata null");
+
+		if (cmsg->cmsg_level != SOL_PACKET)
+			error(1, 0, "cmsg_level != SOL_PACKET");
+
+		if (cmsg->cmsg_type != PACKET_AUXDATA)
+			error(1, 0, "cmsg_type != PACKET_AUXDATA");
+
+		adata = (struct tpacket_auxdata *)CMSG_DATA(cmsg);
+
+		if (adata->tp_net != ETH_HLEN)
+			error(1, 0, "cmsg tp_net != ETH_HLEN");
+
+		if (adata->tp_len != expected_len)
+			error(1, 0, "cmsg tp_len != %u", expected_len);
+
+		if (adata->tp_snaplen != expected_len)
+			error(1, 0, "cmsg tp_snaplen != %u", expected_len);
+	}
+
 	fprintf(stderr, "rx: %u\n", ret);
 }
 
@@ -312,6 +355,10 @@ static int setup_sniffer(void)
 		if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &one, sizeof(one)))
 			error(1, errno, "setsockopt SO_RCVBUF");
 
+	if (cfg_aux_data)
+		if (setsockopt(fd, SOL_PACKET, PACKET_AUXDATA, &one, sizeof(one)))
+			error(1, errno, "setsockopt PACKET_AUXDATA");
+
 	pair_udp_setfilter(fd);
 	do_bind(fd);
 
@@ -322,8 +369,11 @@ static void parse_opts(int argc, char **argv)
 {
 	int c;
 
-	while ((c = getopt(argc, argv, "bcCdDgl:qt:vV")) != -1) {
+	while ((c = getopt(argc, argv, "abcCdDgl:qt:vV")) != -1) {
 		switch (c) {
+		case 'a':
+			cfg_aux_data = true;
+			break;
 		case 'b':
 			cfg_use_bind = true;
 			break;
@@ -436,7 +486,8 @@ static void run_test(void)
 		check_packet_stats(fds);
 	}
 
-	do_rx(fdr, cfg_payload_len, tbuf + total_len - cfg_payload_len);
+	if (!cfg_aux_data)
+		do_rx(fdr, cfg_payload_len, tbuf + total_len - cfg_payload_len);
 
 out:
 	if (close(fds))
diff --git a/tools/testing/selftests/net/psock_snd.sh b/tools/testing/selftests/net/psock_snd.sh
index b6ef12fad5d5..111c9e2f0d21 100755
--- a/tools/testing/selftests/net/psock_snd.sh
+++ b/tools/testing/selftests/net/psock_snd.sh
@@ -97,4 +97,9 @@ echo "raw gso max size + 1 (expected to fail)"
 echo "test drops statistics"
 ./in_netns.sh ./psock_snd -D
 
+# test aux data
+
+echo "test aux data"
+./in_netns.sh ./psock_snd -a
+
 echo "OK. All tests passed"
-- 
2.52.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [net-next 2/3] selftests/net: Test PACKET_STATISTICS drops
  2026-04-02 23:21 ` [net-next 2/3] selftests/net: Test PACKET_STATISTICS drops Joe Damato
@ 2026-04-03 15:26   ` Willem de Bruijn
  2026-04-03 17:02     ` Joe Damato
  0 siblings, 1 reply; 7+ messages in thread
From: Willem de Bruijn @ 2026-04-03 15:26 UTC (permalink / raw)
  To: Joe Damato, netdev, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Simon Horman, Shuah Khan
  Cc: andrew+netdev, linux-kernel, willemb, Joe Damato, linux-kselftest

Joe Damato wrote:
> Extend psock_snd to test drops by setting a tiny receive buffer and
> sending a large burst of packets.
> 
> Signed-off-by: Joe Damato <joe@dama.to>
> ---
>  tools/testing/selftests/net/psock_snd.c  | 52 ++++++++++++++++++++----
>  tools/testing/selftests/net/psock_snd.sh |  5 +++
>  2 files changed, 48 insertions(+), 9 deletions(-)
> 
> diff --git a/tools/testing/selftests/net/psock_snd.c b/tools/testing/selftests/net/psock_snd.c
> index 5be481a3d2bd..7bbce274b9f0 100644
> --- a/tools/testing/selftests/net/psock_snd.c
> +++ b/tools/testing/selftests/net/psock_snd.c
> @@ -39,6 +39,7 @@ static bool	cfg_use_gso;
>  static bool	cfg_use_qdisc_bypass;
>  static bool	cfg_use_vlan;
>  static bool	cfg_use_vnet;
> +static bool	cfg_drop;
>  
>  static char	*cfg_ifname = "lo";
>  static int	cfg_mtu	= 1500;
> @@ -49,6 +50,8 @@ static uint16_t	cfg_port = 8000;
>  /* test sending up to max mtu + 1 */
>  #define TEST_SZ	(sizeof(struct virtio_net_hdr) + ETH_HLEN + ETH_MAX_MTU + 1)
>  
> +#define BURST_CNT (1000)
> +
>  static char tbuf[TEST_SZ], rbuf[TEST_SZ];
>  
>  static unsigned long add_csum_hword(const uint16_t *start, int num_u16)
> @@ -212,13 +215,14 @@ static void do_send(int fd, char *buf, int len)
>  	if (ret != len)
>  		error(1, 0, "write: %u %u", ret, len);
>  
> -	fprintf(stderr, "tx: %u\n", ret);
> +	if (!cfg_drop)
> +		fprintf(stderr, "tx: %u\n", ret);
>  }
>  
> -static int do_tx(void)
> +static int do_tx(bool burst)
>  {
>  	const int one = 1;
> -	int fd, len;
> +	int i, fd, len;
>  
>  	fd = socket(PF_PACKET, cfg_use_dgram ? SOCK_DGRAM : SOCK_RAW, 0);
>  	if (fd == -1)
> @@ -242,6 +246,10 @@ static int do_tx(void)
>  
>  	do_send(fd, tbuf, len);
>  
> +	if (burst)
> +		for (i = 0; i < BURST_CNT; i++)
> +			do_send(fd, tbuf, len);
> +
>  	if (close(fd))
>  		error(1, errno, "close t");
>  
> @@ -290,6 +298,7 @@ static void do_rx(int fd, int expected_len, char *expected)
>  static int setup_sniffer(void)
>  {
>  	struct timeval tv = { .tv_usec = 100 * 1000 };
> +	const int one = 1;
>  	int fd;
>  
>  	fd = socket(PF_PACKET, SOCK_RAW, 0);
> @@ -299,6 +308,10 @@ static int setup_sniffer(void)
>  	if (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)))
>  		error(1, errno, "setsockopt rcv timeout");
>  
> +	if (cfg_drop)
> +		if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &one, sizeof(one)))
> +			error(1, errno, "setsockopt SO_RCVBUF");
> +
>  	pair_udp_setfilter(fd);
>  	do_bind(fd);
>  
> @@ -309,7 +322,7 @@ static void parse_opts(int argc, char **argv)
>  {
>  	int c;
>  
> -	while ((c = getopt(argc, argv, "bcCdgl:qt:vV")) != -1) {
> +	while ((c = getopt(argc, argv, "bcCdDgl:qt:vV")) != -1) {
>  		switch (c) {
>  		case 'b':
>  			cfg_use_bind = true;
> @@ -323,6 +336,9 @@ static void parse_opts(int argc, char **argv)
>  		case 'd':
>  			cfg_use_dgram = true;
>  			break;
> +		case 'D':
> +			cfg_drop = true;
> +			break;
>  		case 'g':
>  			cfg_use_gso = true;
>  			break;
> @@ -367,11 +383,23 @@ static void check_packet_stats(int fd)
>  	if (getsockopt(fd, SOL_PACKET, PACKET_STATISTICS, &st, &len))
>  		error(1, errno, "getsockopt packet statistics");
>  
> -	if (st.tp_packets != 1)
> -		error(1, 0, "stats: tp_packets %u != 1", st.tp_packets);
> +	if (cfg_drop) {
> +		/* PACKET_STATISTICS reports all packets seen (including
> +		 * drops) in tp_packets
> +		 */
> +		if (st.tp_packets < st.tp_drops)
> +			error(1, 0, "stats: tp_packets %u < tp_drops %u",
> +			      st.tp_packets, st.tp_drops);
>  
> -	if (st.tp_drops != 0)
> -		error(1, 0, "stats: tp_drops %u != 0", st.tp_drops);
> +		if (st.tp_drops == 0)
> +			error(1, 0, "stats: expected drops but tp_drops == 0");
> +	} else {
> +		if (st.tp_packets != 1)
> +			error(1, 0, "stats: tp_packets %u != 1", st.tp_packets);
> +
> +		if (st.tp_drops != 0)
> +			error(1, 0, "stats: tp_drops %u != 0", st.tp_drops);
> +	}
>  
>  	/* verify clear on read */
>  	memset(&st, 0xff, sizeof(st));
> @@ -394,7 +422,12 @@ static void run_test(void)
>  	fdr = setup_rx();
>  	fds = setup_sniffer();
>  
> -	total_len = do_tx();
> +	total_len = do_tx(cfg_drop);

only if respinning: no need to pass global cfg_.. variables through
function arguments.

> +
> +	if (cfg_drop) {
> +		check_packet_stats(fds);
> +		goto out;
> +	}

can this not use the check_packet_stats added in the previous patch
right below?

>  
>  	/* BPF filter accepts only this length, vlan changes MAC */
>  	if (cfg_payload_len == DATA_LEN && !cfg_use_vlan) {
> @@ -405,6 +438,7 @@ static void run_test(void)
>  
>  	do_rx(fdr, cfg_payload_len, tbuf + total_len - cfg_payload_len);
>  
> +out:
>  	if (close(fds))
>  		error(1, errno, "close s");
>  	if (close(fdr))
> diff --git a/tools/testing/selftests/net/psock_snd.sh b/tools/testing/selftests/net/psock_snd.sh
> index 1cbfeb5052ec..b6ef12fad5d5 100755
> --- a/tools/testing/selftests/net/psock_snd.sh
> +++ b/tools/testing/selftests/net/psock_snd.sh
> @@ -92,4 +92,9 @@ echo "raw gso max size"
>  echo "raw gso max size + 1 (expected to fail)"
>  (! ./in_netns.sh ./psock_snd -v -c -g -l "${max_mss_exceeds}")
>  
> +# test drops statistics
> +
> +echo "test drops statistics"
> +./in_netns.sh ./psock_snd -D
> +
>  echo "OK. All tests passed"
> -- 
> 2.52.0
> 



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [net-next 3/3] selftests/net: Test PACKET_AUXDATA
  2026-04-02 23:21 ` [net-next 3/3] selftests/net: Test PACKET_AUXDATA Joe Damato
@ 2026-04-03 15:37   ` Willem de Bruijn
  0 siblings, 0 replies; 7+ messages in thread
From: Willem de Bruijn @ 2026-04-03 15:37 UTC (permalink / raw)
  To: Joe Damato, netdev, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Simon Horman, Shuah Khan
  Cc: andrew+netdev, linux-kernel, willemb, Joe Damato, linux-kselftest

Joe Damato wrote:
> Extend the packet socket selftest, adding a recvmsg path, to test
> PACKET_AUXDATA. Check basic attributes of tpacket_auxdata.
> 
> Signed-off-by: Joe Damato <joe@dama.to>
> ---
>  tools/testing/selftests/net/psock_snd.c  | 57 ++++++++++++++++++++++--
>  tools/testing/selftests/net/psock_snd.sh |  5 +++
>  2 files changed, 59 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/testing/selftests/net/psock_snd.c b/tools/testing/selftests/net/psock_snd.c
> index 7bbce274b9f0..682e0afe364d 100644
> --- a/tools/testing/selftests/net/psock_snd.c
> +++ b/tools/testing/selftests/net/psock_snd.c
> @@ -40,6 +40,7 @@ static bool	cfg_use_qdisc_bypass;
>  static bool	cfg_use_vlan;
>  static bool	cfg_use_vnet;
>  static bool	cfg_drop;
> +static bool	cfg_aux_data;
>  
>  static char	*cfg_ifname = "lo";
>  static int	cfg_mtu	= 1500;
> @@ -281,9 +282,26 @@ static int setup_rx(void)
>  
>  static void do_rx(int fd, int expected_len, char *expected)
>  {
> +	char cmsg_buf[1024] = {};
> +	struct msghdr msg = {};
> +	struct iovec iov[1];
>  	int ret;
>  
> -	ret = recv(fd, rbuf, sizeof(rbuf), 0);
> +	if (cfg_aux_data) {
> +		iov[0].iov_base = rbuf;
> +		iov[0].iov_len = sizeof(rbuf);
> +
> +		msg.msg_iov = iov;
> +		msg.msg_iovlen = 1;
> +
> +		msg.msg_control = cmsg_buf;
> +		msg.msg_controllen = sizeof(cmsg_buf);
> +
> +		ret = recvmsg(fd, &msg, 0);
> +	} else {
> +		ret = recv(fd, rbuf, sizeof(rbuf), 0);
> +	}
> +
>  	if (ret == -1)
>  		error(1, errno, "recv");
>  	if (ret != expected_len)
> @@ -292,6 +310,31 @@ static void do_rx(int fd, int expected_len, char *expected)
>  	if (memcmp(rbuf, expected, ret))
>  		error(1, 0, "recv: data mismatch");
>  
> +	if (cfg_aux_data) {
> +		struct cmsghdr *cmsg = CMSG_FIRSTHDR(&msg);
> +		struct tpacket_auxdata *adata;
> +
> +		if (!cmsg)
> +			error(1, 0, "auxdata null");
> +
> +		if (cmsg->cmsg_level != SOL_PACKET)
> +			error(1, 0, "cmsg_level != SOL_PACKET");
> +
> +		if (cmsg->cmsg_type != PACKET_AUXDATA)
> +			error(1, 0, "cmsg_type != PACKET_AUXDATA");
> +
> +		adata = (struct tpacket_auxdata *)CMSG_DATA(cmsg);
> +
> +		if (adata->tp_net != ETH_HLEN)
> +			error(1, 0, "cmsg tp_net != ETH_HLEN");
> +
> +		if (adata->tp_len != expected_len)
> +			error(1, 0, "cmsg tp_len != %u", expected_len);
> +
> +		if (adata->tp_snaplen != expected_len)
> +			error(1, 0, "cmsg tp_snaplen != %u", expected_len);
> +	}
> +
>  	fprintf(stderr, "rx: %u\n", ret);
>  }
>  
> @@ -312,6 +355,10 @@ static int setup_sniffer(void)
>  		if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &one, sizeof(one)))
>  			error(1, errno, "setsockopt SO_RCVBUF");
>  
> +	if (cfg_aux_data)
> +		if (setsockopt(fd, SOL_PACKET, PACKET_AUXDATA, &one, sizeof(one)))
> +			error(1, errno, "setsockopt PACKET_AUXDATA");
> +
>  	pair_udp_setfilter(fd);
>  	do_bind(fd);
>  
> @@ -322,8 +369,11 @@ static void parse_opts(int argc, char **argv)
>  {
>  	int c;
>  
> -	while ((c = getopt(argc, argv, "bcCdDgl:qt:vV")) != -1) {
> +	while ((c = getopt(argc, argv, "abcCdDgl:qt:vV")) != -1) {
>  		switch (c) {
> +		case 'a':
> +			cfg_aux_data = true;
> +			break;
>  		case 'b':
>  			cfg_use_bind = true;
>  			break;
> @@ -436,7 +486,8 @@ static void run_test(void)
>  		check_packet_stats(fds);
>  	}
>  
> -	do_rx(fdr, cfg_payload_len, tbuf + total_len - cfg_payload_len);
> +	if (!cfg_aux_data)
> +		do_rx(fdr, cfg_payload_len, tbuf + total_len - cfg_payload_len);

Slight preference to instead detect that this is a read not from a packet
socket and skip the cmsg processing inside do_rx as a result.

A roundabout way would be using getsockname. Simpler may be just to pass a new
boolean to do_rx is_psock or os.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [net-next 2/3] selftests/net: Test PACKET_STATISTICS drops
  2026-04-03 15:26   ` Willem de Bruijn
@ 2026-04-03 17:02     ` Joe Damato
  0 siblings, 0 replies; 7+ messages in thread
From: Joe Damato @ 2026-04-03 17:02 UTC (permalink / raw)
  To: Willem de Bruijn
  Cc: netdev, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Simon Horman, Shuah Khan, andrew+netdev,
	linux-kernel, willemb, linux-kselftest

On Fri, Apr 03, 2026 at 11:26:01AM -0400, Willem de Bruijn wrote:

[...]

> > +
> > +	if (cfg_drop) {
> > +		check_packet_stats(fds);
> > +		goto out;
> > +	}
> 
> can this not use the check_packet_stats added in the previous patch
> right below?

IIRC: no it can't because when I tested this the do_rx hits the error path in
the drop case which makes sense because of the tiny receive buffer.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-04-03 17:02 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-02 23:21 [net-next 0/3] Extend packet socket selftests Joe Damato
2026-04-02 23:21 ` [net-next 1/3] selftests/net: Test PACKET_STATISTICS Joe Damato
2026-04-02 23:21 ` [net-next 2/3] selftests/net: Test PACKET_STATISTICS drops Joe Damato
2026-04-03 15:26   ` Willem de Bruijn
2026-04-03 17:02     ` Joe Damato
2026-04-02 23:21 ` [net-next 3/3] selftests/net: Test PACKET_AUXDATA Joe Damato
2026-04-03 15:37   ` Willem de Bruijn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox