diff options
author | David Gibson <david@gibson.dropbear.id.au> | 2024-09-20 14:12:41 +1000 |
---|---|---|
committer | Stefano Brivio <sbrivio@redhat.com> | 2024-09-25 19:03:15 +0200 |
commit | 204e77cd11b2df720c9acd35d562e1ed868304b4 (patch) | |
tree | ce3581d818e00d0662fde4bdb146b1e7ae1c260a | |
parent | 8f8c4d27eb2e023fd80986d8fdf8a68b37e3877e (diff) | |
download | passt-204e77cd11b2df720c9acd35d562e1ed868304b4.tar passt-204e77cd11b2df720c9acd35d562e1ed868304b4.tar.gz passt-204e77cd11b2df720c9acd35d562e1ed868304b4.tar.bz2 passt-204e77cd11b2df720c9acd35d562e1ed868304b4.tar.lz passt-204e77cd11b2df720c9acd35d562e1ed868304b4.tar.xz passt-204e77cd11b2df720c9acd35d562e1ed868304b4.tar.zst passt-204e77cd11b2df720c9acd35d562e1ed868304b4.zip |
udp: Don't attempt to get dual-stack sockets in nonsensical cases
To save some kernel memory we try to use "dual stack" sockets (that listen
to both IPv4 and IPv6 traffic) when possible. However udp_sock_init()
attempts to do this in some cases that can't work. Specifically we can
only do this when listening on any address. That's never true for the
ns (splicing) case, because we always listen on loopback. For the !ns
case and AF_UNSPEC case, addr should always be NULL, but add an assert to
verify.
This is harmless: if addr is non-NULL, sock_l4() will just fail and we'll
fall back to the other path. But, it's messy and makes some upcoming
changes harder, so avoid attempting this in cases we know can't work.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
-rw-r--r-- | udp.c | 19 |
1 files changed, 7 insertions, 12 deletions
@@ -803,21 +803,16 @@ int udp_sock_init(const struct ctx *c, int ns, sa_family_t af, ASSERT(!c->no_udp); - if (af == AF_UNSPEC && c->ifi4 && c->ifi6) { + if (af == AF_UNSPEC && c->ifi4 && c->ifi6 && !ns) { int s; + ASSERT(!addr); + /* Attempt to get a dual stack socket */ - if (!ns) { - s = sock_l4(c, AF_UNSPEC, EPOLL_TYPE_UDP_LISTEN, - addr, ifname, port, uref.u32); - udp_splice_init[V4][port] = s < 0 ? -1 : s; - udp_splice_init[V6][port] = s < 0 ? -1 : s; - } else { - s = sock_l4(c, AF_UNSPEC, EPOLL_TYPE_UDP_LISTEN, - &in4addr_loopback, ifname, port, uref.u32); - udp_splice_ns[V4][port] = s < 0 ? -1 : s; - udp_splice_ns[V6][port] = s < 0 ? -1 : s; - } + s = sock_l4(c, AF_UNSPEC, EPOLL_TYPE_UDP_LISTEN, + NULL, ifname, port, uref.u32); + udp_splice_init[V4][port] = s < 0 ? -1 : s; + udp_splice_init[V6][port] = s < 0 ? -1 : s; if (IN_INTERVAL(0, FD_REF_MAX, s)) return 0; } |