From c09d0d0f6085944a7b0e58434148702b2d5f5e9a Mon Sep 17 00:00:00 2001 From: David Gibson Date: Fri, 3 Nov 2023 13:23:03 +1100 Subject: port_fwd: Simplify get_bound_ports_*() to port_fwd_scan_*() get_bound_ports_*() now only use their context and ns parameters to determine which forwarding maps they're operating on. Each function needs the map they're actually updating, as well as the map for the other direction, to avoid creating forwarding loops. The UDP function also requires the corresponding TCP map, to implement the behaviour where we forward UDP ports of the same number as bound TCP ports for tools like iperf3. Passing those maps directly as parameters simplifies the code without making the callers life harder, because those already know the relevant maps. IMO, invoking these functions in terms of where they're looking for updated forwarding also makes more logical sense than in terms of where they're looking for bound ports. Given that new way of looking at the functions, also rename them to port_fwd_scan_*(). Signed-off-by: David Gibson Signed-off-by: Stefano Brivio --- port_fwd.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'port_fwd.h') diff --git a/port_fwd.h b/port_fwd.h index 8ab6b48..8a823d8 100644 --- a/port_fwd.h +++ b/port_fwd.h @@ -35,8 +35,9 @@ struct port_fwd { in_port_t delta[NUM_PORTS]; }; -void get_bound_ports_tcp(struct ctx *c, int ns); -void get_bound_ports_udp(struct ctx *c, int ns); +void port_fwd_scan_tcp(struct port_fwd *fwd, const struct port_fwd *rev); +void port_fwd_scan_udp(struct port_fwd *fwd, const struct port_fwd *rev, + const struct port_fwd *tcp); void port_fwd_init(struct ctx *c); #endif /* PORT_FWD_H */ -- cgit v1.2.3