Address allocation tweaking - lease outside dhcp-range but in subnet.
diff --git a/src/dhcp6.c b/src/dhcp6.c
index e31456c..4453ddf 100644
--- a/src/dhcp6.c
+++ b/src/dhcp6.c
@@ -323,14 +323,21 @@
   return tmp;
 }
 
-static int is_addr_in_context6(struct dhcp_context *context, struct dhcp_config *config)
+static int is_config_in_context6(struct dhcp_context *context, struct dhcp_config *config)
 {
   if (!context) /* called via find_config() from lease_update_from_configs() */
     return 1; 
-  if (!(config->flags & CONFIG_ADDR6))
+  if (!(config->flags & CONFIG_ADDR6) || is_addr_in_context6(context, &config->addr6))
     return 1;
+  
+  return 0;
+}
+
+
+int is_addr_in_context6(struct dhcp_context *context, struct in6_addr *addr)
+{
   for (; context; context = context->current)
-    if (is_same_net6(&config->addr6, &context->start6, context->prefix))
+    if (is_same_net6(addr, &context->start6, context->prefix))
       return 1;
   
   return 0;
@@ -350,7 +357,7 @@
 	{
 	  if (config->clid_len == duid_len && 
 	      memcmp(config->clid, duid, duid_len) == 0 &&
-	      is_addr_in_context6(context, config))
+	      is_config_in_context6(context, config))
 	    return config;
 	}
     
@@ -358,7 +365,7 @@
     for (config = configs; config; config = config->next)
       if ((config->flags & CONFIG_NAME) && 
           hostname_isequal(config->hostname, hostname) &&
-          is_addr_in_context6(context, config))
+          is_config_in_context6(context, config))
         return config;
 
   return NULL;
diff --git a/src/dnsmasq.h b/src/dnsmasq.h
index 5cbe0e5..98a2327 100644
--- a/src/dnsmasq.h
+++ b/src/dnsmasq.h
@@ -1092,6 +1092,7 @@
 void dhcp6_packet(time_t now);
 int address6_allocate(struct dhcp_context *context,  unsigned char *clid, int clid_len, 
 		      int serial, struct dhcp_netid *netids, struct in6_addr *ans);
+int is_addr_in_context6(struct dhcp_context *context, struct in6_addr *addr);
 struct dhcp_context *address6_available(struct dhcp_context *context, 
 					struct in6_addr *taddr,
 					struct dhcp_netid *netids);
diff --git a/src/lease.c b/src/lease.c
index 5f91bc8..7982476 100644
--- a/src/lease.c
+++ b/src/lease.c
@@ -582,7 +582,7 @@
 	continue;
       
       /* leases on the wrong interface get filtered out here */
-      if (!address6_available(context, (struct in6_addr *)&lease->hwaddr, NULL))
+      if (!is_addr_in_context6(context, (struct in6_addr *)&lease->hwaddr))
 	lease->flags |= LEASE_USED;
     }
 }
diff --git a/src/rfc3315.c b/src/rfc3315.c
index 14cbc66..716aa4a 100644
--- a/src/rfc3315.c
+++ b/src/rfc3315.c
@@ -582,7 +582,6 @@
 		    if (!addrp &&
 			(lease = lease6_find(clid, clid_len, 
 					     ia_type == OPTION6_IA_NA ? LEASE_NA : LEASE_TA, iaid, NULL)) &&
-			address6_available(context, (struct in6_addr *)&lease->hwaddr, tags) &&
 			!config_find_by_address6(daemon->dhcp_conf, (struct in6_addr *)&lease->hwaddr, 128, 0))
 		      addrp = (struct in6_addr *)&lease->hwaddr;