Add an api to create a pluggable dpif.
Signed-off-by: Roi Dayan <[email protected]>
---
build-aux/thread-safety-forbidden | 1 -
lib/automake.mk | 4 ++
lib/dpif-plugin.c | 79 +++++++++++++++++++++++++++++++
lib/dpif-plugin.h | 36 ++++++++++++++
lib/dpif-provider.h | 3 ++
lib/dpif.c | 17 +++++++
6 files changed, 139 insertions(+), 1 deletion(-)
create mode 100644 lib/dpif-plugin.c
create mode 100644 lib/dpif-plugin.h
diff --git a/build-aux/thread-safety-forbidden
b/build-aux/thread-safety-forbidden
index 42560df9ce59..eb036b9eb909 100644
--- a/build-aux/thread-safety-forbidden
+++ b/build-aux/thread-safety-forbidden
@@ -14,7 +14,6 @@
\bdbm_open(
\bdbm_store(
\bdirname(
-\bdlerror(
\bdrand48(
\becvt(
\bencrypt(
diff --git a/lib/automake.mk b/lib/automake.mk
index 78d6e651645d..a6c0acb971e4 100644
--- a/lib/automake.mk
+++ b/lib/automake.mk
@@ -691,3 +691,7 @@ lib/ovs-fields.7: $(srcdir)/build-aux/extract-ofp-fields
include/openvswitch/met
$(srcdir)/lib/meta-flow.xml > [email protected]
$(AM_V_at)mv [email protected] $@
EXTRA_DIST += lib/meta-flow.xml
+
+lib_libopenvswitch_la_SOURCES += \
+ lib/dpif-plugin.c \
+ lib/dpif-plugin.h
diff --git a/lib/dpif-plugin.c b/lib/dpif-plugin.c
new file mode 100644
index 000000000000..1eb9ca955425
--- /dev/null
+++ b/lib/dpif-plugin.c
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* XXX: Use libtool ltdl instead of dlopen ? */
+#include <dlfcn.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <config.h>
+#include "dpif-plugin.h"
+#include "openvswitch/vlog.h"
+
+VLOG_DEFINE_THIS_MODULE(dpif_plugin);
+
+static void *BODY; /* cached handle dlopen(NULL) */
+static struct dpif_plugin *dpif_plugin_list;
+
+static struct dpif_plugin *
+any_plugin_get(const char *prefix, const char *str)
+{
+ struct dpif_plugin *p;
+ char buf[256];
+ void *dlh;
+
+ for (p = dpif_plugin_list; p; p = p->next) {
+ if (strcmp(p->id, str) == 0) {
+ return p;
+ }
+ }
+
+ snprintf(buf, sizeof(buf), "%s-%s.so", prefix, str);
+ dlh = dlopen(buf, RTLD_LAZY);
+ if (!dlh) {
+ /* look in current binary, only open once */
+ dlh = BODY;
+ if (dlh == NULL) {
+ dlh = BODY = dlopen(NULL, RTLD_LAZY);
+ if (dlh == NULL)
+ goto noexist;
+ }
+ }
+
+ VLOG_INFO("Loaded plugin '%s-%s'", prefix, str);
+ dlerror(); /* Clear any existing error */
+ snprintf(buf, sizeof(buf), "%s_%s_plugin", prefix, str);
+ p = dlsym(dlh, buf);
+ if (p == NULL) {
+ VLOG_INFO("Cannot find symbol '%s_%s_plugin'", prefix, str);
+ goto noexist;
+ }
+
+ p->next = dpif_plugin_list;
+ p->id = strdup(str);
+ dpif_plugin_list = p;
+ return p;
+
+noexist:
+ return NULL;
+}
+
+struct dpif_plugin *
+dp_plugin_get(const char *str)
+{
+ return any_plugin_get("dpif", str);
+}
diff --git a/lib/dpif-plugin.h b/lib/dpif-plugin.h
new file mode 100644
index 000000000000..4bce4b3cc2c4
--- /dev/null
+++ b/lib/dpif-plugin.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef DPIF_PLUGIN_H
+#define DPIF_PLUGIN_H 1
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct dpif_plugin {
+ struct dpif_plugin *next;
+ const char *id;
+
+ const void *plugin_class;
+};
+
+struct dpif_plugin *dp_plugin_get(const char *str);
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* dpif-plugin.h */
diff --git a/lib/dpif-provider.h b/lib/dpif-provider.h
index 520e21e68db2..d4ee25888775 100644
--- a/lib/dpif-provider.h
+++ b/lib/dpif-provider.h
@@ -22,6 +22,9 @@
* exposed over OpenFlow as a single switch. Datapaths and the collections of
* ports that they contain may be fixed or dynamic. */
+#include <config.h>
+#include "lib/ct-dpif.h"
+#include "dpif.h"
#include "openflow/openflow.h"
#include "dpif.h"
#include "util.h"
diff --git a/lib/dpif.c b/lib/dpif.c
index a064f717f1a6..3ac831779bc8 100644
--- a/lib/dpif.c
+++ b/lib/dpif.c
@@ -27,6 +27,7 @@
#include "dp-packet.h"
#include "dpctl.h"
#include "dpif-netdev.h"
+#include "dpif-plugin.h"
#include "flow.h"
#include "netdev-offload.h"
#include "netdev-provider.h"
@@ -112,6 +113,20 @@ dpif_is_tap_port(const char *type)
return !strcmp(type, "tap");
}
+static void
+dp_register_dynamic_provider(const char *provider)
+{
+ struct dpif_plugin *p;
+
+ VLOG_INFO("Look for dp provider '%s'", provider);
+ p = dp_plugin_get(provider);
+ if (!p) {
+ return;
+ }
+ VLOG_INFO("Register dp provider '%s'", provider);
+ dp_register_provider(p->plugin_class);
+}
+
static void
dp_initialize(void)
{
@@ -130,6 +145,8 @@ dp_initialize(void)
dp_register_provider(base_dpif_classes[i]);
}
+ dp_register_dynamic_provider("netdev");
+
ovsthread_once_done(&once);
}
}
--
2.46.1
_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev