Allow trailing '*' wildcard in interface names.
diff --git a/CHANGELOG b/CHANGELOG
index 854992b..48fab50 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -48,8 +48,11 @@
Don't erroneously reject some option names in --dhcp-match
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
Fix regression which broke forwarding of queries sent via
TCP which are not for A and AAAA and which were directed to
diff --git a/man/dnsmasq.8 b/man/dnsmasq.8
index bb19b37..f46ae52 100644
--- a/man/dnsmasq.8
+++ b/man/dnsmasq.8
@@ -171,7 +171,12 @@
.B --interface
or
.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
.B \-I, --except-interface=<interface name>
Do not listen on the specified interface. Note that the order of
diff --git a/src/dhcp-common.c b/src/dhcp-common.c
index 3f21267..8ddec58 100644
--- a/src/dhcp-common.c
+++ b/src/dhcp-common.c
@@ -714,8 +714,7 @@
template = p;
p += sprintf(p, ", ");
- sprintf(p, "template for %s%s", context->template_interface,
- (context->flags & CONTEXT_WILDCARD) ? "*" : "");
+ sprintf(p, "template for %s", context->template_interface);
}
#endif
diff --git a/src/dhcp.c b/src/dhcp.c
index 5874e66..6b8b803 100644
--- a/src/dhcp.c
+++ b/src/dhcp.c
@@ -252,7 +252,7 @@
}
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;
/* unlinked contexts are marked by context->current == context */
diff --git a/src/dhcp6.c b/src/dhcp6.c
index 62a6309..7d7d358 100644
--- a/src/dhcp6.c
+++ b/src/dhcp6.c
@@ -120,11 +120,11 @@
return;
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;
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;
parm.current = NULL;
@@ -153,7 +153,7 @@
{
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;
if (!tmp && !parm.addr_match)
@@ -530,9 +530,7 @@
}
}
- 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)))
+ else if (addr6part(local) == addr6part(&template->start6) && wildcard_match(template->template_interface, ifrn_name))
{
start6 = *local;
setaddr6part(&start6, addr6part(&template->start6));
diff --git a/src/dnsmasq.h b/src/dnsmasq.h
index 5d1cf3a..482af22 100644
--- a/src/dnsmasq.h
+++ b/src/dnsmasq.h
@@ -721,9 +721,8 @@
#define CONTEXT_CONSTRUCTED 2048
#define CONTEXT_GC 4096
#define CONTEXT_RA 8192
-#define CONTEXT_WILDCARD 16384
+#define CONTEXT_CONF_USED 16384
#define CONTEXT_USED 32768
-#define CONTEXT_CONF_USED 65536
struct ping_result {
struct in_addr addr;
@@ -980,6 +979,8 @@
void bump_maxfd(int fd, int *max);
int read_write(int fd, unsigned char *packet, int size, int rw);
+int wildcard_match(const char* wildcard, const char* match);
+
/* log.c */
void die(char *message, char *arg1, int exit_code);
int log_start(struct passwd *ent_pw, int errfd);
diff --git a/src/network.c b/src/network.c
index 6b7e27a..792914b 100644
--- a/src/network.c
+++ b/src/network.c
@@ -123,7 +123,7 @@
ret = 0;
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;
if (addr)
@@ -143,7 +143,7 @@
}
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;
@@ -291,7 +291,7 @@
}
else
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;
dhcp_ok = 0;
diff --git a/src/option.c b/src/option.c
index b71fd2a..8caa333 100644
--- a/src/option.c
+++ b/src/option.c
@@ -2375,11 +2375,6 @@
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;
}
diff --git a/src/radv.c b/src/radv.c
index 2dc533d..a708758 100644
--- a/src/radv.c
+++ b/src/radv.c
@@ -158,7 +158,7 @@
return;
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;
if (packet[1] != 0)
@@ -533,7 +533,7 @@
{
struct iname *tmp;
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;
if (!tmp)
send_ra(now, param.iface, interface, NULL);
diff --git a/src/tftp.c b/src/tftp.c
index a3d111e..960b1ee 100644
--- a/src/tftp.c
+++ b/src/tftp.c
@@ -209,7 +209,7 @@
#ifdef HAVE_DHCP
/* allowed interfaces are the same as for DHCP */
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;
#endif
diff --git a/src/util.c b/src/util.c
index 360a85f..848e01b 100644
--- a/src/util.c
+++ b/src/util.c
@@ -581,3 +581,20 @@
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;
+}