1 /* Copyright (c) 2008, 2009, 2010 Nicira Networks
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
24 #define UUID_BIT 128 /* Number of bits in a UUID. */
25 #define UUID_OCTET (UUID_BIT / 8) /* Number of bytes in a UUID. */
27 /* A Universally Unique IDentifier (UUID) compliant with RFC 4122.
29 * Each of the parts is stored in host byte order, but the parts themselves are
30 * ordered from left to right. That is, (parts[0] >> 24) is the first 8 bits
31 * of the UUID when output in the standard form, and (parts[3] & 0xff) is the
36 BUILD_ASSERT_DECL(sizeof(struct uuid) == UUID_OCTET);
38 /* Formats a UUID as a string, in the conventional format.
41 * struct uuid uuid = ...;
42 * printf("This UUID is "UUID_FMT"\n", UUID_ARGS(&uuid));
46 #define UUID_FMT "%08x-%04x-%04x-%04x-%04x%08x"
47 #define UUID_ARGS(UUID) \
48 ((unsigned int) ((UUID)->parts[0])), \
49 ((unsigned int) ((UUID)->parts[1] >> 16)), \
50 ((unsigned int) ((UUID)->parts[1] & 0xffff)), \
51 ((unsigned int) ((UUID)->parts[2] >> 16)), \
52 ((unsigned int) ((UUID)->parts[2] & 0xffff)), \
53 ((unsigned int) ((UUID)->parts[3]))
55 /* Returns a hash value for 'uuid'. This hash value is the same regardless of
56 * whether we are running on a 32-bit or 64-bit or big-endian or little-endian
59 uuid_hash(const struct uuid *uuid)
61 return uuid->parts[0];
64 /* Returns true if 'a == b', false otherwise. */
66 uuid_equals(const struct uuid *a, const struct uuid *b)
68 return (a->parts[0] == b->parts[0]
69 && a->parts[1] == b->parts[1]
70 && a->parts[2] == b->parts[2]
71 && a->parts[3] == b->parts[3]);
75 void uuid_generate(struct uuid *);
76 void uuid_zero(struct uuid *);
77 bool uuid_is_zero(const struct uuid *);
78 int uuid_compare_3way(const struct uuid *, const struct uuid *);
79 bool uuid_from_string(struct uuid *, const char *);
80 bool uuid_from_string_prefix(struct uuid *, const char *);
82 #endif /* vswitchd/cfgdb.h */