mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-05-11 09:43:54 -04:00
selftests/bpf: sockmap_listen cleanup: Drop af_unix redir tests
Remove tests covered by sockmap_redir. Signed-off-by: Michal Luczaj <mhal@rbox.co> Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org> Acked-by: John Fastabend <john.fastabend@gmail.com> Link: https://lore.kernel.org/r/20250515-selftests-sockmap-redir-v3-7-a1ea723f7e7e@rbox.co
This commit is contained in:
committed by
Martin KaFai Lau
parent
9266e49d60
commit
f3de1cf621
@@ -1429,64 +1429,6 @@ static void pairs_redir_to_connected(int cli0, int peer0, int cli1, int peer1,
|
||||
}
|
||||
}
|
||||
|
||||
static void unix_redir_to_connected(int sotype, int sock_mapfd,
|
||||
int verd_mapfd, enum redir_mode mode)
|
||||
{
|
||||
int c0, c1, p0, p1;
|
||||
int sfd[2];
|
||||
|
||||
if (socketpair(AF_UNIX, sotype | SOCK_NONBLOCK, 0, sfd))
|
||||
return;
|
||||
c0 = sfd[0], p0 = sfd[1];
|
||||
|
||||
if (socketpair(AF_UNIX, sotype | SOCK_NONBLOCK, 0, sfd))
|
||||
goto close0;
|
||||
c1 = sfd[0], p1 = sfd[1];
|
||||
|
||||
pairs_redir_to_connected(c0, p0, c1, p1, sock_mapfd, -1, verd_mapfd,
|
||||
mode, NO_FLAGS);
|
||||
|
||||
xclose(c1);
|
||||
xclose(p1);
|
||||
close0:
|
||||
xclose(c0);
|
||||
xclose(p0);
|
||||
}
|
||||
|
||||
static void unix_skb_redir_to_connected(struct test_sockmap_listen *skel,
|
||||
struct bpf_map *inner_map, int sotype)
|
||||
{
|
||||
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 = false;
|
||||
unix_redir_to_connected(sotype, sock_map, verdict_map, REDIR_EGRESS);
|
||||
skel->bss->test_ingress = true;
|
||||
unix_redir_to_connected(sotype, sock_map, verdict_map, REDIR_INGRESS);
|
||||
|
||||
xbpf_prog_detach2(verdict, sock_map, BPF_SK_SKB_VERDICT);
|
||||
}
|
||||
|
||||
static void test_unix_redir(struct test_sockmap_listen *skel, struct bpf_map *map,
|
||||
int sotype)
|
||||
{
|
||||
const char *family_name, *map_name;
|
||||
char s[MAX_TEST_NAME];
|
||||
|
||||
family_name = family_str(AF_UNIX);
|
||||
map_name = map_type_str(map);
|
||||
snprintf(s, sizeof(s), "%s %s %s", map_name, family_name, __func__);
|
||||
if (!test__start_subtest(s))
|
||||
return;
|
||||
unix_skb_redir_to_connected(skel, map, sotype);
|
||||
}
|
||||
|
||||
static void test_reuseport(struct test_sockmap_listen *skel,
|
||||
struct bpf_map *map, int family, int sotype)
|
||||
{
|
||||
@@ -1589,162 +1531,6 @@ static void test_udp_redir(struct test_sockmap_listen *skel, struct bpf_map *map
|
||||
udp_skb_redir_to_connected(skel, map, family);
|
||||
}
|
||||
|
||||
static void inet_unix_redir_to_connected(int family, int type, int sock_mapfd,
|
||||
int verd_mapfd, enum redir_mode mode)
|
||||
{
|
||||
int c0, c1, p0, p1;
|
||||
int sfd[2];
|
||||
int err;
|
||||
|
||||
if (socketpair(AF_UNIX, type | SOCK_NONBLOCK, 0, sfd))
|
||||
return;
|
||||
c0 = sfd[0], p0 = sfd[1];
|
||||
|
||||
err = inet_socketpair(family, type, &p1, &c1);
|
||||
if (err)
|
||||
goto close;
|
||||
|
||||
pairs_redir_to_connected(c0, p0, c1, p1, sock_mapfd, -1, verd_mapfd,
|
||||
mode, NO_FLAGS);
|
||||
|
||||
xclose(c1);
|
||||
xclose(p1);
|
||||
close:
|
||||
xclose(c0);
|
||||
xclose(p0);
|
||||
}
|
||||
|
||||
static void inet_unix_skb_redir_to_connected(struct test_sockmap_listen *skel,
|
||||
struct bpf_map *inner_map, int family)
|
||||
{
|
||||
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 = false;
|
||||
inet_unix_redir_to_connected(family, SOCK_DGRAM, sock_map, verdict_map,
|
||||
REDIR_EGRESS);
|
||||
inet_unix_redir_to_connected(family, SOCK_STREAM, sock_map, verdict_map,
|
||||
REDIR_EGRESS);
|
||||
skel->bss->test_ingress = true;
|
||||
inet_unix_redir_to_connected(family, SOCK_DGRAM, sock_map, verdict_map,
|
||||
REDIR_INGRESS);
|
||||
inet_unix_redir_to_connected(family, SOCK_STREAM, sock_map, verdict_map,
|
||||
REDIR_INGRESS);
|
||||
|
||||
xbpf_prog_detach2(verdict, sock_map, BPF_SK_SKB_VERDICT);
|
||||
}
|
||||
|
||||
static void unix_inet_redir_to_connected(int family, int type, int sock_mapfd,
|
||||
int nop_mapfd, int verd_mapfd,
|
||||
enum redir_mode mode, int send_flags)
|
||||
{
|
||||
int c0, c1, p0, p1;
|
||||
int sfd[2];
|
||||
int err;
|
||||
|
||||
err = inet_socketpair(family, type, &p0, &c0);
|
||||
if (err)
|
||||
return;
|
||||
|
||||
if (socketpair(AF_UNIX, type | SOCK_NONBLOCK, 0, sfd))
|
||||
goto close_cli0;
|
||||
c1 = sfd[0], p1 = sfd[1];
|
||||
|
||||
pairs_redir_to_connected(c0, p0, c1, p1, sock_mapfd, nop_mapfd,
|
||||
verd_mapfd, mode, send_flags);
|
||||
|
||||
xclose(c1);
|
||||
xclose(p1);
|
||||
close_cli0:
|
||||
xclose(c0);
|
||||
xclose(p0);
|
||||
}
|
||||
|
||||
static void unix_inet_skb_redir_to_connected(struct test_sockmap_listen *skel,
|
||||
struct bpf_map *inner_map, int family)
|
||||
{
|
||||
int verdict = bpf_program__fd(skel->progs.prog_skb_verdict);
|
||||
int nop_map = bpf_map__fd(skel->maps.nop_map);
|
||||
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 = false;
|
||||
unix_inet_redir_to_connected(family, SOCK_DGRAM,
|
||||
sock_map, -1, verdict_map,
|
||||
REDIR_EGRESS, NO_FLAGS);
|
||||
unix_inet_redir_to_connected(family, SOCK_STREAM,
|
||||
sock_map, -1, verdict_map,
|
||||
REDIR_EGRESS, NO_FLAGS);
|
||||
|
||||
unix_inet_redir_to_connected(family, SOCK_DGRAM,
|
||||
sock_map, nop_map, verdict_map,
|
||||
REDIR_EGRESS, NO_FLAGS);
|
||||
unix_inet_redir_to_connected(family, SOCK_STREAM,
|
||||
sock_map, nop_map, verdict_map,
|
||||
REDIR_EGRESS, NO_FLAGS);
|
||||
|
||||
/* MSG_OOB not supported by AF_UNIX SOCK_DGRAM */
|
||||
unix_inet_redir_to_connected(family, SOCK_STREAM,
|
||||
sock_map, nop_map, verdict_map,
|
||||
REDIR_EGRESS, MSG_OOB);
|
||||
|
||||
skel->bss->test_ingress = true;
|
||||
unix_inet_redir_to_connected(family, SOCK_DGRAM,
|
||||
sock_map, -1, verdict_map,
|
||||
REDIR_INGRESS, NO_FLAGS);
|
||||
unix_inet_redir_to_connected(family, SOCK_STREAM,
|
||||
sock_map, -1, verdict_map,
|
||||
REDIR_INGRESS, NO_FLAGS);
|
||||
|
||||
unix_inet_redir_to_connected(family, SOCK_DGRAM,
|
||||
sock_map, nop_map, verdict_map,
|
||||
REDIR_INGRESS, NO_FLAGS);
|
||||
unix_inet_redir_to_connected(family, SOCK_STREAM,
|
||||
sock_map, nop_map, verdict_map,
|
||||
REDIR_INGRESS, NO_FLAGS);
|
||||
|
||||
/* MSG_OOB not supported by AF_UNIX SOCK_DGRAM */
|
||||
unix_inet_redir_to_connected(family, SOCK_STREAM,
|
||||
sock_map, nop_map, verdict_map,
|
||||
REDIR_INGRESS, MSG_OOB);
|
||||
|
||||
xbpf_prog_detach2(verdict, sock_map, BPF_SK_SKB_VERDICT);
|
||||
}
|
||||
|
||||
static void test_udp_unix_redir(struct test_sockmap_listen *skel, struct bpf_map *map,
|
||||
int family)
|
||||
{
|
||||
const char *family_name, *map_name;
|
||||
struct netns_obj *netns;
|
||||
char s[MAX_TEST_NAME];
|
||||
|
||||
family_name = family_str(family);
|
||||
map_name = map_type_str(map);
|
||||
snprintf(s, sizeof(s), "%s %s %s", map_name, family_name, __func__);
|
||||
if (!test__start_subtest(s))
|
||||
return;
|
||||
|
||||
netns = netns_new("sockmap_listen", true);
|
||||
if (!ASSERT_OK_PTR(netns, "netns_new"))
|
||||
return;
|
||||
|
||||
inet_unix_skb_redir_to_connected(skel, map, family);
|
||||
unix_inet_skb_redir_to_connected(skel, map, family);
|
||||
|
||||
netns_free(netns);
|
||||
}
|
||||
|
||||
static void run_tests(struct test_sockmap_listen *skel, struct bpf_map *map,
|
||||
int family)
|
||||
{
|
||||
@@ -1754,7 +1540,6 @@ static void run_tests(struct test_sockmap_listen *skel, struct bpf_map *map,
|
||||
test_reuseport(skel, map, family, SOCK_STREAM);
|
||||
test_reuseport(skel, map, family, SOCK_DGRAM);
|
||||
test_udp_redir(skel, map, family);
|
||||
test_udp_unix_redir(skel, map, family);
|
||||
}
|
||||
|
||||
void serial_test_sockmap_listen(void)
|
||||
@@ -1770,14 +1555,10 @@ void serial_test_sockmap_listen(void)
|
||||
skel->bss->test_sockmap = true;
|
||||
run_tests(skel, skel->maps.sock_map, AF_INET);
|
||||
run_tests(skel, skel->maps.sock_map, AF_INET6);
|
||||
test_unix_redir(skel, skel->maps.sock_map, SOCK_DGRAM);
|
||||
test_unix_redir(skel, skel->maps.sock_map, SOCK_STREAM);
|
||||
|
||||
skel->bss->test_sockmap = false;
|
||||
run_tests(skel, skel->maps.sock_hash, AF_INET);
|
||||
run_tests(skel, skel->maps.sock_hash, AF_INET6);
|
||||
test_unix_redir(skel, skel->maps.sock_hash, SOCK_DGRAM);
|
||||
test_unix_redir(skel, skel->maps.sock_hash, SOCK_STREAM);
|
||||
|
||||
test_sockmap_listen__destroy(skel);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user