--------------------- PatchSet 4735 Date: 2007/06/14 11:40:30 Author: amosjeffries Branch: squid3-ipv6 Tag: (none) Log: Cleanup conversion in IPInterception Members: src/IPInterception.cc:1.4.4.6->1.4.4.7 Index: squid3/src/IPInterception.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/IPInterception.cc,v retrieving revision 1.4.4.6 retrieving revision 1.4.4.7 diff -u -r1.4.4.6 -r1.4.4.7 --- squid3/src/IPInterception.cc 27 May 2007 13:18:07 -0000 1.4.4.6 +++ squid3/src/IPInterception.cc 14 Jun 2007 11:40:30 -0000 1.4.4.7 @@ -1,6 +1,6 @@ /* - * $Id: IPInterception.cc,v 1.4.4.6 2007/05/27 13:18:07 amosjeffries Exp $ + * $Id: IPInterception.cc,v 1.4.4.7 2007/06/14 11:40:30 amosjeffries Exp $ * * DEBUG: section 89 NAT / IP Interception * AUTHOR: Robert Collins @@ -198,7 +198,6 @@ #elif LINUX_NETFILTER int - clientNatLookup(int fd, const IPAddress &me, const IPAddress &peer, IPAddress &dst) { dst = me; @@ -206,13 +205,14 @@ if( !peer.IsIPv4() ) return -1; static time_t last_reported = 0; - socklen_t sock_sz = sizeof(struct sockaddr_in); - struct sockaddr_in lookup; + struct addrinfo *lookup = NULL; - dst.GetSockAddr(lookup); + dst.GetAddrInfo(lookup,AF_INET); - if (getsockopt(fd, SOL_IP, SO_ORIGINAL_DST, &lookup, &sock_sz) != 0) + if (getsockopt(fd, SOL_IP, SO_ORIGINAL_DST, &lookup->ai_addr, &lookup->ai_addrlen) != 0) { + dst.FreeAddrInfo(lookup); + if (squid_curtime - last_reported > 60) { debugs(89, 1, "clientNatLookup: NF getsockopt(SO_ORIGINAL_DST) failed: " << xstrerror()); last_reported = squid_curtime; @@ -220,7 +220,9 @@ return -1; } - dst = lookup; + dst = *lookup; + + dst.FreeAddrInfo(lookup); debugs(89, 5, "clientNatLookup: addr = " << dst << ""); @@ -263,7 +265,7 @@ peer.GetInAddr(nl.saddr.v4); nl.sport = htons(peer.GetPort()); - me.GetINAddr(nl.daddr.v4); + me.GetInAddr(nl.daddr.v4); nl.dport = htons(me.GetPort()); nl.af = AF_INET; @@ -300,17 +302,30 @@ int clientNatLookup(int fd, const IPAddress &me, const IPAddress &peer, IPAddress &dst) { - int ret; - struct sockaddr_in s; - int slen = sizeof(struct sockaddr_in); - - ret = getsockname(fd, (struct sockaddr *) &s, (socklen_t * )&slen); - if (ret < 0) { - debugs(89, 1, "clientNatLookup: getpeername failed (fd " << fd << "), errstr " << xstrerror()); - return -1; - } - *dst = s; - return 0; + int ret; + struct addrinfo *lookup = NULL; + + if( !me.IsIPv4() ) return -1; + if( !peer.IsIPv4() ) return -1; + + dst.GetAddrInfo(lookup,AF_INET); + + ret = getsockname(fd, lookup->ai_addr, &lookup->ai_addrlen); + + if (ret < 0) { + + dst.FreeAddrInfo(lookup); + + debugs(89, 1, "clientNatLookup: getpeername failed (fd " << fd << "), errstr " << xstrerror()); + + return -1; + } + + dst = *lookup; + + dst.FreeAddrInfo(lookup); + + return 0; } #else