Blob Blame History Raw
From 24b5a5d50bc793f7e218ef6018ad210eab28c686 Mon Sep 17 00:00:00 2001
From: Simon Kelley <simon@thekelleys.org.uk>
Date: Fri, 11 Oct 2013 15:19:28 +0100
Subject: [PATCH 1/1] dhcp-host selection fix for v4/v6

---
 CHANGELOG         |    5 +++++
 src/dhcp-common.c |   35 +++++++++++++++++------------------
 src/rfc1035.c     |   14 +++++++-------
 3 files changed, 29 insertions(+), 25 deletions(-)

diff --git a/src/dhcp-common.c b/src/dhcp-common.c
index 304c47e..5b0756d 100644
--- a/src/dhcp-common.c
+++ b/src/dhcp-common.c
@@ -272,27 +272,26 @@ static int is_config_in_context(struct dhcp_context *context, struct dhcp_config
   if (!context) /* called via find_config() from lease_update_from_configs() */
     return 1; 
 
-  if (!(context->flags & CONTEXT_V6))
-    {
-      if (!(config->flags & CONFIG_ADDR))
-	return 1;
+  if (!(config->flags & (CONFIG_ADDR | CONFIG_ADDR6)))
+    return 1;
+  
+#ifdef HAVE_DHCP6
+  if ((context->flags & CONTEXT_V6) && (config->flags & CONFIG_WILDCARD))
+    return 1;
+#endif
 
-      for (; context; context = context->current)
-	if (is_same_net(config->addr, context->start, context->netmask))
-	  return 1;
-    }
+  for (; context; context = context->current)
 #ifdef HAVE_DHCP6
-  else 
-    {
-      if (!(config->flags & CONFIG_ADDR6) || (config->flags & CONFIG_WILDCARD))
-	return 1;
-      
-      for (; context; context = context->current)
-	if (is_same_net6(&config->addr6, &context->start6, context->prefix))
-      return 1;
-    }
+    if (context->flags & CONTEXT_V6) 
+      {
+	if ((config->flags & CONFIG_ADDR6) && is_same_net6(&config->addr6, &context->start6, context->prefix))
+	  return 1;
+      }
+    else 
 #endif
-  
+      if ((config->flags & CONFIG_ADDR) && is_same_net(config->addr, context->start, context->netmask))
+	return 1;
+
   return 0;
 }