From 4ccdeecb744d48e0c70386d561d34ced860bfacd Mon Sep 17 00:00:00 2001 From: David Gibson Date: Wed, 15 Nov 2023 16:25:33 +1100 Subject: tcp: Simplify away tcp_port_rebind() tcp_port_rebind() is desgined to be called from NS_CALL() and has two disjoint cases: one where it enters the namespace (outbound forwards) and one where it doesn't (inbound forwards). We only actually need the NS_CALL() framing for the outbound case, for inbound we can just call tcp_port_do_rebind() directly. So simplify tcp_port_rebind() to tcp_port_rebind_outbound(), allowing us to eliminate an awkward parameters structure. With that done we can safely rename tcp_port_do_rebind() to tcp_port_rebind() for brevity. Signed-off-by: David Gibson Signed-off-by: Stefano Brivio --- tcp.c | 41 ++++++++++++----------------------------- 1 file changed, 12 insertions(+), 29 deletions(-) diff --git a/tcp.c b/tcp.c index cb23204..a0e577d 100644 --- a/tcp.c +++ b/tcp.c @@ -3151,13 +3151,13 @@ int tcp_init(struct ctx *c) } /** - * tcp_port_do_rebind() - Rebind ports to match forward maps + * tcp_port_rebind() - Rebind ports to match forward maps * @c: Execution context * @outbound: True to remap outbound forwards, otherwise inbound * * Must be called in namespace context if @outbound is true. */ -static void tcp_port_do_rebind(struct ctx *c, bool outbound) +static void tcp_port_rebind(struct ctx *c, bool outbound) { const uint8_t *fmap = outbound ? c->tcp.fwd_out.map : c->tcp.fwd_in.map; const uint8_t *rmap = outbound ? c->tcp.fwd_in.map : c->tcp.fwd_out.map; @@ -3194,32 +3194,19 @@ static void tcp_port_do_rebind(struct ctx *c, bool outbound) } /** - * struct tcp_port_rebind_arg - Arguments for tcp_port_rebind() - * @c: Execution context - * @bind_in_ns: Rebind ports in namespace, not in init - */ -struct tcp_port_rebind_arg { - struct ctx *c; - int bind_in_ns; -}; - -/** - * tcp_port_rebind() - Rebind ports in namespace or init - * @arg: See struct tcp_port_rebind_arg + * tcp_port_rebind_outbound() - Rebind ports in namespace + * @arg: Execution context + * + * Called with NS_CALL() * * Return: 0 */ -static int tcp_port_rebind(void *arg) +static int tcp_port_rebind_outbound(void *arg) { - struct tcp_port_rebind_arg *a = (struct tcp_port_rebind_arg *)arg; - - if (a->bind_in_ns) { - ns_enter(a->c); + struct ctx *c = (struct ctx *)arg; - tcp_port_do_rebind(a->c, true); - } else { - tcp_port_do_rebind(a->c, false); - } + ns_enter(c); + tcp_port_rebind(c, true); return 0; } @@ -3236,18 +3223,14 @@ void tcp_timer(struct ctx *c, const struct timespec *ts) (void)ts; if (c->mode == MODE_PASTA) { - struct tcp_port_rebind_arg rebind_arg = { c, 0 }; - if (c->tcp.fwd_out.mode == FWD_AUTO) { port_fwd_scan_tcp(&c->tcp.fwd_out, &c->tcp.fwd_in); - rebind_arg.bind_in_ns = 1; - NS_CALL(tcp_port_rebind, &rebind_arg); + NS_CALL(tcp_port_rebind_outbound, c); } if (c->tcp.fwd_in.mode == FWD_AUTO) { port_fwd_scan_tcp(&c->tcp.fwd_in, &c->tcp.fwd_out); - rebind_arg.bind_in_ns = 0; - tcp_port_rebind(&rebind_arg); + tcp_port_rebind(c, false); } } -- cgit v1.2.3