Blame SOURCES/dhcp-4.2.5-sendDecline.patch

c8bb8f
diff -up dhcp-4.2.5b1/client/dhc6.c.sendDecline dhcp-4.2.5b1/client/dhc6.c
c8bb8f
--- dhcp-4.2.5b1/client/dhc6.c.sendDecline	2012-12-05 02:17:38.000000000 +0100
c8bb8f
+++ dhcp-4.2.5b1/client/dhc6.c	2012-12-17 13:21:16.922444939 +0100
c8bb8f
@@ -96,6 +96,8 @@ void do_select6(void *input);
c8bb8f
 void do_refresh6(void *input);
c8bb8f
 static void do_release6(void *input);
c8bb8f
 static void start_bound(struct client_state *client);
c8bb8f
+static void start_decline6(struct client_state *client);
c8bb8f
+static void do_decline6(void *input);
c8bb8f
 static void start_informed(struct client_state *client);
c8bb8f
 void informed_handler(struct packet *packet, struct client_state *client);
c8bb8f
 void bound_handler(struct packet *packet, struct client_state *client);
c8bb8f
@@ -2080,6 +2082,7 @@ start_release6(struct client_state *clie
c8bb8f
 	cancel_timeout(do_select6, client);
c8bb8f
 	cancel_timeout(do_refresh6, client);
c8bb8f
 	cancel_timeout(do_release6, client);
c8bb8f
+	cancel_timeout(do_decline6, client);
c8bb8f
 	client->state = S_STOPPED;
c8bb8f
 
c8bb8f
 	/*
c8bb8f
@@ -2713,6 +2716,7 @@ dhc6_check_reply(struct client_state *cl
c8bb8f
 		break;
c8bb8f
 
c8bb8f
 	      case S_STOPPED:
c8bb8f
+	      case S_DECLINED:
c8bb8f
 		action = dhc6_stop_action;
c8bb8f
 		break;
c8bb8f
 
c8bb8f
@@ -2814,6 +2818,7 @@ dhc6_check_reply(struct client_state *cl
c8bb8f
 		break;
c8bb8f
 
c8bb8f
 	      case S_STOPPED:
c8bb8f
+	      case S_DECLINED:
c8bb8f
 		/* Nothing critical to do at this stage. */
c8bb8f
 		break;
c8bb8f
 
c8bb8f
@@ -3804,17 +3809,23 @@ reply_handler(struct packet *packet, str
c8bb8f
 	cancel_timeout(do_select6, client);
c8bb8f
 	cancel_timeout(do_refresh6, client);
c8bb8f
 	cancel_timeout(do_release6, client);
c8bb8f
+	cancel_timeout(do_decline6, client);
c8bb8f
 
c8bb8f
 	/* If this is in response to a Release/Decline, clean up and return. */
c8bb8f
-	if (client->state == S_STOPPED) {
c8bb8f
-		if (client->active_lease == NULL)
c8bb8f
-			return;
c8bb8f
+	if ((client->state == S_STOPPED) ||
c8bb8f
+	    (client->state == S_DECLINED)) {
c8bb8f
+
c8bb8f
+		if (client->active_lease != NULL) {
c8bb8f
+			dhc6_lease_destroy(&client->active_lease, MDL);
c8bb8f
+			client->active_lease = NULL;
c8bb8f
+			/* We should never wait for nothing!? */
c8bb8f
+			if (stopping_finished())
c8bb8f
+				exit(0);
c8bb8f
+		}
c8bb8f
+
c8bb8f
+		if (client->state == S_DECLINED)
c8bb8f
+			start_init6(client);
c8bb8f
 
c8bb8f
-		dhc6_lease_destroy(&client->active_lease, MDL);
c8bb8f
-		client->active_lease = NULL;
c8bb8f
-		/* We should never wait for nothing!? */
c8bb8f
-		if (stopping_finished())
c8bb8f
-			exit(0);
c8bb8f
 		return;
c8bb8f
 	}
c8bb8f
 
c8bb8f
@@ -4342,7 +4353,11 @@ start_bound(struct client_state *client)
c8bb8f
 			dhc6_marshall_values("new_", client, lease, ia, addr);
c8bb8f
 			script_write_requested6(client);
c8bb8f
 
c8bb8f
-			script_go(client);
c8bb8f
+			// when script returns 3, DAD failed
c8bb8f
+			if (script_go(client) == 3) {
c8bb8f
+				start_decline6(client);
c8bb8f
+				return;
c8bb8f
+			}
c8bb8f
 		}
c8bb8f
 
c8bb8f
 		/* XXX: maybe we should loop on the old values instead? */
c8bb8f
@@ -4390,6 +4405,149 @@ start_bound(struct client_state *client)
c8bb8f
 	dhc6_check_times(client);
c8bb8f
 }
c8bb8f
 
c8bb8f
+/*
c8bb8f
+ * Decline addresses.
c8bb8f
+ */
c8bb8f
+void
c8bb8f
+start_decline6(struct client_state *client)
c8bb8f
+{
c8bb8f
+	/* Cancel any pending transmissions */
c8bb8f
+	cancel_timeout(do_confirm6, client);
c8bb8f
+	cancel_timeout(do_select6, client);
c8bb8f
+	cancel_timeout(do_refresh6, client);
c8bb8f
+	cancel_timeout(do_release6, client);
c8bb8f
+	cancel_timeout(do_decline6, client);
c8bb8f
+	client->state = S_DECLINED;
c8bb8f
+
c8bb8f
+	if (client->active_lease == NULL)
c8bb8f
+		return;
c8bb8f
+
c8bb8f
+	/* Set timers per RFC3315 section 18.1.7. */
c8bb8f
+	client->IRT = DEC_TIMEOUT * 100;
c8bb8f
+	client->MRT = 0;
c8bb8f
+	client->MRC = DEC_MAX_RC;
c8bb8f
+	client->MRD = 0;
c8bb8f
+
c8bb8f
+	dhc6_retrans_init(client);
c8bb8f
+	client->v6_handler = reply_handler;
c8bb8f
+
c8bb8f
+	client->refresh_type = DHCPV6_DECLINE;
c8bb8f
+	do_decline6(client);
c8bb8f
+}
c8bb8f
+
c8bb8f
+/*
c8bb8f
+ * do_decline6() creates a Decline packet and transmits it.
c8bb8f
+ */
c8bb8f
+static void
c8bb8f
+do_decline6(void *input)
c8bb8f
+{
c8bb8f
+	struct client_state *client;
c8bb8f
+	struct data_string ds;
c8bb8f
+	int send_ret;
c8bb8f
+	struct timeval elapsed, tv;
c8bb8f
+
c8bb8f
+	client = input;
c8bb8f
+
c8bb8f
+	if ((client->active_lease == NULL) || !active_prefix(client))
c8bb8f
+		return;
c8bb8f
+
c8bb8f
+	if ((client->MRC != 0) && (client->txcount > client->MRC))  {
c8bb8f
+		log_info("Max retransmission count exceeded.");
c8bb8f
+		goto decline_done;
c8bb8f
+	}
c8bb8f
+
c8bb8f
+	/*
c8bb8f
+	 * Start_time starts at the first transmission.
c8bb8f
+	 */
c8bb8f
+	if (client->txcount == 0) {
c8bb8f
+		client->start_time.tv_sec = cur_tv.tv_sec;
c8bb8f
+		client->start_time.tv_usec = cur_tv.tv_usec;
c8bb8f
+	}
c8bb8f
+
c8bb8f
+	/* elapsed = cur - start */
c8bb8f
+	elapsed.tv_sec = cur_tv.tv_sec - client->start_time.tv_sec;
c8bb8f
+	elapsed.tv_usec = cur_tv.tv_usec - client->start_time.tv_usec;
c8bb8f
+	if (elapsed.tv_usec < 0) {
c8bb8f
+		elapsed.tv_sec -= 1;
c8bb8f
+		elapsed.tv_usec += 1000000;
c8bb8f
+	}
c8bb8f
+
c8bb8f
+	memset(&ds, 0, sizeof(ds));
c8bb8f
+	if (!buffer_allocate(&ds.buffer, 4, MDL)) {
c8bb8f
+		log_error("Unable to allocate memory for Decline.");
c8bb8f
+		goto decline_done;
c8bb8f
+	}
c8bb8f
+
c8bb8f
+	ds.data = ds.buffer->data;
c8bb8f
+	ds.len = 4;
c8bb8f
+	ds.buffer->data[0] = DHCPV6_DECLINE;
c8bb8f
+	memcpy(ds.buffer->data + 1, client->dhcpv6_transaction_id, 3);
c8bb8f
+
c8bb8f
+	/* Form an elapsed option. */
c8bb8f
+	/* Maximum value is 65535 1/100s coded as 0xffff. */
c8bb8f
+	if ((elapsed.tv_sec < 0) || (elapsed.tv_sec > 655) ||
c8bb8f
+	    ((elapsed.tv_sec == 655) && (elapsed.tv_usec > 350000))) {
c8bb8f
+		client->elapsed = 0xffff;
c8bb8f
+	} else {
c8bb8f
+		client->elapsed = elapsed.tv_sec * 100;
c8bb8f
+		client->elapsed += elapsed.tv_usec / 10000;
c8bb8f
+	}
c8bb8f
+
c8bb8f
+	client->elapsed = htons(client->elapsed);
c8bb8f
+
c8bb8f
+	log_debug("XMT: Forming Decline.");
c8bb8f
+	make_client6_options(client, &client->sent_options,
c8bb8f
+			     client->active_lease, DHCPV6_DECLINE);
c8bb8f
+	dhcpv6_universe.encapsulate(&ds, NULL, NULL, client, NULL,
c8bb8f
+				    client->sent_options, &global_scope,
c8bb8f
+				    &dhcpv6_universe);
c8bb8f
+
c8bb8f
+	/* Append IA's (but don't release temporary addresses). */
c8bb8f
+	if (wanted_ia_na &&
c8bb8f
+	    dhc6_add_ia_na(client, &ds, client->active_lease,
c8bb8f
+			   DHCPV6_DECLINE) != ISC_R_SUCCESS) {
c8bb8f
+		data_string_forget(&ds, MDL);
c8bb8f
+		goto decline_done;
c8bb8f
+	}
c8bb8f
+	if (wanted_ia_pd &&
c8bb8f
+	    dhc6_add_ia_pd(client, &ds, client->active_lease,
c8bb8f
+			   DHCPV6_DECLINE) != ISC_R_SUCCESS) {
c8bb8f
+		data_string_forget(&ds, MDL);
c8bb8f
+		goto decline_done;
c8bb8f
+	}
c8bb8f
+
c8bb8f
+	/* Transmit and wait. */
c8bb8f
+	log_info("XMT: Decline on %s, interval %ld0ms.",
c8bb8f
+		 client->name ? client->name : client->interface->name,
c8bb8f
+		 (long int)client->RT);
c8bb8f
+
c8bb8f
+	send_ret = send_packet6(client->interface, ds.data, ds.len,
c8bb8f
+				&DHCPv6DestAddr);
c8bb8f
+	if (send_ret != ds.len) {
c8bb8f
+		log_error("dhc6: sendpacket6() sent %d of %d bytes",
c8bb8f
+			  send_ret, ds.len);
c8bb8f
+	}
c8bb8f
+
c8bb8f
+	data_string_forget(&ds, MDL);
c8bb8f
+
c8bb8f
+	/* Wait RT */
c8bb8f
+	tv.tv_sec = cur_tv.tv_sec + client->RT / 100;
c8bb8f
+	tv.tv_usec = cur_tv.tv_usec + (client->RT % 100) * 10000;
c8bb8f
+	if (tv.tv_usec >= 1000000) {
c8bb8f
+		tv.tv_sec += 1;
c8bb8f
+		tv.tv_usec -= 1000000;
c8bb8f
+	}
c8bb8f
+	add_timeout(&tv, do_decline6, client, NULL, NULL);
c8bb8f
+	dhc6_retrans_advance(client);
c8bb8f
+	return;
c8bb8f
+
c8bb8f
+decline_done:
c8bb8f
+	dhc6_lease_destroy(&client->active_lease, MDL);
c8bb8f
+	client->active_lease = NULL;
c8bb8f
+	start_init6(client);
c8bb8f
+	return;
c8bb8f
+}
c8bb8f
+
c8bb8f
 /* While bound, ignore packets.  In the future we'll want to answer
c8bb8f
  * Reconfigure-Request messages and the like.
c8bb8f
  */