From: Amos Jeffries Date: Sat, 11 Oct 2008 13:21:08 +0000 (+1300) Subject: General ICMP dependant cleanups. X-Git-Tag: SQUID_3_2_0_1~1398^2~4 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9b5c4a9a0762dc4410413d64bfc7c7073092086d;p=thirdparty%2Fsquid.git General ICMP dependant cleanups. 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. --- diff --git a/src/Makefile.am b/src/Makefile.am index a1d9c5edfd..6a8ef35f04 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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} \ diff --git a/src/comm.cc b/src/comm.cc index 8e3e156ca5..46aa0e4685 100644 --- a/src/comm.cc +++ b/src/comm.cc @@ -50,6 +50,7 @@ #include "IPAddress.h" #include "IPInterception.h" #include "DescriptorSet.h" +#include "icmp/net_db.h" #if defined(_SQUID_CYGWIN_) #include @@ -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); diff --git a/src/fd.cc b/src/fd.cc index cc98eb9fec..a14a1b9785 100644 --- 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); diff --git a/src/forward.cc b/src/forward.cc index 39471e21d9..dae274ef25 100644 --- a/src/forward.cc +++ b/src/forward.cc @@ -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; diff --git a/src/htcp.cc b/src/htcp.cc index a0d9f503c8..b1ab9d798e 100644 --- a/src/htcp.cc +++ b/src/htcp.cc @@ -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); diff --git a/src/icmp/IcmpSquid.cc b/src/icmp/IcmpSquid.cc index 11b2d627ef..4928ff3950 100644 --- a/src/icmp/IcmpSquid.cc +++ b/src/icmp/IcmpSquid.cc @@ -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" diff --git a/src/icmp/net_db.cc b/src/icmp/net_db.cc index d15fc1e823..12928a8e1c 100644 --- a/src/icmp/net_db.cc +++ b/src/icmp/net_db.cc @@ -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) { diff --git a/src/icmp/net_db.h b/src/icmp/net_db.h index 60596abb16..e79f51ef01 100644 --- a/src/icmp/net_db.h +++ b/src/icmp/net_db.h @@ -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 */ diff --git a/src/icp_v2.cc b/src/icp_v2.cc index facf268318..47b7b4eec2 100644 --- a/src/icp_v2.cc +++ b/src/icp_v2.cc @@ -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); diff --git a/src/internal.cc b/src/internal.cc index a5527564eb..68e62e69e1 100644 --- a/src/internal.cc +++ b/src/internal.cc @@ -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); diff --git a/src/main.cc b/src/main.cc index 4adf37e170..816d430483 100644 --- a/src/main.cc +++ b/src/main.cc @@ -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 diff --git a/src/neighbors.cc b/src/neighbors.cc index 537b65d6e1..eca7c06582 100644 --- a/src/neighbors.cc +++ b/src/neighbors.cc @@ -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 diff --git a/src/peer_select.cc b/src/peer_select.cc index 2492130eb9..49cbdff0fe 100644 --- a/src/peer_select.cc +++ b/src/peer_select.cc @@ -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) diff --git a/src/urn.cc b/src/urn.cc index 53b20f0c35..ce37576c2e 100644 --- a/src/urn.cc +++ b/src/urn.cc @@ -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++; } diff --git a/test-suite/test_tools.cc b/test-suite/test_tools.cc index 6e10b651a1..953573b0a3 100644 --- a/test-suite/test_tools.cc +++ b/test-suite/test_tools.cc @@ -10,6 +10,13 @@ #include #include +/* 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) {