]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
- Moved IP lookups to commConnect stuff.
authorwessels <>
Mon, 2 Jun 1997 05:22:17 +0000 (05:22 +0000)
committerwessels <>
Mon, 2 Jun 1997 05:22:17 +0000 (05:22 +0000)
- Added support for retrying connect().

src/comm.cc
src/http.cc
src/ipcache.cc
src/main.cc
src/squid.h
src/ssl.cc
src/tunnel.cc
src/wais.cc

index bca1aecbac4d431cb3d31eea8e25418d68f6e8f5..579790e64c86949202679a7a639e4fc866aad9c7 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: comm.cc,v 1.155 1997/05/26 04:04:56 wessels Exp $
+ * $Id: comm.cc,v 1.156 1997/06/01 23:22:17 wessels Exp $
  *
  * DEBUG: section 5     Socket Functions
  * AUTHOR: Harvest Derived
@@ -154,6 +154,7 @@ static void commConnectFree _PARAMS((int fd, void *data));
 static void commConnectHandle _PARAMS((int fd, void *data));
 static void commHandleWrite _PARAMS((int fd, void *data));
 static int fdIsHttpOrIcp _PARAMS((int fd));
+static IPH commConnectDnsHandle;
 
 static struct timeval zero_tv;
 
@@ -167,7 +168,6 @@ commCancelWriteHandler(int fd)
     }
 }
 
-
 static void
 CommWriteStateCallbackAndFree(int fd, int code)
 {
@@ -321,6 +321,19 @@ commConnectStart(int fd, const char *host, u_short port, CNCB * callback, void *
     cs->callback = callback;
     cs->data = data;
     comm_add_close_handler(fd, commConnectFree, cs);
+    ipcache_nbgethostbyname(host, fd, commConnectDnsHandle, cs);
+}
+
+static void
+commConnectDnsHandle(int fd, const ipcache_addrs * ia, void *data)
+{
+    ConnectStateData *cs = data;
+    if (ia == NULL) {
+       debug(5, 3, "commConnectDnsHandle: Unknown host: %s\n", cs->host);
+       cs->callback(fd, COMM_ERR_DNS, cs->data);
+       return;
+    }
+    cs->in_addr = ia->in_addrs[ia->cur];
     commConnectHandle(fd, cs);
 }
 
@@ -332,24 +345,34 @@ commConnectFree(int fd, void *data)
     xfree(cs);
 }
 
+static int
+commRetryConnect(int fd, ConnectStateData * connectState)
+{
+    int fd2;
+    if (++connectState->tries == 4)
+       return 0;
+    fd2 = socket(AF_INET, SOCK_STREAM, 0);
+    if (fd2 < 0) {
+       debug(5, 0, "commRetryConnect: socket: %s\n", xstrerror());
+       return 0;
+    }
+    if (dup2(fd2, fd) < 0) {
+       debug(5, 0, "commRetryConnect: dup2: %s\n", xstrerror());
+       return 0;
+    }
+    commSetNonBlocking(fd);
+    close(fd2);
+    return 1;
+}
+
 /* Connect SOCK to specified DEST_PORT at DEST_HOST. */
 static void
 commConnectHandle(int fd, void *data)
 {
     ConnectStateData *connectState = data;
-    const ipcache_addrs *ia = NULL;
     if (connectState->S.sin_addr.s_addr == 0) {
-       ia = ipcache_gethostbyname(connectState->host, IP_BLOCKING_LOOKUP);
-       if (ia == NULL) {
-           debug(5, 3, "commConnectHandle: Unknown host: %s\n",
-               connectState->host);
-           connectState->callback(fd,
-               COMM_ERROR,
-               connectState->data);
-           return;
-       }
        connectState->S.sin_family = AF_INET;
-       connectState->S.sin_addr = ia->in_addrs[ia->cur];
+       connectState->S.sin_addr = connectState->in_addr;
        connectState->S.sin_port = htons(connectState->port);
        if (Config.Log.log_fqdn)
            fqdncache_gethostbyaddr(connectState->S.sin_addr, FQDN_LOOKUP_IF_MISS);
@@ -369,8 +392,19 @@ commConnectHandle(int fd, void *data)
        connectState->callback(fd, COMM_OK, connectState->data);
        break;
     default:
-       ipcacheRemoveBadAddr(connectState->host, connectState->S.sin_addr);
-       connectState->callback(fd, COMM_ERROR, connectState->data);
+       if (commRetryConnect(fd, connectState)) {
+           debug(5, 1, "Retrying connection to %s: %s\n",
+               connectState->host, xstrerror());
+           connectState->S.sin_addr.s_addr = 0;
+           ipcacheCycleAddr(connectState->host);
+           ipcache_nbgethostbyname(connectState->host,
+               fd,
+               commConnectDnsHandle,
+               connectState);
+       } else {
+           ipcacheRemoveBadAddr(connectState->host, connectState->S.sin_addr);
+           connectState->callback(fd, COMM_ERR_CONNECT, connectState->data);
+       }
        break;
     }
 }
