From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id E71285A0276 for ; Mon, 12 Feb 2024 07:07:10 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1707718024; bh=ORiLT7OnQN73OhmWJAVuXVSIv8m/0TlFsW2kpAD2zjM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YHPeGauZSv+P37OUvgyDckmtRJ/gPmmfLKDN9VZwUPPeZn4Ef6Ly24izYKcBoVvB9 jKhAcewxbnKLco+6P6pdWYIcUPUCIzW1qRmqsJjYoUGT+R2YXdoYqU3F1iQVXePFk+ v7ooWrd03gIH93lIkTJkxnKn7gfiWb2IQrgWjN7Y+MQw83aY6aeKk/WP9+Od1UQshO Oje55grGYT7KZDUixzMKiV1Y4gq+OV3sGvCahPPOKMQtS7ftRAspeJPYL+SZB06H1G bIYvvGiyNpvcqvXuC06tKwNFnHZKKtfcBcvStgJqzOm2aQNYjUivKasIxu83i5xyYB 62q3kPNZprB5g== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4TYDWD37xRz4x1m; Mon, 12 Feb 2024 17:07:04 +1100 (AEDT) From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH 2/2] udp: udp_sock_init_ns() partially duplicats udp_port_rebind_outbound() Date: Mon, 12 Feb 2024 17:06:58 +1100 Message-ID: <20240212060658.857608-3-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240212060658.857608-1-david@gibson.dropbear.id.au> References: <20240212060658.857608-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: VTXQA7UEUJEETARQ4RAHXLGLCNIQDBNM X-Message-ID-Hash: VTXQA7UEUJEETARQ4RAHXLGLCNIQDBNM 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: Usually automatically forwarded UDP outbound ports are set up by udp_port_rebind_outbound() called from udp_timer(). However, the very first time they're created and bound is by udp_sock_init_ns() called from udp_init(). udp_sock_init_ns() is essentially an unnecessary cut down version of udp_port_rebind_outbound(), so we can jusat remove it. Doing so does require moving udp_init() below udp_port_rebind_outbound()'s definition. Signed-off-by: David Gibson --- udp.c | 73 ++++++++++++++++++++--------------------------------------- 1 file changed, 25 insertions(+), 48 deletions(-) diff --git a/udp.c b/udp.c index b240185e..933f24b8 100644 --- a/udp.c +++ b/udp.c @@ -1041,29 +1041,6 @@ int udp_sock_init(const struct ctx *c, int ns, sa_family_t af, return r4 < 0 ? r4 : r6; } -/** - * udp_sock_init_ns() - Bind sockets in namespace for outbound connections - * @arg: Execution context - * - * Return: 0 - */ -int udp_sock_init_ns(void *arg) -{ - const struct ctx *c = (const struct ctx *)arg; - unsigned dst; - - ns_enter(c); - - for (dst = 0; dst < NUM_PORTS; dst++) { - if (!bitmap_isset(c->udp.fwd_out.f.map, dst)) - continue; - - udp_sock_init(c, 1, AF_UNSPEC, NULL, NULL, dst); - } - - return 0; -} - /** * udp_splice_iov_init() - Set up buffers and descriptors for recvmmsg/sendmmsg */ @@ -1090,31 +1067,6 @@ static void udp_splice_iov_init(void) } } -/** - * udp_init() - Initialise per-socket data, and sockets in namespace - * @c: Execution context - * - * Return: 0 - */ -int udp_init(struct ctx *c) -{ - if (c->ifi4) - udp_sock4_iov_init(c); - - if (c->ifi6) - udp_sock6_iov_init(c); - - udp_invert_portmap(&c->udp.fwd_in); - udp_invert_portmap(&c->udp.fwd_out); - - if (c->mode == MODE_PASTA) { - udp_splice_iov_init(); - NS_CALL(udp_sock_init_ns, c); - } - - return 0; -} - /** * udp_timer_one() - Handler for timed events on one port * @c: Execution context @@ -1272,3 +1224,28 @@ v6: goto v6; } } + +/** + * udp_init() - Initialise per-socket data, and sockets in namespace + * @c: Execution context + * + * Return: 0 + */ +int udp_init(struct ctx *c) +{ + if (c->ifi4) + udp_sock4_iov_init(c); + + if (c->ifi6) + udp_sock6_iov_init(c); + + udp_invert_portmap(&c->udp.fwd_in); + udp_invert_portmap(&c->udp.fwd_out); + + if (c->mode == MODE_PASTA) { + udp_splice_iov_init(); + NS_CALL(udp_port_rebind_outbound, c); + } + + return 0; +} -- 2.43.0