]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
General ICMP dependant cleanups.
authorAmos Jeffries <squid3@treenet.co.nz>
Sat, 11 Oct 2008 13:21:08 +0000 (02:21 +1300)
committerAmos Jeffries <squid3@treenet.co.nz>
Sat, 11 Oct 2008 13:21:08 +0000 (02:21 +1300)
Moved netdb*() function definitions into icmp/net_db.h

Various compile and link errors after ICMP and Net_db move.

Some large blocks of potentially expensive code which are no-op without
ICMP and NetDB capabilities are now built only when useful.

15 files changed:
src/Makefile.am
src/comm.cc
src/fd.cc
src/forward.cc
src/htcp.cc
src/icmp/IcmpSquid.cc
src/icmp/net_db.cc
src/icmp/net_db.h
src/icp_v2.cc
src/internal.cc
src/main.cc
src/neighbors.cc
src/peer_select.cc
src/urn.cc
test-suite/test_tools.cc

index a1d9c5edfd91c86874964df5dc22747cee781bb3..6a8ef35f04b103119af6697dac6447e9d6207b3e 100644 (file)
@@ -1619,6 +1619,7 @@ nodist_tests_testEvent_SOURCES = \
 tests_testEvent_LDADD = \
        libsquid.la \
        libauth.la \
+       icmp/libicmp.la icmp/libicmp-core.la \
        @REPL_OBJS@ \
        ${ADAPTATION_LIBS} \
        @REGEXLIB@ \
@@ -1774,6 +1775,7 @@ nodist_tests_testEventLoop_SOURCES = \
 tests_testEventLoop_LDADD = \
        libsquid.la \
        libauth.la \
+       icmp/libicmp.la icmp/libicmp-core.la \
        @REPL_OBJS@ \
        ${ADAPTATION_LIBS} \
        @REGEXLIB@ \
@@ -1924,6 +1926,7 @@ nodist_tests_test_http_range_SOURCES = \
 tests_test_http_range_LDADD = \
        libsquid.la \
        libauth.la \
+       icmp/libicmp.la icmp/libicmp-core.la \
        @REPL_OBJS@ \
        @STORE_OBJS@ \
        ${ADAPTATION_LIBS} \
@@ -2080,6 +2083,7 @@ nodist_tests_testHttpRequest_SOURCES = \
 tests_testHttpRequest_LDADD = \
        libsquid.la \
        libauth.la \
+       icmp/libicmp.la icmp/libicmp-core.la \
        @REPL_OBJS@ \
        ${ADAPTATION_LIBS} \
        @REGEXLIB@ \
@@ -2423,6 +2427,7 @@ nodist_tests_testURL_SOURCES = \
 tests_testURL_LDADD = \
        libsquid.la \
        libauth.la \
+       icmp/libicmp.la icmp/libicmp-core.la \
        @REGEXLIB@ \
        @REPL_OBJS@ \
        ${ADAPTATION_LIBS} \
index 8e3e156ca5cf9c1187457c7528258407c4f5a57d..46aa0e46852473baacc85c65ce04f7f118f5bb39 100644 (file)
@@ -50,6 +50,7 @@
 #include "IPAddress.h"
 #include "IPInterception.h"
 #include "DescriptorSet.h"
+#include "icmp/net_db.h"
 
 #if defined(_SQUID_CYGWIN_)
 #include <sys/ioctl.h>
@@ -1113,8 +1114,10 @@ ConnectStateData::connect()
         tries++;
         ipcacheMarkBadAddr(host, S);
 
+#if USE_ICMP
         if (Config.onoff.test_reachability)
             netdbDeleteAddrNetwork(S);
