File tree Expand file tree Collapse file tree 3 files changed +42
-0
lines changed
Expand file tree Collapse file tree 3 files changed +42
-0
lines changed Original file line number Diff line number Diff line change 1+ /* SPDX-License-Identifier: LGPL-2.1+ */
2+
3+ #include "bpf-link.h"
4+
5+ bool can_link_bpf_program (struct bpf_program * prog ) {
6+ _cleanup_ (bpf_link_freep ) struct bpf_link * link = NULL ;
7+
8+ assert (prog );
9+
10+ /* Pass invalid cgroup fd intentionally. */
11+ link = bpf_program__attach_cgroup (prog , /*cgroup_fd=*/ -1 );
12+
13+ /* EBADF indicates that bpf_link is supported by kernel. */
14+ return libbpf_get_error (link ) == - EBADF ;
15+ }
16+
17+ struct bpf_link * bpf_link_free (struct bpf_link * link ) {
18+ /* bpf_link__destroy handles link == NULL case */
19+ (void ) bpf_link__destroy (link );
20+
21+ return NULL ;
22+ }
Original file line number Diff line number Diff line change 1+ /* SPDX-License-Identifier: LGPL-2.1+ */
2+
3+ #pragma once
4+
5+ #include <bpf/libbpf.h>
6+
7+ #include "macro.h"
8+
9+ bool can_link_bpf_program (struct bpf_program * prog );
10+
11+ struct bpf_link * bpf_link_free (struct bpf_link * p );
12+ DEFINE_TRIVIAL_CLEANUP_FUNC (struct bpf_link * , bpf_link_free );
Original file line number Diff line number Diff line change @@ -319,6 +319,13 @@ if conf.get('HAVE_LIBIPTC') == 1
319319 shared_sources += files (' firewall-util-iptables.c' )
320320endif
321321
322+ if conf.get(' HAVE_LIBBPF' ) == 1
323+ shared_sources += files ('''
324+ bpf-link.c
325+ bpf-link.h
326+ ''' .split())
327+ endif
328+
322329if conf.get(' HAVE_KMOD' ) == 1
323330 shared_sources += files (' module-util.c' )
324331endif
@@ -378,6 +385,7 @@ libshared_name = 'systemd-shared-@0@'.format(meson.project_version())
378385libshared_deps = [threads,
379386 libacl,
380387 libblkid,
388+ libbpf,
381389 libcap,
382390 libcrypt,
383391 libgcrypt,
You can’t perform that action at this time.
0 commit comments