]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/bpf-link.c
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
3 #include "bpf-dlopen.h"
7 bool bpf_can_link_program(struct bpf_program
*prog
) {
8 _cleanup_(bpf_link_freep
) struct bpf_link
*link
= NULL
;
15 /* Pass invalid cgroup fd intentionally. */
16 link
= sym_bpf_program__attach_cgroup(prog
, /*cgroup_fd=*/-1);
18 /* EBADF indicates that bpf_link is supported by kernel. */
19 return sym_libbpf_get_error(link
) == -EBADF
;
22 int bpf_serialize_link(FILE *f
, FDSet
*fds
, const char *key
, struct bpf_link
*link
) {
28 if (sym_libbpf_get_error(link
) != 0)
31 return serialize_fd(f
, fds
, key
, sym_bpf_link__fd(link
));
34 struct bpf_link
*bpf_link_free(struct bpf_link
*link
) {
35 /* If libbpf wasn't dlopen()ed, sym_bpf_link__destroy might be unresolved (NULL), so let's not try to
36 * call it if link is NULL. link might also be a non-null "error pointer", but such a value can only
37 * originate from a call to libbpf, but that means that libbpf is available, and we can let
38 * bpf_link__destroy() handle it. */
40 (void) sym_bpf_link__destroy(link
);