"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/domain.c" between
dnsmasq-2.80.tar.gz and dnsmasq-2.81.tar.xz

About: Dnsmasq is a lightweight caching DNS forwarder and DHCP server.

domain.c  (dnsmasq-2.80):domain.c  (dnsmasq-2.81.tar.xz)
/* 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 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 it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 dated June, 1991, or the Free Software Foundation; version 2 dated June, 1991, or
(at your option) version 3 dated 29 June, 2007. (at your option) version 3 dated 29 June, 2007.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "dnsmasq.h" #include "dnsmasq.h"
static struct cond_domain *search_domain(struct in_addr addr, struct cond_domain *c); 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_dom ain *c); static struct cond_domain *search_domain6(struct in6_addr *addr, struct cond_dom ain *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; char *p;
struct cond_domain *c = NULL; struct cond_domain *c = NULL;
int prot = AF_INET; int prot = (flags & F_IPV6) ? AF_INET6 : AF_INET;
#ifdef HAVE_IPV6
if (flags & F_IPV6)
prot = AF_INET6;
#endif
for (c = daemon->synth_domains; c; c = c->next) for (c = daemon->synth_domains; c; c = c->next)
{ {
int found = 0; int found = 0;
char *tail, *pref; char *tail, *pref;
for (tail = name, pref = c->prefix; *tail != 0 && pref && *pref != 0; tail ++, pref++) for (tail = name, pref = c->prefix; *tail != 0 && pref && *pref != 0; tail ++, pref++)
{ {
unsigned int c1 = (unsigned char) *pref; unsigned int c1 = (unsigned char) *pref;
unsigned int c2 = (unsigned char) *tail; unsigned int c2 = (unsigned char) *tail;
skipping to change at line 81 skipping to change at line 74
if (hostname_isequal(c->domain, p+1)) if (hostname_isequal(c->domain, p+1))
{ {
if (prot == AF_INET) if (prot == AF_INET)
{ {
unsigned int index = atoi(tail); unsigned int index = atoi(tail);
if (!c->is6 && if (!c->is6 &&
index <= ntohl(c->end.s_addr) - ntohl(c->start.s_addr)) index <= ntohl(c->end.s_addr) - ntohl(c->start.s_addr))
{ {
addr->addr.addr4.s_addr = htonl(ntohl(c->start.s_addr) + in dex); addr->addr4.s_addr = htonl(ntohl(c->start.s_addr) + index);
found = 1; found = 1;
} }
} }
#ifdef HAVE_IPV6
else else
{ {
u64 index = atoll(tail); u64 index = atoll(tail);
if (c->is6 && if (c->is6 &&
index <= addr6part(&c->end6) - addr6part(&c->start6)) index <= addr6part(&c->end6) - addr6part(&c->start6))
{ {
u64 start = addr6part(&c->start6); u64 start = addr6part(&c->start6);
addr->addr.addr6 = c->start6; addr->addr6 = c->start6;
setaddr6part(&addr->addr.addr6, start + index); setaddr6part(&addr->addr6, start + index);
found = 1; found = 1;
} }
} }
#endif
} }
} }
else else
{ {
/* NB, must not alter name if we return zero */ /* NB, must not alter name if we return zero */
for (p = tail; *p; p++) for (p = tail; *p; p++)
{ {
char c = *p; char c = *p;
if ((c >='0' && c <= '9') || c == '-') if ((c >='0' && c <= '9') || c == '-')
continue; continue;
#ifdef HAVE_IPV6
if (prot == AF_INET6 && ((c >='A' && c <= 'F') || (c >='a' && c <= 'f'))) if (prot == AF_INET6 && ((c >='A' && c <= 'F') || (c >='a' && c <= 'f')))
continue; continue;
#endif
break; break;
} }
if (*p != '.') if (*p != '.')
continue; continue;
*p = 0; *p = 0;
#ifdef HAVE_IPV6
if (prot == AF_INET6 && strstr(tail, "--ffff-") == tail) if (prot == AF_INET6 && strstr(tail, "--ffff-") == tail)
{ {
/* special hack for v4-mapped. */ /* special hack for v4-mapped. */
memcpy(tail, "::ffff:", 7); memcpy(tail, "::ffff:", 7);
for (p = tail + 7; *p; p++) for (p = tail + 7; *p; p++)
if (*p == '-') if (*p == '-')
*p = '.'; *p = '.';
} }
else else
#endif
{ {
/* swap . or : for - */ /* swap . or : for - */
for (p = tail; *p; p++) for (p = tail; *p; p++)
if (*p == '-') if (*p == '-')
{ {
if (prot == AF_INET) if (prot == AF_INET)
*p = '.'; *p = '.';
#ifdef HAVE_IPV6
else else
*p = ':'; *p = ':';
#endif
} }
} }
if (hostname_isequal(c->domain, p+1) && inet_pton(prot, tail, addr)) if (hostname_isequal(c->domain, p+1) && inet_pton(prot, tail, addr))
{ {
if (prot == AF_INET) if (prot == AF_INET)
{ {
if (!c->is6 && if (!c->is6 &&
ntohl(addr->addr.addr4.s_addr) >= ntohl(c->start.s_addr) && ntohl(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->end.s_addr))
found = 1; found = 1;
} }
#ifdef HAVE_IPV6
else else
{ {
u64 addrpart = addr6part(&addr->addr.addr6); u64 addrpart = addr6part(&addr->addr6);
if (c->is6 && 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->start6) &&
addrpart <= addr6part(&c->end6)) addrpart <= addr6part(&c->end6))
found = 1; found = 1;
} }
#endif
} }
} }
/* restore name */ /* restore name */
for (p = tail; *p; p++) for (p = tail; *p; p++)
if (*p == '.' || *p == ':') if (*p == '.' || *p == ':')
*p = '-'; *p = '-';
*p = '.'; *p = '.';
if (found) if (found)
return 1; return 1;
} }
return 0; return 0;
} }
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; struct cond_domain *c;
if (flag & F_IPV4 && (c = search_domain(addr->addr.addr4, daemon->synth_domai ns))) if (flag & F_IPV4 && (c = search_domain(addr->addr4, daemon->synth_domains)))
{ {
char *p; char *p;
*name = 0; *name = 0;
if (c->indexed) 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); snprintf(name, MAXDNAME, "%s%u", c->prefix ? c->prefix : "", index);
} }
else else
{ {
if (c->prefix) if (c->prefix)
strncpy(name, c->prefix, MAXDNAME - ADDRSTRLEN); strncpy(name, c->prefix, MAXDNAME - ADDRSTRLEN);
inet_ntop(AF_INET, &addr->addr.addr4, name + strlen(name), ADD RSTRLEN); inet_ntop(AF_INET, &addr->addr4, name + strlen(name), ADDRSTRL EN);
for (p = name; *p; p++) for (p = name; *p; p++)
if (*p == '.') if (*p == '.')
*p = '-'; *p = '-';
} }
strncat(name, ".", MAXDNAME); strncat(name, ".", MAXDNAME);
strncat(name, c->domain, MAXDNAME); strncat(name, c->domain, MAXDNAME);
return 1; return 1;
} }
#ifdef HAVE_IPV6 if ((flag & F_IPV6) && (c = search_domain6(&addr->addr6, daemon->synth_domain
if (flag & F_IPV6 && (c = search_domain6(&addr->addr.addr6, daemon->synth_dom s)))
ains)))
{ {
char *p; char *p;
*name = 0; *name = 0;
if (c->indexed) 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); snprintf(name, MAXDNAME, "%s%llu", c->prefix ? c->prefix : "", index);
} }
else else
{ {
if (c->prefix) if (c->prefix)
strncpy(name, c->prefix, MAXDNAME - ADDRSTRLEN); 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 name s /* IPv6 presentation address can start with ":", but valid domain name s
cannot start with "-" so prepend a zero in that case. */ cannot start with "-" so prepend a zero in that case. */
if (!c->prefix && *name == ':') if (!c->prefix && *name == ':')
{ {
*name = '0'; *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.... */ /* V4-mapped have periods.... */
for (p = name; *p; p++) for (p = name; *p; p++)
if (*p == ':' || *p == '.') if (*p == ':' || *p == '.')
*p = '-'; *p = '-';
} }
strncat(name, ".", MAXDNAME); strncat(name, ".", MAXDNAME);
strncat(name, c->domain, MAXDNAME); strncat(name, c->domain, MAXDNAME);
return 1; return 1;
} }
#endif
return 0; return 0;
} }
static struct cond_domain *search_domain(struct in_addr addr, struct cond_domain *c) static struct cond_domain *search_domain(struct in_addr addr, struct cond_domain *c)
{ {
for (; c; c = c->next) for (; c; c = c->next)
if (!c->is6 && if (!c->is6 &&
ntohl(addr.s_addr) >= ntohl(c->start.s_addr) && ntohl(addr.s_addr) >= ntohl(c->start.s_addr) &&
ntohl(addr.s_addr) <= ntohl(c->end.s_addr)) ntohl(addr.s_addr) <= ntohl(c->end.s_addr))
skipping to change at line 284 skipping to change at line 265
char *get_domain(struct in_addr addr) char *get_domain(struct in_addr addr)
{ {
struct cond_domain *c; struct cond_domain *c;
if ((c = search_domain(addr, daemon->cond_domain))) if ((c = search_domain(addr, daemon->cond_domain)))
return c->domain; return c->domain;
return daemon->domain_suffix; return daemon->domain_suffix;
} }
#ifdef HAVE_IPV6
static struct cond_domain *search_domain6(struct in6_addr *addr, struct cond_dom ain *c) static struct cond_domain *search_domain6(struct in6_addr *addr, struct cond_dom ain *c)
{ {
u64 addrpart = addr6part(addr); u64 addrpart = addr6part(addr);
for (; c; c = c->next) for (; c; c = c->next)
if (c->is6 && if (c->is6 &&
is_same_net6(addr, &c->start6, 64) && is_same_net6(addr, &c->start6, 64) &&
addrpart >= addr6part(&c->start6) && addrpart >= addr6part(&c->start6) &&
addrpart <= addr6part(&c->end6)) addrpart <= addr6part(&c->end6))
return c; return c;
skipping to change at line 308 skipping to change at line 288
char *get_domain6(struct in6_addr *addr) char *get_domain6(struct in6_addr *addr)
{ {
struct cond_domain *c; struct cond_domain *c;
if (addr && (c = search_domain6(addr, daemon->cond_domain))) if (addr && (c = search_domain6(addr, daemon->cond_domain)))
return c->domain; return c->domain;
return daemon->domain_suffix; return daemon->domain_suffix;
} }
#endif
 End of changes. 31 change blocks. 
39 lines changed or deleted 19 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)