pasta: fix tcp port forwarding in auto mode

The logic in tcp_timer() was inverted. fwd_out should expose the host
ports in the ns. Therfore it must read the ports on the host and then
bind them in the netns. The same for fwd_in which checks ports in the
ns and then exposes them on the host.

Note that this only fixes tcp ports, udp does not seems to work at all
right now with the auto mode.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
Fixes: 1128fa03fe ("Improve types and names for port forwarding configuration")
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
Paul Holzinger 2023-03-20 19:10:34 +01:00 committed by Stefano Brivio
parent dd23496619
commit 418f75ac37

4
tcp.c
View file

@ -3308,14 +3308,14 @@ void tcp_timer(struct ctx *c, const struct timespec *ts)
struct tcp_port_detect_arg detect_arg = { c, 0 }; struct tcp_port_detect_arg detect_arg = { c, 0 };
struct tcp_port_rebind_arg rebind_arg = { c, 0 }; struct tcp_port_rebind_arg rebind_arg = { c, 0 };
if (c->tcp.fwd_in.mode == FWD_AUTO) { if (c->tcp.fwd_out.mode == FWD_AUTO) {
detect_arg.detect_in_ns = 0; detect_arg.detect_in_ns = 0;
tcp_port_detect(&detect_arg); tcp_port_detect(&detect_arg);
rebind_arg.bind_in_ns = 1; rebind_arg.bind_in_ns = 1;
NS_CALL(tcp_port_rebind, &rebind_arg); NS_CALL(tcp_port_rebind, &rebind_arg);
} }
if (c->tcp.fwd_out.mode == FWD_AUTO) { if (c->tcp.fwd_in.mode == FWD_AUTO) {
detect_arg.detect_in_ns = 1; detect_arg.detect_in_ns = 1;
NS_CALL(tcp_port_detect, &detect_arg); NS_CALL(tcp_port_detect, &detect_arg);
rebind_arg.bind_in_ns = 0; rebind_arg.bind_in_ns = 0;