diff options
author | Jakub Kicinski <jakub.kicinski@netronome.com> | 2018-07-10 17:43:02 -0400 |
---|---|---|
committer | Daniel Borkmann <daniel@iogearbox.net> | 2018-07-11 16:13:34 -0400 |
commit | 07f2d4eac2a850fc9649b27aa935cdcd263fb1ff (patch) | |
tree | bfc4c4d61592997b01393ccc8df1c6becb5c2c64 /tools/lib/bpf | |
parent | f83fb22c6c68fdbc98c76291c9e12a40d1eb7ca5 (diff) |
tools: libbpf: add extended attributes version of bpf_object__open()
Similarly to bpf_prog_load() users of bpf_object__open() may need
to specify the expected program type. Program type is needed at
open to avoid the kernel version check for program types which don't
require it.
Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: Quentin Monnet <quentin.monnet@netronome.com>
Acked-by: Andrey Ignatov <rdna@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Diffstat (limited to 'tools/lib/bpf')
-rw-r--r-- | tools/lib/bpf/libbpf.c | 26 | ||||
-rw-r--r-- | tools/lib/bpf/libbpf.h | 6 |
2 files changed, 26 insertions, 6 deletions
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 30992305f4c1..06cd534d2fba 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c | |||
@@ -1520,15 +1520,26 @@ out: | |||
1520 | return ERR_PTR(err); | 1520 | return ERR_PTR(err); |
1521 | } | 1521 | } |
1522 | 1522 | ||
1523 | struct bpf_object *bpf_object__open(const char *path) | 1523 | struct bpf_object *bpf_object__open_xattr(struct bpf_object_open_attr *attr) |
1524 | { | 1524 | { |
1525 | /* param validation */ | 1525 | /* param validation */ |
1526 | if (!path) | 1526 | if (!attr->file) |
1527 | return NULL; | 1527 | return NULL; |
1528 | 1528 | ||
1529 | pr_debug("loading %s\n", path); | 1529 | pr_debug("loading %s\n", attr->file); |
1530 | |||
1531 | return __bpf_object__open(attr->file, NULL, 0, | ||
1532 | bpf_prog_type__needs_kver(attr->prog_type)); | ||
1533 | } | ||
1534 | |||
1535 | struct bpf_object *bpf_object__open(const char *path) | ||
1536 | { | ||
1537 | struct bpf_object_open_attr attr = { | ||
1538 | .file = path, | ||
1539 | .prog_type = BPF_PROG_TYPE_UNSPEC, | ||
1540 | }; | ||
1530 | 1541 | ||
1531 | return __bpf_object__open(path, NULL, 0, true); | 1542 | return bpf_object__open_xattr(&attr); |
1532 | } | 1543 | } |
1533 | 1544 | ||
1534 | struct bpf_object *bpf_object__open_buffer(void *obj_buf, | 1545 | struct bpf_object *bpf_object__open_buffer(void *obj_buf, |
@@ -2238,6 +2249,10 @@ int bpf_prog_load(const char *file, enum bpf_prog_type type, | |||
2238 | int bpf_prog_load_xattr(const struct bpf_prog_load_attr *attr, | 2249 | int bpf_prog_load_xattr(const struct bpf_prog_load_attr *attr, |
2239 | struct bpf_object **pobj, int *prog_fd) | 2250 | struct bpf_object **pobj, int *prog_fd) |
2240 | { | 2251 | { |
2252 | struct bpf_object_open_attr open_attr = { | ||
2253 | .file = attr->file, | ||
2254 | .prog_type = attr->prog_type, | ||
2255 | }; | ||
2241 | struct bpf_program *prog, *first_prog = NULL; | 2256 | struct bpf_program *prog, *first_prog = NULL; |
2242 | enum bpf_attach_type expected_attach_type; | 2257 | enum bpf_attach_type expected_attach_type; |
2243 | enum bpf_prog_type prog_type; | 2258 | enum bpf_prog_type prog_type; |
@@ -2250,8 +2265,7 @@ int bpf_prog_load_xattr(const struct bpf_prog_load_attr *attr, | |||
2250 | if (!attr->file) | 2265 | if (!attr->file) |
2251 | return -EINVAL; | 2266 | return -EINVAL; |
2252 | 2267 | ||
2253 | obj = __bpf_object__open(attr->file, NULL, 0, | 2268 | obj = bpf_object__open_xattr(&open_attr); |
2254 | bpf_prog_type__needs_kver(attr->prog_type)); | ||
2255 | if (IS_ERR_OR_NULL(obj)) | 2269 | if (IS_ERR_OR_NULL(obj)) |
2256 | return -ENOENT; | 2270 | return -ENOENT; |
2257 | 2271 | ||
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h index 749acf58a5da..e911ad32d02e 100644 --- a/tools/lib/bpf/libbpf.h +++ b/tools/lib/bpf/libbpf.h | |||
@@ -66,7 +66,13 @@ void libbpf_set_print(libbpf_print_fn_t warn, | |||
66 | /* Hide internal to user */ | 66 | /* Hide internal to user */ |
67 | struct bpf_object; | 67 | struct bpf_object; |
68 | 68 | ||
69 | struct bpf_object_open_attr { | ||
70 | const char *file; | ||
71 | enum bpf_prog_type prog_type; | ||
72 | }; | ||
73 | |||
69 | struct bpf_object *bpf_object__open(const char *path); | 74 | struct bpf_object *bpf_object__open(const char *path); |
75 | struct bpf_object *bpf_object__open_xattr(struct bpf_object_open_attr *attr); | ||
70 | struct bpf_object *bpf_object__open_buffer(void *obj_buf, | 76 | struct bpf_object *bpf_object__open_buffer(void *obj_buf, |
71 | size_t obj_buf_sz, | 77 | size_t obj_buf_sz, |
72 | const char *name); | 78 | const char *name); |