summaryrefslogtreecommitdiff
path: root/src/domain.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/domain.c')
-rw-r--r--src/domain.c60
1 files changed, 20 insertions, 40 deletions
diff --git a/src/domain.c b/src/domain.c
index 04d7cf8..3dc96ab 100644
--- a/src/domain.c
+++ b/src/domain.c
@@ -1,4 +1,4 @@
-/* dnsmasq is Copyright (c) 2000-2018 Simon Kelley
+/* dnsmasq is Copyright (c) 2000-2020 Simon Kelley
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -18,21 +18,14 @@
static struct cond_domain *search_domain(struct in_addr addr, struct cond_domain *c);
-#ifdef HAVE_IPV6
static struct cond_domain *search_domain6(struct in6_addr *addr, struct cond_domain *c);
-#endif
-int is_name_synthetic(int flags, char *name, struct all_addr *addr)
+int is_name_synthetic(int flags, char *name, union all_addr *addr)
{
char *p;
struct cond_domain *c = NULL;
- int prot = AF_INET;
-
-#ifdef HAVE_IPV6
- if (flags & F_IPV6)
- prot = AF_INET6;
-#endif
+ int prot = (flags & F_IPV6) ? AF_INET6 : AF_INET;
for (c = daemon->synth_domains; c; c = c->next)
{
@@ -80,11 +73,10 @@ int is_name_synthetic(int flags, char *name, struct all_addr *addr)
if (!c->is6 &&
index <= ntohl(c->end.s_addr) - ntohl(c->start.s_addr))
{
- addr->addr.addr4.s_addr = htonl(ntohl(c->start.s_addr) + index);
+ addr->addr4.s_addr = htonl(ntohl(c->start.s_addr) + index);
found = 1;
}
- }
-#ifdef HAVE_IPV6
+ }
else
{
u64 index = atoll(tail);
@@ -93,12 +85,11 @@ int is_name_synthetic(int flags, char *name, struct all_addr *addr)
index <= addr6part(&c->end6) - addr6part(&c->start6))
{
u64 start = addr6part(&c->start6);
- addr->addr.addr6 = c->start6;
- setaddr6part(&addr->addr.addr6, start + index);
+ addr->addr6 = c->start6;
+ setaddr6part(&addr->addr6, start + index);
found = 1;
}
}
-#endif
}
}
else
@@ -111,10 +102,8 @@ int is_name_synthetic(int flags, char *name, struct all_addr *addr)
if ((c >='0' && c <= '9') || c == '-')
continue;
-#ifdef HAVE_IPV6
if (prot == AF_INET6 && ((c >='A' && c <= 'F') || (c >='a' && c <= 'f')))
continue;
-#endif
break;
}
@@ -124,7 +113,6 @@ int is_name_synthetic(int flags, char *name, struct all_addr *addr)
*p = 0;
-#ifdef HAVE_IPV6
if (prot == AF_INET6 && strstr(tail, "--ffff-") == tail)
{
/* special hack for v4-mapped. */
@@ -134,7 +122,6 @@ int is_name_synthetic(int flags, char *name, struct all_addr *addr)
*p = '.';
}
else
-#endif
{
/* swap . or : for - */
for (p = tail; *p; p++)
@@ -142,10 +129,8 @@ int is_name_synthetic(int flags, char *name, struct all_addr *addr)
{
if (prot == AF_INET)
*p = '.';
-#ifdef HAVE_IPV6
else
*p = ':';
-#endif
}
}
@@ -154,22 +139,20 @@ int is_name_synthetic(int flags, char *name, struct all_addr *addr)
if (prot == AF_INET)
{
if (!c->is6 &&
- ntohl(addr->addr.addr4.s_addr) >= ntohl(c->start.s_addr) &&
- ntohl(addr->addr.addr4.s_addr) <= ntohl(c->end.s_addr))
+ ntohl(addr->addr4.s_addr) >= ntohl(c->start.s_addr) &&
+ ntohl(addr->addr4.s_addr) <= ntohl(c->end.s_addr))
found = 1;
}
-#ifdef HAVE_IPV6
else
{
- u64 addrpart = addr6part(&addr->addr.addr6);
+ u64 addrpart = addr6part(&addr->addr6);
if (c->is6 &&
- is_same_net6(&addr->addr.addr6, &c->start6, 64) &&
+ is_same_net6(&addr->addr6, &c->start6, 64) &&
addrpart >= addr6part(&c->start6) &&
addrpart <= addr6part(&c->end6))
found = 1;
}
-#endif
}
}
@@ -190,18 +173,18 @@ int is_name_synthetic(int flags, char *name, struct all_addr *addr)
}
-int is_rev_synth(int flag, struct all_addr *addr, char *name)
+int is_rev_synth(int flag, union all_addr *addr, char *name)
{
struct cond_domain *c;
- if (flag & F_IPV4 && (c = search_domain(addr->addr.addr4, daemon->synth_domains)))
+ if (flag & F_IPV4 && (c = search_domain(addr->addr4, daemon->synth_domains)))
{
char *p;
*name = 0;
if (c->indexed)
{
- unsigned int index = ntohl(addr->addr.addr4.s_addr) - ntohl(c->start.s_addr);
+ unsigned int index = ntohl(addr->addr4.s_addr) - ntohl(c->start.s_addr);
snprintf(name, MAXDNAME, "%s%u", c->prefix ? c->prefix : "", index);
}
else
@@ -209,7 +192,7 @@ int is_rev_synth(int flag, struct all_addr *addr, char *name)
if (c->prefix)
strncpy(name, c->prefix, MAXDNAME - ADDRSTRLEN);
- inet_ntop(AF_INET, &addr->addr.addr4, name + strlen(name), ADDRSTRLEN);
+ inet_ntop(AF_INET, &addr->addr4, name + strlen(name), ADDRSTRLEN);
for (p = name; *p; p++)
if (*p == '.')
*p = '-';
@@ -221,15 +204,14 @@ int is_rev_synth(int flag, struct all_addr *addr, char *name)
return 1;
}
-#ifdef HAVE_IPV6
- if (flag & F_IPV6 && (c = search_domain6(&addr->addr.addr6, daemon->synth_domains)))
+ if ((flag & F_IPV6) && (c = search_domain6(&addr->addr6, daemon->synth_domains)))
{
char *p;
*name = 0;
if (c->indexed)
{
- u64 index = addr6part(&addr->addr.addr6) - addr6part(&c->start6);
+ u64 index = addr6part(&addr->addr6) - addr6part(&c->start6);
snprintf(name, MAXDNAME, "%s%llu", c->prefix ? c->prefix : "", index);
}
else
@@ -237,14 +219,14 @@ int is_rev_synth(int flag, struct all_addr *addr, char *name)
if (c->prefix)
strncpy(name, c->prefix, MAXDNAME - ADDRSTRLEN);
- inet_ntop(AF_INET6, &addr->addr.addr6, name + strlen(name), ADDRSTRLEN);
+ inet_ntop(AF_INET6, &addr->addr6, name + strlen(name), ADDRSTRLEN);
/* IPv6 presentation address can start with ":", but valid domain names
cannot start with "-" so prepend a zero in that case. */
if (!c->prefix && *name == ':')
{
*name = '0';
- inet_ntop(AF_INET6, &addr->addr.addr6, name+1, ADDRSTRLEN);
+ inet_ntop(AF_INET6, &addr->addr6, name+1, ADDRSTRLEN);
}
/* V4-mapped have periods.... */
@@ -259,7 +241,6 @@ int is_rev_synth(int flag, struct all_addr *addr, char *name)
return 1;
}
-#endif
return 0;
}
@@ -286,7 +267,7 @@ char *get_domain(struct in_addr addr)
return daemon->domain_suffix;
}
-#ifdef HAVE_IPV6
+
static struct cond_domain *search_domain6(struct in6_addr *addr, struct cond_domain *c)
{
u64 addrpart = addr6part(addr);
@@ -310,4 +291,3 @@ char *get_domain6(struct in6_addr *addr)
return daemon->domain_suffix;
}
-#endif