@@ -70,6 +70,7 @@ struct bpf_cfg_in {
const char *section;
const char *prog_name;
const char *uds;
+ const char *pin_path;
enum bpf_prog_type type;
enum bpf_mode mode;
__u32 ifindex;
@@ -827,7 +827,7 @@ static int bpf_obj_pinned(const char *pathname, enum bpf_prog_type type)
static int bpf_do_parse(struct bpf_cfg_in *cfg, const bool *opt_tbl)
{
- const char *file, *section, *uds_name, *prog_name;
+ const char *file, *section, *uds_name, *prog_name, *pin_path;
bool verbose = false;
int i, ret, argc;
char **argv;
@@ -858,7 +858,7 @@ static int bpf_do_parse(struct bpf_cfg_in *cfg, const bool *opt_tbl)
}
NEXT_ARG();
- file = section = uds_name = prog_name = NULL;
+ file = section = uds_name = prog_name = pin_path = NULL;
if (cfg->mode == EBPF_OBJECT || cfg->mode == EBPF_PINNED) {
file = *argv;
NEXT_ARG_FWD();
@@ -901,6 +901,12 @@ static int bpf_do_parse(struct bpf_cfg_in *cfg, const bool *opt_tbl)
NEXT_ARG_FWD();
}
+ if (argc > 0 && strcmp(*argv, "pin_path") == 0) {
+ NEXT_ARG();
+ pin_path = *argv;
+ NEXT_ARG_FWD();
+ }
+
if (__bpf_prog_meta[cfg->type].may_uds_export) {
uds_name = getenv(BPF_ENV_UDS);
if (argc > 0 && !uds_name &&
@@ -939,6 +945,7 @@ static int bpf_do_parse(struct bpf_cfg_in *cfg, const bool *opt_tbl)
cfg->argv = argv;
cfg->verbose = verbose;
cfg->prog_name = prog_name;
+ cfg->pin_path = pin_path;
return ret;
}
@@ -226,7 +226,7 @@ static int handle_legacy_maps(struct bpf_object *obj)
bpf_object__for_each_map(map, obj) {
map_name = bpf_map__name(map);
-
+ fprintf(stderr, "Processing map: %s\n", map_name);
ret = handle_legacy_map_in_map(obj, map, map_name);
if (ret)
return ret;
@@ -277,16 +277,18 @@ static int load_bpf_object(struct bpf_cfg_in *cfg)
char root_path[PATH_MAX];
struct bpf_map *map;
int prog_fd, ret = 0;
-
- ret = iproute2_get_root_path(root_path, PATH_MAX);
- if (ret)
- return ret;
-
+ if (cfg->pin_path) {
+ strncpy(root_path , cfg->pin_path, PATH_MAX);
+ } else {
+ ret = iproute2_get_root_path(root_path, PATH_MAX);
+ if (ret)
+ return ret;
+ }
DECLARE_LIBBPF_OPTS(bpf_object_open_opts, open_opts,
.relaxed_maps = true,
.pin_root_path = root_path,
);
-
+ fprintf(stderr, "About to bpf_object__open_file()\n");
obj = bpf_object__open_file(cfg->object, &open_opts);
if (libbpf_get_error(obj)) {
fprintf(stderr, "ERROR: opening BPF object file failed\n");
@@ -28,7 +28,7 @@ static void explain(void)
"\n"
"eBPF use case:\n"
" object-file FILE [ section CLS_NAME ] [ export UDS_FILE ]"
- " [ verbose ] [ direct-action ] [ skip_hw | skip_sw ]\n"
+ " [ verbose ] [ direct-action ] [ skip_hw | skip_sw ] [pin_path PATH]\n"
" object-pinned FILE [ direct-action ] [ skip_hw | skip_sw ]\n"
"\n"
"Common remaining options:\n"
@@ -48,6 +48,8 @@ static void explain(void)
"Where UDS_FILE points to a unix domain socket file in order\n"
"to hand off control of all created eBPF maps to an agent.\n"
"\n"
+ "Where PATH points to a path under bpffs where all eBPF maps will be pinned.\n"
+ "\n"
"ACTION_SPEC := ... look at individual actions\n"
"NOTE: CLASSID is parsed as hexadecimal input.\n",
bpf_prog_to_default_section(bpf_type));