From nobody Mon Feb 9 02:27:22 2026 Delivered-To: wpasupplicant.patchew@gmail.com Received: by 2002:a02:cbb9:0:0:0:0:0 with SMTP id v25csp7705157jap; Tue, 16 Nov 2021 05:59:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJxLiC6WZQM9d8nJ/a/BOjdSrGxnpGCx3Ea0dipz9uLjnjO5IbYBRhdX3YcBtVNynRQl4scj X-Received: by 2002:aa7:83cd:0:b0:480:9e79:fae5 with SMTP id j13-20020aa783cd000000b004809e79fae5mr40529579pfn.42.1637071170152; Tue, 16 Nov 2021 05:59:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1637071170; cv=none; d=google.com; s=arc-20160816; b=oW4uw9Gk5YFV8lwg2ZBfdRd4KpFwUSZAJ/p6iPYqulikWT/HskVcuK/sdPIJFkBLv4 Vc8JKdx7PahbkDwalZkBmZAhSwYjBf/mXI2XZjMuoLIaySLjNyjoJGnkDWYSl8XU2X46 5cRQzTFBuH2QI6KvSKU/x4KxZxCW+DzIlyQh+1IG5fD1VpaPplwOlj/mY396WMfvwGW7 H2JXhxllODDx5tlNpb5uPqPYwm3Vj3GvpOf8vvklKJbzcouXBygF+rF7ElKvWZxOivKR 9pWdD+OxknJcznwGIpQJfWx+Tr/FLhyokIoJuDqIXCOqb7ERNQN/ekhcBqFib9N/Ej6r JovA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=qgkT64WZVTuVA59luxJdqTNCqDHNJebqupWXp7xOfos=; b=FftTr98hk2pH4gu1bHGs7U8Quw657w1H83+nxnw7u/mEQ/glLNeMMn5Plv+i+xGsJ7 n1MyR9QlIdK4wRCDCNELTLnmWl2oFe9KXo0IoZxOqUunQt3VqPY0NyZdfZAK1SgLtepF h33Up2etKHCdfnWIqdaFnRdMceWUMKQlJV7dNcEBnM4kzT/FcBDRdUgx8KLFdsTVgkbq nIUbongU8z44P2dBAVIp013vgIIagx6oxpOxywdQ3dkyOq6WUt6orGr1Gfbn909wcYL9 Fu1GHxsdkvHg/y0W/R7uAUbi+VnUcHKBc+4t9GRmYGD5v0Cs1TU/UsbxbdfT13OMFg43 ZHgw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of mptcp+bounces-2447-wpasupplicant.patchew=gmail.com@lists.linux.dev designates 2604:1380:1000:8100::1 as permitted sender) smtp.mailfrom="mptcp+bounces-2447-wpasupplicant.patchew=gmail.com@lists.linux.dev" Return-Path: Received: from sjc.edge.kernel.org (sjc.edge.kernel.org. [2604:1380:1000:8100::1]) by mx.google.com with ESMTPS id t13si104212plg.85.2021.11.16.05.59.30 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Nov 2021 05:59:30 -0800 (PST) Received-SPF: pass (google.com: domain of mptcp+bounces-2447-wpasupplicant.patchew=gmail.com@lists.linux.dev designates 2604:1380:1000:8100::1 as permitted sender) client-ip=2604:1380:1000:8100::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of mptcp+bounces-2447-wpasupplicant.patchew=gmail.com@lists.linux.dev designates 2604:1380:1000:8100::1 as permitted sender) smtp.mailfrom="mptcp+bounces-2447-wpasupplicant.patchew=gmail.com@lists.linux.dev" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sjc.edge.kernel.org (Postfix) with ESMTPS id D9AA93E0F0C for ; Tue, 16 Nov 2021 13:59:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6EADF2C96; Tue, 16 Nov 2021 13:59:29 +0000 (UTC) X-Original-To: mptcp@lists.linux.dev Received: from Chamillionaire.breakpoint.cc (Chamillionaire.breakpoint.cc [193.142.43.52]) (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 F0E082C85 for ; Tue, 16 Nov 2021 13:59:27 +0000 (UTC) Received: from fw by Chamillionaire.breakpoint.cc with local (Exim 4.92) (envelope-from ) id 1mmyze-0003Tg-9U; Tue, 16 Nov 2021 14:59:26 +0100 From: Florian Westphal To: Cc: Florian Westphal Subject: [PATCH mptcp-next v3 2/4] selftests: mptcp: add TCP_INQ support Date: Tue, 16 Nov 2021 14:48:02 +0100 Message-Id: <20211116134804.30090-3-fw@strlen.de> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211116134804.30090-1-fw@strlen.de> References: <20211116134804.30090-1-fw@strlen.de> Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Do checks on the returned inq counter. Fail on: 1. Huge value (> 1 kbyte, test case files are 1 kb) 2. last hint larger than returned bytes when read was short 3. erronenous indication of EOF. 3) happens when a hint of X bytes reads X-1 on next call but next recvmsg returns more data (instead of EOF). Signed-off-by: Florian Westphal --- .../selftests/net/mptcp/mptcp_connect.c | 58 ++++++++++++++++++- .../selftests/net/mptcp/mptcp_sockopt.sh | 4 +- 2 files changed, 59 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/net/mptcp/mptcp_connect.c b/tools/test= ing/selftests/net/mptcp/mptcp_connect.c index ada9b80774d4..0e396af4545a 100644 --- a/tools/testing/selftests/net/mptcp/mptcp_connect.c +++ b/tools/testing/selftests/net/mptcp/mptcp_connect.c @@ -73,12 +73,20 @@ static uint32_t cfg_mark; struct cfg_cmsg_types { unsigned int cmsg_enabled:1; unsigned int timestampns:1; + unsigned int tcp_inq:1; }; =20 struct cfg_sockopt_types { unsigned int transparent:1; }; =20 +struct tcp_inq_state { + unsigned int last; + bool expect_eof; +}; + +static struct tcp_inq_state tcp_inq; + static struct cfg_cmsg_types cfg_cmsg_types; static struct cfg_sockopt_types cfg_sockopt_types; =20 @@ -389,7 +397,9 @@ static size_t do_write(const int fd, char *buf, const s= ize_t len) static void process_cmsg(struct msghdr *msgh) { struct __kernel_timespec ts; + bool inq_found =3D false; bool ts_found =3D false; + unsigned int inq =3D 0; struct cmsghdr *cmsg; =20 for (cmsg =3D CMSG_FIRSTHDR(msgh); cmsg ; cmsg =3D CMSG_NXTHDR(msgh, cmsg= )) { @@ -398,12 +408,27 @@ static void process_cmsg(struct msghdr *msgh) ts_found =3D true; continue; } + if (cmsg->cmsg_level =3D=3D IPPROTO_TCP && cmsg->cmsg_type =3D=3D TCP_CM= _INQ) { + memcpy(&inq, CMSG_DATA(cmsg), sizeof(inq)); + inq_found =3D true; + continue; + } + } =20 if (cfg_cmsg_types.timestampns) { if (!ts_found) xerror("TIMESTAMPNS not present\n"); } + + if (cfg_cmsg_types.tcp_inq) { + if (!inq_found) + xerror("TCP_INQ not present\n"); + + if (inq > 1024) + xerror("tcp_inq %u is larger than one kbyte\n", inq); + tcp_inq.last =3D inq; + } } =20 static ssize_t do_recvmsg_cmsg(const int fd, char *buf, const size_t len) @@ -420,10 +445,23 @@ static ssize_t do_recvmsg_cmsg(const int fd, char *bu= f, const size_t len) .msg_controllen =3D sizeof(msg_buf), }; int flags =3D 0; + unsigned int last_hint =3D tcp_inq.last; int ret =3D recvmsg(fd, &msg, flags); =20 - if (ret <=3D 0) + if (ret <=3D 0) { + if (ret =3D=3D 0 && tcp_inq.expect_eof) + return ret; + + if (ret =3D=3D 0 && cfg_cmsg_types.tcp_inq) + if (last_hint !=3D 1 && last_hint !=3D 0) + xerror("EOF but last tcp_inq hint was %u\n", last_hint); + return ret; + } + + if (tcp_inq.expect_eof) + xerror("expected EOF, last_hint %u, now %u\n", + last_hint, tcp_inq.last); =20 if (msg.msg_controllen && !cfg_cmsg_types.cmsg_enabled) xerror("got %lu bytes of cmsg data, expected 0\n", @@ -435,6 +473,17 @@ static ssize_t do_recvmsg_cmsg(const int fd, char *buf= , const size_t len) if (msg.msg_controllen) process_cmsg(&msg); =20 + if (cfg_cmsg_types.tcp_inq) { + if ((size_t)ret < len && last_hint > (unsigned int)ret) { + if (ret + 1 !=3D (int)last_hint) { + int next =3D read(fd, msg_buf, sizeof(msg_buf)); + + xerror("read %u of %u, last_hint was %u tcp_inq hint now %u next_read = returned %d/%m\n", ret, (unsigned int)len, last_hint, tcp_inq.last, next); + } else + tcp_inq.expect_eof =3D true; + } + } + return ret; } =20 @@ -944,6 +993,8 @@ static void apply_cmsg_types(int fd, const struct cfg_c= msg_types *cmsg) =20 if (cmsg->timestampns) xsetsockopt(fd, SOL_SOCKET, SO_TIMESTAMPNS_NEW, &on, sizeof(on)); + if (cmsg->tcp_inq) + xsetsockopt(fd, IPPROTO_TCP, TCP_INQ, &on, sizeof(on)); } =20 static void parse_cmsg_types(const char *type) @@ -965,6 +1016,11 @@ static void parse_cmsg_types(const char *type) return; } =20 + if (strncmp(type, "TCPINQ", len) =3D=3D 0) { + cfg_cmsg_types.tcp_inq =3D 1; + return; + } + fprintf(stderr, "Unrecognized cmsg option %s\n", type); exit(1); } diff --git a/tools/testing/selftests/net/mptcp/mptcp_sockopt.sh b/tools/tes= ting/selftests/net/mptcp/mptcp_sockopt.sh index 41de643788b8..c8c364369599 100755 --- a/tools/testing/selftests/net/mptcp/mptcp_sockopt.sh +++ b/tools/testing/selftests/net/mptcp/mptcp_sockopt.sh @@ -178,7 +178,7 @@ do_transfer() =20 timeout ${timeout_test} \ ip netns exec ${listener_ns} \ - $mptcp_connect -t ${timeout_poll} -l -M 1 -p $port -s ${srv_proto} -c T= IMESTAMPNS \ + $mptcp_connect -t ${timeout_poll} -l -M 1 -p $port -s ${srv_proto} -c T= IMESTAMPNS,TCPINQ \ ${local_addr} < "$sin" > "$sout" & spid=3D$! =20 @@ -186,7 +186,7 @@ do_transfer() =20 timeout ${timeout_test} \ ip netns exec ${connector_ns} \ - $mptcp_connect -t ${timeout_poll} -M 2 -p $port -s ${cl_proto} -c TIMES= TAMPNS \ + $mptcp_connect -t ${timeout_poll} -M 2 -p $port -s ${cl_proto} -c TIMES= TAMPNS,TCPINQ \ $connect_addr < "$cin" > "$cout" & =20 cpid=3D$! --=20 2.32.0