diff options
| author | David Gibson <david@gibson.dropbear.id.au> | 2025-10-31 15:19:28 +1100 |
|---|---|---|
| committer | Stefano Brivio <sbrivio@redhat.com> | 2025-11-01 00:23:04 +0100 |
| commit | 942bfdb801732e9076ebc90e9d8206513ddbcd90 (patch) | |
| tree | 0784e58304b5c214660dcc2039423b8ee6a9f9b6 | |
| parent | 06c3dcc2a6e2a814b52dc2549ef3db8c0771b454 (diff) | |
| download | passt-942bfdb801732e9076ebc90e9d8206513ddbcd90.tar passt-942bfdb801732e9076ebc90e9d8206513ddbcd90.tar.gz passt-942bfdb801732e9076ebc90e9d8206513ddbcd90.tar.bz2 passt-942bfdb801732e9076ebc90e9d8206513ddbcd90.tar.lz passt-942bfdb801732e9076ebc90e9d8206513ddbcd90.tar.xz passt-942bfdb801732e9076ebc90e9d8206513ddbcd90.tar.zst passt-942bfdb801732e9076ebc90e9d8206513ddbcd90.zip | |
fwd: Check forwarding mode in fwd_scan_ports_*() rather than caller
fwd_scan_ports() needs to check for FWD_AUTO mode before calling each
scan function - otherwise it would clobber the forwarding bitmap which
should retain the user's fixed configuration.
Make this slightly cleaner and safer by moving the mode check into
fwd_scan_ports_{tcp,udp}().
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
| -rw-r--r-- | fwd.c | 24 |
1 files changed, 12 insertions, 12 deletions
@@ -363,6 +363,9 @@ static void procfs_scan_listen(int fd, unsigned int lstate, uint8_t *map) static void fwd_scan_ports_tcp(struct fwd_ports *fwd, const struct fwd_ports *rev) { + if (fwd->mode != FWD_AUTO) + return; + memset(fwd->map, 0, PORT_BITMAP_SIZE); procfs_scan_listen(fwd->scan4, TCP_LISTEN, fwd->map); procfs_scan_listen(fwd->scan6, TCP_LISTEN, fwd->map); @@ -381,6 +384,9 @@ static void fwd_scan_ports_udp(struct fwd_ports *fwd, const struct fwd_ports *tcp_fwd, const struct fwd_ports *tcp_rev) { + if (fwd->mode != FWD_AUTO) + return; + memset(fwd->map, 0, PORT_BITMAP_SIZE); procfs_scan_listen(fwd->scan4, UDP_LISTEN, fwd->map); procfs_scan_listen(fwd->scan6, UDP_LISTEN, fwd->map); @@ -408,18 +414,12 @@ static void fwd_scan_ports_udp(struct fwd_ports *fwd, */ static void fwd_scan_ports(struct ctx *c) { - if (c->tcp.fwd_out.mode == FWD_AUTO) - fwd_scan_ports_tcp(&c->tcp.fwd_out, &c->tcp.fwd_in); - if (c->tcp.fwd_in.mode == FWD_AUTO) - fwd_scan_ports_tcp(&c->tcp.fwd_in, &c->tcp.fwd_out); - if (c->udp.fwd_out.mode == FWD_AUTO) { - fwd_scan_ports_udp(&c->udp.fwd_out, &c->udp.fwd_in, - &c->tcp.fwd_out, &c->tcp.fwd_in); - } - if (c->udp.fwd_in.mode == FWD_AUTO) { - fwd_scan_ports_udp(&c->udp.fwd_in, &c->udp.fwd_out, - &c->tcp.fwd_in, &c->tcp.fwd_out); - } + fwd_scan_ports_tcp(&c->tcp.fwd_out, &c->tcp.fwd_in); + fwd_scan_ports_tcp(&c->tcp.fwd_in, &c->tcp.fwd_out); + fwd_scan_ports_udp(&c->udp.fwd_out, &c->udp.fwd_in, + &c->tcp.fwd_out, &c->tcp.fwd_in); + fwd_scan_ports_udp(&c->udp.fwd_in, &c->udp.fwd_out, + &c->tcp.fwd_in, &c->tcp.fwd_out); } /** |
