8173a68
diff -up dhcp-4.3.4/client/dhclient.c.duid_uuid dhcp-4.3.4/client/dhclient.c
8173a68
--- dhcp-4.3.4/client/dhclient.c.duid_uuid	2016-04-29 12:58:14.846150838 +0200
8173a68
+++ dhcp-4.3.4/client/dhclient.c	2016-04-29 12:58:14.851150839 +0200
8173a68
@@ -3868,6 +3868,59 @@ write_options(struct client_state *clien
a40b8cb
 	}
a40b8cb
 }
a40b8cb
 
a40b8cb
+int unhexchar(char c) {
a40b8cb
+
a40b8cb
+	if (c >= '0' && c <= '9')
a40b8cb
+		return c - '0';
a40b8cb
+
a40b8cb
+	if (c >= 'a' && c <= 'f')
a40b8cb
+		return c - 'a' + 10;
a40b8cb
+
a40b8cb
+	if (c >= 'A' && c <= 'F')
a40b8cb
+		return c - 'A' + 10;
a40b8cb
+
a40b8cb
+	return -1;
a40b8cb
+}
a40b8cb
+
a40b8cb
+isc_result_t
a40b8cb
+read_uuid(u_int8_t* uuid) {
a40b8cb
+	const char *id_fname = "/etc/machine-id";
a40b8cb
+	char id[32];
a40b8cb
+	size_t nread;
a40b8cb
+	FILE * file = fopen( id_fname , "r");
a40b8cb
+	if (!file) {
a40b8cb
+		log_debug("Cannot open %s", id_fname);
a40b8cb
+		return ISC_R_IOERROR;
a40b8cb
+	}
a40b8cb
+	nread = fread(id, 1, sizeof id, file);
a40b8cb
+	fclose(file);
a40b8cb
+
a40b8cb
+	if (nread < 32) {
a40b8cb
+		log_debug("Not enough data in %s", id_fname);
a40b8cb
+		return ISC_R_IOERROR;
a40b8cb
+	}
baeda11
+	int j;
baeda11
+	for (j = 0; j < 16; j++) {
a40b8cb
+		int a, b;
a40b8cb
+
a40b8cb
+		a = unhexchar(id[j*2]);
a40b8cb
+		b = unhexchar(id[j*2+1]);
a40b8cb
+
a40b8cb
+		if (a < 0 || b < 0) {
a40b8cb
+			log_debug("Wrong data in %s", id_fname);
a40b8cb
+                        return ISC_R_IOERROR;
a40b8cb
+		}
a40b8cb
+		uuid[j] = a << 4 | b;
a40b8cb
+	}
a40b8cb
+
a40b8cb
+	/* Set UUID version to 4 --- truly random generation */
a40b8cb
+	uuid[6] = (uuid[6] & 0x0F) | 0x40;
a40b8cb
+	/* Set the UUID variant to DCE */
a40b8cb
+	uuid[8] = (uuid[8] & 0x3F) | 0x80;
a40b8cb
+
a40b8cb
+	return ISC_R_SUCCESS;
a40b8cb
+}
a40b8cb
+
a40b8cb
 /*
a40b8cb
  * The "best" default DUID, since we cannot predict any information
a40b8cb
  * about the system (such as whether or not the hardware addresses are
8173a68
@@ -3888,6 +3941,7 @@ form_duid(struct data_string *duid, cons
a40b8cb
 	struct interface_info *ip;
a40b8cb
 	int len;
a40b8cb
 	char *str;
a40b8cb
+	u_int8_t uuid[16];
a40b8cb
 
a40b8cb
 	/* For now, just use the first interface on the list. */
a40b8cb
 	ip = interfaces;
8173a68
@@ -3908,9 +3962,16 @@ form_duid(struct data_string *duid, cons
a40b8cb
 	    (ip->hw_address.hlen > sizeof(ip->hw_address.hbuf)))
a40b8cb
 		log_fatal("Impossible hardware address length at %s:%d.", MDL);
a40b8cb
 
a40b8cb
-	if (duid_type == 0)
a40b8cb
-		duid_type = stateless ? DUID_LL : DUID_LLT;
a40b8cb
-
a40b8cb
+	if (duid_type == 0) {
a40b8cb
+		if (read_uuid(uuid) == ISC_R_SUCCESS)
a40b8cb
+		    duid_type = DUID_UUID;
a40b8cb
+		else
a40b8cb
+		    duid_type = stateless ? DUID_LL : DUID_LLT;
a40b8cb
+	}
a40b8cb
+	
a40b8cb
+	if (duid_type == DUID_UUID)
a40b8cb
+		len = 2 + sizeof (uuid);
a40b8cb
+	else {
a40b8cb
 	/*
a40b8cb
 	 * 2 bytes for the 'duid type' field.
a40b8cb
 	 * 2 bytes for the 'htype' field.
8173a68
@@ -3921,13 +3982,18 @@ form_duid(struct data_string *duid, cons
a40b8cb
 	len = 4 + (ip->hw_address.hlen - 1);
a40b8cb
 	if (duid_type == DUID_LLT)
a40b8cb
 		len += 4;
a40b8cb
+	}
a40b8cb
 	if (!buffer_allocate(&duid->buffer, len, MDL))
a40b8cb
 		log_fatal("no memory for default DUID!");
a40b8cb
 	duid->data = duid->buffer->data;
a40b8cb
 	duid->len = len;
a40b8cb
 
a40b8cb
+	if (duid_type == DUID_UUID) {
a40b8cb
+		putUShort(duid->buffer->data, DUID_UUID);
a40b8cb
+		memcpy(duid->buffer->data + 2, uuid, sizeof(uuid));
a40b8cb
+	}
a40b8cb
 	/* Basic Link Local Address type of DUID. */
a40b8cb
-	if (duid_type == DUID_LLT) {
a40b8cb
+	else if (duid_type == DUID_LLT) {
a40b8cb
 		putUShort(duid->buffer->data, DUID_LLT);
a40b8cb
 		putUShort(duid->buffer->data + 2, ip->hw_address.hbuf[0]);
a40b8cb
 		putULong(duid->buffer->data + 4, cur_time - DUID_TIME_EPOCH);