From patchwork Sun Jun 18 06:24:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 109572 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2320174vqr; Sat, 17 Jun 2023 23:38:00 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6aKaR4j88NpzouXvIFgZG0qM6JfqgaKVFsVc+bO9rk1y3pI9yaKmwhR5m3DvzNYRbMlSg1 X-Received: by 2002:a05:6a20:1601:b0:11f:8a0e:e0cb with SMTP id l1-20020a056a20160100b0011f8a0ee0cbmr4938281pzj.15.1687070279814; Sat, 17 Jun 2023 23:37:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687070279; cv=none; d=google.com; s=arc-20160816; b=kCxDkTw8YoM24kUVhaYwC2WanIZW0cNfn/CCjIuhwRTk5v3goO9T2uef8iBVMBkrRP G0CD5LTnF26ukPpie/zomtiud9hGo8MWXXfeqRcT45u05qHQa28W1dNbPdRwiRmH8siV JcGA3W48zhvsiiOQDB5JmJIPZ7lVKadDq20hijqpjOyQ0+3QwRXqe3iokaok7703LliJ I/kgLn3+ZypjIjDM+EqR+N+47yQWlzPZBD7ua7xgmvEQu9hnx31U/v+IMNbO4ONpe2wV dHEUnf/Ix8pWGevGLiiY81qfNI4aP0e0HYHE6fSMd6TJFT/eROSM6SJr2kyPNSQbME8f 6cXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=zgsAeO7ZZncpPTynVaz+VDbdNBDA85YSMh2T8X4pUbw=; b=vXTVUMu4dD/f+SdsmxMNoyDWEcDMOqcUMJd9wvjXYKIurc9ce/vaq0sinfVVV3PT7A i/tElV//K0QnmUUvLhf1+7oZAN4VGmBWfT6VxZ3VjPGJ6vdjm2YxmD11uSH+22/BmibQ wSJWyAIyS1+LSL4vGSHOPc1cfluhBgnMS7X265AoGXb6FpavFBJQLSU4RnvtGLfOS/ig NdfmUdVwRnpt1D9DVVly3TKNcVtpFuS7fiWtnBYDD9bp6yU7O3egAWC3E9sn0Exscc78 1uXI/cy5EFKnSD2xoopC/dULwBI5GAxRkKePvxKwNqD8AX72itxAyRayM2A82F4CownH VVzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=G0gbPFZR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z11-20020a6552cb000000b00543fd615d2fsi14971545pgp.879.2023.06.17.23.37.45; Sat, 17 Jun 2023 23:37:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=G0gbPFZR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229671AbjFRGaW (ORCPT + 99 others); Sun, 18 Jun 2023 02:30:22 -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 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 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769021406003233078?= X-GMAIL-MSGID: =?utf-8?q?1769021406003233078?= 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_test.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) #define MSG_PEEK_BUF_LEN 64 -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; - fd = vsock_stream_connect(opts->peer_cid, 1234); + if (seqpacket) + fd = vsock_seqpacket_connect(opts->peer_cid, 1234); + else + fd = 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 test_opts *opts) close(fd); } -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 test_opts *opts) ssize_t res; int fd; - fd = vsock_stream_accept(VMADDR_CID_ANY, 1234, NULL); + if (seqpacket) + fd = vsock_seqpacket_accept(VMADDR_CID_ANY, 1234, NULL); + else + fd = 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 test_opts *opts) exit(EXIT_FAILURE); } + if (seqpacket) { + /* This type of socket supports MSG_TRUNC flag, + * so check it with MSG_PEEK. We must get length + * of the message. + */ + res = recv(fd, buf_half, sizeof(buf_half), MSG_PEEK | + MSG_TRUNC); + if (res != sizeof(buf_peek)) { + fprintf(stderr, + "recv(2) + MSG_PEEK | MSG_TRUNC, exp %zu, got %zi\n", + sizeof(buf_half), res); + exit(EXIT_FAILURE); + } + } + res = recv(fd, buf_normal, sizeof(buf_normal), 0); if (res != 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 test_opts *opts) close(fd); } +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) @@ -1113,6 +1148,16 @@ static void test_stream_virtio_skb_merge_server(const struct test_opts *opts) close(fd); } +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[] = { { .name = "SOCK_STREAM connection reset", @@ -1188,6 +1233,11 @@ static struct test_case test_cases[] = { .run_client = test_stream_virtio_skb_merge_client, .run_server = test_stream_virtio_skb_merge_server, }, + { + .name = "SOCK_SEQPACKET MSG_PEEK", + .run_client = test_seqpacket_msg_peek_client, + .run_server = test_seqpacket_msg_peek_server, + }, {}, };