From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTP id C28E15A004E for ; Wed, 17 Jul 2024 17:07:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721228851; 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=PpmjWRyVQqSPWXYxkC8btqoS5Kh7d5Tt8oYGspPADB4=; b=C1+jyszqJCcfifNmDZR0G3Z3xjJ14n8KWqoyPWLwBJyx0rDx+H4hgXaJKJ+Ncl0oo0h4yu fH8pRJYNXe/rAYrEy47I3iteoO8iQatSvfyIU6jWhn3fHJ79TNcwGyJxCe7YD0VMQI4eeO SoZ/M7gXaGvy7R010DTgAO6yY8WGUq8= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-228-jB4SgBOrPgqxlKvWPIEjpg-1; Wed, 17 Jul 2024 11:07:29 -0400 X-MC-Unique: jB4SgBOrPgqxlKvWPIEjpg-1 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-6b798fa1812so4395886d6.2 for ; Wed, 17 Jul 2024 08:07:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721228848; x=1721833648; h=content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=PpmjWRyVQqSPWXYxkC8btqoS5Kh7d5Tt8oYGspPADB4=; b=WsiRzLUQcxN8B4kIWKecIIVuG/5rIddL9zxtUDZ9bGg9J6CtIj3jn37bHkYXoxqCQq 0qud8hVkn/ZU4ou/eyn7nlg5Ye61h68arbDqzLHG8vUqHLYMjYTDi03DI+xUs1/aa3rR 8PTJwui9zgZW0vSVRi4wwZUUT4oFUzOvpck2nJ2dWMq9zizru6QLlSwATUT7o5mHmXIq 90vy/xJCU3EzF7JmSqnEJk3dgJ2ZpEgI7HAAPvMh5jSGTcB87r7zisAuFD968wUXZNzp hosOlrEsugFu1ZqEqH6SAkHD4RvU1zpi14eRvs6UnIvHqcG7Yn7b/fj0nkSbDBtA1Otv sZXg== X-Gm-Message-State: AOJu0YwtDLPFeAceAI8WHlgIk1XkHIrSHbaWgonKzvE0ta+Bvm0Y/HsF yODN37TFk7RHQeRs0//KFKeyI8+AR0HUfl5f+H0xyw8dAGz5Is/SZZn2VVPVTPlc3RzKOCK7wnr OusWfyaCgI8K8rzqNhBG2yMSAMh9+mekgRkQ47RlFbDb51BdM0sXVMYv+LcUp X-Received: by 2002:a05:6214:1c41:b0:6b5:d311:962 with SMTP id 6a1803df08f44-6b78cac978fmr24111066d6.22.1721228848575; Wed, 17 Jul 2024 08:07:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF4D5v0CH4sEQh+qUqPCl2YIulDt5DPOoduXVMKbd3wE712aMi7/JATTb5DvKpcnu22opnvMQ== X-Received: by 2002:a05:6214:1c41:b0:6b5:d311:962 with SMTP id 6a1803df08f44-6b78cac978fmr24110816d6.22.1721228848111; Wed, 17 Jul 2024 08:07:28 -0700 (PDT) Received: from maya.cloud.tilaa.com (maya.cloud.tilaa.com. [164.138.29.33]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6b7619b3414sm42736856d6.69.2024.07.17.08.07.27 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Jul 2024 08:07:27 -0700 (PDT) Date: Wed, 17 Jul 2024 17:06:50 +0200 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH 6/6] doc: Extend zero-recv test with methods using msghdr Message-ID: <20240717170650.07e7ef1b@elisabeth> In-Reply-To: <20240717045223.2309975-7-david@gibson.dropbear.id.au> References: <20240717045223.2309975-1-david@gibson.dropbear.id.au> <20240717045223.2309975-7-david@gibson.dropbear.id.au> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.41; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: FL5JEIB4QKGD7HCMHJQGLJSWTGI3BSBE X-Message-ID-Hash: FL5JEIB4QKGD7HCMHJQGLJSWTGI3BSBE X-MailFrom: sbrivio@redhat.com 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: On Wed, 17 Jul 2024 14:52:23 +1000 David Gibson wrote: > This test program verifies that we can receive and discard datagrams by > using recv() with a NULL buffer and zero-length. Extend it to verify it > also works using recvmsg() and either an iov with a zero-length NULL > buffer or an iov that itself is NULL and zero-length. > > Signed-off-by: David Gibson > --- > doc/platform-requirements/recv-zero.c | 60 +++++++++++++++++++++++---- > 1 file changed, 52 insertions(+), 8 deletions(-) > > diff --git a/doc/platform-requirements/recv-zero.c b/doc/platform-requirements/recv-zero.c > index f161e5c2..ab27704d 100644 > --- a/doc/platform-requirements/recv-zero.c > +++ b/doc/platform-requirements/recv-zero.c > @@ -23,11 +23,27 @@ > > #define DSTPORT 13257U > > +enum discard_method { > + DISCARD_NULL_BUF, > + DISCARD_ZERO_IOV, > + DISCARD_NULL_IOV, > + NUM_METHODS, > +}; > + > /* 127.0.0.1:DSTPORT */ > static const struct sockaddr_in lo_dst = SOCKADDR_INIT(INADDR_LOOPBACK, DSTPORT); > > -static void test_discard(void) > +static void test_discard(enum discard_method method) > { > + struct iovec zero_iov = { .iov_base = NULL, .iov_len = 0, }; > + struct msghdr mh_zero = { > + .msg_iov = &zero_iov, > + .msg_iovlen = 1, > + }; > + struct msghdr mh_null = { > + .msg_iov = NULL, > + .msg_iovlen = 0, > + }; > long token1, token2; > int recv_s, send_s; > ssize_t rc; > @@ -46,11 +62,36 @@ static void test_discard(void) > send_token(send_s, token1); > send_token(send_s, token2); > > - /* cppcheck-suppress nullPointer */ > - rc = recv(recv_s, NULL, 0, MSG_DONTWAIT); > - if (rc < 0) > - die("discarding recv(): %s\n", strerror(errno)); > - > + switch (method) { > + case DISCARD_NULL_BUF: > + /* cppcheck-suppress nullPointer */ > + rc = recv(recv_s, NULL, 0, MSG_DONTWAIT); > + if (rc < 0) > + die("discarding recv(): %s\n", strerror(errno)); > + break; > + > + case DISCARD_ZERO_IOV: > + rc = recvmsg(recv_s, &mh_zero, MSG_DONTWAIT); > + if (rc < 0) > + die("recvmsg() with zero-length buffer: %s\n", > + strerror(errno)); > + if (!((unsigned)mh_zero.msg_flags & MSG_TRUNC)) > + die("Missing MSG_TRUNC flag\n"); > + break; > + > + case DISCARD_NULL_IOV: > + rc = recvmsg(recv_s, &mh_null, MSG_DONTWAIT); > + if (rc < 0) > + die("recvmsg() with zero-length iov: %s\n", > + strerror(errno)); > + if (!((unsigned)mh_null.msg_flags & MSG_TRUNC)) > + die("Missing MSG_TRUNC flag\n"); > + break; > + > + default: > + die("Bad method\n"); > + } > + > recv_token(recv_s, token2); > > /* cppcheck-suppress nullPointer */ > @@ -63,12 +104,15 @@ static void test_discard(void) > > int main(int argc, char *argv[]) > { > + enum discard_method method; > + > (void)argc; > (void)argv; > > - test_discard(); > + for (method = 0; method < NUM_METHODS; method++) > + test_discard(method); > > - printf("Discarding datagrams with a 0-length recv() seems to work\n"); > + printf("Discarding datagrams with a 0-length receives seems to work\n"); Nit: also fixed up on merge: "with 0-length receives". > > exit(0); > } -- Stefano