From nobody Mon Feb 9 14:14:21 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 00910C0015E for ; Sun, 18 Jun 2023 06:30:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229685AbjFRGaX (ORCPT ); Sun, 18 Jun 2023 02:30:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229571AbjFRGaM (ORCPT ); Sun, 18 Jun 2023 02:30:12 -0400 Received: from mx.sberdevices.ru (mx.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77EDB171B; Sat, 17 Jun 2023 23:30:06 -0700 (PDT) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id D9DD95FD27; Sun, 18 Jun 2023 09:30:02 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1687069802; bh=zgsAeO7ZZncpPTynVaz+VDbdNBDA85YSMh2T8X4pUbw=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=G0gbPFZRqGQHbjLXDcfSz97/AlUdJ/hYlNUzaQc7QF10oG0HeEYx/zuqoqlV1jjET 648yw2Y70OznSk4NQPFE+NmBfcGeMd4p+gM0ym85lxvKeFID49HNSOvbTnlN6wQD4u otMX2uT/MQ4vl89kxgWLsXajiDqz4Jiey+gvyi14OU6CtKsEcHdFB4Y4R/3U4zqmCf xPJiQHiiylOGiBbV8t4OdMdFXXLPW0WTi5ZnTU7Y/xu/HWiszk++pHCjwvUJOvZ8rl RpGBhXKP19QYIi1D73SwjoeQdSZDhnKtcLhtMriNxsRMCgHNayA7JDw23UGDGJQeKh MAnBFBOE2FGCg== Received: from p-i-exch-sc-m01.sberdevices.ru (p-i-exch-sc-m01.sberdevices.ru [172.16.192.107]) by mx.sberdevices.ru (Postfix) with ESMTP; Sun, 18 Jun 2023 09:30:02 +0300 (MSK) From: Arseniy Krasnov To: Stefan Hajnoczi , Stefano Garzarella , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Michael S. Tsirkin" , Jason Wang , Bobby Eshleman CC: , , , , , , , Arseniy Krasnov Subject: [RFC PATCH v1 4/4] vsock/test: MSG_PEEK test for SOCK_SEQPACKET Date: Sun, 18 Jun 2023 09:24:51 +0300 Message-ID: <20230618062451.79980-5-AVKrasnov@sberdevices.ru> X-Mailer: git-send-email 2.35.0 In-Reply-To: <20230618062451.79980-1-AVKrasnov@sberdevices.ru> References: <20230618062451.79980-1-AVKrasnov@sberdevices.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [172.16.1.6] X-ClientProxiedBy: S-MS-EXCH01.sberdevices.ru (172.16.1.4) To p-i-exch-sc-m01.sberdevices.ru (172.16.192.107) X-KSMG-Rule-ID: 4 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiPhishing: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 1.1.2.30, bases: 2023/06/18 01:53:00 #21507494 X-KSMG-AntiVirus-Status: Clean, skipped Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This adds MSG_PEEK test for SOCK_SEQPACKET. It works in the same way as SOCK_STREAM test, except it also tests MSG_TRUNC flag. Signed-off-by: Arseniy Krasnov --- tools/testing/vsock/vsock_test.c | 58 +++++++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 4 deletions(-) diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_t= est.c index 104ac102e411..2bacd0ea1195 100644 --- a/tools/testing/vsock/vsock_test.c +++ b/tools/testing/vsock/vsock_test.c @@ -257,13 +257,18 @@ static void test_stream_multiconn_server(const struct= test_opts *opts) =20 #define MSG_PEEK_BUF_LEN 64 =20 -static void test_stream_msg_peek_client(const struct test_opts *opts) +static void __test_msg_peek_client(const struct test_opts *opts, + bool seqpacket) { unsigned char buf[MSG_PEEK_BUF_LEN]; int fd; int i; =20 - fd =3D vsock_stream_connect(opts->peer_cid, 1234); + if (seqpacket) + fd =3D vsock_seqpacket_connect(opts->peer_cid, 1234); + else + fd =3D vsock_stream_connect(opts->peer_cid, 1234); + if (fd < 0) { perror("connect"); exit(EXIT_FAILURE); @@ -278,7 +283,8 @@ static void test_stream_msg_peek_client(const struct te= st_opts *opts) close(fd); } =20 -static void test_stream_msg_peek_server(const struct test_opts *opts) +static void __test_msg_peek_server(const struct test_opts *opts, + bool seqpacket) { unsigned char buf_half[MSG_PEEK_BUF_LEN / 2]; unsigned char buf_normal[MSG_PEEK_BUF_LEN]; @@ -286,7 +292,11 @@ static void test_stream_msg_peek_server(const struct t= est_opts *opts) ssize_t res; int fd; =20 - fd =3D vsock_stream_accept(VMADDR_CID_ANY, 1234, NULL); + if (seqpacket) + fd =3D vsock_seqpacket_accept(VMADDR_CID_ANY, 1234, NULL); + else + fd =3D vsock_stream_accept(VMADDR_CID_ANY, 1234, NULL); + if (fd < 0) { perror("accept"); exit(EXIT_FAILURE); @@ -328,6 +338,21 @@ static void test_stream_msg_peek_server(const struct t= est_opts *opts) exit(EXIT_FAILURE); } =20 + if (seqpacket) { + /* This type of socket supports MSG_TRUNC flag, + * so check it with MSG_PEEK. We must get length + * of the message. + */ + res =3D recv(fd, buf_half, sizeof(buf_half), MSG_PEEK | + MSG_TRUNC); + if (res !=3D sizeof(buf_peek)) { + fprintf(stderr, + "recv(2) + MSG_PEEK | MSG_TRUNC, exp %zu, got %zi\n", + sizeof(buf_half), res); + exit(EXIT_FAILURE); + } + } + res =3D recv(fd, buf_normal, sizeof(buf_normal), 0); if (res !=3D sizeof(buf_normal)) { fprintf(stderr, "recv(2), expected %zu, got %zi\n", @@ -344,6 +369,16 @@ static void test_stream_msg_peek_server(const struct t= est_opts *opts) close(fd); } =20 +static void test_stream_msg_peek_client(const struct test_opts *opts) +{ + return __test_msg_peek_client(opts, false); +} + +static void test_stream_msg_peek_server(const struct test_opts *opts) +{ + return __test_msg_peek_server(opts, false); +} + #define SOCK_BUF_SIZE (2 * 1024 * 1024) #define MAX_MSG_SIZE (32 * 1024) =20 @@ -1113,6 +1148,16 @@ static void test_stream_virtio_skb_merge_server(cons= t struct test_opts *opts) close(fd); } =20 +static void test_seqpacket_msg_peek_client(const struct test_opts *opts) +{ + return __test_msg_peek_client(opts, true); +} + +static void test_seqpacket_msg_peek_server(const struct test_opts *opts) +{ + return __test_msg_peek_server(opts, true); +} + static struct test_case test_cases[] =3D { { .name =3D "SOCK_STREAM connection reset", @@ -1188,6 +1233,11 @@ static struct test_case test_cases[] =3D { .run_client =3D test_stream_virtio_skb_merge_client, .run_server =3D test_stream_virtio_skb_merge_server, }, + { + .name =3D "SOCK_SEQPACKET MSG_PEEK", + .run_client =3D test_seqpacket_msg_peek_client, + .run_server =3D test_seqpacket_msg_peek_server, + }, {}, }; =20 --=20 2.25.1