/* libbpf, clang and llc compile time dependencies are satisfied */
#include "bpf-dlopen.h"
#include "bpf-link.h"
-#include "bpf-util.h"
#include "bpf/restrict_fs/restrict-fs-skel.h"
#define CGROUP_HASH_SIZE_MAX 2048
if (!initialize)
return false;
- if (!cgroup_bpf_supported())
+ if (dlopen_bpf_full(LOG_WARNING) < 0)
return (supported = false);
r = lsm_supported("bpf");
#include "bpf-dlopen.h"
#include "bpf-link.h"
-#include "bpf-util.h"
#include "bpf/restrict_ifaces/restrict-ifaces-skel.h"
static struct restrict_ifaces_bpf *restrict_ifaces_bpf_free(struct restrict_ifaces_bpf *obj) {
if (supported >= 0)
return supported;
- if (!cgroup_bpf_supported())
+ if (dlopen_bpf_full(LOG_WARNING) < 0)
return (supported = false);
if (!compat_libbpf_probe_bpf_prog_type(BPF_PROG_TYPE_CGROUP_SKB, /*opts=*/NULL)) {
/* libbpf, clang, llvm and bpftool compile time dependencies are satisfied */
#include "bpf-dlopen.h"
#include "bpf-link.h"
-#include "bpf-util.h"
#include "bpf/socket_bind/socket-bind-api.bpf.h"
#include "bpf/socket_bind/socket-bind-skel.h"
_cleanup_(socket_bind_bpf_freep) struct socket_bind_bpf *obj = NULL;
int r;
- if (!cgroup_bpf_supported())
+ if (dlopen_bpf_full(LOG_WARNING) < 0)
return false;
if (!compat_libbpf_probe_bpf_prog_type(BPF_PROG_TYPE_CGROUP_SOCK_ADDR, /*opts=*/NULL)) {
+++ /dev/null
-/* SPDX-License-Identifier: LGPL-2.1-or-later */
-
-#include "bpf-dlopen.h"
-#include "bpf-util.h"
-#include "cgroup-util.h"
-#include "initrd-util.h"
-#include "log.h"
-
-bool cgroup_bpf_supported(void) {
- static int supported = -1;
- int r;
-
- if (supported >= 0)
- return supported;
-
- r = dlopen_bpf();
- if (r < 0) {
- log_full_errno(in_initrd() ? LOG_DEBUG : LOG_INFO,
- r, "Failed to open libbpf, cgroup BPF features disabled: %m");
- return (supported = false);
- }
-
- return (supported = true);
-}
+++ /dev/null
-/* SPDX-License-Identifier: LGPL-2.1-or-later */
-
-#include <stdbool.h>
-
-bool cgroup_bpf_supported(void);
'varlink.c',
)
-if conf.get('BPF_FRAMEWORK') == 1
- libcore_sources += files(
- 'bpf-util.c',
- )
-endif
-
subdir('bpf/socket_bind')
subdir('bpf/restrict_fs')
subdir('bpf/restrict_ifaces')
return log_internalv(LOG_DEBUG, errno, NULL, 0, NULL, fmt, ap);
}
-int dlopen_bpf(void) {
+int dlopen_bpf_full(int log_level) {
+ static int cached = 0;
void *dl;
int r;
+ if (cached != 0)
+ return cached;
+
ELF_NOTE_DLOPEN("bpf",
"Support firewalling and sandboxing with BPF",
ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
* list for both files, and when we assume 1.0+ is present we can remove this dlopen */
dl = dlopen("libbpf.so.0", RTLD_NOW|RTLD_NODELETE);
if (!dl)
- return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
- "neither libbpf.so.1 nor libbpf.so.0 are installed: %s", dlerror());
+ return cached = log_full_errno(log_level, SYNTHETIC_ERRNO(EOPNOTSUPP),
+ "Neither libbpf.so.1 nor libbpf.so.0 are installed, cgroup BPF features disabled: %s",
+ dlerror());
log_debug("Loaded 'libbpf.so.0' via dlopen()");
);
}
if (r < 0)
- return r;
+ return cached = log_full_errno(log_level, r, "Failed to load libbpf symbols, cgroup BPF features disabled: %m");
r = dlsym_many_or_warn(
dl, LOG_DEBUG,
DLSYM_ARG(ring_buffer__new),
DLSYM_ARG(ring_buffer__poll));
if (r < 0)
- return r;
+ return cached = log_full_errno(log_level, r, "Failed to load libbpf symbols, cgroup BPF features disabled: %m");
/* We set the print helper unconditionally. Otherwise libbpf will emit not useful log messages. */
(void) sym_libbpf_set_print(bpf_print_func);
REENABLE_WARNING;
- return r;
+ return cached = true;
}
int bpf_get_error_translated(const void *ptr) {
#else
-int dlopen_bpf(void) {
- return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
- "libbpf support is not compiled in.");
+int dlopen_bpf_full(int log_level) {
+ return log_once_errno(log_level, SYNTHETIC_ERRNO(EOPNOTSUPP),
+ "libbpf support is not compiled in, cgroup BPF features disabled.");
}
#endif
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
+#include <stdbool.h>
+#include <syslog.h>
+
#if HAVE_LIBBPF
#include <bpf/bpf.h>
#endif
-int dlopen_bpf(void);
+int dlopen_bpf_full(int log_level);
+static inline int dlopen_bpf(void) {
+ return dlopen_bpf_full(LOG_DEBUG);
+}