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_arg
  • struct rte_bpf_xsym
  • struct rte_bpf_prm
  • struct 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 β€” undefined
  • RTE_BPF_ARG_RAW β€” scalar value
  • RTE_BPF_ARG_PTR β€” pointer to data buffer
  • RTE_BPF_ARG_PTR_MBUF β€” pointer to rte_mbuf
  • RTE_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 β€” function
  • RTE_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 function
  • ENOMEM - can't reserve enough memory
bestie if you get NULL please actually check rte_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 function
  • ENOMEM - 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 in ctx[] (and rc[]).

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 the rte_bpf_jit structure to be filled with related data.

Returns

  • -EINVAL if 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 output
  • buf β€” A pointer to BPF instructions
  • len β€” 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 from pcap_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 function
  • ENOMEM - can't reserve enough memory
  • ENOTSUP - 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