bpf: fix convert API can be undefined
PATCH 1/1 bpf: fix convert API can be undefined
rte_bpf_convert() implementation depends on libpcap. Right now it is defined only when this library is installed and RTE_PORT_PCAP is defined.
Fix that by providing for such case stub rte_bpf_convert() implementation that will always return an error.
Also move stub for another function (rte_bpf_elf_load) into the same place (bpf_stub.c).
--- lib/bpf/bpf_load.c | 18 ------------------ lib/bpf/bpf_stub.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ lib/bpf/meson.build | 1 + lib/bpf/rte_bpf.h | 4 ---- 4 files changed, 46 insertions(+), 22 deletions(-) create mode 100644 lib/bpf/bpf_stub.c
lib/bpf/bpf_load.c +0 -18
@@ -130,21 +130,3 @@ rte_bpf_load(const struct rte_bpf_prm *prm)return bpf; } - -#ifndef RTE_LIBRTE_BPF_ELF -struct rte_bpf * -rte_bpf_elf_load (const struct rte_bpf_prm *prm,const char *fname, -const char *sname) -{ -if (prm ==NULL || fname ==NULL || sname ==NULL ) { - rte_errno =EINVAL ; -return NULL ; - } - -RTE_BPF_LOG (ERR ,"%s() is not supported with current config\n" -"rebuild with libelf installed\n" , - __func__); - rte_errno =ENOTSUP ; -return NULL ; -} -#endif
lib/bpf/bpf_stub.c new file +45 -0
45 lines not on this page · raw message
lib/bpf/meson.build +1 -0
@@ -12,6 +12,7 @@ sources = files('bpf.c', 'bpf_exec.c', 'bpf_load.c', 'bpf_pkt.c', + 'bpf_stub.c', 'bpf_validate.c') if arch_subdir == 'x86' and dpdk_conf.get('RTE_ARCH_64')
lib/bpf/rte_bpf.h +0 -4
@@ -212,8 +212,6 @@ __rte_experimentalvoid rte_bpf_dump (FILE *f,const struct ebpf_insn *buf,uint32_t len); -#ifdef RTE_PORT_PCAP -struct bpf_program ;/**
@@ -235,8 +233,6 @@ __rte_experimentalstruct rte_bpf_prm *rte_bpf_convert (const struct bpf_program *prog); -#endif - #ifdef __cplusplus }#endif
Signature · 1 line
2.25.1
v2 cover few bpf library fixes
v2:
- add fix for doxygen comments
Konstantin Ananyev (2):
bpf: fix doxygen comments
bpf: fix convert API can be undefined
lib/bpf/bpf_load.c | 18 ------------------ lib/bpf/bpf_stub.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ lib/bpf/meson.build | 1 + lib/bpf/rte_bpf.h | 7 +------ 4 files changed, 47 insertions(+), 24 deletions(-) create mode 100644 lib/bpf/bpf_stub.c
Signature · 1 line
2.25.1
PATCH v2 1/2 bpf: fix doxygen comments
Fix typo in doxygen comments for rte_bpf_convert().
--- lib/bpf/rte_bpf.h | 2 -- 1 file changed, 2 deletions(-)
lib/bpf/rte_bpf.h +0 -2
@@ -221,8 +221,6 @@ struct bpf_program;* * @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,
Signature · 1 line
2.25.1
PATCH v2 2/2 bpf: fix convert API can be undefined
In reply to Konstantin Ananyevrte_bpf_convert() implementation depends on libpcap. Right now it is defined only when this library is installed and RTE_PORT_PCAP is defined.
Fix that by providing for such case stub rte_bpf_convert() implementation that will always return an error.
Also move stub for another function (rte_bpf_elf_load) into the same place (bpf_stub.c).
--- lib/bpf/bpf_load.c | 18 ------------------ lib/bpf/bpf_stub.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ lib/bpf/meson.build | 1 + lib/bpf/rte_bpf.h | 5 +---- 4 files changed, 47 insertions(+), 22 deletions(-) create mode 100644 lib/bpf/bpf_stub.c
lib/bpf/bpf_load.c +0 -18
@@ -130,21 +130,3 @@ rte_bpf_load(const struct rte_bpf_prm *prm)return bpf; } - -#ifndef RTE_LIBRTE_BPF_ELF -struct rte_bpf * -rte_bpf_elf_load (const struct rte_bpf_prm *prm,const char *fname, -const char *sname) -{ -if (prm ==NULL || fname ==NULL || sname ==NULL ) { - rte_errno =EINVAL ; -return NULL ; - } - -RTE_BPF_LOG (ERR ,"%s() is not supported with current config\n" -"rebuild with libelf installed\n" , - __func__); - rte_errno =ENOTSUP ; -return NULL ; -} -#endif
lib/bpf/bpf_stub.c new file +45 -0
45 lines not on this page · raw message
lib/bpf/meson.build +1 -0
@@ -12,6 +12,7 @@ sources = files('bpf.c', 'bpf_exec.c', 'bpf_load.c', 'bpf_pkt.c', + 'bpf_stub.c', 'bpf_validate.c') if arch_subdir == 'x86' and dpdk_conf.get('RTE_ARCH_64')
lib/bpf/rte_bpf.h +1 -4
@@ -212,8 +212,6 @@ __rte_experimentalvoid rte_bpf_dump (FILE *f,const struct ebpf_insn *buf,uint32_t len); -#ifdef RTE_PORT_PCAP -struct bpf_program ;/**
@@ -228,13 +226,12 @@ struct bpf_program;* Possible rte_errno errors include: * - EINVAL - invalid parameter passed to function * - ENOMEM - can't reserve enough memory +* - ENOTSUP - operation not supported */ __rte_experimental struct rte_bpf_prm *rte_bpf_convert (const struct bpf_program *prog); -#endif - #ifdef __cplusplus }#endif
Signature · 1 line
2.25.1
Quoted 11 lines · On Mon, 1 Nov 2021 16:10:13 +0000 Konstantin Ananyev…
rte_bpf_convert()implementation depends on libpcap. Right now it is defined only when this library is installed andRTE_PORT_PCAPis defined.
Fix that by providing for such case stubrte_bpf_convert()implementation that will always return an error.
Also move stub for another function (rte_bpf_elf_load) into the same place (bpf_stub.c).Fixes 2eccf6afbea9 ("bpf: add function to convert classic BPF to DPDK BPF")Signed-off-by Konstantin Ananyev <[email protected]>
Wouldn't it be better to fail compiling a program using unimplemented calls rather than forcing the user to see a failure later?
Quoted 10 lines
Quoted 10 lines
rte_bpf_convert()implementation depends on libpcap. Right now it is defined only when this library is installed andRTE_PORT_PCAPis defined.
Fix that by providing for such case stubrte_bpf_convert()implementation that will always return an error.
Also move stub for another function (rte_bpf_elf_load) into the same place (bpf_stub.c).
Quoted 6 lines
Quoted 3 lines
Fixes 2eccf6afbea9 ("bpf: add function to convert classic BPF to DPDK BPF")Signed-off-by Konstantin Ananyev <[email protected]>Wouldn't it be better to fail compiling a program using unimplemented calls rather than forcing the user to see a failure later?
You mean to keep things as they are right now?
That way we'll have to put #ifdef RTE_PORT_PCAP around every call to bpf_convert(). Doesn't look like a good thing to me.
Also in other places we use similar approach: if HW/SW is not available provide a dummy implementation that will report an error.
Quoted 12 lines · Konstantin
Quoted 12 lines
Quoted 11 lines
rte_bpf_convert()implementation depends on libpcap. Right now it is defined only when this library is installed andRTE_PORT_PCAPis defined.
Fix that by providing for such case stubrte_bpf_convert()implementation that will always return an error.
Also move stub for another function (rte_bpf_elf_load) into the same place (bpf_stub.c).Fixes 2eccf6afbea9 ("bpf: add function to convert classic BPF to DPDK BPF")Signed-off-by Konstantin Ananyev <[email protected]>
Quoted 8 lines
Quoted 2 lines
Wouldn't it be better to fail compiling a program using unimplemented calls rather than forcing the user to see a failure later?
You mean to keep things as they are right now?
That way we'll have to put #ifdefRTE_PORT_PCAParound every call tobpf_convert(). Doesn't look like a good thing to me.
Also in other places we use similar approach: if HW/SW is not available provide a dummy implementation that will report an error.
Is there a way to do both, return an error and report a warning in the build?
Quoted 20 lines
Quoted 15 lines · Konstantin
Quoted 14 lines
Quoted 11 lines
rte_bpf_convert()implementation depends on libpcap. Right now it is defined only when this library is installed andRTE_PORT_PCAPis defined.
Fix that by providing for such case stubrte_bpf_convert()implementation that will always return an error.
Also move stub for another function (rte_bpf_elf_load) into the same place (bpf_stub.c).Fixes 2eccf6afbea9 ("bpf: add function to convert classic BPF to DPDK BPF")Signed-off-by Konstantin Ananyev <[email protected]>Wouldn't it be better to fail compiling a program using unimplemented calls rather than forcing the user to see a failure later?
Quoted 7 lines
Quoted 5 lines
You mean to keep things as they are right now?
That way we'll have to put #ifdefRTE_PORT_PCAParound every call tobpf_convert(). Doesn't look like a good thing to me.
Also in other places we use similar approach: if HW/SW is not available provide a dummy implementation that will report an error.Is there a way to do both, return an error and report a warning in the build?
Sounds like a good idea, will add a warning to meson.build.
Quoted 11 lines · On Mon, 1 Nov 2021 16:10:13 +0000 Konstantin Ananyev…
rte_bpf_convert()implementation depends on libpcap. Right now it is defined only when this library is installed andRTE_PORT_PCAPis defined.
Fix that by providing for such case stubrte_bpf_convert()implementation that will always return an error.
Also move stub for another function (rte_bpf_elf_load) into the same place (bpf_stub.c).Fixes 2eccf6afbea9 ("bpf: add function to convert classic BPF to DPDK BPF")Signed-off-by Konstantin Ananyev <[email protected]>
Should also change dumpcap to print more complete error?
app/dumpcap/main.c +1 -1
@@ -285,7 +285,7 @@ static void compile_filter(void) bpf_prm =rte_bpf_convert (&bf);if (bpf_prm ==NULL )rte_exit (EXIT_FAILURE , -"bpf convert failed\n" ); +"bpf convert failed: %s\n" ,rte_strerror (rte_errno));if (dump_bpf) {printf ("cBPF program (%u insns)\n" , bf.bf_len);
v3 cover few bpf library fixes
In reply to Konstantin Ananyevv3:
- add meson warnings if dependencies are missing (Stephen)
- more descriptive error message (Stephen)
v2:
- add fix for doxygen comments
Konstantin Ananyev (2):
bpf: fix doxygen comments
bpf: fix convert API can be undefined
app/dumpcap/main.c | 3 ++- lib/bpf/bpf_load.c | 18 ------------------ lib/bpf/bpf_stub.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ lib/bpf/meson.build | 5 +++++ lib/bpf/rte_bpf.h | 7 +------ 5 files changed, 53 insertions(+), 25 deletions(-) create mode 100644 lib/bpf/bpf_stub.c
Signature · 1 line
2.25.1
PATCH v3 1/2 bpf: fix doxygen comments
Fix typo in doxygen comments for rte_bpf_convert().
--- lib/bpf/rte_bpf.h | 2 -- 1 file changed, 2 deletions(-)
lib/bpf/rte_bpf.h +0 -2
@@ -221,8 +221,6 @@ struct bpf_program;* * @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,
Signature · 1 line
2.25.1
PATCH v3 2/2 bpf: fix convert API can be undefined
In reply to Konstantin Ananyevrte_bpf_convert() implementation depends on libpcap. Right now it is defined only when this library is installed and RTE_PORT_PCAP is defined.
Fix that by providing for such case stub rte_bpf_convert() implementation that will always return an error.
To draw user attention, if proper implementation is disabled, warning will be thrown at meson configure stage.
Also move stub for another function (rte_bpf_elf_load) into the same place (bpf_stub.c).
--- app/dumpcap/main.c | 3 ++- lib/bpf/bpf_load.c | 18 ------------------ lib/bpf/bpf_stub.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ lib/bpf/meson.build | 5 +++++ lib/bpf/rte_bpf.h | 5 +---- 5 files changed, 53 insertions(+), 23 deletions(-) create mode 100644 lib/bpf/bpf_stub.c
app/dumpcap/main.c +2 -1
@@ -285,7 +285,8 @@ static void compile_filter(void) bpf_prm =rte_bpf_convert (&bf);if (bpf_prm ==NULL )rte_exit (EXIT_FAILURE , -"bpf convert failed\n" ); +"bpf convert failed: %s(%d)\n" , +rte_strerror (rte_errno), rte_errno);if (dump_bpf) {printf ("cBPF program (%u insns)\n" , bf.bf_len);
lib/bpf/bpf_load.c +0 -18
@@ -130,21 +130,3 @@ rte_bpf_load(const struct rte_bpf_prm *prm)return bpf; } - -#ifndef RTE_LIBRTE_BPF_ELF -struct rte_bpf * -rte_bpf_elf_load (const struct rte_bpf_prm *prm,const char *fname, -const char *sname) -{ -if (prm ==NULL || fname ==NULL || sname ==NULL ) { - rte_errno =EINVAL ; -return NULL ; - } - -RTE_BPF_LOG (ERR ,"%s() is not supported with current config\n" -"rebuild with libelf installed\n" , - __func__); - rte_errno =ENOTSUP ; -return NULL ; -} -#endif
lib/bpf/bpf_stub.c new file +45 -0
45 lines not on this page · raw message
lib/bpf/meson.build +5 -0
@@ -12,6 +12,7 @@ sources = files('bpf.c', 'bpf_exec.c', 'bpf_load.c', 'bpf_pkt.c', + 'bpf_stub.c', 'bpf_validate.c') if arch_subdir == 'x86' and dpdk_conf.get('RTE_ARCH_64')
@@ -31,9 +32,13 @@ if dep.found() dpdk_conf.set('RTE_LIBRTE_BPF_ELF', 1) sources += files('bpf_load_elf.c') ext_deps += dep +else + warning('libelf is missing, rte_bpf_elf_load API will be disabled') endif if dpdk_conf.has('RTE_PORT_PCAP') sources += files('bpf_convert.c') ext_deps += pcap_dep +else + warning('RTE_PORT_PCAP is missing, rte_bpf_convert API will be disabled') endif
lib/bpf/rte_bpf.h +1 -4
@@ -212,8 +212,6 @@ __rte_experimentalvoid rte_bpf_dump (FILE *f,const struct ebpf_insn *buf,uint32_t len); -#ifdef RTE_PORT_PCAP -struct bpf_program ;/**
@@ -228,13 +226,12 @@ struct bpf_program;* Possible rte_errno errors include: * - EINVAL - invalid parameter passed to function * - ENOMEM - can't reserve enough memory +* - ENOTSUP - operation not supported */ __rte_experimental struct rte_bpf_prm *rte_bpf_convert (const struct bpf_program *prog); -#endif - #ifdef __cplusplus }#endif
Signature · 1 line
2.25.1
Thomas Monjalon
AppliedRe: [dpdk-dev] [PATCH v3 0/2] few bpf library fixes
In reply to Konstantin AnanyevQuoted 3 lines
Konstantin Ananyev (2):
bpf: fix doxygen comments
bpf: fix convert API can be undefined
Applied, thanks.
Quoted 11 lines · On Mon, 1 Nov 2021 14:52:46 +0000 Konstantin Ananyev…
rte_bpf_convert()implementation depends on libpcap. Right now it is defined only when this library is installed andRTE_PORT_PCAPis defined.
Fix that by providing for such case stubrte_bpf_convert()implementation that will always return an error.
Also move stub for another function (rte_bpf_elf_load) into the same place (bpf_stub.c).Fixes 2eccf6afbea9 ("bpf: add function to convert classic BPF to DPDK BPF")Signed-off-by Konstantin Ananyev <[email protected]>
It would be better to fail calls at compile time rather than returning an error.