--------------------- PatchSet 5155 Date: 2007/08/05 12:30:23 Author: amosjeffries Branch: squid3-ipv6 Tag: (none) Log: Fix http_port with FQDN fails with 'Bungled squid.conf' Adds IPAddress::GetHostByName() to perform char* conversion with rDNS, assignment conversion does numeric-IPA-only, without rDNS. Members: include/IPAddress.h:1.1.2.28->1.1.2.29 lib/IPAddress.cc:1.1.2.58->1.1.2.59 src/cache_cf.cc:1.40.2.35->1.40.2.36 Index: squid3/include/IPAddress.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/include/Attic/IPAddress.h,v retrieving revision 1.1.2.28 retrieving revision 1.1.2.29 diff -u -r1.1.2.28 -r1.1.2.29 --- squid3/include/IPAddress.h 5 Aug 2007 08:56:14 -0000 1.1.2.28 +++ squid3/include/IPAddress.h 5 Aug 2007 12:30:23 -0000 1.1.2.29 @@ -1,6 +1,6 @@ /* - * $Id: IPAddress.h,v 1.1.2.28 2007/08/05 08:56:14 amosjeffries Exp $ + * $Id: IPAddress.h,v 1.1.2.29 2007/08/05 12:30:23 amosjeffries Exp $ * * DEBUG: section 14 IP Storage and Handling * AUTHOR: Amos Jeffries @@ -332,6 +332,14 @@ */ void InitAddrInfo(struct addrinfo *&ai) const; + /** + * Lookup a Host by Name. Equivalent to system call gethostbyname(char*) + * \param s The textual FQDN of teh host being located. + * \retval true lookup was successful and an IPA was located. + * \retval false lookup failed or FQDN has no IP associated. + */ + bool GetHostByName(const char *s); + public: /* FIXME: When C => C++ conversion is done will be fully private. * Legacy Transition Methods. @@ -373,6 +381,9 @@ void Map6to4(const struct in6_addr &src, struct in_addr &dest) const; #endif + // Worker behind GetHostName and char* converters + bool LookupHostIP(const char *s, bool nodns); + /* variables */ IPAddressType m_Type; #if USE_IPV6 Index: squid3/lib/IPAddress.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/lib/Attic/IPAddress.cc,v retrieving revision 1.1.2.58 retrieving revision 1.1.2.59 diff -u -r1.1.2.58 -r1.1.2.59 --- squid3/lib/IPAddress.cc 30 Jul 2007 03:17:59 -0000 1.1.2.58 +++ squid3/lib/IPAddress.cc 5 Aug 2007 12:30:25 -0000 1.1.2.59 @@ -1,6 +1,6 @@ /* - * $Id: IPAddress.cc,v 1.1.2.58 2007/07/30 03:17:59 amosjeffries Exp $ + * $Id: IPAddress.cc,v 1.1.2.59 2007/08/05 12:30:25 amosjeffries Exp $ * * DEBUG: section 14 IP Storage and Handling * AUTHOR: Amos Jeffries @@ -435,6 +435,16 @@ bool IPAddress::operator =(const char* s) { + return LookupHostIP(s, true); +} + +bool IPAddress::GetHostByName(const char* s) +{ + return LookupHostIP(s, false); +} + +bool IPAddress::LookupHostIP(const char *s, bool nodns) +{ int err = 0; struct addrinfo *res = NULL; @@ -442,7 +452,9 @@ struct addrinfo want; memset(&want, 0, sizeof(struct addrinfo)); - want.ai_flags = AI_NUMERICHOST; // prevent actual DNS lookups! + if(nodns) { + want.ai_flags = AI_NUMERICHOST; // prevent actual DNS lookups! + } #if !USE_IPV6 want.ai_family = AF_INET; #endif Index: squid3/src/cache_cf.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/cache_cf.cc,v retrieving revision 1.40.2.35 retrieving revision 1.40.2.36 diff -u -r1.40.2.35 -r1.40.2.36 --- squid3/src/cache_cf.cc 5 Aug 2007 09:02:06 -0000 1.40.2.35 +++ squid3/src/cache_cf.cc 5 Aug 2007 12:30:25 -0000 1.40.2.36 @@ -1,6 +1,6 @@ /* - * $Id: cache_cf.cc,v 1.40.2.35 2007/08/05 09:02:06 amosjeffries Exp $ + * $Id: cache_cf.cc,v 1.40.2.36 2007/08/05 12:30:25 amosjeffries Exp $ * * DEBUG: section 3 Configuration File Parsing * AUTHOR: Harvest Derived @@ -2516,7 +2516,6 @@ char *tmp; IPAddress ipa; - const struct hostent *hp; unsigned short port; IPAddress_list *s; @@ -2551,17 +2550,16 @@ port = 0; } - ipa.SetPort(port); - if (NULL == host) ipa.SetAnyAddr(); - else if ( ipa = host ) + else if ( ipa.GetHostByName(host) ) /* dont use ipcache. Accept either FQDN or IPA. */ (void) 0; - else if ((hp = gethostbyname(host))) /* dont use ipcache */ - ipa = *hp; else self_destruct(); + /* port MUST be set after the IPA lookup/conversion is perofrmed. */ + ipa.SetPort(port); + while (*head) head = &(*head)->next; @@ -2617,7 +2615,6 @@ parse_http_port_specification(http_port_list * s, char *token) { char *host = NULL; - const struct hostent *hp; unsigned short port = 0; char *t = NULL; char *junk = NULL; @@ -2629,11 +2626,15 @@ /* [ipv6]:port */ host = token + 1; t = strchr(host, ']'); - if (!t) + if (!t) { + debugs(3, 0, "http(s)_port: missing ']' on IPv6 address: " << token); self_destruct(); + } *t++ = '\0'; - if (*t != ':') + if (*t != ':') { + debugs(3, 0, "http(s)_port: missing Port in: " << token); self_destruct(); + } port = xatos(t + 1); } else #endif @@ -2646,29 +2647,33 @@ } else if ((port = strtol(token, &junk, 10)), !*junk) { /* port */ - debugs(3, 3, "parse_http_port_specification: found Listen on Port: " << port); + debugs(3, 3, "http(s)_port: found Listen on Port: " << port); } else { + debugs(3, 0, "http(s)_port: missing Port: " << token); self_destruct(); } - if (port == 0) + if (port == 0) { + debugs(3, 0, "http(s)_port: Port cannot be 0: " << token); self_destruct(); + } if (NULL == host) { s->s.SetAnyAddr(); - debugs(3, 3, "parse_http_port_specification: found Listen on wildcard address: " << s->s); + debugs(3, 3, "http(s)_port: found Listen on wildcard address: " << s->s); } - else if ( s->s = host) { - debugs(3, 3, "parse_http_port_specification: found Listen on IP: " << s->s); + else if ( s->s = host ) { /* check/parse numeric IPA */ + debugs(3, 3, "http(s)_port: Listen on Host/IP: " << host << " --> " << s->s); } - else if ((hp = gethostbyname(host))) { + else if ( s->s.GetHostByName(host) ) { /* check/parse for FQDN */ /* dont use ipcache */ - s->s = *hp; s->defaultsite = xstrdup(host); - debugs(3, 3, "parse_http_port_specification: found Listen as host '" << s->defaultsite << "' on IP: " << s->s); + debugs(3, 3, "http(s)_port: found Listen as Host " << s->defaultsite << " on IP: " << s->s); } - else + else { + debugs(3, 0, "http(s)_port: failed to resolve Host/IP: " << host); self_destruct(); + } s->s.SetPort(port); }