Blame SOURCES/dhcp-duid_uuid.patch

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