selftests/bpf: Switch SEC("classifier*") usage to a strict SEC("tc")
Convert all SEC("classifier*") uses to a new and strict SEC("tc") section name. In reference_tracking selftests switch from ambiguous searching by program title (section name) to non-ambiguous searching by name in some selftests, getting closer to completely removing bpf_object__find_program_by_title(). Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/20210928161946.2512801-4-andrii@kernel.org
This commit is contained in:
parent
8fffa0e345
commit
c22bdd2825
|
@ -2,14 +2,14 @@
|
||||||
#include <test_progs.h>
|
#include <test_progs.h>
|
||||||
|
|
||||||
static void toggle_object_autoload_progs(const struct bpf_object *obj,
|
static void toggle_object_autoload_progs(const struct bpf_object *obj,
|
||||||
const char *title_load)
|
const char *name_load)
|
||||||
{
|
{
|
||||||
struct bpf_program *prog;
|
struct bpf_program *prog;
|
||||||
|
|
||||||
bpf_object__for_each_program(prog, obj) {
|
bpf_object__for_each_program(prog, obj) {
|
||||||
const char *title = bpf_program__section_name(prog);
|
const char *name = bpf_program__name(prog);
|
||||||
|
|
||||||
if (!strcmp(title_load, title))
|
if (!strcmp(name_load, name))
|
||||||
bpf_program__set_autoload(prog, true);
|
bpf_program__set_autoload(prog, true);
|
||||||
else
|
else
|
||||||
bpf_program__set_autoload(prog, false);
|
bpf_program__set_autoload(prog, false);
|
||||||
|
@ -39,23 +39,19 @@ void test_reference_tracking(void)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
bpf_object__for_each_program(prog, obj_iter) {
|
bpf_object__for_each_program(prog, obj_iter) {
|
||||||
const char *title;
|
const char *name;
|
||||||
|
|
||||||
/* Ignore .text sections */
|
name = bpf_program__name(prog);
|
||||||
title = bpf_program__section_name(prog);
|
if (!test__start_subtest(name))
|
||||||
if (strstr(title, ".text") != NULL)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (!test__start_subtest(title))
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
obj = bpf_object__open_file(file, &open_opts);
|
obj = bpf_object__open_file(file, &open_opts);
|
||||||
if (!ASSERT_OK_PTR(obj, "obj_open_file"))
|
if (!ASSERT_OK_PTR(obj, "obj_open_file"))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
toggle_object_autoload_progs(obj, title);
|
toggle_object_autoload_progs(obj, name);
|
||||||
/* Expect verifier failure if test name has 'err' */
|
/* Expect verifier failure if test name has 'err' */
|
||||||
if (strstr(title, "err_") != NULL) {
|
if (strncmp(name, "err_", sizeof("err_") - 1) == 0) {
|
||||||
libbpf_print_fn_t old_print_fn;
|
libbpf_print_fn_t old_print_fn;
|
||||||
|
|
||||||
old_print_fn = libbpf_set_print(NULL);
|
old_print_fn = libbpf_set_print(NULL);
|
||||||
|
@ -64,7 +60,8 @@ void test_reference_tracking(void)
|
||||||
} else {
|
} else {
|
||||||
err = bpf_object__load(obj);
|
err = bpf_object__load(obj);
|
||||||
}
|
}
|
||||||
CHECK(err, title, "\n");
|
ASSERT_OK(err, name);
|
||||||
|
|
||||||
bpf_object__close(obj);
|
bpf_object__close(obj);
|
||||||
obj = NULL;
|
obj = NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ configure_stack(void)
|
||||||
return false;
|
return false;
|
||||||
sprintf(tc_cmd, "%s %s %s %s", "tc filter add dev lo ingress bpf",
|
sprintf(tc_cmd, "%s %s %s %s", "tc filter add dev lo ingress bpf",
|
||||||
"direct-action object-file ./test_sk_assign.o",
|
"direct-action object-file ./test_sk_assign.o",
|
||||||
"section classifier/sk_assign_test",
|
"section tc",
|
||||||
(env.verbosity < VERBOSE_VERY) ? " 2>/dev/null" : "verbose");
|
(env.verbosity < VERBOSE_VERY) ? " 2>/dev/null" : "verbose");
|
||||||
if (CHECK(system(tc_cmd), "BPF load failed;",
|
if (CHECK(system(tc_cmd), "BPF load failed;",
|
||||||
"run with -vv for more info\n"))
|
"run with -vv for more info\n"))
|
||||||
|
|
|
@ -21,7 +21,7 @@ static void test_tailcall_1(void)
|
||||||
if (CHECK_FAIL(err))
|
if (CHECK_FAIL(err))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
prog = bpf_object__find_program_by_title(obj, "classifier");
|
prog = bpf_object__find_program_by_name(obj, "entry");
|
||||||
if (CHECK_FAIL(!prog))
|
if (CHECK_FAIL(!prog))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
@ -38,9 +38,9 @@ static void test_tailcall_1(void)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
for (i = 0; i < bpf_map__def(prog_array)->max_entries; i++) {
|
for (i = 0; i < bpf_map__def(prog_array)->max_entries; i++) {
|
||||||
snprintf(prog_name, sizeof(prog_name), "classifier/%i", i);
|
snprintf(prog_name, sizeof(prog_name), "classifier_%d", i);
|
||||||
|
|
||||||
prog = bpf_object__find_program_by_title(obj, prog_name);
|
prog = bpf_object__find_program_by_name(obj, prog_name);
|
||||||
if (CHECK_FAIL(!prog))
|
if (CHECK_FAIL(!prog))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
@ -70,9 +70,9 @@ static void test_tailcall_1(void)
|
||||||
err, errno, retval);
|
err, errno, retval);
|
||||||
|
|
||||||
for (i = 0; i < bpf_map__def(prog_array)->max_entries; i++) {
|
for (i = 0; i < bpf_map__def(prog_array)->max_entries; i++) {
|
||||||
snprintf(prog_name, sizeof(prog_name), "classifier/%i", i);
|
snprintf(prog_name, sizeof(prog_name), "classifier_%d", i);
|
||||||
|
|
||||||
prog = bpf_object__find_program_by_title(obj, prog_name);
|
prog = bpf_object__find_program_by_name(obj, prog_name);
|
||||||
if (CHECK_FAIL(!prog))
|
if (CHECK_FAIL(!prog))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
@ -92,9 +92,9 @@ static void test_tailcall_1(void)
|
||||||
|
|
||||||
for (i = 0; i < bpf_map__def(prog_array)->max_entries; i++) {
|
for (i = 0; i < bpf_map__def(prog_array)->max_entries; i++) {
|
||||||
j = bpf_map__def(prog_array)->max_entries - 1 - i;
|
j = bpf_map__def(prog_array)->max_entries - 1 - i;
|
||||||
snprintf(prog_name, sizeof(prog_name), "classifier/%i", j);
|
snprintf(prog_name, sizeof(prog_name), "classifier_%d", j);
|
||||||
|
|
||||||
prog = bpf_object__find_program_by_title(obj, prog_name);
|
prog = bpf_object__find_program_by_name(obj, prog_name);
|
||||||
if (CHECK_FAIL(!prog))
|
if (CHECK_FAIL(!prog))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
@ -159,7 +159,7 @@ static void test_tailcall_2(void)
|
||||||
if (CHECK_FAIL(err))
|
if (CHECK_FAIL(err))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
prog = bpf_object__find_program_by_title(obj, "classifier");
|
prog = bpf_object__find_program_by_name(obj, "entry");
|
||||||
if (CHECK_FAIL(!prog))
|
if (CHECK_FAIL(!prog))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
@ -176,9 +176,9 @@ static void test_tailcall_2(void)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
for (i = 0; i < bpf_map__def(prog_array)->max_entries; i++) {
|
for (i = 0; i < bpf_map__def(prog_array)->max_entries; i++) {
|
||||||
snprintf(prog_name, sizeof(prog_name), "classifier/%i", i);
|
snprintf(prog_name, sizeof(prog_name), "classifier_%d", i);
|
||||||
|
|
||||||
prog = bpf_object__find_program_by_title(obj, prog_name);
|
prog = bpf_object__find_program_by_name(obj, prog_name);
|
||||||
if (CHECK_FAIL(!prog))
|
if (CHECK_FAIL(!prog))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
@ -233,7 +233,7 @@ static void test_tailcall_count(const char *which)
|
||||||
if (CHECK_FAIL(err))
|
if (CHECK_FAIL(err))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
prog = bpf_object__find_program_by_title(obj, "classifier");
|
prog = bpf_object__find_program_by_name(obj, "entry");
|
||||||
if (CHECK_FAIL(!prog))
|
if (CHECK_FAIL(!prog))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
@ -249,7 +249,7 @@ static void test_tailcall_count(const char *which)
|
||||||
if (CHECK_FAIL(map_fd < 0))
|
if (CHECK_FAIL(map_fd < 0))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
prog = bpf_object__find_program_by_title(obj, "classifier/0");
|
prog = bpf_object__find_program_by_name(obj, "classifier_0");
|
||||||
if (CHECK_FAIL(!prog))
|
if (CHECK_FAIL(!prog))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
@ -329,7 +329,7 @@ static void test_tailcall_4(void)
|
||||||
if (CHECK_FAIL(err))
|
if (CHECK_FAIL(err))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
prog = bpf_object__find_program_by_title(obj, "classifier");
|
prog = bpf_object__find_program_by_name(obj, "entry");
|
||||||
if (CHECK_FAIL(!prog))
|
if (CHECK_FAIL(!prog))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
@ -354,9 +354,9 @@ static void test_tailcall_4(void)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (i = 0; i < bpf_map__def(prog_array)->max_entries; i++) {
|
for (i = 0; i < bpf_map__def(prog_array)->max_entries; i++) {
|
||||||
snprintf(prog_name, sizeof(prog_name), "classifier/%i", i);
|
snprintf(prog_name, sizeof(prog_name), "classifier_%d", i);
|
||||||
|
|
||||||
prog = bpf_object__find_program_by_title(obj, prog_name);
|
prog = bpf_object__find_program_by_name(obj, prog_name);
|
||||||
if (CHECK_FAIL(!prog))
|
if (CHECK_FAIL(!prog))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
@ -417,7 +417,7 @@ static void test_tailcall_5(void)
|
||||||
if (CHECK_FAIL(err))
|
if (CHECK_FAIL(err))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
prog = bpf_object__find_program_by_title(obj, "classifier");
|
prog = bpf_object__find_program_by_name(obj, "entry");
|
||||||
if (CHECK_FAIL(!prog))
|
if (CHECK_FAIL(!prog))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
@ -442,9 +442,9 @@ static void test_tailcall_5(void)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (i = 0; i < bpf_map__def(prog_array)->max_entries; i++) {
|
for (i = 0; i < bpf_map__def(prog_array)->max_entries; i++) {
|
||||||
snprintf(prog_name, sizeof(prog_name), "classifier/%i", i);
|
snprintf(prog_name, sizeof(prog_name), "classifier_%d", i);
|
||||||
|
|
||||||
prog = bpf_object__find_program_by_title(obj, prog_name);
|
prog = bpf_object__find_program_by_name(obj, prog_name);
|
||||||
if (CHECK_FAIL(!prog))
|
if (CHECK_FAIL(!prog))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
@ -503,7 +503,7 @@ static void test_tailcall_bpf2bpf_1(void)
|
||||||
if (CHECK_FAIL(err))
|
if (CHECK_FAIL(err))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
prog = bpf_object__find_program_by_title(obj, "classifier");
|
prog = bpf_object__find_program_by_name(obj, "entry");
|
||||||
if (CHECK_FAIL(!prog))
|
if (CHECK_FAIL(!prog))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
@ -521,9 +521,9 @@ static void test_tailcall_bpf2bpf_1(void)
|
||||||
|
|
||||||
/* nop -> jmp */
|
/* nop -> jmp */
|
||||||
for (i = 0; i < bpf_map__def(prog_array)->max_entries; i++) {
|
for (i = 0; i < bpf_map__def(prog_array)->max_entries; i++) {
|
||||||
snprintf(prog_name, sizeof(prog_name), "classifier/%i", i);
|
snprintf(prog_name, sizeof(prog_name), "classifier_%d", i);
|
||||||
|
|
||||||
prog = bpf_object__find_program_by_title(obj, prog_name);
|
prog = bpf_object__find_program_by_name(obj, prog_name);
|
||||||
if (CHECK_FAIL(!prog))
|
if (CHECK_FAIL(!prog))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
@ -587,7 +587,7 @@ static void test_tailcall_bpf2bpf_2(void)
|
||||||
if (CHECK_FAIL(err))
|
if (CHECK_FAIL(err))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
prog = bpf_object__find_program_by_title(obj, "classifier");
|
prog = bpf_object__find_program_by_name(obj, "entry");
|
||||||
if (CHECK_FAIL(!prog))
|
if (CHECK_FAIL(!prog))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
@ -603,7 +603,7 @@ static void test_tailcall_bpf2bpf_2(void)
|
||||||
if (CHECK_FAIL(map_fd < 0))
|
if (CHECK_FAIL(map_fd < 0))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
prog = bpf_object__find_program_by_title(obj, "classifier/0");
|
prog = bpf_object__find_program_by_name(obj, "classifier_0");
|
||||||
if (CHECK_FAIL(!prog))
|
if (CHECK_FAIL(!prog))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
@ -665,7 +665,7 @@ static void test_tailcall_bpf2bpf_3(void)
|
||||||
if (CHECK_FAIL(err))
|
if (CHECK_FAIL(err))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
prog = bpf_object__find_program_by_title(obj, "classifier");
|
prog = bpf_object__find_program_by_name(obj, "entry");
|
||||||
if (CHECK_FAIL(!prog))
|
if (CHECK_FAIL(!prog))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
@ -682,9 +682,9 @@ static void test_tailcall_bpf2bpf_3(void)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
for (i = 0; i < bpf_map__def(prog_array)->max_entries; i++) {
|
for (i = 0; i < bpf_map__def(prog_array)->max_entries; i++) {
|
||||||
snprintf(prog_name, sizeof(prog_name), "classifier/%i", i);
|
snprintf(prog_name, sizeof(prog_name), "classifier_%d", i);
|
||||||
|
|
||||||
prog = bpf_object__find_program_by_title(obj, prog_name);
|
prog = bpf_object__find_program_by_name(obj, prog_name);
|
||||||
if (CHECK_FAIL(!prog))
|
if (CHECK_FAIL(!prog))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
@ -762,7 +762,7 @@ static void test_tailcall_bpf2bpf_4(bool noise)
|
||||||
if (CHECK_FAIL(err))
|
if (CHECK_FAIL(err))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
prog = bpf_object__find_program_by_title(obj, "classifier");
|
prog = bpf_object__find_program_by_name(obj, "entry");
|
||||||
if (CHECK_FAIL(!prog))
|
if (CHECK_FAIL(!prog))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
@ -779,9 +779,9 @@ static void test_tailcall_bpf2bpf_4(bool noise)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
for (i = 0; i < bpf_map__def(prog_array)->max_entries; i++) {
|
for (i = 0; i < bpf_map__def(prog_array)->max_entries; i++) {
|
||||||
snprintf(prog_name, sizeof(prog_name), "classifier/%i", i);
|
snprintf(prog_name, sizeof(prog_name), "classifier_%d", i);
|
||||||
|
|
||||||
prog = bpf_object__find_program_by_title(obj, prog_name);
|
prog = bpf_object__find_program_by_name(obj, prog_name);
|
||||||
if (CHECK_FAIL(!prog))
|
if (CHECK_FAIL(!prog))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@ check_percpu_elem(struct bpf_map *map, __u32 *key, __u64 *val,
|
||||||
|
|
||||||
u32 arraymap_output = 0;
|
u32 arraymap_output = 0;
|
||||||
|
|
||||||
SEC("classifier")
|
SEC("tc")
|
||||||
int test_pkt_access(struct __sk_buff *skb)
|
int test_pkt_access(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
struct callback_ctx data;
|
struct callback_ctx data;
|
||||||
|
|
|
@ -78,7 +78,7 @@ int hashmap_output = 0;
|
||||||
int hashmap_elems = 0;
|
int hashmap_elems = 0;
|
||||||
int percpu_map_elems = 0;
|
int percpu_map_elems = 0;
|
||||||
|
|
||||||
SEC("classifier")
|
SEC("tc")
|
||||||
int test_pkt_access(struct __sk_buff *skb)
|
int test_pkt_access(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
struct callback_ctx data;
|
struct callback_ctx data;
|
||||||
|
|
|
@ -8,7 +8,7 @@ extern int bpf_kfunc_call_test2(struct sock *sk, __u32 a, __u32 b) __ksym;
|
||||||
extern __u64 bpf_kfunc_call_test1(struct sock *sk, __u32 a, __u64 b,
|
extern __u64 bpf_kfunc_call_test1(struct sock *sk, __u32 a, __u64 b,
|
||||||
__u32 c, __u64 d) __ksym;
|
__u32 c, __u64 d) __ksym;
|
||||||
|
|
||||||
SEC("classifier")
|
SEC("tc")
|
||||||
int kfunc_call_test2(struct __sk_buff *skb)
|
int kfunc_call_test2(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
struct bpf_sock *sk = skb->sk;
|
struct bpf_sock *sk = skb->sk;
|
||||||
|
@ -23,7 +23,7 @@ int kfunc_call_test2(struct __sk_buff *skb)
|
||||||
return bpf_kfunc_call_test2((struct sock *)sk, 1, 2);
|
return bpf_kfunc_call_test2((struct sock *)sk, 1, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
SEC("classifier")
|
SEC("tc")
|
||||||
int kfunc_call_test1(struct __sk_buff *skb)
|
int kfunc_call_test1(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
struct bpf_sock *sk = skb->sk;
|
struct bpf_sock *sk = skb->sk;
|
||||||
|
|
|
@ -33,7 +33,7 @@ int __noinline f1(struct __sk_buff *skb)
|
||||||
return (__u32)bpf_kfunc_call_test1((struct sock *)sk, 1, 2, 3, 4);
|
return (__u32)bpf_kfunc_call_test1((struct sock *)sk, 1, 2, 3, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
SEC("classifier")
|
SEC("tc")
|
||||||
int kfunc_call_test1(struct __sk_buff *skb)
|
int kfunc_call_test1(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
return f1(skb);
|
return f1(skb);
|
||||||
|
|
|
@ -25,7 +25,7 @@ out:
|
||||||
return ip;
|
return ip;
|
||||||
}
|
}
|
||||||
|
|
||||||
SEC("classifier/cls")
|
SEC("tc")
|
||||||
int main_prog(struct __sk_buff *skb)
|
int main_prog(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
struct iphdr *ip = NULL;
|
struct iphdr *ip = NULL;
|
||||||
|
|
|
@ -11,8 +11,8 @@ struct {
|
||||||
} jmp_table SEC(".maps");
|
} jmp_table SEC(".maps");
|
||||||
|
|
||||||
#define TAIL_FUNC(x) \
|
#define TAIL_FUNC(x) \
|
||||||
SEC("classifier/" #x) \
|
SEC("tc") \
|
||||||
int bpf_func_##x(struct __sk_buff *skb) \
|
int classifier_##x(struct __sk_buff *skb) \
|
||||||
{ \
|
{ \
|
||||||
return x; \
|
return x; \
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ TAIL_FUNC(0)
|
||||||
TAIL_FUNC(1)
|
TAIL_FUNC(1)
|
||||||
TAIL_FUNC(2)
|
TAIL_FUNC(2)
|
||||||
|
|
||||||
SEC("classifier")
|
SEC("tc")
|
||||||
int entry(struct __sk_buff *skb)
|
int entry(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
/* Multiple locations to make sure we patch
|
/* Multiple locations to make sure we patch
|
||||||
|
@ -45,4 +45,3 @@ int entry(struct __sk_buff *skb)
|
||||||
}
|
}
|
||||||
|
|
||||||
char __license[] SEC("license") = "GPL";
|
char __license[] SEC("license") = "GPL";
|
||||||
int _version SEC("version") = 1;
|
|
||||||
|
|
|
@ -10,41 +10,41 @@ struct {
|
||||||
__uint(value_size, sizeof(__u32));
|
__uint(value_size, sizeof(__u32));
|
||||||
} jmp_table SEC(".maps");
|
} jmp_table SEC(".maps");
|
||||||
|
|
||||||
SEC("classifier/0")
|
SEC("tc")
|
||||||
int bpf_func_0(struct __sk_buff *skb)
|
int classifier_0(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
bpf_tail_call_static(skb, &jmp_table, 1);
|
bpf_tail_call_static(skb, &jmp_table, 1);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SEC("classifier/1")
|
SEC("tc")
|
||||||
int bpf_func_1(struct __sk_buff *skb)
|
int classifier_1(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
bpf_tail_call_static(skb, &jmp_table, 2);
|
bpf_tail_call_static(skb, &jmp_table, 2);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
SEC("classifier/2")
|
SEC("tc")
|
||||||
int bpf_func_2(struct __sk_buff *skb)
|
int classifier_2(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
SEC("classifier/3")
|
SEC("tc")
|
||||||
int bpf_func_3(struct __sk_buff *skb)
|
int classifier_3(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
bpf_tail_call_static(skb, &jmp_table, 4);
|
bpf_tail_call_static(skb, &jmp_table, 4);
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
SEC("classifier/4")
|
SEC("tc")
|
||||||
int bpf_func_4(struct __sk_buff *skb)
|
int classifier_4(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
bpf_tail_call_static(skb, &jmp_table, 3);
|
bpf_tail_call_static(skb, &jmp_table, 3);
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
SEC("classifier")
|
SEC("tc")
|
||||||
int entry(struct __sk_buff *skb)
|
int entry(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
bpf_tail_call_static(skb, &jmp_table, 0);
|
bpf_tail_call_static(skb, &jmp_table, 0);
|
||||||
|
@ -56,4 +56,3 @@ int entry(struct __sk_buff *skb)
|
||||||
}
|
}
|
||||||
|
|
||||||
char __license[] SEC("license") = "GPL";
|
char __license[] SEC("license") = "GPL";
|
||||||
int _version SEC("version") = 1;
|
|
||||||
|
|
|
@ -12,15 +12,15 @@ struct {
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
SEC("classifier/0")
|
SEC("tc")
|
||||||
int bpf_func_0(struct __sk_buff *skb)
|
int classifier_0(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
count++;
|
count++;
|
||||||
bpf_tail_call_static(skb, &jmp_table, 0);
|
bpf_tail_call_static(skb, &jmp_table, 0);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
SEC("classifier")
|
SEC("tc")
|
||||||
int entry(struct __sk_buff *skb)
|
int entry(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
bpf_tail_call_static(skb, &jmp_table, 0);
|
bpf_tail_call_static(skb, &jmp_table, 0);
|
||||||
|
@ -28,4 +28,3 @@ int entry(struct __sk_buff *skb)
|
||||||
}
|
}
|
||||||
|
|
||||||
char __license[] SEC("license") = "GPL";
|
char __license[] SEC("license") = "GPL";
|
||||||
int _version SEC("version") = 1;
|
|
||||||
|
|
|
@ -13,8 +13,8 @@ struct {
|
||||||
int selector = 0;
|
int selector = 0;
|
||||||
|
|
||||||
#define TAIL_FUNC(x) \
|
#define TAIL_FUNC(x) \
|
||||||
SEC("classifier/" #x) \
|
SEC("tc") \
|
||||||
int bpf_func_##x(struct __sk_buff *skb) \
|
int classifier_##x(struct __sk_buff *skb) \
|
||||||
{ \
|
{ \
|
||||||
return x; \
|
return x; \
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ TAIL_FUNC(0)
|
||||||
TAIL_FUNC(1)
|
TAIL_FUNC(1)
|
||||||
TAIL_FUNC(2)
|
TAIL_FUNC(2)
|
||||||
|
|
||||||
SEC("classifier")
|
SEC("tc")
|
||||||
int entry(struct __sk_buff *skb)
|
int entry(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
bpf_tail_call(skb, &jmp_table, selector);
|
bpf_tail_call(skb, &jmp_table, selector);
|
||||||
|
@ -30,4 +30,3 @@ int entry(struct __sk_buff *skb)
|
||||||
}
|
}
|
||||||
|
|
||||||
char __license[] SEC("license") = "GPL";
|
char __license[] SEC("license") = "GPL";
|
||||||
int _version SEC("version") = 1;
|
|
||||||
|
|
|
@ -13,8 +13,8 @@ struct {
|
||||||
int selector = 0;
|
int selector = 0;
|
||||||
|
|
||||||
#define TAIL_FUNC(x) \
|
#define TAIL_FUNC(x) \
|
||||||
SEC("classifier/" #x) \
|
SEC("tc") \
|
||||||
int bpf_func_##x(struct __sk_buff *skb) \
|
int classifier_##x(struct __sk_buff *skb) \
|
||||||
{ \
|
{ \
|
||||||
return x; \
|
return x; \
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ TAIL_FUNC(0)
|
||||||
TAIL_FUNC(1)
|
TAIL_FUNC(1)
|
||||||
TAIL_FUNC(2)
|
TAIL_FUNC(2)
|
||||||
|
|
||||||
SEC("classifier")
|
SEC("tc")
|
||||||
int entry(struct __sk_buff *skb)
|
int entry(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
|
@ -37,4 +37,3 @@ int entry(struct __sk_buff *skb)
|
||||||
}
|
}
|
||||||
|
|
||||||
char __license[] SEC("license") = "GPL";
|
char __license[] SEC("license") = "GPL";
|
||||||
int _version SEC("version") = 1;
|
|
||||||
|
|
|
@ -12,8 +12,8 @@ struct {
|
||||||
|
|
||||||
int count, which;
|
int count, which;
|
||||||
|
|
||||||
SEC("classifier/0")
|
SEC("tc")
|
||||||
int bpf_func_0(struct __sk_buff *skb)
|
int classifier_0(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
count++;
|
count++;
|
||||||
if (__builtin_constant_p(which))
|
if (__builtin_constant_p(which))
|
||||||
|
@ -22,7 +22,7 @@ int bpf_func_0(struct __sk_buff *skb)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
SEC("classifier")
|
SEC("tc")
|
||||||
int entry(struct __sk_buff *skb)
|
int entry(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
if (__builtin_constant_p(which))
|
if (__builtin_constant_p(which))
|
||||||
|
|
|
@ -10,8 +10,8 @@ struct {
|
||||||
} jmp_table SEC(".maps");
|
} jmp_table SEC(".maps");
|
||||||
|
|
||||||
#define TAIL_FUNC(x) \
|
#define TAIL_FUNC(x) \
|
||||||
SEC("classifier/" #x) \
|
SEC("tc") \
|
||||||
int bpf_func_##x(struct __sk_buff *skb) \
|
int classifier_##x(struct __sk_buff *skb) \
|
||||||
{ \
|
{ \
|
||||||
return x; \
|
return x; \
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ int subprog_tail(struct __sk_buff *skb)
|
||||||
return skb->len * 2;
|
return skb->len * 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
SEC("classifier")
|
SEC("tc")
|
||||||
int entry(struct __sk_buff *skb)
|
int entry(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
bpf_tail_call_static(skb, &jmp_table, 1);
|
bpf_tail_call_static(skb, &jmp_table, 1);
|
||||||
|
@ -35,4 +35,3 @@ int entry(struct __sk_buff *skb)
|
||||||
}
|
}
|
||||||
|
|
||||||
char __license[] SEC("license") = "GPL";
|
char __license[] SEC("license") = "GPL";
|
||||||
int _version SEC("version") = 1;
|
|
||||||
|
|
|
@ -22,14 +22,14 @@ int subprog_tail(struct __sk_buff *skb)
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
SEC("classifier/0")
|
SEC("tc")
|
||||||
int bpf_func_0(struct __sk_buff *skb)
|
int classifier_0(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
count++;
|
count++;
|
||||||
return subprog_tail(skb);
|
return subprog_tail(skb);
|
||||||
}
|
}
|
||||||
|
|
||||||
SEC("classifier")
|
SEC("tc")
|
||||||
int entry(struct __sk_buff *skb)
|
int entry(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
bpf_tail_call_static(skb, &jmp_table, 0);
|
bpf_tail_call_static(skb, &jmp_table, 0);
|
||||||
|
@ -38,4 +38,3 @@ int entry(struct __sk_buff *skb)
|
||||||
}
|
}
|
||||||
|
|
||||||
char __license[] SEC("license") = "GPL";
|
char __license[] SEC("license") = "GPL";
|
||||||
int _version SEC("version") = 1;
|
|
||||||
|
|
|
@ -33,23 +33,23 @@ int subprog_tail(struct __sk_buff *skb)
|
||||||
return skb->len * 2;
|
return skb->len * 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
SEC("classifier/0")
|
SEC("tc")
|
||||||
int bpf_func_0(struct __sk_buff *skb)
|
int classifier_0(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
volatile char arr[128] = {};
|
volatile char arr[128] = {};
|
||||||
|
|
||||||
return subprog_tail2(skb);
|
return subprog_tail2(skb);
|
||||||
}
|
}
|
||||||
|
|
||||||
SEC("classifier/1")
|
SEC("tc")
|
||||||
int bpf_func_1(struct __sk_buff *skb)
|
int classifier_1(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
volatile char arr[128] = {};
|
volatile char arr[128] = {};
|
||||||
|
|
||||||
return skb->len * 3;
|
return skb->len * 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
SEC("classifier")
|
SEC("tc")
|
||||||
int entry(struct __sk_buff *skb)
|
int entry(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
volatile char arr[128] = {};
|
volatile char arr[128] = {};
|
||||||
|
@ -58,4 +58,3 @@ int entry(struct __sk_buff *skb)
|
||||||
}
|
}
|
||||||
|
|
||||||
char __license[] SEC("license") = "GPL";
|
char __license[] SEC("license") = "GPL";
|
||||||
int _version SEC("version") = 1;
|
|
||||||
|
|
|
@ -50,30 +50,29 @@ int subprog_tail(struct __sk_buff *skb)
|
||||||
return skb->len;
|
return skb->len;
|
||||||
}
|
}
|
||||||
|
|
||||||
SEC("classifier/1")
|
SEC("tc")
|
||||||
int bpf_func_1(struct __sk_buff *skb)
|
int classifier_1(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
return subprog_tail_2(skb);
|
return subprog_tail_2(skb);
|
||||||
}
|
}
|
||||||
|
|
||||||
SEC("classifier/2")
|
SEC("tc")
|
||||||
int bpf_func_2(struct __sk_buff *skb)
|
int classifier_2(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
count++;
|
count++;
|
||||||
return subprog_tail_2(skb);
|
return subprog_tail_2(skb);
|
||||||
}
|
}
|
||||||
|
|
||||||
SEC("classifier/0")
|
SEC("tc")
|
||||||
int bpf_func_0(struct __sk_buff *skb)
|
int classifier_0(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
return subprog_tail_1(skb);
|
return subprog_tail_1(skb);
|
||||||
}
|
}
|
||||||
|
|
||||||
SEC("classifier")
|
SEC("tc")
|
||||||
int entry(struct __sk_buff *skb)
|
int entry(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
return subprog_tail(skb);
|
return subprog_tail(skb);
|
||||||
}
|
}
|
||||||
|
|
||||||
char __license[] SEC("license") = "GPL";
|
char __license[] SEC("license") = "GPL";
|
||||||
int _version SEC("version") = 1;
|
|
||||||
|
|
|
@ -145,7 +145,7 @@ release:
|
||||||
return TC_ACT_OK;
|
return TC_ACT_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
SEC("classifier/ingress")
|
SEC("tc")
|
||||||
int cls_ingress(struct __sk_buff *skb)
|
int cls_ingress(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
struct ipv6hdr *ip6h;
|
struct ipv6hdr *ip6h;
|
||||||
|
|
|
@ -153,7 +153,7 @@ int xdp_input_len_exceed(struct xdp_md *ctx)
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
SEC("classifier")
|
SEC("tc")
|
||||||
int tc_use_helper(struct __sk_buff *ctx)
|
int tc_use_helper(struct __sk_buff *ctx)
|
||||||
{
|
{
|
||||||
int retval = BPF_OK; /* Expected retval on successful test */
|
int retval = BPF_OK; /* Expected retval on successful test */
|
||||||
|
@ -172,7 +172,7 @@ out:
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
SEC("classifier")
|
SEC("tc")
|
||||||
int tc_exceed_mtu(struct __sk_buff *ctx)
|
int tc_exceed_mtu(struct __sk_buff *ctx)
|
||||||
{
|
{
|
||||||
__u32 ifindex = GLOBAL_USER_IFINDEX;
|
__u32 ifindex = GLOBAL_USER_IFINDEX;
|
||||||
|
@ -196,7 +196,7 @@ int tc_exceed_mtu(struct __sk_buff *ctx)
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
SEC("classifier")
|
SEC("tc")
|
||||||
int tc_exceed_mtu_da(struct __sk_buff *ctx)
|
int tc_exceed_mtu_da(struct __sk_buff *ctx)
|
||||||
{
|
{
|
||||||
/* SKB Direct-Access variant */
|
/* SKB Direct-Access variant */
|
||||||
|
@ -223,7 +223,7 @@ int tc_exceed_mtu_da(struct __sk_buff *ctx)
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
SEC("classifier")
|
SEC("tc")
|
||||||
int tc_minus_delta(struct __sk_buff *ctx)
|
int tc_minus_delta(struct __sk_buff *ctx)
|
||||||
{
|
{
|
||||||
int retval = BPF_OK; /* Expected retval on successful test */
|
int retval = BPF_OK; /* Expected retval on successful test */
|
||||||
|
@ -245,7 +245,7 @@ int tc_minus_delta(struct __sk_buff *ctx)
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
SEC("classifier")
|
SEC("tc")
|
||||||
int tc_input_len(struct __sk_buff *ctx)
|
int tc_input_len(struct __sk_buff *ctx)
|
||||||
{
|
{
|
||||||
int retval = BPF_OK; /* Expected retval on successful test */
|
int retval = BPF_OK; /* Expected retval on successful test */
|
||||||
|
@ -265,7 +265,7 @@ int tc_input_len(struct __sk_buff *ctx)
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
SEC("classifier")
|
SEC("tc")
|
||||||
int tc_input_len_exceed(struct __sk_buff *ctx)
|
int tc_input_len_exceed(struct __sk_buff *ctx)
|
||||||
{
|
{
|
||||||
int retval = BPF_DROP; /* Fail */
|
int retval = BPF_DROP; /* Fail */
|
||||||
|
|
|
@ -928,7 +928,7 @@ static INLINING verdict_t process_ipv6(buf_t *pkt, metrics_t *metrics)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SEC("classifier/cls_redirect")
|
SEC("tc")
|
||||||
int cls_redirect(struct __sk_buff *skb)
|
int cls_redirect(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
metrics_t *metrics = get_global_metrics();
|
metrics_t *metrics = get_global_metrics();
|
||||||
|
|
|
@ -68,7 +68,7 @@ static struct foo struct3 = {
|
||||||
bpf_map_update_elem(&result_##map, &key, var, 0); \
|
bpf_map_update_elem(&result_##map, &key, var, 0); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
SEC("classifier/static_data_load")
|
SEC("tc")
|
||||||
int load_static_data(struct __sk_buff *skb)
|
int load_static_data(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
static const __u64 bar = ~0;
|
static const __u64 bar = ~0;
|
||||||
|
|
|
@ -38,7 +38,7 @@ int f3(int val, struct __sk_buff *skb, int var)
|
||||||
return skb->ifindex * val * var;
|
return skb->ifindex * val * var;
|
||||||
}
|
}
|
||||||
|
|
||||||
SEC("classifier/test")
|
SEC("tc")
|
||||||
int test_cls(struct __sk_buff *skb)
|
int test_cls(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
return f0(1, skb) + f1(skb) + f2(2, skb) + f3(3, skb, 4);
|
return f0(1, skb) + f1(skb) + f2(2, skb) + f3(3, skb, 4);
|
||||||
|
|
|
@ -54,7 +54,7 @@ int f8(struct __sk_buff *skb)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
SEC("classifier/test")
|
SEC("tc")
|
||||||
int test_cls(struct __sk_buff *skb)
|
int test_cls(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
#ifndef NO_FN8
|
#ifndef NO_FN8
|
||||||
|
|
|
@ -24,7 +24,7 @@ int f3(int val, struct __sk_buff *skb)
|
||||||
return skb->ifindex * val;
|
return skb->ifindex * val;
|
||||||
}
|
}
|
||||||
|
|
||||||
SEC("classifier/test")
|
SEC("tc")
|
||||||
int test_cls(struct __sk_buff *skb)
|
int test_cls(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
return f1(skb) + f2(2, skb) + f3(3, skb);
|
return f1(skb) + f2(2, skb) + f3(3, skb);
|
||||||
|
|
|
@ -24,7 +24,7 @@ int f3(int val, struct __sk_buff *skb)
|
||||||
return skb->ifindex * val;
|
return skb->ifindex * val;
|
||||||
}
|
}
|
||||||
|
|
||||||
SEC("classifier/test")
|
SEC("tc")
|
||||||
int test_cls(struct __sk_buff *skb)
|
int test_cls(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
return f1(skb) + f2(2, skb) + f3(3, skb);
|
return f1(skb) + f2(2, skb) + f3(3, skb);
|
||||||
|
|
|
@ -10,7 +10,7 @@ void foo(struct __sk_buff *skb)
|
||||||
skb->tc_index = 0;
|
skb->tc_index = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SEC("classifier/test")
|
SEC("tc")
|
||||||
int test_cls(struct __sk_buff *skb)
|
int test_cls(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
foo(skb);
|
foo(skb);
|
||||||
|
|
|
@ -97,7 +97,7 @@ int test_pkt_write_access_subprog(struct __sk_buff *skb, __u32 off)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SEC("classifier/test_pkt_access")
|
SEC("tc")
|
||||||
int test_pkt_access(struct __sk_buff *skb)
|
int test_pkt_access(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
void *data_end = (void *)(long)skb->data_end;
|
void *data_end = (void *)(long)skb->data_end;
|
||||||
|
|
|
@ -7,8 +7,6 @@
|
||||||
#include <linux/pkt_cls.h>
|
#include <linux/pkt_cls.h>
|
||||||
#include <bpf/bpf_helpers.h>
|
#include <bpf/bpf_helpers.h>
|
||||||
|
|
||||||
int _version SEC("version") = 1;
|
|
||||||
|
|
||||||
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
||||||
#define TEST_FIELD(TYPE, FIELD, MASK) \
|
#define TEST_FIELD(TYPE, FIELD, MASK) \
|
||||||
{ \
|
{ \
|
||||||
|
@ -27,7 +25,7 @@ int _version SEC("version") = 1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
SEC("classifier/test_pkt_md_access")
|
SEC("tc")
|
||||||
int test_pkt_md_access(struct __sk_buff *skb)
|
int test_pkt_md_access(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
TEST_FIELD(__u8, len, 0xFF);
|
TEST_FIELD(__u8, len, 0xFF);
|
||||||
|
|
|
@ -36,7 +36,6 @@ struct {
|
||||||
.pinning = PIN_GLOBAL_NS,
|
.pinning = PIN_GLOBAL_NS,
|
||||||
};
|
};
|
||||||
|
|
||||||
int _version SEC("version") = 1;
|
|
||||||
char _license[] SEC("license") = "GPL";
|
char _license[] SEC("license") = "GPL";
|
||||||
|
|
||||||
/* Fill 'tuple' with L3 info, and attempt to find L4. On fail, return NULL. */
|
/* Fill 'tuple' with L3 info, and attempt to find L4. On fail, return NULL. */
|
||||||
|
@ -159,7 +158,7 @@ assign:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
SEC("classifier/sk_assign_test")
|
SEC("tc")
|
||||||
int bpf_sk_assign_test(struct __sk_buff *skb)
|
int bpf_sk_assign_test(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
struct bpf_sock_tuple *tuple, ln = {0};
|
struct bpf_sock_tuple *tuple, ln = {0};
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
#include <bpf/bpf_helpers.h>
|
#include <bpf/bpf_helpers.h>
|
||||||
#include <bpf/bpf_endian.h>
|
#include <bpf/bpf_endian.h>
|
||||||
|
|
||||||
int _version SEC("version") = 1;
|
|
||||||
char _license[] SEC("license") = "GPL";
|
char _license[] SEC("license") = "GPL";
|
||||||
|
|
||||||
/* Fill 'tuple' with L3 info, and attempt to find L4. On fail, return NULL. */
|
/* Fill 'tuple' with L3 info, and attempt to find L4. On fail, return NULL. */
|
||||||
|
@ -53,8 +52,8 @@ static struct bpf_sock_tuple *get_tuple(void *data, __u64 nh_off,
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
SEC("classifier/sk_lookup_success")
|
SEC("tc")
|
||||||
int bpf_sk_lookup_test0(struct __sk_buff *skb)
|
int sk_lookup_success(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
void *data_end = (void *)(long)skb->data_end;
|
void *data_end = (void *)(long)skb->data_end;
|
||||||
void *data = (void *)(long)skb->data;
|
void *data = (void *)(long)skb->data;
|
||||||
|
@ -79,8 +78,8 @@ int bpf_sk_lookup_test0(struct __sk_buff *skb)
|
||||||
return sk ? TC_ACT_OK : TC_ACT_UNSPEC;
|
return sk ? TC_ACT_OK : TC_ACT_UNSPEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
SEC("classifier/sk_lookup_success_simple")
|
SEC("tc")
|
||||||
int bpf_sk_lookup_test1(struct __sk_buff *skb)
|
int sk_lookup_success_simple(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
struct bpf_sock_tuple tuple = {};
|
struct bpf_sock_tuple tuple = {};
|
||||||
struct bpf_sock *sk;
|
struct bpf_sock *sk;
|
||||||
|
@ -91,8 +90,8 @@ int bpf_sk_lookup_test1(struct __sk_buff *skb)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SEC("classifier/err_use_after_free")
|
SEC("tc")
|
||||||
int bpf_sk_lookup_uaf(struct __sk_buff *skb)
|
int err_use_after_free(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
struct bpf_sock_tuple tuple = {};
|
struct bpf_sock_tuple tuple = {};
|
||||||
struct bpf_sock *sk;
|
struct bpf_sock *sk;
|
||||||
|
@ -106,8 +105,8 @@ int bpf_sk_lookup_uaf(struct __sk_buff *skb)
|
||||||
return family;
|
return family;
|
||||||
}
|
}
|
||||||
|
|
||||||
SEC("classifier/err_modify_sk_pointer")
|
SEC("tc")
|
||||||
int bpf_sk_lookup_modptr(struct __sk_buff *skb)
|
int err_modify_sk_pointer(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
struct bpf_sock_tuple tuple = {};
|
struct bpf_sock_tuple tuple = {};
|
||||||
struct bpf_sock *sk;
|
struct bpf_sock *sk;
|
||||||
|
@ -121,8 +120,8 @@ int bpf_sk_lookup_modptr(struct __sk_buff *skb)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SEC("classifier/err_modify_sk_or_null_pointer")
|
SEC("tc")
|
||||||
int bpf_sk_lookup_modptr_or_null(struct __sk_buff *skb)
|
int err_modify_sk_or_null_pointer(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
struct bpf_sock_tuple tuple = {};
|
struct bpf_sock_tuple tuple = {};
|
||||||
struct bpf_sock *sk;
|
struct bpf_sock *sk;
|
||||||
|
@ -135,8 +134,8 @@ int bpf_sk_lookup_modptr_or_null(struct __sk_buff *skb)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SEC("classifier/err_no_release")
|
SEC("tc")
|
||||||
int bpf_sk_lookup_test2(struct __sk_buff *skb)
|
int err_no_release(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
struct bpf_sock_tuple tuple = {};
|
struct bpf_sock_tuple tuple = {};
|
||||||
|
|
||||||
|
@ -144,8 +143,8 @@ int bpf_sk_lookup_test2(struct __sk_buff *skb)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SEC("classifier/err_release_twice")
|
SEC("tc")
|
||||||
int bpf_sk_lookup_test3(struct __sk_buff *skb)
|
int err_release_twice(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
struct bpf_sock_tuple tuple = {};
|
struct bpf_sock_tuple tuple = {};
|
||||||
struct bpf_sock *sk;
|
struct bpf_sock *sk;
|
||||||
|
@ -156,8 +155,8 @@ int bpf_sk_lookup_test3(struct __sk_buff *skb)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SEC("classifier/err_release_unchecked")
|
SEC("tc")
|
||||||
int bpf_sk_lookup_test4(struct __sk_buff *skb)
|
int err_release_unchecked(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
struct bpf_sock_tuple tuple = {};
|
struct bpf_sock_tuple tuple = {};
|
||||||
struct bpf_sock *sk;
|
struct bpf_sock *sk;
|
||||||
|
@ -173,8 +172,8 @@ void lookup_no_release(struct __sk_buff *skb)
|
||||||
bpf_sk_lookup_tcp(skb, &tuple, sizeof(tuple), BPF_F_CURRENT_NETNS, 0);
|
bpf_sk_lookup_tcp(skb, &tuple, sizeof(tuple), BPF_F_CURRENT_NETNS, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
SEC("classifier/err_no_release_subcall")
|
SEC("tc")
|
||||||
int bpf_sk_lookup_test5(struct __sk_buff *skb)
|
int err_no_release_subcall(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
lookup_no_release(skb);
|
lookup_no_release(skb);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -14,7 +14,7 @@ struct {
|
||||||
|
|
||||||
char _license[] SEC("license") = "GPL";
|
char _license[] SEC("license") = "GPL";
|
||||||
|
|
||||||
SEC("classifier/test_skb_helpers")
|
SEC("tc")
|
||||||
int test_skb_helpers(struct __sk_buff *skb)
|
int test_skb_helpers(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
struct task_struct *task;
|
struct task_struct *task;
|
||||||
|
|
|
@ -24,7 +24,7 @@ struct {
|
||||||
__type(value, __u64);
|
__type(value, __u64);
|
||||||
} dst_sock_hash SEC(".maps");
|
} dst_sock_hash SEC(".maps");
|
||||||
|
|
||||||
SEC("classifier/copy_sock_map")
|
SEC("tc")
|
||||||
int copy_sock_map(void *ctx)
|
int copy_sock_map(void *ctx)
|
||||||
{
|
{
|
||||||
struct bpf_sock *sk;
|
struct bpf_sock *sk;
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
/* Dummy prog to test TC-BPF API */
|
/* Dummy prog to test TC-BPF API */
|
||||||
|
|
||||||
SEC("classifier")
|
SEC("tc")
|
||||||
int cls(struct __sk_buff *skb)
|
int cls(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -70,7 +70,7 @@ static __always_inline bool is_remote_ep_v6(struct __sk_buff *skb,
|
||||||
return v6_equal(ip6h->daddr, addr);
|
return v6_equal(ip6h->daddr, addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
SEC("classifier/chk_egress")
|
SEC("tc")
|
||||||
int tc_chk(struct __sk_buff *skb)
|
int tc_chk(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
void *data_end = ctx_ptr(skb->data_end);
|
void *data_end = ctx_ptr(skb->data_end);
|
||||||
|
@ -83,7 +83,7 @@ int tc_chk(struct __sk_buff *skb)
|
||||||
return !raw[0] && !raw[1] && !raw[2] ? TC_ACT_SHOT : TC_ACT_OK;
|
return !raw[0] && !raw[1] && !raw[2] ? TC_ACT_SHOT : TC_ACT_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
SEC("classifier/dst_ingress")
|
SEC("tc")
|
||||||
int tc_dst(struct __sk_buff *skb)
|
int tc_dst(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
__u8 zero[ETH_ALEN * 2];
|
__u8 zero[ETH_ALEN * 2];
|
||||||
|
@ -108,7 +108,7 @@ int tc_dst(struct __sk_buff *skb)
|
||||||
return bpf_redirect_neigh(IFINDEX_SRC, NULL, 0, 0);
|
return bpf_redirect_neigh(IFINDEX_SRC, NULL, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
SEC("classifier/src_ingress")
|
SEC("tc")
|
||||||
int tc_src(struct __sk_buff *skb)
|
int tc_src(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
__u8 zero[ETH_ALEN * 2];
|
__u8 zero[ETH_ALEN * 2];
|
||||||
|
|
|
@ -75,7 +75,7 @@ static __always_inline int fill_fib_params_v6(struct __sk_buff *skb,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SEC("classifier/chk_egress")
|
SEC("tc")
|
||||||
int tc_chk(struct __sk_buff *skb)
|
int tc_chk(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
void *data_end = ctx_ptr(skb->data_end);
|
void *data_end = ctx_ptr(skb->data_end);
|
||||||
|
@ -143,13 +143,13 @@ static __always_inline int tc_redir(struct __sk_buff *skb)
|
||||||
/* these are identical, but keep them separate for compatibility with the
|
/* these are identical, but keep them separate for compatibility with the
|
||||||
* section names expected by test_tc_redirect.sh
|
* section names expected by test_tc_redirect.sh
|
||||||
*/
|
*/
|
||||||
SEC("classifier/dst_ingress")
|
SEC("tc")
|
||||||
int tc_dst(struct __sk_buff *skb)
|
int tc_dst(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
return tc_redir(skb);
|
return tc_redir(skb);
|
||||||
}
|
}
|
||||||
|
|
||||||
SEC("classifier/src_ingress")
|
SEC("tc")
|
||||||
int tc_src(struct __sk_buff *skb)
|
int tc_src(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
return tc_redir(skb);
|
return tc_redir(skb);
|
||||||
|
|
|
@ -16,31 +16,31 @@ volatile const __u32 IFINDEX_DST;
|
||||||
static const __u8 src_mac[] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55};
|
static const __u8 src_mac[] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55};
|
||||||
static const __u8 dst_mac[] = {0x00, 0x22, 0x33, 0x44, 0x55, 0x66};
|
static const __u8 dst_mac[] = {0x00, 0x22, 0x33, 0x44, 0x55, 0x66};
|
||||||
|
|
||||||
SEC("classifier/chk_egress")
|
SEC("tc")
|
||||||
int tc_chk(struct __sk_buff *skb)
|
int tc_chk(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
return TC_ACT_SHOT;
|
return TC_ACT_SHOT;
|
||||||
}
|
}
|
||||||
|
|
||||||
SEC("classifier/dst_ingress")
|
SEC("tc")
|
||||||
int tc_dst(struct __sk_buff *skb)
|
int tc_dst(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
return bpf_redirect_peer(IFINDEX_SRC, 0);
|
return bpf_redirect_peer(IFINDEX_SRC, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
SEC("classifier/src_ingress")
|
SEC("tc")
|
||||||
int tc_src(struct __sk_buff *skb)
|
int tc_src(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
return bpf_redirect_peer(IFINDEX_DST, 0);
|
return bpf_redirect_peer(IFINDEX_DST, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
SEC("classifier/dst_ingress_l3")
|
SEC("tc")
|
||||||
int tc_dst_l3(struct __sk_buff *skb)
|
int tc_dst_l3(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
return bpf_redirect(IFINDEX_SRC, 0);
|
return bpf_redirect(IFINDEX_SRC, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
SEC("classifier/src_ingress_l3")
|
SEC("tc")
|
||||||
int tc_src_l3(struct __sk_buff *skb)
|
int tc_src_l3(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
__u16 proto = skb->protocol;
|
__u16 proto = skb->protocol;
|
||||||
|
|
|
@ -148,7 +148,7 @@ release:
|
||||||
bpf_sk_release(sk);
|
bpf_sk_release(sk);
|
||||||
}
|
}
|
||||||
|
|
||||||
SEC("clsact/check_syncookie")
|
SEC("tc")
|
||||||
int check_syncookie_clsact(struct __sk_buff *skb)
|
int check_syncookie_clsact(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
check_syncookie(skb, (void *)(long)skb->data,
|
check_syncookie(skb, (void *)(long)skb->data,
|
||||||
|
|
|
@ -76,7 +76,7 @@ DIR=$(dirname $0)
|
||||||
TEST_IF=lo
|
TEST_IF=lo
|
||||||
MAX_PING_TRIES=5
|
MAX_PING_TRIES=5
|
||||||
BPF_PROG_OBJ="${DIR}/test_tcp_check_syncookie_kern.o"
|
BPF_PROG_OBJ="${DIR}/test_tcp_check_syncookie_kern.o"
|
||||||
CLSACT_SECTION="clsact/check_syncookie"
|
CLSACT_SECTION="tc"
|
||||||
XDP_SECTION="xdp"
|
XDP_SECTION="xdp"
|
||||||
BPF_PROG_ID=0
|
BPF_PROG_ID=0
|
||||||
PROG="${DIR}/test_tcp_check_syncookie_user"
|
PROG="${DIR}/test_tcp_check_syncookie_user"
|
||||||
|
|
Loading…
Reference in New Issue