]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/bpf-link.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
6 bool can_link_bpf_program(struct bpf_program
*prog
) {
7 _cleanup_(bpf_link_freep
) struct bpf_link
*link
= NULL
;
11 /* Pass invalid cgroup fd intentionally. */
12 link
= bpf_program__attach_cgroup(prog
, /*cgroup_fd=*/-1);
14 /* EBADF indicates that bpf_link is supported by kernel. */
15 return libbpf_get_error(link
) == -EBADF
;
18 int serialize_bpf_link(FILE *f
, FDSet
*fds
, const char *key
, struct bpf_link
*link
) {
26 if (libbpf_get_error(link
) != 0)
29 fd
= bpf_link__fd(link
);
30 return serialize_fd(f
, fds
, key
, fd
);
33 struct bpf_link
*bpf_link_free(struct bpf_link
*link
) {
34 /* bpf_link__destroy handles link == NULL case */
35 (void) bpf_link__destroy(link
);