aboutgitcodebugslistschat
path: root/udp.c
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2022-11-30 15:13:07 +1100
committerStefano Brivio <sbrivio@redhat.com>2022-12-06 07:41:35 +0100
commitc277c6dd7d90e6f83284ecf60b94c4693dd89322 (patch)
tree45e6619db027ecf929a61e970a7f382cec284357 /udp.c
parentd9394eb9b7d84b90169f32242611009735996a75 (diff)
downloadpasst-c277c6dd7d90e6f83284ecf60b94c4693dd89322.tar
passt-c277c6dd7d90e6f83284ecf60b94c4693dd89322.tar.gz
passt-c277c6dd7d90e6f83284ecf60b94c4693dd89322.tar.bz2
passt-c277c6dd7d90e6f83284ecf60b94c4693dd89322.tar.lz
passt-c277c6dd7d90e6f83284ecf60b94c4693dd89322.tar.xz
passt-c277c6dd7d90e6f83284ecf60b94c4693dd89322.tar.zst
passt-c277c6dd7d90e6f83284ecf60b94c4693dd89322.zip
udp: Don't create double sockets for -U port
For each IP version udp_socket() has 3 possible calls to sock_l4(). One is for the "non-spliced" bound socket in the init namespace, one for the "spliced" bound socket in the init namespace and one for the "spliced" bound socket in the pasta namespace. However when this is called to create a socket in the pasta namspeace there is a logic error which causes it to take the path for the init side spliced socket as well as the ns socket. This essentially tries to create two identical sockets on the ns side. Unsurprisingly the second bind() call fails according to strace. Correct this to only attempt to open one socket within the ns. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'udp.c')
-rw-r--r--udp.c32
1 files changed, 14 insertions, 18 deletions
diff --git a/udp.c b/udp.c
index 8c5deee..3fa74a1 100644
--- a/udp.c
+++ b/udp.c
@@ -1090,17 +1090,15 @@ void udp_sock_init(const struct ctx *c, int ns, sa_family_t af,
port, uref.u32);
udp_tap_map[V4][uref.udp.port].sock = s;
- }
-
- if (c->mode == MODE_PASTA) {
- bind_addr = &(uint32_t){ htonl(INADDR_LOOPBACK) };
- uref.udp.splice = uref.udp.orig = true;
- sock_l4(c, AF_INET, IPPROTO_UDP, bind_addr, ifname,
- port, uref.u32);
- }
+ if (c->mode == MODE_PASTA) {
+ bind_addr = &(uint32_t){ htonl(INADDR_LOOPBACK) };
+ uref.udp.splice = uref.udp.orig = true;
- if (ns) {
+ sock_l4(c, AF_INET, IPPROTO_UDP, bind_addr, ifname,
+ port, uref.u32);
+ }
+ } else {
uref.udp.splice = uref.udp.orig = uref.udp.ns = true;
bind_addr = &(uint32_t){ htonl(INADDR_LOOPBACK) };
@@ -1124,17 +1122,15 @@ void udp_sock_init(const struct ctx *c, int ns, sa_family_t af,
port, uref.u32);
udp_tap_map[V6][uref.udp.port].sock = s;
- }
-
- if (c->mode == MODE_PASTA) {
- bind_addr = &in6addr_loopback;
- uref.udp.splice = uref.udp.orig = true;
- sock_l4(c, AF_INET6, IPPROTO_UDP, bind_addr, ifname,
- port, uref.u32);
- }
+ if (c->mode == MODE_PASTA) {
+ bind_addr = &in6addr_loopback;
+ uref.udp.splice = uref.udp.orig = true;
- if (ns) {
+ sock_l4(c, AF_INET6, IPPROTO_UDP, bind_addr, ifname,
+ port, uref.u32);
+ }
+ } else {
bind_addr = &in6addr_loopback;
uref.udp.splice = uref.udp.orig = uref.udp.ns = true;