@@ -7545,6 +7545,16 @@ const char *bpf_object__name(const struct bpf_object *obj)
return obj ? obj->name : libbpf_err_ptr(-EINVAL);
}
+int bpf_object__set_name(struct bpf_object *obj, const char* name)
+{
+ if (!name)
+ return libbpf_err(-EINVAL);
+
+ strncpy(obj->name, name, sizeof(obj->name) - 1);
+
+ return 0;
+}
+
unsigned int bpf_object__kversion(const struct bpf_object *obj)
{
return obj ? obj->kern_version : 0;
@@ -161,6 +161,7 @@ LIBBPF_API int bpf_object__load_xattr(struct bpf_object_load_attr *attr);
LIBBPF_API int bpf_object__unload(struct bpf_object *obj);
LIBBPF_API const char *bpf_object__name(const struct bpf_object *obj);
+LIBBPF_API int bpf_object__set_name(struct bpf_object *obj, const char* name);
LIBBPF_API unsigned int bpf_object__kversion(const struct bpf_object *obj);
LIBBPF_API int bpf_object__set_kversion(struct bpf_object *obj, __u32 kern_version);
@@ -377,4 +377,5 @@ LIBBPF_0.5.0 {
bpf_object__gen_loader;
btf_dump__dump_type_data;
libbpf_set_strict_mode;
+ bpf_object__set_name;
} LIBBPF_0.4.0;
@@ -5,6 +5,7 @@ void test_reference_tracking(void)
{
const char *file = "test_sk_lookup_kern.o";
const char *obj_name = "ref_track";
+ const char *obj_name2 = "ref_track2";
DECLARE_LIBBPF_OPTS(bpf_object_open_opts, open_opts,
.object_name = obj_name,
.relaxed_maps = true,
@@ -23,6 +24,12 @@ void test_reference_tracking(void)
bpf_object__name(obj), obj_name))
goto cleanup;
+ bpf_object__set_name(obj, obj_name2);
+ if (CHECK(strcmp(bpf_object__name(obj), obj_name2), "obj_name",
+ "wrong obj name '%s', expected '%s'\n",
+ bpf_object__name(obj), obj_name2))
+ goto cleanup;
+
bpf_object__for_each_program(prog, obj) {
const char *title;