]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Generate RFC4122 compliant UUIDs
authorMilos Vyletel <milos.vyletel@sde.cz>
Mon, 8 Apr 2013 18:10:54 +0000 (14:10 -0400)
committerEric Blake <eblake@redhat.com>
Mon, 8 Apr 2013 19:18:07 +0000 (13:18 -0600)
Even though http://libvirt.org/formatdomain.html#elementsMetadata
states that it requires RFC4122 compliance UUIDs that are generated
by virUUIDGenerate() are not. Following patch modifies generated
UUIDs to conform to rules described in RFC.

Signed-off-by: Milos Vyletel <milos.vyletel@sde.cz>
src/util/viruuid.c

index 7250543fe1d264a5214b2ab3e76700a06b19c23d..8f82187467cf802bb51a41062526793e16ee003a 100644 (file)
@@ -114,6 +114,25 @@ virUUIDGenerate(unsigned char *uuid)
         err = virUUIDGeneratePseudoRandomBytes(uuid, VIR_UUID_BUFLEN);
     }
 
+    /*
+     * Make UUID RFC 4122 compliant. Following form will be used:
+     *
+     * xxxxxxxx-xxxx-Axxx-Bxxx-xxxxxxxxxxxx
+     *
+     * where
+     * A is version defined in 4.1.3 of RFC
+     *  Msb0  Msb1  Msb2  Msb3   Version  Description
+     *   0     1     0     0        4     The randomly or pseudo-
+     *                                    randomly generated version
+     *                                    specified in this document.
+     *
+     * B is variant defined in 4.1.1 of RFC
+     *  Msb0  Msb1  Msb2  Description
+     *   1     0     x    The variant specified in this document.
+     */
+    uuid[6] = (uuid[6] & 0x0F) | (4 << 4);
+    uuid[8] = (uuid[8] & 0x3F) | (2 << 6);
+
     return err;
 }