Commit 15669e1d authored by Andrii Nakryiko's avatar Andrii Nakryiko Committed by Alexei Starovoitov

selftests/bpf: Normalize all the rest SEC() uses

Normalize all the other non-conforming SEC() usages across all
selftests. This is in preparation for libbpf to start to enforce
stricter SEC() rules in libbpf 1.0 mode.
Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
Acked-by: default avatarDave Marchevsky <davemarchevsky@fb.com>
Link: https://lore.kernel.org/bpf/20210928161946.2512801-5-andrii@kernel.org
parent c22bdd28
...@@ -458,9 +458,9 @@ static int init_prog_array(struct bpf_object *obj, struct bpf_map *prog_array) ...@@ -458,9 +458,9 @@ static int init_prog_array(struct bpf_object *obj, struct bpf_map *prog_array)
return -1; return -1;
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), "flow_dissector/%i", i); snprintf(prog_name, sizeof(prog_name), "flow_dissector_%d", i);
prog = bpf_object__find_program_by_title(obj, prog_name); prog = bpf_object__find_program_by_name(obj, prog_name);
if (!prog) if (!prog)
return -1; return -1;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#include <test_progs.h> #include <test_progs.h>
#include "cgroup_helpers.h" #include "cgroup_helpers.h"
static int prog_attach(struct bpf_object *obj, int cgroup_fd, const char *title) static int prog_attach(struct bpf_object *obj, int cgroup_fd, const char *title, const char *name)
{ {
enum bpf_attach_type attach_type; enum bpf_attach_type attach_type;
enum bpf_prog_type prog_type; enum bpf_prog_type prog_type;
...@@ -15,23 +15,23 @@ static int prog_attach(struct bpf_object *obj, int cgroup_fd, const char *title) ...@@ -15,23 +15,23 @@ static int prog_attach(struct bpf_object *obj, int cgroup_fd, const char *title)
return -1; return -1;
} }
prog = bpf_object__find_program_by_title(obj, title); prog = bpf_object__find_program_by_name(obj, name);
if (!prog) { if (!prog) {
log_err("Failed to find %s BPF program", title); log_err("Failed to find %s BPF program", name);
return -1; return -1;
} }
err = bpf_prog_attach(bpf_program__fd(prog), cgroup_fd, err = bpf_prog_attach(bpf_program__fd(prog), cgroup_fd,
attach_type, BPF_F_ALLOW_MULTI); attach_type, BPF_F_ALLOW_MULTI);
if (err) { if (err) {
log_err("Failed to attach %s BPF program", title); log_err("Failed to attach %s BPF program", name);
return -1; return -1;
} }
return 0; return 0;
} }
static int prog_detach(struct bpf_object *obj, int cgroup_fd, const char *title) static int prog_detach(struct bpf_object *obj, int cgroup_fd, const char *title, const char *name)
{ {
enum bpf_attach_type attach_type; enum bpf_attach_type attach_type;
enum bpf_prog_type prog_type; enum bpf_prog_type prog_type;
...@@ -42,7 +42,7 @@ static int prog_detach(struct bpf_object *obj, int cgroup_fd, const char *title) ...@@ -42,7 +42,7 @@ static int prog_detach(struct bpf_object *obj, int cgroup_fd, const char *title)
if (err) if (err)
return -1; return -1;
prog = bpf_object__find_program_by_title(obj, title); prog = bpf_object__find_program_by_name(obj, name);
if (!prog) if (!prog)
return -1; return -1;
...@@ -89,7 +89,7 @@ static int run_getsockopt_test(struct bpf_object *obj, int cg_parent, ...@@ -89,7 +89,7 @@ static int run_getsockopt_test(struct bpf_object *obj, int cg_parent,
* - child: 0x80 -> 0x90 * - child: 0x80 -> 0x90
*/ */
err = prog_attach(obj, cg_child, "cgroup/getsockopt/child"); err = prog_attach(obj, cg_child, "cgroup/getsockopt", "_getsockopt_child");
if (err) if (err)
goto detach; goto detach;
...@@ -113,7 +113,7 @@ static int run_getsockopt_test(struct bpf_object *obj, int cg_parent, ...@@ -113,7 +113,7 @@ static int run_getsockopt_test(struct bpf_object *obj, int cg_parent,
* - parent: 0x90 -> 0xA0 * - parent: 0x90 -> 0xA0
*/ */
err = prog_attach(obj, cg_parent, "cgroup/getsockopt/parent"); err = prog_attach(obj, cg_parent, "cgroup/getsockopt", "_getsockopt_parent");
if (err) if (err)
goto detach; goto detach;
...@@ -157,7 +157,7 @@ static int run_getsockopt_test(struct bpf_object *obj, int cg_parent, ...@@ -157,7 +157,7 @@ static int run_getsockopt_test(struct bpf_object *obj, int cg_parent,
* - parent: unexpected 0x40, EPERM * - parent: unexpected 0x40, EPERM
*/ */
err = prog_detach(obj, cg_child, "cgroup/getsockopt/child"); err = prog_detach(obj, cg_child, "cgroup/getsockopt", "_getsockopt_child");
if (err) { if (err) {
log_err("Failed to detach child program"); log_err("Failed to detach child program");
goto detach; goto detach;
...@@ -198,8 +198,8 @@ static int run_getsockopt_test(struct bpf_object *obj, int cg_parent, ...@@ -198,8 +198,8 @@ static int run_getsockopt_test(struct bpf_object *obj, int cg_parent,
} }
detach: detach:
prog_detach(obj, cg_child, "cgroup/getsockopt/child"); prog_detach(obj, cg_child, "cgroup/getsockopt", "_getsockopt_child");
prog_detach(obj, cg_parent, "cgroup/getsockopt/parent"); prog_detach(obj, cg_parent, "cgroup/getsockopt", "_getsockopt_parent");
return err; return err;
} }
...@@ -236,7 +236,7 @@ static int run_setsockopt_test(struct bpf_object *obj, int cg_parent, ...@@ -236,7 +236,7 @@ static int run_setsockopt_test(struct bpf_object *obj, int cg_parent,
/* Attach child program and make sure it adds 0x10. */ /* Attach child program and make sure it adds 0x10. */
err = prog_attach(obj, cg_child, "cgroup/setsockopt"); err = prog_attach(obj, cg_child, "cgroup/setsockopt", "_setsockopt");
if (err) if (err)
goto detach; goto detach;
...@@ -263,7 +263,7 @@ static int run_setsockopt_test(struct bpf_object *obj, int cg_parent, ...@@ -263,7 +263,7 @@ static int run_setsockopt_test(struct bpf_object *obj, int cg_parent,
/* Attach parent program and make sure it adds another 0x10. */ /* Attach parent program and make sure it adds another 0x10. */
err = prog_attach(obj, cg_parent, "cgroup/setsockopt"); err = prog_attach(obj, cg_parent, "cgroup/setsockopt", "_setsockopt");
if (err) if (err)
goto detach; goto detach;
...@@ -289,8 +289,8 @@ static int run_setsockopt_test(struct bpf_object *obj, int cg_parent, ...@@ -289,8 +289,8 @@ static int run_setsockopt_test(struct bpf_object *obj, int cg_parent,
} }
detach: detach:
prog_detach(obj, cg_child, "cgroup/setsockopt"); prog_detach(obj, cg_child, "cgroup/setsockopt", "_setsockopt");
prog_detach(obj, cg_parent, "cgroup/setsockopt"); prog_detach(obj, cg_parent, "cgroup/setsockopt", "_setsockopt");
return err; return err;
} }
......
...@@ -19,9 +19,8 @@ ...@@ -19,9 +19,8 @@
#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;
#define PROG(F) PROG_(F, _##F) #define PROG(F) PROG_(F, _##F)
#define PROG_(NUM, NAME) SEC("flow_dissector/"#NUM) int bpf_func##NAME #define PROG_(NUM, NAME) SEC("flow_dissector") int flow_dissector_##NUM
/* These are the identifiers of the BPF programs that will be used in tail /* These are the identifiers of the BPF programs that will be used in tail
* calls. Name is limited to 16 characters, with the terminating character and * calls. Name is limited to 16 characters, with the terminating character and
......
...@@ -20,7 +20,7 @@ struct { ...@@ -20,7 +20,7 @@ struct {
__u32 invocations = 0; __u32 invocations = 0;
SEC("cgroup_skb/egress/1") SEC("cgroup_skb/egress")
int egress1(struct __sk_buff *skb) int egress1(struct __sk_buff *skb)
{ {
struct cgroup_value *ptr_cg_storage = struct cgroup_value *ptr_cg_storage =
...@@ -32,7 +32,7 @@ int egress1(struct __sk_buff *skb) ...@@ -32,7 +32,7 @@ int egress1(struct __sk_buff *skb)
return 1; return 1;
} }
SEC("cgroup_skb/egress/2") SEC("cgroup_skb/egress")
int egress2(struct __sk_buff *skb) int egress2(struct __sk_buff *skb)
{ {
struct cgroup_value *ptr_cg_storage = struct cgroup_value *ptr_cg_storage =
......
...@@ -20,7 +20,7 @@ struct { ...@@ -20,7 +20,7 @@ struct {
__u32 invocations = 0; __u32 invocations = 0;
SEC("cgroup_skb/egress/1") SEC("cgroup_skb/egress")
int egress1(struct __sk_buff *skb) int egress1(struct __sk_buff *skb)
{ {
struct cgroup_value *ptr_cg_storage = struct cgroup_value *ptr_cg_storage =
...@@ -32,7 +32,7 @@ int egress1(struct __sk_buff *skb) ...@@ -32,7 +32,7 @@ int egress1(struct __sk_buff *skb)
return 1; return 1;
} }
SEC("cgroup_skb/egress/2") SEC("cgroup_skb/egress")
int egress2(struct __sk_buff *skb) int egress2(struct __sk_buff *skb)
{ {
struct cgroup_value *ptr_cg_storage = struct cgroup_value *ptr_cg_storage =
......
...@@ -4,9 +4,8 @@ ...@@ -4,9 +4,8 @@
#include <bpf/bpf_helpers.h> #include <bpf/bpf_helpers.h>
char _license[] SEC("license") = "GPL"; char _license[] SEC("license") = "GPL";
__u32 _version SEC("version") = 1;
SEC("cgroup/getsockopt/child") SEC("cgroup/getsockopt")
int _getsockopt_child(struct bpf_sockopt *ctx) int _getsockopt_child(struct bpf_sockopt *ctx)
{ {
__u8 *optval_end = ctx->optval_end; __u8 *optval_end = ctx->optval_end;
...@@ -29,7 +28,7 @@ int _getsockopt_child(struct bpf_sockopt *ctx) ...@@ -29,7 +28,7 @@ int _getsockopt_child(struct bpf_sockopt *ctx)
return 1; return 1;
} }
SEC("cgroup/getsockopt/parent") SEC("cgroup/getsockopt")
int _getsockopt_parent(struct bpf_sockopt *ctx) int _getsockopt_parent(struct bpf_sockopt *ctx)
{ {
__u8 *optval_end = ctx->optval_end; __u8 *optval_end = ctx->optval_end;
......
...@@ -6,14 +6,14 @@ ...@@ -6,14 +6,14 @@
int calls = 0; int calls = 0;
int alt_calls = 0; int alt_calls = 0;
SEC("cgroup_skb/egress1") SEC("cgroup_skb/egress")
int egress(struct __sk_buff *skb) int egress(struct __sk_buff *skb)
{ {
__sync_fetch_and_add(&calls, 1); __sync_fetch_and_add(&calls, 1);
return 1; return 1;
} }
SEC("cgroup_skb/egress2") SEC("cgroup_skb/egress")
int egress_alt(struct __sk_buff *skb) int egress_alt(struct __sk_buff *skb)
{ {
__sync_fetch_and_add(&alt_calls, 1); __sync_fetch_and_add(&alt_calls, 1);
......
...@@ -293,7 +293,7 @@ static int handle_passive_estab(struct bpf_sock_ops *skops) ...@@ -293,7 +293,7 @@ static int handle_passive_estab(struct bpf_sock_ops *skops)
return check_active_hdr_in(skops); return check_active_hdr_in(skops);
} }
SEC("sockops/misc_estab") SEC("sockops")
int misc_estab(struct bpf_sock_ops *skops) int misc_estab(struct bpf_sock_ops *skops)
{ {
int true_val = 1; int true_val = 1;
......
...@@ -84,13 +84,13 @@ int lookup_drop(struct bpf_sk_lookup *ctx) ...@@ -84,13 +84,13 @@ int lookup_drop(struct bpf_sk_lookup *ctx)
return SK_DROP; return SK_DROP;
} }
SEC("sk_reuseport/reuse_pass") SEC("sk_reuseport")
int reuseport_pass(struct sk_reuseport_md *ctx) int reuseport_pass(struct sk_reuseport_md *ctx)
{ {
return SK_PASS; return SK_PASS;
} }
SEC("sk_reuseport/reuse_drop") SEC("sk_reuseport")
int reuseport_drop(struct sk_reuseport_md *ctx) int reuseport_drop(struct sk_reuseport_md *ctx)
{ {
return SK_DROP; return SK_DROP;
...@@ -194,7 +194,7 @@ int select_sock_a_no_reuseport(struct bpf_sk_lookup *ctx) ...@@ -194,7 +194,7 @@ int select_sock_a_no_reuseport(struct bpf_sk_lookup *ctx)
return err ? SK_DROP : SK_PASS; return err ? SK_DROP : SK_PASS;
} }
SEC("sk_reuseport/select_sock_b") SEC("sk_reuseport")
int select_sock_b(struct sk_reuseport_md *ctx) int select_sock_b(struct sk_reuseport_md *ctx)
{ {
__u32 key = KEY_SERVER_B; __u32 key = KEY_SERVER_B;
......
...@@ -56,7 +56,7 @@ int prog_stream_verdict(struct __sk_buff *skb) ...@@ -56,7 +56,7 @@ int prog_stream_verdict(struct __sk_buff *skb)
return verdict; return verdict;
} }
SEC("sk_skb/skb_verdict") SEC("sk_skb")
int prog_skb_verdict(struct __sk_buff *skb) int prog_skb_verdict(struct __sk_buff *skb)
{ {
unsigned int *count; unsigned int *count;
......
...@@ -9,7 +9,7 @@ struct { ...@@ -9,7 +9,7 @@ struct {
__type(value, __u64); __type(value, __u64);
} sock_map SEC(".maps"); } sock_map SEC(".maps");
SEC("sk_skb/skb_verdict") SEC("sk_skb")
int prog_skb_verdict(struct __sk_buff *skb) int prog_skb_verdict(struct __sk_buff *skb)
{ {
return SK_DROP; return SK_DROP;
......
...@@ -594,7 +594,7 @@ static int handle_parse_hdr(struct bpf_sock_ops *skops) ...@@ -594,7 +594,7 @@ static int handle_parse_hdr(struct bpf_sock_ops *skops)
return CG_OK; return CG_OK;
} }
SEC("sockops/estab") SEC("sockops")
int estab(struct bpf_sock_ops *skops) int estab(struct bpf_sock_ops *skops)
{ {
int true_val = 1; int true_val = 1;
......
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