mirror of
https://github.com/torvalds/linux.git
synced 2026-09-22 12:44:03 +02:00
selftests/net: Test PACKET_STATISTICS
Update the existing packet socket test to include a test for the sockopt PACKET_STATISTICS. Signed-off-by: Joe Damato <joe@dama.to> Reviewed-by: Willem de Bruijn <willemb@google.com> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
parent
24d0af194b
commit
d6587d0c0f
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user