Skip to content

Commit c1878f7

Browse files
sowminivdavem330
authored andcommitted
tools: psock_tpacket: block Rx until socket filter has been added and socket has been bound to loopback.
Packets from any/all interfaces may be queued up on the PF_PACKET socket before it is bound to the loopback interface by psock_tpacket, and when these are passed up by the kernel, they could interfere with the Rx tests. Avoid interference from spurious packet by blocking Rx until the socket filter has been set up, and the packet has been bound to the desired (lo) interface. The effective sequence is socket(PF_PACKET, SOCK_RAW, 0); set up ring Invoke SO_ATTACH_FILTER bind to sll_protocol set to ETH_P_ALL, sll_ifindex for lo After this sequence, the only packets that will be passed up are those received on loopback that pass the attached filter. Signed-off-by: Sowmini Varadhan <sowmini.varadhan@oracle.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent ad02c4f commit c1878f7

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

tools/testing/selftests/net/psock_tpacket.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ static unsigned int total_packets, total_bytes;
110110

111111
static int pfsocket(int ver)
112112
{
113-
int ret, sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
113+
int ret, sock = socket(PF_PACKET, SOCK_RAW, 0);
114114
if (sock == -1) {
115115
perror("socket");
116116
exit(1);
@@ -239,7 +239,6 @@ static void walk_v1_v2_rx(int sock, struct ring *ring)
239239
bug_on(ring->type != PACKET_RX_RING);
240240

241241
pair_udp_open(udp_sock, PORT_BASE);
242-
pair_udp_setfilter(sock);
243242

244243
memset(&pfd, 0, sizeof(pfd));
245244
pfd.fd = sock;
@@ -601,7 +600,6 @@ static void walk_v3_rx(int sock, struct ring *ring)
601600
bug_on(ring->type != PACKET_RX_RING);
602601

603602
pair_udp_open(udp_sock, PORT_BASE);
604-
pair_udp_setfilter(sock);
605603

606604
memset(&pfd, 0, sizeof(pfd));
607605
pfd.fd = sock;
@@ -741,6 +739,8 @@ static void bind_ring(int sock, struct ring *ring)
741739
{
742740
int ret;
743741

742+
pair_udp_setfilter(sock);
743+
744744
ring->ll.sll_family = PF_PACKET;
745745
ring->ll.sll_protocol = htons(ETH_P_ALL);
746746
ring->ll.sll_ifindex = if_nametoindex("lo");

0 commit comments

Comments
 (0)