From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id A6FC55A0272 for ; Tue, 6 Feb 2024 02:52:48 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1707184365; bh=X55ZB2z43wrvnhOEVonQKmXE7woq25cY+z8l6vD7oBw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=hjuiJFj3c+DfTz+ToSnjGKVCEt9nPbVSaP8S3GkAQPUn1DDaN8n3wO4BVQsg4JM/j 1QyKUPmPYRd4PJ1rJ7if4aEdqDuppOn2GKKWc/Qato9fRivawCjjzXTqh2pGWZuJky 3r6lqb/3cWUPAOqICtjs475HCkrwo/Kn0rvVZF0t0LrTaEN9ZwnU8thksJA85KDYYK ZJL6nDft6EGBCf/FK4JwJ++7SM85JEr3nCR87AH3Ogvwnixx8MvrJq4lTtOJi+H1Y6 iZ/UmpegN3TVzynQhfUJsq0phL1Jz1MvQmMClc5MyBR23TNZONMBLw+4hg9glAEGkW dgW+kPMmsEGWw== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4TTR8Y72Nrz4wp3; Tue, 6 Feb 2024 12:52:45 +1100 (AEDT) Date: Tue, 6 Feb 2024 12:48:30 +1100 From: David Gibson To: Laurent Vivier Subject: Re: [PATCH 10/24] tcp: rename functions that manage buffers Message-ID: References: <20240202141151.3762941-1-lvivier@redhat.com> <20240202141151.3762941-11-lvivier@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="jG9LC4xwPSQa8T4q" Content-Disposition: inline In-Reply-To: <20240202141151.3762941-11-lvivier@redhat.com> Message-ID-Hash: HVUDSLI5M3OKMUXNMLHGHB7B5VXY2MDV X-Message-ID-Hash: HVUDSLI5M3OKMUXNMLHGHB7B5VXY2MDV X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: --jG9LC4xwPSQa8T4q Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Feb 02, 2024 at 03:11:37PM +0100, Laurent Vivier wrote: > To separate these functions from the ones specific to TCP management, > we are going to move it to a new file, but before that update their names > to reflect their role. >=20 > Signed-off-by: Laurent Vivier > --- > passt.c | 2 +- > tcp.c | 84 ++++++++++++++++++++++++++++----------------------------- > tcp.h | 2 +- > 3 files changed, 44 insertions(+), 44 deletions(-) >=20 > diff --git a/passt.c b/passt.c > index 44d3a0b0548c..10042a9b9789 100644 > --- a/passt.c > +++ b/passt.c > @@ -164,7 +164,7 @@ static void timer_init(struct ctx *c, const struct ti= mespec *now) > */ > void proto_update_l2_buf(const unsigned char *eth_d, const unsigned char= *eth_s) > { > - tcp_update_l2_buf(eth_d, eth_s); > + tcp_buf_update_l2(eth_d, eth_s); > udp_update_l2_buf(eth_d, eth_s); > } > =20 > diff --git a/tcp.c b/tcp.c > index cdbceed65033..640209533772 100644 > --- a/tcp.c > +++ b/tcp.c > @@ -383,7 +383,7 @@ struct tcp6_l2_head { /* For MSS6 macro: keep in sync= with tcp6_l2_buf_t */ > #define ACK (1 << 4) > /* Flags for internal usage */ > #define DUP_ACK (1 << 5) > -#define ACK_IF_NEEDED 0 /* See tcp_send_flag() */ > +#define ACK_IF_NEEDED 0 /* See tcp_buf_send_flag() */ > =20 > #define OPT_EOL 0 > #define OPT_NOP 1 > @@ -960,11 +960,11 @@ static uint16_t tcp_update_check_tcp6(struct ipv6hd= r *ip6h) > } > =20 > /** > - * tcp_update_l2_buf() - Update L2 buffers with Ethernet and IPv4 addres= ses > + * tcp_buf_update_l2() - Update L2 buffers with Ethernet and IPv4 addres= ses > * @eth_d: Ethernet destination address, NULL if unchanged > * @eth_s: Ethernet source address, NULL if unchanged > */ > -void tcp_update_l2_buf(const unsigned char *eth_d, const unsigned char *= eth_s) > +void tcp_buf_update_l2(const unsigned char *eth_d, const unsigned char *= eth_s) > { > int i; > =20 > @@ -982,10 +982,10 @@ void tcp_update_l2_buf(const unsigned char *eth_d, = const unsigned char *eth_s) > } > =20 > /** > - * tcp_sock4_iov_init() - Initialise scatter-gather L2 buffers for IPv4 = sockets > + * tcp_buf_sock4_iov_init() - Initialise scatter-gather L2 buffers for I= Pv4 sockets > * @c: Execution context > */ > -static void tcp_sock4_iov_init(const struct ctx *c) > +static void tcp_buf_sock4_iov_init(const struct ctx *c) > { > struct iphdr iph =3D L2_BUF_IP4_INIT(IPPROTO_TCP); > struct iovec *iov; > @@ -1014,10 +1014,10 @@ static void tcp_sock4_iov_init(const struct ctx *= c) > } > =20 > /** > - * tcp_sock6_iov_init() - Initialise scatter-gather L2 buffers for IPv6 = sockets > + * tcp_buf_sock6_iov_init() - Initialise scatter-gather L2 buffers for I= Pv6 sockets > * @c: Execution context > */ > -static void tcp_sock6_iov_init(const struct ctx *c) > +static void tcp_buf_sock6_iov_init(const struct ctx *c) > { > struct iovec *iov; > int i; > @@ -1277,10 +1277,10 @@ static void tcp_rst_do(struct ctx *c, struct tcp_= tap_conn *conn); > } while (0) > =20 > /** > - * tcp_l2_flags_buf_flush() - Send out buffers for segments with no data= (flags) > + * tcp_buf_l2_flags_flush() - Send out buffers for segments with no data= (flags) > * @c: Execution context > */ > -static void tcp_l2_flags_buf_flush(const struct ctx *c) > +static void tcp_buf_l2_flags_flush(const struct ctx *c) > { > tap_send_frames(c, tcp6_l2_flags_iov, tcp6_l2_flags_buf_used); > tcp6_l2_flags_buf_used =3D 0; > @@ -1290,10 +1290,10 @@ static void tcp_l2_flags_buf_flush(const struct c= tx *c) > } > =20 > /** > - * tcp_l2_data_buf_flush() - Send out buffers for segments with data > + * tcp_buf_l2_data_flush() - Send out buffers for segments with data > * @c: Execution context > */ > -static void tcp_l2_data_buf_flush(const struct ctx *c) > +static void tcp_buf_l2_data_flush(const struct ctx *c) > { > unsigned i; > size_t m; > @@ -1316,8 +1316,8 @@ static void tcp_l2_data_buf_flush(const struct ctx = *c) > /* cppcheck-suppress [constParameterPointer, unmatchedSuppression] */ > void tcp_defer_handler(struct ctx *c) > { > - tcp_l2_flags_buf_flush(c); > - tcp_l2_data_buf_flush(c); > + tcp_buf_l2_flags_flush(c); > + tcp_buf_l2_data_flush(c); > } > =20 > static void tcp_set_tcp_header(struct tcphdr *th, > @@ -1629,7 +1629,7 @@ static int do_tcp_send_flag(struct ctx *c, struct t= cp_tap_conn *conn, int flags, > return 1; > } > =20 > -static int tcp_send_flag(struct ctx *c, struct tcp_tap_conn *conn, int f= lags) > +static int tcp_buf_send_flag(struct ctx *c, struct tcp_tap_conn *conn, i= nt flags) The functions above could reasonably be said to be part of the buffer management, but I'm not convinced on this one - it's primary purpose is to, well, send a flag, so it uses the buffers, but I wouldn't really say it manages them. > { > size_t optlen =3D 0; > struct iovec *iov; > @@ -1664,7 +1664,7 @@ static int tcp_send_flag(struct ctx *c, struct tcp_= tap_conn *conn, int flags) > } > =20 > if (tcp4_l2_flags_buf_used > ARRAY_SIZE(tcp4_l2_flags_buf) - 2) > - tcp_l2_flags_buf_flush(c); > + tcp_buf_l2_flags_flush(c); > } else { > struct tcp6_l2_flags_buf_t *b6; > =20 > @@ -1688,7 +1688,7 @@ static int tcp_send_flag(struct ctx *c, struct tcp_= tap_conn *conn, int flags) > } > =20 > if (tcp6_l2_flags_buf_used > ARRAY_SIZE(tcp6_l2_flags_buf) - 2) > - tcp_l2_flags_buf_flush(c); > + tcp_buf_l2_flags_flush(c); > } > =20 > return 0; > @@ -1704,7 +1704,7 @@ static void tcp_rst_do(struct ctx *c, struct tcp_ta= p_conn *conn) > if (conn->events =3D=3D CLOSED) > return; > =20 > - if (!tcp_send_flag(c, conn, RST)) > + if (!tcp_buf_send_flag(c, conn, RST)) > conn_event(c, conn, CLOSED); > } > =20 > @@ -2024,7 +2024,7 @@ static void tcp_conn_from_tap(struct ctx *c, > } else { > tcp_get_sndbuf(conn); > =20 > - if (tcp_send_flag(c, conn, SYN | ACK)) > + if (tcp_buf_send_flag(c, conn, SYN | ACK)) > return; > =20 > conn_event(c, conn, TAP_SYN_ACK_SENT); > @@ -2100,7 +2100,7 @@ static void tcp_data_to_tap(const struct ctx *c, st= ruct tcp_tap_conn *conn, > iov =3D tcp4_l2_iov + tcp4_l2_buf_used++; > iov->iov_len =3D tap_iov_len(c, &b->taph, ip_len); > if (tcp4_l2_buf_used > ARRAY_SIZE(tcp4_l2_buf) - 1) > - tcp_l2_data_buf_flush(c); > + tcp_buf_l2_data_flush(c); > } else if (CONN_V6(conn)) { > struct tcp6_l2_buf_t *b =3D &tcp6_l2_buf[tcp6_l2_buf_used]; > =20 > @@ -2112,12 +2112,12 @@ static void tcp_data_to_tap(const struct ctx *c, = struct tcp_tap_conn *conn, > iov =3D tcp6_l2_iov + tcp6_l2_buf_used++; > iov->iov_len =3D tap_iov_len(c, &b->taph, ip_len); > if (tcp6_l2_buf_used > ARRAY_SIZE(tcp6_l2_buf) - 1) > - tcp_l2_data_buf_flush(c); > + tcp_buf_l2_data_flush(c); > } > } > =20 > /** > - * tcp_data_from_sock() - Handle new data from socket, queue to tap, in = window > + * tcp_buf_data_from_sock() - Handle new data from socket, queue to tap,= in window Same with this one. > * @c: Execution context > * @conn: Connection pointer > * > @@ -2125,7 +2125,7 @@ static void tcp_data_to_tap(const struct ctx *c, st= ruct tcp_tap_conn *conn, > * > * #syscalls recvmsg > */ > -static int tcp_data_from_sock(struct ctx *c, struct tcp_tap_conn *conn) > +static int tcp_buf_data_from_sock(struct ctx *c, struct tcp_tap_conn *co= nn) > { > uint32_t wnd_scaled =3D conn->wnd_from_tap << conn->ws_from_tap; > int fill_bufs, send_bufs =3D 0, last_len, iov_rem =3D 0; > @@ -2169,7 +2169,7 @@ static int tcp_data_from_sock(struct ctx *c, struct= tcp_tap_conn *conn) > =20 > if (( v4 && tcp4_l2_buf_used + fill_bufs > ARRAY_SIZE(tcp4_l2_buf)) || > (!v4 && tcp6_l2_buf_used + fill_bufs > ARRAY_SIZE(tcp6_l2_buf))) { > - tcp_l2_data_buf_flush(c); > + tcp_buf_l2_data_flush(c); > =20 > /* Silence Coverity CWE-125 false positive */ > tcp4_l2_buf_used =3D tcp6_l2_buf_used =3D 0; > @@ -2195,7 +2195,7 @@ static int tcp_data_from_sock(struct ctx *c, struct= tcp_tap_conn *conn) > =20 > if (!len) { > if ((conn->events & (SOCK_FIN_RCVD | TAP_FIN_SENT)) =3D=3D SOCK_FIN_RC= VD) { > - if ((ret =3D tcp_send_flag(c, conn, FIN | ACK))) { > + if ((ret =3D tcp_buf_send_flag(c, conn, FIN | ACK))) { > tcp_rst(c, conn); > return ret; > } > @@ -2378,7 +2378,7 @@ static int tcp_data_from_tap(struct ctx *c, struct = tcp_tap_conn *conn, > max_ack_seq, conn->seq_to_tap); > conn->seq_ack_from_tap =3D max_ack_seq; > conn->seq_to_tap =3D max_ack_seq; > - tcp_data_from_sock(c, conn); > + tcp_buf_data_from_sock(c, conn); > } > =20 > if (!iov_i) > @@ -2394,14 +2394,14 @@ eintr: > * Then swiftly looked away and left. > */ > conn->seq_from_tap =3D seq_from_tap; > - tcp_send_flag(c, conn, ACK); > + tcp_buf_send_flag(c, conn, ACK); > } > =20 > if (errno =3D=3D EINTR) > goto eintr; > =20 > if (errno =3D=3D EAGAIN || errno =3D=3D EWOULDBLOCK) { > - tcp_send_flag(c, conn, ACK_IF_NEEDED); > + tcp_buf_send_flag(c, conn, ACK_IF_NEEDED); > return p->count - idx; > =20 > } > @@ -2411,7 +2411,7 @@ eintr: > if (n < (int)(seq_from_tap - conn->seq_from_tap)) { > partial_send =3D 1; > conn->seq_from_tap +=3D n; > - tcp_send_flag(c, conn, ACK_IF_NEEDED); > + tcp_buf_send_flag(c, conn, ACK_IF_NEEDED); > } else { > conn->seq_from_tap +=3D n; > } > @@ -2424,7 +2424,7 @@ out: > */ > if (conn->seq_dup_ack_approx !=3D (conn->seq_from_tap & 0xff)) { > conn->seq_dup_ack_approx =3D conn->seq_from_tap & 0xff; > - tcp_send_flag(c, conn, DUP_ACK); > + tcp_buf_send_flag(c, conn, DUP_ACK); > } > return p->count - idx; > } > @@ -2438,7 +2438,7 @@ out: > =20 > conn_event(c, conn, TAP_FIN_RCVD); > } else { > - tcp_send_flag(c, conn, ACK_IF_NEEDED); > + tcp_buf_send_flag(c, conn, ACK_IF_NEEDED); > } > =20 > return p->count - idx; > @@ -2474,8 +2474,8 @@ static void tcp_conn_from_sock_finish(struct ctx *c= , struct tcp_tap_conn *conn, > /* The client might have sent data already, which we didn't > * dequeue waiting for SYN,ACK from tap -- check now. > */ > - tcp_data_from_sock(c, conn); > - tcp_send_flag(c, conn, ACK); > + tcp_buf_data_from_sock(c, conn); > + tcp_buf_send_flag(c, conn, ACK); > } > =20 > /** > @@ -2555,7 +2555,7 @@ int tcp_tap_handler(struct ctx *c, uint8_t pif, int= af, > conn->seq_from_tap++; > =20 > shutdown(conn->sock, SHUT_WR); > - tcp_send_flag(c, conn, ACK); > + tcp_buf_send_flag(c, conn, ACK); > conn_event(c, conn, SOCK_FIN_SENT); > =20 > return 1; > @@ -2566,7 +2566,7 @@ int tcp_tap_handler(struct ctx *c, uint8_t pif, int= af, > =20 > tcp_tap_window_update(conn, ntohs(th->window)); > =20 > - tcp_data_from_sock(c, conn); > + tcp_buf_data_from_sock(c, conn); > =20 > if (p->count - idx =3D=3D 1) > return 1; > @@ -2596,7 +2596,7 @@ int tcp_tap_handler(struct ctx *c, uint8_t pif, int= af, > if ((conn->events & TAP_FIN_RCVD) && !(conn->events & SOCK_FIN_SENT)) { > shutdown(conn->sock, SHUT_WR); > conn_event(c, conn, SOCK_FIN_SENT); > - tcp_send_flag(c, conn, ACK); > + tcp_buf_send_flag(c, conn, ACK); > ack_due =3D 0; > } > =20 > @@ -2630,7 +2630,7 @@ static void tcp_connect_finish(struct ctx *c, struc= t tcp_tap_conn *conn) > return; > } > =20 > - if (tcp_send_flag(c, conn, SYN | ACK)) > + if (tcp_buf_send_flag(c, conn, SYN | ACK)) > return; > =20 > conn_event(c, conn, TAP_SYN_ACK_SENT); > @@ -2698,7 +2698,7 @@ static void tcp_tap_conn_from_sock(struct ctx *c, > =20 > conn->wnd_from_tap =3D WINDOW_DEFAULT; > =20 > - tcp_send_flag(c, conn, SYN); > + tcp_buf_send_flag(c, conn, SYN); > conn_flag(c, conn, ACK_FROM_TAP_DUE); > =20 > tcp_get_sndbuf(conn); > @@ -2762,7 +2762,7 @@ void tcp_timer_handler(struct ctx *c, union epoll_r= ef ref) > return; > =20 > if (conn->flags & ACK_TO_TAP_DUE) { > - tcp_send_flag(c, conn, ACK_IF_NEEDED); > + tcp_buf_send_flag(c, conn, ACK_IF_NEEDED); > tcp_timer_ctl(c, conn); > } else if (conn->flags & ACK_FROM_TAP_DUE) { > if (!(conn->events & ESTABLISHED)) { > @@ -2778,7 +2778,7 @@ void tcp_timer_handler(struct ctx *c, union epoll_r= ef ref) > flow_dbg(conn, "ACK timeout, retry"); > conn->retrans++; > conn->seq_to_tap =3D conn->seq_ack_from_tap; > - tcp_data_from_sock(c, conn); > + tcp_buf_data_from_sock(c, conn); > tcp_timer_ctl(c, conn); > } > } else { > @@ -2833,7 +2833,7 @@ void tcp_sock_handler(struct ctx *c, union epoll_re= f ref, uint32_t events) > conn_event(c, conn, SOCK_FIN_RCVD); > =20 > if (events & EPOLLIN) > - tcp_data_from_sock(c, conn); > + tcp_buf_data_from_sock(c, conn); > =20 > if (events & EPOLLOUT) > tcp_update_seqack_wnd(c, conn, 0, NULL); > @@ -3058,10 +3058,10 @@ int tcp_init(struct ctx *c) > tc_hash[b] =3D FLOW_SIDX_NONE; > =20 > if (c->ifi4) > - tcp_sock4_iov_init(c); > + tcp_buf_sock4_iov_init(c); > =20 > if (c->ifi6) > - tcp_sock6_iov_init(c); > + tcp_buf_sock6_iov_init(c); > =20 > memset(init_sock_pool4, 0xff, sizeof(init_sock_pool4)); > memset(init_sock_pool6, 0xff, sizeof(init_sock_pool6)); > diff --git a/tcp.h b/tcp.h > index b9f546d31002..e7dbcfa2ddbd 100644 > --- a/tcp.h > +++ b/tcp.h > @@ -23,7 +23,7 @@ int tcp_init(struct ctx *c); > void tcp_timer(struct ctx *c, const struct timespec *now); > void tcp_defer_handler(struct ctx *c); > =20 > -void tcp_update_l2_buf(const unsigned char *eth_d, const unsigned char *= eth_s); > +void tcp_buf_update_l2(const unsigned char *eth_d, const unsigned char *= eth_s); > =20 > /** > * union tcp_epoll_ref - epoll reference portion for TCP connections --=20 David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson --jG9LC4xwPSQa8T4q Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmXBj+0ACgkQzQJF27ox 2Geksw//TIW+leot8K4Apx4TNovVmmOLWeIikHmzoa7eNVsAWKLPyBCDpMIxC+S+ lwbxPR2fP1SycR60dRx951r30q5lHIcD7zWYERPx14aj4hsCpcd4qtMp10gU/gq0 RypN4r60g5YL5g//fwV3rpFjg7ycG34oZEpv1kNREKAyX/v0rs8HZHaMhyla8M+3 8tZA7T/R+Qw3+fMuzbfAPLZtAsbiep3qBH9Ju3jQ4RD1oqKj5ZyvUcHg47SueSwG uM1emQvoTZ6wYAcXgIB+wxXHFuiwB0cPEUbDkZzsbPXd+KHTOG1qR3epqJUmsLIM bi9LPec2GscKaWsb+AZI7t2JN+W3JgcFkufOJVTt3ADU0ia1JY7ziAw5lpB/P9Ta IvY+3QMmbp/aq0P4CR2lnmBjEXNDZu02HS0/o/uEVR0FLPMiuomClwrYhEXrUIur 2hsybxD7I4gdlpC5PaPJOjjHt11sqZmYYJugK15m2980YvF2dlpNRtiXJ3Im4E2J HMffW/rPMOh5tA+RUAbqKPb8D66TPvEmn3Nr+fEVOUNaHnCYN5HzRlCYpdQsZjdU teOfF8oAQkWovqstfVFbg+HQlC1FMmakkFbLzGkegIBXfgviBy9EBdtP4f9eZRAW Wd5KJf92NWlEhj8trZmUd38zKeV3e46wISwpNkPa3GprrF62mtk= =15iZ -----END PGP SIGNATURE----- --jG9LC4xwPSQa8T4q--