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