tcp, tcp_splice: Use less awkward syntax to swap in/out sockets from pools

Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
Stefano Brivio 2022-03-25 11:24:23 +01:00
parent f41f0416b8
commit 415ccf6116
2 changed files with 10 additions and 12 deletions

9
tcp.c
View file

@ -2031,14 +2031,13 @@ static uint32_t tcp_seq_init(struct ctx *c, int af, void *addr,
*/ */
static int tcp_conn_new_sock(struct ctx *c, sa_family_t af) static int tcp_conn_new_sock(struct ctx *c, sa_family_t af)
{ {
int *pool = af == AF_INET6 ? init_sock_pool6 : init_sock_pool4, i, s; int *p = af == AF_INET6 ? init_sock_pool6 : init_sock_pool4, i, s = -1;
for (i = 0; i < TCP_SOCK_POOL_SIZE; i++, pool++) { for (i = 0; i < TCP_SOCK_POOL_SIZE; i++, p++) {
if ((s = *pool) >= 0) { SWAP(s, *p);
*pool = -1; if (s >= 0)
break; break;
} }
}
if (s < 0) if (s < 0)
s = socket(af, SOCK_STREAM | SOCK_NONBLOCK, IPPROTO_TCP); s = socket(af, SOCK_STREAM | SOCK_NONBLOCK, IPPROTO_TCP);

View file

@ -501,19 +501,18 @@ static int tcp_splice_new(struct ctx *c, struct tcp_splice_conn *conn,
in_port_t port) in_port_t port)
{ {
struct tcp_splice_connect_ns_arg ns_arg = { c, conn, port, 0 }; struct tcp_splice_connect_ns_arg ns_arg = { c, conn, port, 0 };
int *sock_pool_p, i, s = -1; int *p, i, s = -1;
if (bitmap_isset(c->tcp.port_to_tap, port)) if (bitmap_isset(c->tcp.port_to_tap, port))
sock_pool_p = CONN_V6(conn) ? ns_sock_pool6 : ns_sock_pool4; p = CONN_V6(conn) ? ns_sock_pool6 : ns_sock_pool4;
else else
sock_pool_p = CONN_V6(conn) ? init_sock_pool6 : init_sock_pool4; p = CONN_V6(conn) ? init_sock_pool6 : init_sock_pool4;
for (i = 0; i < TCP_SOCK_POOL_SIZE; i++, sock_pool_p++) { for (i = 0; i < TCP_SOCK_POOL_SIZE; i++, p++) {
if ((s = *sock_pool_p) >= 0) { SWAP(s, *p);
*sock_pool_p = -1; if (s >= 0)
break; break;
} }
}
if (s < 0 && bitmap_isset(c->tcp.port_to_tap, port)) { if (s < 0 && bitmap_isset(c->tcp.port_to_tap, port)) {
NS_CALL(tcp_splice_connect_ns, &ns_arg); NS_CALL(tcp_splice_connect_ns, &ns_arg);