From d0dd0242a69f4ae5be4f46030bf321eb6867b2f8 Mon Sep 17 00:00:00 2001 From: Stefano Brivio Date: Mon, 10 Oct 2022 19:00:43 +0200 Subject: tcp, tcp_splice: Fix port remapping for inbound, spliced connections In pasta mode, when we receive a new inbound connection, we need to select a socket that was created in the namespace to proceed and connect() it to its final destination. The existing condition might pick a wrong socket, though, if the destination port is remapped, because we'll check the bitmap of inbound ports using the remapped port (stored in the epoll reference) as index, and not the original port. Instead of using the port bitmap for this purpose, store this information in the epoll reference itself, by adding a new 'outbound' bit, that's set if the listening socket was created the namespace, and unset otherwise. Then, use this bit to pick a socket on the right side. Suggested-by: David Gibson Fixes: 33482d5bf293 ("passt: Add PASTA mode, major rework") Signed-off-by: Stefano Brivio Reviewed-by: David Gibson --- tcp.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'tcp.c') diff --git a/tcp.c b/tcp.c index 63153b6..0d4ce57 100644 --- a/tcp.c +++ b/tcp.c @@ -3084,15 +3084,14 @@ void tcp_sock_handler(struct ctx *c, union epoll_ref ref, uint32_t events, void tcp_sock_init(const struct ctx *c, int ns, sa_family_t af, const void *addr, const char *ifname, in_port_t port) { - union tcp_epoll_ref tref = { .tcp.listen = 1 }; + union tcp_epoll_ref tref = { .tcp.listen = 1, .tcp.outbound = ns }; const void *bind_addr; int s; - if (ns) { + if (ns) tref.tcp.index = (in_port_t)(port + c->tcp.fwd_out.delta[port]); - } else { + else tref.tcp.index = (in_port_t)(port + c->tcp.fwd_in.delta[port]); - } if (af == AF_INET || af == AF_UNSPEC) { if (!addr && c->mode == MODE_PASTA) -- cgit v1.2.3