@@ -419,8 +453,6 @@ comm_connect_addr(int sock, const struct sockaddr_in *address)
     if (connect(sock, (struct sockaddr *) address, sizeof(struct sockaddr_in)) < 0) {
        switch (errno) {
        case EALREADY:
-           return COMM_ERROR;
-           /* NOTREACHED */
 #if EAGAIN != EWOULDBLOCK
        case EAGAIN:
 #endif
@@ -1093,42 +1125,35 @@ comm_set_mcast_ttl(int fd, int mcast_ttl)
     return 0;
 }
 
-int
-comm_join_mcast_groups(int fd)
+void
+comm_join_mcast_groups(int fd, const ipcache_addrs * ia, void *data)
 {
 #ifdef IP_MULTICAST_TTL
     struct ip_mreq mr;
-    wordlist *s = NULL;
-    const ipcache_addrs *ia = NULL;
     int i;
     int x;
     char c = 0;
-    for (s = Config.mcast_group_list; s; s = s->next) {
-       debug(5, 10, "comm_join_mcast_groups: joining group %s on FD %d\n",
-           s->key, fd);
-       ia = ipcache_gethostbyname(s->key, IP_BLOCKING_LOOKUP);
-       if (ia == NULL) {
-           debug(5, 0, "Unknown host: %s\n", s->key);
-           continue;
-       }
-       for (i = 0; i < (int) ia->count; i++) {
-           mr.imr_multiaddr.s_addr = (ia->in_addrs + i)->s_addr;
-           mr.imr_interface.s_addr = INADDR_ANY;
-           x = setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP,
-               (char *) &mr, sizeof(struct ip_mreq));
-           if (x < 0)
-               debug(5, 1, "comm_join_mcast_groups: FD %d, addr: %s [%s]\n",
-                   fd, s->key, inet_ntoa(*(ia->in_addrs + i)));
-           x = setsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP, &c, 1);
-           if (x < 0)
-               debug(5, 1,
-                   "comm_join_mcast_groups: can't disable m'cast loopback: %s\n",
-                   xstrerror());
-
-       }
+    if (ia == NULL) {
+       debug(5, 0, "comm_join_mcast_groups: Unknown host\n");
+       return;
+    }
+    for (i = 0; i < (int) ia->count; i++) {
+       debug(5, 10, "Listening for ICP requests on %s\n",
+           inet_ntoa(*(ia->in_addrs + i)));
+       mr.imr_multiaddr.s_addr = (ia->in_addrs + i)->s_addr;
+       mr.imr_interface.s_addr = INADDR_ANY;
+       x = setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP,
+           (char *) &mr, sizeof(struct ip_mreq));
+       if (x < 0)
+           debug(5, 1, "comm_join_mcast_groups: FD %d, [%s]\n",
+               fd, inet_ntoa(*(ia->in_addrs + i)));
+       x = setsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP, &c, 1);
+       if (x < 0)
+           debug(5, 1,
+               "comm_join_mcast_groups: can't disable m'cast loopback: %s\n",
+               xstrerror());
     }
 #endif
-    return 0;
 }
 
 static void
index 16e3e9d162a75e8e1a0c83e874fb116b7daf74b3..601b7b144edbc2c6338fb8b2265b9a26cfe005d3 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: http.cc,v 1.165 1997/06/01 18:19:52 wessels Exp $
+ * $Id: http.cc,v 1.166 1997/06/01 23:22:20 wessels Exp $
  *
  * DEBUG: section 11    Hypertext Transfer Protocol (HTTP)
  * AUTHOR: Harvest Derived
@@ -200,7 +200,6 @@ static struct {
 
 static CNCB httpConnectDone;
 static CWCB httpSendComplete;
-static IPH httpConnect;
 static PF httpReadReply;
 static PF httpSendRequest;
 static PF httpStateFree;
@@ -221,8 +220,6 @@ httpStateFree(int fd, void *data)
        put_free_8k_page(httpState->reply_hdr);
        httpState->reply_hdr = NULL;
     }
