aboutsummaryrefslogtreecommitdiffstats
path: root/tools/lib/bpf/libbpf.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/lib/bpf/libbpf.c')
-rw-r--r--tools/lib/bpf/libbpf.c26
1 files changed, 20 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
1523struct bpf_object *bpf_object__open(const char *path) 1523struct 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
1535struct 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
1534struct bpf_object *bpf_object__open_buffer(void *obj_buf, 1545struct 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,
2238int bpf_prog_load_xattr(const struct bpf_prog_load_attr *attr, 2249int 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