From: Stefano Brivio <sbrivio@redhat.com>
To: David Gibson <david@gibson.dropbear.id.au>
Cc: passt-dev@passt.top
Subject: Re: [PATCH 6/6] doc: Extend zero-recv test with methods using msghdr
Date: Wed, 17 Jul 2024 17:06:50 +0200 [thread overview]
Message-ID: <20240717170650.07e7ef1b@elisabeth> (raw)
In-Reply-To: <20240717045223.2309975-7-david@gibson.dropbear.id.au>
On Wed, 17 Jul 2024 14:52:23 +1000
David Gibson <david@gibson.dropbear.id.au> 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 <david@gibson.dropbear.id.au>
> ---
> 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
next prev parent reply other threads:[~2024-07-17 15:07 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-17 4:52 [PATCH 0/6] Of course there are more flow table preliminaries David Gibson
2024-07-17 4:52 ` [PATCH 1/6] flow, icmp, tcp: Clean up helpers for getting flow from index David Gibson
2024-07-17 4:52 ` [PATCH 2/6] flow, tcp_splice: Prefer 'sidei' for variables referring to side index David Gibson
2024-07-17 5:20 ` Stefano Brivio
2024-07-17 5:28 ` David Gibson
2024-07-17 5:50 ` David Gibson
2024-07-17 7:20 ` Stefano Brivio
2024-07-17 7:27 ` David Gibson
2024-07-17 4:52 ` [PATCH 3/6] flow: Introduce flow_foreach_sidei() macro David Gibson
2024-07-17 4:52 ` [PATCH 4/6] tcp_splice: Use parameterised macros for per-side event/flag bits David Gibson
2024-07-17 4:52 ` [PATCH 5/6] doc: Test behaviour of closing duplicate UDP sockets David Gibson
2024-07-17 4:52 ` [PATCH 6/6] doc: Extend zero-recv test with methods using msghdr David Gibson
2024-07-17 15:06 ` Stefano Brivio [this message]
2024-07-17 15:07 ` [PATCH 0/6] Of course there are more flow table preliminaries Stefano Brivio
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240717170650.07e7ef1b@elisabeth \
--to=sbrivio@redhat.com \
--cc=david@gibson.dropbear.id.au \
--cc=passt-dev@passt.top \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://passt.top/passt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).