]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/bpf-program.h
Merge pull request #7388 from keszybz/doc-tweak
[thirdparty/systemd.git] / src / basic / bpf-program.h
1 #pragma once
2
3 /***
4 This file is part of systemd.
5
6 Copyright 2016 Daniel Mack
7
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
12
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20
21 [Except for the stuff copy/pasted from the kernel sources, see below]
22 ***/
23
24 #include <linux/bpf.h>
25 #include <stdint.h>
26 #include <sys/syscall.h>
27
28 #include "list.h"
29 #include "macro.h"
30
31 typedef struct BPFProgram BPFProgram;
32
33 struct BPFProgram {
34 int kernel_fd;
35 uint32_t prog_type;
36
37 size_t n_instructions;
38 size_t allocated;
39 struct bpf_insn *instructions;
40 };
41
42 int bpf_program_new(uint32_t prog_type, BPFProgram **ret);
43 BPFProgram *bpf_program_unref(BPFProgram *p);
44
45 int bpf_program_add_instructions(BPFProgram *p, const struct bpf_insn *insn, size_t count);
46 int bpf_program_load_kernel(BPFProgram *p, char *log_buf, size_t log_size);
47
48 int bpf_program_cgroup_attach(BPFProgram *p, int type, const char *path, uint32_t flags);
49 int bpf_program_cgroup_detach(int type, const char *path);
50
51 int bpf_map_new(enum bpf_map_type type, size_t key_size, size_t value_size, size_t max_entries, uint32_t flags);
52 int bpf_map_update_element(int fd, const void *key, void *value);
53 int bpf_map_lookup_element(int fd, const void *key, void *value);
54
55 DEFINE_TRIVIAL_CLEANUP_FUNC(BPFProgram*, bpf_program_unref);