/*
- * $Id: ICMPSquid.cc,v 1.1 2007/12/14 23:11:45 amosjeffries Exp $
+ * $Id$
*
* DEBUG: section 37 ICMP Routines
* AUTHOR: Duane Wessels, Amos Jeffries
*/
#include "squid.h"
+#include "comm.h"
+#include "comm/Loops.h"
#include "icmp/IcmpSquid.h"
#include "icmp/net_db.h"
-#include "comm.h"
+#include "ip/tools.h"
+#include "protos.h"
#include "SquidTime.h"
+#if HAVE_ERRNO_H
+#include <errno.h>
+#endif
+
// Instance global to be available in main() and elsewhere.
IcmpSquid icmpEngine;
#endif /* USE_ICMP */
-
IcmpSquid::IcmpSquid() : Icmp()
{
; // nothing new.
Close();
}
-
#if USE_ICMP
void
-IcmpSquid::SendEcho(IPAddress &to, int opcode, const char *payload, int len)
+IcmpSquid::SendEcho(Ip::Address &to, int opcode, const char *payload, int len)
{
static pingerEchoData pecho;
int x, slen;
pecho.psize = len;
if (len > 0)
- xmemcpy(pecho.payload, payload, len);
+ memcpy(pecho.payload, payload, len);
slen = sizeof(pingerEchoData) - PINGER_PAYLOAD_SZ + pecho.psize;
x = comm_udp_send(icmp_sock, (char *)&pecho, slen, 0);
if (x < 0) {
- debugs(37, 1, HERE << "send: " << xstrerror());
+ debugs(37, DBG_IMPORTANT, HERE << "send: " << xstrerror());
/** \li If the send results in ECONNREFUSED or EPIPE errors from helper, will cleanly shutdown the module. */
/** \todo This should try restarting the helper a few times?? before giving up? */
}
/** All other send errors are ignored. */
} else if (x != slen) {
- debugs(37, 1, HERE << "Wrote " << x << " of " << slen << " bytes");
+ debugs(37, DBG_IMPORTANT, HERE << "Wrote " << x << " of " << slen << " bytes");
}
}
int n;
static int fail_count = 0;
pingerReplyData preply;
- static IPAddress F;
+ static Ip::Address F;
- commSetSelect(icmp_sock, COMM_SELECT_READ, icmpSquidRecv, NULL, 0);
+ Comm::SetSelect(icmp_sock, COMM_SELECT_READ, icmpSquidRecv, NULL, 0);
memset(&preply, '\0', sizeof(pingerReplyData));
n = comm_udp_recv(icmp_sock,
(char *) &preply,
0);
if (n < 0 && EAGAIN != errno) {
- debugs(37, 1, HERE << "recv: " << xstrerror());
+ debugs(37, DBG_IMPORTANT, HERE << "recv: " << xstrerror());
if (errno == ECONNREFUSED)
Close();
break;
default:
- debugs(37, 1, HERE << "Bad opcode: " << preply.opcode << " from " << F);
+ debugs(37, DBG_IMPORTANT, HERE << "Bad opcode: " << preply.opcode << " from " << F);
break;
}
}
#endif /* USE_ICMP */
void
-IcmpSquid::DomainPing(IPAddress &to, const char *domain)
+IcmpSquid::DomainPing(Ip::Address &to, const char *domain)
{
#if USE_ICMP
debugs(37, 4, HERE << "'" << domain << "' (" << to << ")");
const char *args[2];
int rfd;
int wfd;
- IPAddress localhost;
+ Ip::Address localhost;
/* User configured disabled. */
if (!Config.pinger.enable) {
fd_note(icmp_sock, "pinger");
- commSetSelect(icmp_sock, COMM_SELECT_READ, icmpSquidRecv, NULL, 0);
+ Comm::SetSelect(icmp_sock, COMM_SELECT_READ, icmpSquidRecv, NULL, 0);
- commSetTimeout(icmp_sock, -1, NULL, NULL);
+ commUnsetFdTimeout(icmp_sock);
- debugs(37, 1, HERE << "Pinger socket opened on FD " << icmp_sock);
+ debugs(37, DBG_IMPORTANT, HERE << "Pinger socket opened on FD " << icmp_sock);
/* Tests the pinger immediately using localhost */
-#if USE_IPV6
- SendEcho(localhost, S_ICMP_ECHO, "ip6-localhost");
-#endif
+ if (Ip::EnableIpv6)
+ SendEcho(localhost, S_ICMP_ECHO, "ip6-localhost");
if (localhost.SetIPv4())
SendEcho(localhost, S_ICMP_ECHO, "localhost");
-#ifdef _SQUID_MSWIN_
+#if _SQUID_MSWIN_
debugs(37, 4, HERE << "Pinger handle: 0x" << std::hex << hIpc << std::dec << ", PID: " << pid);
if (icmp_sock < 0)
return;
- debugs(37, 1, HERE << "Closing Pinger socket on FD " << icmp_sock);
+ debugs(37, DBG_IMPORTANT, HERE << "Closing Pinger socket on FD " << icmp_sock);
-#ifdef _SQUID_MSWIN_
+#if _SQUID_MSWIN_
send(icmp_sock, (const void *) "$shutdown\n", 10, 0);
comm_close(icmp_sock);
-#ifdef _SQUID_MSWIN_
+#if _SQUID_MSWIN_
if (hIpc) {
if (WaitForSingleObject(hIpc, 12000) != WAIT_OBJECT_0) {
getCurrentTime();
- debugs(37, 0, HERE << "WARNING: (pinger," << pid << ") didn't exit in 12 seconds");
+ debugs(37, DBG_CRITICAL, HERE << "WARNING: (pinger," << pid << ") didn't exit in 12 seconds");
}
CloseHandle(hIpc);