summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--man/dnsmasq.82
-rw-r--r--src/dbus.c2
-rw-r--r--src/dnsmasq.h2
-rw-r--r--src/option.c81
4 files changed, 56 insertions, 31 deletions
diff --git a/man/dnsmasq.8 b/man/dnsmasq.8
index a2dde82..6db2477 100644
--- a/man/dnsmasq.8
+++ b/man/dnsmasq.8
@@ -538,7 +538,7 @@ of a server during startup. If name resolution fails, starting dnsmasq fails, to
If the system's configuration is such that the system resolver sends DNS queries
through the dnsmasq instance which is starting up then this will time-out and fail.
.TP
-.B --rev-server=<ip-address>[/<prefix-len>][,<ipaddr>][#<port>][@<interface>][@<source-ip>[#<port>]]
+.B --rev-server=<ip-address>[/<prefix-len>][,<server>][#<port>][@<interface>][@<source-ip>[#<port>]]
This is functionally the same as
.B --server,
but provides some syntactic sugar to make specifying address-to-name queries easier. For example
diff --git a/src/dbus.c b/src/dbus.c
index 5cbddd9..870912a 100644
--- a/src/dbus.c
+++ b/src/dbus.c
@@ -380,7 +380,7 @@ static DBusMessage* dbus_read_servers_ex(DBusMessage *message, int strings)
}
/* parse the IP address */
- if ((addr_err = parse_server(str_addr, &sdetails, 0)) ||
+ if ((addr_err = parse_server(str_addr, &sdetails)) ||
(addr_err = parse_server_addr(&sdetails)))
{
error = dbus_message_new_error_printf(message, DBUS_ERROR_INVALID_ARGS,
diff --git a/src/dnsmasq.h b/src/dnsmasq.h
index 97dcc40..9f06a7f 100644
--- a/src/dnsmasq.h
+++ b/src/dnsmasq.h
@@ -1476,7 +1476,7 @@ void read_servers_file(void);
void set_option_bool(unsigned int opt);
void reset_option_bool(unsigned int opt);
struct hostsfile *expand_filelist(struct hostsfile *list);
-char *parse_server(char *arg, struct server_details *sdetails, const int can_resolve);
+char *parse_server(char *arg, struct server_details *sdetails);
char *parse_server_addr(struct server_details *sdetails);
int option_read_dynfile(char *file, int flags);
diff --git a/src/option.c b/src/option.c
index 53df70a..85bc876 100644
--- a/src/option.c
+++ b/src/option.c
@@ -855,7 +855,7 @@ static char *parse_mysockaddr(char *arg, union mysockaddr *addr)
return NULL;
}
-char *parse_server(char *arg, struct server_details *sdetails, const int can_resolve)
+char *parse_server(char *arg, struct server_details *sdetails)
{
sdetails->serv_port = NAMESERVER_PORT;
char *portno;
@@ -901,11 +901,10 @@ char *parse_server(char *arg, struct server_details *sdetails, const int can_res
sdetails->addr_type = AF_INET;
else if (inet_pton(AF_INET6, arg, &sdetails->addr->in6.sin6_addr) > 0)
sdetails->addr_type = AF_INET6;
- /* if the argument is neither an IPv4 not an IPv6 address, it might be a
- hostname and we should try to resolve it to a suitable address.
- However, we don't try this in domain_rev4/6 (can_resolve = 0) */
- else if (can_resolve)
+ else
{
+ /* if the argument is neither an IPv4 not an IPv6 address, it might be a
+ hostname and we should try to resolve it to a suitable address. */
memset(&hints, 0, sizeof(hints));
/* The AI_ADDRCONFIG flag ensures that then IPv4 addresses are returned in
the result only if the local system has at least one IPv4 address
@@ -927,8 +926,10 @@ char *parse_server(char *arg, struct server_details *sdetails, const int can_res
that can be used with node <arg> and service "domain". */
hints.ai_family = AF_UNSPEC;
- /* Get addresses suitable for sending datagrams or TCP connections. */
- hints.ai_socktype = 0;
+ /* Get addresses suitable for sending datagrams. We assume that we can use the
+ same addresses for TCP connections. Settting this to zero gets each address
+ threes times, for SOCK_STREAM, SOCK_RAW and SOCK_DGRAM, which is not useful. */
+ hints.ai_socktype = SOCK_DGRAM;
/* Get address associated with this hostname */
ecode = getaddrinfo(arg, NULL, &hints, &sdetails->hostinfo);
@@ -952,8 +953,6 @@ char *parse_server(char *arg, struct server_details *sdetails, const int can_res
return _((char*)gai_strerror(ecode));
}
}
- else
- return _("bad address");
sdetails->valid = 1;
return NULL;
@@ -984,7 +983,7 @@ char *parse_server_addr(struct server_details *sdetails)
/* When resolving a server IP by hostname, we can simply skip mismatching
server / source IP pairs. Otherwise, when an IP address is given directly,
this is a fatal error. */
- if(!sdetails->resolved)
+ if (!sdetails->resolved)
return _("cannot use IPv4 server address with IPv6 source address");
}
else
@@ -1104,20 +1103,19 @@ static char *domain_rev4(int from_file, char *server, struct in_addr *addr4, int
if (!server)
flags = SERV_LITERAL_ADDRESS;
- else if ((string = parse_server(server, &sdetails, 0)) ||
- (string = parse_server_addr(&sdetails)))
+ else if ((string = parse_server(server, &sdetails)))
return string;
-
+
if (from_file)
flags |= SERV_FROM_FILE;
-
+
rem = size & 0x7;
addrbytes = (32 - size) >> 3;
addrbits = (32 - size) & 7;
if (size > 32 || size < 1)
return _("bad IPv4 prefix length");
-
+
/* Zero out last address bits according to CIDR mask */
((u8 *)addr4)[3-addrbytes] &= ~((1 << addrbits)-1);
@@ -1131,23 +1129,37 @@ static char *domain_rev4(int from_file, char *server, struct in_addr *addr4, int
*domain = 0;
string = domain;
msize = size/8;
-
+
for (j = (rem == 0) ? msize-1 : msize; j >= 0; j--)
{
int dig = ((unsigned char *)addr4)[j];
-
+
if (j == msize)
dig += i;
-
+
string += sprintf(string, "%d.", dig);
}
-
+
sprintf(string, "in-addr.arpa");
- if (!add_update_server(flags, &serv_addr, &source_addr, interface, domain, NULL))
- return _("error");
+ if (flags & SERV_LITERAL_ADDRESS)
+ {
+ if (!add_update_server(flags, &serv_addr, &source_addr, interface, domain, NULL))
+ return _("error");
+ }
+ else
+ {
+ while (parse_server_next(&sdetails))
+ {
+ if ((string = parse_server_addr(&sdetails)))
+ return string;
+
+ if (!add_update_server(flags, &serv_addr, &source_addr, interface, domain, NULL))
+ return _("error");
+ }
+ }
}
-
+
return NULL;
}
@@ -1169,8 +1181,7 @@ static char *domain_rev6(int from_file, char *server, struct in6_addr *addr6, in
if (!server)
flags = SERV_LITERAL_ADDRESS;
- else if ((string = parse_server(server, &sdetails, 0)) ||
- (string = parse_server_addr(&sdetails)))
+ else if ((string = parse_server(server, &sdetails)))
return string;
if (from_file)
@@ -1211,10 +1222,24 @@ static char *domain_rev6(int from_file, char *server, struct in6_addr *addr6, in
sprintf(string, "ip6.arpa");
- if (!add_update_server(flags, &serv_addr, &source_addr, interface, domain, NULL))
- return _("error");
+ if (flags & SERV_LITERAL_ADDRESS)
+ {
+ if (!add_update_server(flags, &serv_addr, &source_addr, interface, domain, NULL))
+ return _("error");
+ }
+ else
+ {
+ while (parse_server_next(&sdetails))
+ {
+ if ((string = parse_server_addr(&sdetails)))
+ return string;
+
+ if (!add_update_server(flags, &serv_addr, &source_addr, interface, domain, NULL))
+ return _("error");
+ }
+ }
}
-
+
return NULL;
}
@@ -2970,7 +2995,7 @@ static int one_opt(int option, char *arg, char *errstr, char *gen_err, int comma
}
else
{
- if ((err = parse_server(arg, &sdetails, 1)))
+ if ((err = parse_server(arg, &sdetails)))
ret_err(err);
}