From 11be3addbe04cbfc94a50cf2a6ddee3ed8b60dcb Mon Sep 17 00:00:00 2001 From: "John J. Rushford" Date: Tue, 6 Dec 2016 17:22:50 +0000 Subject: [PATCH] TS-5060: Fix DNAME support for OSX and FreeBSD. --- configure.ac | 2 ++ iocore/dns/DNS.cc | 40 ++++++++++++++++++------------------- iocore/dns/I_DNSProcessor.h | 8 ++++---- lib/ts/ink_platform.h | 3 +++ lib/ts/ink_res_init.cc | 3 +++ lib/ts/ink_res_mkquery.cc | 5 ++++- lib/ts/ink_resolver.h | 3 +++ 7 files changed, 39 insertions(+), 25 deletions(-) diff --git a/configure.ac b/configure.ac index bb4c6fbcb41..f906135fd15 100644 --- a/configure.ac +++ b/configure.ac @@ -1491,6 +1491,7 @@ AC_CHECK_HEADERS([sys/types.h \ sys/sockio.h \ sys/prctl.h \ arpa/nameser.h \ + arpa/nameser_compat.h \ execinfo.h \ netdb.h \ ctype.h \ @@ -1535,6 +1536,7 @@ AC_SUBST(sys_sysinfoh) AC_SUBST(sys_systeminfoh) AC_SUBST(arpa_ineth) AC_SUBST(arpa_nameserh) +AC_SUBST(arpa_nameser_compath) AC_SUBST(execinfoh) AC_SUBST(netdbh) AC_SUBST(ctypeh) diff --git a/iocore/dns/DNS.cc b/iocore/dns/DNS.cc index 69359a20ae2..39dc8ff2093 100644 --- a/iocore/dns/DNS.cc +++ b/iocore/dns/DNS.cc @@ -62,12 +62,12 @@ namespace inline const char * QtypeName(int qtype) { - return ns_t_aaaa == qtype ? "AAAA" : ns_t_a == qtype ? "A" : "*"; + return T_AAAA == qtype ? "AAAA" : T_A == qtype ? "A" : "*"; } inline bool is_addr_query(int qtype) { - return qtype == ns_t_a || qtype == ns_t_aaaa; + return qtype == T_A || qtype == T_AAAA; } } @@ -361,9 +361,9 @@ DNSEntry::init(const char *x, int len, int qtype_arg, Continuation *acont, DNSPr if (is_addr_query(qtype)) { // adjust things based on family preference. if (HOST_RES_IPV4 == host_res_style || HOST_RES_IPV4_ONLY == host_res_style) { - qtype = ns_t_a; + qtype = T_A; } else if (HOST_RES_IPV6 == host_res_style || HOST_RES_IPV6_ONLY == host_res_style) { - qtype = ns_t_aaaa; + qtype = T_AAAA; } } submit_time = Thread::get_hrtime(); @@ -384,7 +384,7 @@ DNSEntry::init(const char *x, int len, int qtype_arg, Continuation *acont, DNSPr mutex = dnsH->mutex; - if (is_addr_query(qtype) || qtype == ns_t_srv) { + if (is_addr_query(qtype) || qtype == T_SRV) { if (len) { len = len > (MAXDNAME - 1) ? (MAXDNAME - 1) : len; memcpy(qname, x, len); @@ -394,14 +394,14 @@ DNSEntry::init(const char *x, int len, int qtype_arg, Continuation *acont, DNSPr qname_len = ink_strlcpy(qname, x, MAXDNAME); orig_qname_len = qname_len; } - } else { // ns_t_ptr + } else { // T_PTR IpAddr const *ip = reinterpret_cast(x); if (ip->isIp6()) make_ipv6_ptr(&ip->_addr._ip6, qname); else if (ip->isIp4()) make_ipv4_ptr(ip->_addr._ip4, qname); else - ink_assert(!"ns_t_ptr query to DNS must be IP address."); + ink_assert(!"T_PTR query to DNS must be IP address."); } SET_HANDLER((DNSEntryHandler)&DNSEntry::mainEvent); @@ -564,7 +564,7 @@ DNSHandler::retry_named(int ndx, ink_hrtime t, bool reopen) char buffer[MAX_DNS_PACKET_LEN]; Debug("dns", "trying to resolve '%s' from DNS connection, ndx %d", try_server_names[try_servers], ndx); - int r = _ink_res_mkquery(m_res, try_server_names[try_servers], ns_t_a, buffer); + int r = _ink_res_mkquery(m_res, try_server_names[try_servers], T_A, buffer); try_servers = (try_servers + 1) % countof(try_server_names); ink_assert(r >= 0); if (r >= 0) { // looking for a bounce @@ -587,7 +587,7 @@ DNSHandler::try_primary_named(bool reopen) last_primary_retry = t; Debug("dns", "trying to resolve '%s' from primary DNS connection", try_server_names[try_servers]); - int r = _ink_res_mkquery(m_res, try_server_names[try_servers], ns_t_a, buffer); + int r = _ink_res_mkquery(m_res, try_server_names[try_servers], T_A, buffer); // if try_server_names[] is not full, round-robin within the // filled entries. if (local_num_entries < DEFAULT_NUM_TRY_SERVER) @@ -1089,7 +1089,7 @@ Action * DNSProcessor::getby(const char *x, int len, int type, Continuation *cont, Options const &opt) { Debug("dns", "received query %s type = %d, timeout = %d", x, type, opt.timeout); - if (type == ns_t_srv) { + if (type == T_SRV) { Debug("dns_srv", "DNSProcessor::getby attempting an SRV lookup for %s, timeout = %d", x, opt.timeout); } DNSEntry *e = dnsEntryAllocator.alloc(); @@ -1175,7 +1175,7 @@ dns_result(DNSHandler *h, DNSEntry *e, HostEnt *ent, bool retry) const char *result = "FAIL"; if (ent) { result = "SUCCESS"; - ptr = inet_ntop(e->qtype == ns_t_aaaa ? AF_INET6 : AF_INET, ent->ent.h_addr_list[0], buff, sizeof(buff)); + ptr = inet_ntop(e->qtype == T_AAAA ? AF_INET6 : AF_INET, ent->ent.h_addr_list[0], buff, sizeof(buff)); } Debug("dns", "%s result for %s = %s retry %d", result, e->qname, ptr, retry); } else { @@ -1423,7 +1423,7 @@ dns_process(DNSHandler *handler, HostEnt *buf, int len) this skips the query section (qdcount) */ unsigned char *here = (unsigned char *)buf->buf + HFIXEDSZ; - if (e->qtype == ns_t_srv) { + if (e->qtype == T_SRV) { for (int ctr = ntohs(h->qdcount); ctr > 0; ctr--) { int strlen = dn_skipname(here, eom); here += strlen + QFIXEDSZ; @@ -1444,7 +1444,7 @@ dns_process(DNSHandler *handler, HostEnt *buf, int len) short int type; NS_GET16(type, cp); cp += NS_INT16SZ; // NS_GET16(cls, cp); - NS_GET32(temp_ttl, cp); // NOTE: this is not a "long" but 32-bits (from nameser.h) + NS_GET32(temp_ttl, cp); // NOTE: this is not a "long" but 32-bits (from nameser_compat.h) if ((temp_ttl < buf->ttl) || (buf->ttl == 0)) buf->ttl = temp_ttl; NS_GET16(n, cp); @@ -1452,7 +1452,7 @@ dns_process(DNSHandler *handler, HostEnt *buf, int len) // // Decode cname // - if (is_addr_query(e->qtype) && (type == ns_t_cname || type == ns_t_dname)) { + if (is_addr_query(e->qtype) && (type == T_CNAME || type == T_DNAME)) { if (ap >= &buf->host_aliases[DNS_MAX_ALIASES - 1]) continue; n = ink_dn_expand((u_char *)h, eom, cp, tbuf, sizeof(tbuf)); @@ -1475,10 +1475,10 @@ dns_process(DNSHandler *handler, HostEnt *buf, int len) buflen -= n; if (is_debug_tag_set("dns")) { switch (type) { - case ns_t_cname: + case T_CNAME: Debug("dns", "received cname = %s", tbuf); break; - case ns_t_dname: + case T_DNAME: Debug("dns", "received dname = %s", tbuf); break; } @@ -1492,7 +1492,7 @@ dns_process(DNSHandler *handler, HostEnt *buf, int len) // // Decode names // - if (type == ns_t_ptr) { + if (type == T_PTR) { n = ink_dn_expand((u_char *)h, eom, cp, bp, buflen); if (n < 0) { ++error; @@ -1512,7 +1512,7 @@ dns_process(DNSHandler *handler, HostEnt *buf, int len) bp += n; buflen -= n; } - } else if (type == ns_t_srv) { + } else if (type == T_SRV) { if (num_srv >= HOST_DB_MAX_ROUND_ROBIN_INFO) break; cp = here; /* hack */ @@ -1553,7 +1553,7 @@ dns_process(DNSHandler *handler, HostEnt *buf, int len) } else { int nn; buf->ent.h_length = n; - buf->ent.h_addrtype = ns_t_a == type ? AF_INET : AF_INET6; + buf->ent.h_addrtype = T_A == type ? AF_INET : AF_INET6; buf->ent.h_name = (char *)bp; nn = strlen((char *)bp) + 1; Debug("dns", "received %s name = %s", QtypeName(type), bp); @@ -1573,7 +1573,7 @@ dns_process(DNSHandler *handler, HostEnt *buf, int len) } memcpy((*hap++ = bp), cp, n); Debug("dns", "received %s = %s", QtypeName(type), - inet_ntop(ns_t_aaaa == type ? AF_INET6 : AF_INET, bp, ip_string, sizeof(ip_string))); + inet_ntop(T_AAAA == type ? AF_INET6 : AF_INET, bp, ip_string, sizeof(ip_string))); bp += n; cp += n; } diff --git a/iocore/dns/I_DNSProcessor.h b/iocore/dns/I_DNSProcessor.h index f3d1c23d9df..564582d93fa 100644 --- a/iocore/dns/I_DNSProcessor.h +++ b/iocore/dns/I_DNSProcessor.h @@ -156,25 +156,25 @@ extern DNSProcessor dnsProcessor; inline Action * DNSProcessor::getSRVbyname(Continuation *cont, const char *name, Options const &opt) { - return getby(name, 0, ns_t_srv, cont, opt); + return getby(name, 0, T_SRV, cont, opt); } inline Action * DNSProcessor::gethostbyname(Continuation *cont, const char *name, Options const &opt) { - return getby(name, 0, ns_t_a, cont, opt); + return getby(name, 0, T_A, cont, opt); } inline Action * DNSProcessor::gethostbyname(Continuation *cont, const char *name, int len, Options const &opt) { - return getby(name, len, ns_t_a, cont, opt); + return getby(name, len, T_A, cont, opt); } inline Action * DNSProcessor::gethostbyaddr(Continuation *cont, IpAddr const *addr, Options const &opt) { - return getby(reinterpret_cast(addr), 0, ns_t_ptr, cont, opt); + return getby(reinterpret_cast(addr), 0, T_PTR, cont, opt); } inline DNSProcessor::Options::Options() : handler(0), timeout(0), host_res_style(HOST_RES_IPV4) diff --git a/lib/ts/ink_platform.h b/lib/ts/ink_platform.h index f230b833a4a..db38cb79ef9 100644 --- a/lib/ts/ink_platform.h +++ b/lib/ts/ink_platform.h @@ -93,6 +93,9 @@ #ifdef HAVE_ARPA_NAMESER_H #include #endif +#ifdef HAVE_ARPA_NAMESER_COMPAT_H +#include +#endif #include #ifdef HAVE_SIGINFO_H diff --git a/lib/ts/ink_res_init.cc b/lib/ts/ink_res_init.cc index a61bb9d3df0..71f1597be26 100644 --- a/lib/ts/ink_res_init.cc +++ b/lib/ts/ink_res_init.cc @@ -74,6 +74,9 @@ #include #include #include +#ifdef HAVE_ARPA_NAMESER_COMPAT_H +#include +#endif #include #include #include diff --git a/lib/ts/ink_res_mkquery.cc b/lib/ts/ink_res_mkquery.cc index 9368ef82bd7..f1e6f2cd713 100644 --- a/lib/ts/ink_res_mkquery.cc +++ b/lib/ts/ink_res_mkquery.cc @@ -71,6 +71,9 @@ #include #include #include +#ifdef HAVE_ARPA_NAMESER_COMPAT_H +#include +#endif #include #include #include @@ -141,7 +144,7 @@ int ink_res_mkquery(ink_res_state statp, int op, /*!< opcode of qu if (n < 0) return (-1); cp += n; - NS_PUT16(ns_t_null, cp); + NS_PUT16(T_NULL, cp); NS_PUT16(_class, cp); NS_PUT32(0, cp); NS_PUT16(0, cp); diff --git a/lib/ts/ink_resolver.h b/lib/ts/ink_resolver.h index f9a7c400520..e979ad93c5f 100644 --- a/lib/ts/ink_resolver.h +++ b/lib/ts/ink_resolver.h @@ -85,6 +85,9 @@ #define NS_PUT32 PUTLONG #endif +#ifndef T_DNAME +#define T_DNAME ns_t_dname +#endif #define INK_RES_F_VC 0x00000001 /*%< socket is TCP */ #define INK_RES_F_CONN 0x00000002 /*%< socket is connected */ #define INK_RES_F_EDNS0ERR 0x00000004 /*%< EDNS0 caused errors */