--- /dev/null
+/* SPDX-License-Identifier: LGPL-2.1+ */
+
+#include "bpf-link.h"
+
+bool can_link_bpf_program(struct bpf_program *prog) {
+ _cleanup_(bpf_link_freep) struct bpf_link *link = NULL;
+
+ assert(prog);
+
+ /* Pass invalid cgroup fd intentionally. */
+ link = bpf_program__attach_cgroup(prog, /*cgroup_fd=*/-1);
+
+ /* EBADF indicates that bpf_link is supported by kernel. */
+ return libbpf_get_error(link) == -EBADF;
+}
+
+struct bpf_link *bpf_link_free(struct bpf_link *link) {
+ /* bpf_link__destroy handles link == NULL case */
+ (void) bpf_link__destroy(link);
+
+ return NULL;
+}
--- /dev/null
+/* SPDX-License-Identifier: LGPL-2.1+ */
+
+#pragma once
+
+#include <bpf/libbpf.h>
+
+#include "macro.h"
+
+bool can_link_bpf_program(struct bpf_program *prog);
+
+struct bpf_link *bpf_link_free(struct bpf_link *p);
+DEFINE_TRIVIAL_CLEANUP_FUNC(struct bpf_link *, bpf_link_free);
shared_sources += files('firewall-util-iptables.c')
endif
+if conf.get('HAVE_LIBBPF') == 1
+ shared_sources += files('''
+ bpf-link.c
+ bpf-link.h
+ '''.split())
+endif
+
if conf.get('HAVE_KMOD') == 1
shared_sources += files('module-util.c')
endif
libshared_deps = [threads,
libacl,
libblkid,
+ libbpf,
libcap,
libcrypt,
libgcrypt,