shared, bpf: add bpf link helpers
add can_link_bpf_program and bpf_link_free helpers.
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
/* 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;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
/* 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);
|
||||
@@ -319,6 +319,13 @@ if conf.get('HAVE_LIBIPTC') == 1
|
||||
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
|
||||
@@ -378,6 +385,7 @@ libshared_name = 'systemd-shared-@0@'.format(meson.project_version())
|
||||
libshared_deps = [threads,
|
||||
libacl,
|
||||
libblkid,
|
||||
libbpf,
|
||||
libcap,
|
||||
libcrypt,
|
||||
libgcrypt,
|
||||
|
||||
Reference in New Issue
Block a user