summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNeil Jerram <nj@metaswitch.com>2014-06-11 21:22:40 +0100
committerSimon Kelley <simon@thekelleys.org.uk>2014-06-11 21:22:40 +0100
commit70772c909199ad6701dc25593bc185938fa4cd23 (patch)
tree02699f8dc9f7d52a7b31d1ee6057c14cd8c92371
parent10d8540f6202aa97bda542edef8169c7aa3b033c (diff)
downloaddnsmasq-70772c909199ad6701dc25593bc185938fa4cd23.tar.gz
Allow wildcard aliases in --bridge-interface option
This is useful when using dnsmasq as DHCP server for a set of VMs whose data is routed by the host instead of being bridged. In this scenario: - There is an unbounded set of TAP interfaces that have no IP address at the host end. - DHCP allocation is done from an IPv4 address range associated with a dummy interface. - We run dnsmasq with --interface dummy --interface tap* --bind-dynamic, so that it listens on all the TAP interfaces, and --bridge-interface=dummy,tap*, so that it will allocate IP addresses via the TAP interfaces from the range associated with the dummy interface.
-rw-r--r--man/dnsmasq.81
-rw-r--r--man/fr/dnsmasq.82
-rw-r--r--src/dhcp.c2
-rw-r--r--src/dnsmasq.h1
-rw-r--r--src/util.c19
5 files changed, 23 insertions, 2 deletions
diff --git a/man/dnsmasq.8 b/man/dnsmasq.8
index f25119d..0530a19 100644
--- a/man/dnsmasq.8
+++ b/man/dnsmasq.8
@@ -1550,6 +1550,7 @@ Treat DHCP request packets arriving at any of the <alias> interfaces
as if they had arrived at <interface>. This option is necessary when
using "old style" bridging on BSD platforms, since
packets arrive at tap interfaces which don't have an IP address.
+A trailing '*' wildcard can be used in each <alias>.
.TP
.B \-s, --domain=<domain>[,<address range>[,local]]
Specifies DNS domains for the DHCP server. Domains may be be given
diff --git a/man/fr/dnsmasq.8 b/man/fr/dnsmasq.8
index 2f329ee..e0d1e9a 100644
--- a/man/fr/dnsmasq.8
+++ b/man/fr/dnsmasq.8
@@ -1659,7 +1659,7 @@ Traiter les requêtes DHCP arrivant sur n'importe laquelle des interfaces <alias
comme si elles arrivaient de l'interface <interface>. Cette option est
nécessaire lors de l'utilisation de pont ethernet "ancien mode" sur plate-forme
BSD, puisque dans ce cas les paquets arrivent sur des interfaces "tap" n'ont
-pas d'adresse IP.
+pas d'adresse IP. Chaque <alias> peut finir avec un simple '*' joker.
.TP
.B \-s, --domain=<domaine>[,<gamme d'adresses>[,local]]
Spécifie le domaine du serveur DHCP. Le domaine peut être donné de manière
diff --git a/src/dhcp.c b/src/dhcp.c
index 9463e23..7acf2c4 100644
--- a/src/dhcp.c
+++ b/src/dhcp.c
@@ -232,7 +232,7 @@ void dhcp_packet(time_t now, int pxe_fd)
for (bridge = daemon->bridges; bridge; bridge = bridge->next)
{
for (alias = bridge->alias; alias; alias = alias->next)
- if (strncmp(ifr.ifr_name, alias->iface, IF_NAMESIZE) == 0)
+ if (wildcard_matchn(alias->iface, ifr.ifr_name, IF_NAMESIZE))
{
if (!(iface_index = if_nametoindex(bridge->iface)))
{
diff --git a/src/dnsmasq.h b/src/dnsmasq.h
index de98956..dfa9773 100644
--- a/src/dnsmasq.h
+++ b/src/dnsmasq.h
@@ -1150,6 +1150,7 @@ 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);
+int wildcard_matchn(const char* wildcard, const char* match, int num);
/* log.c */
void die(char *message, char *arg1, int exit_code);
diff --git a/src/util.c b/src/util.c
index 7c46d40..a503082 100644
--- a/src/util.c
+++ b/src/util.c
@@ -602,3 +602,22 @@ int wildcard_match(const char* wildcard, const char* match)
return *wildcard == *match;
}
+
+/* The same but comparing a maximum of NUM characters, like strncmp. */
+int wildcard_matchn(const char* wildcard, const char* match, int num)
+{
+ while (*wildcard && *match && num)
+ {
+ if (*wildcard == '*')
+ return 1;
+
+ if (*wildcard != *match)
+ return 0;
+
+ ++wildcard;
+ ++match;
+ --num;
+ }
+
+ return (!num) || (*wildcard == *match);
+}