]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
SetPort(0) on right address
authorAmos Jeffries <squid3@treenet.co.nz>
Mon, 22 Sep 2008 21:55:15 +0000 (09:55 +1200)
committerAmos Jeffries <squid3@treenet.co.nz>
Mon, 22 Sep 2008 21:55:15 +0000 (09:55 +1200)
src/IPInterception.cc
src/client_side.cc

index c51a8e21abeb747ff30a45ce087d97c275a0e4d0..e5be35368ab380c54c4d9997497a12a2757d05a5 100644 (file)
@@ -155,7 +155,7 @@ IPIntercept::NetfilterInterception(int fd, const IPAddress &me, IPAddress &dst,
 }
 
 int
-IPIntercept::NetfilterTransparent(int fd, const IPAddress &me, IPAddress &dst, int silent)
+IPIntercept::NetfilterTransparent(int fd, const IPAddress &me, IPAddress &client, int silent)
 {
 #if LINUX_NETFILTER
 
@@ -163,7 +163,7 @@ IPIntercept::NetfilterTransparent(int fd, const IPAddress &me, IPAddress &dst, i
      * We will simply attempt a bind outgoing on our own IP.
      */
     if(fd_table[fd].flags.transparent) {
-        dst.SetPort(0); // allow random outgoing port to prevent address clashes
+        client.SetPort(0); // allow random outgoing port to prevent address clashes
         return 0;
     }
 #endif
@@ -203,10 +203,10 @@ IPIntercept::IPFWInterception(int fd, const IPAddress &me, IPAddress &dst, int s
 }
 
 int
-IPIntercept::NatLookup(int fd, const IPAddress &me, const IPAddress &peer, IPAddress &dst)
+IPIntercept::NatLookup(int fd, const IPAddress &me, const IPAddress &peer, IPAddress &client, IPAddress &dst)
 {
 #if IPF_TRANSPARENT  /* --enable-ipf-transparent */
-    dst = me;
+    client = me;
     if( !me.IsIPv4() ) return -1;
     if( !peer.IsIPv4() ) return -1;
 
@@ -302,9 +302,9 @@ IPIntercept::NatLookup(int fd, const IPAddress &me, const IPAddress &peer, IPAdd
     } else
     {
         if (me != natLookup.nl_realip) {
-            dst = natLookup.nl_realip;
+            client = natLookup.nl_realip;
 
-            dst.SetPort(ntohs(natLookup.nl_realport));
+            client.SetPort(ntohs(natLookup.nl_realport));
         }
         // else. we already copied it.
 
@@ -319,7 +319,8 @@ IPIntercept::NatLookup(int fd, const IPAddress &me, const IPAddress &peer, IPAdd
      * This allows us to perform a nice clean failover sequence for them.
      */
 
-    dst = me;
+    client = me;
+    dst = peer;
 
     if( !me.IsIPv4()   ) return -1;
     if( !peer.IsIPv4() ) return -1;
@@ -333,8 +334,8 @@ IPIntercept::NatLookup(int fd, const IPAddress &me, const IPAddress &peer, IPAdd
 #endif
 
     if(intercept_active) {
-        if( NetfilterInterception(fd, me, dst, silent) == 0) return 0;
-        if( IPFWInterception(fd, me, dst, silent) == 0) return 0;
+        if( NetfilterInterception(fd, me, client, silent) == 0) return 0;
+        if( IPFWInterception(fd, me, client, silent) == 0) return 0;
     }
     if(transparent_active) {
         if( NetfilterTransparent(fd, me, dst, silent) == 0) return 0;
@@ -364,7 +365,7 @@ IPIntercept::NatLookup(int fd, const IPAddress &me, const IPAddress &peer, IPAdd
 
     }
 
-    dst.SetEmpty();
+    client.SetEmpty();
 
     memset(&nl, 0, sizeof(struct pfioc_natlook));
     peer.GetInAddr(nl.saddr.v4);
@@ -393,8 +394,8 @@ IPIntercept::NatLookup(int fd, const IPAddress &me, const IPAddress &peer, IPAdd
     } else
     {
         int natted = (me != nl.rdaddr.v4);
-        dst = nl.rdaddr.v4;
-        dst.SetPort(ntohs(nl.rdport));
+        client = nl.rdaddr.v4;
+        client.SetPort(ntohs(nl.rdport));
 
         if (natted)
             return 0;
index a27f6676b1cc11c5ac7bfc89ddd2906dd42ac19f..202a1b502e4b792f54fdc895e70aa22efd396796 100644 (file)
@@ -2772,10 +2772,11 @@ connStateCreate(const IPAddress &peer, const IPAddress &me, int fd, http_port_li
     result->port = cbdataReference(port);
 
     if(port->intercepted || port->spoof_client_ip) {
-        IPAddress dst;
+        IPAddress client, dst;
 
-        if (IPInterceptor.NatLookup(fd, me, peer, dst) == 0) {
-            result->me = dst; /* XXX This should be moved to another field */
+        if (IPInterceptor.NatLookup(fd, me, peer, client, dst) == 0) {
+            result->me = client;
+            result->peer = dst;
             result->transparent(true);
         }
     }