> 
> The pcap library emits classic BPF (32 bit) and is useful for
> creating filter programs.  The DPDK BPF library only implements
> extended BPF (eBPF).  Add an function to convert from old to
> new.
> 
> The rte_bpf_convert function uses rte_malloc to put the resulting
> program in hugepage shared memory so it can be passed from a
> secondary process to a primary process.
> 
> The code to convert was originally done as part of the Linux
> kernel implementation then converted to a userspace program.
> Both authors have agreed that it is allowable to license this
> as BSD licensed in DPDK.
> 
> Signed-off-by: Stephen Hemminger <step...@networkplumber.org>
> ---
>  lib/bpf/bpf_convert.c | 570 ++++++++++++++++++++++++++++++++++++++++++
>  lib/bpf/meson.build   |   5 +
>  lib/bpf/rte_bpf.h     |  25 ++
>  lib/bpf/version.map   |   6 +
>  4 files changed, 606 insertions(+)
>  create mode 100644 lib/bpf/bpf_convert.c
> 
> diff --git a/lib/bpf/meson.build b/lib/bpf/meson.build
> index 63cbd60185e0..54f7610ae990 100644
> --- a/lib/bpf/meson.build
> +++ b/lib/bpf/meson.build
> @@ -25,3 +25,8 @@ if dep.found()
>      sources += files('bpf_load_elf.c')
>      ext_deps += dep
>  endif
> +
> +if dpdk_conf.has('RTE_PORT_PCAP')

Do we really need that 'if' above?
Why not to always have it enabled?

> +    sources += files('bpf_convert.c')
> +    ext_deps += pcap_dep
> +endif
> 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
> +
> +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
> diff --git a/lib/bpf/version.map b/lib/bpf/version.map
> index 0bf35f487666..47082d5003ef 100644
> --- a/lib/bpf/version.map
> +++ b/lib/bpf/version.map
> @@ -14,3 +14,9 @@ DPDK_22 {
> 
>       local: *;
>  };
> +
> +EXPERIMENTAL {
> +     global:
> +
> +     rte_bpf_convert;
> +};
> --

Cool feature, thanks for contributing.
Acked-by: Konstantin Ananyev <konstantin.anan...@intel.com>

> 2.30.2

Reply via email to