/*
- * $Id$
- *
- * 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.
+ * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
*
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
*/
+/* DEBUG: section 37 ICMP Routines */
+
#include "squid.h"
#include "comm.h"
#include "comm/Loops.h"
+#include "defines.h"
+#include "fd.h"
+#include "icmp/IcmpConfig.h"
#include "icmp/IcmpSquid.h"
#include "icmp/net_db.h"
#include "ip/tools.h"
+#include "SquidConfig.h"
+#include "SquidIpc.h"
#include "SquidTime.h"
+#include <cerrno>
+
// Instance global to be available in main() and elsewhere.
IcmpSquid icmpEngine;
#if USE_ICMP
#define S_ICMP_ECHO 1
-#if DEAD_CODE
-#define S_ICMP_ICP 2
-#endif
#define S_ICMP_DOM 3
static void * hIpc;
#endif /* USE_ICMP */
-
IcmpSquid::IcmpSquid() : Icmp()
{
; // nothing new.
Close();
}
-
#if USE_ICMP
void
else if (payload && len == 0)
len = strlen(payload);
- /** \li
- \bug If length specified or auto-detected is greater than the possible payload squid will die with an assert.
- \todo This should perhapse be reduced to a truncated payload? or no payload. A WARNING is due anyway.
- */
+ // XXX: If length specified or auto-detected is greater than the possible payload squid will die with an assert.
+ // TODO: This should perhapse be reduced to a truncated payload? or no payload. A WARNING is due anyway.
assert(len <= PINGER_PAYLOAD_SZ);
pecho.to = to;
x = comm_udp_send(icmp_sock, (char *)&pecho, slen, 0);
if (x < 0) {
- debugs(37, 1, HERE << "send: " << xstrerror());
+ int xerrno = errno;
+ debugs(37, DBG_IMPORTANT, MYNAME << "send: " << xstrerr(xerrno));
/** \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? */
- if (errno == ECONNREFUSED || errno == EPIPE) {
+ // TODO: try restarting the helper a few times before giving up?
+ if (xerrno == ECONNREFUSED || xerrno == EPIPE) {
Close();
return;
}
/** 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");
}
}
static Ip::Address F;
Comm::SetSelect(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, HERE << "recv: " << xstrerror());
+ int xerrno = errno;
+ debugs(37, DBG_IMPORTANT, MYNAME << "recv: " << xstrerr(xerrno));
- if (errno == ECONNREFUSED)
+ if (xerrno == ECONNREFUSED)
Close();
- if (errno == ECONNRESET)
+ if (xerrno == ECONNRESET)
Close();
if (++fail_count == 10)
F = preply.from;
- F.SetPort(0);
+ F.port(0);
switch (preply.opcode) {
break;
default:
- debugs(37, 1, HERE << "Bad opcode: " << preply.opcode << " from " << F);
+ debugs(37, DBG_IMPORTANT, HERE << "Bad opcode: " << preply.opcode << " from " << F);
break;
}
}
Ip::Address localhost;
/* User configured disabled. */
- if (!Config.pinger.enable) {
+ if (!IcmpCfg.enable) {
Close();
return -1;
}
args[0] = "(pinger)";
args[1] = NULL;
- localhost.SetLocalhost();
+ localhost.setLocalhost();
/*
* Do NOT use IPC_DGRAM (=IPC_UNIX_DGRAM) here because you can't
* least on FreeBSD).
*/
pid = ipcCreate(IPC_UDP_SOCKET,
- Config.pinger.program,
+ IcmpCfg.program.c_str(),
args,
"Pinger Socket",
localhost,
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 (Ip::EnableIpv6)
SendEcho(localhost, S_ICMP_ECHO, "ip6-localhost");
- if (localhost.SetIPv4())
+ if (localhost.setIPv4())
SendEcho(localhost, S_ICMP_ECHO, "localhost");
-#ifdef _SQUID_MSWIN_
+#if _SQUID_WINDOWS_
debugs(37, 4, HERE << "Pinger handle: 0x" << std::hex << hIpc << std::dec << ", PID: " << pid);
-#endif /* _SQUID_MSWIN_ */
+#endif /* _SQUID_WINDOWS_ */
return icmp_sock;
#else /* USE_ICMP */
return -1;
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_WINDOWS_
send(icmp_sock, (const void *) "$shutdown\n", 10, 0);
comm_close(icmp_sock);
-#ifdef _SQUID_MSWIN_
+#if _SQUID_WINDOWS_
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);
#endif
}
+