From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202602 header.b=RZL37nmM; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 7E60D5A061E for ; Thu, 19 Mar 2026 07:12:12 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1773900722; bh=JVsHX4FPSfu3EQI1FB2w2AZ424Tt0G/7SZSS4ebWhI8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RZL37nmMkOwbwXsha2psqB2yAhrjhBHqeceWNsmEhTRcTpbvw2b8jBVk1CbCxpD/z WcAJQoscpLcWpIod5gR7UvdEbYMnxIIZaCWCLSxF6T2B8Oh4ZRWlOKQ/ERgJlY+Jy6 FG7mtgYqt4PksygHX1azNcHs3gB5frie7dLBm3LH66nCspDPxeYEjEzJqB7Ga7vmMW X0EiunXBTbnkK6yXQSrllawFp59PYlOVU9iKYqHPmilZfatb2IDLDXogVnMhzCQ3T6 yVRLSxt2bAYCzlQUC8EHjJDYGDr9YXlRpvdC65PQb51CgkVFS2i94dQzyeg7Oqdo3S FEAVe7Fdp9YXg== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4fbwMQ0ChYz4wSq; Thu, 19 Mar 2026 17:12:02 +1100 (AEDT) From: David Gibson To: Stefano Brivio , passt-dev@passt.top Subject: [PATCH v2 05/15] fwd: Look up rule index in fwd_sync_one() Date: Thu, 19 Mar 2026 17:11:47 +1100 Message-ID: <20260319061157.1983818-6-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260319061157.1983818-1-david@gibson.dropbear.id.au> References: <20260319061157.1983818-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: T2E4YODRZEAF7LZXVTIVAFN2CKJE4ADT X-Message-ID-Hash: T2E4YODRZEAF7LZXVTIVAFN2CKJE4ADT 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: Currently we have the slightly silly setup that fwd_listen_sync_() looks up the pointer to a rule based on its index, then fwd_sync_one() turns it back into an index. Avoid this by passing the index directly into fwd_sync_one(). Signed-off-by: David Gibson --- fwd.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/fwd.c b/fwd.c index a306b409..7844a674 100644 --- a/fwd.c +++ b/fwd.c @@ -506,7 +506,7 @@ void fwd_rules_print(const struct fwd_table *fwd) /** fwd_sync_one() - Create or remove listening sockets for a forward entry * @c: Execution context * @fwd: Forwarding table - * @rule: Forwarding rule + * @idx: Rule index * @pif: Interface to create listening sockets for * @tcp: Bitmap of TCP ports to listen for on FWD_SCAN entries * @udp: Bitmap of UDP ports to listen for on FWD_SCAN entries @@ -514,23 +514,21 @@ void fwd_rules_print(const struct fwd_table *fwd) * Return: 0 on success, -1 on failure */ static int fwd_sync_one(const struct ctx *c, const struct fwd_table *fwd, - const struct fwd_rule *rule, uint8_t pif, + unsigned idx, uint8_t pif, const uint8_t *tcp, const uint8_t *udp) { + const struct fwd_rule *rule = &fwd->rules[idx]; const union inany_addr *addr = fwd_rule_addr(rule); const char *ifname = rule->ifname; const uint8_t *map = NULL; bool bound_one = false; - unsigned port, idx; + unsigned port; assert(pif_is_socket(pif)); if (!*ifname) ifname = NULL; - idx = rule - fwd->rules; - assert(idx < MAX_FWD_RULES); - if (rule->flags & FWD_SCAN) { if (rule->proto == IPPROTO_TCP) map = tcp; @@ -628,8 +626,8 @@ static int fwd_listen_sync_(void *arg) ns_enter(a->c); for (i = 0; i < a->fwd->count; i++) { - a->ret = fwd_sync_one(a->c, a->fwd, &a->fwd->rules[i], - a->pif, a->tcpmap, a->udpmap); + a->ret = fwd_sync_one(a->c, a->fwd, i, a->pif, + a->tcpmap, a->udpmap); if (a->ret < 0) break; } -- 2.53.0