From: Amos Jeffries Date: Fri, 18 Apr 2014 18:44:12 +0000 (-0600) Subject: Bug 3982: EUI logging and helpers show blank MAC address X-Git-Tag: SQUID_3_4_4_1~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1e7642ece0dc2fce8cb4803bd8820ef12ec0e0ae;p=thirdparty%2Fsquid.git Bug 3982: EUI logging and helpers show blank MAC address Also, * improved debugging of EUI processing. * fixed code correctness in EUI class definitions --- diff --git a/src/comm/TcpAcceptor.cc b/src/comm/TcpAcceptor.cc index 33cf3fbd7f..0e703024fd 100644 --- a/src/comm/TcpAcceptor.cc +++ b/src/comm/TcpAcceptor.cc @@ -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 diff --git a/src/eui/Eui48.cc b/src/eui/Eui48.cc index d7d9ab7a78..aecff67abf 100644 --- a/src/eui/Eui48.cc +++ b/src/eui/Eui48.cc @@ -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; diff --git a/src/eui/Eui48.h b/src/eui/Eui48.h index c46172cc95..93e8de5dd8 100644 --- a/src/eui/Eui48.h +++ b/src/eui/Eui48.h @@ -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. diff --git a/src/eui/Eui64.cc b/src/eui/Eui64.cc index f0cb3fff59..1c98299e37 100644 --- a/src/eui/Eui64.cc +++ b/src/eui/Eui64.cc @@ -18,8 +18,12 @@ 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(); diff --git a/src/eui/Eui64.h b/src/eui/Eui64.h index ec318201d9..f7b6f4b39c 100644 --- a/src/eui/Eui64.h +++ b/src/eui/Eui64.h @@ -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.