blob: f960b5fb3ed842e9adf4ddfd698fde9f9781d8ac [file] [log] [blame]
Alexei Starovoitov249b8122014-12-01 15:06:37 -08001#ifndef __BPF_HELPERS_H
2#define __BPF_HELPERS_H
3
4/* helper macro to place programs, maps, license in
5 * different sections in elf_bpf file. Section names
6 * are interpreted by elf_bpf loader
7 */
8#define SEC(NAME) __attribute__((section(NAME), used))
9
10/* helper functions called from eBPF programs written in C */
11static void *(*bpf_map_lookup_elem)(void *map, void *key) =
12 (void *) BPF_FUNC_map_lookup_elem;
13static int (*bpf_map_update_elem)(void *map, void *key, void *value,
14 unsigned long long flags) =
15 (void *) BPF_FUNC_map_update_elem;
16static int (*bpf_map_delete_elem)(void *map, void *key) =
17 (void *) BPF_FUNC_map_delete_elem;
Alexei Starovoitovb896c4f2015-03-25 12:49:23 -070018static int (*bpf_probe_read)(void *dst, int size, void *unsafe_ptr) =
19 (void *) BPF_FUNC_probe_read;
20static unsigned long long (*bpf_ktime_get_ns)(void) =
21 (void *) BPF_FUNC_ktime_get_ns;
22static int (*bpf_trace_printk)(const char *fmt, int fmt_size, ...) =
23 (void *) BPF_FUNC_trace_printk;
Alexei Starovoitov249b8122014-12-01 15:06:37 -080024
25/* llvm builtin functions that eBPF C program may use to
26 * emit BPF_LD_ABS and BPF_LD_IND instructions
27 */
28struct sk_buff;
29unsigned long long load_byte(void *skb,
30 unsigned long long off) asm("llvm.bpf.load.byte");
31unsigned long long load_half(void *skb,
32 unsigned long long off) asm("llvm.bpf.load.half");
33unsigned long long load_word(void *skb,
34 unsigned long long off) asm("llvm.bpf.load.word");
35
36/* a helper structure used by eBPF C program
37 * to describe map attributes to elf_bpf loader
38 */
39struct bpf_map_def {
40 unsigned int type;
41 unsigned int key_size;
42 unsigned int value_size;
43 unsigned int max_entries;
44};
45
Alexei Starovoitov91bc48222015-04-01 17:12:13 -070046static int (*bpf_skb_store_bytes)(void *ctx, int off, void *from, int len, int flags) =
47 (void *) BPF_FUNC_skb_store_bytes;
48static int (*bpf_l3_csum_replace)(void *ctx, int off, int from, int to, int flags) =
49 (void *) BPF_FUNC_l3_csum_replace;
50static int (*bpf_l4_csum_replace)(void *ctx, int off, int from, int to, int flags) =
51 (void *) BPF_FUNC_l4_csum_replace;
52
Alexei Starovoitov249b8122014-12-01 15:06:37 -080053#endif