From 771287be11940a08b8773895e9ea4c92209bff38 Mon Sep 17 00:00:00 2001 From: Simon Kelley Date: Sun, 30 Dec 2012 17:38:09 +0000 Subject: [PATCH] Wildcards in dhcp-range constructors --- src/dhcp-common.c | 11 ++++++++--- src/dhcp6.c | 5 +++-- src/dnsmasq.h | 2 +- src/option.c | 5 +++++ 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/dhcp-common.c b/src/dhcp-common.c index e0bb1d4..9c58603 100644 --- a/src/dhcp-common.c +++ b/src/dhcp-common.c @@ -712,14 +712,19 @@ void log_context(int family, struct dhcp_context *context) #ifdef HAVE_DHCP6 if (context->flags & CONTEXT_CONSTRUCTED) { - n = p; - p += sprintf(p, ", constructed for %s", context->template_interface); + char ifrn_name[IFNAMSIZ]; + if (indextoname(daemon->doing_dhcp6 ? daemon->dhcp6fd : daemon->icmp6fd, context->if_index, ifrn_name)) + { + n = p; + p += sprintf(p, ", constructed for %s", ifrn_name); + } } if (context->flags & CONTEXT_TEMPLATE) { n = p; - p += sprintf(p, ", template for %s", context->template_interface); + p += sprintf(p, ", template for %s%s", context->template_interface, + (context->flags & CONTEXT_WILDCARD) ? "*" : ""); } #endif diff --git a/src/dhcp6.c b/src/dhcp6.c index f708af5..8f2e053 100644 --- a/src/dhcp6.c +++ b/src/dhcp6.c @@ -531,8 +531,9 @@ static int construct_worker(struct in6_addr *local, int prefix, } } - else if (strcmp(ifrn_name, template->template_interface) == 0 && - addr6part(local) == addr6part(&template->start6)) + else if (addr6part(local) == addr6part(&template->start6) && + strncmp(template->template_interface, ifrn_name, strlen(template->template_interface)) == 0 && + (strlen(template->template_interface) == strlen(ifrn_name) || (template->flags & CONTEXT_WILDCARD))) { start6 = *local; setaddr6part(&start6, addr6part(&template->start6)); diff --git a/src/dnsmasq.h b/src/dnsmasq.h index 3181db6..5eadaa1 100644 --- a/src/dnsmasq.h +++ b/src/dnsmasq.h @@ -706,7 +706,7 @@ struct dhcp_context { #define CONTEXT_CONSTRUCTED 2048 #define CONTEXT_GC 4096 #define CONTEXT_RA 8192 - +#define CONTEXT_WILDCARD 16384 struct ping_result { struct in_addr addr; diff --git a/src/option.c b/src/option.c index 9757171..02ebf48 100644 --- a/src/option.c +++ b/src/option.c @@ -2291,6 +2291,11 @@ static int one_opt(int option, char *arg, char *errstr, char *gen_err, int comma new->flags |= CONTEXT_DHCP; else if (strstr(a[leasepos], "constructor:") == a[leasepos]) { + if (a[leasepos][strlen(a[leasepos])-1] == '*') + { + a[leasepos][strlen(a[leasepos])-1] = 0; + new->flags |= CONTEXT_WILDCARD; + } new->template_interface = opt_string_alloc(a[leasepos] + 12); new->flags |= CONTEXT_TEMPLATE; }