From: Michal Luczaj <mhal@rbox.co>
To: Jakub Sitnicki <jakub@cloudflare.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>,
bpf@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH bpf-next v2 0/6] selftests/bpf: Various sockmap-related fixes
Date: Tue, 24 Sep 2024 12:25:33 +0200 [thread overview]
Message-ID: <e78254c5-8f2f-4dc5-bf81-401caefabdd1@rbox.co> (raw)
In-Reply-To: <877cccqnvj.fsf@cloudflare.com>
On 8/19/24 22:05, Jakub Sitnicki wrote:
> On Wed, Aug 14, 2024 at 06:14 PM +02, Michal Luczaj wrote:
>> On 8/6/24 19:45, Jakub Sitnicki wrote:
>>> On Tue, Aug 06, 2024 at 07:18 PM +02, Michal Luczaj wrote:
>>>> Great, thanks for the review. With this completed, I guess we can unwind
>>>> the (mail) stack to [1]. Is that ingress-to-local et al. something you
>>>> wanted to take care of yourself or can I give it a try?
>>>> [1] https://lore.kernel.org/netdev/87msmqn9ws.fsf@cloudflare.com/
>>>
>>> I haven't stated any work on. You're welcome to tackle that.
>>>
>>> All I have is a toy test that I've used to generate the redirect matrix.
>>> Perhaps it can serve as inspiration:
>>>
>>> https://github.com/jsitnicki/sockmap-redir-matrix
>>
>> All right, please let me know if this is more or less what you meant and
>> I'll post the whole series for a review (+patch to purge sockmap_listen of
>> redir tests, fix misnomers). [...]
>
> Gave it a look as promised. It makes sense to me as well to put these
> tests in a new module. There will be some overlap with sockmap_listen,
> which has diverged from its inital scope, but we can dedup that later.
>
> One thought that I had is that it could make sense to test the not
> supported redirect combos (and expect an error). Sometimes folks make
> changes and enable some parts of the API by accient.
All right, so I did what sockmap_listen does: check
test_sockmap_listen.c:verdict_map[SK_PASS] to see if the redirect took
place for a given combo. And that works well... except for skb/msg to
ingress af_vsock. Even though this is unsupported and no redirect
actually happens, verdict appears to be SK_PASS. Is this correct?
Maybe I'm missing something, so below is a crude testcase I've cobbled
together.
And sorry for the delay, I was away from keyboard.
Michal
All error logs:
./test_progs:unix_vsock_redir_fail:1600: want pass=0 / drop=1, have 1 / 0
unix_vsock_redir_fail:FAIL:1600
diff --git a/tools/testing/selftests/bpf/prog_tests/sockmap_listen.c b/tools/testing/selftests/bpf/prog_tests/sockmap_listen.c
index 4ee1148d22be..e59e1654f110 100644
--- a/tools/testing/selftests/bpf/prog_tests/sockmap_listen.c
+++ b/tools/testing/selftests/bpf/prog_tests/sockmap_listen.c
@@ -1561,6 +1561,45 @@ static void vsock_unix_redir_connectible(int sock_mapfd, int verd_mapfd,
close(u1);
}
+static void unix_vsock_redir_fail(int sock_mapfd, int verd_mapfd)
+{
+ int v0, v1, u[2], pass, drop;
+ char a = 'a';
+
+ bpf_map_delete_elem(sock_mapfd, &(int){0});
+ bpf_map_delete_elem(sock_mapfd, &(int){1});
+ zero_verdict_count(verd_mapfd);
+
+ if (socketpair(AF_UNIX, SOCK_STREAM, 0, u)) {
+ FAIL_ERRNO("socketpair(af_unix)");
+ return;
+ }
+
+ if (create_pair(AF_VSOCK, SOCK_STREAM, &v0, &v1))
+ return;
+
+ if (add_to_sockmap(sock_mapfd, v0, u[0]))
+ return;
+
+ if (write(u[1], &a, sizeof(a)) != 1) {
+ FAIL_ERRNO("write()");
+ return;
+ }
+
+ errno = 0;
+ if (recv_timeout(v0, &a, sizeof(a), 0, 1) >= 0 ||
+ recv_timeout(v1, &a, sizeof(a), 0, 1) >= 0 ||
+ recv_timeout(u[0], &a, sizeof(a), 0, 1) >= 0 ||
+ recv_timeout(u[1], &a, sizeof(a), 0, 1) >= 0)
+ FAIL("recv() returned >=0, errno=%d", errno);
+
+ if (xbpf_map_lookup_elem(verd_mapfd, &(int){SK_PASS}, &pass) ||
+ xbpf_map_lookup_elem(verd_mapfd, &(int){SK_DROP}, &drop))
+ return;
+ if (pass != 0 || drop != 1)
+ FAIL("want pass=0 / drop=1, have %d / %d", pass, drop);
+}
+
static void vsock_unix_skb_redir_connectible(struct test_sockmap_listen *skel,
struct bpf_map *inner_map,
int sotype)
@@ -1582,6 +1621,23 @@ static void vsock_unix_skb_redir_connectible(struct test_sockmap_listen *skel,
xbpf_prog_detach2(verdict, sock_map, BPF_SK_SKB_VERDICT);
}
+static void unix_vsock_redir(struct test_sockmap_listen *skel, struct bpf_map *inner_map)
+{
+ int verdict = bpf_program__fd(skel->progs.prog_skb_verdict);
+ int verdict_map = bpf_map__fd(skel->maps.verdict_map);
+ int sock_map = bpf_map__fd(inner_map);
+ int err;
+
+ err = xbpf_prog_attach(verdict, sock_map, BPF_SK_SKB_VERDICT, 0);
+ if (err)
+ return;
+
+ skel->bss->test_ingress = true;
+ unix_vsock_redir_fail(sock_map, verdict_map);
+
+ xbpf_prog_detach2(verdict, sock_map, BPF_SK_SKB_VERDICT);
+}
+
static void test_vsock_redir(struct test_sockmap_listen *skel, struct bpf_map *map)
{
const char *family_name, *map_name;
@@ -1883,6 +1939,7 @@ void serial_test_sockmap_listen(void)
test_unix_redir(skel, skel->maps.sock_map, SOCK_DGRAM);
test_unix_redir(skel, skel->maps.sock_map, SOCK_STREAM);
test_vsock_redir(skel, skel->maps.sock_map);
+ unix_vsock_redir(skel, skel->maps.sock_map);
skel->bss->test_sockmap = false;
run_tests(skel, skel->maps.sock_hash, AF_INET);
next prev parent reply other threads:[~2024-09-24 11:03 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-31 10:01 [PATCH bpf-next v2 0/6] selftests/bpf: Various sockmap-related fixes Michal Luczaj
2024-07-31 10:01 ` [PATCH bpf-next v2 1/6] selftests/bpf: Support more socket types in create_pair() Michal Luczaj
2024-07-31 10:01 ` [PATCH bpf-next v2 2/6] selftests/bpf: Socket pair creation, cleanups Michal Luczaj
2024-07-31 10:01 ` [PATCH bpf-next v2 3/6] selftests/bpf: Simplify inet_socketpair() and vsock_socketpair_connectible() Michal Luczaj
2024-07-31 10:01 ` [PATCH bpf-next v2 4/6] selftests/bpf: Honour the sotype of af_unix redir tests Michal Luczaj
2024-07-31 10:01 ` [PATCH bpf-next v2 5/6] selftests/bpf: Exercise SOCK_STREAM unix_inet_redir_to_connected() Michal Luczaj
2024-07-31 10:01 ` [PATCH bpf-next v2 6/6] selftests/bpf: Introduce __attribute__((cleanup)) in create_pair() Michal Luczaj
2024-08-05 15:22 ` [PATCH bpf-next v2 0/6] selftests/bpf: Various sockmap-related fixes Jakub Sitnicki
2024-08-05 19:54 ` Michal Luczaj
2024-08-06 12:01 ` Jakub Sitnicki
2024-08-06 17:18 ` Michal Luczaj
2024-08-06 17:45 ` Jakub Sitnicki
2024-08-14 16:14 ` Michal Luczaj
2024-08-14 16:17 ` [PATCH 1/3] selftests/bpf: Support AF_UNIX SOCK_DGRAM socket pair creation Michal Luczaj
2024-08-14 16:18 ` [PATCH 2/3] selftests/bpf: Allow setting BPF_F_INGRESS in prog_msg_verdict() Michal Luczaj
2024-08-14 16:20 ` [PATCH 3/3] selftests/bpf: Add selftest for sockmap/hashmap redirection Michal Luczaj
2024-08-16 19:03 ` [PATCH bpf-next v2 0/6] selftests/bpf: Various sockmap-related fixes Jakub Sitnicki
2024-08-19 22:45 ` Martin KaFai Lau
2024-08-19 20:05 ` Jakub Sitnicki
2024-09-24 10:25 ` Michal Luczaj [this message]
2024-09-26 22:54 ` Michal Luczaj
2024-09-27 9:15 ` Jakub Sitnicki
2024-10-02 8:27 ` Michal Luczaj
2024-10-09 9:46 ` Jakub Sitnicki
2024-10-09 22:31 ` Michal Luczaj
2025-04-11 11:44 ` Michal Luczaj
2024-08-20 0:20 ` Martin KaFai Lau
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=e78254c5-8f2f-4dc5-bf81-401caefabdd1@rbox.co \
--to=mhal@rbox.co \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--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-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=martin.lau@linux.dev \
--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