41ed8fd
diff -up dhcp-4.2.0/server/dhcpv6.c.noprefixavail dhcp-4.2.0/server/dhcpv6.c
41ed8fd
--- dhcp-4.2.0/server/dhcpv6.c.noprefixavail	2010-10-07 13:48:45.000000000 +0200
41ed8fd
+++ dhcp-4.2.0/server/dhcpv6.c	2010-10-13 11:00:25.000000000 +0200
41ed8fd
@@ -1134,7 +1134,7 @@ try_client_v6_prefix(struct iasubopt **p
41ed8fd
 		return DHCP_R_INVALIDARG;
41ed8fd
 	}
41ed8fd
 	tmp_plen = (int) requested_pref->data[0];
41ed8fd
-	if ((tmp_plen < 3) || (tmp_plen > 128)) {
41ed8fd
+	if ((tmp_plen < 3) || (tmp_plen > 128) ||((int)tmp_plen != pool->units)) {
41ed8fd
 		return ISC_R_FAILURE;
41ed8fd
 	}
41ed8fd
 	memcpy(&tmp_pref, requested_pref->data + 1, sizeof(tmp_pref));
41ed8fd
@@ -1147,9 +1147,8 @@ try_client_v6_prefix(struct iasubopt **p
41ed8fd
 		return ISC_R_FAILURE;
41ed8fd
 	}
41ed8fd
 
41ed8fd
-	if (((int)tmp_plen != pool->units) ||
41ed8fd
-	    !ipv6_in_pool(&tmp_pref, pool)) {
41ed8fd
-		return ISC_R_FAILURE;
41ed8fd
+	if (!ipv6_in_pool(&tmp_pref, pool)) {
41ed8fd
+		return ISC_R_ADDRNOTAVAIL;
41ed8fd
 	}
41ed8fd
 
41ed8fd
 	if (prefix6_exists(pool, &tmp_pref, tmp_plen)) {
41ed8fd
@@ -1409,13 +1408,6 @@ lease_to_client(struct data_string *repl
41ed8fd
 		if ((status != ISC_R_SUCCESS) &&
41ed8fd
 		    (status != ISC_R_NORESOURCES))
41ed8fd
 			goto exit;
41ed8fd
-
41ed8fd
-		/*
41ed8fd
-		 * If any prefix cannot be given to any IA_PD, then
41ed8fd
-		 * set the NoPrefixAvail status code.
41ed8fd
-		 */
41ed8fd
-		if (reply.client_resources == 0)
41ed8fd
-			no_resources_avail = ISC_TRUE;
41ed8fd
 	}
41ed8fd
 
41ed8fd
 	/*
41ed8fd
@@ -1549,36 +1541,6 @@ lease_to_client(struct data_string *repl
41ed8fd
 					       reply.opt_state, reply.packet,
41ed8fd
 					       required_opts_NAA,
41ed8fd
 					       NULL);
41ed8fd
-	} else if (no_resources_avail && (reply.ia_count == 0) &&
41ed8fd
-		   (reply.packet->dhcpv6_msg_type == DHCPV6_SOLICIT))
41ed8fd
-	{
41ed8fd
-		/* Set the NoPrefixAvail status code. */
41ed8fd
-		if (!set_status_code(STATUS_NoPrefixAvail,
41ed8fd
-				     "No prefixes available for this "
41ed8fd
-				     "interface.", reply.opt_state)) {
41ed8fd
-			log_error("lease_to_client: Unable to set "
41ed8fd
-				  "NoPrefixAvail status code.");
41ed8fd
-			goto exit;
41ed8fd
-		}
41ed8fd
-
41ed8fd
-		/* Rewind the cursor to the start. */
41ed8fd
-		reply.cursor = REPLY_OPTIONS_INDEX;
41ed8fd
-
41ed8fd
-		/*
41ed8fd
-		 * Produce an advertise that includes only:
41ed8fd
-		 *
41ed8fd
-		 * Status code.
41ed8fd
-		 * Server DUID.
41ed8fd
-		 * Client DUID.
41ed8fd
-		 */
41ed8fd
-		reply.buf.reply.msg_type = DHCPV6_ADVERTISE;
41ed8fd
-		reply.cursor += store_options6((char *)reply.buf.data +
41ed8fd
-							reply.cursor,
41ed8fd
-					       sizeof(reply.buf) -
41ed8fd
-					       		reply.cursor,
41ed8fd
-					       reply.opt_state, reply.packet,
41ed8fd
-					       required_opts_NAA,
41ed8fd
-					       NULL);
41ed8fd
 	} else {
41ed8fd
 		/*
41ed8fd
 		 * Having stored the client's IA's, store any options that
41ed8fd
@@ -2793,16 +2755,18 @@ find_client_temporaries(struct reply_sta
41ed8fd
  */
41ed8fd
 static isc_result_t
41ed8fd
 reply_process_try_addr(struct reply_state *reply, struct iaddr *addr) {
41ed8fd
-	isc_result_t status = ISC_R_NORESOURCES;
41ed8fd
+	isc_result_t status = ISC_R_ADDRNOTAVAIL;
41ed8fd
 	struct ipv6_pool *pool;
41ed8fd
 	int i;
41ed8fd
 	struct data_string data_addr;
41ed8fd
 
41ed8fd
 	if ((reply == NULL) || (reply->shared == NULL) ||
41ed8fd
-	    (reply->shared->ipv6_pools == NULL) || (addr == NULL) ||
41ed8fd
-	    (reply->lease != NULL))
41ed8fd
+	    (addr == NULL) || (reply->lease != NULL))
41ed8fd
 		return DHCP_R_INVALIDARG;
41ed8fd
 
41ed8fd
+	if (reply->shared->ipv6_pools == NULL)
41ed8fd
+		return ISC_R_ADDRNOTAVAIL;
41ed8fd
+
41ed8fd
 	memset(&data_addr, 0, sizeof(data_addr));
41ed8fd
 	data_addr.len = addr->len;
41ed8fd
 	data_addr.data = addr->iabuf;
41ed8fd
@@ -3314,7 +3278,9 @@ reply_process_ia_pd(struct reply_state *
41ed8fd
 		if (status == ISC_R_CANCELED)
41ed8fd
 			break;
41ed8fd
 
41ed8fd
-		if ((status != ISC_R_SUCCESS) && (status != ISC_R_ADDRINUSE))
41ed8fd
+		if ((status != ISC_R_SUCCESS) &&
41ed8fd
+		    (status != ISC_R_ADDRINUSE) &&
41ed8fd
+		    (status != ISC_R_ADDRNOTAVAIL))
41ed8fd
 			goto cleanup;
41ed8fd
 	}
41ed8fd
 
41ed8fd
@@ -3594,7 +3560,8 @@ reply_process_prefix(struct reply_state 
41ed8fd
 
41ed8fd
 			/* Either error out or skip this prefix. */
41ed8fd
 			if ((status != ISC_R_SUCCESS) && 
41ed8fd
-			    (status != ISC_R_ADDRINUSE)) 
41ed8fd
+			    (status != ISC_R_ADDRINUSE) &&
41ed8fd
+			    (status != ISC_R_ADDRNOTAVAIL))
41ed8fd
 				goto cleanup;
41ed8fd
 
41ed8fd
 			if (reply->lease == NULL) {
41ed8fd
@@ -3773,16 +3740,18 @@ prefix_is_owned(struct reply_state *repl
41ed8fd
 static isc_result_t
41ed8fd
 reply_process_try_prefix(struct reply_state *reply,
41ed8fd
 			 struct iaddrcidrnet *pref) {
41ed8fd
-	isc_result_t status = ISC_R_NORESOURCES;
41ed8fd
+	isc_result_t status = ISC_R_ADDRNOTAVAIL;
41ed8fd
 	struct ipv6_pool *pool;
41ed8fd
 	int i;
41ed8fd
 	struct data_string data_pref;
41ed8fd
 
41ed8fd
 	if ((reply == NULL) || (reply->shared == NULL) ||
41ed8fd
-	    (reply->shared->ipv6_pools == NULL) || (pref == NULL) ||
41ed8fd
-	    (reply->lease != NULL))
41ed8fd
+	    (pref == NULL) || (reply->lease != NULL))
41ed8fd
 		return DHCP_R_INVALIDARG;
41ed8fd
 
41ed8fd
+	if (reply->shared->ipv6_pools == NULL)
41ed8fd
+		return ISC_R_ADDRNOTAVAIL;
41ed8fd
+
41ed8fd
 	memset(&data_pref, 0, sizeof(data_pref));
41ed8fd
 	data_pref.len = 17;
41ed8fd
 	if (!buffer_allocate(&data_pref.buffer, data_pref.len, MDL)) {