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 <david@gibson.dropbear.id.au>
This commit is contained in:
parent
1467a35b5a
commit
f5a31ee94c
5 changed files with 7 additions and 55 deletions
14
conf.c
14
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;
|
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;
|
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 };
|
uint8_t exclude[PORT_BITMAP_SIZE] = { 0 };
|
||||||
char buf[BUFSIZ], *sep, *spec, *p;
|
char buf[BUFSIZ], *sep, *spec, *p;
|
||||||
sa_family_t af = AF_UNSPEC;
|
sa_family_t af = AF_UNSPEC;
|
||||||
|
in_port_t *delta;
|
||||||
uint8_t *map;
|
uint8_t *map;
|
||||||
|
|
||||||
if (optname == 't') {
|
if (optname == 't') {
|
||||||
map = c->tcp.fwd_in.map;
|
map = c->tcp.fwd_in.map;
|
||||||
remap = tcp_remap_to_tap;
|
delta = c->tcp.fwd_in.delta;
|
||||||
} else if (optname == 'T') {
|
} else if (optname == 'T') {
|
||||||
map = c->tcp.fwd_out.map;
|
map = c->tcp.fwd_out.map;
|
||||||
remap = tcp_remap_to_init;
|
delta = c->tcp.fwd_out.delta;
|
||||||
} else if (optname == 'u') {
|
} else if (optname == 'u') {
|
||||||
map = c->udp.fwd_in.f.map;
|
map = c->udp.fwd_in.f.map;
|
||||||
remap = udp_remap_to_tap;
|
delta = c->udp.fwd_in.f.delta;
|
||||||
} else if (optname == 'U') {
|
} else if (optname == 'U') {
|
||||||
map = c->udp.fwd_out.f.map;
|
map = c->udp.fwd_out.f.map;
|
||||||
remap = udp_remap_to_init;
|
delta = c->udp.fwd_out.f.delta;
|
||||||
} else { /* For gcc -O3 */
|
} else { /* For gcc -O3 */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -365,8 +365,8 @@ static int conf_ports(struct ctx *c, char optname, const char *optarg,
|
||||||
|
|
||||||
if (start_dst != -1) {
|
if (start_dst != -1) {
|
||||||
/* 80:8080 or 22-80:8080:8080 */
|
/* 80:8080 or 22-80:8080:8080 */
|
||||||
remap(c, i, (in_port_t)(start_dst -
|
delta[i] = (in_port_t)(start_dst -
|
||||||
start_src));
|
start_src);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (optname == 't')
|
if (optname == 't')
|
||||||
|
|
22
tcp.c
22
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); \
|
conn_event_do(c, conn, event); \
|
||||||
} while (0)
|
} 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
|
* tcp_rtt_dst_low() - Check if low RTT was seen for connection endpoint
|
||||||
* @conn: Connection pointer
|
* @conn: Connection pointer
|
||||||
|
|
2
tcp.h
2
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_sock_set_bufsize(const struct ctx *c, int s);
|
||||||
void tcp_update_l2_buf(const unsigned char *eth_d, const unsigned char *eth_s,
|
void tcp_update_l2_buf(const unsigned char *eth_d, const unsigned char *eth_s,
|
||||||
const uint32_t *ip_da);
|
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
|
* union tcp_epoll_ref - epoll reference portion for TCP connections
|
||||||
|
|
22
udp.c
22
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 iovec udp_iov_sendto [UDP_SPLICE_FRAMES];
|
||||||
static struct mmsghdr udp_mmh_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
|
* udp_invert_portmap() - Compute reverse port translations for return packets
|
||||||
* @fwd: Port forwarding configuration to compute reverse map for
|
* @fwd: Port forwarding configuration to compute reverse map for
|
||||||
|
|
2
udp.h
2
udp.h
|
@ -18,8 +18,6 @@ int udp_init(struct ctx *c);
|
||||||
void udp_timer(struct ctx *c, const struct timespec *ts);
|
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,
|
void udp_update_l2_buf(const unsigned char *eth_d, const unsigned char *eth_s,
|
||||||
const uint32_t *ip_da);
|
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
|
* union udp_epoll_ref - epoll reference portion for TCP connections
|
||||||
|
|
Loading…
Reference in a new issue