From 3a225db7079158d1c46e56dced7ac3103a8864e2 Mon Sep 17 00:00:00 2001
From: Ben Pfaff <blp@nicira.com>
Date: Tue, 5 Apr 2011 12:52:58 -0700
Subject: [PATCH] dpif: New function dpif_normalize_type().

This allows dpif types to be compared.
---
 lib/dpif.c | 14 +++++++++++---
 lib/dpif.h |  2 ++
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/lib/dpif.c b/lib/dpif.c
index 81e180fbb..26d3dc2ae 100644
--- a/lib/dpif.c
+++ b/lib/dpif.c
@@ -260,9 +260,7 @@ do_open(const char *name, const char *type, bool create, struct dpif **dpifp)
 
     dp_initialize();
 
-    if (!type || *type == '\0') {
-        type = "system";
-    }
+    type = dpif_normalize_type(type);
 
     registered_class = shash_find_data(&dpif_classes, type);
     if (!registered_class) {
@@ -363,6 +361,16 @@ dpif_base_name(const struct dpif *dpif)
     return dpif->base_name;
 }
 
+/* Returns the fully spelled out name for the given datapath 'type'.
+ *
+ * Normalized type string can be compared with strcmp().  Unnormalized type
+ * string might be the same even if they have different spellings. */
+const char *
+dpif_normalize_type(const char *type)
+{
+    return type && type[0] ? type : "system";
+}
+
 /* Destroys the datapath that 'dpif' is connected to, first removing all of its
  * ports.  After calling this function, it does not make sense to pass 'dpif'
  * to any functions other than dpif_name() or dpif_close(). */
diff --git a/lib/dpif.h b/lib/dpif.h
index 0e0f407c3..d6adbc302 100644
--- a/lib/dpif.h
+++ b/lib/dpif.h
@@ -55,6 +55,8 @@ void dpif_close(struct dpif *);
 const char *dpif_name(const struct dpif *);
 const char *dpif_base_name(const struct dpif *);
 
+const char *dpif_normalize_type(const char *);
+
 int dpif_delete(struct dpif *);
 
 int dpif_get_dp_stats(const struct dpif *, struct odp_stats *);
-- 
2.47.0