From f5a31ee94c37f92729d458335705f5befa168151 Mon Sep 17 00:00:00 2001 From: David Gibson Date: Sat, 24 Sep 2022 19:08:19 +1000 Subject: Don't use indirect remap functions for conf_ports() 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, const char *optarg, { int start_src, end_src, start_dst, end_dst, exclude_only = 1, i, port; char addr_buf[sizeof(struct in6_addr)] = { 0 }, *addr = addr_buf; - void (*remap)(struct ctx *c, in_port_t port, in_port_t delta); uint8_t exclude[PORT_BITMAP_SIZE] = { 0 }; char buf[BUFSIZ], *sep, *spec, *p; sa_family_t af = AF_UNSPEC; + in_port_t *delta; uint8_t *map; if (optname == 't') { map = c->tcp.fwd_in.map; - remap = tcp_remap_to_tap; + delta = c->tcp.fwd_in.delta; } else if (optname == 'T') { map = c->tcp.fwd_out.map; - remap = tcp_remap_to_init; + delta = c->tcp.fwd_out.delta; } else if (optname == 'u') { map = c->udp.fwd_in.f.map; - remap = udp_remap_to_tap; + delta = c->udp.fwd_in.f.delta; } else if (optname == 'U') { map = c->udp.fwd_out.f.map; - remap = udp_remap_to_init; + delta = 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, if (start_dst != -1) { /* 80:8080 or 22-80:8080:8080 */ - remap(c, i, (in_port_t)(start_dst - - start_src)); + delta[i] = (in_port_t)(start_dst - + start_src); } if (optname == '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 tcp_conn *conn, conn_event_do(c, conn, event); \ } while (0) -/** - * 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] = 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] = 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); /** * 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]; -/** - * 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] = delta; -} - -/** - * udp_remap_to_init() - Set delta for port translation to/from init namespace - * @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] = delta; -} - /** * udp_invert_portmap() - Compute reverse port translations for return packets * @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); /** * union udp_epoll_ref - epoll reference portion for TCP connections -- cgit v1.2.3