Commit 49333cbd authored by Simon Kelley's avatar Simon Kelley

Allow trailing '*' wildcard in interface names.

parent de92b479
...@@ -48,8 +48,11 @@ version 2.66 ...@@ -48,8 +48,11 @@ version 2.66
Don't erroneously reject some option names in --dhcp-match Don't erroneously reject some option names in --dhcp-match
options. Thnaks to Benedikt Hochstrasser for the bug report. options. Thnaks to Benedikt Hochstrasser for the bug report.
Allow a trailing '*' wildcard in all interface-name
configurations. Thanks to Christian Parpart for the patch.
version 2.65 version 2.65
Fix regression which broke forwarding of queries sent via Fix regression which broke forwarding of queries sent via
TCP which are not for A and AAAA and which were directed to TCP which are not for A and AAAA and which were directed to
......
...@@ -171,7 +171,12 @@ options. IP alias interfaces (eg "eth1:0") cannot be used with ...@@ -171,7 +171,12 @@ options. IP alias interfaces (eg "eth1:0") cannot be used with
.B --interface .B --interface
or or
.B --except-interface .B --except-interface
options, use --listen-address instead. options, use --listen-address instead. A simple wildcard, consisting
of a trailing '*', can be used in
.B \--interface
and
.B \--except-interface
options.
.TP .TP
.B \-I, --except-interface=<interface name> .B \-I, --except-interface=<interface name>
Do not listen on the specified interface. Note that the order of Do not listen on the specified interface. Note that the order of
......
...@@ -714,8 +714,7 @@ void log_context(int family, struct dhcp_context *context) ...@@ -714,8 +714,7 @@ void log_context(int family, struct dhcp_context *context)
template = p; template = p;
p += sprintf(p, ", "); p += sprintf(p, ", ");
sprintf(p, "template for %s%s", context->template_interface, sprintf(p, "template for %s", context->template_interface);
(context->flags & CONTEXT_WILDCARD) ? "*" : "");
} }
#endif #endif
......
...@@ -252,7 +252,7 @@ void dhcp_packet(time_t now, int pxe_fd) ...@@ -252,7 +252,7 @@ void dhcp_packet(time_t now, int pxe_fd)
} }
for (tmp = daemon->dhcp_except; tmp; tmp = tmp->next) for (tmp = daemon->dhcp_except; tmp; tmp = tmp->next)
if (tmp->name && (strcmp(tmp->name, ifr.ifr_name) == 0)) if (tmp->name && wildcard_match(tmp->name, ifr.ifr_name))
return; return;
/* unlinked contexts are marked by context->current == context */ /* unlinked contexts are marked by context->current == context */
......
...@@ -120,11 +120,11 @@ void dhcp6_packet(time_t now) ...@@ -120,11 +120,11 @@ void dhcp6_packet(time_t now)
return; return;
for (tmp = daemon->if_except; tmp; tmp = tmp->next) for (tmp = daemon->if_except; tmp; tmp = tmp->next)
if (tmp->name && (strcmp(tmp->name, ifr.ifr_name) == 0)) if (tmp->name && wildcard_match(tmp->name, ifr.ifr_name))
return; return;
for (tmp = daemon->dhcp_except; tmp; tmp = tmp->next) for (tmp = daemon->dhcp_except; tmp; tmp = tmp->next)
if (tmp->name && (strcmp(tmp->name, ifr.ifr_name) == 0)) if (tmp->name && wildcard_match(tmp->name, ifr.ifr_name))
return; return;
parm.current = NULL; parm.current = NULL;
...@@ -153,7 +153,7 @@ void dhcp6_packet(time_t now) ...@@ -153,7 +153,7 @@ void dhcp6_packet(time_t now)
{ {
for (tmp = daemon->if_names; tmp; tmp = tmp->next) for (tmp = daemon->if_names; tmp; tmp = tmp->next)
if (tmp->name && (strcmp(tmp->name, ifr.ifr_name) == 0)) if (tmp->name && wildcard_match(tmp->name, ifr.ifr_name))
break; break;
if (!tmp && !parm.addr_match) if (!tmp && !parm.addr_match)
...@@ -530,9 +530,7 @@ static int construct_worker(struct in6_addr *local, int prefix, ...@@ -530,9 +530,7 @@ static int construct_worker(struct in6_addr *local, int prefix,
} }
} }
else if (addr6part(local) == addr6part(&template->start6) && else if (addr6part(local) == addr6part(&template->start6) && wildcard_match(template->template_interface, ifrn_name))
strncmp(template->template_interface, ifrn_name, strlen(template->template_interface)) == 0 &&
(strlen(template->template_interface) == strlen(ifrn_name) || (template->flags & CONTEXT_WILDCARD)))
{ {
start6 = *local; start6 = *local;
setaddr6part(&start6, addr6part(&template->start6)); setaddr6part(&start6, addr6part(&template->start6));
......
...@@ -721,9 +721,8 @@ struct dhcp_context { ...@@ -721,9 +721,8 @@ struct dhcp_context {
#define CONTEXT_CONSTRUCTED 2048 #define CONTEXT_CONSTRUCTED 2048
#define CONTEXT_GC 4096 #define CONTEXT_GC 4096
#define CONTEXT_RA 8192 #define CONTEXT_RA 8192
#define CONTEXT_WILDCARD 16384 #define CONTEXT_CONF_USED 16384
#define CONTEXT_USED 32768 #define CONTEXT_USED 32768
#define CONTEXT_CONF_USED 65536
struct ping_result { struct ping_result {
struct in_addr addr; struct in_addr addr;
...@@ -980,6 +979,8 @@ char *print_mac(char *buff, unsigned char *mac, int len); ...@@ -980,6 +979,8 @@ char *print_mac(char *buff, unsigned char *mac, int len);
void bump_maxfd(int fd, int *max); void bump_maxfd(int fd, int *max);
int read_write(int fd, unsigned char *packet, int size, int rw); int read_write(int fd, unsigned char *packet, int size, int rw);
int wildcard_match(const char* wildcard, const char* match);
/* log.c */ /* log.c */
void die(char *message, char *arg1, int exit_code); void die(char *message, char *arg1, int exit_code);
int log_start(struct passwd *ent_pw, int errfd); int log_start(struct passwd *ent_pw, int errfd);
......
...@@ -123,7 +123,7 @@ int iface_check(int family, struct all_addr *addr, char *name, int *auth) ...@@ -123,7 +123,7 @@ int iface_check(int family, struct all_addr *addr, char *name, int *auth)
ret = 0; ret = 0;
for (tmp = daemon->if_names; tmp; tmp = tmp->next) for (tmp = daemon->if_names; tmp; tmp = tmp->next)
if (tmp->name && (strcmp(tmp->name, name) == 0)) if (tmp->name && wildcard_match(tmp->name, name))
ret = tmp->used = 1; ret = tmp->used = 1;
if (addr) if (addr)
...@@ -143,7 +143,7 @@ int iface_check(int family, struct all_addr *addr, char *name, int *auth) ...@@ -143,7 +143,7 @@ int iface_check(int family, struct all_addr *addr, char *name, int *auth)
} }
for (tmp = daemon->if_except; tmp; tmp = tmp->next) for (tmp = daemon->if_except; tmp; tmp = tmp->next)
if (tmp->name && (strcmp(tmp->name, name) == 0)) if (tmp->name && wildcard_match(tmp->name, name))
ret = 0; ret = 0;
...@@ -291,7 +291,7 @@ static int iface_allowed(struct irec **irecp, int if_index, ...@@ -291,7 +291,7 @@ static int iface_allowed(struct irec **irecp, int if_index,
} }
else else
for (tmp = daemon->dhcp_except; tmp; tmp = tmp->next) for (tmp = daemon->dhcp_except; tmp; tmp = tmp->next)
if (tmp->name && (strcmp(tmp->name, ifr.ifr_name) == 0)) if (tmp->name && wildcard_match(tmp->name, ifr.ifr_name))
{ {
tftp_ok = 0; tftp_ok = 0;
dhcp_ok = 0; dhcp_ok = 0;
......
...@@ -2375,11 +2375,6 @@ static int one_opt(int option, char *arg, char *errstr, char *gen_err, int comma ...@@ -2375,11 +2375,6 @@ static int one_opt(int option, char *arg, char *errstr, char *gen_err, int comma
new->flags |= CONTEXT_DHCP; new->flags |= CONTEXT_DHCP;
else if (strstr(a[leasepos], "constructor:") == a[leasepos]) 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->template_interface = opt_string_alloc(a[leasepos] + 12);
new->flags |= CONTEXT_TEMPLATE; new->flags |= CONTEXT_TEMPLATE;
} }
......
...@@ -158,7 +158,7 @@ void icmp6_packet(time_t now) ...@@ -158,7 +158,7 @@ void icmp6_packet(time_t now)
return; return;
for (tmp = daemon->dhcp_except; tmp; tmp = tmp->next) for (tmp = daemon->dhcp_except; tmp; tmp = tmp->next)
if (tmp->name && (strcmp(tmp->name, interface) == 0)) if (tmp->name && wildcard_match(tmp->name, interface))
return; return;
if (packet[1] != 0) if (packet[1] != 0)
...@@ -533,7 +533,7 @@ time_t periodic_ra(time_t now) ...@@ -533,7 +533,7 @@ time_t periodic_ra(time_t now)
{ {
struct iname *tmp; struct iname *tmp;
for (tmp = daemon->dhcp_except; tmp; tmp = tmp->next) for (tmp = daemon->dhcp_except; tmp; tmp = tmp->next)
if (tmp->name && (strcmp(tmp->name, interface) == 0)) if (tmp->name && wildcard_match(tmp->name, interface))
break; break;
if (!tmp) if (!tmp)
send_ra(now, param.iface, interface, NULL); send_ra(now, param.iface, interface, NULL);
......
...@@ -209,7 +209,7 @@ void tftp_request(struct listener *listen, time_t now) ...@@ -209,7 +209,7 @@ void tftp_request(struct listener *listen, time_t now)
#ifdef HAVE_DHCP #ifdef HAVE_DHCP
/* allowed interfaces are the same as for DHCP */ /* allowed interfaces are the same as for DHCP */
for (tmp = daemon->dhcp_except; tmp; tmp = tmp->next) for (tmp = daemon->dhcp_except; tmp; tmp = tmp->next)
if (tmp->name && (strcmp(tmp->name, name) == 0)) if (tmp->name && wildcard_match(tmp->name, name))
return; return;
#endif #endif
......
...@@ -581,3 +581,20 @@ int read_write(int fd, unsigned char *packet, int size, int rw) ...@@ -581,3 +581,20 @@ int read_write(int fd, unsigned char *packet, int size, int rw)
return 1; return 1;
} }
/* Basically match a string value against a wildcard pattern. */
int wildcard_match(const char* wildcard, const char* match)
{
while (*wildcard && *match)
{
if (*wildcard == '*')
return 1;
if (*wildcard != *match)
return 0;
++wildcard;
++match;
}
return *wildcard == *match;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment