/*
- * $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
STATE_BODY
} netdb_conn_state_t;
-typedef struct
-{
+typedef struct {
peer *p;
StoreEntry *e;
store_client *sc;
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);
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;
}
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);
}
}
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;
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;
netdbSaveState(void *foo)
{
if (strcmp(Config.netdbFilename, "none") == 0)
- return;
+ return;
Logfile *lf;
netdbEntry *n;
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);
}
netdbReloadState(void)
{
if (strcmp(Config.netdbFilename, "none") == 0)
- return;
+ return;
char *s;
int fd;
netdbEntry *n;
netdbEntry N;
- IPAddress addr;
+ Ip::Address addr;
int count = 0;
struct timeval start = current_time;
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 *
static void
netdbExchangeHandleReply(void *data, StoreIOBuffer receivedData)
{
- IPAddress addr;
+ Ip::Address addr;
netdbExchangeState *ex = (netdbExchangeState *)data;
int rec_sz = 0;
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 */
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;
#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);
}
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
}
}
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;
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;
}
}
void
-
-netdbDeleteAddrNetwork(IPAddress &addr)
+netdbDeleteAddrNetwork(Ip::Address &addr)
{
#if USE_ICMP
netdbEntry *n = netdbLookupAddr(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;
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);
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;
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
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;
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
}