From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 77C7E5A026D for ; Wed, 15 Nov 2023 06:25:43 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1700025940; bh=iRc/oB0Zdy5sB4ooTUdgZ/ijCgXg5IYDCEsF+xs4J+E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ve0vsYqjKXwrwz1H5eLn1VsFduKA8ewcZXhYn7TjjRw+2vsYrrbX9ThsCK5PMgHbx 7n18oh33OiEQ3EcGSLzwxXnulpAqxOrzoivjAhY9ToP4j46NOt4+av6SehClF0Ue2W hrAjJfYWNNH3KbZODS2HnUInx9Vp5/CMw9YwRbxo= Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4SVWpX2Nvkz4xFR; Wed, 15 Nov 2023 16:25:40 +1100 (AEDT) From: David Gibson To: Stefano Brivio , passt-dev@passt.top Subject: [PATCH 2/3] tcp: Simplify away tcp_port_rebind() Date: Wed, 15 Nov 2023 16:25:33 +1100 Message-ID: <20231115052534.1826261-3-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231115052534.1826261-1-david@gibson.dropbear.id.au> References: <20231115052534.1826261-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: ZD7E5T3WXOJRUG6CGUEO33QDKHSXFZGU X-Message-ID-Hash: ZD7E5T3WXOJRUG6CGUEO33QDKHSXFZGU X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: David Gibson X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 --- tcp.c | 41 ++++++++++++----------------------------- 1 file changed, 12 insertions(+), 29 deletions(-) diff --git a/tcp.c b/tcp.c index 6bc040c..b933042 100644 --- a/tcp.c +++ b/tcp.c @@ -3156,13 +3156,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; @@ -3199,32 +3199,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; } @@ -3241,18 +3228,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); } } -- 2.41.0