]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/icmp/IcmpSquid.cc
Source Format Enforcement (#532)
[thirdparty/squid.git] / src / icmp / IcmpSquid.cc
index 46f9e5e80033b1733f930cd827b7ddbbe5736483..46425a87f84dad70077c87589698141c19f2ad9d 100644 (file)
@@ -1,54 +1,34 @@
 /*
- * $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-2020 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.
  */
 
-#include "squid-old.h"
+/* 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;
@@ -56,7 +36,6 @@ static pid_t pid;
 
 #endif /* USE_ICMP */
 
-
 IcmpSquid::IcmpSquid() : Icmp()
 {
     ; // nothing new.
@@ -67,7 +46,6 @@ IcmpSquid::~IcmpSquid()
     Close();
 }
 
-
 #if USE_ICMP
 
 void
@@ -115,17 +93,18 @@ IcmpSquid::SendEcho(Ip::Address &to, int opcode, const char *payload, int len)
     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) {
+        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");
     }
 }
 
@@ -146,19 +125,19 @@ IcmpSquid::Recv()
     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)
@@ -176,7 +155,7 @@ IcmpSquid::Recv()
 
     F = preply.from;
 
-    F.SetPort(0);
+    F.port(0);
 
     switch (preply.opcode) {
 
@@ -190,7 +169,7 @@ IcmpSquid::Recv()
         break;
 
     default:
-        debugs(37, 1, HERE << "Bad opcode: " << preply.opcode << " from " << F);
+        debugs(37, DBG_IMPORTANT, HERE << "Bad opcode: " << preply.opcode << " from " << F);
         break;
     }
 }
@@ -216,14 +195,14 @@ IcmpSquid::Open(void)
     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
@@ -231,7 +210,7 @@ IcmpSquid::Open(void)
      * least on FreeBSD).
      */
     pid = ipcCreate(IPC_UDP_SOCKET,
-                    Config.pinger.program,
+                    IcmpCfg.program.c_str(),
                     args,
                     "Pinger Socket",
                     localhost,
@@ -252,19 +231,19 @@ IcmpSquid::Open(void)
 
     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");
 
-#if _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;
@@ -279,9 +258,9 @@ IcmpSquid::Close(void)
     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);
 
-#if _SQUID_MSWIN_
+#if _SQUID_WINDOWS_
 
     send(icmp_sock, (const void *) "$shutdown\n", 10, 0);
 
@@ -289,12 +268,12 @@ IcmpSquid::Close(void)
 
     comm_close(icmp_sock);
 
-#if _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);
@@ -305,3 +284,4 @@ IcmpSquid::Close(void)
 
 #endif
 }
+