Skip to content

Commit cb2fba0

Browse files
Richard Palethorpemetan-ucw
authored andcommitted
pty04: Avoid receiving packets from all interfaces
Raw sockets receive all packets from all interfaces as soon as they are created. They don't need to be bound to one or more interfaces like I thought. This creates the socket with a NULL packet type which appears to be unused in the Linux kernel and receives no packets. The protocol is then changed to ETH_P_ALL when binding to the netdevice we are interested in. I assume it is impossible for a packet to have zero for its packet type. Most likely using ETH_P_LOOP would have been OK too, but I suppose that is really used by some hardware. This also fixes various other problems that have been observed with this test. Such as memory allocation failures. Signed-off-by: Richard Palethorpe <rpalethorpe@suse.com> Cc: Jan Stancek <jstancek@redhat.com> Acked-by: Cyril Hrubis <chrubis@suse.cz> Tested-by: Jan Stancek <jstancek@redhat.com>
1 parent 04d0e52 commit cb2fba0

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

testcases/kernel/pty/pty04.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ static void open_netdev(const struct ldisc_info *ldisc)
206206
SAFE_IOCTL(pts, SIOCGIFNAME, ifreq.ifr_name);
207207
tst_res(TINFO, "Netdev is %s", ifreq.ifr_name);
208208

209-
sk = SAFE_SOCKET(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
209+
sk = SAFE_SOCKET(PF_PACKET, SOCK_RAW, 0);
210210

211211
ifreq.ifr_mtu = ldisc->mtu;
212212
if (ioctl(sk, SIOCSIFMTU, &ifreq))

0 commit comments

Comments
 (0)