DPDK 26.07.0-rc2
rte_bpf.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Intel Corporation
3 */
4
5#ifndef _RTE_BPF_H_
6#define _RTE_BPF_H_
7
19#include <rte_common.h>
20#include <rte_mbuf.h>
21#include <rte_malloc.h>
22#include <bpf_def.h>
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28#define RTE_BPF_EXEC_FLAG_JIT RTE_BIT64(0)
31#define RTE_BPF_EXEC_FLAG_MASK RTE_BPF_EXEC_FLAG_JIT
32
33/* Format instructions as assembler. */
34#define RTE_BPF_FORMAT_FLAG_DISASSEMBLY 0
35/* Format instructions as hexadecimal. */
36#define RTE_BPF_FORMAT_FLAG_HEXADECIMAL RTE_BIT32(0)
37
38/* Only valid in disassembly mode. */
39/* Format jump offsets relative to the next instruction. */
40#define RTE_BPF_FORMAT_FLAG_RELATIVE_JUMPS 0
41/* Format jump targets relative to the start of the program. */
42#define RTE_BPF_FORMAT_FLAG_ABSOLUTE_JUMPS RTE_BIT32(1)
43
44/* Only valid in hexadecimal mode. */
45/* Format full hexadecimal representation of wide instructions. */
46#define RTE_BPF_FORMAT_FLAG_AUTO_WIDE 0
47/* Format as hexadecimal only first half of wide instructions. */
48#define RTE_BPF_FORMAT_FLAG_NEVER_WIDE RTE_BIT32(2)
49
59};
60
65 enum rte_bpf_arg_type type;
70 size_t size;
71 size_t buf_size;
73};
74
78#define RTE_BPF_ARG_PTR_TYPE(x) ((x) & RTE_BPF_ARG_PTR)
79
86};
87
92 const char *name;
94 union {
95 struct {
96 uint64_t (*val)(uint64_t, uint64_t, uint64_t,
97 uint64_t, uint64_t);
98 uint32_t nb_args;
99 struct rte_bpf_arg args[EBPF_FUNC_MAX_ARGS];
102 } func;
103 struct {
104 void *val;
106 } var;
107 };
108};
109
118};
119
120struct bpf_insn;
121struct rte_bpf_validate_debug;
122
129 size_t sz;
131 uint32_t flags;
136 union {
137 struct {
138 const struct ebpf_insn *ins;
139 uint32_t nb_ins;
140 } raw;
141 struct {
142 const struct bpf_insn *ins;
143 uint32_t nb_ins;
144 } cbpf;
145 struct {
146 const char *path;
147 const char *section;
148 } elf_file;
149 struct {
150 const void *data;
151 size_t size;
152 const char *section;
153 } elf_memory;
154 };
155
156 const struct rte_bpf_xsym *xsym;
158 uint32_t nb_xsym;
160 struct rte_bpf_arg prog_arg[EBPF_FUNC_MAX_ARGS];
161 uint32_t nb_prog_arg;
163 /* Validate debug instance. */
164 struct rte_bpf_validate_debug *debug;
165};
166
171 const struct ebpf_insn *ins;
172 uint32_t nb_ins;
173 const struct rte_bpf_xsym *xsym;
175 uint32_t nb_xsym;
177};
178
183 uint64_t (*func)(void *);
184 size_t sz;
185};
186
187union rte_bpf_func_arg {
188 uint64_t u64;
189 void *ptr;
190};
191
192typedef uint64_t (*rte_bpf_jit_func0_t)(void);
193typedef uint64_t (*rte_bpf_jit_func1_t)(union rte_bpf_func_arg);
194typedef uint64_t (*rte_bpf_jit_func2_t)(union rte_bpf_func_arg, union rte_bpf_func_arg);
195typedef uint64_t (*rte_bpf_jit_func3_t)(union rte_bpf_func_arg, union rte_bpf_func_arg,
196 union rte_bpf_func_arg);
197typedef uint64_t (*rte_bpf_jit_func4_t)(union rte_bpf_func_arg, union rte_bpf_func_arg,
198 union rte_bpf_func_arg, union rte_bpf_func_arg);
199typedef uint64_t (*rte_bpf_jit_func5_t)(union rte_bpf_func_arg, union rte_bpf_func_arg,
200 union rte_bpf_func_arg, union rte_bpf_func_arg, union rte_bpf_func_arg);
201
206 union {
207 void *raw;
208 rte_bpf_jit_func0_t func0; /* nullary function */
209 rte_bpf_jit_func1_t func1; /* unary function */
210 rte_bpf_jit_func2_t func2; /* binary function */
211 rte_bpf_jit_func3_t func3; /* ternary function */
212 rte_bpf_jit_func4_t func4; /* quaternary function */
213 rte_bpf_jit_func5_t func5; /* quinary function */
214 };
215 size_t sz;
216};
217
218/* Tuple of eBPF program arguments. */
219struct rte_bpf_prog_ctx {
220 union rte_bpf_func_arg arg[EBPF_FUNC_MAX_ARGS];
221};
222
223struct rte_bpf;
224
231void
232rte_bpf_destroy(struct rte_bpf *bpf);
233
255__rte_experimental
256struct rte_bpf *
259
272struct rte_bpf *
273rte_bpf_load(const struct rte_bpf_prm *prm)
275
296struct rte_bpf *
297rte_bpf_elf_load(const struct rte_bpf_prm *prm, const char *fname,
298 const char *sname)
300
311uint64_t
312rte_bpf_exec(const struct rte_bpf *bpf, void *ctx);
313
331__rte_experimental
332uint64_t
333rte_bpf_exec_ex(const struct rte_bpf *bpf, const struct rte_bpf_prog_ctx *ctx,
334 uint64_t flags);
335
350uint32_t
351rte_bpf_exec_burst(const struct rte_bpf *bpf, void *ctx[], uint64_t rc[],
352 uint32_t num);
353
376__rte_experimental
377uint32_t
378rte_bpf_exec_burst_ex(const struct rte_bpf *bpf, const struct rte_bpf_prog_ctx *ctx,
379 uint64_t rc[], uint32_t num, uint64_t flags);
380
393int
394rte_bpf_get_jit(const struct rte_bpf *bpf, struct rte_bpf_jit *jit);
395
411__rte_experimental
412int
413rte_bpf_get_jit_ex(const struct rte_bpf *bpf, struct rte_bpf_jit_ex *jit);
414
421__rte_experimental
422bool
423rte_bpf_insn_is_wide(const struct ebpf_insn *ins);
424
444__rte_experimental
445int
446rte_bpf_format(char *buffer, size_t bufsz, const struct ebpf_insn *ins,
447 uint32_t pc, uint32_t flags);
448
459void
460rte_bpf_dump(FILE *f, const struct ebpf_insn *buf, uint32_t len);
461
462struct bpf_program;
463
478struct rte_bpf_prm *
479rte_bpf_convert(const struct bpf_program *prog)
481
482#ifdef __cplusplus
483}
484#endif
485
486#endif /* _RTE_BPF_H_ */
rte_bpf_origin
Definition: rte_bpf.h:113
@ RTE_BPF_ORIGIN_RAW
Definition: rte_bpf.h:114
@ RTE_BPF_ORIGIN_CBPF
Definition: rte_bpf.h:115
@ RTE_BPF_ORIGIN_ELF_MEMORY
Definition: rte_bpf.h:117
@ RTE_BPF_ORIGIN_ELF_FILE
Definition: rte_bpf.h:116
__rte_experimental struct rte_bpf struct rte_bpf * rte_bpf_load(const struct rte_bpf_prm *prm) __rte_malloc __rte_dealloc(rte_bpf_destroy
__rte_experimental int rte_bpf_format(char *buffer, size_t bufsz, const struct ebpf_insn *ins, uint32_t pc, uint32_t flags)
int rte_bpf_get_jit(const struct rte_bpf *bpf, struct rte_bpf_jit *jit)
__rte_experimental bool rte_bpf_insn_is_wide(const struct ebpf_insn *ins)
struct rte_bpf_prm * rte_bpf_convert(const struct bpf_program *prog) __rte_malloc __rte_dealloc_free
__rte_experimental int rte_bpf_get_jit_ex(const struct rte_bpf *bpf, struct rte_bpf_jit_ex *jit)
rte_bpf_xtype
Definition: rte_bpf.h:83
@ RTE_BPF_XTYPE_VAR
Definition: rte_bpf.h:85
@ RTE_BPF_XTYPE_FUNC
Definition: rte_bpf.h:84
__rte_experimental struct rte_bpf struct rte_bpf struct rte_bpf * rte_bpf_elf_load(const struct rte_bpf_prm *prm, const char *fname, const char *sname) __rte_malloc __rte_dealloc(rte_bpf_destroy
__rte_experimental struct rte_bpf struct rte_bpf struct rte_bpf uint64_t rte_bpf_exec(const struct rte_bpf *bpf, void *ctx)
void rte_bpf_dump(FILE *f, const struct ebpf_insn *buf, uint32_t len)
__rte_experimental uint64_t rte_bpf_exec_ex(const struct rte_bpf *bpf, const struct rte_bpf_prog_ctx *ctx, uint64_t flags)
rte_bpf_arg_type
Definition: rte_bpf.h:53
@ RTE_BPF_ARG_UNDEF
Definition: rte_bpf.h:54
@ RTE_BPF_ARG_PTR_MBUF
Definition: rte_bpf.h:57
@ RTE_BPF_ARG_PTR
Definition: rte_bpf.h:56
@ RTE_BPF_ARG_RAW
Definition: rte_bpf.h:55
@ RTE_BPF_ARG_RESERVED
Definition: rte_bpf.h:58
__rte_experimental struct rte_bpf * rte_bpf_load_ex(const struct rte_bpf_prm_ex *prm) __rte_malloc __rte_dealloc(rte_bpf_destroy
uint32_t rte_bpf_exec_burst(const struct rte_bpf *bpf, void *ctx[], uint64_t rc[], uint32_t num)
__rte_experimental uint32_t rte_bpf_exec_burst_ex(const struct rte_bpf *bpf, const struct rte_bpf_prog_ctx *ctx, uint64_t rc[], uint32_t num, uint64_t flags)
void rte_bpf_destroy(struct rte_bpf *bpf)
#define __rte_dealloc(dealloc, argno)
Definition: rte_common.h:339
#define __rte_malloc
Definition: rte_common.h:328
#define __rte_dealloc_free
Definition: rte_malloc.h:37
size_t size
Definition: rte_bpf.h:70
size_t buf_size
Definition: rte_bpf.h:71
uint64_t(* func)(void *)
Definition: rte_bpf.h:183
size_t sz
Definition: rte_bpf.h:184
const struct bpf_insn * ins
Definition: rte_bpf.h:142
const void * data
Definition: rte_bpf.h:150
enum rte_bpf_origin origin
Definition: rte_bpf.h:133
const char * path
Definition: rte_bpf.h:146
struct rte_bpf_arg prog_arg[EBPF_FUNC_MAX_ARGS]
Definition: rte_bpf.h:160
const char * section
Definition: rte_bpf.h:147
uint32_t flags
Definition: rte_bpf.h:131
size_t size
Definition: rte_bpf.h:151
const struct rte_bpf_xsym * xsym
Definition: rte_bpf.h:156
uint32_t nb_prog_arg
Definition: rte_bpf.h:161
size_t sz
Definition: rte_bpf.h:129
uint32_t nb_ins
Definition: rte_bpf.h:139
const struct ebpf_insn * ins
Definition: rte_bpf.h:138
uint32_t nb_xsym
Definition: rte_bpf.h:158
struct rte_bpf_arg prog_arg
Definition: rte_bpf.h:176
const struct rte_bpf_xsym * xsym
Definition: rte_bpf.h:173
uint32_t nb_ins
Definition: rte_bpf.h:172
const struct ebpf_insn * ins
Definition: rte_bpf.h:171
uint32_t nb_xsym
Definition: rte_bpf.h:175
struct rte_bpf_arg ret
Definition: rte_bpf.h:101
const char * name
Definition: rte_bpf.h:92
enum rte_bpf_xtype type
Definition: rte_bpf.h:93
void * val
Definition: rte_bpf.h:104
struct rte_bpf_arg args[EBPF_FUNC_MAX_ARGS]
Definition: rte_bpf.h:99
struct rte_bpf_arg desc
Definition: rte_bpf.h:105
struct rte_bpf_xsym::@70::@73 var