2021-09-09 16:33 (UTC-0700), Stephen Hemminger: [...] > + prm = rte_zmalloc("bpf_filter", > + sizeof(*prm) + ebpf_len * sizeof(*ebpf), 0); > + if (prm == NULL) { > + rte_errno = ENOMEM; > + return NULL; > + } > + > + /* The EPBF instructions in this case are right after the header */ > + ebpf = (void *)(prm + 1); > + > + /* 2nd pass: remap cBPF to eBPF instructions */ > + ret = bpf_convert_filter(prog->bf_insns, prog->bf_len, ebpf, &ebpf_len); > + if (ret < 0) { > + RTE_BPF_LOG(ERR, "%s: cannot convert cBPF to eBPF\n", __func__); > + free(prm);
free -> rte_free > + rte_errno = -ret; > + return NULL; > + } [...] > diff --git a/lib/bpf/rte_bpf.h b/lib/bpf/rte_bpf.h > index 69116f36ba8b..2f23e272a376 100644 > --- a/lib/bpf/rte_bpf.h > +++ b/lib/bpf/rte_bpf.h > @@ -198,6 +198,31 @@ rte_bpf_exec_burst(const struct rte_bpf *bpf, void > *ctx[], uint64_t rc[], > int > rte_bpf_get_jit(const struct rte_bpf *bpf, struct rte_bpf_jit *jit); > > +#ifdef RTE_PORT_PCAP In libre_bpf the function for ELF loading is always declared, and defined as a stub when libelf is unavailable. The app using it can link to DPDK with or without ELF support. No strong opinion here, but using different approaches is a bit messy. > + > +struct bpf_program; > + > +/** > + * Convert a Classic BPF program from libpcap into a DPDK BPF code. > + * > + * @param prog > + * Classic BPF program from pcap_compile(). > + * @param prm > + * Result Extended BPF program. > + * @return > + * 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 > + */ > +__rte_experimental > +struct rte_bpf_prm * > +rte_bpf_convert(const struct bpf_program *prog); > + > +#endif > + > #ifdef __cplusplus > } > #endif