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=gMBXe2fp; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 5F80F5A0653 for ; Fri, 27 Mar 2026 05:34:42 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1774586072; bh=OzlMz6CpHlt1RofvZY9/vDJewsEpJzb4t8ir5GJCO60=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gMBXe2fp+26HbwAOGYSsBQgBrXb/jCuU47Knxk6bWnB9rmNZIa2PD/jiwMTyoEPcU X3+Y1sUnssWD5X9KMW+3Moacv6EuU/xtYyE2tWI5NxkQDslI+VukXNDHR3llRUH683 yu6de6m50z8QtH8cOb2bajBKvSHoGcA4RBxB9WVbG8z8YFBlnit0AhBz4h6JIQVk1E px/2m9vexOHbMCyOQkuj3ePB8Wko/7gADqdNnOE3HTkinbNwfTby4bi1MawuvryIfJ TXStewjUfLSyw7m3kjiNeL9WsCmJlkbgeAUmLYeOebiJ5r/PYB9nR7Kate1LjgW6iT +YhSJ4Oiu3Ffw== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4fhnqD5Hhhz4wT3; Fri, 27 Mar 2026 15:34:32 +1100 (AEDT) From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH 07/18] fwd: Look up rule index in fwd_sync_one() Date: Fri, 27 Mar 2026 15:34:19 +1100 Message-ID: <20260327043430.1785787-8-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260327043430.1785787-1-david@gibson.dropbear.id.au> References: <20260327043430.1785787-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: Q45TT7S72X7AG6I2STQEGPBUYKNSTH6L X-Message-ID-Hash: Q45TT7S72X7AG6I2STQEGPBUYKNSTH6L 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 74260a32..f47d666d 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