netdev-vport: Use vport set_stats instead of internal dev.
[openvswitch] / lib / uuid.c
index 264d9bf5afb113f0dc1813d08ca9f90447a66c6f..9aaa91590d9a1bc0c025831f8674328c9dea1bbe 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2008, 2009 Nicira Networks
+/* Copyright (c) 2008, 2009, 2010 Nicira Networks
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -107,6 +107,14 @@ uuid_zero(struct uuid *uuid)
     uuid->parts[0] = uuid->parts[1] = uuid->parts[2] = uuid->parts[3] = 0;
 }
 
+/* Returns true if 'uuid' is all zero, otherwise false. */
+bool
+uuid_is_zero(const struct uuid *uuid)
+{
+    return (!uuid->parts[0] && !uuid->parts[1]
+            && !uuid->parts[2] && !uuid->parts[3]);
+}
+
 /* Compares 'a' and 'b'.  Returns a negative value if 'a < b', zero if 'a ==
  * b', or positive if 'a > b'.  The ordering is lexicographical order of the
  * conventional way of writing out UUIDs as strings. */
@@ -132,6 +140,22 @@ uuid_compare_3way(const struct uuid *a, const struct uuid *b)
  * be set to all-zero-bits. */
 bool
 uuid_from_string(struct uuid *uuid, const char *s)
+{
+    if (!uuid_from_string_prefix(uuid, s)) {
+        return false;
+    } else if (s[UUID_LEN] != '\0') {
+        uuid_zero(uuid);
+        return false;
+    } else {
+        return true;
+    }
+}
+
+/* Same as uuid_from_string() but s[UUID_LEN] is not required to be a null byte
+ * to succeed; that is, 's' need only begin with UUID syntax, not consist
+ * entirely of it. */
+bool
+uuid_from_string_prefix(struct uuid *uuid, const char *s)
 {
     static const char template[] = "00000000-1111-1111-2222-222233333333";
     const char *t;
@@ -144,10 +168,10 @@ uuid_from_string(struct uuid *uuid, const char *s)
                 goto error;
             }
             *part = (*part << 4) + hexit_value(*s);
-        } else if (*t != *s) {
-            goto error;
         } else if (*t == 0) {
             return true;
+        } else if (*t != *s) {
+            goto error;
         }
     }