Hi, I looked around the source code and made some modifications to fit my needs. With this patch,
server=/.google./127.0.0.1#5053 # match domains with .google. in it or ending with .google #server=/.google/127.0.0.1#5053 # ditto server=/.google.co./127.0.0.1#5053 # the same as server=/. google.co/127.0.0.1#5053 server=/.google.com/127.0.0.1#5053 # the same as server=/.google.com./ 127.0.0.1#5053 .google.com.hk will match the /.google.com/, and .google.co.hk will match the /.google.co./ Regards, hmj --- diff --git a/src/forward.c b/src/forward.c index e4745a3..6b5976e 100644 --- a/src/forward.c +++ b/src/forward.c @@ -150,10 +150,19 @@ static unsigned int search_servers(time_t now, union all_addr **addrpp, unsigned } else if (serv->flags & SERV_HAS_DOMAIN) { + int isequal; unsigned int domainlen = strlen(serv->domain); - char *matchstart = qdomain + namelen - domainlen; + char *matchstart = strcasestr(qdomain, serv->domain); + if ((matchstart != NULL) && (*(matchstart+domainlen) == 0 || *(matchstart+domainlen) == '.')) + isequal = 1; + else + { + matchstart = qdomain + namelen - domainlen; + isequal = hostname_isequal(matchstart, serv->domain); + } + if (namelen >= domainlen && - hostname_isequal(matchstart, serv->domain) && + isequal && (domainlen == 0 || namelen == domainlen || *(matchstart-1) == '.' )) { if ((serv->flags & SERV_NO_REBIND) && norebind) @@ -589,9 +598,17 @@ static size_t process_reply(struct dns_header *header, time_t now, struct server unsigned int matchlen = 0; for (ipset_pos = daemon->ipsets; ipset_pos; ipset_pos = ipset_pos->next) { + int isequal; unsigned int domainlen = strlen(ipset_pos->domain); - char *matchstart = daemon->namebuff + namelen - domainlen; - if (namelen >= domainlen && hostname_isequal(matchstart, ipset_pos->domain) && + char *matchstart = strcasestr(daemon->namebuff, ipset_pos->domain); + if ((matchstart != NULL) && (*(matchstart+domainlen) == 0 || *(matchstart+domainlen) == '.')) + isequal = 1; + else + { + matchstart = daemon->namebuff + namelen - domainlen; + isequal = hostname_isequal(matchstart, ipset_pos->domain); + } + if (namelen >= domainlen && isequal && (domainlen == 0 || namelen == domainlen || *(matchstart - 1) == '.' ) && domainlen >= matchlen) { -- On Sun, Nov 24, 2019 at 4:45 PM Geert Stappers <stapp...@stappers.nl> wrote: > On Sun, Nov 24, 2019 at 09:09:20AM +0800, Top Quoter wrote: > > On Sun, Nov 24, 2019 at 1:10 AM Geert Stappers wrote: > > > On Sat, Nov 23, 2019 at 11:48:45PM +0800, New to Mailinglists wrote: > > > > In the config file, I have to write several lines for all domains . > > > > google.com.ar, .google.com.jp, etc. For example, > > > > > > > > server=/.google.com.ar/127.0.0.1#5053 > > > > server=/.google.com.jp/127.0.0.1#5053 > > > > > > > > I just wonder it may be more friendly to use only one line, as > follows, > > > > > > > > server=/.google.com./127.0.0.1#5053 > > > > > > > > to match any .google.com.XX > > > > > > > > > > Please report back if > > > > > > server=/.google.com.*/127.0.0.1#5053 > > > > > > fits your needs. > > > > > > > > No. > > > > server=/.google.com.*/127.0.0.1#5053 > > > > will not match .google.com.XX > > > Acknowledge. > > Time will tell which other possiblities exist. > > > Regards > Geert Stappers > > P.S. > Make reading in the discussion order possible. > Example given > http://lists.thekelleys.org.uk/pipermail/dnsmasq-discuss/2019q4/013526.html > Reply below the text. > > _______________________________________________ > Dnsmasq-discuss mailing list > Dnsmasq-discuss@lists.thekelleys.org.uk > http://lists.thekelleys.org.uk/mailman/listinfo/dnsmasq-discuss >
_______________________________________________ Dnsmasq-discuss mailing list Dnsmasq-discuss@lists.thekelleys.org.uk http://lists.thekelleys.org.uk/mailman/listinfo/dnsmasq-discuss