--------------------- PatchSet 4658 Date: 2007/05/27 14:17:30 Author: amosjeffries Branch: squid3-ipv6 Tag: (none) Log: Cleanup some duplicate socket handling. Members: src/comm.cc:1.47.2.28->1.47.2.29 Index: squid3/src/comm.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/comm.cc,v retrieving revision 1.47.2.28 retrieving revision 1.47.2.29 diff -u -r1.47.2.28 -r1.47.2.29 --- squid3/src/comm.cc 27 May 2007 13:18:09 -0000 1.47.2.28 +++ squid3/src/comm.cc 27 May 2007 14:17:30 -0000 1.47.2.29 @@ -1,6 +1,6 @@ /* - * $Id: comm.cc,v 1.47.2.28 2007/05/27 13:18:09 amosjeffries Exp $ + * $Id: comm.cc,v 1.47.2.29 2007/05/27 14:17:30 amosjeffries Exp $ * * DEBUG: section 5 Socket Functions * AUTHOR: Harvest Derived @@ -234,10 +234,9 @@ // defaults given by client char *host; - u_short port; - struct IN_ADDR in_addr; + IPAddress default_addr; - IPAddress S; // Sockaddr for live data link ?? + IPAddress S; CallBack callback; int fd; @@ -847,6 +846,17 @@ } +void +comm_set_v6only(int fd, int tos) +{ +#ifdef IPV6_V6ONLY + if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, (char *) &tos, sizeof(int)) < 0) { + debugs(50, 1, "comm_open: setsockopt(IPV6_V6ONLY) on FD " << fd << ": " << xstrerror()); + } +#else + debugs(50, 0, "comm_open: setsockopt(IPV6_V6ONLY) not supported on this platform"); +#endif /* sockopt */ +} /* Create a socket. Default is blocking, stream (TCP) socket. IO_TYPE * is OR of flags specified in defines.h:COMM_* */ @@ -895,23 +905,12 @@ tos = TOS; } -#if USE_IPV6 && USE_IPV6_SPLITSTACK - -# ifdef IPV6_V6ONLY +#if USE_IPV6_SPLITSTACK - if( addr.IsIPv6() ) { - if (setsockopt(new_socket, IPPROTO_IPV6, IPV6_V6ONLY, (char *) &tos, sizeof(int)) < 0) { - debugs(50, 1, "comm_open: setsockopt(IP_TOS) on FD " << new_socket << ": " << xstrerror()); - } - } - // else not needed on IPv4 socket ?? (no IPv4 option anyway) + if( addr.IsIPv6() ) + comm_set_v6only(new_socket, tos); -# else - - debugs(50, 0, "comm_open: setsockopt(IPV6_V6ONLY) not supported on this platform"); - -# endif /* sockopt */ -#endif /* stack available */ +#endif /* update fdstat */ debugs(5, 5, "comm_open: FD " << new_socket << " is a new socket"); @@ -1007,7 +1006,7 @@ cs = new ConnectStateData; cs->fd = fd; cs->host = xstrdup(host); - cs->port = port; + cs->default_addr.SetPort(port); cs->callback = CallBack(callback, data); comm_add_close_handler(fd, commConnectFree, cs); ipcache_nbgethostbyname(host, commConnectDnsHandle, cs); @@ -1033,8 +1032,7 @@ assert(ia->cur < ia->count); -/* FIXME INET6 : drop temp conversion */ struct in_addr tmp; ia->in_addrs[ia->cur].GetInAddr(tmp); - cs->in_addr = tmp; + cs->default_addr = ia->in_addrs[ia->cur]; if (Config.onoff.balance_on_multiple_ip) ipcacheCycleAddr(cs->host, NULL); @@ -1150,15 +1148,16 @@ return 0; } -// FIXME INET6 : duplicate the socket V6ONLY logic from comm_openex() here. + if (F->tos) + comm_set_tos(fd, F->tos); -#ifdef IP_TOS - if (F->tos) { - if (setsockopt(fd, IPPROTO_IP, IP_TOS, (char *) &F->tos, sizeof(int)) < 0) - debugs(50, 1, "commResetFD: setsockopt(IP_TOS) on FD " << fd << ": " << xstrerror()); - } +#if USE_IPV6_SPLITSTACK + + if( F->local_addr.IsIPv6() ) + comm_set_v6only(fd, F->tos); #endif + copyFDFlags (fd, F); return 1; @@ -1202,8 +1201,9 @@ void ConnectStateData::defaults() { - S = in_addr; - S.SetPort(port); /* port is HS */ +// S = in_addr; +// S.SetPort(port); /* port is HS */ +/*AYJ*/ S = default_addr; } void