--- embedaddon/dnsmasq/src/domain.c 2021/03/17 00:56:46 1.1.1.3 +++ embedaddon/dnsmasq/src/domain.c 2023/09/27 11:02:07 1.1.1.4 @@ -1,4 +1,4 @@ -/* dnsmasq is Copyright (c) 2000-2021 Simon Kelley +/* dnsmasq is Copyright (c) 2000-2022 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,9 +18,10 @@ static struct cond_domain *search_domain(struct in_addr addr, struct cond_domain *c); +static int match_domain(struct in_addr addr, struct cond_domain *c); static struct cond_domain *search_domain6(struct in6_addr *addr, struct cond_domain *c); +static int match_domain6(struct in6_addr *addr, struct cond_domain *c); - int is_name_synthetic(int flags, char *name, union all_addr *addr) { char *p; @@ -135,28 +136,9 @@ int is_name_synthetic(int flags, char *name, union all } if (hostname_isequal(c->domain, p+1) && inet_pton(prot, tail, addr)) - { - if (prot == AF_INET) - { - if (!c->is6 && - ntohl(addr->addr4.s_addr) >= ntohl(c->start.s_addr) && - ntohl(addr->addr4.s_addr) <= ntohl(c->end.s_addr)) - found = 1; - } - else - { - u64 addrpart = addr6part(&addr->addr6); - - if (c->is6 && - is_same_net6(&addr->addr6, &c->start6, 64) && - addrpart >= addr6part(&c->start6) && - addrpart <= addr6part(&c->end6)) - found = 1; - } - } - + found = (prot == AF_INET) ? match_domain(addr->addr4, c) : match_domain6(&addr->addr6, c); } - + /* restore name */ for (p = tail; *p; p++) if (*p == '.' || *p == ':') @@ -246,14 +228,30 @@ int is_rev_synth(int flag, union all_addr *addr, char } +static int match_domain(struct in_addr addr, struct cond_domain *c) +{ + if (c->interface) + { + struct addrlist *al; + for (al = c->al; al; al = al->next) + if (!(al->flags & ADDRLIST_IPV6) && + is_same_net_prefix(addr, al->addr.addr4, al->prefixlen)) + return 1; + } + else if (!c->is6 && + ntohl(addr.s_addr) >= ntohl(c->start.s_addr) && + ntohl(addr.s_addr) <= ntohl(c->end.s_addr)) + return 1; + + return 0; +} + static struct cond_domain *search_domain(struct in_addr addr, struct cond_domain *c) { for (; c; c = c->next) - if (!c->is6 && - ntohl(addr.s_addr) >= ntohl(c->start.s_addr) && - ntohl(addr.s_addr) <= ntohl(c->end.s_addr)) + if (match_domain(addr, c)) return c; - + return NULL; } @@ -267,16 +265,39 @@ char *get_domain(struct in_addr addr) return daemon->domain_suffix; } +static int match_domain6(struct in6_addr *addr, struct cond_domain *c) +{ + + /* subnet from interface address. */ + if (c->interface) + { + struct addrlist *al; + for (al = c->al; al; al = al->next) + if (al->flags & ADDRLIST_IPV6 && + is_same_net6(addr, &al->addr.addr6, al->prefixlen)) + return 1; + } + else if (c->is6) + { + if (c->prefixlen >= 64) + { + u64 addrpart = addr6part(addr); + if (is_same_net6(addr, &c->start6, 64) && + addrpart >= addr6part(&c->start6) && + addrpart <= addr6part(&c->end6)) + return 1; + } + else if (is_same_net6(addr, &c->start6, c->prefixlen)) + return 1; + } + + return 0; +} static struct cond_domain *search_domain6(struct in6_addr *addr, struct cond_domain *c) { - u64 addrpart = addr6part(addr); - for (; c; c = c->next) - if (c->is6 && - is_same_net6(addr, &c->start6, 64) && - addrpart >= addr6part(&c->start6) && - addrpart <= addr6part(&c->end6)) + if (match_domain6(addr, c)) return c; return NULL;