LCOV - code coverage report
Current view: top level - lib/bpf - bpf.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 18 28 64.3 %
Date: 2026-07-01 18:02:41 Functions: 4 5 80.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 8 16 50.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2018 Intel Corporation
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <stdio.h>
       6                 :            : #include <errno.h>
       7                 :            : #include <stdint.h>
       8                 :            : 
       9                 :            : #include <eal_export.h>
      10                 :            : #include <rte_common.h>
      11                 :            : 
      12                 :            : #include "bpf_impl.h"
      13                 :            : 
      14                 :            : RTE_EXPORT_SYMBOL(rte_bpf_destroy)
      15                 :            : void
      16                 :        659 : rte_bpf_destroy(struct rte_bpf *bpf)
      17                 :            : {
      18         [ +  + ]:        659 :         if (bpf != NULL) {
      19         [ +  + ]:        423 :                 if (bpf->jit.raw != NULL)
      20                 :        191 :                         munmap(bpf->jit.raw, bpf->jit.sz);
      21                 :        423 :                 munmap(bpf, bpf->sz);
      22                 :            :         }
      23                 :        659 : }
      24                 :            : 
      25                 :            : RTE_EXPORT_SYMBOL(rte_bpf_get_jit)
      26                 :            : int
      27                 :        124 : rte_bpf_get_jit(const struct rte_bpf *bpf, struct rte_bpf_jit *jit)
      28                 :            : {
      29         [ +  - ]:        124 :         if (bpf == NULL || jit == NULL)
      30                 :            :                 return -EINVAL;
      31                 :            : 
      32         [ -  + ]:        124 :         if (bpf->prm.nb_prog_arg != 1) {
      33                 :          0 :                 RTE_BPF_LOG_LINE(ERR,
      34                 :            :                         "this program takes %d arguments, use rte_bpf_get_jit_ex",
      35                 :            :                         bpf->prm.nb_prog_arg);
      36                 :          0 :                 return -EINVAL;
      37                 :            :         }
      38                 :            : 
      39                 :        124 :         *jit = (struct rte_bpf_jit) {
      40                 :        124 :                 .func = bpf->jit.raw,
      41                 :        124 :                 .sz = bpf->jit.sz,
      42                 :            :         };
      43                 :        124 :         return 0;
      44                 :            : }
      45                 :            : 
      46                 :            : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_bpf_get_jit_ex, 26.07)
      47                 :            : int
      48                 :          0 : rte_bpf_get_jit_ex(const struct rte_bpf *bpf, struct rte_bpf_jit_ex *jit)
      49                 :            : {
      50         [ #  # ]:          0 :         if (bpf == NULL || jit == NULL)
      51                 :            :                 return -EINVAL;
      52                 :            : 
      53         [ #  # ]:          0 :         if (bpf->jit.raw == NULL) {
      54                 :          0 :                 RTE_BPF_LOG_LINE(ERR, "no JIT-compiled version");
      55                 :          0 :                 return -ENOENT;
      56                 :            :         }
      57                 :            : 
      58                 :          0 :         *jit = bpf->jit;
      59                 :          0 :         return 0;
      60                 :            : }
      61                 :            : 
      62                 :            : int
      63                 :        191 : __rte_bpf_jit(struct rte_bpf *bpf)
      64                 :            : {
      65                 :            :         int32_t rc;
      66                 :            : 
      67                 :            : #if defined(RTE_ARCH_X86_64)
      68                 :        191 :         rc = __rte_bpf_jit_x86(bpf);
      69                 :            : #elif defined(RTE_ARCH_ARM64)
      70                 :            :         rc = __rte_bpf_jit_arm64(bpf);
      71                 :            : #else
      72                 :            :         rc = -ENOTSUP;
      73                 :            : #endif
      74                 :            : 
      75         [ -  + ]:        191 :         if (rc != 0)
      76                 :          0 :                 RTE_BPF_LOG_LINE(WARNING, "%s(%p) failed, error code: %d;",
      77                 :            :                         __func__, bpf, rc);
      78                 :        191 :         return rc;
      79                 :            : }
      80                 :            : 
      81         [ -  + ]:        301 : RTE_LOG_REGISTER_DEFAULT(rte_bpf_logtype, INFO);

Generated by: LCOV version 1.14