-    if (httpState->ip_lookup_pending)
-       ipcacheUnregister(httpState->request->host, httpState);
     requestUnlink(httpState->request);
     requestUnlink(httpState->orig_request);
     xfree(httpState);
@@ -871,35 +868,13 @@ proxyhttpStart(request_t * orig_request,
     comm_add_close_handler(httpState->fd,
        httpStateFree,
        httpState);
-    commSetTimeout(fd, Config.Timeout.read, httpTimeout, httpState);
     request->method = orig_request->method;
     xstrncpy(request->host, e->host, SQUIDHOSTNAMELEN);
     request->port = e->http_port;
     xstrncpy(request->urlpath, entry->url, MAX_URL);
     BIT_SET(request->flags, REQ_PROXYING);
-    httpState->ip_lookup_pending = 1;
-    ipcache_nbgethostbyname(request->host,
-       httpState->fd,
-       httpConnect,
-       httpState);
-}
-
-static void
-httpConnect(int fd, const ipcache_addrs * ia, void *data)
-{
-    HttpStateData *httpState = data;
-    request_t *request = httpState->request;
-    StoreEntry *entry = httpState->entry;
-    httpState->ip_lookup_pending = 0;
-    if (ia == NULL) {
-       debug(11, 4, "httpConnect: Unknown host: %s\n", request->host);
-       squid_error_entry(entry, ERR_DNS_FAIL, dns_error_message);
-       comm_close(fd);
-       return;
-    }
-    /* Open connection. */
     commSetTimeout(fd, Config.Timeout.connect, httpTimeout, httpState);
-    commConnectStart(fd,
+    commConnectStart(httpState->fd,
        request->host,
        request->port,
        httpConnectDone,
@@ -912,7 +887,11 @@ httpConnectDone(int fd, int status, void *data)
     HttpStateData *httpState = data;
     request_t *request = httpState->request;
     StoreEntry *entry = httpState->entry;
-    if (status != COMM_OK) {
+    if (status == COMM_ERR_DNS) {
+       debug(11, 4, "httpConnectDone: Unknown host: %s\n", request->host);
+       squid_error_entry(entry, ERR_DNS_FAIL, dns_error_message);
+       comm_close(fd);
+    } else if (status != COMM_OK) {
        squid_error_entry(entry, ERR_CONNECT_FAIL, xstrerror());
        if (httpState->neighbor)
            peerCheckConnectStart(httpState->neighbor);
@@ -954,11 +933,11 @@ httpStart(request_t * request, StoreEntry * entry)
     comm_add_close_handler(httpState->fd,
        httpStateFree,
        httpState);
-    commSetTimeout(fd, Config.Timeout.read, httpTimeout, httpState);
-    httpState->ip_lookup_pending = 1;
-    ipcache_nbgethostbyname(request->host,
-       httpState->fd,
-       httpConnect,
+    commSetTimeout(fd, Config.Timeout.connect, httpTimeout, httpState);
+    commConnectStart(httpState->fd,
+       request->host,
+       request->port,
+       httpConnectDone,
        httpState);
 }
 
index cd0755a5eba3adbfa50c728cb2d22aadeb629ab1..248096215290070a5c07111310f877d66a2b12ba 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: ipcache.cc,v 1.118 1997/05/23 16:56:16 wessels Exp $
+ * $Id: ipcache.cc,v 1.119 1997/06/01 23:22:23 wessels Exp $
  *
  * DEBUG: section 14    IP Cache
  * AUTHOR: Harvest Derived
@@ -248,7 +248,7 @@ ipcache_release(ipcache_entry * i)
        fatal_dump("ipcache_release: i != table_entry!");
     if (i->locks) {
        i->expires = squid_curtime;
-        ipcacheChangeKey(i);
+       ipcacheChangeKey(i);
        IpcacheStats.release_locked++;
        return;
     }
@@ -615,12 +615,12 @@ ipcache_dnsHandleRead(int fd, void *data)
        }
        ipcacheUnlockEntry(i);  /* unlock from IP_DISPATCHED */
     } else {
-       debug(14,5,"ipcache_dnsHandleRead: Incomplete reply\n");
-           commSetSelect(fd,
-               COMM_SELECT_READ,
-               ipcache_dnsHandleRead,
-               dnsData,
-               0);
+       debug(14, 5, "ipcache_dnsHandleRead: Incomplete reply\n");
+       commSetSelect(fd,
+           COMM_SELECT_READ,
+           ipcache_dnsHandleRead,
+           dnsData,
+           0);
     }
     if (dnsData->offset == 0) {
        dnsData->data = NULL;
index a9af7001df515a6fa53ab4fc0a8235a7883bd2c4..1ec9ea5c8cb9cbdc61eab04b463b1ccbef6130a9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: main.cc,v 1.149 1997/05/26 04:05:00 wessels Exp $
+ * $Id: main.cc,v 1.150 1997/06/01 23:22:25 wessels Exp $
  *
  * DEBUG: section 1     Startup and Main Loop
  * AUTHOR: Harvest Derived
@@ -340,6 +340,7 @@ serverConnectionsOpen(void)
     int len;
     int x;
     int fd;
+    wordlist *s;
     for (x = 0; x < Config.Port.n_http; x++) {
        enter_suid();
        fd = comm_open(SOCK_STREAM,
@@ -376,7 +377,11 @@ serverConnectionsOpen(void)
                COMM_SELECT_READ,
                icpHandleUdp,
                NULL, 0);
-           comm_join_mcast_groups(theInIcpConnection);
+           for (s = Config.mcast_group_list; s; s = s->next)
+               ipcache_nbgethostbyname(s->key,
+                   theInIcpConnection,
+                   comm_join_mcast_groups,
+                   NULL);
            debug(1, 1, "Accepting ICP connections on port %d, FD %d.\n",
                (int) port, theInIcpConnection);
 
index 1232175af3bdf5b33e0baa1824fbee2d631bb431..2e2bcdca2589f4a3af17e46b545b1bcc7e5ea34b 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: squid.h,v 1.117 1997/05/23 05:21:00 wessels Exp $
+ * $Id: squid.h,v 1.118 1997/06/01 23:22:27 wessels Exp $
  *
  * AUTHOR: Duane Wessels
  *
@@ -235,6 +235,7 @@ typedef struct _MemObject MemObject;
 typedef struct _cachemgr_passwd cachemgr_passwd;
 typedef struct _fileMap fileMap;
 typedef struct _cwstate CommWriteStateData;
+typedef struct _ipcache_addrs ipcache_addrs;
 
 /* 32 bit integer compatability hack */
 #if SIZEOF_INT == 4
@@ -326,7 +327,7 @@ extern int theInIcpConnection;      /* main.c */
 extern int theOutIcpConnection;        /* main.c */
 extern int vizSock;
 extern volatile int shutdown_pending;  /* main.c */
-extern volatile int reconfigure_pending;/* main.c */
+extern volatile int reconfigure_pending;       /* main.c */
 extern int opt_reload_hit_only;        /* main.c */
 extern int opt_dns_tests;      /* main.c */
 extern int opt_foreground_rebuild;     /* main.c */
index a59013a638d5ab67b7c4726d001664afb694197f..881d83304819485d45f348bd895c2925416c3c1c 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: ssl.cc,v 1.51 1997/05/15 23:38:02 wessels Exp $
+ * $Id: ssl.cc,v 1.52 1997/06/01 23:22:28 wessels Exp $
  *
  * DEBUG: section 26    Secure Sockets Layer Proxy
  * AUTHOR: Duane Wessels
@@ -46,7 +46,6 @@ typedef struct {
     time_t timeout;
     int *size_ptr;             /* pointer to size in an ConnStateData for logging */
     int proxying;
-    int ip_lookup_pending;
 } SslStateData;
 
 static const char *const conn_established = "HTTP/1.0 200 Connection established\r\n\r\n";
@@ -58,7 +57,6 @@ static void sslWriteServer _PARAMS((int fd, void *));
 static void sslWriteClient _PARAMS((int fd, void *));
 static void sslConnected _PARAMS((int fd, void *));
 static void sslProxyConnected _PARAMS((int fd, void *));
-static IPH sslConnect;
 static void sslErrorComplete _PARAMS((int, char *, int, int, void *));
 static void sslClose _PARAMS((SslStateData * sslState));
 static void sslClientClosed _PARAMS((int fd, void *));
@@ -115,8 +113,6 @@ sslStateFree(int fd, void *data)
     safe_free(sslState->client.buf);
     xfree(sslState->url);
     requestUnlink(sslState->request);
-    if (sslState->ip_lookup_pending)
-       ipcacheUnregister(sslState->host, sslState);
     safe_free(sslState);
 }
 
@@ -317,13 +313,12 @@ sslErrorComplete(int fd, char *buf, int size, int errflag, void *sslState)
 
 
 static void
-sslConnect(int fd, const ipcache_addrs * ia, void *data)
+sslConnectDone(int fd, int status, void *data)
 {
     SslStateData *sslState = data;
     request_t *request = sslState->request;
     char *buf = NULL;
-    sslState->ip_lookup_pending = 0;
-    if (ia == NULL) {
+    if (status == COMM_ERR_DNS) {
        debug(26, 4, "sslConnect: Unknown host: %s\n", sslState->host);
        buf = squid_error_url(sslState->url,
            request->method,
@@ -338,27 +333,7 @@ sslConnect(int fd, const ipcache_addrs * ia, void *data)
            sslState,
            xfree);
        return;
-    }
-    debug(26, 5, "sslConnect: client=%d server=%d\n",
-       sslState->client.fd,
-       sslState->server.fd);
-    commSetTimeout(sslState->server.fd,
-       Config.Timeout.read,
-       sslTimeout,
-       sslState);
-    commConnectStart(fd,
-       sslState->host,
-       sslState->port,
-       sslConnectDone,
-       sslState);
-}
-
-static void
-sslConnectDone(int fd, int status, void *data)
-{
-    SslStateData *sslState = data;
-    char *buf = NULL;
-    if (status == COMM_ERROR) {
+    } else if (status != COMM_OK) {
        buf = squid_error_url(sslState->url,
            sslState->request->method,
            ERR_CONNECT_FAIL,
@@ -477,10 +452,10 @@ sslPeerSelectComplete(peer * p, void *data)
     } else {
        sslState->port = CACHE_HTTP_PORT;
     }
-    sslState->ip_lookup_pending = 1;
-    ipcache_nbgethostbyname(sslState->host,
-       sslState->server.fd,
-       sslConnect,
+    commConnectStart(sslState->server.fd,
+       sslState->host,
+       sslState->port,
+       sslConnectDone,
        sslState);
 }
 
index 8cc9276bce7d33b88072590455da55f804093e95..cea5dd37dc1e0679f17cacf2300e9b66c24c020c 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: tunnel.cc,v 1.51 1997/05/15 23:38:02 wessels Exp $
+ * $Id: tunnel.cc,v 1.52 1997/06/01 23:22:28 wessels Exp $
  *
  * DEBUG: section 26    Secure Sockets Layer Proxy
  * AUTHOR: Duane Wessels
@@ -46,7 +46,6 @@ typedef struct {
     time_t timeout;
     int *size_ptr;             /* pointer to size in an ConnStateData for logging */
     int proxying;
-    int ip_lookup_pending;
 } SslStateData;
 
 static const char *const conn_established = "HTTP/1.0 200 Connection established\r\n\r\n";
@@ -58,7 +57,6 @@ static void sslWriteServer _PARAMS((int fd, void *));
 static void sslWriteClient _PARAMS((int fd, void *));
 static void sslConnected _PARAMS((int fd, void *));
 static void sslProxyConnected _PARAMS((int fd, void *));
-static IPH sslConnect;
 static void sslErrorComplete _PARAMS((int, char *, int, int, void *));
 static void sslClose _PARAMS((SslStateData * sslState));
 static void sslClientClosed _PARAMS((int fd, void *));
@@ -115,8 +113,6 @@ sslStateFree(int fd, void *data)
     safe_free(sslState->client.buf);
     xfree(sslState->url);
     requestUnlink(sslState->request);
-    if (sslState->ip_lookup_pending)
-       ipcacheUnregister(sslState->host, sslState);
     safe_free(sslState);
 }
 
@@ -317,13 +313,12 @@ sslErrorComplete(int fd, char *buf, int size, int errflag, void *sslState)
 
 
 static void
-sslConnect(int fd, const ipcache_addrs * ia, void *data)
+sslConnectDone(int fd, int status, void *data)
 {
     SslStateData *sslState = data;
     request_t *request = sslState->request;
     char *buf = NULL;
-    sslState->ip_lookup_pending = 0;
-    if (ia == NULL) {
+    if (status == COMM_ERR_DNS) {
        debug(26, 4, "sslConnect: Unknown host: %s\n", sslState->host);
        buf = squid_error_url(sslState->url,
            request->method,
@@ -338,27 +333,7 @@ sslConnect(int fd, const ipcache_addrs * ia, void *data)
            sslState,
            xfree);
        return;
-    }
-    debug(26, 5, "sslConnect: client=%d server=%d\n",
-       sslState->client.fd,
-       sslState->server.fd);
-    commSetTimeout(sslState->server.fd,
-       Config.Timeout.read,
-       sslTimeout,
-       sslState);
-    commConnectStart(fd,
-       sslState->host,
-       sslState->port,
-       sslConnectDone,
-       sslState);
-}
-
-static void
-sslConnectDone(int fd, int status, void *data)
-{
-    SslStateData *sslState = data;
-    char *buf = NULL;
-    if (status == COMM_ERROR) {
+    } else if (status != COMM_OK) {
        buf = squid_error_url(sslState->url,
            sslState->request->method,
            ERR_CONNECT_FAIL,
@@ -477,10 +452,10 @@ sslPeerSelectComplete(peer * p, void *data)
     } else {
        sslState->port = CACHE_HTTP_PORT;
     }
-    sslState->ip_lookup_pending = 1;
-    ipcache_nbgethostbyname(sslState->host,
-       sslState->server.fd,
-       sslConnect,
+    commConnectStart(sslState->server.fd,
+       sslState->host,
+       sslState->port,
+       sslConnectDone,
        sslState);
 }
 
index f00fffe804167f0258f83fed1145ca006e5e312b..d0d169ef11e1786cbabaf2e7f4f1373f1182e323 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: wais.cc,v 1.71 1997/05/23 05:21:04 wessels Exp $
+ * $Id: wais.cc,v 1.72 1997/06/01 23:22:29 wessels Exp $
  *
  * DEBUG: section 24    WAIS Relay
  * AUTHOR: Harvest Derived
@@ -116,7 +116,6 @@ typedef struct {
     int relayport;
     char *request_hdr;
     char request[MAX_URL];
-    int ip_lookup_pending;
 } WaisStateData;
 
 static PF waisStateFree;
@@ -124,7 +123,6 @@ static PF waisTimeout;
 static PF waisReadReply;
 static CWCB waisSendComplete;
 static PF waisSendRequest;
-static IPH waisConnect;
 static CNCB waisConnectDone;
 
 static void
@@ -134,8 +132,6 @@ waisStateFree(int fd, void *data)
     if (waisState == NULL)
        return;
     storeUnlockObject(waisState->entry);
-    if (waisState->ip_lookup_pending)
-       ipcacheUnregister(waisState->relayhost, waisState);
     xfree(waisState);
 }
 
@@ -334,26 +330,7 @@ waisStart(method_t method, StoreEntry * entry)
        waisState);
     commSetTimeout(fd, Config.Timeout.read, waisTimeout, waisState);
     storeLockObject(entry);
-    waisState->ip_lookup_pending = 1;
-    ipcache_nbgethostbyname(waisState->relayhost,
-       waisState->fd,
-       waisConnect,
-       waisState);
-}
-
-static void
-waisConnect(int fd, const ipcache_addrs * ia, void *data)
-{
-    WaisStateData *waisState = data;
-    waisState->ip_lookup_pending = 0;
-    if (!ipcache_gethostbyname(waisState->relayhost, 0)) {
-       debug(24, 4, "waisstart: Unknown host: %s\n", waisState->relayhost);
-       squid_error_entry(waisState->entry, ERR_DNS_FAIL, dns_error_message);
-       comm_close(waisState->fd);
-       return;
-    }
-    commSetTimeout(fd, Config.Timeout.connect, waisTimeout, waisState);
-    commConnectStart(fd,
+    commConnectStart(waisState->fd,
        waisState->relayhost,
        waisState->relayport,
        waisConnectDone,
@@ -364,12 +341,15 @@ static void
 waisConnectDone(int fd, int status, void *data)
 {
     WaisStateData *waisState = data;
-    if (status == COMM_ERROR) {
+    if (status == COMM_ERR_DNS) {
+       squid_error_entry(waisState->entry, ERR_DNS_FAIL, dns_error_message);
+       comm_close(fd);
+       return;
+    } else if (status != COMM_OK) {
        squid_error_entry(waisState->entry, ERR_CONNECT_FAIL, xstrerror());
        comm_close(fd);
        return;
     }
-    /* Install connection complete handler. */
     if (opt_no_ipcache)
        ipcacheInvalidate(waisState->relayhost);
     commSetSelect(fd,