xref: /openbmc/linux/tools/lib/bpf/bpf_helpers.h (revision 068ac0db)
1 /* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */
2 #ifndef __BPF_HELPERS__
3 #define __BPF_HELPERS__
4 
5 #include "bpf_helper_defs.h"
6 
7 #define __uint(name, val) int (*name)[val]
8 #define __type(name, val) typeof(val) *name
9 
10 /* Helper macro to print out debug messages */
11 #define bpf_printk(fmt, ...)				\
12 ({							\
13 	char ____fmt[] = fmt;				\
14 	bpf_trace_printk(____fmt, sizeof(____fmt),	\
15 			 ##__VA_ARGS__);		\
16 })
17 
18 /*
19  * Helper macro to place programs, maps, license in
20  * different sections in elf_bpf file. Section names
21  * are interpreted by elf_bpf loader
22  */
23 #define SEC(NAME) __attribute__((section(NAME), used))
24 
25 #ifndef __always_inline
26 #define __always_inline __attribute__((always_inline))
27 #endif
28 
29 /*
30  * Helper structure used by eBPF C program
31  * to describe BPF map attributes to libbpf loader
32  */
33 struct bpf_map_def {
34 	unsigned int type;
35 	unsigned int key_size;
36 	unsigned int value_size;
37 	unsigned int max_entries;
38 	unsigned int map_flags;
39 };
40 
41 enum libbpf_pin_type {
42 	LIBBPF_PIN_NONE,
43 	/* PIN_BY_NAME: pin maps by name (in /sys/fs/bpf by default) */
44 	LIBBPF_PIN_BY_NAME,
45 };
46 
47 #endif
48