]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/bpf-link.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
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
) {
36 /* Avoid a useless dlopen() if link == NULL */
40 (void) sym_bpf_link__destroy(link
);