]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/icmp/net_db.cc
Merge form trunk
[thirdparty/squid.git] / src / icmp / net_db.cc
index 659c6ba55626908c99f3c04529d7c54b0894e12d..216847484264c6d6a28ac9a0bd56bac292bc2b32 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id: net_db.cc,v 1.202 2008/01/07 17:12:28 hno Exp $
- *
  * DEBUG: section 38    Network Measurement Database
  * AUTHOR: Duane Wessels
  *
  *  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.
  */
 
 #include "squid.h"
+#include "icmp/net_db.h"
+#include "log/File.h"
 #include "cbdata.h"
 #include "event.h"
-#include "CacheManager.h"
+#include "mgr/Registration.h"
 #include "Store.h"
 #include "SwapDir.h"
 #include "HttpRequest.h"
 #include "forward.h"
 #include "SquidTime.h"
 #include "wordlist.h"
-#include "IPAddress.h"
+#include "ip/Address.h"
 
 #if USE_ICMP
-#include "IcmpSquid.h"
+#include "icmp/IcmpSquid.h"
 #include "StoreClient.h"
 
 #define        NETDB_REQBUF_SZ 4096
@@ -67,8 +67,7 @@ typedef enum {
     STATE_BODY
 } netdb_conn_state_t;
 
-typedef struct
-{
+typedef struct {
     peer *p;
     StoreEntry *e;
     store_client *sc;
@@ -83,10 +82,10 @@ typedef struct
 static hash_table *addr_table = NULL;
 static hash_table *host_table = NULL;
 
-IPAddress networkFromInaddr(const IPAddress &a);
+Ip::Address networkFromInaddr(const Ip::Address &a);
 static void netdbRelease(netdbEntry * n);
 
-static void netdbHashInsert(netdbEntry * n, IPAddress &addr);
+static void netdbHashInsert(netdbEntry * n, Ip::Address &addr);
 static void netdbHashDelete(const char *key);
 static void netdbHostInsert(netdbEntry * n, const char *hostname);
 static void netdbHostDelete(const net_db_name * x);
@@ -111,7 +110,7 @@ static void netdbExchangeDone(void *);
 static wordlist *peer_names = NULL;
 
 static void
-netdbHashInsert(netdbEntry * n, IPAddress &addr)
+netdbHashInsert(netdbEntry * n, Ip::Address &addr)
 {
     networkFromInaddr(addr).NtoA(n->network, MAX_IPSTRLEN);
     n->hash.key = n->network;
@@ -247,25 +246,25 @@ netdbPurgeLRU(void)
 }
 
 static netdbEntry *
-netdbLookupAddr(const IPAddress &addr)
+netdbLookupAddr(const Ip::Address &addr)
 {
     netdbEntry *n;
     char *key = new char[MAX_IPSTRLEN];
     networkFromInaddr(addr).NtoA(key,MAX_IPSTRLEN);
     n = (netdbEntry *) hash_lookup(addr_table, key);
+    delete[] key;
     return n;
 }
 
 static netdbEntry *
-netdbAdd(IPAddress &addr)
+netdbAdd(Ip::Address &addr)
 {
     netdbEntry *n;
 
     if (memInUse(MEM_NETDBENTRY) > Config.Netdb.high)
         netdbPurgeLRU();
 
-    if ((n = netdbLookupAddr(addr)) == NULL)
-    {
+    if ((n = netdbLookupAddr(addr)) == NULL) {
         n = (netdbEntry *)memAllocate(MEM_NETDBENTRY);
         netdbHashInsert(n, addr);
     }
@@ -274,9 +273,9 @@ netdbAdd(IPAddress &addr)
 }
 
 static void
-netdbSendPing(const ipcache_addrs * ia, void *data)
+netdbSendPing(const ipcache_addrs *ia, const DnsLookupDetails &, void *data)
 {
-    IPAddress addr;
+    Ip::Address addr;
     char *hostname = NULL;
     static_cast<generic_cbdata *>(data)->unwrap(&hostname);
     netdbEntry *n;
@@ -341,23 +340,19 @@ netdbSendPing(const ipcache_addrs * ia, void *data)
     xfree(hostname);
 }
 
-IPAddress
-networkFromInaddr(const IPAddress &in)
+Ip::Address
+networkFromInaddr(const Ip::Address &in)
 {
-    IPAddress out;
+    Ip::Address out;
 
     out = in;
-#if USE_IPV6
 
     /* in IPv6 the 'network' should be the routing section. */
-
-    if( in.IsIPv6() )
-    {
+    if ( in.IsIPv6() ) {
         out.ApplyMask(64, AF_INET6);
         debugs(14, 5, "networkFromInaddr : Masked IPv6 Address to " << in << "/64 routing part.");
         return out;
     }
-#endif
 
 #if USE_CLASSFUL
     struct in_addr b;
@@ -465,7 +460,7 @@ static void
 netdbSaveState(void *foo)
 {
     if (strcmp(Config.netdbFilename, "none") == 0)
-       return;
+        return;
 
     Logfile *lf;
     netdbEntry *n;
@@ -519,8 +514,8 @@ netdbSaveState(void *foo)
     logfileClose(lf);
     getCurrentTime();
     debugs(38, 1, "NETDB state saved; " <<
-                 count << " entries, " <<
-                 tvSubMsec(start, current_time) << " msec" );
+           count << " entries, " <<
+           tvSubMsec(start, current_time) << " msec" );
     eventAddIsh("netdbSaveState", netdbSaveState, NULL, 3600.0, 1);
 }
 
@@ -528,7 +523,7 @@ static void
 netdbReloadState(void)
 {
     if (strcmp(Config.netdbFilename, "none") == 0)
-       return;
+        return;
 
     char *s;
     int fd;
@@ -538,7 +533,7 @@ netdbReloadState(void)
     netdbEntry *n;
     netdbEntry N;
 
-    IPAddress addr;
+    Ip::Address addr;
     int count = 0;
 
     struct timeval start = current_time;
@@ -642,8 +637,8 @@ netdbReloadState(void)
     xfree(buf);
     getCurrentTime();
     debugs(38, 1, "NETDB state reloaded; " <<
-                  count << " entries, " << 
-                  tvSubMsec(start, current_time) << " msec" );
+           count << " entries, " <<
+           tvSubMsec(start, current_time) << " msec" );
 }
 
 static const char *
@@ -679,7 +674,7 @@ netdbFreeNameEntry(void *data)
 static void
 netdbExchangeHandleReply(void *data, StoreIOBuffer receivedData)
 {
-    IPAddress addr;
+    Ip::Address addr;
 
     netdbExchangeState *ex = (netdbExchangeState *)data;
     int rec_sz = 0;
@@ -887,8 +882,7 @@ netdbExchangeDone(void *data)
 static void
 netdbRegisterWithCacheManager(void)
 {
-    CacheManager::GetInstance()->
-        registerAction("netdb", "Network Measurement Database", netdbDump, 0, 1);
+    Mgr::RegisterAction("netdb", "Network Measurement Database", netdbDump, 0, 1);
 }
 
 #endif /* USE_ICMP */
@@ -933,13 +927,13 @@ netdbPingSite(const char *hostname)
             return;
 
     ipcache_nbgethostbyname(hostname, netdbSendPing,
-                           new generic_cbdata(xstrdup(hostname)));
+                            new generic_cbdata(xstrdup(hostname)));
 
 #endif
 }
 
 void
-netdbHandlePingReply(const IPAddress &from, int hops, int rtt)
+netdbHandlePingReply(const Ip::Address &from, int hops, int rtt)
 {
 #if USE_ICMP
     netdbEntry *n;
@@ -986,13 +980,12 @@ netdbFreeMemory(void)
 
 #if 0 // AYJ: Looks to be unused code.
 int
-netdbHops(IPAddress &addr)
+netdbHops(Ip::Address &addr)
 {
 #if USE_ICMP
     netdbEntry *n = netdbLookupAddr(addr);
 
-    if (n && n->pings_recv)
-    {
+    if (n && n->pings_recv) {
         n->last_use_time = squid_curtime;
         return (int) (n->hops + 0.5);
     }
@@ -1063,8 +1056,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
 }
 
@@ -1155,7 +1147,7 @@ netdbUpdatePeer(HttpRequest * r, peer * e, int irtt, int ihops)
 }
 
 void
-netdbExchangeUpdatePeer(IPAddress &addr, peer * e, double rtt, double hops)
+netdbExchangeUpdatePeer(Ip::Address &addr, peer * e, double rtt, double hops)
 {
 #if USE_ICMP
     netdbEntry *n;
@@ -1164,7 +1156,7 @@ netdbExchangeUpdatePeer(IPAddress &addr, peer * e, double rtt, double hops)
            std::setfill('0')<< std::setprecision(2) << hops << " hops, " <<
            rtt << " rtt");
 
-    if( !addr.IsIPv4() ) {
+    if ( !addr.IsIPv4() ) {
         debugs(38, 5, "netdbExchangeUpdatePeer: Aborting peer update for '" << addr << "', NetDB cannot handle IPv6.");
         return;
     }
@@ -1197,8 +1189,7 @@ netdbExchangeUpdatePeer(IPAddress &addr, peer * e, double rtt, double hops)
 }
 
 void
-
-netdbDeleteAddrNetwork(IPAddress &addr)
+netdbDeleteAddrNetwork(Ip::Address &addr)
 {
 #if USE_ICMP
     netdbEntry *n = netdbLookupAddr(addr);
@@ -1209,17 +1200,17 @@ netdbDeleteAddrNetwork(IPAddress &addr)
     debugs(38, 3, "netdbDeleteAddrNetwork: " << n->network);
 
     netdbRelease(n);
-
 #endif
 }
 
+
 void
 netdbBinaryExchange(StoreEntry * s)
 {
     HttpReply *reply = new HttpReply;
 #if USE_ICMP
 
-    IPAddress addr;
+    Ip::Address addr;
 
     netdbEntry *n;
     int i;
@@ -1229,8 +1220,7 @@ netdbBinaryExchange(StoreEntry * s)
 
     struct in_addr line_addr;
     s->buffer();
-    HttpVersion version(1, 0);
-    reply->setHeaders(version, HTTP_OK, "OK", NULL, -1, squid_curtime, -2);
+    reply->setHeaders(HTTP_OK, "OK", NULL, -1, squid_curtime, -2);
     s->replaceHttpReply(reply);
     rec_sz = 0;
     rec_sz += 1 + sizeof(struct in_addr);
@@ -1251,7 +1241,7 @@ netdbBinaryExchange(StoreEntry * s)
             continue;
 
         /* FIXME INET6 : NetDB cannot yet handle IPv6 addresses. Ensure only IPv4 get sent. */
-        if( !addr.IsIPv4() )
+        if ( !addr.IsIPv4() )
             continue;
 
         buf[i++] = (char) NETDB_EX_NETWORK;
@@ -1293,9 +1283,7 @@ netdbBinaryExchange(StoreEntry * s)
     memFree(buf, MEM_4K_BUF);
 #else
 
-    HttpVersion version(1,0);
-    reply->setHeaders(version, HTTP_BAD_REQUEST, "Bad Request",
-                      NULL, -1, squid_curtime, -2);
+    reply->setHeaders(HTTP_BAD_REQUEST, "Bad Request", NULL, -1, squid_curtime, -2);
     s->replaceHttpReply(reply);
     storeAppendPrintf(s, "NETDB support not compiled into this Squid cache.\n");
 #endif
@@ -1330,7 +1318,7 @@ netdbExchangeStart(void *data)
 
     HTTPMSGLOCK(ex->r);
     assert(NULL != ex->r);
-    ex->r->http_ver = HttpVersion(1,0);
+    ex->r->http_ver = HttpVersion(1,1);
     ex->connstate = STATE_HEADER;
     ex->e = storeCreateEntry(uri, uri, request_flags(), METHOD_GET);
     ex->buf_sz = NETDB_REQBUF_SZ;
@@ -1346,7 +1334,10 @@ netdbExchangeStart(void *data)
     if (p->login)
         xstrncpy(ex->r->login, p->login, MAX_LOGIN_SZ);
 
-    FwdState::fwdStart(-1, ex->e, ex->r);
+    urlCanonical(ex->r);
+
+    Comm::ConnectionPointer nul;
+    FwdState::fwdStart(nul, ex->e, ex->r);
 
 #endif
 }