DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] bpf: fix convert API can be undefined
@ 2021-11-01 14:52 Konstantin Ananyev
  2021-11-01 16:10 ` [dpdk-dev] [PATCH v2 0/2] few bpf library fixes Konstantin Ananyev
  2021-11-01 16:15 ` [dpdk-dev] [PATCH] bpf: fix convert API can be undefined Stephen Hemminger
  0 siblings, 2 replies; 14+ messages in thread
From: Konstantin Ananyev @ 2021-11-01 14:52 UTC (permalink / raw)
  To: dev; +Cc: stephen, 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")

Signed-off-by: Konstantin Ananyev <konstantin.ananyev@intel.com>
---
 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

diff --git a/lib/bpf/bpf_load.c b/lib/bpf/bpf_load.c
index 2a3b901d74..272f2ba11b 100644
--- a/lib/bpf/bpf_load.c
+++ b/lib/bpf/bpf_load.c
@@ -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
diff --git a/lib/bpf/bpf_stub.c b/lib/bpf/bpf_stub.c
new file mode 100644
index 0000000000..caec00f42f
--- /dev/null
+++ b/lib/bpf/bpf_stub.c
@@ -0,0 +1,45 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2018-2021 Intel Corporation
+ */
+
+#include "bpf_impl.h"
+#include <rte_errno.h>
+
+/**
+ * Contains stubs for unimplemented public API functions
+ */
+
+#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
+
+#ifndef RTE_PORT_PCAP
+struct rte_bpf_prm *
+rte_bpf_convert(const struct bpf_program *prog)
+{
+	if (prog == NULL) {
+		rte_errno = EINVAL;
+		return NULL;
+	}
+
+	RTE_BPF_LOG(ERR, "%s() is not supported with current config\n"
+		"rebuild with libpcap installed\n",
+		__func__);
+	rte_errno = ENOTSUP;
+	return NULL;
+}
+#endif
diff --git a/lib/bpf/meson.build b/lib/bpf/meson.build
index 33b506f3ac..0ec067957b 100644
--- a/lib/bpf/meson.build
+++ b/lib/bpf/meson.build
@@ -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')
diff --git a/lib/bpf/rte_bpf.h b/lib/bpf/rte_bpf.h
index 0d0a84b130..5ec1f8abbb 100644
--- a/lib/bpf/rte_bpf.h
+++ b/lib/bpf/rte_bpf.h
@@ -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
-- 
2.25.1


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [dpdk-dev] [PATCH v2 0/2] few bpf library fixes
  2021-11-01 14:52 [dpdk-dev] [PATCH] bpf: fix convert API can be undefined Konstantin Ananyev
@ 2021-11-01 16:10 ` Konstantin Ananyev
  2021-11-01 16:10   ` [dpdk-dev] [PATCH v2 1/2] bpf: fix doxygen comments Konstantin Ananyev
                     ` (2 more replies)
  2021-11-01 16:15 ` [dpdk-dev] [PATCH] bpf: fix convert API can be undefined Stephen Hemminger
  1 sibling, 3 replies; 14+ messages in thread
From: Konstantin Ananyev @ 2021-11-01 16:10 UTC (permalink / raw)
  To: dev; +Cc: stephen, Konstantin Ananyev

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

-- 
2.25.1


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [dpdk-dev] [PATCH v2 1/2] bpf: fix doxygen comments
  2021-11-01 16:10 ` [dpdk-dev] [PATCH v2 0/2] few bpf library fixes Konstantin Ananyev
@ 2021-11-01 16:10   ` Konstantin Ananyev
  2021-11-01 16:10   ` [dpdk-dev] [PATCH v2 2/2] bpf: fix convert API can be undefined Konstantin Ananyev
  2021-11-03 11:17   ` [dpdk-dev] [PATCH v3 0/2] few bpf library fixes Konstantin Ananyev
  2 siblings, 0 replies; 14+ messages in thread
From: Konstantin Ananyev @ 2021-11-01 16:10 UTC (permalink / raw)
  To: dev; +Cc: stephen, Konstantin Ananyev

Fix typo in doxygen comments for rte_bpf_convert().

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

Signed-off-by: Konstantin Ananyev <konstantin.ananyev@intel.com>
---
 lib/bpf/rte_bpf.h | 2 --
 1 file changed, 2 deletions(-)

diff --git a/lib/bpf/rte_bpf.h b/lib/bpf/rte_bpf.h
index 0d0a84b130..f09e36b65b 100644
--- a/lib/bpf/rte_bpf.h
+++ b/lib/bpf/rte_bpf.h
@@ -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,
-- 
2.25.1


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [dpdk-dev] [PATCH v2 2/2] bpf: fix convert API can be undefined
  2021-11-01 16:10 ` [dpdk-dev] [PATCH v2 0/2] few bpf library fixes Konstantin Ananyev
  2021-11-01 16:10   ` [dpdk-dev] [PATCH v2 1/2] bpf: fix doxygen comments Konstantin Ananyev
@ 2021-11-01 16:10   ` Konstantin Ananyev
  2021-11-01 17:05     ` Stephen Hemminger
  2021-11-02 15:27     ` Stephen Hemminger
  2021-11-03 11:17   ` [dpdk-dev] [PATCH v3 0/2] few bpf library fixes Konstantin Ananyev
  2 siblings, 2 replies; 14+ messages in thread
From: Konstantin Ananyev @ 2021-11-01 16:10 UTC (permalink / raw)
  To: dev; +Cc: stephen, 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")

Signed-off-by: Konstantin Ananyev <konstantin.ananyev@intel.com>
---
 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

diff --git a/lib/bpf/bpf_load.c b/lib/bpf/bpf_load.c
index 2a3b901d74..272f2ba11b 100644
--- a/lib/bpf/bpf_load.c
+++ b/lib/bpf/bpf_load.c
@@ -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
diff --git a/lib/bpf/bpf_stub.c b/lib/bpf/bpf_stub.c
new file mode 100644
index 0000000000..caec00f42f
--- /dev/null
+++ b/lib/bpf/bpf_stub.c
@@ -0,0 +1,45 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2018-2021 Intel Corporation
+ */
+
+#include "bpf_impl.h"
+#include <rte_errno.h>
+
+/**
+ * Contains stubs for unimplemented public API functions
+ */
+
+#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
+
+#ifndef RTE_PORT_PCAP
+struct rte_bpf_prm *
+rte_bpf_convert(const struct bpf_program *prog)
+{
+	if (prog == NULL) {
+		rte_errno = EINVAL;
+		return NULL;
+	}
+
+	RTE_BPF_LOG(ERR, "%s() is not supported with current config\n"
+		"rebuild with libpcap installed\n",
+		__func__);
+	rte_errno = ENOTSUP;
+	return NULL;
+}
+#endif
diff --git a/lib/bpf/meson.build b/lib/bpf/meson.build
index 33b506f3ac..0ec067957b 100644
--- a/lib/bpf/meson.build
+++ b/lib/bpf/meson.build
@@ -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')
diff --git a/lib/bpf/rte_bpf.h b/lib/bpf/rte_bpf.h
index f09e36b65b..7e7d03b9c7 100644
--- a/lib/bpf/rte_bpf.h
+++ b/lib/bpf/rte_bpf.h
@@ -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
-- 
2.25.1


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [dpdk-dev] [PATCH] bpf: fix convert API can be undefined
  2021-11-01 14:52 [dpdk-dev] [PATCH] bpf: fix convert API can be undefined Konstantin Ananyev
  2021-11-01 16:10 ` [dpdk-dev] [PATCH v2 0/2] few bpf library fixes Konstantin Ananyev
@ 2021-11-01 16:15 ` Stephen Hemminger
  1 sibling, 0 replies; 14+ messages in thread
From: Stephen Hemminger @ 2021-11-01 16:15 UTC (permalink / raw)
  To: Konstantin Ananyev; +Cc: dev

On Mon,  1 Nov 2021 14:52:46 +0000
Konstantin Ananyev <konstantin.ananyev@intel.com> wrote:

> 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")
> 
> Signed-off-by: Konstantin Ananyev <konstantin.ananyev@intel.com>

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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [dpdk-dev] [PATCH v2 2/2] bpf: fix convert API can be undefined
  2021-11-01 16:10   ` [dpdk-dev] [PATCH v2 2/2] bpf: fix convert API can be undefined Konstantin Ananyev
@ 2021-11-01 17:05     ` Stephen Hemminger
  2021-11-02 10:54       ` Ananyev, Konstantin
  2021-11-02 15:27     ` Stephen Hemminger
  1 sibling, 1 reply; 14+ messages in thread
From: Stephen Hemminger @ 2021-11-01 17:05 UTC (permalink / raw)
  To: Konstantin Ananyev; +Cc: dev

On Mon,  1 Nov 2021 16:10:13 +0000
Konstantin Ananyev <konstantin.ananyev@intel.com> wrote:

> 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")
> 
> Signed-off-by: Konstantin Ananyev <konstantin.ananyev@intel.com>

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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [dpdk-dev] [PATCH v2 2/2] bpf: fix convert API can be undefined
  2021-11-01 17:05     ` Stephen Hemminger
@ 2021-11-02 10:54       ` Ananyev, Konstantin
  2021-11-02 15:05         ` Stephen Hemminger
  0 siblings, 1 reply; 14+ messages in thread
From: Ananyev, Konstantin @ 2021-11-02 10:54 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: dev



> > 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")
> >
> > Signed-off-by: Konstantin Ananyev <konstantin.ananyev@intel.com>
> 
> 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. 


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [dpdk-dev] [PATCH v2 2/2] bpf: fix convert API can be undefined
  2021-11-02 10:54       ` Ananyev, Konstantin
@ 2021-11-02 15:05         ` Stephen Hemminger
  2021-11-03 10:54           ` Ananyev, Konstantin
  0 siblings, 1 reply; 14+ messages in thread
From: Stephen Hemminger @ 2021-11-02 15:05 UTC (permalink / raw)
  To: Ananyev, Konstantin; +Cc: dev

On Tue, 2 Nov 2021 10:54:59 +0000
"Ananyev, Konstantin" <konstantin.ananyev@intel.com> wrote:

> > > 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")
> > >
> > > Signed-off-by: Konstantin Ananyev <konstantin.ananyev@intel.com>  
> > 
> > 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?

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [dpdk-dev] [PATCH v2 2/2] bpf: fix convert API can be undefined
  2021-11-01 16:10   ` [dpdk-dev] [PATCH v2 2/2] bpf: fix convert API can be undefined Konstantin Ananyev
  2021-11-01 17:05     ` Stephen Hemminger
@ 2021-11-02 15:27     ` Stephen Hemminger
  1 sibling, 0 replies; 14+ messages in thread
From: Stephen Hemminger @ 2021-11-02 15:27 UTC (permalink / raw)
  To: Konstantin Ananyev; +Cc: dev

On Mon,  1 Nov 2021 16:10:13 +0000
Konstantin Ananyev <konstantin.ananyev@intel.com> wrote:

> 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")
> 
> Signed-off-by: Konstantin Ananyev <konstantin.ananyev@intel.com>

Should also change dumpcap to print more complete error?


diff --git a/app/dumpcap/main.c b/app/dumpcap/main.c
index baf9eee46666..fff460eee518 100644
--- a/app/dumpcap/main.c
+++ b/app/dumpcap/main.c
@@ -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);

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [dpdk-dev] [PATCH v2 2/2] bpf: fix convert API can be undefined
  2021-11-02 15:05         ` Stephen Hemminger
@ 2021-11-03 10:54           ` Ananyev, Konstantin
  0 siblings, 0 replies; 14+ messages in thread
From: Ananyev, Konstantin @ 2021-11-03 10:54 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: dev



> On Tue, 2 Nov 2021 10:54:59 +0000
> "Ananyev, Konstantin" <konstantin.ananyev@intel.com> wrote:
> 
> > > > 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")
> > > >
> > > > Signed-off-by: Konstantin Ananyev <konstantin.ananyev@intel.com>
> > >
> > > 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?

Sounds like a good idea, will add a warning to meson.build.


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [dpdk-dev] [PATCH v3 0/2] few bpf library fixes
  2021-11-01 16:10 ` [dpdk-dev] [PATCH v2 0/2] few bpf library fixes Konstantin Ananyev
  2021-11-01 16:10   ` [dpdk-dev] [PATCH v2 1/2] bpf: fix doxygen comments Konstantin Ananyev
  2021-11-01 16:10   ` [dpdk-dev] [PATCH v2 2/2] bpf: fix convert API can be undefined Konstantin Ananyev
@ 2021-11-03 11:17   ` Konstantin Ananyev
  2021-11-03 11:17     ` [dpdk-dev] [PATCH v3 1/2] bpf: fix doxygen comments Konstantin Ananyev
                       ` (2 more replies)
  2 siblings, 3 replies; 14+ messages in thread
From: Konstantin Ananyev @ 2021-11-03 11:17 UTC (permalink / raw)
  To: dev; +Cc: stephen, 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

-- 
2.25.1


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [dpdk-dev] [PATCH v3 1/2] bpf: fix doxygen comments
  2021-11-03 11:17   ` [dpdk-dev] [PATCH v3 0/2] few bpf library fixes Konstantin Ananyev
@ 2021-11-03 11:17     ` Konstantin Ananyev
  2021-11-03 11:17     ` [dpdk-dev] [PATCH v3 2/2] bpf: fix convert API can be undefined Konstantin Ananyev
  2021-11-04 19:00     ` [dpdk-dev] [PATCH v3 0/2] few bpf library fixes Thomas Monjalon
  2 siblings, 0 replies; 14+ messages in thread
From: Konstantin Ananyev @ 2021-11-03 11:17 UTC (permalink / raw)
  To: dev; +Cc: stephen, Konstantin Ananyev

Fix typo in doxygen comments for rte_bpf_convert().

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

Signed-off-by: Konstantin Ananyev <konstantin.ananyev@intel.com>
---
 lib/bpf/rte_bpf.h | 2 --
 1 file changed, 2 deletions(-)

diff --git a/lib/bpf/rte_bpf.h b/lib/bpf/rte_bpf.h
index 0d0a84b130..f09e36b65b 100644
--- a/lib/bpf/rte_bpf.h
+++ b/lib/bpf/rte_bpf.h
@@ -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,
-- 
2.25.1


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [dpdk-dev] [PATCH v3 2/2] bpf: fix convert API can be undefined
  2021-11-03 11:17   ` [dpdk-dev] [PATCH v3 0/2] few bpf library fixes Konstantin Ananyev
  2021-11-03 11:17     ` [dpdk-dev] [PATCH v3 1/2] bpf: fix doxygen comments Konstantin Ananyev
@ 2021-11-03 11:17     ` Konstantin Ananyev
  2021-11-04 19:00     ` [dpdk-dev] [PATCH v3 0/2] few bpf library fixes Thomas Monjalon
  2 siblings, 0 replies; 14+ messages in thread
From: Konstantin Ananyev @ 2021-11-03 11:17 UTC (permalink / raw)
  To: dev; +Cc: stephen, 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")

Signed-off-by: Konstantin Ananyev <konstantin.ananyev@intel.com>
---
 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

diff --git a/app/dumpcap/main.c b/app/dumpcap/main.c
index baf9eee466..c5fe440302 100644
--- a/app/dumpcap/main.c
+++ b/app/dumpcap/main.c
@@ -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);
diff --git a/lib/bpf/bpf_load.c b/lib/bpf/bpf_load.c
index 2a3b901d74..272f2ba11b 100644
--- a/lib/bpf/bpf_load.c
+++ b/lib/bpf/bpf_load.c
@@ -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
diff --git a/lib/bpf/bpf_stub.c b/lib/bpf/bpf_stub.c
new file mode 100644
index 0000000000..caec00f42f
--- /dev/null
+++ b/lib/bpf/bpf_stub.c
@@ -0,0 +1,45 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2018-2021 Intel Corporation
+ */
+
+#include "bpf_impl.h"
+#include <rte_errno.h>
+
+/**
+ * Contains stubs for unimplemented public API functions
+ */
+
+#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
+
+#ifndef RTE_PORT_PCAP
+struct rte_bpf_prm *
+rte_bpf_convert(const struct bpf_program *prog)
+{
+	if (prog == NULL) {
+		rte_errno = EINVAL;
+		return NULL;
+	}
+
+	RTE_BPF_LOG(ERR, "%s() is not supported with current config\n"
+		"rebuild with libpcap installed\n",
+		__func__);
+	rte_errno = ENOTSUP;
+	return NULL;
+}
+#endif
diff --git a/lib/bpf/meson.build b/lib/bpf/meson.build
index 33b506f3ac..0df55a2236 100644
--- a/lib/bpf/meson.build
+++ b/lib/bpf/meson.build
@@ -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
diff --git a/lib/bpf/rte_bpf.h b/lib/bpf/rte_bpf.h
index f09e36b65b..7e7d03b9c7 100644
--- a/lib/bpf/rte_bpf.h
+++ b/lib/bpf/rte_bpf.h
@@ -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
-- 
2.25.1


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [dpdk-dev] [PATCH v3 0/2] few bpf library fixes
  2021-11-03 11:17   ` [dpdk-dev] [PATCH v3 0/2] few bpf library fixes Konstantin Ananyev
  2021-11-03 11:17     ` [dpdk-dev] [PATCH v3 1/2] bpf: fix doxygen comments Konstantin Ananyev
  2021-11-03 11:17     ` [dpdk-dev] [PATCH v3 2/2] bpf: fix convert API can be undefined Konstantin Ananyev
