From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Gibson To: passt-dev@passt.top Subject: [PATCH v2 4/8] Don't use indirect remap functions for conf_ports() Date: Sat, 24 Sep 2022 19:08:19 +1000 Message-ID: <20220924090823.1873052-5-david@gibson.dropbear.id.au> In-Reply-To: <20220924090823.1873052-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============8315876078384736451==" --===============8315876078384736451== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Now that we've delayed initialization of the UDP specific "reverse" map until udp_init(), the only difference between the various 'remap' functions used in conf_ports() is which array they target. So, simplify by open coding the logic into conf_ports() with a pointer to the correct mapping array. Signed-off-by: David Gibson --- conf.c | 14 +++++++------- tcp.c | 22 ---------------------- tcp.h | 2 -- udp.c | 22 ---------------------- udp.h | 2 -- 5 files changed, 7 insertions(+), 55 deletions(-) diff --git a/conf.c b/conf.c index 8940ec4..8424699 100644 --- a/conf.c +++ b/conf.c @@ -120,24 +120,24 @@ static int conf_ports(struct ctx *c, char optname, cons= t char *optarg, { int start_src, end_src, start_dst, end_dst, exclude_only =3D 1, i, port; char addr_buf[sizeof(struct in6_addr)] =3D { 0 }, *addr =3D addr_buf; - void (*remap)(struct ctx *c, in_port_t port, in_port_t delta); uint8_t exclude[PORT_BITMAP_SIZE] =3D { 0 }; char buf[BUFSIZ], *sep, *spec, *p; sa_family_t af =3D AF_UNSPEC; + in_port_t *delta; uint8_t *map; =20 if (optname =3D=3D 't') { map =3D c->tcp.fwd_in.map; - remap =3D tcp_remap_to_tap; + delta =3D c->tcp.fwd_in.delta; } else if (optname =3D=3D 'T') { map =3D c->tcp.fwd_out.map; - remap =3D tcp_remap_to_init; + delta =3D c->tcp.fwd_out.delta; } else if (optname =3D=3D 'u') { map =3D c->udp.fwd_in.f.map; - remap =3D udp_remap_to_tap; + delta =3D c->udp.fwd_in.f.delta; } else if (optname =3D=3D 'U') { map =3D c->udp.fwd_out.f.map; - remap =3D udp_remap_to_init; + delta =3D c->udp.fwd_out.f.delta; } else { /* For gcc -O3 */ return 0; } @@ -365,8 +365,8 @@ static int conf_ports(struct ctx *c, char optname, const = char *optarg, =20 if (start_dst !=3D -1) { /* 80:8080 or 22-80:8080:8080 */ - remap(c, i, (in_port_t)(start_dst - - start_src)); + delta[i] =3D (in_port_t)(start_dst - + start_src); } =20 if (optname =3D=3D 't') diff --git a/tcp.c b/tcp.c index e44177f..509a0b3 100644 --- a/tcp.c +++ b/tcp.c @@ -948,28 +948,6 @@ static void conn_event_do(const struct ctx *c, struct tc= p_conn *conn, conn_event_do(c, conn, event); \ } while (0) =20 -/** - * tcp_remap_to_tap() - Set delta for port translation toward guest/tap - * @c: Execution context - * @port: Original destination port, host order - * @delta: Delta to be added to original destination port - */ -void tcp_remap_to_tap(struct ctx *c, in_port_t port, in_port_t delta) -{ - c->tcp.fwd_in.delta[port] =3D delta; -} - -/** - * tcp_remap_to_tap() - Set delta for port translation toward init namespace - * @c: Execution context - * @port: Original destination port, host order - * @delta: Delta to be added to original destination port - */ -void tcp_remap_to_init(struct ctx *c, in_port_t port, in_port_t delta) -{ - c->tcp.fwd_out.delta[port] =3D delta; -} - /** * tcp_rtt_dst_low() - Check if low RTT was seen for connection endpoint * @conn: Connection pointer diff --git a/tcp.h b/tcp.h index 502b096..2548d4d 100644 --- a/tcp.h +++ b/tcp.h @@ -29,8 +29,6 @@ void tcp_defer_handler(struct ctx *c); void tcp_sock_set_bufsize(const struct ctx *c, int s); void tcp_update_l2_buf(const unsigned char *eth_d, const unsigned char *eth_= s, const uint32_t *ip_da); -void tcp_remap_to_tap(struct ctx *c, in_port_t port, in_port_t delta); -void tcp_remap_to_init(struct ctx *c, in_port_t port, in_port_t delta); =20 /** * union tcp_epoll_ref - epoll reference portion for TCP connections diff --git a/udp.c b/udp.c index eb32dda..d17b3b4 100644 --- a/udp.c +++ b/udp.c @@ -258,28 +258,6 @@ static struct mmsghdr udp_mmh_send [UDP_SPLICE_FRAMES]; static struct iovec udp_iov_sendto [UDP_SPLICE_FRAMES]; static struct mmsghdr udp_mmh_sendto [UDP_SPLICE_FRAMES]; =20 -/** - * udp_remap_to_tap() - Set delta for port translation to/from guest/tap - * @c: Execution context - * @port: Original destination port, host order - * @delta: Delta to be added to original destination port - */ -void udp_remap_to_tap(struct ctx *c, in_port_t port, in_port_t delta) -{ - c->udp.fwd_in.f.delta[port] =3D delta; -} - -/** - * udp_remap_to_init() - Set delta for port translation to/from init namespa= ce - * @c: Execution context - * @port: Original destination port, host order - * @delta: Delta to be added to original destination port - */ -void udp_remap_to_init(struct ctx *c, in_port_t port, in_port_t delta) -{ - c->udp.fwd_out.f.delta[port] =3D delta; -} - /** * udp_invert_portmap() - Compute reverse port translations for return packe= ts * @fwd: Port forwarding configuration to compute reverse map for diff --git a/udp.h b/udp.h index 25422b6..bc7b259 100644 --- a/udp.h +++ b/udp.h @@ -18,8 +18,6 @@ int udp_init(struct ctx *c); void udp_timer(struct ctx *c, const struct timespec *ts); void udp_update_l2_buf(const unsigned char *eth_d, const unsigned char *eth_= s, const uint32_t *ip_da); -void udp_remap_to_tap(struct ctx *c, in_port_t port, in_port_t delta); -void udp_remap_to_init(struct ctx *c, in_port_t port, in_port_t delta); =20 /** * union udp_epoll_ref - epoll reference portion for TCP connections --=20 2.37.3 --===============8315876078384736451==--