diff options
author | David Gibson <david@gibson.dropbear.id.au> | 2023-11-03 13:23:00 +1100 |
---|---|---|
committer | Stefano Brivio <sbrivio@redhat.com> | 2023-11-07 09:53:24 +0100 |
commit | 180dbc957aa5f49f03ab04b65f826e32763ab5cd (patch) | |
tree | 611376252fe32e9dd38ebd5a912ac273abd0c5c6 /tcp.c | |
parent | 5a0485425bc9d43bc5228fe1b8b6286be83d3d1e (diff) | |
download | passt-180dbc957aa5f49f03ab04b65f826e32763ab5cd.tar passt-180dbc957aa5f49f03ab04b65f826e32763ab5cd.tar.gz passt-180dbc957aa5f49f03ab04b65f826e32763ab5cd.tar.bz2 passt-180dbc957aa5f49f03ab04b65f826e32763ab5cd.tar.lz passt-180dbc957aa5f49f03ab04b65f826e32763ab5cd.tar.xz passt-180dbc957aa5f49f03ab04b65f826e32763ab5cd.tar.zst passt-180dbc957aa5f49f03ab04b65f826e32763ab5cd.zip |
port_fwd: Don't NS_CALL get_bound_ports()
When we want to scan for bound ports in the namespace we use NS_CALL() to
run get_bound_ports() in the namespace. However, the only thing it
actually needed to be in the namespace for was to open the /proc/net file
it was scanning. Since we now always pre-open those, we no longer need
to switch to the namespace for the actual get_bound_ports() calls.
That in turn means that tcp_port_detect() doesn't need to run in the ns
either, and we can just replace it with inline calls to get_bound_ports().
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'tcp.c')
-rw-r--r-- | tcp.c | 38 |
1 files changed, 2 insertions, 36 deletions
@@ -3197,37 +3197,6 @@ int tcp_init(struct ctx *c) } /** - * struct tcp_port_detect_arg - Arguments for tcp_port_detect() - * @c: Execution context - * @detect_in_ns: Detect ports bound in namespace, not in init - */ -struct tcp_port_detect_arg { - struct ctx *c; - int detect_in_ns; -}; - -/** - * tcp_port_detect() - Detect ports bound in namespace or init - * @arg: See struct tcp_port_detect_arg - * - * Return: 0 - */ -static int tcp_port_detect(void *arg) -{ - struct tcp_port_detect_arg *a = (struct tcp_port_detect_arg *)arg; - - if (a->detect_in_ns) { - ns_enter(a->c); - - get_bound_ports(a->c, 1, IPPROTO_TCP); - } else { - get_bound_ports(a->c, 0, IPPROTO_TCP); - } - - return 0; -} - -/** * struct tcp_port_rebind_arg - Arguments for tcp_port_rebind() * @c: Execution context * @bind_in_ns: Rebind ports in namespace, not in init @@ -3315,19 +3284,16 @@ void tcp_timer(struct ctx *c, const struct timespec *ts) (void)ts; if (c->mode == MODE_PASTA) { - struct tcp_port_detect_arg detect_arg = { c, 0 }; struct tcp_port_rebind_arg rebind_arg = { c, 0 }; if (c->tcp.fwd_out.mode == FWD_AUTO) { - detect_arg.detect_in_ns = 0; - tcp_port_detect(&detect_arg); + get_bound_ports(c, 0, IPPROTO_TCP); rebind_arg.bind_in_ns = 1; NS_CALL(tcp_port_rebind, &rebind_arg); } if (c->tcp.fwd_in.mode == FWD_AUTO) { - detect_arg.detect_in_ns = 1; - NS_CALL(tcp_port_detect, &detect_arg); + get_bound_ports(c, 1, IPPROTO_TCP); rebind_arg.bind_in_ns = 0; tcp_port_rebind(&rebind_arg); } |