[
https://issues.apache.org/jira/browse/TS-2595?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13915940#comment-13915940
]
Leif Hedstrom commented on TS-2595:
-----------------------------------
Looks good. I'd like to make the following change, it simplifies it such that
it always just tries to append. Let me know what you think, perhaps this is not
the intent of how it's supposed to work? But it seems simpler?
{code}
diff --git a/iocore/dns/DNS.cc b/iocore/dns/DNS.cc
index 5f857be..1940a6d 100644
--- a/iocore/dns/DNS.cc
+++ b/iocore/dns/DNS.cc
@@ -1043,9 +1043,10 @@ DNSEntry::mainEvent(int event, Event *e)
SET_HANDLER((DNSEntryHandler) & DNSEntry::delayEvent);
return handleEvent(event, e);
}
- //if (dns_search && !strnchr(qname,'.',MAXDNAME)){
- if (dns_search)
+
+ if (dns_search) {
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));
@@ -1123,35 +1124,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);
- }
- } 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);
+
+ // 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);
+ goto LnextDomain;
}
+
+ e->qname[e->orig_qname_len] = '.';
+ 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;
+
LnextDomain:
++(e->domains);
} while (*e->domains);
{code}
> DNS lookup failed with multiple search domains
> ----------------------------------------------
>
> Key: TS-2595
> URL: https://issues.apache.org/jira/browse/TS-2595
> Project: Traffic Server
> Issue Type: Bug
> Components: DNS
> Reporter: Thach Tran
> Assignee: Leif Hedstrom
> Fix For: 5.0.0
>
> Attachments: ats_bad_dns.log
>
>
> I find the DNS search domain expanding logic of ATS a bit strange. On a
> system with multiple search domains in /etc/resolv.conf such as
> {noformat}
> search cisco.com google.com
> {noformat}
> and proxy.config.dns.search_default_domains set to 1, if ATS tries to lookup
> a hostname say 'developers', it will expand it to 'developers.cisco.com'
> first and then 'developers.cisco.com.google.com'. In other words, the next
> search domain will just get appended to the already expanded name. In this
> instance, it will end up failing as both 'developers.cisco.com' and
> 'developers.cisco.com.google.com' are not resolvable.
> I would expect ATS to lookup 'developers.cisco.com' first and then try
> 'developers.google.com' which will success.
> I have a quick look at the code and it seems like it has been that way since
> Oct 2009 at least. Could someone comment on whether this is intentional or
> it's actually a bug. I find most other dns clients (e.g., nslookup) append
> search domain in turn to the original name rather than work this way.
--
This message was sent by Atlassian JIRA
(v6.1.5#6160)