From nobody Sat Apr 20 13:52:33 2024 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E655EBE2 for ; Wed, 9 Nov 2022 14:52:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668005568; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WIQ7PrtQQKiM/Ge3a6CQ6FqaNFzFWAd8tuOv8cLP8IU=; b=TJ/AYTeboKsbkgTw62GLGpJPJEMSiYF3Lupl5hdCW6Md6RaHCFW0gQwgvuXz4Jo0CbFmsS oUabHjTUYS39G/8PIJD5/rg2R4MDgxYukQtYOR9Hn6NEyrvF1PEID95Nugxd1XtKJIQ0e6 hg9qbCK5sL/CHPlN6e10cPoQPvNz9mw= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-532-qVjuBVdMNO6qYn7W_YFZCA-1; Wed, 09 Nov 2022 09:52:44 -0500 X-MC-Unique: qVjuBVdMNO6qYn7W_YFZCA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 533341C0CE61; Wed, 9 Nov 2022 14:52:44 +0000 (UTC) Received: from gerbillo.redhat.com (unknown [10.39.194.116]) by smtp.corp.redhat.com (Postfix) with ESMTP id AD35D2028E90; Wed, 9 Nov 2022 14:52:43 +0000 (UTC) From: Paolo Abeni To: mptcp@lists.linux.dev Cc: Dmytro Shytyi Subject: [PATCH net-next] Squash-to: "selftests: mptcp: mptfo Initiator/Listener" Date: Wed, 9 Nov 2022 15:52:31 +0100 Message-Id: <41b40e837c47147ce713ae0d35a916471d36f82d.1667993466.git.pabeni@redhat.com> In-Reply-To: <4edc02c8a8e040d0ac212ff61d9256c8148f2429.1667993416.git.pabeni@redhat.com> References: <4edc02c8a8e040d0ac212ff61d9256c8148f2429.1667993416.git.pabeni@redhat.com> Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8"; x-default="true" The TFO is allowed to send less data than the provided one, we need to track more status info to properly allow the next sendmsg() starting from the next to send byte. Signed-off-by: Paolo Abeni --- .../selftests/net/mptcp/mptcp_connect.c | 118 ++++++++---------- 1 file changed, 55 insertions(+), 63 deletions(-) diff --git a/tools/testing/selftests/net/mptcp/mptcp_connect.c b/tools/test= ing/selftests/net/mptcp/mptcp_connect.c index 4bc855159c52..134e569cd75a 100644 --- a/tools/testing/selftests/net/mptcp/mptcp_connect.c +++ b/tools/testing/selftests/net/mptcp/mptcp_connect.c @@ -26,13 +26,11 @@ =20 #include #include -#include =20 +#include #include #include =20 - - extern int optind; =20 #ifndef IPPROTO_MPTCP @@ -93,6 +91,12 @@ struct tcp_inq_state { bool expect_eof; }; =20 +struct wstate { + char buf[8192]; + unsigned int len; + unsigned int off; +}; + static struct tcp_inq_state tcp_inq; =20 static struct cfg_cmsg_types cfg_cmsg_types; @@ -239,7 +243,7 @@ static void set_mptfo(int fd, int pf) { int qlen =3D 25; =20 - if (setsockopt(fd, SOL_TCP, TCP_FASTOPEN, &qlen, sizeof(qlen)) =3D=3D -1) + if (setsockopt(fd, IPPROTO_TCP, TCP_FASTOPEN, &qlen, sizeof(qlen)) =3D=3D= -1) perror("TCP_FASTOPEN"); } =20 @@ -345,17 +349,14 @@ static int sock_listen_mptcp(const char * const liste= naddr, static int sock_connect_mptcp(const char * const remoteaddr, const char * const port, int proto, struct addrinfo **peer, - int infd, - unsigned int *woff) + int infd, struct wstate *winfo) { struct addrinfo hints =3D { .ai_protocol =3D IPPROTO_TCP, .ai_socktype =3D SOCK_STREAM, }; struct addrinfo *a, *addr; - unsigned int wlen =3D 0; int syn_copied =3D 0; - char wbuf[8192]; int sock =3D -1; =20 hints.ai_family =3D pf; @@ -374,13 +375,15 @@ static int sock_connect_mptcp(const char * const remo= teaddr, set_mark(sock, cfg_mark); =20 if (cfg_sockopt_types.mptfo) { - if (wlen =3D=3D 0) - wlen =3D read(infd, wbuf, sizeof(wbuf)); + winfo->len =3D read(infd, winfo->buf, sizeof(winfo->buf)); =20 - syn_copied =3D sendto(sock, wbuf, wlen, MSG_FASTOPEN, + syn_copied =3D sendto(sock, winfo->buf, winfo->len, MSG_FASTOPEN, a->ai_addr, a->ai_addrlen); + if (syn_copied < 0) + perror("sendto"); if (syn_copied) { - *woff =3D wlen; + winfo->off =3D syn_copied; + winfo->len -=3D syn_copied; *peer =3D a; break; /* success */ } @@ -610,14 +613,13 @@ static void shut_wr(int fd) } =20 static int copyfd_io_poll(int infd, int peerfd, int outfd, - bool *in_closed_after_out, unsigned int woff) + bool *in_closed_after_out, struct wstate *winfo) { struct pollfd fds =3D { .fd =3D peerfd, .events =3D POLLIN | POLLOUT, }; - unsigned int wlen =3D 0, total_wlen =3D 0, total_rlen =3D 0; - char wbuf[8192]; + unsigned int total_wlen =3D 0, total_rlen =3D 0; =20 set_nonblock(peerfd, true); =20 @@ -677,19 +679,19 @@ static int copyfd_io_poll(int infd, int peerfd, int o= utfd, } =20 if (fds.revents & POLLOUT) { - if (wlen =3D=3D 0) { - woff =3D 0; - wlen =3D read(infd, wbuf, sizeof(wbuf)); + if (winfo->len =3D=3D 0) { + winfo->off =3D 0; + winfo->len =3D read(infd, winfo->buf, sizeof(winfo->buf)); } =20 - if (wlen > 0) { + if (winfo->len > 0) { ssize_t bw; =20 /* limit the total amount of written data to the trunc value */ - if (cfg_truncate > 0 && wlen + total_wlen > cfg_truncate) - wlen =3D cfg_truncate - total_wlen; + if (cfg_truncate > 0 && winfo->len + total_wlen > cfg_truncate) + winfo->len =3D cfg_truncate - total_wlen; =20 - bw =3D do_rnd_write(peerfd, wbuf + woff, wlen); + bw =3D do_rnd_write(peerfd, winfo->buf + winfo->off, winfo->len); if (bw < 0) { if (cfg_rcv_trunc) return 0; @@ -697,10 +699,10 @@ static int copyfd_io_poll(int infd, int peerfd, int o= utfd, return 111; } =20 - woff +=3D bw; - wlen -=3D bw; + winfo->off +=3D bw; + winfo->len -=3D bw; total_wlen +=3D bw; - } else if (wlen =3D=3D 0) { + } else if (winfo->len =3D=3D 0) { /* We have no more data to send. */ fds.events &=3D ~POLLOUT; =20 @@ -878,7 +880,7 @@ static int copyfd_io_sendfile(int infd, int peerfd, int= outfd, return err; } =20 -static int copyfd_io(int infd, int peerfd, int outfd, bool close_peerfd, u= nsigned int woff) +static int copyfd_io(int infd, int peerfd, int outfd, bool close_peerfd, s= truct wstate *winfo) { bool in_closed_after_out =3D false; struct timespec start, end; @@ -890,7 +892,7 @@ static int copyfd_io(int infd, int peerfd, int outfd, b= ool close_peerfd, unsigne =20 switch (cfg_mode) { case CFG_MODE_POLL: - ret =3D copyfd_io_poll(infd, peerfd, outfd, &in_closed_after_out, woff); + ret =3D copyfd_io_poll(infd, peerfd, outfd, &in_closed_after_out, winfo); break; =20 case CFG_MODE_MMAP: @@ -1038,6 +1040,7 @@ static void maybe_close(int fd) int main_loop_s(int listensock) { struct sockaddr_storage ss; + struct wstate winfo; struct pollfd polls; socklen_t salen; int remotesock; @@ -1072,7 +1075,8 @@ int main_loop_s(int listensock) =20 SOCK_TEST_TCPULP(remotesock, 0); =20 - copyfd_io(fd, remotesock, 1, true, 0); + memset(&winfo, 0, sizeof(winfo)); + copyfd_io(fd, remotesock, 1, true, &winfo); } else { perror("accept"); return 1; @@ -1210,53 +1214,40 @@ void xdisconnect(int fd, int addrlen) =20 int main_loop(void) { - int fd, ret, fd_in =3D 0; + int fd =3D 0, ret, fd_in =3D 0; struct addrinfo *peer; - unsigned int woff =3D 0; - - if (!cfg_sockopt_types.mptfo) { - /* listener is ready. */ - fd =3D sock_connect_mptcp(cfg_host, cfg_port, cfg_sock_proto, &peer, 0, = 0); - if (fd < 0) - return 2; -again: - check_getpeername_connect(fd); + struct wstate winfo; =20 - SOCK_TEST_TCPULP(fd, cfg_sock_proto); - - if (cfg_rcvbuf) - set_rcvbuf(fd, cfg_rcvbuf); - if (cfg_sndbuf) - set_sndbuf(fd, cfg_sndbuf); - if (cfg_cmsg_types.cmsg_enabled) - apply_cmsg_types(fd, &cfg_cmsg_types); - } - - if (cfg_input) { + if (cfg_input && cfg_sockopt_types.mptfo) { fd_in =3D open(cfg_input, O_RDONLY); if (fd < 0) xerror("can't open %s:%d", cfg_input, errno); } =20 - if (cfg_sockopt_types.mptfo) { - /* sendto() instead of connect */ - fd =3D sock_connect_mptcp(cfg_host, cfg_port, cfg_sock_proto, &peer, fd_= in, &woff); - if (fd < 0) - return 2; + memset(&winfo, 0, sizeof(winfo)); + fd =3D sock_connect_mptcp(cfg_host, cfg_port, cfg_sock_proto, &peer, fd_i= n, &winfo); + if (fd < 0) + return 2; =20 - check_getpeername_connect(fd); +again: + check_getpeername_connect(fd); =20 - SOCK_TEST_TCPULP(fd, cfg_sock_proto); + SOCK_TEST_TCPULP(fd, cfg_sock_proto); =20 - if (cfg_rcvbuf) - set_rcvbuf(fd, cfg_rcvbuf); - if (cfg_sndbuf) - set_sndbuf(fd, cfg_sndbuf); - if (cfg_cmsg_types.cmsg_enabled) - apply_cmsg_types(fd, &cfg_cmsg_types); + if (cfg_rcvbuf) + set_rcvbuf(fd, cfg_rcvbuf); + if (cfg_sndbuf) + set_sndbuf(fd, cfg_sndbuf); + if (cfg_cmsg_types.cmsg_enabled) + apply_cmsg_types(fd, &cfg_cmsg_types); + + if (cfg_input && !cfg_sockopt_types.mptfo) { + fd_in =3D open(cfg_input, O_RDONLY); + if (fd < 0) + xerror("can't open %s:%d", cfg_input, errno); } =20 - ret =3D copyfd_io(fd_in, fd, 1, 0, 0); + ret =3D copyfd_io(fd_in, fd, 1, 0, &winfo); if (ret) return ret; =20 @@ -1273,6 +1264,7 @@ int main_loop(void) xerror("can't reconnect: %d", errno); if (cfg_input) close(fd_in); + memset(&winfo, 0, sizeof(winfo)); goto again; } else { close(fd); --=20 2.38.1