mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Michal Luczaj <mhal@rbox.co>
To: Jiayuan Chen <mrpre@163.com>
Cc: Andrii Nakryiko <andrii@kernel.org>,
	Eduard Zingerman <eddyz87@gmail.com>,
	Mykola Lysenko <mykolal@fb.com>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Martin KaFai Lau <martin.lau@linux.dev>,
	Song Liu <song@kernel.org>,
	Yonghong Song <yonghong.song@linux.dev>,
	John Fastabend <john.fastabend@gmail.com>,
	KP Singh <kpsingh@kernel.org>,
	Stanislav Fomichev <sdf@fomichev.me>, Hao Luo <haoluo@google.com>,
	Jiri Olsa <jolsa@kernel.org>, Shuah Khan <shuah@kernel.org>,
	Jonathan Corbet <corbet@lwn.net>,
	bpf@vger.kernel.org, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org,
	Jakub Sitnicki <jakub@cloudflare.com>
Subject: Re: [PATCH bpf-next v2 5/9] selftests/bpf: Add selftest for sockmap/hashmap redirection
Date: Wed, 16 Apr 2025 14:33:20 +0200	[thread overview]
Message-ID: <66bf942f-dfdb-4ce9-bd95-8b734e7afa53@rbox.co> (raw)
In-Reply-To: <ghhz3pi3oh3rylyd5t6gfa3x7m35q4ei5liwytmcbfit4r4pit@4al5vrpx7exl>

On 4/11/25 16:31, Jiayuan Chen wrote:
> On Fri, Apr 11, 2025 at 01:32:41PM +0200, Michal Luczaj wrote:
>> +static void test_send_redir_recv(int sd_send, int send_flags, int sd_peer,
>> +				 int sd_in, int sd_out, int sd_recv,
>> +				 struct maps *maps, int status)
>> +{
>> +	unsigned int drop, pass;
>> +	char *send_buf = "ab";
>> +	char recv_buf = '\0';
>> +	ssize_t n, len = 1;
>> +	/* Zero out the verdict map */
>> +	if (xbpf_map_update_elem(maps->verd, &u32(SK_DROP), &u32(0), BPF_ANY) ||
>> +	    xbpf_map_update_elem(maps->verd, &u32(SK_PASS), &u32(0), BPF_ANY))
>> +		return;
>> +
>> +	if (xbpf_map_update_elem(maps->in, &u32(0), &u64(sd_in), BPF_NOEXIST))
>> +		return;
>> +
>> +	if (xbpf_map_update_elem(maps->out, &u32(0), &u64(sd_out), BPF_NOEXIST))
>> +		goto del_in;
>> +
>> +	/* Last byte is OOB data when send_flags has MSG_OOB bit set */
>> +	if (send_flags & MSG_OOB)
>> +		len++;
>> +	n = send(sd_send, send_buf, len, send_flags);
>> +	if (n >= 0 && n < len)
>> +		FAIL("incomplete send");
>> +	if (n < 0) {
>> +		/* sk_msg redirect combo not supported? */
>> +		if (status & SUPPORTED || errno != EACCES)
>> +			FAIL_ERRNO("send");
>> +		goto out;
>> +	}
>> +
>> +	if (!(status & SUPPORTED)) {
>> +		handle_unsupported(sd_send, sd_peer, sd_in, sd_out, sd_recv,
>> +				   maps->verd, status);
>> +		goto out;
>> +	}
>> +
>> +	errno = 0;
>> +	n = recv_timeout(sd_recv, &recv_buf, 1, 0, IO_TIMEOUT_SEC);
>> +	if (n != 1) {
>> +		FAIL_ERRNO("recv_timeout()");
>> +		goto out;
>> +	}
> I prefer multiple send and receive operations, or implementing a loop at
> the outer level.

If you referring to MSG_OOB that "emulates" multiple send(), that's quite
deliberate: to exercise what is actually happening on
unix_stream_sendmsg(, MSG_OOB). And, well, to follow the selftests logic
in sockmap_listen.c:pairs_redir_to_connected().

Would you rather have it split anyway?

Thanks,
Michal

  reply	other threads:[~2025-04-16 12:33 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-11 11:32 [PATCH bpf-next v2 0/9] selftests/bpf: Test sockmap/sockhash redirection Michal Luczaj
2025-04-11 11:32 ` [PATCH bpf-next v2 1/9] selftests/bpf: Support af_unix SOCK_DGRAM socket pair creation Michal Luczaj
2025-04-18 16:07   ` Jakub Sitnicki
2025-04-11 11:32 ` [PATCH bpf-next v2 2/9] selftests/bpf: Add socket_kind_to_str() to socket_helpers Michal Luczaj
2025-04-18 16:08   ` Jakub Sitnicki
2025-04-11 11:32 ` [PATCH bpf-next v2 3/9] selftests/bpf: Add u32()/u64() to sockmap_helpers Michal Luczaj
2025-04-18 16:13   ` Jakub Sitnicki
2025-04-11 11:32 ` [PATCH bpf-next v2 4/9] selftests/bpf: Allow setting BPF_F_INGRESS in prog_msg_verdict() Michal Luczaj
2025-04-11 11:32 ` [PATCH bpf-next v2 5/9] selftests/bpf: Add selftest for sockmap/hashmap redirection Michal Luczaj
2025-04-11 13:09   ` Jiayuan Chen
2025-04-11 17:54     ` Jakub Sitnicki
2025-04-16 12:33       ` Michal Luczaj
2025-04-11 13:17   ` Jiayuan Chen
2025-04-16 12:32     ` Michal Luczaj
2025-04-11 14:31   ` Jiayuan Chen
2025-04-16 12:33     ` Michal Luczaj [this message]
2025-04-11 11:32 ` [PATCH bpf-next v2 6/9] selftests/bpf: sockmap_listen cleanup: Drop af_vsock redir tests Michal Luczaj
2025-04-11 11:32 ` [PATCH bpf-next v2 7/9] selftests/bpf: sockmap_listen cleanup: Drop af_unix " Michal Luczaj
2025-04-11 11:32 ` [PATCH bpf-next v2 8/9] selftests/bpf: sockmap_listen cleanup: Drop af_inet SOCK_DGRAM " Michal Luczaj
2025-04-11 11:32 ` [PATCH bpf-next v2 9/9] docs/bpf: sockmap: Add a missing comma Michal Luczaj
2025-04-11 13:06 ` [PATCH bpf-next v2 0/9] selftests/bpf: Test sockmap/sockhash redirection Jiayuan Chen
2025-04-21  4:20 ` John Fastabend

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=66bf942f-dfdb-4ce9-bd95-8b734e7afa53@rbox.co \
    --to=mhal@rbox.co \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=corbet@lwn.net \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=haoluo@google.com \
    --cc=jakub@cloudflare.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=mrpre@163.com \
    --cc=mykolal@fb.com \
    --cc=sdf@fomichev.me \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --cc=yonghong.song@linux.dev \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®