trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zw...@apache.org
Subject [1/4] git commit: TS-2595 Skip domain expansion if original name ends with dot.
Date Mon, 03 Mar 2014 14:37:35 GMT
Repository: trafficserver
Updated Branches:
  refs/heads/master af3e7aa87 -> b74425c05


TS-2595 Skip domain expansion if original name ends with dot.


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/7405d002
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/7405d002
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/7405d002

Branch: refs/heads/master
Commit: 7405d0025e176e8dbb31f9f9c8d7f3d0a78ccc37
Parents: dfdc985
Author: Thach Tran <tranngocthachs@gmail.com>
Authored: Sun Mar 2 15:38:00 2014 +0700
Committer: Leif Hedstrom <zwoop@apache.org>
Committed: Mon Mar 3 14:36:28 2014 +0000

----------------------------------------------------------------------
 iocore/dns/DNS.cc | 61 ++++++++++++++++++++++----------------------------
 1 file changed, 27 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7405d002/iocore/dns/DNS.cc
----------------------------------------------------------------------
diff --git a/iocore/dns/DNS.cc b/iocore/dns/DNS.cc
index 5f857be..4ddf05f 100644
--- a/iocore/dns/DNS.cc
+++ b/iocore/dns/DNS.cc
@@ -1043,14 +1043,20 @@ DNSEntry::mainEvent(int event, Event *e)
         SET_HANDLER((DNSEntryHandler) & DNSEntry::delayEvent);
         return handleEvent(event, e);
       }
-      //if (dns_search && !strnchr(qname,'.',MAXDNAME)){
-      if (dns_search)
+
+      // trailing '.' indicates no domain expansion
+      if (dns_search && ('.' != qname[orig_qname_len - 1])) {
         domains = dnsH->m_res->dnsrch;
-      if (domains && !strnchr(qname, '.', MAXDNAME)) {
-        qname[orig_qname_len] = '.';
-        ink_strlcpy(qname + orig_qname_len + 1, *domains, MAXDNAME - (orig_qname_len + 1));
-        qname_len = strlen(qname);
-        ++domains;
+        // start domain expansion straight away
+        // if lookup name has no '.'
+        if (domains && !strnchr(qname, '.', MAXDNAME)) {
+          qname[orig_qname_len] = '.';
+          qname_len = orig_qname_len + 1 + ink_strlcpy(qname + orig_qname_len + 1, *domains,
+                                                       MAXDNAME - (orig_qname_len + 1));
+          ++domains;
+        }
+      } else {
+        domains = NULL;
       }
       Debug("dns", "enqueing query %s", qname);
       DNSEntry *dup = get_entry(dnsH, qname, qtype);
@@ -1123,36 +1129,23 @@ dns_result(DNSHandler *h, DNSEntry *e, HostEnt *ent, bool retry) {
     } else if (e->domains && *e->domains) {
       do {
         Debug("dns", "domain extending, last tried '%s', original '%.*s'", e->qname, e->orig_qname_len,
e->qname);
-        //int l = _strlen(e->qname);
-        char *dot = strchr(e->qname, '.');
-        if (dot) {
-          if (e->orig_qname_len + strlen(*e->domains) + 2 > MAXDNAME) {
-            Debug("dns", "domain too large %.*s + %s", e->orig_qname_len, e->qname,
*e->domains);
-            goto LnextDomain;
-          }
-          if (e->qname[e->orig_qname_len - 1] != '.') {
-            e->qname[e->orig_qname_len] = '.';
-            ink_strlcpy(e->qname + e->orig_qname_len + 1, *e->domains, MAXDNAME
- (e->orig_qname_len + 1));
-            e->qname_len = strlen(e->qname);
-          } else {
-            ink_strlcpy(e->qname + e->orig_qname_len, *e->domains, MAXDNAME - e->orig_qname_len);
-            e->qname_len = strlen(e->qname);
-          }
+
+        // Make sure the next try fits
+        if (e->orig_qname_len + strlen(*e->domains) + 2 > MAXDNAME) {
+          Debug("dns", "domain too large %.*s + %s", e->orig_qname_len, e->qname, *e->domains);
         } else {
-          if (e->orig_qname_len + strlen(*e->domains) + 2 > MAXDNAME) {
-            Debug("dns", "domain too large %.*s + %s", e->orig_qname_len, e->qname,
*e->domains);
-            goto LnextDomain;
-          }
           e->qname[e->orig_qname_len] = '.';
-          ink_strlcpy(e->qname + e->orig_qname_len + 1, *e->domains, MAXDNAME -
(e->orig_qname_len + 1));
-          e->qname_len = strlen(e->qname);
+          e->qname_len = e->orig_qname_len + 1 + ink_strlcpy(e->qname + e->orig_qname_len
+ 1, *e->domains,
+                                                             MAXDNAME - (e->orig_qname_len
+ 1));
+          ++(e->domains);
+          e->retries = dns_retries;
+          Debug("dns", "new name = %s retries = %d", e->qname, e->retries);
+          write_dns(h);
+
+          return;
         }
-        ++(e->domains);
-        e->retries = dns_retries;
-        Debug("dns", "new name = %s retries = %d", e->qname, e->retries);
-        write_dns(h);
-        return;
-      LnextDomain:
+
+        // Try another one
         ++(e->domains);
       } while (*e->domains);
     } else {


Mime
View raw message