aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorGravatar Jordan Rife <jrife@google.com> 2024-05-10 14:02:27 -0500
committerGravatar Alexei Starovoitov <ast@kernel.org> 2024-05-12 17:10:42 -0700
commitb0f3af0bffefc54650d9fb10810fc2f974365dfd (patch)
treed5e5c90bda48c70de53351c7e89eb8f805acdb4a /tools
parentselftests/bpf: Migrate wildcard destination rewrite test (diff)
downloadlinux-b0f3af0bffefc54650d9fb10810fc2f974365dfd.tar.gz
linux-b0f3af0bffefc54650d9fb10810fc2f974365dfd.tar.bz2
linux-b0f3af0bffefc54650d9fb10810fc2f974365dfd.zip
selftests/bpf: Migrate expected_attach_type tests
Migrates tests from progs/test_sock_addr.c ensuring that programs fail to load when the expected attach type does not match. Signed-off-by: Jordan Rife <jrife@google.com> Link: https://lore.kernel.org/r/20240510190246.3247730-11-jrife@google.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'tools')
-rw-r--r--tools/testing/selftests/bpf/prog_tests/sock_addr.c96
-rw-r--r--tools/testing/selftests/bpf/test_sock_addr.c84
2 files changed, 96 insertions, 84 deletions
diff --git a/tools/testing/selftests/bpf/prog_tests/sock_addr.c b/tools/testing/selftests/bpf/prog_tests/sock_addr.c
index e3c450d11b9e..8c7c56f99754 100644
--- a/tools/testing/selftests/bpf/prog_tests/sock_addr.c
+++ b/tools/testing/selftests/bpf/prog_tests/sock_addr.c
@@ -492,6 +492,22 @@ static struct sock_addr_test tests[] = {
},
{
SOCK_ADDR_TEST_BIND,
+ "bind4: load prog with wrong expected attach type",
+ bind_v4_prog_load,
+ bind_v4_prog_destroy,
+ BPF_CGROUP_INET6_BIND,
+ &user_ops,
+ AF_INET,
+ SOCK_STREAM,
+ NULL,
+ 0,
+ NULL,
+ 0,
+ NULL,
+ LOAD_REJECT,
+ },
+ {
+ SOCK_ADDR_TEST_BIND,
"bind6: bind (stream)",
bind_v6_prog_load,
bind_v6_prog_destroy,
@@ -522,6 +538,22 @@ static struct sock_addr_test tests[] = {
NULL,
SUCCESS,
},
+ {
+ SOCK_ADDR_TEST_BIND,
+ "bind6: load prog with wrong expected attach type",
+ bind_v6_prog_load,
+ bind_v6_prog_destroy,
+ BPF_CGROUP_INET4_BIND,
+ &user_ops,
+ AF_INET6,
+ SOCK_STREAM,
+ NULL,
+ 0,
+ NULL,
+ 0,
+ NULL,
+ LOAD_REJECT,
+ },
/* bind - kernel calls */
{
@@ -624,6 +656,22 @@ static struct sock_addr_test tests[] = {
},
{
SOCK_ADDR_TEST_CONNECT,
+ "connect4: load prog with wrong expected attach type",
+ connect_v4_prog_load,
+ connect_v4_prog_destroy,
+ BPF_CGROUP_INET6_CONNECT,
+ &user_ops,
+ AF_INET,
+ SOCK_STREAM,
+ NULL,
+ 0,
+ NULL,
+ 0,
+ NULL,
+ LOAD_REJECT,
+ },
+ {
+ SOCK_ADDR_TEST_CONNECT,
"connect6: connect (stream)",
connect_v6_prog_load,
connect_v6_prog_destroy,
@@ -656,6 +704,22 @@ static struct sock_addr_test tests[] = {
},
{
SOCK_ADDR_TEST_CONNECT,
+ "connect6: load prog with wrong expected attach type",
+ connect_v6_prog_load,
+ connect_v6_prog_destroy,
+ BPF_CGROUP_INET4_CONNECT,
+ &user_ops,
+ AF_INET6,
+ SOCK_STREAM,
+ NULL,
+ 0,
+ NULL,
+ 0,
+ NULL,
+ LOAD_REJECT,
+ },
+ {
+ SOCK_ADDR_TEST_CONNECT,
"connect_unix: connect (stream)",
connect_unix_prog_load,
connect_unix_prog_destroy,
@@ -788,6 +852,22 @@ static struct sock_addr_test tests[] = {
},
{
SOCK_ADDR_TEST_SENDMSG,
+ "sendmsg4: load prog with wrong expected attach type",
+ sendmsg_v4_prog_load,
+ sendmsg_v4_prog_destroy,
+ BPF_CGROUP_UDP6_SENDMSG,
+ &user_ops,
+ AF_INET,
+ SOCK_DGRAM,
+ NULL,
+ 0,
+ NULL,
+ 0,
+ NULL,
+ LOAD_REJECT,
+ },
+ {
+ SOCK_ADDR_TEST_SENDMSG,
"sendmsg6: sendmsg (dgram)",
sendmsg_v6_prog_load,
sendmsg_v6_prog_destroy,
@@ -868,6 +948,22 @@ static struct sock_addr_test tests[] = {
},
{
SOCK_ADDR_TEST_SENDMSG,
+ "sendmsg6: load prog with wrong expected attach type",
+ sendmsg_v6_prog_load,
+ sendmsg_v6_prog_destroy,
+ BPF_CGROUP_UDP4_SENDMSG,
+ &user_ops,
+ AF_INET6,
+ SOCK_DGRAM,
+ NULL,
+ 0,
+ NULL,
+ 0,
+ NULL,
+ LOAD_REJECT,
+ },
+ {
+ SOCK_ADDR_TEST_SENDMSG,
"sendmsg_unix: sendmsg (dgram)",
sendmsg_unix_prog_load,
sendmsg_unix_prog_destroy,
diff --git a/tools/testing/selftests/bpf/test_sock_addr.c b/tools/testing/selftests/bpf/test_sock_addr.c
index 85fb2a793be5..4ecbc72477f1 100644
--- a/tools/testing/selftests/bpf/test_sock_addr.c
+++ b/tools/testing/selftests/bpf/test_sock_addr.c
@@ -98,20 +98,6 @@ static int sendmsg6_rw_asm_prog_load(const struct sock_addr_test *test);
static struct sock_addr_test tests[] = {
/* bind */
{
- "bind4: load prog with wrong expected attach type",
- bind4_prog_load,
- BPF_CGROUP_INET6_BIND,
- BPF_CGROUP_INET4_BIND,
- AF_INET,
- SOCK_STREAM,
- NULL,
- 0,
- NULL,
- 0,
- NULL,
- LOAD_REJECT,
- },
- {
"bind4: attach prog with wrong attach type",
bind4_prog_load,
BPF_CGROUP_INET4_BIND,
@@ -126,20 +112,6 @@ static struct sock_addr_test tests[] = {
ATTACH_REJECT,
},
{
- "bind6: load prog with wrong expected attach type",
- bind6_prog_load,
- BPF_CGROUP_INET4_BIND,
- BPF_CGROUP_INET6_BIND,
- AF_INET6,
- SOCK_STREAM,
- NULL,
- 0,
- NULL,
- 0,
- NULL,
- LOAD_REJECT,
- },
- {
"bind6: attach prog with wrong attach type",
bind6_prog_load,
BPF_CGROUP_INET6_BIND,
@@ -156,20 +128,6 @@ static struct sock_addr_test tests[] = {
/* connect */
{
- "connect4: load prog with wrong expected attach type",
- connect4_prog_load,
- BPF_CGROUP_INET6_CONNECT,
- BPF_CGROUP_INET4_CONNECT,
- AF_INET,
- SOCK_STREAM,
- NULL,
- 0,
- NULL,
- 0,
- NULL,
- LOAD_REJECT,
- },
- {
"connect4: attach prog with wrong attach type",
connect4_prog_load,
BPF_CGROUP_INET4_CONNECT,
@@ -184,20 +142,6 @@ static struct sock_addr_test tests[] = {
ATTACH_REJECT,
},
{
- "connect6: load prog with wrong expected attach type",
- connect6_prog_load,
- BPF_CGROUP_INET4_CONNECT,
- BPF_CGROUP_INET6_CONNECT,
- AF_INET6,
- SOCK_STREAM,
- NULL,
- 0,
- NULL,
- 0,
- NULL,
- LOAD_REJECT,
- },
- {
"connect6: attach prog with wrong attach type",
connect6_prog_load,
BPF_CGROUP_INET6_CONNECT,
@@ -214,20 +158,6 @@ static struct sock_addr_test tests[] = {
/* sendmsg */
{
- "sendmsg4: load prog with wrong expected attach type",
- sendmsg4_rw_asm_prog_load,
- BPF_CGROUP_UDP6_SENDMSG,
- BPF_CGROUP_UDP4_SENDMSG,
- AF_INET,
- SOCK_DGRAM,
- NULL,
- 0,
- NULL,
- 0,
- NULL,
- LOAD_REJECT,
- },
- {
"sendmsg4: attach prog with wrong attach type",
sendmsg4_rw_asm_prog_load,
BPF_CGROUP_UDP4_SENDMSG,
@@ -256,20 +186,6 @@ static struct sock_addr_test tests[] = {
SUCCESS,
},
{
- "sendmsg6: load prog with wrong expected attach type",
- sendmsg6_rw_asm_prog_load,
- BPF_CGROUP_UDP4_SENDMSG,
- BPF_CGROUP_UDP6_SENDMSG,
- AF_INET6,
- SOCK_DGRAM,
- NULL,
- 0,
- NULL,
- 0,
- NULL,
- LOAD_REJECT,
- },
- {
"sendmsg6: attach prog with wrong attach type",
sendmsg6_rw_asm_prog_load,
BPF_CGROUP_UDP6_SENDMSG,