[ovs-dev] [RFC 5/5] netdev: do not allow devices to be opened with conflicting types

Thadeu Lima de Souza Cascardo cascardo at redhat.com
Mon Jul 18 17:00:25 UTC 2016


When a device is already opened, netdev_open should verify that the types match,
or else return an error.

Otherwise, users might expect to open a device with a certain type and get a
handle belonging to a different type.

This also prevents certain conflicting configurations that would have a port of
a certain type in the database and one of a different type on the system.
---
 lib/netdev.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/lib/netdev.c b/lib/netdev.c
index 6651173..ab7386a 100644
--- a/lib/netdev.c
+++ b/lib/netdev.c
@@ -339,7 +339,8 @@ netdev_open(const char *name, const char *type, struct netdev **netdevp)
     if (!netdev) {
         struct netdev_registered_class *rc;
 
-        rc = netdev_lookup_class(type && type[0] ? type : "system");
+        type = type && type[0] ? type : "system";
+        rc = netdev_lookup_class(type);
         if (rc && ovs_refcount_try_ref_rcu(&rc->refcnt)) {
             netdev = rc->class->alloc();
             if (netdev) {
@@ -376,6 +377,11 @@ netdev_open(const char *name, const char *type, struct netdev **netdevp)
                       name, type);
             error = EAFNOSUPPORT;
         }
+    } else if (type && strcmp(type, netdev_get_type(netdev))) {
+        VLOG_WARN("trying to create netdev %s of different type %s,"
+                  " already is %s\n",
+                  name, type, netdev_get_type(netdev));
+        error = EEXIST;
     } else {
         error = 0;
     }
-- 
2.7.4




More information about the dev mailing list