--------------------- PatchSet 4661 Date: 2007/05/28 13:32:48 Author: amosjeffries Branch: squid3-ipv6 Tag: (none) Log: Fix: not connecting to parent proxy properly. Members: src/comm.cc:1.47.2.30->1.47.2.31 Index: squid3/src/comm.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/comm.cc,v retrieving revision 1.47.2.30 retrieving revision 1.47.2.31 diff -u -r1.47.2.30 -r1.47.2.31 --- squid3/src/comm.cc 27 May 2007 14:22:09 -0000 1.47.2.30 +++ squid3/src/comm.cc 28 May 2007 13:32:48 -0000 1.47.2.31 @@ -1,6 +1,6 @@ /* - * $Id: comm.cc,v 1.47.2.30 2007/05/27 14:22:09 amosjeffries Exp $ + * $Id: comm.cc,v 1.47.2.31 2007/05/28 13:32:48 amosjeffries Exp $ * * DEBUG: section 5 Socket Functions * AUTHOR: Harvest Derived @@ -234,7 +234,9 @@ // defaults given by client char *host; + u_short default_port; IPAddress default_addr; + // NP: CANNOT store the default addr:port together as it gets set/reset differently. IPAddress S; CallBack callback; @@ -1008,7 +1010,7 @@ cs = new ConnectStateData; cs->fd = fd; cs->host = xstrdup(host); - cs->default_addr.SetPort(port); + cs->default_port = port; cs->callback = CallBack(callback, data); comm_add_close_handler(fd, commConnectFree, cs); ipcache_nbgethostbyname(host, commConnectDnsHandle, cs); @@ -1203,9 +1205,8 @@ void ConnectStateData::defaults() { -// S = in_addr; -// S.SetPort(port); /* port is HS */ -/*AYJ*/ S = default_addr; + S = default_addr; + S.SetPort(default_port); } void @@ -1214,6 +1215,8 @@ if (S.IsAnyAddr()) defaults(); + debugs(5,5, "ConnectSateData::connect: to " << S); + switch (comm_connect_addr(fd, S) ) { case COMM_INPROGRESS: @@ -1270,23 +1273,14 @@ int comm_connect_addr(int sock, const IPAddress &address) { - char buf[MAX_IPSTRLEN]; comm_err_t status = COMM_OK; fde *F = &fd_table[sock]; int x; int err = 0; socklen_t errlen; - memset(buf,0,MAX_IPSTRLEN); - - struct sockaddr_in saddr4; -#if USE_IPV6 - struct sockaddr_in6 saddr6; - if(!address.IsIPv4()) - address.GetSockAddr(saddr6); - else -#endif - address.GetSockAddr(saddr4); + struct addrinfo *AI = new addrinfo; // dynamic so freeaddrinfo(AI) can be properly used. + address.GetAddrInfo(*AI); assert(address.GetPort() != 0); @@ -1299,12 +1293,7 @@ F->flags.called_connect = 1; statCounter.syscalls.sock.connects++; -#if USE_IPV6 - if(!address.IsIPv4()) - x = connect(sock, (struct sockaddr *)&saddr6, sizeof(saddr6)); - else -#endif - x = connect(sock, (struct sockaddr *)&saddr4, sizeof(saddr4)); + x = connect(sock, (struct sockaddr *)AI->ai_addr, AI->ai_addrlen); if (x < 0) { @@ -1316,12 +1305,7 @@ #if defined(_SQUID_NEWSOS6_) /* Makoto MATSUSHITA */ -#if USE_IPV6 - if(!address.IsIPv4()) - connect(sock, (struct sockaddr *)&saddr6, sizeof(saddr6)); - else -#endif - connect(sock, (struct sockaddr *)&saddr4, sizeof(saddr4)); + connect(sock, (struct sockaddr *)AI->ai_addr, AI->ai_addrlen); if (errno == EINVAL) { errlen = sizeof(err); @@ -1369,7 +1353,7 @@ if (status == COMM_OK) { - debugs(5, 10, "comm_connect_addr: FD " << sock << " connected to " << F->ipaddr << ":" << F->remote_port); + debugs(5, 10, "comm_connect_addr: FD " << sock << " connected to " << address); } else if (status == COMM_INPROGRESS) { debugs(5, 10, "comm_connect_addr: FD " << sock << " connection pending");