dpif: New function dpif_normalize_type().
authorBen Pfaff <blp@nicira.com>
Tue, 5 Apr 2011 19:52:58 +0000 (12:52 -0700)
committerBen Pfaff <blp@nicira.com>
Wed, 4 May 2011 17:20:06 +0000 (10:20 -0700)
This allows dpif types to be compared.

lib/dpif.c
lib/dpif.h

index 81e180f..26d3dc2 100644 (file)
@@ -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(). */
index 0e0f407..d6adbc3 100644 (file)
@@ -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 *);