Implement --address=/example.com/#

as (more efficient) syntactic sugar for --address=/example.com/0.0.0.0 and --address=/example.com/::
This commit is contained in:
Simon Kelley
2018-09-03 23:18:36 +01:00
parent c5db8f93ec
commit da8b6517de
4 changed files with 31 additions and 9 deletions

View File

@@ -53,6 +53,12 @@ version 2.80
Add --caa-record config option. Add --caa-record config option.
Implement --address=/example.com/# as (more efficient) syntactic
sugar for --address=/example.com/0.0.0.0 and
--address=/example.com/::
Returning null addresses is a useful technique for ad-blocking.
Thanks to Peter Russell for the suggestion.
version 2.79 version 2.79
Fix parsing of CNAME arguments, which are confused by extra spaces. Fix parsing of CNAME arguments, which are confused by extra spaces.

View File

@@ -510,7 +510,12 @@ upstream nameserver by a more specific \fB--server\fP directive. As for
\fB--server\fP, one or more domains with no address returns a \fB--server\fP, one or more domains with no address returns a
no-such-domain answer, so \fB--address=/example.com/\fP is equivalent to no-such-domain answer, so \fB--address=/example.com/\fP is equivalent to
\fB--server=/example.com/\fP and returns NXDOMAIN for example.com and \fB--server=/example.com/\fP and returns NXDOMAIN for example.com and
all its subdomains. all its subdomains. An address specified as '#' translates to the NULL
address of 0.0.0.0 and its IPv6 equivalent of :: so
\fB--address=/example.com/#\fP will return NULL addresses for example.com and
its subdomains. This is partly syntactic sugar for \fB--address=/example.com/0.0.0.0\fP
and \fB--address=/example.com/::\fP but is also more efficient than including both
as seperate configuration lines.
.TP .TP
.B --ipset=/<domain>[/<domain>...]/<ipset>[,<ipset>...] .B --ipset=/<domain>[/<domain>...]/<ipset>[,<ipset>...]
Places the resolved IP addresses of queries for one or more domains in Places the resolved IP addresses of queries for one or more domains in

View File

@@ -118,6 +118,7 @@ static unsigned int search_servers(time_t now, struct all_addr **addrpp, unsigne
unsigned int matchlen = 0; unsigned int matchlen = 0;
struct server *serv; struct server *serv;
unsigned int flags = 0; unsigned int flags = 0;
static struct all_addr zero;
for (serv = daemon->servers; serv; serv=serv->next) for (serv = daemon->servers; serv; serv=serv->next)
if (qtype == F_DNSSECOK && !(serv->flags & SERV_DO_DNSSEC)) if (qtype == F_DNSSECOK && !(serv->flags & SERV_DO_DNSSEC))
@@ -131,7 +132,14 @@ static unsigned int search_servers(time_t now, struct all_addr **addrpp, unsigne
flags = F_NXDOMAIN; flags = F_NXDOMAIN;
else if (serv->flags & SERV_LITERAL_ADDRESS) else if (serv->flags & SERV_LITERAL_ADDRESS)
{ {
if (sflag & qtype) /* literal address = '#' -> return all-zero address for IPv4 and IPv6 */
if ((serv->flags & SERV_USE_RESOLV) && (qtype & (F_IPV6 | F_IPV4)))
{
memset(&zero, 0, sizeof(zero));
flags = qtype;
*addrpp = &zero;
}
else if (sflag & qtype)
{ {
flags = sflag; flags = sflag;
if (serv->addr.sa.sa_family == AF_INET) if (serv->addr.sa.sa_family == AF_INET)
@@ -184,7 +192,14 @@ static unsigned int search_servers(time_t now, struct all_addr **addrpp, unsigne
flags = F_NXDOMAIN; flags = F_NXDOMAIN;
else if (serv->flags & SERV_LITERAL_ADDRESS) else if (serv->flags & SERV_LITERAL_ADDRESS)
{ {
if (sflag & qtype) /* literal address = '#' -> return all-zero address for IPv4 and IPv6 */
if ((serv->flags & SERV_USE_RESOLV) && (qtype & (F_IPV6 | F_IPV4)))
{
memset(&zero, 0, sizeof(zero));
flags = qtype;
*addrpp = &zero;
}
else if (sflag & qtype)
{ {
flags = sflag; flags = sflag;
if (serv->addr.sa.sa_family == AF_INET) if (serv->addr.sa.sa_family == AF_INET)

View File

@@ -2467,11 +2467,7 @@ static int one_opt(int option, char *arg, char *errstr, char *gen_err, int comma
} }
else if (strcmp(arg, "#") == 0) else if (strcmp(arg, "#") == 0)
{
newlist->flags |= SERV_USE_RESOLV; /* treat in ordinary way */ newlist->flags |= SERV_USE_RESOLV; /* treat in ordinary way */
if (newlist->flags & SERV_LITERAL_ADDRESS)
ret_err(gen_err);
}
else else
{ {
char *err = parse_server(arg, &newlist->addr, &newlist->source_addr, newlist->interface, &newlist->flags); char *err = parse_server(arg, &newlist->addr, &newlist->source_addr, newlist->interface, &newlist->flags);