--------------------- PatchSet 5891 Date: 2007/10/07 06:19:56 Author: amosjeffries Branch: squid3-ipv6 Tag: (none) Log: Abstract the old content of icmp.cc into ICMPSquid class New class provides a virtual interface for teh main squid process, hiding all the pinger external comms and protocol-specifics behind a simple API. Also moves the ICMP class methods into icmp.cc where they should be. Members: src/ICMP.h:1.1.2.3->1.1.2.4 src/ICMPSquid.cc:1.1->1.1.2.1 src/ICMPSquid.h:1.1->1.1.2.1 src/Makefile.am:1.58.2.21->1.58.2.22 src/icmp.cc:1.8.8.15->1.8.8.16 src/main.cc:1.42.4.21->1.42.4.22 src/protos.h:1.48.4.33->1.48.4.34 Index: squid3/src/ICMP.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/Attic/ICMP.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/ICMP.h 7 Oct 2007 01:34:24 -0000 1.1.2.3 +++ squid3/src/ICMP.h 7 Oct 2007 06:19:56 -0000 1.1.2.4 @@ -1,5 +1,5 @@ /* - * $Id: ICMP.h,v 1.1.2.3 2007/10/07 01:34:24 amosjeffries Exp $ + * $Id: ICMP.h,v 1.1.2.4 2007/10/07 06:19:56 amosjeffries Exp $ * * DEBUG: section 37 ICMP Routines * AUTHOR: Duane Wessels, Amos Jeffries @@ -97,81 +97,11 @@ #endif /* USE_ICMP */ }; - -// TODO : move these into icmp.cc once the squid-internals have been moved to ICMPSquid engine. -inline -ICMP::ICMP() -{ -#if USE_ICMP - icmp_sock = -1; - icmp_ident = 0; -#endif -} - -inline void -ICMP::Close() -{ -#if USE_ICMP - if(icmp_sock > 0) - close(icmp_sock); - icmp_sock = -1; - icmp_ident = 0; -#endif -} - -#if USE_ICMP -inline int -ICMP::CheckSum(unsigned short *ptr, int size) -{ - long sum; - unsigned short oddbyte; - unsigned short answer; - sum = 0; - - while (size > 1) { - sum += *ptr++; - size -= 2; - } - - if (size == 1) { - oddbyte = 0; - *((unsigned char *) &oddbyte) = *(unsigned char *) ptr; - sum += oddbyte; - } - - sum = (sum >> 16) + (sum & 0xffff); - sum += (sum >> 16); - answer = (unsigned short) ~sum; - return (answer); -} -#endif - -#if USE_ICMP -inline int -ICMP::ipHops(int ttl) -{ - if (ttl < 33) - return 33 - ttl; - - if (ttl < 63) - return 63 - ttl; /* 62 = (64+60)/2 */ - - if (ttl < 65) - return 65 - ttl; /* 62 = (64+60)/2 */ - - if (ttl < 129) - return 129 - ttl; - - if (ttl < 193) - return 193 - ttl; - - return 256 - ttl; -} -#endif - // Glue for pinger functions use by child engines // To be removed as soon as no longer needed. -extern void pingerLog(const IPAddress &addr, const u_int8_t type, const char* pkt_str, const int rtt, const int hops); -extern void pingerSendtoSquid(pingerReplyData * preply); +#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 --- /dev/null Mon Oct 8 00:19:50 2007 +++ squid3/src/ICMPSquid.cc Mon Oct 8 00:19:50 2007 @@ -0,0 +1,342 @@ +/* + * $Id: ICMPSquid.cc,v 1.1.2.1 2007/10/07 06:19:56 amosjeffries Exp $ + * + * DEBUG: section 37 ICMP Routines + * AUTHOR: Duane Wessels, Amos Jeffries + * + * SQUID Web Proxy Cache http://www.squid-cache.org/ + * ---------------------------------------------------------- + * + * Squid is the result of efforts by numerous individuals from + * the Internet community; see the CONTRIBUTORS file for full + * details. Many organizations have provided support for Squid's + * development; see the SPONSORS file for full details. Squid is + * Copyrighted (C) 2001 by the Regents of the University of + * California; see the COPYRIGHT file for full details. Squid + * incorporates software developed and/or copyrighted by other + * sources; see the CREDITS file for full details. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. + * + */ + +#include "squid.h" +#include "ICMPSquid.h" +#include "comm.h" +#include "SquidTime.h" + + +// Instance global to be available in main() and elsewhere. +ICMPSquid icmpEngine; + +#define S_ICMP_ECHO 1 +#if ALLOW_SOURCE_PING +#define S_ICMP_ICP 2 +#endif +#define S_ICMP_DOM 3 + + +#if USE_ICMP + +static void * hIpc; +static pid_t pid; + +#endif /* USE_ICMP */ + +ICMPSquid::ICMPSquid() : ICMP() +{ + ; // nothing new. +} + +ICMPSquid::~ICMPSquid() +{ + Close(); +} + + +#if USE_ICMP + +static void +icmpSendEcho(IPAddress &to, int opcode, const char *payload, int len) +{ + icmpEngine.SendEcho(to, opcode, payload, len); +} + +void +ICMPSquid::SendEcho(IPAddress &to, int opcode, const char *payload, int len) +{ + static pingerEchoData pecho; + + if (payload && len == 0) + len = strlen(payload); + + assert(len <= PINGER_PAYLOAD_SZ); + + pecho.to = to; + + pecho.opcode = (unsigned char) opcode; + + pecho.psize = len; + + xmemcpy(pecho.payload, payload, len); + + icmpSend(&pecho, sizeof(pingerEchoData) - PINGER_PAYLOAD_SZ + len); +} + +// Callback to wrap the squid-side ICMP handler. +static void +icmpSquidRecv(int unused1, void *unused2) +{ + icmpEngine.Recv(); +} + +void +ICMPSquid::Recv() +{ + int n; + static int fail_count = 0; + pingerReplyData preply; + + static IPAddress F; + commSetSelect(icmp_sock, COMM_SELECT_READ, icmpSquidRecv, NULL, 0); + memset(&preply, '\0', sizeof(pingerReplyData)); + n = comm_udp_recv(icmp_sock, + (char *) &preply, + sizeof(pingerReplyData), + 0); + + if (n < 0 && EAGAIN != errno) { + debugs(37, 1, "icmpRecv: recv: " << xstrerror()); + + if (errno == ECONNREFUSED) + Close(); + + if (errno == ECONNRESET) + Close(); + + if (++fail_count == 10) + Close(); + + return; + } + + fail_count = 0; + + if (n == 0) /* test probe from pinger */ + return; + + F = preply.from; + + F.SetPort(0); + + switch (preply.opcode) { + + case S_ICMP_ECHO: + break; +#if ALLOW_SOURCE_PING + + case S_ICMP_ICP: + HandleSourcePing(F, preply.payload); + break; +#endif + + case S_ICMP_DOM: + netdbHandlePingReply(F, preply.hops, preply.rtt); + break; + + default: + debugs(37, 1, "icmpRecv: Bad opcode: " << preply.opcode << " from " << F); + break; + } +} + +#if 0 +static void +icmpSend(pingerEchoData * pkt, int len) +{ +// private! icmpEngine.Send(pkt, len); +} +#endif + +void +ICMPSquid::Send(pingerEchoData * pkt, int len) +{ + int x; + + if (icmp_sock < 0) + return; + + debugs(37, 2, "icmpSend: to " << pkt->to << ", opcode " << + (int) pkt->opcode << ", len " << pkt->psize); + + x = comm_udp_send(icmp_sock, (char *) pkt, len, 0); + + if (x < 0) { + debugs(37, 1, "icmpSend: send: " << xstrerror()); + + if (errno == ECONNREFUSED || errno == EPIPE) { + Close(); + return; + } + } else if (x != len) { + debugs(37, 1, "icmpSend: Wrote " << x << " of " << len << " bytes"); + } +} + +#if ALLOW_SOURCE_PING +void +ICMPSquid::HandleSourcePing(const IPAddress &from, const char *buf) +{ + const cache_key *key; + icp_common_t header; + const char *url; + xmemcpy(&header, buf, sizeof(icp_common_t)); + url = buf + sizeof(icp_common_t); + key = icpGetCacheKey(url, (int) header.reqnum); + debugs(37, 3, "icmpHandleSourcePing: from " << from << ", key '" << storeKeyText(key) << "'"); + + /* call neighborsUdpAck even if ping_status != PING_WAITING */ + neighborsUdpAck(key, &header, from); +} +#endif + +#endif /* USE_ICMP */ + +#if ALLOW_SOURCE_PING +void +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 << "'"); + + if ((ulen = strlen(url)) > MAX_URL) + return; + + payload = memAllocate(MEM_8K_BUF); + + len = sizeof(icp_common_t); + + xmemcpy(payload, header, len); + + strcpy(payload + len, url); + + len += ulen + 1; + + SendEcho(to, S_ICMP_ICP, payload, len); + + memFree(payload, MEM_8K_BUF); + +#endif +} + +#endif + +void +ICMPSquid::DomainPing(IPAddress &to, const char *domain) +{ +#if USE_ICMP + debugs(37, 3, "icmpDomainPing: '" << domain << "'"); +/* FIXME INET6 : when ICMPv6 implemented this 'if' will die. */ + if(to.IsIPv4()) + { + SendEcho(to, S_ICMP_DOM, domain, 0); + } +#endif +} + +int +ICMPSquid::Open(void) +{ +#if USE_ICMP + const char *args[2]; + int rfd; + int wfd; + args[0] = "(pinger)"; + args[1] = NULL; + /* + * Do NOT use IPC_DGRAM (=IPC_UNIX_DGRAM) here because you can't + * send() more than 4096 bytes on a socketpair() socket (at + * least on FreeBSD). + */ + pid = ipcCreate(IPC_UDP_SOCKET, + Config.Program.pinger, + args, + "Pinger Socket", + default_localhost_addr, + &rfd, + &wfd, + &hIpc); + + if (pid < 0) + return; + + assert(rfd == wfd); + + icmp_sock = rfd; + + fd_note(icmp_sock, "pinger"); + + commSetSelect(icmp_sock, COMM_SELECT_READ, icmpSquidRecv, NULL, 0); + + commSetTimeout(icmp_sock, -1, NULL, NULL); + + debugs(37, 1, "Pinger socket opened on FD " << icmp_sock); + +#ifdef _SQUID_MSWIN_ + + debugs(37, 4, "Pinger handle: 0x" << std::hex << hIpc << std::dec << ", PID: " << pid); + +#endif +#endif + return 0; // not used. would be icmp_sock otherwise. +} + +void +ICMPSquid::Close(void) +{ +#if USE_ICMP + + if (icmp_sock < 0) + return; + + debugs(37, 1, "Closing Pinger socket on FD " << icmp_sock); + +#ifdef _SQUID_MSWIN_ + + send(icmp_sock, (const void *) "$shutdown\n", 10, 0); + +#endif + + comm_close(icmp_sock); + +#ifdef _SQUID_MSWIN_ + + if (hIpc) { + if (WaitForSingleObject(hIpc, 12000) != WAIT_OBJECT_0) { + getCurrentTime(); + debugs(37, 1, "icmpClose: WARNING: (pinger," << pid << ") didn't exit in 12 seconds"); + } + + CloseHandle(hIpc); + } + +#endif + icmp_sock = -1; + +#endif +} --- /dev/null Mon Oct 8 00:19:50 2007 +++ squid3/src/ICMPSquid.h Mon Oct 8 00:19:50 2007 @@ -0,0 +1,80 @@ +/* + * $Id: ICMPSquid.h,v 1.1.2.1 2007/10/07 06:19:56 amosjeffries Exp $ + * + * DEBUG: section 37 ICMP Routines + * AUTHOR: Duane Wessels, Amos Jeffries + * + * SQUID Web Proxy Cache http://www.squid-cache.org/ + * ---------------------------------------------------------- + * + * Squid is the result of efforts by numerous individuals from + * the Internet community; see the CONTRIBUTORS file for full + * details. Many organizations have provided support for Squid's + * development; see the SPONSORS file for full details. Squid is + * Copyrighted (C) 2001 by the Regents of the University of + * California; see the COPYRIGHT file for full details. Squid + * incorporates software developed and/or copyrighted by other + * sources; see the CREDITS file for full details. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. + * + */ +#ifndef _INCLUDE_ICMPSQUID_H +#define _INCLUDE_ICMPSQUID_H + +#include "config.h" +#include "ICMP.h" +#include "IPAddress.h" + +/** + * Implements a non-blocking pseudo-ICMP engine for squid internally. + * + * Rather than doing all the work itself it passes each request off to + * an external pinger helper and returns results form that helper to squid. + * + * Provides ECHO-REQUEST, ECHO-REPLY in a protocol-neutral manner. + */ +class ICMPSquid : public ICMP +{ +public: + ICMPSquid(); + virtual ~ICMPSquid(); + + virtual int Open(); + virtual void Close(); + + void DomainPing(IPAddress &to, const char *domain); + +#if ALLOW_SOURCE_PING + void SourcePing(IPAddress &to, const icp_common_t * header, const char *url); + void HandleSourcePing(const IPAddress &from, const char *buf); +#endif + +#if USE_ICMP + virtual void SendEcho(IPAddress &, int, const char*, int); + virtual void Recv(void); + +private: + virtual void Send(pingerEchoData* pkt, int len); + +#endif +}; + +#if !SQUID_HELPER +// global engine within squid. +SQUIDCEXTERN ICMPSquid icmpEngine; +#endif + +#endif /* _INCLUDE_ICMPSQUID_H */ Index: squid3/src/Makefile.am =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/Makefile.am,v retrieving revision 1.58.2.21 retrieving revision 1.58.2.22 diff -u -r1.58.2.21 -r1.58.2.22 --- squid3/src/Makefile.am 6 Oct 2007 15:17:07 -0000 1.58.2.21 +++ squid3/src/Makefile.am 7 Oct 2007 06:19:56 -0000 1.58.2.22 @@ -1,7 +1,7 @@ # # Makefile for the Squid Object Cache server # -# $Id: Makefile.am,v 1.58.2.21 2007/10/06 15:17:07 amosjeffries Exp $ +# $Id: Makefile.am,v 1.58.2.22 2007/10/07 06:19:56 amosjeffries Exp $ # # Uncomment and customize the following to suit your needs: # @@ -507,7 +507,10 @@ HttpRequestMethod.cc \ HttpRequestMethod.h \ HttpVersion.h \ + icmp.h \ icmp.cc \ + ICMPSquid.h \ + ICMPSquid.cc \ ICP.h \ icp_v2.cc \ icp_v3.cc \ @@ -706,6 +709,7 @@ pinger_SOURCES = \ ICMP.h \ + icmp.cc \ ICMPv4.h \ ICMPv4.cc \ pinger.cc \ @@ -815,7 +819,10 @@ HttpReply.cc \ HttpRequest.cc \ HttpRequestMethod.cc \ + icmp.h \ icmp.cc \ + ICMPSquid.h \ + ICMPSquid.cc \ icp_v2.cc \ icp_v3.cc \ $(IDENT_SOURCE) \ @@ -1318,7 +1325,10 @@ HttpMsg.cc \ HttpReply.cc \ HttpStatusLine.cc \ + icmp.h \ icmp.cc \ + ICMPSquid.h \ + ICMPSquid.cc \ icp_v2.cc \ icp_v3.cc \ $(IDENT_SOURCE) \ @@ -1484,7 +1494,10 @@ HttpMsg.cc \ HttpReply.cc \ HttpStatusLine.cc \ + icmp.h \ icmp.cc \ + ICMPSquid.h \ + ICMPSquid.cc \ icp_v2.cc \ icp_v3.cc \ $(IDENT_SOURCE) \ @@ -1636,7 +1649,10 @@ HttpMsg.cc \ HttpReply.cc \ HttpStatusLine.cc \ + icmp.h \ icmp.cc \ + ICMPSquid.h \ + ICMPSquid.cc \ icp_v2.cc \ icp_v3.cc \ $(IDENT_SOURCE) \ @@ -1816,7 +1832,10 @@ HttpRequest.cc \ HttpRequestMethod.cc \ HttpStatusLine.cc \ + icmp.h \ icmp.cc \ + ICMPSquid.h \ + ICMPSquid.cc \ icp_v2.cc \ icp_v3.cc \ $(IDENT_SOURCE) \ @@ -1971,7 +1990,10 @@ HttpMsg.cc \ HttpReply.cc \ HttpStatusLine.cc \ + icmp.h \ icmp.cc \ + ICMPSquid.h \ + ICMPSquid.cc \ icp_v2.cc \ icp_v3.cc \ $(IDENT_SOURCE) \ @@ -2309,7 +2331,10 @@ HttpMsg.cc \ HttpReply.cc \ HttpStatusLine.cc \ + icmp.h \ icmp.cc \ + ICMPSquid.h \ + ICMPSquid.cc \ icp_v2.cc \ icp_v3.cc \ $(IDENT_SOURCE) \ Index: squid3/src/icmp.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/icmp.cc,v retrieving revision 1.8.8.15 retrieving revision 1.8.8.16 diff -u -r1.8.8.15 -r1.8.8.16 --- squid3/src/icmp.cc 6 Oct 2007 15:17:07 -0000 1.8.8.15 +++ squid3/src/icmp.cc 7 Oct 2007 06:19:57 -0000 1.8.8.16 @@ -1,5 +1,5 @@ /* - * $Id: icmp.cc,v 1.8.8.15 2007/10/06 15:17:07 amosjeffries Exp $ + * $Id: icmp.cc,v 1.8.8.16 2007/10/07 06:19:57 amosjeffries Exp $ * * DEBUG: section 37 ICMP Routines * AUTHOR: Duane Wessels, Amos Jeffries @@ -31,282 +31,75 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. * */ - #include "squid.h" #include "ICMP.h" -#include "comm.h" -#include "SquidTime.h" -#include "IPAddress.h" - -#if USE_ICMP - -#define S_ICMP_ECHO 1 -#if ALLOW_SOURCE_PING -#define S_ICMP_ICP 2 -#endif -#define S_ICMP_DOM 3 - -static PF icmpRecv; -static void icmpSend(pingerEchoData * pkt, int len); -#if ALLOW_SOURCE_PING - -static void icmpHandleSourcePing(const IPAddress &from, const char *buf); -#endif - -static void * hIpc; -static pid_t pid; - -static void - -icmpSendEcho(IPAddress &to, int opcode, const char *payload, int len) -{ - static pingerEchoData pecho; - - if (payload && len == 0) - len = strlen(payload); - - assert(len <= PINGER_PAYLOAD_SZ); - - pecho.to = to; - - pecho.opcode = (unsigned char) opcode; - - pecho.psize = len; - - xmemcpy(pecho.payload, payload, len); - - icmpSend(&pecho, sizeof(pingerEchoData) - PINGER_PAYLOAD_SZ + len); -} - -static void -icmpRecv(int unused1, void *unused2) -{ - int n; - static int fail_count = 0; - pingerReplyData preply; - - static IPAddress F; - commSetSelect(icmp_sock, COMM_SELECT_READ, icmpRecv, NULL, 0); - memset(&preply, '\0', sizeof(pingerReplyData)); - n = comm_udp_recv(icmp_sock, - (char *) &preply, - sizeof(pingerReplyData), - 0); - - if (n < 0 && EAGAIN != errno) { - debugs(37, 1, "icmpRecv: recv: " << xstrerror()); - - if (errno == ECONNREFUSED) - icmpClose(); - - if (errno == ECONNRESET) - icmpClose(); - - if (++fail_count == 10) - icmpClose(); - return; - } - - fail_count = 0; - - if (n == 0) /* test probe from pinger */ - return; - - F = preply.from; - - F.SetPort(0); - - switch (preply.opcode) { - - case S_ICMP_ECHO: - break; -#if ALLOW_SOURCE_PING - - case S_ICMP_ICP: - icmpHandleSourcePing(F, preply.payload); - break; -#endif - - case S_ICMP_DOM: - netdbHandlePingReply(F, preply.hops, preply.rtt); - break; - - default: - debugs(37, 1, "icmpRecv: Bad opcode: " << preply.opcode << " from " << F); - break; - } -} -static void -icmpSend(pingerEchoData * pkt, int len) -{ - int x; - - if (icmp_sock < 0) - return; - - debugs(37, 2, "icmpSend: to " << pkt->to << ", opcode " << - (int) pkt->opcode << ", len " << pkt->psize); - - x = comm_udp_send(icmp_sock, (char *) pkt, len, 0); - - if (x < 0) { - debugs(37, 1, "icmpSend: send: " << xstrerror()); - - if (errno == ECONNREFUSED || errno == EPIPE) { - icmpClose(); - return; - } - } else if (x != len) { - debugs(37, 1, "icmpSend: Wrote " << x << " of " << len << " bytes"); - } -} - -#if ALLOW_SOURCE_PING -static void - -icmpHandleSourcePing(const IPAddress &from, const char *buf) -{ - const cache_key *key; - icp_common_t header; - const char *url; - xmemcpy(&header, buf, sizeof(icp_common_t)); - url = buf + sizeof(icp_common_t); - key = icpGetCacheKey(url, (int) header.reqnum); - debugs(37, 3, "icmpHandleSourcePing: from " << from << ", key '" << storeKeyText(key) << "'"); - - /* call neighborsUdpAck even if ping_status != PING_WAITING */ - neighborsUdpAck(key, &header, from); -} - -#endif - -#endif /* USE_ICMP */ - -#if ALLOW_SOURCE_PING -void - -icmpSourcePing(struct IN_ADDR to, const icp_common_t * header, const char *url) +ICMP::ICMP() { #if USE_ICMP - char *payload; - int len; - int ulen; - debugs(37, 3, "icmpSourcePing: '" << url << "'"); - - if ((ulen = strlen(url)) > MAX_URL) - return; - - payload = memAllocate(MEM_8K_BUF); - - len = sizeof(icp_common_t); - - xmemcpy(payload, header, len); - - strcpy(payload + len, url); - - len += ulen + 1; - - icmpSendEcho(to, S_ICMP_ICP, payload, len); - - memFree(payload, MEM_8K_BUF); - + icmp_sock = -1; + icmp_ident = 0; #endif } -#endif - void - -icmpDomainPing(IPAddress &to, const char *domain) +ICMP::Close() { #if USE_ICMP - debugs(37, 3, "icmpDomainPing: '" << domain << "'"); - if(to.IsIPv4()) - { - icmpSendEcho(to, S_ICMP_DOM, domain, 0); - } + if(icmp_sock > 0) + close(icmp_sock); + icmp_sock = -1; + icmp_ident = 0; #endif } -void -icmpOpen(void) -{ #if USE_ICMP - const char *args[2]; - int rfd; - int wfd; - args[0] = "(pinger)"; - args[1] = NULL; - /* - * Do NOT use IPC_DGRAM (=IPC_UNIX_DGRAM) here because you can't - * send() more than 4096 bytes on a socketpair() socket (at - * least on FreeBSD). - */ - pid = ipcCreate(IPC_UDP_SOCKET, - Config.Program.pinger, - args, - "Pinger Socket", - default_localhost_addr, - &rfd, - &wfd, - &hIpc); - - if (pid < 0) - return; - - assert(rfd == wfd); - - icmp_sock = rfd; - - fd_note(icmp_sock, "pinger"); - - commSetSelect(icmp_sock, COMM_SELECT_READ, icmpRecv, NULL, 0); - - commSetTimeout(icmp_sock, -1, NULL, NULL); - - debugs(37, 1, "Pinger socket opened on FD " << icmp_sock); -#ifdef _SQUID_MSWIN_ +int +ICMP::CheckSum(unsigned short *ptr, int size) +{ + long sum; + unsigned short oddbyte; + unsigned short answer; + sum = 0; + + while (size > 1) { + sum += *ptr++; + size -= 2; + } - debugs(37, 4, "Pinger handle: 0x" << std::hex << hIpc << std::dec << ", PID: " << pid); + if (size == 1) { + oddbyte = 0; + *((unsigned char *) &oddbyte) = *(unsigned char *) ptr; + sum += oddbyte; + } -#endif -#endif + sum = (sum >> 16) + (sum & 0xffff); + sum += (sum >> 16); + answer = (unsigned short) ~sum; + return (answer); } -void -icmpClose(void) +int +ICMP::ipHops(int ttl) { -#if USE_ICMP - - if (icmp_sock < 0) - return; + if (ttl < 33) + return 33 - ttl; - debugs(37, 1, "Closing Pinger socket on FD " << icmp_sock); + if (ttl < 63) + return 63 - ttl; /* 62 = (64+60)/2 */ -#ifdef _SQUID_MSWIN_ + if (ttl < 65) + return 65 - ttl; /* 62 = (64+60)/2 */ - send(icmp_sock, (const void *) "$shutdown\n", 10, 0); + if (ttl < 129) + return 129 - ttl; -#endif + if (ttl < 193) + return 193 - ttl; - comm_close(icmp_sock); - -#ifdef _SQUID_MSWIN_ - - if (hIpc) { - if (WaitForSingleObject(hIpc, 12000) != WAIT_OBJECT_0) { - getCurrentTime(); - debugs(37, 1, "icmpClose: WARNING: (pinger," << pid << ") didn't exit in 12 seconds"); - } - - CloseHandle(hIpc); - } - -#endif - icmp_sock = -1; - -#endif + return 256 - ttl; } + +#endif /* USE_ICMP */ Index: squid3/src/main.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/main.cc,v retrieving revision 1.42.4.21 retrieving revision 1.42.4.22 diff -u -r1.42.4.21 -r1.42.4.22 --- squid3/src/main.cc 26 Sep 2007 03:13:27 -0000 1.42.4.21 +++ squid3/src/main.cc 7 Oct 2007 06:19:57 -0000 1.42.4.22 @@ -1,6 +1,6 @@ /* - * $Id: main.cc,v 1.42.4.21 2007/09/26 03:13:27 amosjeffries Exp $ + * $Id: main.cc,v 1.42.4.22 2007/10/07 06:19:57 amosjeffries Exp $ * * DEBUG: section 1 Startup and Main Loop * AUTHOR: Harvest Derived @@ -72,6 +72,7 @@ #include "SwapDir.h" #include "forward.h" #include "MemPool.h" +#include "ICMPSquid.h" #if USE_WIN32_SERVICE @@ -560,7 +561,7 @@ #endif clientdbInit(); - icmpOpen(); + icmpEngine.Open(); netdbInit(); asnInit(); ACL::Initialize(); @@ -582,7 +583,7 @@ htcpSocketShutdown(); #endif - icmpClose(); + icmpEngine.Close(); #ifdef SQUID_SNMP snmpConnectionShutdown(); @@ -692,7 +693,7 @@ static void mainRotate(void) { - icmpClose(); + icmpEngine.Close(); #if USE_DNSSERVERS dnsShutdown(); @@ -712,7 +713,7 @@ fwdLogRotate(); #endif - icmpOpen(); + icmpEngine.Open(); #if USE_DNSSERVERS dnsInit(); Index: squid3/src/protos.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/protos.h,v retrieving revision 1.48.4.33 retrieving revision 1.48.4.34 diff -u -r1.48.4.33 -r1.48.4.34 --- squid3/src/protos.h 30 Sep 2007 16:13:31 -0000 1.48.4.33 +++ squid3/src/protos.h 7 Oct 2007 06:19:57 -0000 1.48.4.34 @@ -1,6 +1,6 @@ /* - * $Id: protos.h,v 1.48.4.33 2007/09/30 16:13:31 serassio Exp $ + * $Id: protos.h,v 1.48.4.34 2007/10/07 06:19:57 amosjeffries Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -263,13 +263,6 @@ SQUIDCEXTERN void httpHdrMangleList(HttpHeader *, HttpRequest *, int req_or_rep); SQUIDCEXTERN int httpReqHdrManglersConfigured(); -SQUIDCEXTERN void icmpOpen(void); -SQUIDCEXTERN void icmpClose(void); - -SQUIDCEXTERN void icmpSourcePing(IPAddress &to, const icp_common_t *, const char *url); - -SQUIDCEXTERN void icmpDomainPing(IPAddress &to, const char *domain); - #ifdef SQUID_SNMP SQUIDCEXTERN PF snmpHandleUdp; SQUIDCEXTERN void snmpInit(void);