libbpf: make bpf_object__open default to UNSPEC
authorNikita V. Shirokov <tehnerd@tehnerd.com>
Fri, 23 Nov 2018 20:58:12 +0000 (12:58 -0800)
committerDaniel Borkmann <daniel@iogearbox.net>
Fri, 23 Nov 2018 21:27:05 +0000 (22:27 +0100)
currently by default libbpf's bpf_object__open requires
bpf's program to specify  version in a code because of two things:
1) default prog type is set to KPROBE
2) KPROBE requires (in kernel/bpf/syscall.c) version to be specified

in this patch i'm changing default prog type to UNSPEC and also changing
requirments for version's section to be present in object file.
now it would reflect what we have today in kernel
(only KPROBE prog type requires for version to be explicitly set).

v1 -> v2:
 - RFC tag has been dropped

Signed-off-by: Nikita V. Shirokov <tehnerd@tehnerd.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
tools/lib/bpf/libbpf.c

index 0f14f7c074c2997697a7c32f79b75b86006b6f7a..ed4212a4c5f9628e33e4939fc58f5e156b686c60 100644 (file)
@@ -333,7 +333,7 @@ bpf_program__init(void *data, size_t size, char *section_name, int idx,
        prog->idx = idx;
        prog->instances.fds = NULL;
        prog->instances.nr = -1;
-       prog->type = BPF_PROG_TYPE_KPROBE;
+       prog->type = BPF_PROG_TYPE_UNSPEC;
        prog->btf_fd = -1;
 
        return 0;
@@ -1649,12 +1649,12 @@ static bool bpf_prog_type__needs_kver(enum bpf_prog_type type)
        case BPF_PROG_TYPE_LIRC_MODE2:
        case BPF_PROG_TYPE_SK_REUSEPORT:
        case BPF_PROG_TYPE_FLOW_DISSECTOR:
-               return false;
        case BPF_PROG_TYPE_UNSPEC:
-       case BPF_PROG_TYPE_KPROBE:
        case BPF_PROG_TYPE_TRACEPOINT:
-       case BPF_PROG_TYPE_PERF_EVENT:
        case BPF_PROG_TYPE_RAW_TRACEPOINT:
+       case BPF_PROG_TYPE_PERF_EVENT:
+               return false;
+       case BPF_PROG_TYPE_KPROBE:
        default:
                return true;
        }