LCOV - code coverage report
Current view: top level - lib/bpf - bpf_impl.h (source / functions) Hit Total Coverage
Test: Code coverage Lines: 5 5 100.0 %
Date: 2026-07-01 18:02:41 Functions: 0 0 -
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 19 24 79.2 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2018 Intel Corporation
       3                 :            :  */
       4                 :            : 
       5                 :            : #ifndef BPF_IMPL_H
       6                 :            : #define BPF_IMPL_H
       7                 :            : 
       8                 :            : #include <rte_bpf.h>
       9                 :            : #include <sys/mman.h>
      10                 :            : 
      11                 :            : #define MAX_BPF_STACK_SIZE      0x200
      12                 :            : 
      13                 :            : struct rte_bpf {
      14                 :            :         struct rte_bpf_prm_ex prm;
      15                 :            :         struct rte_bpf_jit_ex jit;
      16                 :            :         size_t sz;
      17                 :            :         uint32_t stack_sz;
      18                 :            : };
      19                 :            : 
      20                 :            : /* Temporary copies etc. used by the load process. */
      21                 :            : struct __rte_bpf_load {
      22                 :            :         struct rte_bpf_prm_ex prm;
      23                 :            : 
      24                 :            :         /* Conversion from cBPF. */
      25                 :            :         struct ebpf_insn *ins;
      26                 :            : 
      27                 :            :         /* Loading ELF and applying relocations. */
      28                 :            :         int elf_fd;  /* ELF fd, must be negative (not zero) by default. */
      29                 :            :         void *elf;  /* Using void to avoid dependency on libelf. */
      30                 :            :         const char *elf_section;
      31                 :            : 
      32                 :            :         /* Value we are going to return, if any. */
      33                 :            :         struct rte_bpf *bpf;
      34                 :            : };
      35                 :            : 
      36                 :            : /*
      37                 :            :  * Use '__rte' prefix for non-static internal functions
      38                 :            :  * to avoid potential name conflict with other libraries.
      39                 :            :  */
      40                 :            : 
      41                 :            : /* Free temporary resources created by converting from cBPF to eBPF. */
      42                 :            : void
      43                 :            : __rte_bpf_convert_cleanup(struct __rte_bpf_load *load);
      44                 :            : 
      45                 :            : /* Convert program from cBPF to eBPF. */
      46                 :            : int
      47                 :            : __rte_bpf_convert(struct __rte_bpf_load *load);
      48                 :            : 
      49                 :            : /* Free temporary resources created by opening ELF. */
      50                 :            : void
      51                 :            : __rte_bpf_load_elf_cleanup(struct __rte_bpf_load *load);
      52                 :            : 
      53                 :            : /* Open the ELF file. */
      54                 :            : int
      55                 :            : __rte_bpf_load_elf_file(struct __rte_bpf_load *load);
      56                 :            : 
      57                 :            : /* Open the ELF memory image. */
      58                 :            : int
      59                 :            : __rte_bpf_load_elf_memory(struct __rte_bpf_load *load);
      60                 :            : 
      61                 :            : /* Get code from ELF and apply relocations to it. */
      62                 :            : int
      63                 :            : __rte_bpf_load_elf_code(struct __rte_bpf_load *load);
      64                 :            : 
      65                 :            : /* Validate final BPF code and calculate stack size. */
      66                 :            : int
      67                 :            : __rte_bpf_validate(const struct rte_bpf_prm_ex *prm, uint32_t *stack_sz);
      68                 :            : 
      69                 :            : int __rte_bpf_jit(struct rte_bpf *bpf);
      70                 :            : int __rte_bpf_jit_x86(struct rte_bpf *bpf);
      71                 :            : int __rte_bpf_jit_arm64(struct rte_bpf *bpf);
      72                 :            : 
      73                 :            : extern int rte_bpf_logtype;
      74                 :            : #define RTE_LOGTYPE_BPF rte_bpf_logtype
      75                 :            : 
      76                 :            : #define RTE_BPF_LOG_LINE(lvl, ...) \
      77                 :            :         RTE_LOG_LINE(lvl, BPF, __VA_ARGS__)
      78                 :            : 
      79                 :            : #define RTE_BPF_LOG_FUNC_LINE(lvl, fmt, ...) \
      80                 :            :         RTE_LOG_LINE(lvl, BPF, "%s(): " fmt, __func__, ##__VA_ARGS__)
      81                 :            : 
      82                 :            : static inline size_t
      83                 :            : bpf_size(uint32_t bpf_op_sz)
      84                 :            : {
      85   [ +  +  +  +  :       3281 :         if (bpf_op_sz == BPF_B)
                   +  + ]
      86                 :            :                 return sizeof(uint8_t);
      87   [ +  +  +  +  :       2750 :         else if (bpf_op_sz == BPF_H)
                   +  + ]
      88                 :            :                 return sizeof(uint16_t);
      89   [ +  +  +  +  :       2036 :         else if (bpf_op_sz == BPF_W)
                   -  + ]
      90                 :            :                 return sizeof(uint32_t);
      91   [ +  -  +  -  :        294 :         else if (bpf_op_sz == EBPF_DW)
                   -  - ]
      92                 :        294 :                 return sizeof(uint64_t);
      93                 :            :         return 0;
      94                 :            : }
      95                 :            : 
      96                 :            : #endif /* BPF_IMPL_H */

Generated by: LCOV version 1.14