rte_bpf.h(3)
π rte_bpf.h β Library Functions Manual, section 3 π
okay bestie, gather round, because this is the DPDK BPF page and it's iconic. it's a Library Functions Manual entry, it lives in section 3, and it's here to explain how you load and run eBPF bytecode inside your user-space DPDK app. no cap. π¦
β¨ NAME β¨
rte_bpf.h β that's it, that's the name. the header itself. the moment. π
πΈ SYNOPSIS πΈ
#include <rte_common.h>
#include <rte_mbuf.h>
#include <rte_malloc.h>
#include <bpf_def.h>
π Data Structures π
struct rte_bpf_argstruct rte_bpf_xsymstruct rte_bpf_prmstruct rte_bpf_jit
π Macros π
#define RTE_BPF_ARG_PTR_TYPE(x)
π Enumerations π
enum rte_bpf_arg_type { RTE_BPF_ARG_UNDEF, RTE_BPF_ARG_RAW,
RTE_BPF_ARG_PTR = 0x10, RTE_BPF_ARG_PTR_MBUF, RTE_BPF_ARG_RESERVED }
enum rte_bpf_xtype { RTE_BPF_XTYPE_FUNC, RTE_BPF_XTYPE_VAR }
π Functions π
void rte_bpf_destroy (struct rte_bpf *bpf)
struct rte_bpf * rte_bpf_load (const struct rte_bpf_prm *prm)
__rte_malloc __rte_dealloc(rte_bpf_destroy
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
struct rte_bpf struct rte_bpf uint64_t rte_bpf_exec (const struct
rte_bpf *bpf, void *ctx)
uint32_t rte_bpf_exec_burst (const struct rte_bpf *bpf, void *ctx[],
uint64_t rc[], uint32_t num)
int rte_bpf_get_jit (const struct rte_bpf *bpf, struct rte_bpf_jit *jit)
void rte_bpf_dump (FILE *f, const struct ebpf_insn *buf, uint32_t len)
struct rte_bpf_prm * rte_bpf_convert (const struct bpf_program *prog)
__rte_malloc __rte_dealloc_free
(yes the whitespace in that block is Doing The Most, we don't question it, we just respect it π)
π Detailed Description π
RTE BPF support.
so like, librte_bpf hands you a whole framework to load and execute eBPF bytecode inside user-space applications built on dpdk. it supports a basic set of features from the eBPF spec β not everything, bestie, the basics β and here's where the spec lives:
https://www.kernel.org/doc/Documentation/networking/filter.txt
Definition in file rte_bpf.h.
π§ Macro Definition Documentation π§
#define RTE_BPF_ARG_PTR_TYPE( x)
Value:
((x) & RTE_BPF_ARG_PTR)
determine is argument a pointer π (yes, it just checks that bit for you. lowkey helpful.)
Definition at line 56 of file rte_bpf.h.
π₯ Enumeration Type Documentation π₯
enum rte_bpf_arg_type
Possible types for function/BPF program arguments. aka: what even is this thing you're passing in. π
Enumerator:
RTE_BPF_ARG_UNDEFβ undefinedRTE_BPF_ARG_RAWβ scalar valueRTE_BPF_ARG_PTRβ pointer to data bufferRTE_BPF_ARG_PTR_MBUFβ pointer torte_mbufRTE_BPF_ARG_RESERVEDβ reserved for internal use
Definition at line 31 of file rte_bpf.h.
enum rte_bpf_xtype
Possible types for external symbols. π
Enumerator:
RTE_BPF_XTYPE_FUNCβ functionRTE_BPF_XTYPE_VARβ variable
Definition at line 61 of file rte_bpf.h.
π Function Documentation π
void rte_bpf_destroy (struct rte_bpf * bpf)
De-allocate all the memory this eBPF execution context was hogging. it's giving cleanup era β¨
Parameters
bpfβ BPF handle to destroy.
struct rte_bpf * rte_bpf_load (const struct rte_bpf_prm * prm)
Create a brand new eBPF execution context and load the given BPF code into it. main character move fr fr.
Parameters
prmβ Parameters used to create and initialise the BPF execution context.
Returns
BPF handle that is used in future BPF operations, or NULL on error, with error code set in rte_errno. Possible rte_errno errors include:
EINVAL- invalid parameter passed to functionENOMEM- can't reserve enough memory
bestie if you getNULLplease actually checkrte_errno, don't just vibe and hope π«Ά
struct rte_bpf struct rte_bpf * rte_bpf_elf_load (const struct rte_bpf_prm * prm, const char * fname, const char * sname)
Create a new eBPF execution context and load BPF code from the given ELF file into it. Note that if the function will encounter EBPF_PSEUDO_CALL instruction that references external symbol, it will treat it as standard BPF_CALL to the external helper function. (that's the whole tea. remember it. π)
Parameters
prmβ Parameters used to create and initialise the BPF execution context.fnameβ Pathname for a ELF file.snameβ Name of the executable section within the file to load.
Returns
BPF handle that is used in future BPF operations, or NULL on error, with error code set in rte_errno. Possible rte_errno errors include:
EINVAL- invalid parameter passed to functionENOMEM- can't reserve enough memory
struct rte_bpf struct rte_bpf uint64_t rte_bpf_exec (const struct rte_bpf * bpf, void * ctx)
Execute given BPF bytecode. go go go πββοΈβ¨
Parameters
bpfβ handle for the BPF code to execute.ctxβ pointer to input context.
Returns
BPF execution return value.
uint32_t rte_bpf_exec_burst (const struct rte_bpf * bpf, void * ctx[], uint64_t rc[], uint32_t num)
Execute given BPF bytecode over a whole set of input contexts. it's giving batch processing and honestly? we love her for it. π
Parameters
bpfβ handle for the BPF code to execute.ctxβ array of pointers to the input contexts.rcβ array of return values (one per input).numβ number of elements inctx[](andrc[]).
Returns
number of successfully processed inputs.
int rte_bpf_get_jit (const struct rte_bpf * bpf, struct rte_bpf_jit * jit)
Provide information about natively compiled code for given BPF handle. πβ¨
Parameters
bpfβ handle for the BPF code.jitβ pointer to therte_bpf_jitstructure to be filled with related data.
Returns
-EINVALif the parameters are invalid.- Zero if operation completed successfully.
void rte_bpf_dump (FILE * f, const struct ebpf_insn * buf, uint32_t len)
Dump epf instructions to a file. (that's literally how it's spelled in the original, and I refuse to edit her π β it means eBPF instructions, bestie.)
Parameters
fβ A pointer to a file for outputbufβ A pointer to BPF instructionslenβ Number of BPF instructions to dump.
struct rte_bpf_prm * rte_bpf_convert (const struct bpf_program * prog)
Convert a Classic BPF program from libpcap into a DPDK BPF code. glow-up transformation arc π
Parameters
progβ Classic BPF program frompcap_compile().
Returns
Pointer to BPF program (allocated with rte_malloc) that is used in future BPF operations, or NULL on error, with error code set in rte_errno. Possible rte_errno errors include:
EINVAL- invalid parameter passed to functionENOMEM- can't reserve enough memoryENOTSUP- operation not supported
π Author π
Generated automatically by Doxygen for DPDK from the source code.
(not a human, not a bestie, just Doxygen doing its little thing π€β¨)
okay that's the whole page, and here's the cute sign-off: this was DPDK, Version 25.11.3 π handle your BPF contexts responsibly, destroy what you load, and check your rte_errno. mwah ππ¦πΈ
π¦ where this page comes from
- ubuntu resolute: dpdk-doc 25.11.3-0ubuntu0.26.04.1 Β· BSD-3-Clause
- ubuntu stonking: dpdk-doc 25.11.3-1 Β· BSD-3-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms