]> git.droids-corp.org - dpdk.git/commitdiff
bpf: fix convert API when libpcap missing
authorKonstantin Ananyev <konstantin.ananyev@intel.com>
Wed, 3 Nov 2021 11:17:47 +0000 (11:17 +0000)
committerThomas Monjalon <thomas@monjalon.net>
Thu, 4 Nov 2021 18:56:20 +0000 (19:56 +0100)
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
lib/bpf/bpf_load.c
lib/bpf/bpf_stub.c [new file with mode: 0644]
lib/bpf/meson.build
lib/bpf/rte_bpf.h

index baf9eee466667bc3217fd6570145f491e09abb16..c5fe4403028aaf0432aa313d44cc5b2f620110a3 100644 (file)
@@ -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);
index 2a3b901d74c3fe7520b3dd5a782b82cf2b5fdc3f..272f2ba11b3a2b12fb99aea65bfc89bd07ad3506 100644 (file)
@@ -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 (file)
index 0000000..caec00f
--- /dev/null
@@ -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
index 33b506f3ac1a70bf92a3214c96aac66a1844b3b3..0df55a2236857550cb0c0238c1c55e1a7ec88fb3 100644 (file)
@@ -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
index f09e36b65bf49a099e82721832404fa51a75e7e2..7e7d03b9c72855c6e35323d53bf413f348068fd5 100644 (file)
@@ -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