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 290895A005E for ; Tue, 14 Feb 2023 00:48:27 +0100 (CET) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4PG1Hr6k6Qz4x5Y; Tue, 14 Feb 2023 10:48:24 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1676332104; bh=T/Gm0ocKcSgxLht8qP4CjKPAOGcInU4tH+GpPrZlab4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IMNndRlouPRrzkD9hfRFcG3VSec8m6uwn6bvWyQdzVvL8977RvqydiQWwDFrb54y0 MkWFupbDW8KhoDA9S7jkDtFRKBnzfw5O29Hn/abxADrenwi2Ulu7x39AukJepXnpI5 KyNn64tUb3VEvegXdDOTfj/NxPsP1xCfno0TvYYo= From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH v2 2/5] tcp: Split init and ns cases for tcp_sock_refill() Date: Tue, 14 Feb 2023 10:48:20 +1100 Message-Id: <20230213234823.749379-3-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230213234823.749379-1-david@gibson.dropbear.id.au> References: <20230213234823.749379-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: 3DUER72FIHAN6VPJU6VR476O35P4A3OJ X-Message-ID-Hash: 3DUER72FIHAN6VPJU6VR476O35P4A3OJ 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.3 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: With the creation of the tcp_sock_refill_pool() helper, the ns==true and ns==false paths for tcp_sock_refill() now have almost nothing in common. Split the two versions into tcp_sock_refill_init() and tcp_sock_refill_ns() functions. Signed-off-by: David Gibson --- tcp.c | 53 +++++++++++++++++++++-------------------------------- 1 file changed, 21 insertions(+), 32 deletions(-) diff --git a/tcp.c b/tcp.c index 5d13244..1d1b4ee 100644 --- a/tcp.c +++ b/tcp.c @@ -3038,40 +3038,33 @@ static void tcp_sock_refill_pool(const struct ctx *c, int pool[], int af) } /** - * struct tcp_sock_refill_arg - Arguments for tcp_sock_refill() + * tcp_sock_refill_init() - Refill pools of pre-opened sockets in init ns * @c: Execution context - * @ns: Set to refill pool of sockets created in namespace */ -struct tcp_sock_refill_arg { - struct ctx *c; - int ns; -}; +static void tcp_sock_refill_init(const struct ctx *c) +{ + if (c->ifi4) + tcp_sock_refill_pool(c, init_sock_pool4, AF_INET); + if (c->ifi6) + tcp_sock_refill_pool(c, init_sock_pool6, AF_INET6); +} /** - * tcp_sock_refill() - Refill pool of pre-opened sockets - * @arg: See @tcp_sock_refill_arg + * tcp_sock_refill_ns() - Refill pools of pre-opened sockets in namespace + * @arg: Execution context cast to void * * * Return: 0 */ -static int tcp_sock_refill(void *arg) +static int tcp_sock_refill_ns(void *arg) { - struct tcp_sock_refill_arg *a = (struct tcp_sock_refill_arg *)arg; - int *p4, *p6; + const struct ctx *c = (const struct ctx *)arg; - if (a->ns) { - ns_enter(a->c); - p4 = ns_sock_pool4; - p6 = ns_sock_pool6; - } else { - p4 = init_sock_pool4; - p6 = init_sock_pool6; - } - - if (a->c->ifi4) - tcp_sock_refill_pool(a->c, p4, AF_INET); + ns_enter(c); - if (a->c->ifi6) - tcp_sock_refill_pool(a->c, p6, AF_INET6); + if (c->ifi4) + tcp_sock_refill_pool(c, ns_sock_pool4, AF_INET); + if (c->ifi6) + tcp_sock_refill_pool(c, ns_sock_pool6, AF_INET6); return 0; } @@ -3084,7 +3077,6 @@ static int tcp_sock_refill(void *arg) */ int tcp_init(struct ctx *c) { - struct tcp_sock_refill_arg refill_arg = { c, 0 }; int i; #ifndef HAS_GETRANDOM int dev_random = open("/dev/random", O_RDONLY); @@ -3130,15 +3122,14 @@ int tcp_init(struct ctx *c) memset(tcp_sock_init_ext, 0xff, sizeof(tcp_sock_init_ext)); memset(tcp_sock_ns, 0xff, sizeof(tcp_sock_ns)); - tcp_sock_refill(&refill_arg); + tcp_sock_refill_init(c); if (c->mode == MODE_PASTA) { tcp_splice_init(c); NS_CALL(tcp_ns_socks_init, c); - refill_arg.ns = 1; - NS_CALL(tcp_sock_refill, &refill_arg); + NS_CALL(tcp_sock_refill_ns, c); } return 0; @@ -3258,7 +3249,6 @@ static int tcp_port_rebind(void *arg) */ void tcp_timer(struct ctx *c, const struct timespec *ts) { - struct tcp_sock_refill_arg refill_arg = { c, 0 }; union tcp_conn *conn; (void)ts; @@ -3291,12 +3281,11 @@ void tcp_timer(struct ctx *c, const struct timespec *ts) } } - tcp_sock_refill(&refill_arg); + tcp_sock_refill_init(c); if (c->mode == MODE_PASTA) { - refill_arg.ns = 1; if ((c->ifi4 && ns_sock_pool4[TCP_SOCK_POOL_TSH] < 0) || (c->ifi6 && ns_sock_pool6[TCP_SOCK_POOL_TSH] < 0)) - NS_CALL(tcp_sock_refill, &refill_arg); + NS_CALL(tcp_sock_refill_ns, c); tcp_splice_pipe_refill(c); } -- 2.39.1