Merge branch 'retire-progs-test_sock_addr'
Jordan Rife says: ==================== Retire progs/test_sock_addr.c This patch series migrates remaining tests from bpf/test_sock_addr.c to prog_tests/sock_addr.c and progs/verifier_sock_addr.c in order to fully retire the old-style test program and expands test coverage to test previously untested scenarios related to sockaddr hooks. This is a continuation of the work started recently during the expansion of prog_tests/sock_addr.c. Link: https://lore.kernel.org/bpf/20240429214529.2644801-1-jrife@google.com/T/#u ======= Patches ======= * Patch 1 moves tests that check valid return values for recvmsg hooks into progs/verifier_sock_addr.c, a new addition to the verifier test suite. * Patches 2-5 lay the groundwork for test migration, enabling prog_tests/sock_addr.c to handle more test dimensions. * Patches 6-11 move existing tests to prog_tests/sock_addr.c. * Patch 12 removes some redundant test cases. * Patches 14-17 expand on existing test coverage. ==================== Link: https://lore.kernel.org/r/20240510190246.3247730-1-jrife@google.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
commit
e9dd2290f1
1
tools/testing/selftests/bpf/.gitignore
vendored
1
tools/testing/selftests/bpf/.gitignore
vendored
@ -17,7 +17,6 @@ test_dev_cgroup
|
||||
test_verifier_log
|
||||
feature
|
||||
test_sock
|
||||
test_sock_addr
|
||||
urandom_read
|
||||
test_sockmap
|
||||
test_lirc_mode2_user
|
||||
|
@ -115,7 +115,6 @@ TEST_PROGS := test_kmod.sh \
|
||||
test_xdp_redirect_multi.sh \
|
||||
test_xdp_meta.sh \
|
||||
test_xdp_veth.sh \
|
||||
test_sock_addr.sh \
|
||||
test_tunnel.sh \
|
||||
test_lwt_seg6local.sh \
|
||||
test_lirc_mode2.sh \
|
||||
@ -140,7 +139,7 @@ TEST_PROGS_EXTENDED := with_addr.sh \
|
||||
test_xdp_vlan.sh test_bpftool.py
|
||||
|
||||
# Compile but not part of 'make run_tests'
|
||||
TEST_GEN_PROGS_EXTENDED = test_sock_addr test_skb_cgroup_id_user \
|
||||
TEST_GEN_PROGS_EXTENDED = test_skb_cgroup_id_user \
|
||||
flow_dissector_load test_flow_dissector test_tcp_check_syncookie_user \
|
||||
test_lirc_mode2_user xdping test_cpp runqslower bench bpf_testmod.ko \
|
||||
xskxceiver xdp_redirect_multi xdp_synproxy veristat xdp_hw_metadata \
|
||||
@ -296,7 +295,6 @@ NETWORK_HELPERS := $(OUTPUT)/network_helpers.o
|
||||
$(OUTPUT)/test_dev_cgroup: $(CGROUP_HELPERS) $(TESTING_HELPERS)
|
||||
$(OUTPUT)/test_skb_cgroup_id_user: $(CGROUP_HELPERS) $(TESTING_HELPERS)
|
||||
$(OUTPUT)/test_sock: $(CGROUP_HELPERS) $(TESTING_HELPERS)
|
||||
$(OUTPUT)/test_sock_addr: $(CGROUP_HELPERS) $(TESTING_HELPERS) $(NETWORK_HELPERS)
|
||||
$(OUTPUT)/test_sockmap: $(CGROUP_HELPERS) $(TESTING_HELPERS)
|
||||
$(OUTPUT)/test_tcpnotify_user: $(CGROUP_HELPERS) $(TESTING_HELPERS) $(TRACE_HELPERS)
|
||||
$(OUTPUT)/get_cgroup_id_user: $(CGROUP_HELPERS) $(TESTING_HELPERS)
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -66,6 +66,7 @@
|
||||
#include "verifier_sdiv.skel.h"
|
||||
#include "verifier_search_pruning.skel.h"
|
||||
#include "verifier_sock.skel.h"
|
||||
#include "verifier_sock_addr.skel.h"
|
||||
#include "verifier_spill_fill.skel.h"
|
||||
#include "verifier_spin_lock.skel.h"
|
||||
#include "verifier_stack_ptr.skel.h"
|
||||
@ -181,6 +182,7 @@ void test_verifier_scalar_ids(void) { RUN(verifier_scalar_ids); }
|
||||
void test_verifier_sdiv(void) { RUN(verifier_sdiv); }
|
||||
void test_verifier_search_pruning(void) { RUN(verifier_search_pruning); }
|
||||
void test_verifier_sock(void) { RUN(verifier_sock); }
|
||||
void test_verifier_sock_addr(void) { RUN(verifier_sock_addr); }
|
||||
void test_verifier_spill_fill(void) { RUN(verifier_spill_fill); }
|
||||
void test_verifier_spin_lock(void) { RUN(verifier_spin_lock); }
|
||||
void test_verifier_stack_ptr(void) { RUN(verifier_stack_ptr); }
|
||||
|
@ -158,4 +158,10 @@ int bind_v4_prog(struct bpf_sock_addr *ctx)
|
||||
return 1;
|
||||
}
|
||||
|
||||
SEC("cgroup/bind4")
|
||||
int bind_v4_deny_prog(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
char _license[] SEC("license") = "GPL";
|
||||
|
@ -175,4 +175,10 @@ int bind_v6_prog(struct bpf_sock_addr *ctx)
|
||||
return 1;
|
||||
}
|
||||
|
||||
SEC("cgroup/bind6")
|
||||
int bind_v6_deny_prog(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
char _license[] SEC("license") = "GPL";
|
||||
|
@ -199,4 +199,10 @@ int connect_v4_prog(struct bpf_sock_addr *ctx)
|
||||
return do_bind(ctx) ? 1 : 0;
|
||||
}
|
||||
|
||||
SEC("cgroup/connect4")
|
||||
int connect_v4_deny_prog(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
char _license[] SEC("license") = "GPL";
|
||||
|
@ -90,4 +90,10 @@ int connect_v6_prog(struct bpf_sock_addr *ctx)
|
||||
return 1;
|
||||
}
|
||||
|
||||
SEC("cgroup/connect6")
|
||||
int connect_v6_deny_prog(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
char _license[] SEC("license") = "GPL";
|
||||
|
@ -36,4 +36,10 @@ int connect_unix_prog(struct bpf_sock_addr *ctx)
|
||||
return 1;
|
||||
}
|
||||
|
||||
SEC("cgroup/connect_unix")
|
||||
int connect_unix_deny_prog(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
char _license[] SEC("license") = "GPL";
|
||||
|
24
tools/testing/selftests/bpf/progs/getpeername4_prog.c
Normal file
24
tools/testing/selftests/bpf/progs/getpeername4_prog.c
Normal file
@ -0,0 +1,24 @@
|
||||
// SPDX-License-Identifier: GPL-2.0
|
||||
/* Copyright (c) 2024 Google LLC */
|
||||
|
||||
#include "vmlinux.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <bpf/bpf_helpers.h>
|
||||
#include <bpf/bpf_endian.h>
|
||||
#include <bpf/bpf_core_read.h>
|
||||
#include "bpf_kfuncs.h"
|
||||
|
||||
#define REWRITE_ADDRESS_IP4 0xc0a801fe // 192.168.1.254
|
||||
#define REWRITE_ADDRESS_PORT4 4040
|
||||
|
||||
SEC("cgroup/getpeername4")
|
||||
int getpeername_v4_prog(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
ctx->user_ip4 = bpf_htonl(REWRITE_ADDRESS_IP4);
|
||||
ctx->user_port = bpf_htons(REWRITE_ADDRESS_PORT4);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
char _license[] SEC("license") = "GPL";
|
31
tools/testing/selftests/bpf/progs/getpeername6_prog.c
Normal file
31
tools/testing/selftests/bpf/progs/getpeername6_prog.c
Normal file
@ -0,0 +1,31 @@
|
||||
// SPDX-License-Identifier: GPL-2.0
|
||||
/* Copyright (c) 2024 Google LLC */
|
||||
|
||||
#include "vmlinux.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <bpf/bpf_helpers.h>
|
||||
#include <bpf/bpf_endian.h>
|
||||
#include <bpf/bpf_core_read.h>
|
||||
#include "bpf_kfuncs.h"
|
||||
|
||||
#define REWRITE_ADDRESS_IP6_0 0xfaceb00c
|
||||
#define REWRITE_ADDRESS_IP6_1 0x12345678
|
||||
#define REWRITE_ADDRESS_IP6_2 0x00000000
|
||||
#define REWRITE_ADDRESS_IP6_3 0x0000abcd
|
||||
|
||||
#define REWRITE_ADDRESS_PORT6 6060
|
||||
|
||||
SEC("cgroup/getpeername6")
|
||||
int getpeername_v6_prog(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
ctx->user_ip6[0] = bpf_htonl(REWRITE_ADDRESS_IP6_0);
|
||||
ctx->user_ip6[1] = bpf_htonl(REWRITE_ADDRESS_IP6_1);
|
||||
ctx->user_ip6[2] = bpf_htonl(REWRITE_ADDRESS_IP6_2);
|
||||
ctx->user_ip6[3] = bpf_htonl(REWRITE_ADDRESS_IP6_3);
|
||||
ctx->user_port = bpf_htons(REWRITE_ADDRESS_PORT6);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
char _license[] SEC("license") = "GPL";
|
24
tools/testing/selftests/bpf/progs/getsockname4_prog.c
Normal file
24
tools/testing/selftests/bpf/progs/getsockname4_prog.c
Normal file
@ -0,0 +1,24 @@
|
||||
// SPDX-License-Identifier: GPL-2.0
|
||||
/* Copyright (c) 2024 Google LLC */
|
||||
|
||||
#include "vmlinux.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <bpf/bpf_helpers.h>
|
||||
#include <bpf/bpf_endian.h>
|
||||
#include <bpf/bpf_core_read.h>
|
||||
#include "bpf_kfuncs.h"
|
||||
|
||||
#define REWRITE_ADDRESS_IP4 0xc0a801fe // 192.168.1.254
|
||||
#define REWRITE_ADDRESS_PORT4 4040
|
||||
|
||||
SEC("cgroup/getsockname4")
|
||||
int getsockname_v4_prog(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
ctx->user_ip4 = bpf_htonl(REWRITE_ADDRESS_IP4);
|
||||
ctx->user_port = bpf_htons(REWRITE_ADDRESS_PORT4);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
char _license[] SEC("license") = "GPL";
|
31
tools/testing/selftests/bpf/progs/getsockname6_prog.c
Normal file
31
tools/testing/selftests/bpf/progs/getsockname6_prog.c
Normal file
@ -0,0 +1,31 @@
|
||||
// SPDX-License-Identifier: GPL-2.0
|
||||
/* Copyright (c) 2024 Google LLC */
|
||||
|
||||
#include "vmlinux.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <bpf/bpf_helpers.h>
|
||||
#include <bpf/bpf_endian.h>
|
||||
#include <bpf/bpf_core_read.h>
|
||||
#include "bpf_kfuncs.h"
|
||||
|
||||
#define REWRITE_ADDRESS_IP6_0 0xfaceb00c
|
||||
#define REWRITE_ADDRESS_IP6_1 0x12345678
|
||||
#define REWRITE_ADDRESS_IP6_2 0x00000000
|
||||
#define REWRITE_ADDRESS_IP6_3 0x0000abcd
|
||||
|
||||
#define REWRITE_ADDRESS_PORT6 6060
|
||||
|
||||
SEC("cgroup/getsockname6")
|
||||
int getsockname_v6_prog(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
ctx->user_ip6[0] = bpf_htonl(REWRITE_ADDRESS_IP6_0);
|
||||
ctx->user_ip6[1] = bpf_htonl(REWRITE_ADDRESS_IP6_1);
|
||||
ctx->user_ip6[2] = bpf_htonl(REWRITE_ADDRESS_IP6_2);
|
||||
ctx->user_ip6[3] = bpf_htonl(REWRITE_ADDRESS_IP6_3);
|
||||
ctx->user_port = bpf_htons(REWRITE_ADDRESS_PORT6);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
char _license[] SEC("license") = "GPL";
|
@ -49,4 +49,10 @@ int sendmsg_v4_prog(struct bpf_sock_addr *ctx)
|
||||
return 1;
|
||||
}
|
||||
|
||||
SEC("cgroup/sendmsg4")
|
||||
int sendmsg_v4_deny_prog(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
char _license[] SEC("license") = "GPL";
|
||||
|
@ -20,6 +20,11 @@
|
||||
#define DST_REWRITE_IP6_2 0
|
||||
#define DST_REWRITE_IP6_3 1
|
||||
|
||||
#define DST_REWRITE_IP6_V4_MAPPED_0 0
|
||||
#define DST_REWRITE_IP6_V4_MAPPED_1 0
|
||||
#define DST_REWRITE_IP6_V4_MAPPED_2 0x0000FFFF
|
||||
#define DST_REWRITE_IP6_V4_MAPPED_3 0xc0a80004 // 192.168.0.4
|
||||
|
||||
#define DST_REWRITE_PORT6 6666
|
||||
|
||||
SEC("cgroup/sendmsg6")
|
||||
@ -59,4 +64,56 @@ int sendmsg_v6_prog(struct bpf_sock_addr *ctx)
|
||||
return 1;
|
||||
}
|
||||
|
||||
SEC("cgroup/sendmsg6")
|
||||
int sendmsg_v6_v4mapped_prog(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
/* Rewrite source. */
|
||||
ctx->msg_src_ip6[0] = bpf_htonl(SRC_REWRITE_IP6_0);
|
||||
ctx->msg_src_ip6[1] = bpf_htonl(SRC_REWRITE_IP6_1);
|
||||
ctx->msg_src_ip6[2] = bpf_htonl(SRC_REWRITE_IP6_2);
|
||||
ctx->msg_src_ip6[3] = bpf_htonl(SRC_REWRITE_IP6_3);
|
||||
|
||||
/* Rewrite destination. */
|
||||
ctx->user_ip6[0] = bpf_htonl(DST_REWRITE_IP6_V4_MAPPED_0);
|
||||
ctx->user_ip6[1] = bpf_htonl(DST_REWRITE_IP6_V4_MAPPED_1);
|
||||
ctx->user_ip6[2] = bpf_htonl(DST_REWRITE_IP6_V4_MAPPED_2);
|
||||
ctx->user_ip6[3] = bpf_htonl(DST_REWRITE_IP6_V4_MAPPED_3);
|
||||
|
||||
ctx->user_port = bpf_htons(DST_REWRITE_PORT6);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
SEC("cgroup/sendmsg6")
|
||||
int sendmsg_v6_wildcard_prog(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
/* Rewrite source. */
|
||||
ctx->msg_src_ip6[0] = bpf_htonl(SRC_REWRITE_IP6_0);
|
||||
ctx->msg_src_ip6[1] = bpf_htonl(SRC_REWRITE_IP6_1);
|
||||
ctx->msg_src_ip6[2] = bpf_htonl(SRC_REWRITE_IP6_2);
|
||||
ctx->msg_src_ip6[3] = bpf_htonl(SRC_REWRITE_IP6_3);
|
||||
|
||||
/* Rewrite destination. */
|
||||
ctx->user_ip6[0] = bpf_htonl(0);
|
||||
ctx->user_ip6[1] = bpf_htonl(0);
|
||||
ctx->user_ip6[2] = bpf_htonl(0);
|
||||
ctx->user_ip6[3] = bpf_htonl(0);
|
||||
|
||||
ctx->user_port = bpf_htons(DST_REWRITE_PORT6);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
SEC("cgroup/sendmsg6")
|
||||
int sendmsg_v6_preserve_dst_prog(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
SEC("cgroup/sendmsg6")
|
||||
int sendmsg_v6_deny_prog(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
char _license[] SEC("license") = "GPL";
|
||||
|
@ -36,4 +36,10 @@ int sendmsg_unix_prog(struct bpf_sock_addr *ctx)
|
||||
return 1;
|
||||
}
|
||||
|
||||
SEC("cgroup/sendmsg_unix")
|
||||
int sendmsg_unix_deny_prog(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
char _license[] SEC("license") = "GPL";
|
||||
|
331
tools/testing/selftests/bpf/progs/verifier_sock_addr.c
Normal file
331
tools/testing/selftests/bpf/progs/verifier_sock_addr.c
Normal file
@ -0,0 +1,331 @@
|
||||
// SPDX-License-Identifier: GPL-2.0
|
||||
/* Copyright (c) 2024 Google LLC */
|
||||
|
||||
#include <linux/bpf.h>
|
||||
#include <bpf/bpf_helpers.h>
|
||||
#include <bpf_sockopt_helpers.h>
|
||||
#include "bpf_misc.h"
|
||||
|
||||
SEC("cgroup/recvmsg4")
|
||||
__success
|
||||
int recvmsg4_good_return_code(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
SEC("cgroup/recvmsg4")
|
||||
__failure __msg("At program exit the register R0 has smin=0 smax=0 should have been in [1, 1]")
|
||||
int recvmsg4_bad_return_code(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
SEC("cgroup/recvmsg6")
|
||||
__success
|
||||
int recvmsg6_good_return_code(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
SEC("cgroup/recvmsg6")
|
||||
__failure __msg("At program exit the register R0 has smin=0 smax=0 should have been in [1, 1]")
|
||||
int recvmsg6_bad_return_code(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
SEC("cgroup/recvmsg_unix")
|
||||
__success
|
||||
int recvmsg_unix_good_return_code(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
SEC("cgroup/recvmsg_unix")
|
||||
__failure __msg("At program exit the register R0 has smin=0 smax=0 should have been in [1, 1]")
|
||||
int recvmsg_unix_bad_return_code(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
SEC("cgroup/sendmsg4")
|
||||
__success
|
||||
int sendmsg4_good_return_code_0(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
SEC("cgroup/sendmsg4")
|
||||
__success
|
||||
int sendmsg4_good_return_code_1(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
SEC("cgroup/sendmsg4")
|
||||
__failure __msg("At program exit the register R0 has smin=2 smax=2 should have been in [0, 1]")
|
||||
int sendmsg4_bad_return_code(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
SEC("cgroup/sendmsg6")
|
||||
__success
|
||||
int sendmsg6_good_return_code_0(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
SEC("cgroup/sendmsg6")
|
||||
__success
|
||||
int sendmsg6_good_return_code_1(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
SEC("cgroup/sendmsg6")
|
||||
__failure __msg("At program exit the register R0 has smin=2 smax=2 should have been in [0, 1]")
|
||||
int sendmsg6_bad_return_code(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
SEC("cgroup/sendmsg_unix")
|
||||
__success
|
||||
int sendmsg_unix_good_return_code_0(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
SEC("cgroup/sendmsg_unix")
|
||||
__success
|
||||
int sendmsg_unix_good_return_code_1(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
SEC("cgroup/sendmsg_unix")
|
||||
__failure __msg("At program exit the register R0 has smin=2 smax=2 should have been in [0, 1]")
|
||||
int sendmsg_unix_bad_return_code(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
SEC("cgroup/getpeername4")
|
||||
__success
|
||||
int getpeername4_good_return_code(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
SEC("cgroup/getpeername4")
|
||||
__failure __msg("At program exit the register R0 has smin=0 smax=0 should have been in [1, 1]")
|
||||
int getpeername4_bad_return_code(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
SEC("cgroup/getpeername6")
|
||||
__success
|
||||
int getpeername6_good_return_code(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
SEC("cgroup/getpeername6")
|
||||
__failure __msg("At program exit the register R0 has smin=0 smax=0 should have been in [1, 1]")
|
||||
int getpeername6_bad_return_code(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
SEC("cgroup/getpeername_unix")
|
||||
__success
|
||||
int getpeername_unix_good_return_code(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
SEC("cgroup/getpeername_unix")
|
||||
__failure __msg("At program exit the register R0 has smin=0 smax=0 should have been in [1, 1]")
|
||||
int getpeername_unix_bad_return_code(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
SEC("cgroup/getsockname4")
|
||||
__success
|
||||
int getsockname4_good_return_code(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
SEC("cgroup/getsockname4")
|
||||
__failure __msg("At program exit the register R0 has smin=0 smax=0 should have been in [1, 1]")
|
||||
int getsockname4_bad_return_code(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
SEC("cgroup/getsockname6")
|
||||
__success
|
||||
int getsockname6_good_return_code(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
SEC("cgroup/getsockname6")
|
||||
__failure __msg("At program exit the register R0 has smin=0 smax=0 should have been in [1, 1]")
|
||||
int getsockname6_bad_return_code(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
SEC("cgroup/getsockname_unix")
|
||||
__success
|
||||
int getsockname_unix_good_return_code(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
SEC("cgroup/getsockname_unix")
|
||||
__failure __msg("At program exit the register R0 has smin=0 smax=0 should have been in [1, 1]")
|
||||
int getsockname_unix_unix_bad_return_code(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
SEC("cgroup/bind4")
|
||||
__success
|
||||
int bind4_good_return_code_0(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
SEC("cgroup/bind4")
|
||||
__success
|
||||
int bind4_good_return_code_1(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
SEC("cgroup/bind4")
|
||||
__success
|
||||
int bind4_good_return_code_2(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
SEC("cgroup/bind4")
|
||||
__success
|
||||
int bind4_good_return_code_3(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
SEC("cgroup/bind4")
|
||||
__failure __msg("At program exit the register R0 has smin=4 smax=4 should have been in [0, 3]")
|
||||
int bind4_bad_return_code(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
|
||||
SEC("cgroup/bind6")
|
||||
__success
|
||||
int bind6_good_return_code_0(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
SEC("cgroup/bind6")
|
||||
__success
|
||||
int bind6_good_return_code_1(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
SEC("cgroup/bind6")
|
||||
__success
|
||||
int bind6_good_return_code_2(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
SEC("cgroup/bind6")
|
||||
__success
|
||||
int bind6_good_return_code_3(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
SEC("cgroup/bind6")
|
||||
__failure __msg("At program exit the register R0 has smin=4 smax=4 should have been in [0, 3]")
|
||||
int bind6_bad_return_code(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
|
||||
SEC("cgroup/connect4")
|
||||
__success
|
||||
int connect4_good_return_code_0(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
SEC("cgroup/connect4")
|
||||
__success
|
||||
int connect4_good_return_code_1(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
SEC("cgroup/connect4")
|
||||
__failure __msg("At program exit the register R0 has smin=2 smax=2 should have been in [0, 1]")
|
||||
int connect4_bad_return_code(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
SEC("cgroup/connect6")
|
||||
__success
|
||||
int connect6_good_return_code_0(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
SEC("cgroup/connect6")
|
||||
__success
|
||||
int connect6_good_return_code_1(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
SEC("cgroup/connect6")
|
||||
__failure __msg("At program exit the register R0 has smin=2 smax=2 should have been in [0, 1]")
|
||||
int connect6_bad_return_code(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
SEC("cgroup/connect_unix")
|
||||
__success
|
||||
int connect_unix_good_return_code_0(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
SEC("cgroup/connect_unix")
|
||||
__success
|
||||
int connect_unix_good_return_code_1(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
SEC("cgroup/connect_unix")
|
||||
__failure __msg("At program exit the register R0 has smin=2 smax=2 should have been in [0, 1]")
|
||||
int connect_unix_bad_return_code(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
char _license[] SEC("license") = "GPL";
|
File diff suppressed because it is too large
Load Diff
@ -1,58 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -eu
|
||||
|
||||
ping_once()
|
||||
{
|
||||
type ping${1} >/dev/null 2>&1 && PING="ping${1}" || PING="ping -${1}"
|
||||
$PING -q -c 1 -W 1 ${2%%/*} >/dev/null 2>&1
|
||||
}
|
||||
|
||||
wait_for_ip()
|
||||
{
|
||||
local _i
|
||||
echo -n "Wait for testing IPv4/IPv6 to become available "
|
||||
for _i in $(seq ${MAX_PING_TRIES}); do
|
||||
echo -n "."
|
||||
if ping_once 4 ${TEST_IPv4} && ping_once 6 ${TEST_IPv6}; then
|
||||
echo " OK"
|
||||
return
|
||||
fi
|
||||
done
|
||||
echo 1>&2 "ERROR: Timeout waiting for test IP to become available."
|
||||
exit 1
|
||||
}
|
||||
|
||||
setup()
|
||||
{
|
||||
# Create testing interfaces not to interfere with current environment.
|
||||
ip link add dev ${TEST_IF} type veth peer name ${TEST_IF_PEER}
|
||||
ip link set ${TEST_IF} up
|
||||
ip link set ${TEST_IF_PEER} up
|
||||
|
||||
ip -4 addr add ${TEST_IPv4} dev ${TEST_IF}
|
||||
ip -6 addr add ${TEST_IPv6} dev ${TEST_IF}
|
||||
wait_for_ip
|
||||
}
|
||||
|
||||
cleanup()
|
||||
{
|
||||
ip link del ${TEST_IF} 2>/dev/null || :
|
||||
ip link del ${TEST_IF_PEER} 2>/dev/null || :
|
||||
}
|
||||
|
||||
main()
|
||||
{
|
||||
trap cleanup EXIT 2 3 6 15
|
||||
setup
|
||||
./test_sock_addr setup_done
|
||||
}
|
||||
|
||||
BASENAME=$(basename $0 .sh)
|
||||
TEST_IF="${BASENAME}1"
|
||||
TEST_IF_PEER="${BASENAME}2"
|
||||
TEST_IPv4="127.0.0.4/8"
|
||||
TEST_IPv6="::6/128"
|
||||
MAX_PING_TRIES=5
|
||||
|
||||
main
|
Loading…
x
Reference in New Issue
Block a user