selftests/net: psock: Generalize psock bind

Generalize packet socket binding so that types other than ETH_P_IP can
be used.

Signed-off-by: Joe Damato <joe@dama.to>
Reviewed-by: Willem de Bruijn <willemb@google.com>
Link: https://patch.msgid.link/20260728160935.4128982-2-joe@dama.to
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Joe Damato 2026-07-28 09:09:26 -07:00 committed by Jakub Kicinski
parent bb3fed50cb
commit 0982666c1b

View File

@ -171,12 +171,12 @@ static int build_packet(int payload_len)
return off + payload_len;
}
static void do_bind(int fd)
static void do_bind_proto(int fd, uint16_t proto)
{
struct sockaddr_ll laddr = {0};
laddr.sll_family = AF_PACKET;
laddr.sll_protocol = htons(ETH_P_IP);
laddr.sll_protocol = htons(proto);
laddr.sll_ifindex = if_nametoindex(cfg_ifname);
if (!laddr.sll_ifindex)
error(1, errno, "if_nametoindex");
@ -185,6 +185,11 @@ static void do_bind(int fd)
error(1, errno, "bind");
}
static void do_bind(int fd)
{
do_bind_proto(fd, ETH_P_IP);
}
static void do_send(int fd, char *buf, int len)
{
int ret;