Commit 46253c4a authored by Jakub Sitnicki's avatar Jakub Sitnicki Committed by Andrii Nakryiko

selftests/bpf: use section names understood by libbpf in test_sockmap

libbpf can deduce program type and attach type from the ELF section name.
We don't need to pass it out-of-band if we switch to libbpf convention [1].

[1] https://docs.kernel.org/bpf/libbpf/program_types.htmlSigned-off-by: default avatarJakub Sitnicki <jakub@cloudflare.com>
Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20240522080936.2475833-1-jakub@cloudflare.com
parent f088cabf
...@@ -92,7 +92,7 @@ struct { ...@@ -92,7 +92,7 @@ struct {
__uint(value_size, sizeof(int)); __uint(value_size, sizeof(int));
} tls_sock_map SEC(".maps"); } tls_sock_map SEC(".maps");
SEC("sk_skb1") SEC("sk_skb/stream_parser")
int bpf_prog1(struct __sk_buff *skb) int bpf_prog1(struct __sk_buff *skb)
{ {
int *f, two = 2; int *f, two = 2;
...@@ -104,7 +104,7 @@ int bpf_prog1(struct __sk_buff *skb) ...@@ -104,7 +104,7 @@ int bpf_prog1(struct __sk_buff *skb)
return skb->len; return skb->len;
} }
SEC("sk_skb2") SEC("sk_skb/stream_verdict")
int bpf_prog2(struct __sk_buff *skb) int bpf_prog2(struct __sk_buff *skb)
{ {
__u32 lport = skb->local_port; __u32 lport = skb->local_port;
...@@ -151,7 +151,7 @@ static inline void bpf_write_pass(struct __sk_buff *skb, int offset) ...@@ -151,7 +151,7 @@ static inline void bpf_write_pass(struct __sk_buff *skb, int offset)
memcpy(c + offset, "PASS", 4); memcpy(c + offset, "PASS", 4);
} }
SEC("sk_skb3") SEC("sk_skb/stream_verdict")
int bpf_prog3(struct __sk_buff *skb) int bpf_prog3(struct __sk_buff *skb)
{ {
int err, *f, ret = SK_PASS; int err, *f, ret = SK_PASS;
...@@ -233,7 +233,7 @@ int bpf_sockmap(struct bpf_sock_ops *skops) ...@@ -233,7 +233,7 @@ int bpf_sockmap(struct bpf_sock_ops *skops)
return 0; return 0;
} }
SEC("sk_msg1") SEC("sk_msg")
int bpf_prog4(struct sk_msg_md *msg) int bpf_prog4(struct sk_msg_md *msg)
{ {
int *bytes, zero = 0, one = 1, two = 2, three = 3, four = 4, five = 5; int *bytes, zero = 0, one = 1, two = 2, three = 3, four = 4, five = 5;
...@@ -263,7 +263,7 @@ int bpf_prog4(struct sk_msg_md *msg) ...@@ -263,7 +263,7 @@ int bpf_prog4(struct sk_msg_md *msg)
return SK_PASS; return SK_PASS;
} }
SEC("sk_msg2") SEC("sk_msg")
int bpf_prog6(struct sk_msg_md *msg) int bpf_prog6(struct sk_msg_md *msg)
{ {
int zero = 0, one = 1, two = 2, three = 3, four = 4, five = 5, key = 0; int zero = 0, one = 1, two = 2, three = 3, four = 4, five = 5, key = 0;
...@@ -308,7 +308,7 @@ int bpf_prog6(struct sk_msg_md *msg) ...@@ -308,7 +308,7 @@ int bpf_prog6(struct sk_msg_md *msg)
#endif #endif
} }
SEC("sk_msg3") SEC("sk_msg")
int bpf_prog8(struct sk_msg_md *msg) int bpf_prog8(struct sk_msg_md *msg)
{ {
void *data_end = (void *)(long) msg->data_end; void *data_end = (void *)(long) msg->data_end;
...@@ -329,7 +329,8 @@ int bpf_prog8(struct sk_msg_md *msg) ...@@ -329,7 +329,8 @@ int bpf_prog8(struct sk_msg_md *msg)
return SK_PASS; return SK_PASS;
} }
SEC("sk_msg4")
SEC("sk_msg")
int bpf_prog9(struct sk_msg_md *msg) int bpf_prog9(struct sk_msg_md *msg)
{ {
void *data_end = (void *)(long) msg->data_end; void *data_end = (void *)(long) msg->data_end;
...@@ -347,7 +348,7 @@ int bpf_prog9(struct sk_msg_md *msg) ...@@ -347,7 +348,7 @@ int bpf_prog9(struct sk_msg_md *msg)
return SK_PASS; return SK_PASS;
} }
SEC("sk_msg5") SEC("sk_msg")
int bpf_prog10(struct sk_msg_md *msg) int bpf_prog10(struct sk_msg_md *msg)
{ {
int *bytes, *start, *end, *start_push, *end_push, *start_pop, *pop; int *bytes, *start, *end, *start_push, *end_push, *start_pop, *pop;
......
...@@ -1783,30 +1783,6 @@ char *map_names[] = { ...@@ -1783,30 +1783,6 @@ char *map_names[] = {
"tls_sock_map", "tls_sock_map",
}; };
int prog_attach_type[] = {
BPF_SK_SKB_STREAM_PARSER,
BPF_SK_SKB_STREAM_VERDICT,
BPF_SK_SKB_STREAM_VERDICT,
BPF_CGROUP_SOCK_OPS,
BPF_SK_MSG_VERDICT,
BPF_SK_MSG_VERDICT,
BPF_SK_MSG_VERDICT,
BPF_SK_MSG_VERDICT,
BPF_SK_MSG_VERDICT,
};
int prog_type[] = {
BPF_PROG_TYPE_SK_SKB,
BPF_PROG_TYPE_SK_SKB,
BPF_PROG_TYPE_SK_SKB,
BPF_PROG_TYPE_SOCK_OPS,
BPF_PROG_TYPE_SK_MSG,
BPF_PROG_TYPE_SK_MSG,
BPF_PROG_TYPE_SK_MSG,
BPF_PROG_TYPE_SK_MSG,
BPF_PROG_TYPE_SK_MSG,
};
static int populate_progs(char *bpf_file) static int populate_progs(char *bpf_file)
{ {
struct bpf_program *prog; struct bpf_program *prog;
...@@ -1825,13 +1801,6 @@ static int populate_progs(char *bpf_file) ...@@ -1825,13 +1801,6 @@ static int populate_progs(char *bpf_file)
return -1; return -1;
} }
bpf_object__for_each_program(prog, obj) {
bpf_program__set_type(prog, prog_type[i]);
bpf_program__set_expected_attach_type(prog,
prog_attach_type[i]);
i++;
}
i = bpf_object__load(obj); i = bpf_object__load(obj);
i = 0; i = 0;
bpf_object__for_each_program(prog, obj) { bpf_object__for_each_program(prog, obj) {
......
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