1
0
mirror of https://passt.top/passt synced 2024-06-27 21:42:42 +00:00

udp: udp_sock_init_ns() partially duplicats udp_port_rebind_outbound()

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@gibson.dropbear.id.au>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
David Gibson 2024-02-12 17:06:58 +11:00 committed by Stefano Brivio
parent 96ad5c5acd
commit 927cb84fff

73
udp.c
View File

@ -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;
}