]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Polish: better debugs for IPFilter NAT
authorAmos Jeffries <squid3@treenet.co.nz>
Thu, 22 Dec 2011 07:31:30 +0000 (00:31 -0700)
committerAmos Jeffries <squid3@treenet.co.nz>
Thu, 22 Dec 2011 07:31:30 +0000 (00:31 -0700)
src/ip/Intercept.cc

index 07fecda0311ae82aefcf043efa93fe13afb9263b..30ebd5d9d591f329f1313dcc85cc24c3f0cb7580 100644 (file)
@@ -184,28 +184,18 @@ Ip::Intercept::IpfInterception(const Comm::ConnectionPointer &newConn, int silen
 {
 #if IPF_TRANSPARENT  /* --enable-ipf-transparent */
 
-#if defined(IPFILTER_VERSION) && (IPFILTER_VERSION >= 4000027)
-    struct ipfobj obj;
-#else
-    static int siocgnatl_cmd = SIOCGNATL & 0xff;
-#endif
     struct natlookup natLookup;
     static int natfd = -1;
     int x;
 
-#if defined(IPFILTER_VERSION) && (IPFILTER_VERSION >= 4000027)
-
-    obj.ipfo_rev = IPFILTER_VERSION;
-    obj.ipfo_size = sizeof(natLookup);
-    obj.ipfo_ptr = &natLookup;
-    obj.ipfo_type = IPFOBJ_NATLOOKUP;
-    obj.ipfo_offset = 0;
-#endif
-
+    // all fields must be set to 0
+    memset(natLookup, 0, sizeof(natLookup));
+    // for NAT lookup set local and remote IP:port's
     natLookup.nl_inport = htons(newConn->local.GetPort());
     newConn->local.GetInAddr(natLookup.nl_inip);
     natLookup.nl_outport = htons(newConn->remote.GetPort());
     newConn->remote.GetInAddr(natLookup.nl_outip);
+    // ... and the TCP flag
     natLookup.nl_flags = IPN_TCP;
 
     if (natfd < 0) {
@@ -223,13 +213,20 @@ Ip::Intercept::IpfInterception(const Comm::ConnectionPointer &newConn, int silen
 
     if (natfd < 0) {
         if (!silent) {
-            debugs(89, DBG_IMPORTANT, HERE << "NAT open failed: " << xstrerror());
+            debugs(89, DBG_IMPORTANT, "IPF (IPFilter) NAT open failed: " << xstrerror());
             lastReported_ = squid_curtime;
             return false;
         }
     }
 
 #if defined(IPFILTER_VERSION) && (IPFILTER_VERSION >= 4000027)
+    struct ipfobj obj;
+    memset(&obj, 0, sizeof(obj));
+    obj.ipfo_rev = IPFILTER_VERSION;
+    obj.ipfo_size = sizeof(natLookup);
+    obj.ipfo_ptr = &natLookup;
+    obj.ipfo_type = IPFOBJ_NATLOOKUP;
+
     x = ioctl(natfd, SIOCGNATL, &obj);
 #else
     /*
@@ -239,6 +236,7 @@ Ip::Intercept::IpfInterception(const Comm::ConnectionPointer &newConn, int silen
     * put something in configure and use ifdefs here, but
     * this seems simpler.
     */
+    static int siocgnatl_cmd = SIOCGNATL & 0xff;
     if (63 == siocgnatl_cmd) {
         struct natlookup *nlp = &natLookup;
         x = ioctl(natfd, SIOCGNATL, &nlp);
@@ -250,7 +248,7 @@ Ip::Intercept::IpfInterception(const Comm::ConnectionPointer &newConn, int silen
     if (x < 0) {
         if (errno != ESRCH) {
             if (!silent) {
-                debugs(89, DBG_IMPORTANT, HERE << "NAT lookup failed: ioctl(SIOCGNATL)");
+                debugs(89, DBG_IMPORTANT, "IPF (IPFilter) NAT lookup failed: ioctl(SIOCGNATL) (v=" << IPFILTER_VERSION << "): " << xstrerror());
                 lastReported_ = squid_curtime;
             }