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