From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202408 header.b=GICNzKih; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 4B8805A004C for ; Fri, 20 Sep 2024 06:12:50 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202408; t=1726805566; bh=w2Xa7DreK0Jw8mYhGppa7r5pxRdxvUuIIOc61zb6ZoU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GICNzKihtgXiSVydmq1slRzGzNn6OP/48xvr6PBu9vIp0937WU6hLa1VFFFVJOViZ viTL0WzIOU91LlsL0kgBrgu7rXH4qRcW3dg8585sLAxrDBmVQewrRST25vs5bm1d5W 0elsxZo9mkPrFA9u7cMFEhqo/TbtR4Ng9YKMgNHGbIN+ssbq33b35auWc8DDyw8iXP KK5L4tGc1bEEWQaH5Q1MBFK+kh+3KZ7t+swpLUh/0KhtDQiAVM2l6nryO3dtDBhhZj rYevbsLrX+pyaAHF1RwwD/d2rltoRb6Fcu9NHgyFVqFdESJEDxNxd+ol5F/d8+E45f rH8hH/3xy0ujQ== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4X8zWL46FPz4x6k; Fri, 20 Sep 2024 14:12:46 +1000 (AEST) From: David Gibson To: Stefano Brivio , passt-dev@passt.top Subject: [PATCH 1/4] udp: Don't attempt to get dual-stack sockets in nonsensical cases Date: Fri, 20 Sep 2024 14:12:41 +1000 Message-ID: <20240920041244.593192-2-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20240920041244.593192-1-david@gibson.dropbear.id.au> References: <20240920041244.593192-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: C56BZ5EYU7M76HTHB6ZLOV5LAFKXFA27 X-Message-ID-Hash: C56BZ5EYU7M76HTHB6ZLOV5LAFKXFA27 X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: David Gibson X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 --- udp.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/udp.c b/udp.c index 7b283138..8cea80cd 100644 --- a/udp.c +++ b/udp.c @@ -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; } -- 2.46.1