From: Ben Pfaff Date: Tue, 5 Apr 2011 19:52:58 +0000 (-0700) Subject: dpif: New function dpif_normalize_type(). X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3a225db7079158d1c46e56dced7ac3103a8864e2;p=openvswitch dpif: New function dpif_normalize_type(). This allows dpif types to be compared. --- diff --git a/lib/dpif.c b/lib/dpif.c index 81e180fb..26d3dc2a 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 0e0f407c..d6adbc30 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 *);