21#ifndef BACKENDS_EBPF_RUNTIME_EBPF_KERNEL_H_
22#define BACKENDS_EBPF_RUNTIME_EBPF_KERNEL_H_
24#include "ebpf_common.h"
26#include <bpf/bpf_endian.h>
30#define htons(d) bpf_htons(d)
31#define htonl(d) bpf_htonl(d)
32#define htonll(d) bpf_cpu_to_be64(d)
33#define ntohll(x) bpf_be64_to_cpu(x)
35#define bpf_htonll(x) htonll(x)
38#define load_byte(data, b) (*(((u8*)(data)) + (b)))
39#define load_half(data, b) bpf_ntohs(*(u16 *)((u8*)(data) + (b)))
40#define load_word(data, b) bpf_ntohl(*(u32 *)((u8*)(data) + (b)))
41#define load_dword(data, b) bpf_be64_to_cpu(*(u64 *)((u8*)(data) + (b)))
52#define BPF_USER_MAP_UPDATE_ELEM(index, key, value, flags)\
53 bpf_map_update_elem(index, key, value, flags)
54#define BPF_OBJ_PIN(table, name) bpf_obj_pin(table, name)
55#define BPF_OBJ_GET(name) bpf_obj_get(name)
59#include <linux/pkt_cls.h>
62#include <bpf/bpf_helpers.h>
80#define SK_BUFF struct __sk_buff
83#define BPF_ANNOTATE_KV_PAIR(name, type_key, type_val) \
84 struct ____btf_map_##name { \
88 struct ____btf_map_##name \
89 __attribute__ ((section(".maps." #name), used)) \
90 ____btf_map_##name = {};
92#define REGISTER_START()
95#define REGISTER_TABLE(NAME, TYPE, KEY_TYPE, VALUE_TYPE, MAX_ENTRIES) \
96struct bpf_elf_map SEC("maps") NAME = { \
98 .size_key = sizeof(KEY_TYPE), \
99 .size_value = sizeof(VALUE_TYPE), \
100 .max_elem = MAX_ENTRIES, \
104#define REGISTER_TABLE_INNER(NAME, TYPE, KEY_TYPE, VALUE_TYPE, MAX_ENTRIES, ID, INNER_IDX) \
105struct bpf_elf_map SEC("maps") NAME = { \
107 .size_key = sizeof(KEY_TYPE), \
108 .size_value = sizeof(VALUE_TYPE), \
109 .max_elem = MAX_ENTRIES, \
113 .inner_idx = INNER_IDX, \
115#define REGISTER_TABLE_OUTER(NAME, TYPE, KEY_TYPE, VALUE_TYPE, MAX_ENTRIES, INNER_ID, INNER_NAME) \
116struct bpf_elf_map SEC("maps") NAME = { \
118 .size_key = sizeof(KEY_TYPE), \
119 .size_value = sizeof(VALUE_TYPE), \
120 .max_elem = MAX_ENTRIES, \
123 .inner_id = INNER_ID, \
125#define REGISTER_TABLE_FLAGS(NAME, TYPE, KEY_TYPE, VALUE_TYPE, MAX_ENTRIES, FLAGS) \
126struct bpf_elf_map SEC("maps") NAME = { \
128 .size_key = sizeof(KEY_TYPE), \
129 .size_value = sizeof(VALUE_TYPE), \
130 .max_elem = MAX_ENTRIES, \
135#define REGISTER_TABLE(NAME, TYPE, KEY_TYPE, VALUE_TYPE, MAX_ENTRIES) \
137 __uint(type, TYPE); \
140 __uint(max_entries, MAX_ENTRIES); \
141 __uint(pinning, LIBBPF_PIN_BY_NAME); \
143#define REGISTER_TABLE_FLAGS(NAME, TYPE, KEY_TYPE, VALUE_TYPE, MAX_ENTRIES, FLAGS) \
145 __uint(type, TYPE); \
148 __uint(max_entries, MAX_ENTRIES); \
149 __uint(pinning, LIBBPF_PIN_BY_NAME); \
150 __uint(map_flags, FLAGS); \
152#define REGISTER_TABLE_INNER(NAME, TYPE, KEY_TYPE, VALUE_TYPE, MAX_ENTRIES, ID, INNER_IDX) \
154 __uint(type, TYPE); \
157 __uint(max_entries, MAX_ENTRIES); \
159#define REGISTER_TABLE_OUTER(NAME, TYPE, KEY_TYPE, VALUE_TYPE, MAX_ENTRIES, INNER_ID, INNER_NAME) \
161 __uint(type, TYPE); \
164 __uint(max_entries, MAX_ENTRIES); \
165 __uint(pinning, LIBBPF_PIN_BY_NAME); \
166 __array(values, struct INNER_NAME); \
168#define REGISTER_TABLE_NO_KEY_TYPE(NAME, TYPE, KEY_SIZE, VALUE_TYPE, MAX_ENTRIES) \
170 __uint(type, TYPE); \
171 __uint(key_size, KEY_SIZE); \
173 __uint(max_entries, MAX_ENTRIES); \
174 __uint(pinning, LIBBPF_PIN_BY_NAME); \
177#define REGISTER_END()
179#define BPF_MAP_LOOKUP_ELEM(table, key) \
180 bpf_map_lookup_elem(&table, key)
181#define BPF_MAP_UPDATE_ELEM(table, key, value, flags) \
182 bpf_map_update_elem(&table, key, value, flags)
183#define BPF_MAP_DELETE_ELEM(table, key) \
184 bpf_map_delete_elem(&table, key)
185#define BPF_USER_MAP_UPDATE_ELEM(index, key, value, flags)\
186 bpf_update_elem(index, key, value, flags)
187#define BPF_OBJ_PIN(table, name) bpf_obj_pin(table, name)
188#define BPF_OBJ_GET(name) bpf_obj_get(name)
Definition ebpf_kernel.h:67