Blob Blame Raw
diff -up dhcp-4.1.1/client/dhc6.c.release6-elapsed dhcp-4.1.1/client/dhc6.c
--- dhcp-4.1.1/client/dhc6.c.release6-elapsed	2010-04-19 11:55:59.000000000 +0200
+++ dhcp-4.1.1/client/dhc6.c	2010-04-19 12:00:00.000000000 +0200
@@ -2174,7 +2174,7 @@ do_release6(void *input)
 	struct client_state *client;
 	struct data_string ds;
 	int send_ret;
-	struct timeval tv;
+	struct timeval elapsed, tv;
 
 	client = input;
 
@@ -2194,6 +2194,14 @@ do_release6(void *input)
 		client->start_time.tv_usec = cur_tv.tv_usec;
 	}
 
+	/* elapsed = cur - start */
+	elapsed.tv_sec = cur_tv.tv_sec - client->start_time.tv_sec;
+	elapsed.tv_usec = cur_tv.tv_usec - client->start_time.tv_usec;
+	if (elapsed.tv_usec < 0) {
+		elapsed.tv_sec -= 1;
+		elapsed.tv_usec += 1000000;
+	}
+
 	/*
 	 * Don't use unicast as we don't know if we still have an
 	 * available address with enough scope.
@@ -2210,6 +2218,18 @@ do_release6(void *input)
 	ds.buffer->data[0] = DHCPV6_RELEASE;
 	memcpy(ds.buffer->data + 1, client->dhcpv6_transaction_id, 3);
 
+	/* Form an elapsed option. */
+	/* Maximum value is 65535 1/100s coded as 0xffff. */
+	if ((elapsed.tv_sec < 0) || (elapsed.tv_sec > 655) ||
+	    ((elapsed.tv_sec == 655) && (elapsed.tv_usec > 350000))) {
+		client->elapsed = 0xffff;
+	} else {
+		client->elapsed = elapsed.tv_sec * 100;
+		client->elapsed += elapsed.tv_usec / 10000;
+	}
+
+	client->elapsed = htons(client->elapsed);
+
 	log_debug("XMT: Forming Release.");
 	make_client6_options(client, &client->sent_options,
 			     client->active_lease, DHCPV6_RELEASE);