diff mbox

[ovs-dev,v2,1/5] netdev: get device type from vport prefix if not found

Message ID 1465410123-1879-2-git-send-email-cascardo@redhat.com
State Superseded
Headers show

Commit Message

Thadeu Lima de Souza Cascardo June 8, 2016, 6:21 p.m. UTC
If we cannot find the device type because it's not opened yet, check if it uses
a reserved prefix for a vport type and return that type.

Since these names are reserved, we can assume this is the right type.

This is important when we are querying the datapath right after vswitch has
started and using the right type will be even more important when we add support
to creating tunnel ports with rtnetlink.

Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@redhat.com>
---
 lib/netdev.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
diff mbox

Patch

diff --git a/lib/netdev.c b/lib/netdev.c
index 4be806d..2109818 100644
--- a/lib/netdev.c
+++ b/lib/netdev.c
@@ -281,6 +281,21 @@  netdev_enumerate_types(struct sset *types)
     }
 }
 
+static const char *
+netdev_vport_type_from_name(const char *name)
+{
+    struct netdev_registered_class *rc;
+    const char *type;
+    CMAP_FOR_EACH (rc, cmap_node, &netdev_classes) {
+        const char *dpif_port = netdev_vport_class_get_dpif_port(rc->class);
+        if (dpif_port && !strncmp(name, dpif_port, strlen(dpif_port))) {
+            type = rc->class->type;
+            return type;
+        }
+    }
+    return NULL;
+}
+
 /* Check that the network device name is not the same as any of the registered
  * vport providers' dpif_port name (dpif_port is NULL if the vport provider
  * does not define it) or the datapath internal port name (e.g. ovs-system).
@@ -1762,6 +1777,9 @@  netdev_get_type_from_name(const char *name)
     struct netdev *dev = netdev_from_name(name);
     const char *type = dev ? netdev_get_type(dev) : NULL;
     netdev_close(dev);
+    if (type == NULL) {
+        return netdev_vport_type_from_name(name);
+    }
     return type;
 }