@ 2021-11-04 19:00     ` Thomas Monjalon
  2 siblings, 0 replies; 14+ messages in thread
From: Thomas Monjalon @ 2021-11-04 19:00 UTC (permalink / raw)
  To: Konstantin Ananyev; +Cc: dev, stephen

> Konstantin Ananyev (2):
>   bpf: fix doxygen comments
>   bpf: fix convert API can be undefined

Applied, thanks.




^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2021-11-04 19:00 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-01 14:52 [dpdk-dev] [PATCH] bpf: fix convert API can be undefined Konstantin Ananyev
2021-11-01 16:10 ` [dpdk-dev] [PATCH v2 0/2] few bpf library fixes Konstantin Ananyev
2021-11-01 16:10   ` [dpdk-dev] [PATCH v2 1/2] bpf: fix doxygen comments Konstantin Ananyev
2021-11-01 16:10   ` [dpdk-dev] [PATCH v2 2/2] bpf: fix convert API can be undefined Konstantin Ananyev
2021-11-01 17:05     ` Stephen Hemminger
2021-11-02 10:54       ` Ananyev, Konstantin
2021-11-02 15:05         ` Stephen Hemminger
2021-11-03 10:54           ` Ananyev, Konstantin
2021-11-02 15:27     ` Stephen Hemminger
2021-11-03 11:17   ` [dpdk-dev] [PATCH v3 0/2] few bpf library fixes Konstantin Ananyev
2021-11-03 11:17     ` [dpdk-dev] [PATCH v3 1/2] bpf: fix doxygen comments Konstantin Ananyev
2021-11-03 11:17     ` [dpdk-dev] [PATCH v3 2/2] bpf: fix convert API can be undefined Konstantin Ananyev
2021-11-04 19:00     ` [dpdk-dev] [PATCH v3 0/2] few bpf library fixes Thomas Monjalon
2021-11-01 16:15 ` [dpdk-dev] [PATCH] bpf: fix convert API can be undefined Stephen Hemminger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).