]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Bug 3982: EUI logging and helpers show blank MAC address
authorAmos Jeffries <squid3@treenet.co.nz>
Fri, 18 Apr 2014 18:44:12 +0000 (12:44 -0600)
committerAmos Jeffries <squid3@treenet.co.nz>
Fri, 18 Apr 2014 18:44:12 +0000 (12:44 -0600)
Also,
 * improved debugging of EUI processing.
 * fixed code correctness in EUI class definitions

src/comm/TcpAcceptor.cc
src/eui/Eui48.cc
src/eui/Eui48.h
src/eui/Eui64.cc
src/eui/Eui64.h

index 33cf3fbd7fe01591453c01763a16cf0341736119..0e703024fdafbca3967ed53de2e1f937169d098e 100644 (file)
@@ -388,10 +388,10 @@ Comm::TcpAcceptor::oldAccept(Comm::ConnectionPointer &details)
 
 #if USE_SQUID_EUI
     if (Eui::TheConfig.euiLookup) {
-        if (conn->remote.isIPv4()) {
-            conn->remoteEui48.lookup(conn->remote);
-        } else if (conn->remote.isIPv6()) {
-            conn->remoteEui64.lookup(conn->remote);
+        if (details->remote.isIPv4()) {
+            details->remoteEui48.lookup(details->remote);
+        } else if (details->remote.isIPv6()) {
+            details->remoteEui64.lookup(details->remote);
         }
     }
 #endif
index d7d9ab7a785f1ea9375f7a7d95e2505e39661816..aecff67abf895174aa78b8399c4088acc327b4a5 100644 (file)
@@ -135,18 +135,23 @@ Eui::Eui48::decode(const char *asc)
     eui[3] = (u_char) a4;
     eui[4] = (u_char) a5;
     eui[5] = (u_char) a6;
+
+    debugs(28, 4, "id=" << (void*)this << " decoded " << asc);
     return true;
 }
 
 bool
 Eui::Eui48::encode(char *buf, const int len)
 {
-    if (len < SZ_EUI48_BUF) return false;
+    if (len < SZ_EUI48_BUF)
+        return false;
 
     snprintf(buf, len, "%02x:%02x:%02x:%02x:%02x:%02x",
              eui[0] & 0xff, eui[1] & 0xff,
              eui[2] & 0xff, eui[3] & 0xff,
              eui[4] & 0xff, eui[5] & 0xff);
+
+    debugs(28, 4, "id=" << (void*)this << " encoded " << buf);
     return true;
 }
 
