selftests/bpf: Let libbpf determine program type from section name
authorJakub Sitnicki <jakub@cloudflare.com>
Thu, 12 Dec 2019 10:22:51 +0000 (11:22 +0100)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 13 Dec 2019 20:38:00 +0000 (12:38 -0800)
Now that libbpf can recognize SK_REUSEPORT programs, we no longer have to
pass a prog_type hint before loading the object file.

Signed-off-by: Jakub Sitnicki <jakub@cloudflare.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20191212102259.418536-3-jakub@cloudflare.com
tools/testing/selftests/bpf/progs/test_select_reuseport_kern.c
tools/testing/selftests/bpf/test_select_reuseport.c

index ea7d84f01235283880d3e5246085499f1afd5b73..b1f09f5bb1cfbd123c508c02c29a4369beacd96f 100644 (file)
@@ -62,7 +62,7 @@ struct {
        goto done;                              \
 })
 
-SEC("select_by_skb_data")
+SEC("sk_reuseport")
 int _select_by_skb_data(struct sk_reuseport_md *reuse_md)
 {
        __u32 linum, index = 0, flags = 0, index_zero = 0;
index 7566c13eb51a7c10e7d84f6485ccb01a8bc139eb..1e3cfe1cb28a208e4dd1fa2ef041b14e612c233f 100644 (file)
@@ -87,19 +87,11 @@ static void prepare_bpf_obj(void)
        struct bpf_program *prog;
        struct bpf_map *map;
        int err;
-       struct bpf_object_open_attr attr = {
-               .file = "test_select_reuseport_kern.o",
-               .prog_type = BPF_PROG_TYPE_SK_REUSEPORT,
-       };
 
-       obj = bpf_object__open_xattr(&attr);
+       obj = bpf_object__open("test_select_reuseport_kern.o");
        CHECK(IS_ERR_OR_NULL(obj), "open test_select_reuseport_kern.o",
              "obj:%p PTR_ERR(obj):%ld\n", obj, PTR_ERR(obj));
 
-       prog = bpf_program__next(NULL, obj);
-       CHECK(!prog, "get first bpf_program", "!prog\n");
-       bpf_program__set_type(prog, attr.prog_type);
-
        map = bpf_object__find_map_by_name(obj, "outer_map");
        CHECK(!map, "find outer_map", "!map\n");
        err = bpf_map__reuse_fd(map, outer_map);
@@ -108,6 +100,8 @@ static void prepare_bpf_obj(void)
        err = bpf_object__load(obj);
        CHECK(err, "load bpf_object", "err:%d\n", err);
 
+       prog = bpf_program__next(NULL, obj);
+       CHECK(!prog, "get first bpf_program", "!prog\n");
        select_by_skb_data_prog = bpf_program__fd(prog);
        CHECK(select_by_skb_data_prog == -1, "get prog fd",
              "select_by_skb_data_prog:%d\n", select_by_skb_data_prog);