bpf: fix convert API can be undefined
Checks
Commit Message
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
Comments
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.
@@ -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
new file mode 100644
@@ -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
@@ -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')
@@ -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