From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stefano Brivio To: passt-dev@passt.top Subject: [PATCH 22/24] tcp, tcp_splice: Use less awkward syntax to swap in/out sockets from pools Date: Fri, 25 Mar 2022 23:52:58 +0100 Message-ID: <20220325225300.2803584-23-sbrivio@redhat.com> In-Reply-To: <20220325225300.2803584-1-sbrivio@redhat.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============6068692871158696808==" --===============6068692871158696808== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Signed-off-by: Stefano Brivio --- tcp.c | 9 ++++----- tcp_splice.c | 13 ++++++------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/tcp.c b/tcp.c index 3f61e6a..e0916e0 100644 --- a/tcp.c +++ b/tcp.c @@ -2031,13 +2031,12 @@ static uint32_t tcp_seq_init(struct ctx *c, int af, v= oid *addr, */ static int tcp_conn_new_sock(struct ctx *c, sa_family_t af) { - int *pool =3D af =3D=3D AF_INET6 ? init_sock_pool6 : init_sock_pool4, i, s; + int *p =3D af =3D=3D AF_INET6 ? init_sock_pool6 : init_sock_pool4, i, s =3D= -1; =20 - for (i =3D 0; i < TCP_SOCK_POOL_SIZE; i++, pool++) { - if ((s =3D *pool) >=3D 0) { - *pool =3D -1; + for (i =3D 0; i < TCP_SOCK_POOL_SIZE; i++, p++) { + SWAP(s, *p); + if (s >=3D 0) break; - } } =20 if (s < 0) diff --git a/tcp_splice.c b/tcp_splice.c index b7bdfc2..bcafd33 100644 --- a/tcp_splice.c +++ b/tcp_splice.c @@ -501,18 +501,17 @@ static int tcp_splice_new(struct ctx *c, struct tcp_spl= ice_conn *conn, in_port_t port) { struct tcp_splice_connect_ns_arg ns_arg =3D { c, conn, port, 0 }; - int *sock_pool_p, i, s =3D -1; + int *p, i, s =3D -1; =20 if (bitmap_isset(c->tcp.port_to_tap, port)) - sock_pool_p =3D CONN_V6(conn) ? ns_sock_pool6 : ns_sock_pool4; + p =3D CONN_V6(conn) ? ns_sock_pool6 : ns_sock_pool4; else - sock_pool_p =3D CONN_V6(conn) ? init_sock_pool6 : init_sock_pool4; + p =3D CONN_V6(conn) ? init_sock_pool6 : init_sock_pool4; =20 - for (i =3D 0; i < TCP_SOCK_POOL_SIZE; i++, sock_pool_p++) { - if ((s =3D *sock_pool_p) >=3D 0) { - *sock_pool_p =3D -1; + for (i =3D 0; i < TCP_SOCK_POOL_SIZE; i++, p++) { + SWAP(s, *p); + if (s >=3D 0) break; - } } =20 if (s < 0 && bitmap_isset(c->tcp.port_to_tap, port)) { --=20 2.35.1 --===============6068692871158696808==--