[Dnsmasq-discuss] Domain name wildcard match in the --server option

Geert Stappers stappers at stappers.nl
Mon Nov 25 21:00:15 GMT 2019


On Mon, Nov 25, 2019 at 11:56:56PM +0800, Mingjian Hong wrote:
> On Sun, Nov 24, 2019 at 4:45 PM Geert Stappers 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.
> >
> >
> Hi,
> 
> I looked around the source code and made some modifications to fit my needs.
> With this patch,

Nice

> 
> 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)
>      {
> --
 
Patch got damaged in email. Please email again, but different.
* email as attachment
* email with email program that doesn't do line wrapping.


Groeten
Geert Stappers
-- 
Leven en laten leven



More information about the Dnsmasq-discuss mailing list