diff options
| author | David Gibson <david@gibson.dropbear.id.au> | 2026-03-27 15:34:22 +1100 |
|---|---|---|
| committer | Stefano Brivio <sbrivio@redhat.com> | 2026-03-28 14:35:52 +0100 |
| commit | 1f9ee4fda2ad93d8bb2cc73ad5e7a435983ad1ba (patch) | |
| tree | 0f6001ec735230f872f818c03e6d5394777d5cac | |
| parent | 35c56c5b5e00389b2bf51a7d1c3f3c5387bba264 (diff) | |
| download | passt-1f9ee4fda2ad93d8bb2cc73ad5e7a435983ad1ba.tar passt-1f9ee4fda2ad93d8bb2cc73ad5e7a435983ad1ba.tar.gz passt-1f9ee4fda2ad93d8bb2cc73ad5e7a435983ad1ba.tar.bz2 passt-1f9ee4fda2ad93d8bb2cc73ad5e7a435983ad1ba.tar.lz passt-1f9ee4fda2ad93d8bb2cc73ad5e7a435983ad1ba.tar.xz passt-1f9ee4fda2ad93d8bb2cc73ad5e7a435983ad1ba.tar.zst passt-1f9ee4fda2ad93d8bb2cc73ad5e7a435983ad1ba.zip | |
fwd, conf: Expose ephemeral ports as bitmap rather than function
It turns out the only callers of fwd_port_is_ephemeral() use it to build a
bitmap of ephemeral ports. So, replace it with fwd_port_map_ephemeral(),
which directly builds that bitmap. As a bonus this allows a slightly
cheaper implementation of building the map, since inside fwd.c we know that
the ephemeral ports form a single range.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
| -rw-r--r-- | conf.c | 8 | ||||
| -rw-r--r-- | fwd.c | 15 | ||||
| -rw-r--r-- | fwd.h | 2 |
3 files changed, 10 insertions, 15 deletions
@@ -282,9 +282,7 @@ static void conf_ports(const struct ctx *c, char optname, const char *optarg, *mode = FWD_MODE_ALL; /* Exclude ephemeral ports */ - for (i = 0; i < NUM_PORTS; i++) - if (fwd_port_is_ephemeral(i)) - bitmap_set(exclude, i); + fwd_port_map_ephemeral(exclude); conf_ports_range_except(c, optname, optarg, fwd, NULL, NULL, @@ -376,9 +374,7 @@ static void conf_ports(const struct ctx *c, char optname, const char *optarg, if (exclude_only) { /* Exclude ephemeral ports */ - for (i = 0; i < NUM_PORTS; i++) - if (fwd_port_is_ephemeral(i)) - bitmap_set(exclude, i); + fwd_port_map_ephemeral(exclude); conf_ports_range_except(c, optname, optarg, fwd, addr, ifname, @@ -319,16 +319,15 @@ static const union inany_addr *fwd_rule_addr(const struct fwd_rule *rule) } /** - * fwd_port_is_ephemeral() - Is port number ephemeral? - * @port: Port number - * - * Return: true if @port is ephemeral, that is may be allocated by the kernel as - * a local port for outgoing connections or datagrams, but should not be - * used for binding services to. + * fwd_port_map_ephemeral() - Mark ephemeral ports in a bitmap + * @map: Bitmap to update */ -bool fwd_port_is_ephemeral(in_port_t port) +void fwd_port_map_ephemeral(uint8_t *map) { - return (port >= fwd_ephemeral_min) && (port <= fwd_ephemeral_max); + unsigned port; + + for (port = fwd_ephemeral_min; port <= fwd_ephemeral_max; port++) + bitmap_set(map, port); } /* Forwarding table storage, generally accessed via pointers in struct ctx */ @@ -22,7 +22,7 @@ struct flowside; #define NUM_PORTS (1U << 16) void fwd_probe_ephemeral(void); -bool fwd_port_is_ephemeral(in_port_t port); +void fwd_port_map_ephemeral(uint8_t *map); /** * struct fwd_rule - Forwarding rule governing a range of ports |
