Skip to content

Commit 1469bf4

Browse files
author
Jiri Benc
committed
selftests/bpf: Cover listener cloning with progs attached to sockmap
Bugzilla: https://bugzilla.redhat.com/2177177 commit c88ea16 Author: Jakub Sitnicki <jakub@cloudflare.com> Date: Sat Jan 21 13:41:46 2023 +0100 selftests/bpf: Cover listener cloning with progs attached to sockmap Today we test if a child socket is cloned properly from a listening socket inside a sockmap only when there are no BPF programs attached to the map. A bug has been reported [1] for the case when sockmap has a verdict program attached. So cover this case as well to prevent regressions. [1]: https://lore.kernel.org/r/00000000000073b14905ef2e7401@google.com Signed-off-by: Jakub Sitnicki <jakub@cloudflare.com> Acked-by: John Fastabend <john.fastabend@gmail.com> Link: https://lore.kernel.org/r/20230113-sockmap-fix-v2-4-1e0ee7ac2f90@cloudflare.com Signed-off-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Jiri Benc <jbenc@redhat.com>
1 parent 6a4ea85 commit 1469bf4

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

tools/testing/selftests/bpf/prog_tests/sockmap_listen.c

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -563,8 +563,7 @@ static void test_update_existing(struct test_sockmap_listen *skel __always_unuse
563563
/* Exercise the code path where we destroy child sockets that never
564564
* got accept()'ed, aka orphans, when parent socket gets closed.
565565
*/
566-
static void test_destroy_orphan_child(struct test_sockmap_listen *skel __always_unused,
567-
int family, int sotype, int mapfd)
566+
static void do_destroy_orphan_child(int family, int sotype, int mapfd)
568567
{
569568
struct sockaddr_storage addr;
570569
socklen_t len;
@@ -595,6 +594,33 @@ static void test_destroy_orphan_child(struct test_sockmap_listen *skel __always_
595594
xclose(s);
596595
}
597596

597+
static void test_destroy_orphan_child(struct test_sockmap_listen *skel,
598+
int family, int sotype, int mapfd)
599+
{
600+
int msg_verdict = bpf_program__fd(skel->progs.prog_msg_verdict);
601+
int skb_verdict = bpf_program__fd(skel->progs.prog_skb_verdict);
602+
const struct test {
603+
int progfd;
604+
enum bpf_attach_type atype;
605+
} tests[] = {
606+
{ -1, -1 },
607+
{ msg_verdict, BPF_SK_MSG_VERDICT },
608+
{ skb_verdict, BPF_SK_SKB_VERDICT },
609+
};
610+
const struct test *t;
611+
612+
for (t = tests; t < tests + ARRAY_SIZE(tests); t++) {
613+
if (t->progfd != -1 &&
614+
xbpf_prog_attach(t->progfd, mapfd, t->atype, 0) != 0)
615+
return;
616+
617+
do_destroy_orphan_child(family, sotype, mapfd);
618+
619+
if (t->progfd != -1)
620+
xbpf_prog_detach2(t->progfd, mapfd, t->atype);
621+
}
622+
}
623+
598624
/* Perform a passive open after removing listening socket from SOCKMAP
599625
* to ensure that callbacks get restored properly.
600626
*/

0 commit comments

Comments
 (0)