]> git.proxmox.com Git - mirror_iproute2.git/commitdiff
bpf: dump error to the user when retrieving pinned prog fails
authorDaniel Borkmann <daniel@iogearbox.net>
Sat, 13 May 2017 00:32:35 +0000 (02:32 +0200)
committerStephen Hemminger <stephen@networkplumber.org>
Wed, 31 May 2017 00:49:09 +0000 (17:49 -0700)
I noticed we currently don't dump an error message when a pinned
program couldn't be retrieved, thus add a hint to the user.

Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
lib/bpf.c

index 04ee1ab9b2bc3ab949636c790a12f1b573092422..ae4d97dc4eed3f8cc7d57951c7f360f5f1220eab 100644 (file)
--- a/lib/bpf.c
+++ b/lib/bpf.c
@@ -648,6 +648,16 @@ static int bpf_obj_get(const char *pathname, enum bpf_prog_type type)
        return bpf(BPF_OBJ_GET, &attr, sizeof(attr));
 }
 
+static int bpf_obj_pinned(const char *pathname, enum bpf_prog_type type)
+{
+       int prog_fd = bpf_obj_get(pathname, type);
+
+       if (prog_fd < 0)
+               fprintf(stderr, "Couldn\'t retrieve pinned program \'%s\': %s\n",
+                       pathname, strerror(errno));
+       return prog_fd;
+}
+
 enum bpf_mode {
        CBPF_BYTECODE,
        CBPF_FILE,
@@ -750,7 +760,7 @@ static int bpf_parse(enum bpf_prog_type *type, enum bpf_mode *mode,
        else if (*mode == EBPF_OBJECT)
                ret = bpf_obj_open(file, *type, section, verbose);
        else if (*mode == EBPF_PINNED)
-               ret = bpf_obj_get(file, *type);
+               ret = bpf_obj_pinned(file, *type);
        else
                return -1;