Skip to contentSkip to conversation

bpf: fix convert API can be undefined

PATCH In review Konstantin Ananyev 3 participants 14 messages Nov 1, 2021 – Nov 4, 2021 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

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).

Fixes 2eccf6afbea9 ("bpf: add function to convert classic BPF to DPDK BPF")
---
 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
index 2a3b901d74..272f2ba11b 100644
@@ -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
index 33b506f3ac..0ec067957b 100644
@@ -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
index 0d0a84b130..5ec1f8abbb 100644
@@ -212,8 +212,6 @@ __rte_experimental
 void
 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_experimental
 struct rte_bpf_prm *
 rte_bpf_convert(const struct bpf_program *prog);
 
-#endif
-
 #ifdef __cplusplus
 }
 #endif
Signature · 1 line
2.25.1
#1 lore raw

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
#2 lore raw

PATCH v2 1/2 bpf: fix doxygen comments

Fix typo in doxygen comments for rte_bpf_convert().

Fixes 2eccf6afbea9 ("bpf: add function to convert classic BPF to DPDK BPF")
---
 lib/bpf/rte_bpf.h | 2 --
 1 file changed, 2 deletions(-)
lib/bpf/rte_bpf.h +0 -2
index 0d0a84b130..f09e36b65b 100644
@@ -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
#3 lore raw

PATCH v2 2/2 bpf: fix convert API can be undefined

In reply to Konstantin Ananyev

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).

Fixes 2eccf6afbea9 ("bpf: add function to convert classic BPF to DPDK BPF")
---
 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
index 2a3b901d74..272f2ba11b 100644
@@ -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
index 33b506f3ac..0ec067957b 100644
@@ -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
index f09e36b65b..7e7d03b9c7 100644
@@ -212,8 +212,6 @@ __rte_experimental
 void
 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
#4 lore raw
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 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).

Fixes 2eccf6afbea9 ("bpf: add function to convert classic BPF to DPDK BPF")

Wouldn't it be better to fail compiling a program using unimplemented calls rather than forcing the user to see a failure later?

#5 lore raw
Quoted 10 lines
Quoted 10 lines

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).

Quoted 6 lines
Quoted 3 lines
Fixes 2eccf6afbea9 ("bpf: add function to convert classic BPF to DPDK BPF")

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.

#6 lore raw
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 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).

Fixes 2eccf6afbea9 ("bpf: add function to convert classic BPF to DPDK BPF")
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 #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.

Is there a way to do both, return an error and report a warning in the build?

#7 lore raw
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 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).

Fixes 2eccf6afbea9 ("bpf: add function to convert classic BPF to DPDK BPF")

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 #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.

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.

#8 lore raw
In reply to Konstantin Ananyev
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 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).

Fixes 2eccf6afbea9 ("bpf: add function to convert classic BPF to DPDK BPF")

Should also change dumpcap to print more complete error?

app/dumpcap/main.c +1 -1
index baf9eee46666..fff460eee518 100644
@@ -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);
#9 lore raw

v3 cover few bpf library fixes

In reply to Konstantin Ananyev

v3:
- 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
#10 lore raw

PATCH v3 1/2 bpf: fix doxygen comments

Fix typo in doxygen comments for rte_bpf_convert().

Fixes 2eccf6afbea9 ("bpf: add function to convert classic BPF to DPDK BPF")
---
 lib/bpf/rte_bpf.h | 2 --
 1 file changed, 2 deletions(-)
lib/bpf/rte_bpf.h +0 -2
index 0d0a84b130..f09e36b65b 100644
@@ -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
#11 lore raw

PATCH v3 2/2 bpf: fix convert API can be undefined

In reply to Konstantin Ananyev

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.
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).

Fixes 2eccf6afbea9 ("bpf: add function to convert classic BPF to DPDK BPF")
---
 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
index baf9eee466..c5fe440302 100644
@@ -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
index 2a3b901d74..272f2ba11b 100644
@@ -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
index 33b506f3ac..0df55a2236 100644
@@ -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
index f09e36b65b..7e7d03b9c7 100644
@@ -212,8 +212,6 @@ __rte_experimental
 void
 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
#13 lore raw
In reply to Konstantin Ananyev
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 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).

Fixes 2eccf6afbea9 ("bpf: add function to convert classic BPF to DPDK BPF")

It would be better to fail calls at compile time rather than returning an error.