--------------------- PatchSet 5970 Date: 2007/10/16 13:35:08 Author: amosjeffries Branch: squid3-ipv6 Tag: (none) Log: Add ICMPPinger for pinger side of squid-pinger link. This is the last of the major changes. BUT none of them are sufficiently tested. I recommend --disable-icmp unless you want to aid the test of it. Members: NOTES-IPv6:1.1.2.70->1.1.2.71 src/ICMP.h:1.1.2.6->1.1.2.7 src/ICMPSquid.cc:1.1.2.2->1.1.2.3 src/ICMPSquid.h:1.1.2.1->1.1.2.2 src/ICMPv4.cc:1.1.2.3->1.1.2.4 src/ICMPv4.h:1.1.2.3->1.1.2.4 src/ICMPv6.cc:1.1.2.1->1.1.2.2 src/ICMPv6.h:1.1.2.1->1.1.2.2 src/Makefile.am:1.58.2.24->1.58.2.25 src/icmp.cc:1.8.8.16->1.8.8.17 src/neighbors.cc:1.23.4.24->1.23.4.25 src/pinger.cc:1.9.8.11->1.9.8.12 src/structs.h:1.66.2.33->1.66.2.34 Index: squid3/NOTES-IPv6 =================================================================== RCS file: /cvsroot/squid-sf//squid3/Attic/NOTES-IPv6,v retrieving revision 1.1.2.70 retrieving revision 1.1.2.71 diff -u -r1.1.2.70 -r1.1.2.71 --- squid3/NOTES-IPv6 10 Oct 2007 01:25:00 -0000 1.1.2.70 +++ squid3/NOTES-IPv6 16 Oct 2007 13:35:08 -0000 1.1.2.71 @@ -1,4 +1,4 @@ -$Id: NOTES-IPv6,v 1.1.2.70 2007/10/10 01:25:00 amosjeffries Exp $ +$Id: NOTES-IPv6,v 1.1.2.71 2007/10/16 13:35:08 amosjeffries Exp $ NP: Any problems with this version of squid please contact squid3@treenet.co.nz for assistance. @@ -7,6 +7,9 @@ Any volunteers welcome. For the rest cache_dir's should be built from an empty state in the usual manner. +NP: pinger has had major alteration. If you just want to run this branch (no testing). + I recommend --disable-icmp until its had at the very least some unit-tests created. + IPv6 NEW FEATURES: Index: squid3/src/ICMP.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/Attic/ICMP.h,v retrieving revision 1.1.2.6 retrieving revision 1.1.2.7 diff -u -r1.1.2.6 -r1.1.2.7 --- squid3/src/ICMP.h 8 Oct 2007 13:50:28 -0000 1.1.2.6 +++ squid3/src/ICMP.h 16 Oct 2007 13:35:08 -0000 1.1.2.7 @@ -1,5 +1,5 @@ /* - * $Id: ICMP.h,v 1.1.2.6 2007/10/08 13:50:28 amosjeffries Exp $ + * $Id: ICMP.h,v 1.1.2.7 2007/10/16 13:35:08 amosjeffries Exp $ * * DEBUG: section 37 ICMP Routines * AUTHOR: Duane Wessels, Amos Jeffries @@ -53,6 +53,28 @@ #endif /* ALLOW_SOURCE_PING */ +#if USE_ICMP + +/* This is a line-data format struct. DO NOT alter. */ +struct pingerEchoData +{ + IPAddress to; + unsigned char opcode; + int psize; + char payload[PINGER_PAYLOAD_SZ]; +}; + +/* This is a line-data format struct. DO NOT alter. */ +struct pingerReplyData +{ + IPAddress from; + unsigned char opcode; + int rtt; + int hops; + int psize; + char payload[PINGER_PAYLOAD_SZ]; +}; + struct icmpEchoData { struct timeval tv; @@ -62,15 +84,19 @@ SQUIDCEXTERN int icmp_pkts_sent; +#endif /* USE_ICMP */ + + /** * Implements the squid interface to access ICMP operations * * Child implementations define specific parts of these operations * using these methods as a naming and parameter template. * - * icmp - implements the squid-side of pinger communications - * icmp4 - implements pinger helper for ICMPv4 - * icmp6 - implements pinger helper for ICMPv6 + * ICMPSquid - implements the squid side of squid-pinger interface + * ICMPPinger - implements the pinger side of the squid-pinger interface + * ICMPv4 - implements pinger helper for ICMPv4 + * ICMPv6 - implements pinger helper for ICMPv6 */ class ICMP { @@ -93,23 +119,21 @@ virtual void Recv(void) =0; protected: - /// Send ICMP - virtual void Send(pingerEchoData * pkt, int len) =0; + /* shared internal methods */ + /// Calculate a packet checksum int CheckSum(unsigned short *ptr, int size); + + /// calculate the hop-count from packet TTL int ipHops(int ttl); + /// Log the packet. + void Log(const IPAddress &addr, const u_int8_t type, const char* pkt_str, const int rtt, const int hops); + /* no use wasting memory */ int icmp_sock; int icmp_ident; #endif /* USE_ICMP */ }; -// Glue for pinger functions use by child engines -// To be removed as soon as no longer needed. -#if SQUID_HELPER -SQUIDCEXTERN void pingerLog(const IPAddress &addr, const u_int8_t type, const char* pkt_str, const int rtt, const int hops); -SQUIDCEXTERN void pingerSendtoSquid(pingerReplyData * preply); -#endif - #endif Index: squid3/src/ICMPSquid.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/Attic/ICMPSquid.cc,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- squid3/src/ICMPSquid.cc 7 Oct 2007 11:37:20 -0000 1.1.2.2 +++ squid3/src/ICMPSquid.cc 16 Oct 2007 13:35:08 -0000 1.1.2.3 @@ -1,5 +1,5 @@ /* - * $Id: ICMPSquid.cc,v 1.1.2.2 2007/10/07 11:37:20 amosjeffries Exp $ + * $Id: ICMPSquid.cc,v 1.1.2.3 2007/10/16 13:35:08 amosjeffries Exp $ * * DEBUG: section 37 ICMP Routines * AUTHOR: Duane Wessels, Amos Jeffries @@ -89,7 +89,7 @@ Send(&pecho, sizeof(pingerEchoData) - PINGER_PAYLOAD_SZ + len); } -// Callback to wrap the squid-side ICMP handler. +// static Callback to wrap the squid-side ICMP handler. static void icmpSquidRecv(int unused1, void *unused2) { @@ -201,17 +201,25 @@ #endif /* USE_ICMP */ #if ALLOW_SOURCE_PING -void +/** + \retval 1 SourcePing sent + \retval 0 ICMP not active. + \retval -1 An error occured. + */ +int ICMPSquid::SourcePing(IPAddress &to, const icp_common_t * header, const char *url) { #if USE_ICMP char *payload; int len; int ulen; - debugs(37, 3, "icmpSourcePing: '" << url << "'"); + debugs(37, 3, "ICMPSquid::SourcePing: '" << url << "'"); + + if(icmp_sock < 0) + return 0; if ((ulen = strlen(url)) > MAX_URL) - return; + return -1; payload = memAllocate(MEM_8K_BUF); @@ -227,6 +235,8 @@ memFree(payload, MEM_8K_BUF); +#else + return -1; #endif } Index: squid3/src/ICMPSquid.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/Attic/ICMPSquid.h,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- squid3/src/ICMPSquid.h 7 Oct 2007 06:19:56 -0000 1.1.2.1 +++ squid3/src/ICMPSquid.h 16 Oct 2007 13:35:08 -0000 1.1.2.2 @@ -1,5 +1,5 @@ /* - * $Id: ICMPSquid.h,v 1.1.2.1 2007/10/07 06:19:56 amosjeffries Exp $ + * $Id: ICMPSquid.h,v 1.1.2.2 2007/10/16 13:35:08 amosjeffries Exp $ * * DEBUG: section 37 ICMP Routines * AUTHOR: Duane Wessels, Amos Jeffries @@ -58,7 +58,7 @@ void DomainPing(IPAddress &to, const char *domain); #if ALLOW_SOURCE_PING - void SourcePing(IPAddress &to, const icp_common_t * header, const char *url); + int SourcePing(IPAddress &to, const icp_common_t * header, const char *url); void HandleSourcePing(const IPAddress &from, const char *buf); #endif @@ -67,7 +67,7 @@ virtual void Recv(void); private: - virtual void Send(pingerEchoData* pkt, int len); + void Send(pingerEchoData* pkt, int len); #endif }; Index: squid3/src/ICMPv4.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/Attic/ICMPv4.cc,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -u -r1.1.2.3 -r1.1.2.4 --- squid3/src/ICMPv4.cc 8 Oct 2007 13:50:28 -0000 1.1.2.3 +++ squid3/src/ICMPv4.cc 16 Oct 2007 13:35:08 -0000 1.1.2.4 @@ -1,5 +1,5 @@ /* - * $Id: ICMPv4.cc,v 1.1.2.3 2007/10/08 13:50:28 amosjeffries Exp $ + * $Id: ICMPv4.cc,v 1.1.2.4 2007/10/16 13:35:08 amosjeffries Exp $ * * DEBUG: section 42 ICMP Pinger program * AUTHOR: Duane Wessels, Amos Jeffries @@ -35,11 +35,13 @@ #define SQUID_HELPER 1 #include "squid.h" -#include "SquidTime.h" -#include "ICMPv4.h" #if USE_ICMP +#include "SquidTime.h" +#include "ICMPv4.h" +#include "ICMPPinger.h" + /* Native Windows port doesn't have netinet support, so we emulate it. At this time, Cygwin lacks icmp support in its include files, so we need to use the native Windows port definitions. @@ -217,13 +219,7 @@ 0, S->ai_addr, S->ai_addrlen); - pingerLog(to, ' ', NULL, 0, 0); -} - -void -ICMPv4::Send(pingerEchoData* unused1, int unused2) -{ - ; // Use SendEcho() instead. + Log(to, ' ', NULL, 0, 0); } void @@ -306,9 +302,9 @@ preply.psize = n - iphdrlen - (sizeof(icmpEchoData) - MAX_PKT4_SZ); - pingerSendtoSquid(&preply); + control.SendResult(preply, (sizeof(pingerReplyData) - MAX_PKT4_SZ + preply.psize) ); - pingerLog(preply.from, icmp->icmp_type, icmpPktStr[icmp->icmp_type], preply.rtt, preply.hops); + Log(preply.from, icmp->icmp_type, icmpPktStr[icmp->icmp_type], preply.rtt, preply.hops); } #endif /* USE_ICMP */ Index: squid3/src/ICMPv4.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/Attic/ICMPv4.h,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -u -r1.1.2.3 -r1.1.2.4 --- squid3/src/ICMPv4.h 8 Oct 2007 13:50:28 -0000 1.1.2.3 +++ squid3/src/ICMPv4.h 16 Oct 2007 13:35:08 -0000 1.1.2.4 @@ -1,5 +1,5 @@ /* - * $Id: ICMPv4.h,v 1.1.2.3 2007/10/08 13:50:28 amosjeffries Exp $ + * $Id: ICMPv4.h,v 1.1.2.4 2007/10/16 13:35:08 amosjeffries Exp $ * * DEBUG: section 37 ICMP Routines * AUTHOR: Duane Wessels, Amos Jeffries @@ -162,13 +162,14 @@ #if USE_ICMP virtual void SendEcho(IPAddress &, int, const char*, int); virtual void Recv(void); - -private: - virtual void Send(pingerEchoData* unused1, int unused2); - #endif }; -extern const char *icmpPktStr[]; +#if USE_ICMP && SQUID_HELPER + +/// pinger helper contains one of these as a global object. +SQUIDCEXTERN ICMPv4 icmp4; + +#endif /* USE_ICMP && SQUID_HELPER */ #endif Index: squid3/src/ICMPv6.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/Attic/ICMPv6.cc,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- squid3/src/ICMPv6.cc 8 Oct 2007 13:50:28 -0000 1.1.2.1 +++ squid3/src/ICMPv6.cc 16 Oct 2007 13:35:08 -0000 1.1.2.2 @@ -1,5 +1,5 @@ /* - * $Id: ICMPv6.cc,v 1.1.2.1 2007/10/08 13:50:28 amosjeffries Exp $ + * $Id: ICMPv6.cc,v 1.1.2.2 2007/10/16 13:35:08 amosjeffries Exp $ * * DEBUG: section 42 ICMP Pinger program * AUTHOR: Duane Wessels, Amos Jeffries @@ -39,6 +39,7 @@ #if USE_ICMP && USE_IPV6 #include "ICMPv6.h" +#include "ICMPPinger.h" // ICMPv6 OP-Codes // see http://www.iana.org/assignments/icmpv6-parameters @@ -191,13 +192,7 @@ 0, S->ai_addr, S->ai_addrlen); - pingerLog(to, 0, NULL, 0, 0); -} - -void -ICMPv6::Send(pingerEchoData* unused1, int unused2) -{ - assert(false); // shoudl be unused. + Log(to, 0, NULL, 0, 0); } /** @@ -265,9 +260,9 @@ preply.psize = n - iphdrlen - (sizeof(icmpEchoData) - MAX_PKT6_SZ); /* send results of the lookup back to squid.*/ - pingerSendtoSquid(&preply); + control.SendResult(preply, (sizeof(pingerReplyData) - MAX_PKT6_SZ + preply.psize) ); - pingerLog(preply.from, preply.opcode, + Log(preply.from, preply.opcode, ( preply.opcode&0x80 ? icmp6HighPktStr[(preply.opcode&0x7f)] : icmp6LowPktStr[(preply.opcode&0x7f)] ), preply.rtt, preply.hops); } Index: squid3/src/ICMPv6.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/Attic/ICMPv6.h,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- squid3/src/ICMPv6.h 8 Oct 2007 13:50:28 -0000 1.1.2.1 +++ squid3/src/ICMPv6.h 16 Oct 2007 13:35:08 -0000 1.1.2.2 @@ -1,5 +1,5 @@ /* - * $Id: ICMPv6.h,v 1.1.2.1 2007/10/08 13:50:28 amosjeffries Exp $ + * $Id: ICMPv6.h,v 1.1.2.2 2007/10/16 13:35:08 amosjeffries Exp $ * * DEBUG: section 37 ICMP Routines * AUTHOR: Duane Wessels, Amos Jeffries @@ -69,13 +69,16 @@ #if USE_ICMP virtual void SendEcho(IPAddress &, int, const char*, int); virtual void Recv(void); - -private: - virtual void Send(pingerEchoData* unused1, int unused2); - #endif }; +#if USE_ICMP && SQUID_HELPER + +/// pinger helper contains one of these as a global object. +SQUIDCEXTERN ICMPv6 icmp6; + +#endif /* USE_ICMP && SQUID_HELPER */ + #endif /* USE_IPV6 */ #endif /* _INCLUDE_ICMPV6_H */ Index: squid3/src/Makefile.am =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/Makefile.am,v retrieving revision 1.58.2.24 retrieving revision 1.58.2.25 diff -u -r1.58.2.24 -r1.58.2.25 --- squid3/src/Makefile.am 8 Oct 2007 13:50:28 -0000 1.58.2.24 +++ squid3/src/Makefile.am 16 Oct 2007 13:35:08 -0000 1.58.2.25 @@ -1,7 +1,7 @@ # # Makefile for the Squid Object Cache server # -# $Id: Makefile.am,v 1.58.2.24 2007/10/08 13:50:28 amosjeffries Exp $ +# $Id: Makefile.am,v 1.58.2.25 2007/10/16 13:35:08 amosjeffries Exp $ # # Uncomment and customize the following to suit your needs: # @@ -710,6 +710,8 @@ pinger_SOURCES = \ ICMP.h \ icmp.cc \ + ICMPPinger.h \ + ICMPPinger.cc \ ICMPv4.h \ ICMPv4.cc \ ICMPv6.h \ Index: squid3/src/icmp.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/icmp.cc,v retrieving revision 1.8.8.16 retrieving revision 1.8.8.17 diff -u -r1.8.8.16 -r1.8.8.17 --- squid3/src/icmp.cc 7 Oct 2007 06:19:57 -0000 1.8.8.16 +++ squid3/src/icmp.cc 16 Oct 2007 13:35:09 -0000 1.8.8.17 @@ -1,5 +1,5 @@ /* - * $Id: icmp.cc,v 1.8.8.16 2007/10/07 06:19:57 amosjeffries Exp $ + * $Id: icmp.cc,v 1.8.8.17 2007/10/16 13:35:09 amosjeffries Exp $ * * DEBUG: section 37 ICMP Routines * AUTHOR: Duane Wessels, Amos Jeffries @@ -102,4 +102,15 @@ return 256 - ttl; } +void +ICMP::Log(const IPAddress &addr, const u_int8_t type, const char* pkt_str, const int rtt, const int hops) +{ + debugs(42, 2, "pingerLog: " << std::setw(9) << current_time.tv_sec << + "." << std::setfill('0') << std::setw(6) << + current_time.tv_usec << " " << std::left << std::setfill(' ') << + std::setw(45) << addr << " " << type << + " " << std::setw(15) << pkt_str << " " << rtt << + "ms " << hops << " hops"); +} + #endif /* USE_ICMP */ Index: squid3/src/neighbors.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/neighbors.cc,v retrieving revision 1.23.4.24 retrieving revision 1.23.4.25 diff -u -r1.23.4.24 -r1.23.4.25 --- squid3/src/neighbors.cc 30 Jul 2007 03:17:59 -0000 1.23.4.24 +++ squid3/src/neighbors.cc 16 Oct 2007 13:35:09 -0000 1.23.4.25 @@ -1,6 +1,6 @@ /* - * $Id: neighbors.cc,v 1.23.4.24 2007/07/30 03:17:59 amosjeffries Exp $ + * $Id: neighbors.cc,v 1.23.4.25 2007/10/16 13:35:09 amosjeffries Exp $ * * DEBUG: section 15 Neighbor Routines * AUTHOR: Harvest Derived @@ -710,9 +710,7 @@ debugs(15, 6, "neighborsUdpPing: Source Ping: to " << host << " for '" << url << "'"); echo_hdr.reqnum = reqnum; - if (icmp_sock != -1) { - icmpSourcePing(ia->in_addrs[ia->cur], &echo_hdr, url); - } else { + if (icmpSourcePing(ia->in_addrs[ia->cur], &echo_hdr, url) <= 0) { to_addr.sin_family = AF_INET; to_addr.sin_addr = ia->in_addrs[ia->cur]; to_addr.sin_port = htons(echo_port); Index: squid3/src/pinger.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/pinger.cc,v retrieving revision 1.9.8.11 retrieving revision 1.9.8.12 diff -u -r1.9.8.11 -r1.9.8.12 --- squid3/src/pinger.cc 8 Oct 2007 13:50:28 -0000 1.9.8.11 +++ squid3/src/pinger.cc 16 Oct 2007 13:35:09 -0000 1.9.8.12 @@ -1,5 +1,5 @@ /* - * $Id: pinger.cc,v 1.9.8.11 2007/10/08 13:50:28 amosjeffries Exp $ + * $Id: pinger.cc,v 1.9.8.12 2007/10/16 13:35:09 amosjeffries Exp $ * * DEBUG: section 42 ICMP Pinger program * AUTHOR: Duane Wessels @@ -41,50 +41,22 @@ #include "ICMPv4.h" #include "ICMPv6.h" - -/* Native Windows port doesn't have netinet support, so we emulate it. - At this time, Cygwin lacks icmp support in its include files, so we need - to use the native Windows port definitions. - */ - -#ifndef _SQUID_WIN32_ - -#define PINGER_TIMEOUT 10 - -static int socket_from_squid = 0; -static int socket_to_squid = 1; - -#else /* _SQUID_WIN32_ */ - -#include "fde.h" +#include "ICMPPinger.h" #ifdef _SQUID_MSWIN_ #include #include +#include "fde.h" #define PINGER_TIMEOUT 5 -static int socket_to_squid = -1; -#define socket_from_squid socket_to_squid - -#else /* _SQUID_CYGWIN_ */ - -#define PINGER_TIMEOUT 10 - -static int socket_from_squid = 0; -static int socket_to_squid = 1; +/* windows uses the control socket for feedback to squid */ +#define LINK_TO_SQUID squid_link -#endif - -#endif /* _SQUID_MSWIN_ */ +// windows still requires WSAFD but there are too many dependancy problems +// to just link to win32.cc where it is normally defined. -int icmp_pkts_sent = 0; - -static void pingerOpen(void); -static void pingerClose(void); - -#ifdef _SQUID_MSWIN_ int Win32__WSAFDIsSet(int fd, fd_set FAR * set) { @@ -93,197 +65,24 @@ return __WSAFDIsSet(s, set); } -#endif - -// ICMP Engines are declared global here so they can call each other easily. -ICMPv4 icmp4; -#if USE_IPV6 -ICMPv6 icmp6; -#endif - - -void -pingerOpen(void) -{ - - struct protoent *proto = NULL; -#ifdef _SQUID_MSWIN_ - - WSADATA wsaData; - WSAPROTOCOL_INFO wpi; - char buf[sizeof(wpi)]; - int x; - - struct sockaddr_in PS; - - WSAStartup(2, &wsaData); - - getCurrentTime(); - _db_init(NULL, "ALL,1"); - setmode(0, O_BINARY); - setmode(1, O_BINARY); - x = read(0, buf, sizeof(wpi)); - - if (x < (int)sizeof(wpi)) { - getCurrentTime(); - debugs(42, 0, "pingerOpen: read: FD 0: " << xstrerror()); - write(1, "ERR\n", 4); - exit(1); - } - - xmemcpy(&wpi, buf, sizeof(wpi)); - - write(1, "OK\n", 3); - x = read(0, buf, sizeof(PS)); - - if (x < (int)sizeof(PS)) { - getCurrentTime(); - debugs(42, 0, "pingerOpen: read: FD 0: " << xstrerror()); - write(1, "ERR\n", 4); - exit(1); - } - - xmemcpy(&PS, buf, sizeof(PS)); -#endif - - if ((proto = getprotobyname("icmp")) == 0) { - debugs(42, 0, "pingerOpen: unknown protocol: icmp"); - exit(1); - } - - -#ifdef _SQUID_MSWIN_ - - socket_to_squid = - WSASocket(FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, - &wpi, 0, 0); - - if (socket_to_squid == -1) { - getCurrentTime(); - debugs(42, 0, "pingerOpen: WSASocket: " << xstrerror()); - write(1, "ERR\n", 4); - exit(1); - } - - x = connect(socket_to_squid, (struct sockaddr *) &PS, sizeof(PS)); - - if (SOCKET_ERROR == x) { - getCurrentTime(); - debugs(42, 0, "pingerOpen: connect: " << xstrerror()); - write(1, "ERR\n", 4); - exit(1); - } - - write(1, "OK\n", 3); - memset(buf, 0, sizeof(buf)); - x = recv(socket_to_squid, (void *) buf, sizeof(buf), 0); - - if (x < 3) { - debugs(42, 0, "icmpOpen: recv: " << xstrerror()); - exit(1); - } - - x = send(socket_to_squid, (const void *) buf, strlen(buf), 0); - - if (x < 3 || strncmp("OK\n", buf, 3)) { - debugs(42, 0, "icmpOpen: recv: " << xstrerror()); - exit(1); - } - - getCurrentTime(); - debugs(42, 0, "pinger: Squid socket opened"); -#endif -} - -void -pingerClose(void) -{ -#ifdef _SQUID_MSWIN_ - - shutdown(socket_to_squid, SD_BOTH); - close(socket_to_squid); - socket_to_squid = -1; -#endif - - icmp4.Close(); -#if USE_IPV6 - icmp6.Close(); -#endif -} - -void -pingerLog(const IPAddress &addr, const u_int8_t type, const char* pkt_str, const int rtt, const int hops) -{ - debugs(42, 2, "pingerLog: " << std::setw(9) << current_time.tv_sec << - "." << std::setfill('0') << std::setw(6) << - current_time.tv_usec << " " << std::left << std::setfill(' ') << - std::setw(45) << addr << " " << type << - " " << std::setw(15) << pkt_str << " " << rtt << - "ms " << hops << " hops"); -} -static int -pingerReadRequest(void) -{ - static pingerEchoData pecho; - int n; - int guess_size; - memset(&pecho, '\0', sizeof(pecho)); - n = recv(socket_from_squid, &pecho, sizeof(pecho), 0); - - if (n < 0) - return n; - - if (0 == n) { - /* EOF indicator */ - fprintf(stderr, "EOF encountered\n"); - errno = 0; - return -1; - } - - guess_size = n - (sizeof(pingerEchoData) - PINGER_PAYLOAD_SZ); - - if (guess_size != pecho.psize) { - fprintf(stderr, "size mismatch, guess=%d psize=%d\n", - guess_size, pecho.psize); - /* don't process this message, but keep running */ - return 0; - } +#else -#if USE_IPV6 - if(pecho.to.IsIPv6()) { - icmp6.SendEcho(pecho.to, - pecho.opcode, - pecho.payload, - pecho.psize); - } -#endif +#define PINGER_TIMEOUT 10 - if(pecho.to.IsIPv4()) { - icmp4.SendEcho(pecho.to, - pecho.opcode, - pecho.payload, - pecho.psize); - } +/* non-windows use STDOUT for feedback to squid */ +#define LINK_TO_SQUID 1 - return n; -} +#endif /* _SQUID_MSWIN_ */ -void -pingerSendtoSquid(pingerReplyData * preply) -{ +// ICMP Engines are declared global here so they can call each other easily. +ICMPPinger control; +ICMPv4 icmp4; #if USE_IPV6 - int len = sizeof(pingerReplyData) - MAX_PKT6_SZ + preply->psize; -#else - int len = sizeof(pingerReplyData) - MAX_PKT4_SZ + preply->psize; -#endif +ICMPv6 icmp6; +#endif /* USE_IPV6 */ - if (send(socket_to_squid, preply, len, 0) < 0) { - debugs(50, 0, "pinger: send: " << xstrerror()); - pingerClose(); - exit(1); - } -} +int icmp_pkts_sent = 0; int main(int argc, char *argv[]) @@ -302,6 +101,7 @@ */ int icmp4_worker = -1; int icmp6_worker = -1; + int squid_link = -1; icmp4_worker = icmp4.Open(); if(icmp4_worker < 0) { @@ -323,7 +123,13 @@ exit(1); } - pingerOpen(); + if( (squid_link = control.Open()) < 0) { + icmp4.Close(); +#if USE_IPV6 + icmp6.Close(); +#endif + exit(1); // fatal error if the control channel fails. + } setgid(getgid()); setuid(getuid()); @@ -341,21 +147,17 @@ FD_ZERO(&R); FD_SET(icmp4_worker, &R); FD_SET(icmp6_worker, &R); - FD_SET(socket_from_squid, &R); - x = select(socket_from_squid + 1, &R, NULL, NULL, &tv); + FD_SET(squid_link, &R); + x = select(squid_link + 1, &R, NULL, NULL, &tv); getCurrentTime(); if (x < 0) { - pingerClose(); + control.Close(); exit(1); } - if (FD_ISSET(socket_from_squid, &R)) - if (pingerReadRequest() < 0) { - debugs(42, 0, "Pinger exiting."); - pingerClose(); - exit(1); - } + if (FD_ISSET(squid_link, &R)) + control.Recv(); #if USE_IPV6 if (FD_ISSET(icmp6_worker, &R)) @@ -366,8 +168,8 @@ icmp4.Recv(); if (PINGER_TIMEOUT + last_check_time < squid_curtime) { - if (send(socket_to_squid, &tv, 0, 0) < 0) { - pingerClose(); + if (send(LINK_TO_SQUID, &tv, 0, 0) < 0) { + control.Close(); exit(1); } Index: squid3/src/structs.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/structs.h,v retrieving revision 1.66.2.33 retrieving revision 1.66.2.34 diff -u -r1.66.2.33 -r1.66.2.34 --- squid3/src/structs.h 10 Oct 2007 00:51:42 -0000 1.66.2.33 +++ squid3/src/structs.h 16 Oct 2007 13:35:09 -0000 1.66.2.34 @@ -1,6 +1,6 @@ /* - * $Id: structs.h,v 1.66.2.33 2007/10/10 00:51:42 amosjeffries Exp $ + * $Id: structs.h,v 1.66.2.34 2007/10/16 13:35:09 amosjeffries Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -1190,30 +1190,6 @@ }; -#if USE_ICMP - -/* This is a line-data format struct. DO NOT alter. */ -struct pingerEchoData -{ - IPAddress to; - unsigned char opcode; - int psize; - char payload[PINGER_PAYLOAD_SZ]; -}; - -/* This is a line-data format struct. DO NOT alter. */ -struct pingerReplyData -{ - IPAddress from; - unsigned char opcode; - int rtt; - int hops; - int psize; - char payload[PINGER_PAYLOAD_SZ]; -}; - -#endif - struct _iostats {