util: Correct sock_l4() binding for link local addresses

When binding an IPv6 socket in sock_l4() we need to supply a scope id
if the address is link-local.  We check for this by comparing the
given address to c->ip6.addr_ll.  This is correct only by accident:
while c->ip6.addr_ll is typically set to the host interface's link
local address, the actual purpose of it is to provide a link local
address for passt's private use on the tap interface.

Instead set the scope id for any link-local address we're binding to.
We're going to need something and this is what makes sense for sockets
on the host.  It doesn't make sense for PIF_SPLICE sockets, but those
should always have loopback, not link-local addresses.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
David Gibson 2024-08-21 14:20:08 +10:00 committed by Stefano Brivio
parent 57532f1ded
commit c9f0ec3227

3
util.c
View file

@ -199,8 +199,7 @@ int sock_l4(const struct ctx *c, sa_family_t af, enum epoll_type type,
if (bind_addr) { if (bind_addr) {
addr6.sin6_addr = *(struct in6_addr *)bind_addr; addr6.sin6_addr = *(struct in6_addr *)bind_addr;
if (!memcmp(bind_addr, &c->ip6.addr_ll, if (IN6_IS_ADDR_LINKLOCAL(bind_addr))
sizeof(c->ip6.addr_ll)))
addr6.sin6_scope_id = c->ifi6; addr6.sin6_scope_id = c->ifi6;
} }
return sock_l4_sa(c, type, &addr6, sizeof(addr6), ifname, return sock_l4_sa(c, type, &addr6, sizeof(addr6), ifname,