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