+#endif
 
         if (commRetryConnect()) {
             eventAdd("commReconnect", commReconnect, this, this->addrcount == 1 ? 0.05 : 0.0, 0);
index cc98eb9fecbef9c2d45bf72e195e2583c67e0e4d..a14a1b978560fc5c6d5aff32bc9392347d6dda8e 100644 (file)
--- a/src/fd.cc
+++ b/src/fd.cc
@@ -36,6 +36,7 @@
 #include "squid.h"
 #include "fde.h"
 #include "SquidTime.h"
+#include "Debug.h"
 
 int default_read_method(int, char *, int);
 int default_write_method(int, const char *, int);
index 39471e21d9aaa595f8563ddc1925487854c762f8..dae274ef255f2da4d38e86090a7b6ac0d3fc021f 100644 (file)
@@ -48,8 +48,7 @@
 #include "pconn.h"
 #include "SquidTime.h"
 #include "Store.h"
-
-/* for IPInterceptor API */
+#include "icmp/net_db.h"
 #include "IPInterception.h"
 
 static PSC fwdStartCompleteWrapper;
index a0d9f503c8410905a9c684a6ef5753ae02afa4c4..b1ab9d798e1ed9d4e2a8e57dda5aa83a4e5fde59 100644 (file)
@@ -44,6 +44,7 @@
 #include "comm.h"
 #include "MemBuf.h"
 #include "http.h"
+#include "icmp/net_db.h"
 
 typedef struct _Countstr Countstr;
 
@@ -857,7 +858,6 @@ htcpAccessCheck(acl_access * acl, htcpSpecifier * s, IPAddress &from)
 }
 
 static void
