Search code examples
dpdkebpfbpf

Using eBPF in dpdk


Sorry for some basic question. I understand eBPF in kernel context and use of bpf() system call or helper libraries. How are hooks created in dpdk ? How do we load eBPF code into an already running dpdk application ? I want to have dpdk process expose hooks at multiple places and want to load bpf to dump packets or print stats. I couldn't find all answers or examples of such real world scenarios.

I have gone through the dpdk examples and code implementation but couldn't get the details to actually write an app


Solution

  • The DPDK API for its eBPF module offers the following generic functions:

    struct rte_bpf *rte_bpf_load(const struct rte_bpf_prm *prm);
    struct rte_bpf *rte_bpf_elf_load(const struct rte_bpf_prm *prm, const char *fname, const char *sname);
    void            rte_bpf_destroy(struct rte_bpf *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);
    

    They allow you to load and execute BPF programs in your DPDK code.

    In addition to those, the DPDK library offers 4 functions to attach BPF programs to specific ports & queues. They will then execute when packets are received and sent on those queues.

    void rte_bpf_eth_rx_unload(uint16_t port, uint16_t queue);
    void rte_bpf_eth_tx_unload(uint16_t port, uint16_t queue);
    int  rte_bpf_eth_rx_elf_load(uint16_t port, uint16_t queue, const struct rte_bpf_prm *prm, const char *fname, const char *sname, uint32_t flags);
    int  rte_bpf_eth_tx_elf_load(uint16_t port, uint16_t queue, const struct rte_bpf_prm *prm, const char *fname, const char *sname, uint32_t flags);
    

    You can find more information in this presentation.