]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/bpf-program.h
alloc-util: simplify GREEDY_REALLOC() logic by relying on malloc_usable_size()
[thirdparty/systemd.git] / src / shared / bpf-program.h
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 #include <linux/bpf.h>
5 #include <stdint.h>
6 #include <sys/syscall.h>
7
8 #include "list.h"
9 #include "macro.h"
10
11 typedef struct BPFProgram BPFProgram;
12
13 struct BPFProgram {
14 unsigned n_ref;
15
16 int kernel_fd;
17 uint32_t prog_type;
18
19 size_t n_instructions;
20 struct bpf_insn *instructions;
21
22 char *attached_path;
23 int attached_type;
24 uint32_t attached_flags;
25 };
26
27 int bpf_program_new(uint32_t prog_type, BPFProgram **ret);
28 int bpf_program_new_from_bpffs_path(const char *path, BPFProgram **ret);
29 BPFProgram *bpf_program_ref(BPFProgram *p);
30 BPFProgram *bpf_program_unref(BPFProgram *p);
31
32 int bpf_program_add_instructions(BPFProgram *p, const struct bpf_insn *insn, size_t count);
33 int bpf_program_load_kernel(BPFProgram *p, char *log_buf, size_t log_size);
34 int bpf_program_load_from_bpf_fs(BPFProgram *p, const char *path);
35
36 int bpf_program_cgroup_attach(BPFProgram *p, int type, const char *path, uint32_t flags);
37 int bpf_program_cgroup_detach(BPFProgram *p);
38 int bpf_program_pin(int prog_fd, const char *bpffs_path);
39 int bpf_program_get_id_by_fd(int prog_fd, uint32_t *ret_id);
40
41 int bpf_map_new(enum bpf_map_type type, size_t key_size, size_t value_size, size_t max_entries, uint32_t flags);
42 int bpf_map_update_element(int fd, const void *key, void *value);
43 int bpf_map_lookup_element(int fd, const void *key, void *value);
44
45 int bpf_cgroup_attach_type_from_string(const char *str) _pure_;
46 const char *bpf_cgroup_attach_type_to_string(int attach_type) _const_;
47
48 DEFINE_TRIVIAL_CLEANUP_FUNC(BPFProgram*, bpf_program_unref);