diff options
| author | David Gibson <david@gibson.dropbear.id.au> | 2026-03-27 15:34:18 +1100 |
|---|---|---|
| committer | Stefano Brivio <sbrivio@redhat.com> | 2026-03-28 14:35:44 +0100 |
| commit | 0dc9f207247558adc93b05782828b41fba48ed92 (patch) | |
| tree | 168191f7d90ea18ed6a5b342e6809c9edd22cc55 | |
| parent | b7a471813b03cf296c37bd93f45f5bb17147ccd4 (diff) | |
| download | passt-0dc9f207247558adc93b05782828b41fba48ed92.tar passt-0dc9f207247558adc93b05782828b41fba48ed92.tar.gz passt-0dc9f207247558adc93b05782828b41fba48ed92.tar.bz2 passt-0dc9f207247558adc93b05782828b41fba48ed92.tar.lz passt-0dc9f207247558adc93b05782828b41fba48ed92.tar.xz passt-0dc9f207247558adc93b05782828b41fba48ed92.tar.zst passt-0dc9f207247558adc93b05782828b41fba48ed92.zip | |
fwd: Move selecting correct scan bitmap into fwd_sync_one()
Currently fwd_listen_sync_() determines which of the two port scanned
bitmaps is the correct one for a rule before passing it into
fwd_sync_one(). However, fwd_sync_one() is already looking at the rule
internals so is better placed to do this.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
| -rw-r--r-- | fwd.c | 28 |
1 files changed, 15 insertions, 13 deletions
@@ -508,16 +508,18 @@ void fwd_rules_print(const struct fwd_table *fwd) * @fwd: Forwarding table * @rule: Forwarding rule * @pif: Interface to create listening sockets for - * @scanmap: Bitmap of ports to listen for on FWD_SCAN entries + * @tcp: Bitmap of TCP ports to listen for on FWD_SCAN entries + * @udp: Bitmap of UDP ports to listen for on FWD_SCAN entries * * 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, - const uint8_t *scanmap) + const uint8_t *tcp, const uint8_t *udp) { 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; @@ -528,12 +530,19 @@ static int fwd_sync_one(const struct ctx *c, const struct fwd_table *fwd, idx = rule - fwd->rules; assert(idx < MAX_FWD_RULES); - assert(!(rule->flags & FWD_SCAN && !scanmap)); - + + if (rule->flags & FWD_SCAN) { + if (rule->proto == IPPROTO_TCP) + map = tcp; + else if (rule->proto == IPPROTO_UDP) + map = udp; + assert(map); + } + for (port = rule->first; port <= rule->last; port++) { int fd = rule->socks[port - rule->first]; - if ((rule->flags & FWD_SCAN) && !bitmap_isset(scanmap, port)) { + if (map && !bitmap_isset(map, port)) { /* We don't want to listen on this port */ if (fd >= 0) { /* We already are, so stop */ @@ -619,15 +628,8 @@ static int fwd_listen_sync_(void *arg) ns_enter(a->c); for (i = 0; i < a->fwd->count; i++) { - const uint8_t *scanmap = NULL; - - if (a->fwd->rules[i].proto == IPPROTO_TCP) - scanmap = a->tcpmap; - else if (a->fwd->rules[i].proto == IPPROTO_UDP) - scanmap = a->udpmap; - a->ret = fwd_sync_one(a->c, a->fwd, &a->fwd->rules[i], - a->pif, scanmap); + a->pif, a->tcpmap, a->udpmap); if (a->ret < 0) break; } |
