]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/icmp/IcmpSquid.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / icmp / IcmpSquid.cc
index ea45720699d6bd6e8410def9652dae68a59a8810..82a1599c2b8f5c6ce78e6d31b3f4e58088088ae9 100644 (file)
  */
 
 #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;
 
@@ -54,7 +61,6 @@ static pid_t pid;
 
 #endif /* USE_ICMP */
 
-
 IcmpSquid::IcmpSquid() : Icmp()
 {
     ; // nothing new.
@@ -65,11 +71,10 @@ IcmpSquid::~IcmpSquid()
     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;
@@ -104,7 +109,7 @@ IcmpSquid::SendEcho(IpAddress &to, int opcode, const char *payload, int len)
     pecho.psize = len;
 
     if (len > 0)
-        xmemcpy(pecho.payload, payload, len);
+        memcpy(pecho.payload, payload, len);
 
     slen = sizeof(pingerEchoData) - PINGER_PAYLOAD_SZ + pecho.psize;
 
@@ -113,7 +118,7 @@ IcmpSquid::SendEcho(IpAddress &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());
+        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? */
@@ -123,7 +128,7 @@ IcmpSquid::SendEcho(IpAddress &to, int opcode, const char *payload, int len)
         }
         /** 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");
     }
 }
 
@@ -141,9 +146,9 @@ IcmpSquid::Recv()
     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,
@@ -151,7 +156,7 @@ IcmpSquid::Recv()
                       0);
 
     if (n < 0 && EAGAIN != errno) {
-        debugs(37, 1, HERE << "recv: " << xstrerror());
+        debugs(37, DBG_IMPORTANT, HERE << "recv: " << xstrerror());
 
         if (errno == ECONNREFUSED)
             Close();
@@ -188,7 +193,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;
     }
 }
@@ -196,7 +201,7 @@ IcmpSquid::Recv()
 #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 << ")");
@@ -211,7 +216,7 @@ IcmpSquid::Open(void)
     const char *args[2];
     int rfd;
     int wfd;
-    IpAddress localhost;
+    Ip::Address localhost;
 
     /* User configured disabled. */
     if (!Config.pinger.enable) {
@@ -246,20 +251,19 @@ IcmpSquid::Open(void)
 
     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);
 
@@ -278,9 +282,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);
 
-#ifdef _SQUID_MSWIN_
+#if _SQUID_MSWIN_
 
     send(icmp_sock, (const void *) "$shutdown\n", 10, 0);
 
@@ -288,12 +292,12 @@ IcmpSquid::Close(void)
 
     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);