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 <david(a)gibson.dropbear.id.au> --- 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