]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
71e5200f DM |
2 | #pragma once |
3 | ||
4 | /*** | |
71e5200f DM |
5 | Copyright 2016 Daniel Mack |
6 | ||
71e5200f DM |
7 | [Except for the stuff copy/pasted from the kernel sources, see below] |
8 | ***/ | |
9 | ||
10 | #include <linux/bpf.h> | |
11 | #include <stdint.h> | |
12 | #include <sys/syscall.h> | |
13 | ||
14 | #include "list.h" | |
15 | #include "macro.h" | |
16 | ||
17 | typedef struct BPFProgram BPFProgram; | |
18 | ||
19 | struct BPFProgram { | |
aa2b6f1d LP |
20 | unsigned n_ref; |
21 | ||
71e5200f DM |
22 | int kernel_fd; |
23 | uint32_t prog_type; | |
24 | ||
25 | size_t n_instructions; | |
26 | size_t allocated; | |
27 | struct bpf_insn *instructions; | |
aa2b6f1d LP |
28 | |
29 | char *attached_path; | |
30 | int attached_type; | |
31 | uint32_t attached_flags; | |
71e5200f DM |
32 | }; |
33 | ||
34 | int bpf_program_new(uint32_t prog_type, BPFProgram **ret); | |
35 | BPFProgram *bpf_program_unref(BPFProgram *p); | |
aa2b6f1d | 36 | BPFProgram *bpf_program_ref(BPFProgram *p); |
71e5200f DM |
37 | |
38 | int bpf_program_add_instructions(BPFProgram *p, const struct bpf_insn *insn, size_t count); | |
39 | int bpf_program_load_kernel(BPFProgram *p, char *log_buf, size_t log_size); | |
40 | ||
9f2e6892 | 41 | int bpf_program_cgroup_attach(BPFProgram *p, int type, const char *path, uint32_t flags); |
aa2b6f1d | 42 | int bpf_program_cgroup_detach(BPFProgram *p); |
71e5200f DM |
43 | |
44 | int bpf_map_new(enum bpf_map_type type, size_t key_size, size_t value_size, size_t max_entries, uint32_t flags); | |
45 | int bpf_map_update_element(int fd, const void *key, void *value); | |
46 | int bpf_map_lookup_element(int fd, const void *key, void *value); | |
47 | ||
48 | DEFINE_TRIVIAL_CLEANUP_FUNC(BPFProgram*, bpf_program_unref); |