@@ -154,9 +159,6 @@ Eui::Eui48::encode(char *buf, const int len)
 bool
 Eui::Eui48::lookup(const Ip::Address &c)
 {
-#if !_SQUID_WINDOWS_
-#endif /* !_SQUID_WINDOWS_ */
-
     Ip::Address ipAddr = c;
     ipAddr.port(0);
 
@@ -198,6 +200,7 @@ Eui::Eui48::lookup(const Ip::Address &c)
     ipAddr.getSockAddr(*sa);
 
     /* Query ARP table */
+    debugs(28, 4, "id=" << (void*)this << " query ARP table");
     if (ioctl(tmpSocket, SIOCGARP, &arpReq) != -1) {
         /* Skip non-ethernet interfaces */
         close(tmpSocket);
@@ -207,7 +210,7 @@ Eui::Eui48::lookup(const Ip::Address &c)
             return false;
         }
 
-        debugs(28, 4, "Got address "<< std::setfill('0') << std::hex <<
+        debugs(28, 4, "id=" << (void*)this << " got address "<< std::setfill('0') << std::hex <<
                std::setw(2) << (arpReq.arp_ha.sa_data[0] & 0xff)  << ":" <<
                std::setw(2) << (arpReq.arp_ha.sa_data[1] & 0xff)  << ":" <<
                std::setw(2) << (arpReq.arp_ha.sa_data[2] & 0xff)  << ":" <<
@@ -240,20 +243,22 @@ Eui::Eui48::lookup(const Ip::Address &c)
 
     /* Attempt ARP lookup on each interface */
     offset = 0;
-
+    debugs(28, 4, "id=" << (void*)this << " query ARP on each interface (" << ifc.ifc_len << " found)");
     while (offset < ifc.ifc_len) {
 
         ifr = (struct ifreq *) (ifbuffer + offset);
         offset += sizeof(*ifr);
-        /* Skip loopback and aliased interfaces */
 
-        if (0 == strncmp(ifr->ifr_name, "lo", 2))
+        debugs(28, 4, "id=" << (void*)this << " found interface " << ifr->ifr_name);
+
+        /* Skip loopback and aliased interfaces */
+        if (!strncmp(ifr->ifr_name, "lo", 2))
             continue;
 
-        if (NULL != strchr(ifr->ifr_name, ':'))
+        if (strchr(ifr->ifr_name, ':'))
             continue;
 
-        debugs(28, 4, "Looking up ARP address for " << ipAddr << " on " << ifr->ifr_name);
+        debugs(28, 4, "id=" << (void*)this << " looking up ARP address for " << ipAddr << " on " << ifr->ifr_name);
 
         /* Set up structures for ARP lookup */
 
@@ -284,10 +289,12 @@ Eui::Eui48::lookup(const Ip::Address &c)
         }
 
         /* Skip non-ethernet interfaces */
-        if (arpReq.arp_ha.sa_family != ARPHRD_ETHER)
+        if (arpReq.arp_ha.sa_family != ARPHRD_ETHER) {
+            debugs(28, 4, "id=" << (void*)this << "... not an Ethernet interface");
             continue;
+        }
 
-        debugs(28, 4, "Got address "<< std::setfill('0') << std::hex <<
+        debugs(28, 4, "id=" << (void*)this << " got address "<< std::setfill('0') << std::hex <<
                std::setw(2) << (arpReq.arp_ha.sa_data[0] & 0xff)  << ":" <<
                std::setw(2) << (arpReq.arp_ha.sa_data[1] & 0xff)  << ":" <<
                std::setw(2) << (arpReq.arp_ha.sa_data[2] & 0xff)  << ":" <<
@@ -528,7 +535,7 @@ Eui::Eui48::lookup(const Ip::Address &c)
     /*
      * Address was not found on any interface
      */
-    debugs(28, 3, HERE << ipAddr << " NOT found");
+    debugs(28, 3, "id=" << (void*)this << ' ' << ipAddr << " NOT found");
 
     clear();
     return false;
index c46172cc9581edb088c665971a7891d19774d9ed..93e8de5dd877aa4f7f19dcfc8eed4df122a83881 100644 (file)
@@ -27,9 +27,9 @@ class Eui48
 {
 
 public:
-    Eui48() { clear(); };
-    Eui48(const Eui48 &t) { memcpy(this, &t, sizeof(Eui48)); };
-    ~Eui48() {};
+    Eui48() { clear(); }
+    Eui48(const Eui48 &t) { memcpy(this, &t, sizeof(Eui48)); }
+    ~Eui48() {}
 
     const unsigned char *get(void);
 
@@ -38,9 +38,9 @@ public:
         if (len < SZ_EUI48_BUF) clear();
         memcpy(eui, src, len);
         return true;
-    };
+    }
 
-    void clear() { memset(eui, 0, SZ_EUI48_BUF); };
+    void clear() { memset(eui, 0, SZ_EUI48_BUF); }
 
     /**
      * Decode an ascii representation of an EUI-48 ethernet address.
index f0cb3fff595615e012772bf0c2f4097a0f7dd804..1c98299e37981348fe51bde4bd7e64852128b952 100644 (file)
 bool
 Eui::Eui64::decode(const char *asc)
 {
-    if (eui64_aton(asc, (struct eui64 *)eui) != 0) return false;
+    if (eui64_aton(asc, (struct eui64 *)eui) != 0) {
+       debugs(28, 4, "id=" << (void*)this << " decode fail on " << asc);
+       return false;
+    }
 
+    debugs(28, 4, "id=" << (void*)this << " ATON decoded " << asc);
     return true;
 }
 
@@ -31,6 +35,7 @@ Eui::Eui64::encode(char *buf, const int len)
     snprintf(buf, len, "%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x",
              eui[0], eui[1], eui[2], eui[3],
              eui[4], eui[5], eui[6], eui[7]);
+    debugs(28, 4, "id=" << (void*)this << " encoded " << buf);
     return true;
 }
 
@@ -39,7 +44,8 @@ bool
 Eui::Eui64::lookup(const Ip::Address &c)
 {
     /* try to short-circuit slow OS lookups by using SLAAC data */
-    if (lookupSlaac(c)) return true;
+    if (lookupSlaac(c))
+        return true;
 
     // find EUI-64 some other way. NDP table lookup?
     return lookupNdp(c);
@@ -49,15 +55,18 @@ bool
 Eui::Eui64::lookupSlaac(const Ip::Address &c)
 {
     /* RFC 4291 Link-Local unicast addresses which contain SLAAC - usually trustable. */
-    if (c.isSiteLocal6() && c.isSiteLocalAuto() ) {
+    if (c.isSiteLocal6() && c.isSiteLocalAuto()) {
 
         // strip the final 64 bits of the address...
         struct in6_addr tmp;
         c.getInAddr(tmp);
         memcpy(eui, &(tmp.s6_addr[8]), SZ_EUI64_BUF);
-
+        debugs(28, 4, "id=" << (void*)this << " SLAAC decoded " << c);
         return true;
     }
+
+    debugs(28, 4, "id=" << (void*)this << " SLAAC fail on " << c << " SL-6="
+           << (c.isSiteLocal6()?'T':'F') << " AAC-6=" << (c.isSiteLocalAuto()?'T':'F'));
     return false;
 }
 
@@ -73,7 +82,7 @@ Eui::Eui64::lookupNdp(const Ip::Address &c)
     /*
      * Address was not found on any interface
      */
-    debugs(28, 3, HERE << c << " NOT found");
+    debugs(28, 3, "id=" << (void*)this << ' ' << c << " NOT found");
 #endif /* 0 */
 
     clear();
index ec318201d906f89df7d43f08a0ce43aab5ecee47..f7b6f4b39c90d912eda8b32e22e64c17255358f6 100644 (file)
@@ -34,9 +34,9 @@ class Eui64
 {
 
 public:
-    Eui64() { clear(); };
-    Eui64(const Eui64 &t) { memcpy(this, &t, sizeof(Eui64)); };
-    ~Eui64() {};
+    Eui64() { clear(); }
+    Eui64(const Eui64 &t) { memcpy(this, &t, sizeof(Eui64)); }
+    ~Eui64() {}
 
     const unsigned char *get(void);
 
@@ -45,9 +45,9 @@ public:
         if (len < SZ_EUI64_BUF) clear();
         memcpy(eui, src, len);
         return true;
-    };
+    }
 
-    void clear() { memset(eui, 0, SZ_EUI64_BUF); };
+    void clear() { memset(eui, 0, SZ_EUI64_BUF); }
 
     /**
      * Decode an ascii representation of an EUI-64 address.