Commit 8a9d22b8 authored by Jordan Rife's avatar Jordan Rife Committed by Martin KaFai Lau

selftests/bpf: Move IPv4 and IPv6 sockaddr test cases

This patch lays the groundwork for testing IPv4 and IPv6 sockaddr hooks
and their interaction with both socket syscalls and kernel functions
(e.g. kernel_connect, kernel_bind, etc.). It moves some of the test
cases from the old-style bpf/test_sock_addr.c self test into the
sock_addr prog_test in a step towards fully retiring
bpf/test_sock_addr.c. We will expand the test dimensions in the
sock_addr prog_test in a later patch series in order to migrate the
remaining test cases.
Signed-off-by: default avatarJordan Rife <jrife@google.com>
Link: https://lore.kernel.org/r/20240429214529.2644801-5-jrife@google.comSigned-off-by: default avatarMartin KaFai Lau <martin.lau@kernel.org>
parent 15b6671e
......@@ -97,11 +97,7 @@ static int sendmsg_deny_prog_load(const struct sock_addr_test *test);
static int recvmsg_allow_prog_load(const struct sock_addr_test *test);
static int recvmsg_deny_prog_load(const struct sock_addr_test *test);
static int sendmsg4_rw_asm_prog_load(const struct sock_addr_test *test);
static int recvmsg4_rw_c_prog_load(const struct sock_addr_test *test);
static int sendmsg4_rw_c_prog_load(const struct sock_addr_test *test);
static int sendmsg6_rw_asm_prog_load(const struct sock_addr_test *test);
static int recvmsg6_rw_c_prog_load(const struct sock_addr_test *test);
static int sendmsg6_rw_c_prog_load(const struct sock_addr_test *test);
static int sendmsg6_rw_v4mapped_prog_load(const struct sock_addr_test *test);
static int sendmsg6_rw_wildcard_prog_load(const struct sock_addr_test *test);
......@@ -135,34 +131,6 @@ static struct sock_addr_test tests[] = {
NULL,
ATTACH_REJECT,
},
{
"bind4: rewrite IP & TCP port in",
bind4_prog_load,
BPF_CGROUP_INET4_BIND,
BPF_CGROUP_INET4_BIND,
AF_INET,
SOCK_STREAM,
SERV4_IP,
SERV4_PORT,
SERV4_REWRITE_IP,
SERV4_REWRITE_PORT,
NULL,
SUCCESS,
},
{
"bind4: rewrite IP & UDP port in",
bind4_prog_load,
BPF_CGROUP_INET4_BIND,
BPF_CGROUP_INET4_BIND,
AF_INET,
SOCK_DGRAM,
SERV4_IP,
SERV4_PORT,
SERV4_REWRITE_IP,
SERV4_REWRITE_PORT,
NULL,
SUCCESS,
},
{
"bind6: load prog with wrong expected attach type",
bind6_prog_load,
......@@ -191,34 +159,6 @@ static struct sock_addr_test tests[] = {
NULL,
ATTACH_REJECT,
},
{
"bind6: rewrite IP & TCP port in",
bind6_prog_load,
BPF_CGROUP_INET6_BIND,
BPF_CGROUP_INET6_BIND,
AF_INET6,
SOCK_STREAM,
SERV6_IP,
SERV6_PORT,
SERV6_REWRITE_IP,
SERV6_REWRITE_PORT,
NULL,
SUCCESS,
},
{
"bind6: rewrite IP & UDP port in",
bind6_prog_load,
BPF_CGROUP_INET6_BIND,
BPF_CGROUP_INET6_BIND,
AF_INET6,
SOCK_DGRAM,
SERV6_IP,
SERV6_PORT,
SERV6_REWRITE_IP,
SERV6_REWRITE_PORT,
NULL,
SUCCESS,
},
/* connect */
{
......@@ -249,34 +189,6 @@ static struct sock_addr_test tests[] = {
NULL,
ATTACH_REJECT,
},
{
"connect4: rewrite IP & TCP port",
connect4_prog_load,
BPF_CGROUP_INET4_CONNECT,
BPF_CGROUP_INET4_CONNECT,
AF_INET,
SOCK_STREAM,
SERV4_IP,
SERV4_PORT,
SERV4_REWRITE_IP,
SERV4_REWRITE_PORT,
SRC4_REWRITE_IP,
SUCCESS,
},
{
"connect4: rewrite IP & UDP port",
connect4_prog_load,
BPF_CGROUP_INET4_CONNECT,
BPF_CGROUP_INET4_CONNECT,
AF_INET,
SOCK_DGRAM,
SERV4_IP,
SERV4_PORT,
SERV4_REWRITE_IP,
SERV4_REWRITE_PORT,
SRC4_REWRITE_IP,
SUCCESS,
},
{
"connect6: load prog with wrong expected attach type",
connect6_prog_load,
......@@ -305,34 +217,6 @@ static struct sock_addr_test tests[] = {
NULL,
ATTACH_REJECT,
},
{
"connect6: rewrite IP & TCP port",
connect6_prog_load,
BPF_CGROUP_INET6_CONNECT,
BPF_CGROUP_INET6_CONNECT,
AF_INET6,
SOCK_STREAM,
SERV6_IP,
SERV6_PORT,
SERV6_REWRITE_IP,
SERV6_REWRITE_PORT,
SRC6_REWRITE_IP,
SUCCESS,
},
{
"connect6: rewrite IP & UDP port",
connect6_prog_load,
BPF_CGROUP_INET6_CONNECT,
BPF_CGROUP_INET6_CONNECT,
AF_INET6,
SOCK_DGRAM,
SERV6_IP,
SERV6_PORT,
SERV6_REWRITE_IP,
SERV6_REWRITE_PORT,
SRC6_REWRITE_IP,
SUCCESS,
},
/* sendmsg */
{
......@@ -377,20 +261,6 @@ static struct sock_addr_test tests[] = {
SRC4_REWRITE_IP,
SUCCESS,
},
{
"sendmsg4: rewrite IP & port (C)",
sendmsg4_rw_c_prog_load,
BPF_CGROUP_UDP4_SENDMSG,
BPF_CGROUP_UDP4_SENDMSG,
AF_INET,
SOCK_DGRAM,
SERV4_IP,
SERV4_PORT,
SERV4_REWRITE_IP,
SERV4_REWRITE_PORT,
SRC4_REWRITE_IP,
SUCCESS,
},
{
"sendmsg4: deny call",
sendmsg_deny_prog_load,
......@@ -447,20 +317,6 @@ static struct sock_addr_test tests[] = {
SRC6_REWRITE_IP,
SUCCESS,
},
{
"sendmsg6: rewrite IP & port (C)",
sendmsg6_rw_c_prog_load,
BPF_CGROUP_UDP6_SENDMSG,
BPF_CGROUP_UDP6_SENDMSG,
AF_INET6,
SOCK_DGRAM,
SERV6_IP,
SERV6_PORT,
SERV6_REWRITE_IP,
SERV6_REWRITE_PORT,
SRC6_REWRITE_IP,
SUCCESS,
},
{
"sendmsg6: IPv4-mapped IPv6",
sendmsg6_rw_v4mapped_prog_load,
......@@ -575,34 +431,6 @@ static struct sock_addr_test tests[] = {
NULL,
LOAD_REJECT,
},
{
"recvmsg4: rewrite IP & port (C)",
recvmsg4_rw_c_prog_load,
BPF_CGROUP_UDP4_RECVMSG,
BPF_CGROUP_UDP4_RECVMSG,
AF_INET,
SOCK_DGRAM,
SERV4_REWRITE_IP,
SERV4_REWRITE_PORT,
SERV4_REWRITE_IP,
SERV4_REWRITE_PORT,
SERV4_IP,
SUCCESS,
},
{
"recvmsg6: rewrite IP & port (C)",
recvmsg6_rw_c_prog_load,
BPF_CGROUP_UDP6_RECVMSG,
BPF_CGROUP_UDP6_RECVMSG,
AF_INET6,
SOCK_DGRAM,
SERV6_REWRITE_IP,
SERV6_REWRITE_PORT,
SERV6_REWRITE_IP,
SERV6_REWRITE_PORT,
SERV6_IP,
SUCCESS,
},
};
static int load_insns(const struct sock_addr_test *test,
......@@ -761,16 +589,6 @@ static int sendmsg4_rw_asm_prog_load(const struct sock_addr_test *test)
return load_insns(test, insns, ARRAY_SIZE(insns));
}
static int recvmsg4_rw_c_prog_load(const struct sock_addr_test *test)
{
return load_path(test, RECVMSG4_PROG_PATH);
}
static int sendmsg4_rw_c_prog_load(const struct sock_addr_test *test)
{
return load_path(test, SENDMSG4_PROG_PATH);
}
static int sendmsg6_rw_dst_asm_prog_load(const struct sock_addr_test *test,
const char *rw_dst_ip)
{
......@@ -829,11 +647,6 @@ static int sendmsg6_rw_asm_prog_load(const struct sock_addr_test *test)
return sendmsg6_rw_dst_asm_prog_load(test, SERV6_REWRITE_IP);
}
static int recvmsg6_rw_c_prog_load(const struct sock_addr_test *test)
{
return load_path(test, RECVMSG6_PROG_PATH);
}
static int sendmsg6_rw_v4mapped_prog_load(const struct sock_addr_test *test)
{
return sendmsg6_rw_dst_asm_prog_load(test, SERV6_V4MAPPED_IP);
......@@ -844,11 +657,6 @@ static int sendmsg6_rw_wildcard_prog_load(const struct sock_addr_test *test)
return sendmsg6_rw_dst_asm_prog_load(test, WILDCARD6_IP);
}
static int sendmsg6_rw_c_prog_load(const struct sock_addr_test *test)
{
return load_path(test, SENDMSG6_PROG_PATH);
}
static int cmp_addr(const struct sockaddr_storage *addr1,
const struct sockaddr_storage *addr2, int cmp_port)
{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment