aboutgitcodebugslistschat
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2026-03-27 15:34:19 +1100
committerStefano Brivio <sbrivio@redhat.com>2026-03-28 14:35:46 +0100
commit1f974cc68c63b1d4c3b1b8fd6ae612b3308cac2c (patch)
treeea0dfc534632a814aa4b0ed89552a98d607dbdd9
parent0dc9f207247558adc93b05782828b41fba48ed92 (diff)
downloadpasst-1f974cc68c63b1d4c3b1b8fd6ae612b3308cac2c.tar
passt-1f974cc68c63b1d4c3b1b8fd6ae612b3308cac2c.tar.gz
passt-1f974cc68c63b1d4c3b1b8fd6ae612b3308cac2c.tar.bz2
passt-1f974cc68c63b1d4c3b1b8fd6ae612b3308cac2c.tar.lz
passt-1f974cc68c63b1d4c3b1b8fd6ae612b3308cac2c.tar.xz
passt-1f974cc68c63b1d4c3b1b8fd6ae612b3308cac2c.tar.zst
passt-1f974cc68c63b1d4c3b1b8fd6ae612b3308cac2c.zip
fwd: Look up rule index in fwd_sync_one()
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 <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
-rw-r--r--fwd.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/fwd.c b/fwd.c
index 74260a3..f47d666 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;
}