Skip to content

Commit d9cefbc

Browse files
lschreckentohojo
authored andcommitted
xdpdump: Adapt the behavior of util.c find_bpf_file() to the libxdp.c variant
In contrast to the libxdp.c variant, the function find_bpf_file() in the util.c file does not use the environment variable LIBXDP_OBJECT_PATH to overwrite the default path, but always uses the default variable BPF_OBJECT_PATH, which is set at compile time. To unify the behavior, the behavior of the util.c variant is adapted to that of the libxdp.c variant. Signed-off-by: Lukas Schreckenberg <[email protected]>
1 parent 1d58978 commit d9cefbc

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

lib/util/util.c

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/* SPDX-License-Identifier: GPL-2.0 */
22

3+
#define _GNU_SOURCE
4+
35
#include <errno.h>
46
#include <unistd.h>
57
#include <stdlib.h>
@@ -148,6 +150,21 @@ const char *get_libbpf_version(void)
148150
return _libbpf_version;
149151
}
150152

153+
static bool try_bpf_file(char *buf, size_t buf_size, char *path,
154+
const char *progname)
155+
{
156+
struct stat sb = {};
157+
158+
if (try_snprintf(buf, buf_size, "%s/%s", path, progname))
159+
return false;
160+
161+
pr_debug("Looking for '%s'\n", buf);
162+
if (stat(buf, &sb))
163+
return false;
164+
165+
return true;
166+
}
167+
151168
int find_bpf_file(char *buf, size_t buf_size, const char *progname)
152169
{
153170
static char *bpf_obj_paths[] = {
@@ -157,21 +174,15 @@ int find_bpf_file(char *buf, size_t buf_size, const char *progname)
157174
BPF_OBJECT_PATH,
158175
NULL
159176
};
160-
struct stat sb = {};
161-
char **path;
162-
int err;
163-
164-
for (path = bpf_obj_paths; *path; path++) {
165-
err = try_snprintf(buf, buf_size, "%s/%s", *path, progname);
166-
if (err)
167-
return err;
168-
169-
pr_debug("Looking for '%s'\n", buf);
170-
err = stat(buf, &sb);
171-
if (err)
172-
continue;
177+
char *path, **p;
173178

179+
path = secure_getenv(XDP_OBJECT_ENVVAR);
180+
if (path && try_bpf_file(buf, buf_size, path, progname)) {
174181
return 0;
182+
} else if (!path) {
183+
for (p = bpf_obj_paths; *p; p++)
184+
if (try_bpf_file(buf, buf_size, *p, progname))
185+
return 0;
175186
}
176187

177188
pr_warn("Couldn't find a BPF file with name %s\n", progname);

0 commit comments

Comments
 (0)