import of dnsmasq-2.22.tar.gz
diff --git a/src/dhcp.c b/src/dhcp.c
index b12215b..63392cb 100644
--- a/src/dhcp.c
+++ b/src/dhcp.c
@@ -206,8 +206,9 @@
 	return; 
     }
   
+  /* unlinked contexts are marked by context->current == context */
   for (context = daemon->dhcp; context; context = context->next)
-    context->current = NULL;
+    context->current = context;
   
 #ifdef HAVE_RTNETLINK
   if (!netlink_process(daemon, iface_index, mess->giaddr, iface_addr, &context))
@@ -381,7 +382,8 @@
 	  if (is_same_net(local, context->start, context->netmask) &&
 	      is_same_net(local, context->end, context->netmask))
 	    {
-	      if (!context->current)
+	      /* link it onto the current chain if we've not seen it before */
+	      if (context->current == context)
 		{
 		  context->router = local;
 		  context->local = local;
@@ -684,6 +686,7 @@
 	{ 
 	  for (config = configs; config; config = config->next)
 	    if ((config->flags & CONFIG_HWADDR) && 
+		config->wildcard_mask == 0 &&
 		memcmp(config->hwaddr, hwaddr, ETHER_ADDR_LEN) == 0)
 	      break;
 	  
@@ -692,6 +695,7 @@
 	      if (!(config = malloc(sizeof(struct dhcp_config))))
 		continue;
 	      config->flags = 0;
+	      config->wildcard_mask = 0;
 	      config->next = configs;
 	      configs = config;
 	    }