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

MingJian Hong hongmingjian at gmail.com
Wed Nov 27 14:06:33 GMT 2019


  It is my first time to submit a patch by 'git send-email'.
If it doesn't work, please let me know. Thanks.

Regards,
hmj

---
 src/forward.c | 25 +++++++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)

diff --git a/src/forward.c b/src/forward.c
index e4745a3..d291695 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) 
 	    {
-- 
2.21.0




More information about the Dnsmasq-discuss mailing list