-
 htcpTstReply(htcpDataHeader * dhdr, StoreEntry * e, htcpSpecifier * spec, IPAddress &from)
 {
     htcpStuff stuff;
@@ -867,9 +867,6 @@ htcpTstReply(htcpDataHeader * dhdr, StoreEntry * e, htcpSpecifier * spec, IPAddr
     Packer p;
     ssize_t pktlen;
     char *host;
-    int rtt = 0;
-    int hops = 0;
-    int samp = 0;
     char cto_buf[128];
     memset(&stuff, '\0', sizeof(stuff));
     stuff.op = HTCP_TST;
@@ -911,7 +908,11 @@ htcpTstReply(htcpDataHeader * dhdr, StoreEntry * e, htcpSpecifier * spec, IPAddr
 
         hdr.reset();
 
+#if USE_ICMP
         if ((host = urlHostname(spec->uri))) {
+           int rtt = 0;
+           int hops = 0;
+            int samp = 0;
             netdbHostData(host, &samp, &rtt, &hops);
 
             if (rtt || hops) {
@@ -920,6 +921,7 @@ htcpTstReply(htcpDataHeader * dhdr, StoreEntry * e, htcpSpecifier * spec, IPAddr
                 hdr.putExt("Cache-to-Origin", cto_buf);
             }
         }
+#endif /* USE_ICMP */
 
         hdr.packInto(&p);
         stuff.D.cache_hdrs = xstrdup(mb.buf);
index 11b2d627eff1fd111965070eda1e51d63864fcc6..4928ff39508f5da4bcf9b6e7ce9cbb82a412f262 100644 (file)
@@ -33,7 +33,8 @@
  */
 
 #include "squid.h"
-#include "IcmpSquid.h"
+#include "icmp/IcmpSquid.h"
+#include "icmp/net_db.h"
 #include "comm.h"
 #include "SquidTime.h"
 
index d15fc1e823e1bd0ffc9edc3ff571b3b1e59921b4..12928a8e1c2f9caf4c823712c9c55eebb5e91c90 100644 (file)
@@ -41,6 +41,7 @@
  */
 
 #include "squid.h"
+#include "icmp/net_db.h"
 #include "cbdata.h"
 #include "event.h"
 #include "CacheManager.h"
@@ -56,7 +57,7 @@
 #include "IPAddress.h"
 
 #if USE_ICMP
-#include "IcmpSquid.h"
+#include "icmp/IcmpSquid.h"
 #include "StoreClient.h"
 
 #define        NETDB_REQBUF_SZ 4096
@@ -1059,8 +1060,7 @@ netdbDump(StoreEntry * sentry)
     xfree(list);
 #else
 
-    storeAppendPrintf(sentry,
-                      "NETDB support not compiled into this Squid cache.\n");
+    storeAppendPrintf(sentry,"NETDB support not compiled into this Squid cache.\n");
 #endif
 }
 
@@ -1193,7 +1193,6 @@ netdbExchangeUpdatePeer(IPAddress &addr, peer * e, double rtt, double hops)
 }
 
 void
-
 netdbDeleteAddrNetwork(IPAddress &addr)
 {
 #if USE_ICMP
@@ -1205,10 +1204,10 @@ netdbDeleteAddrNetwork(IPAddress &addr)
     debugs(38, 3, "netdbDeleteAddrNetwork: " << n->network);
 
     netdbRelease(n);
-
 #endif
 }
 
+
 void
 netdbBinaryExchange(StoreEntry * s)
 {
index 60596abb165d1a51d3ecbee8e820efee775dfb1d..e79f51ef016cd0c76338c05ead7df53801fb283a 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef ICMP_NET_DB_H
 #define ICMP_NET_DB_H
 
+#include "config.h"
 
 class IPAddress;
 class StoreEntry;
@@ -33,5 +34,4 @@ SQUIDCEXTERN void netdbExchangeUpdatePeer(IPAddress &, peer *, double, double);
 SQUIDCEXTERN peer *netdbClosestParent(HttpRequest *);
 SQUIDCEXTERN void netdbHostData(const char *host, int *samp, int *rtt, int *hops);
 
-
 #endif /* ICMP_NET_DB_H */
index facf268318e4bbfb334aa94408e9381b049b8cb9..47b7b4eec201388f6b94f3763eeec9c5c4fb2762 100644 (file)
@@ -49,6 +49,7 @@
 #include "SquidTime.h"
 #include "SwapDir.h"
 #include "IPAddress.h"
+#include "icmp/net_db.h"
 
 /// \ingroup ServerProtocolICPInternal2
 static void icpLogIcp(const IPAddress &, log_type, int, const char *, int);
@@ -151,10 +152,12 @@ ICP2State::created(StoreEntry *newEntry)
     if (icpCheckUdpHit(entry, request)) {
         codeToSend = ICP_HIT;
     } else {
+#if USE_ICMP
         if (Config.onoff.test_reachability && rtt == 0) {
             if ((rtt = netdbHostRtt(request->GetHost())) == 0)
                 netdbPingSite(request->GetHost());
         }
+#endif /* USE_ICMP */
 
         if (icpGetCommonOpcode() != ICP_ERR)
             codeToSend = icpGetCommonOpcode();
@@ -461,7 +464,7 @@ doV2Query(int fd, IPAddress &from, char *buf, icp_common_t header)
         HTTPMSGUNLOCK(icp_request);
         return;
     }
-
+#if USE_ICMP
     if (header.flags & ICP_FLAG_SRC_RTT) {
         rtt = netdbHostRtt(icp_request->GetHost());
         int hops = netdbHostHops(icp_request->GetHost());
@@ -470,6 +473,7 @@ doV2Query(int fd, IPAddress &from, char *buf, icp_common_t header)
         if (rtt)
             flags |= ICP_FLAG_SRC_RTT;
     }
+#endif /* USE_ICMP */
 
     /* The peer is allowed to use this cache */
     ICP2State *state = new ICP2State (header, icp_request);
index a5527564eb765cd939af865ed10b36aecba95203..68e62e69e1f9902c982d3a508a253a82ff4d4b09 100644 (file)
@@ -41,6 +41,7 @@
 #include "MemBuf.h"
 #include "SquidTime.h"
 #include "wordlist.h"
+#include "icmp/net_db.h"
 
 /* called when we "miss" on an internal object;
  * generate known dynamic objects,
@@ -60,7 +61,7 @@ internalStart(HttpRequest * request, StoreEntry * entry)
         const char *msgbuf = "This cache is currently building its digest.\n";
 #else
 
-        const char *msgbuf = "This cache does not suport Cache Digests.\n";
+        const char *msgbuf = "This cache does not support Cache Digests.\n";
 #endif
 
         HttpVersion version(1, 0);
index 4adf37e17055623cd850f03d4895761aaca260bd..816d430483a2a4fd96c4cc188e900290ad4b613d 100644 (file)
@@ -68,7 +68,8 @@
 #include "SwapDir.h"
 #include "forward.h"
 #include "MemPool.h"
-#include "ICMPSquid.h"
+#include "icmp/IcmpSquid.h"
+#include "icmp/net_db.h"
 #include "TextException.h"
 
 #if USE_LOADABLE_MODULES
index 537b65d6e1011523146b74e1c1c1f429de914c40..eca7c06582aa8c698a0fab86014927d4ea0f4676 100644 (file)
@@ -47,6 +47,7 @@
 #include "SquidTime.h"
 #include "Store.h"
 #include "IPAddress.h"
+#include "icmp/net_db.h"
 
 /* count mcast group peers every 15 minutes */
 #define MCAST_COUNT_RATE 900
@@ -1278,9 +1279,12 @@ peerDNSConfigure(const ipcache_addrs * ia, void *data)
     if (p->type == PEER_MULTICAST)
         peerCountMcastPeersSchedule(p, 10);
 
+#if USE_ICMP
     if (p->type != PEER_MULTICAST)
         if (!p->options.no_netdb_exchange)
             eventAddIsh("netdbExchangeStart", netdbExchangeStart, p, 30.0, 1);
+#endif
+
 }
 
 static void
index 2492130eb945a6a56933971cceeb29298951235e..49cbdff0fe70a0b4fe1a20a0913224ac1f459d6c 100644 (file)
@@ -42,6 +42,7 @@
 #include "htcp.h"
 #include "forward.h"
 #include "SquidTime.h"
+#include "icmp/net_db.h"
 
 const char *hier_strings[] = {
     "NONE",
@@ -241,6 +242,7 @@ peerSelectCallback(ps_state * psstate)
 static int
 peerCheckNetdbDirect(ps_state * psstate)
 {
+#if USE_ICMP
     peer *p;
     int myrtt;
     int myhops;
@@ -248,12 +250,13 @@ peerCheckNetdbDirect(ps_state * psstate)
     if (psstate->direct == DIRECT_NO)
         return 0;
 
+    /* base lookup on RTT and Hops if ICMP NetDB is enabled. */
+
     myrtt = netdbHostRtt(psstate->request->GetHost());
 
     debugs(44, 3, "peerCheckNetdbDirect: MY RTT = " << myrtt << " msec");
     debugs(44, 3, "peerCheckNetdbDirect: minimum_direct_rtt = " << Config.minDirectRtt << " msec");
 
-
     if (myrtt && myrtt <= Config.minDirectRtt)
         return 1;
 
@@ -262,7 +265,6 @@ peerCheckNetdbDirect(ps_state * psstate)
     debugs(44, 3, "peerCheckNetdbDirect: MY hops = " << myhops);
     debugs(44, 3, "peerCheckNetdbDirect: minimum_direct_hops = " << Config.minDirectHops);
 
-
     if (myhops && myhops <= Config.minDirectHops)
         return 1;
 
@@ -276,6 +278,8 @@ peerCheckNetdbDirect(ps_state * psstate)
     if (myrtt && myrtt <= psstate->ping.p_rtt)
         return 1;
 
+#endif /* USE_ICMP */
+
     return 0;
 }
 
@@ -396,7 +400,7 @@ peerSelectPinned(ps_state * ps)
  * following methods:
  *      Cache Digests
  *      CARP
- *      Netdb RTT estimates
+ *      ICMP Netdb RTT estimates
  *      ICP/HTCP queries
  */
 static void
@@ -621,12 +625,12 @@ static void
 peerIcpParentMiss(peer * p, icp_common_t * header, ps_state * ps)
 {
     int rtt;
-    int hops;
 
+#if USE_ICMP
     if (Config.onoff.query_icmp) {
         if (header->flags & ICP_FLAG_SRC_RTT) {
             rtt = header->pad & 0xFFFF;
-            hops = (header->pad >> 16) & 0xFFFF;
+            int hops = (header->pad >> 16) & 0xFFFF;
 
             if (rtt > 0 && rtt < 0xFFFF)
                 netdbUpdatePeer(ps->request, p, rtt, hops);
@@ -637,6 +641,7 @@ peerIcpParentMiss(peer * p, icp_common_t * header, ps_state * ps)
             }
         }
     }
+#endif /* USE_ICMP */
 
     /* if closest-only is set, then don't allow FIRST_PARENT_MISS */
     if (p->options.closest_only)
@@ -720,12 +725,12 @@ static void
 peerHtcpParentMiss(peer * p, htcpReplyData * htcp, ps_state * ps)
 {
     int rtt;
-    int hops;
 
+#if USE_ICMP
     if (Config.onoff.query_icmp) {
         if (htcp->cto.rtt > 0) {
             rtt = (int) htcp->cto.rtt * 1000;
-            hops = (int) htcp->cto.hops * 1000;
+            int hops = (int) htcp->cto.hops * 1000;
             netdbUpdatePeer(ps->request, p, rtt, hops);
 
             if (rtt && (ps->ping.p_rtt == 0 || rtt < ps->ping.p_rtt)) {
@@ -734,6 +739,7 @@ peerHtcpParentMiss(peer * p, htcpReplyData * htcp, ps_state * ps)
             }
         }
     }
+#endif /* USE_ICMP */
 
     /* if closest-only is set, then don't allow FIRST_PARENT_MISS */
     if (p->options.closest_only)
index 53b20f0c35e7c77d97c5a29b019c4a589eadc0c5..ce37576c2e3013f34e58ec7b74a4053ef2b58854 100644 (file)
@@ -42,6 +42,7 @@
 #include "MemBuf.h"
 #include "forward.h"
 #include "SquidTime.h"
+#include "icmp/net_db.h"
 
 #define        URN_REQBUF_SZ   4096
 
@@ -471,7 +472,6 @@ urnParseReply(const char *inbuf, const HttpRequestMethod& m)
     char *token;
     char *url;
     char *host;
-    int rtt;
     url_entry *list;
     url_entry *old;
     int n = 32;
@@ -496,16 +496,19 @@ urnParseReply(const char *inbuf, const HttpRequestMethod& m)
         if (NULL == host)
             continue;
 
-        rtt = netdbHostRtt(host);
+#if USE_ICMP
+        list[i].rtt = netdbHostRtt(host);
 
-        if (0 == rtt) {
+        if (0 == list[i].rtt) {
             debugs(52, 3, "urnParseReply: Pinging " << host);
             netdbPingSite(host);
         }
+#else
+        list[i].rtt = 0;
+#endif
 
         list[i].url = url;
         list[i].host = xstrdup(host);
-        list[i].rtt = rtt;
         list[i].flags.cached = storeGetPublic(url, m) ? 1 : 0;
         i++;
     }
index 6e10b651a146ef6fb1ad9fa9c6212b45744a3032..953573b0a39de20bf6ce79bb1e656e1992051b5c 100644 (file)
 #include <iostream>
 #include <sstream>
 
+/* AYJ: the debug stuff here should really be in a stub_debug.cc file for tests to link */
+
+/* for correct pre-definitions of debug objects */
+#include "Debug.h"
+
+FILE *debug_log = NULL;
+
 void
 xassert(const char *msg, const char *file, int line)
 {