-
/*
- * DEBUG: section 53 AS Number handling
- * AUTHOR: Duane Wessels, Kostas Anagnostakis
- *
- * SQUID Web Proxy Cache http://www.squid-cache.org/
- * ----------------------------------------------------------
- *
- * Squid is the result of efforts by numerous individuals from
- * the Internet community; see the CONTRIBUTORS file for full
- * details. Many organizations have provided support for Squid's
- * development; see the SPONSORS file for full details. Squid is
- * Copyrighted (C) 2001 by the Regents of the University of
- * California; see the COPYRIGHT file for full details. Squid
- * incorporates software developed and/or copyrighted by other
- * sources; see the CREDITS file for full details.
- *
- * This program is free software; you can redistribute it and/or modify
- * 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.
+ * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
*
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
*/
+/* DEBUG: section 53 AS Number handling */
+
#include "squid.h"
#include "acl/Acl.h"
#include "acl/Asn.h"
#include "acl/DestinationIp.h"
#include "acl/SourceAsn.h"
#include "cache_cf.h"
-#include "src/forward.h"
+#include "FwdState.h"
#include "HttpReply.h"
#include "HttpRequest.h"
#include "ipcache.h"
#include "Store.h"
#include "StoreClient.h"
#include "StoreClient.h"
-#include "wordlist.h"
#define WHOIS_PORT 43
-#define AS_REQBUF_SZ 4096
+#define AS_REQBUF_SZ 4096
/* BEGIN of definitions for radix tree entries */
/* explicit instantiation required for some systems */
-/// \cond AUTODOCS-IGNORE
+/// \cond AUTODOCS_IGNORE
template cbdata_type CbDataList<int>::CBDATA_CbDataList;
/// \endcond
*/
struct as_info {
CbDataList<int> *as_number;
- time_t expires; /* NOTUSED */
+ time_t expires; /* NOTUSED */
};
-struct ASState {
+class ASState
+{
+ CBDATA_CLASS(ASState);
+
+public:
+ ASState();
+ ~ASState();
+
StoreEntry *entry;
store_client *sc;
- HttpRequest *request;
+ HttpRequest::Pointer request;
int as_number;
int64_t offset;
int reqofs;
bool dataRead;
};
+CBDATA_CLASS_INIT(ASState);
+
+ASState::ASState() :
+ entry(NULL),
+ sc(NULL),
+ request(NULL),
+ as_number(0),
+ offset(0),
+ reqofs(0),
+ dataRead(false)
+{
+ memset(reqbuf, 0, AS_REQBUF_SZ);
+}
+
+ASState::~ASState()
+{
+ debugs(53, 3, entry->url());
+ storeUnregister(sc, entry, this);
+ entry->unlock("~ASState");
+}
+
/** entry into the radix tree */
struct rtentry_t {
struct squid_radix_node e_nodes[2];
extern "C" {
#endif
- static int destroyRadixNode(struct squid_radix_node *rn, void *w);
- static int printRadixNode(struct squid_radix_node *rn, void *sentry);
+static int destroyRadixNode(struct squid_radix_node *rn, void *w);
+static int printRadixNode(struct squid_radix_node *rn, void *sentry);
#if defined(__cplusplus)
}
void asnAclInitialize(ACL * acls);
-static void asStateFree(void *data);
-
static void destroyRadixNodeInfo(as_info *);
static OBJH asnStats;
if (AS_tree_head == NULL)
return 0;
- if (addr.IsNoAddr())
+ if (addr.isNoAddr())
return 0;
- if (addr.IsAnyAddr())
+ if (addr.isAnyAddr())
return 0;
m_addr.addr = addr;
/* initialize the radix tree structure */
-SQUIDCEXTERN int squid_max_keylen; /* yuck.. this is in lib/radix.c */
+SQUIDCEXTERN int squid_max_keylen; /* yuck.. this is in lib/radix.c */
-CBDATA_TYPE(ASState);
void
asnInit(void)
{
static bool inited = false;
squid_max_keylen = 40;
- CBDATA_INIT_TYPE(ASState);
if (!inited) {
inited = true;
{
LOCAL_ARRAY(char, asres, 4096);
StoreEntry *e;
- ASState *asState;
- asState = cbdataAlloc(ASState);
- asState->dataRead = 0;
- debugs(53, 3, "asnCacheStart: AS " << as);
+ ASState *asState = new ASState;
+ debugs(53, 3, "AS " << as);
snprintf(asres, 4096, "whois://%s/!gAS%d", Config.as_whois_server, as);
asState->as_number = as;
asState->request = HttpRequest::CreateFromUrl(asres);
- assert(NULL != asState->request);
- HTTPMSGLOCK(asState->request);
+ assert(asState->request != NULL);
if ((e = storeGetPublic(asres, Http::METHOD_GET)) == NULL) {
e = storeCreateEntry(asres, asres, RequestFlags(), Http::METHOD_GET);
asState->sc = storeClientListAdd(e, asState);
- FwdState::fwdStart(Comm::ConnectionPointer(), e, asState->request);
+ FwdState::fwdStart(Comm::ConnectionPointer(), e, asState->request.getRaw());
} else {
-
- e->lock();
+ e->lock("Asn");
asState->sc = storeClientListAdd(e, asState);
}
asState->entry = e;
- asState->offset = 0;
- asState->reqofs = 0;
StoreIOBuffer readBuffer (AS_REQBUF_SZ, asState->offset, asState->reqbuf);
- storeClientCopy(asState->sc,
- e,
- readBuffer,
- asHandleReply,
- asState);
+ storeClientCopy(asState->sc, e, readBuffer, asHandleReply, asState);
}
static void
/* First figure out whether we should abort the request */
if (EBIT_TEST(e->flags, ENTRY_ABORTED)) {
- asStateFree(asState);
+ delete asState;
return;
}
if (result.length == 0 && asState->dataRead) {
- debugs(53, 3, "asHandleReply: Done: " << e->url() );
- asStateFree(asState);
+ debugs(53, 3, "asHandleReply: Done: " << e->url());
+ delete asState;
return;
} else if (result.flags.error) {
debugs(53, DBG_IMPORTANT, "asHandleReply: Called with Error set and size=" << (unsigned int) result.length);
- asStateFree(asState);
+ delete asState;
return;
} else if (e->getReply()->sline.status() != Http::scOkay) {
debugs(53, DBG_IMPORTANT, "WARNING: AS " << asState->as_number << " whois request failed");
- asStateFree(asState);
+ delete asState;
return;
}
debugs(53, 3, "asHandleReply: AS# " << s << " (" << asState->as_number << ")");
asnAddNet(s, asState->as_number);
s = t + 1;
- asState->dataRead = 1;
+ asState->dataRead = true;
}
/*
}
}
-static void
-asStateFree(void *data)
-{
- ASState *asState = (ASState *)data;
- debugs(53, 3, "asnStateFree: " << asState->entry->url() );
- storeUnregister(asState->sc, asState->entry, asState);
- asState->entry->unlock();
- HTTPMSGUNLOCK(asState->request);
- cbdataFree(asState);
-}
-
/**
* add a network (addr, mask) to the radix tree, with matching AS number
*/
t = strchr(as_string, '.');
// generate Netbits Format Mask
- mask.SetNoAddr();
- mask.ApplyMask(bitl, (t!=NULL?AF_INET:AF_INET6) );
+ mask.setNoAddr();
+ mask.applyMask(bitl, (t!=NULL?AF_INET:AF_INET6) );
debugs(53, 3, "asnAddNet: called for " << addr << "/" << mask );
e->e_info = asinfo;
}
- if (rn == 0) { /* assert might expand to nothing */
+ if (rn == 0) { /* assert might expand to nothing */
xfree(asinfo);
delete q;
xfree(e);
addr = e->e_addr.addr;
mask = e->e_mask.addr;
storeAppendPrintf(sentry, "%s/%d\t",
- addr.NtoA(buf, MAX_IPSTRLEN),
- mask.GetCIDR() );
+ addr.toStr(buf, MAX_IPSTRLEN),
+ mask.cidr() );
asinfo = e->e_info;
assert(asinfo->as_number);
return asnMatchIp(data, toMatch);
}
-wordlist *
-ACLASN::dump()
+SBufList
+ACLASN::dump() const
{
- wordlist *W = NULL;
- char buf[32];
+ SBufList sl;
+
CbDataList<int> *ldata = data;
while (ldata != NULL) {
- snprintf(buf, sizeof(buf), "%d", ldata->element);
- wordlistAdd(&W, buf);
+ SBuf s;
+ s.Printf("%d", ldata->element);
+ sl.push_back(s);
ldata = ldata->next;
}
- return W;
+ return sl;
}
bool
// else fall through to noaddr match, hiding the lookup failure (XXX)
}
Ip::Address noaddr;
- noaddr.SetNoAddr();
+ noaddr.setNoAddr();
return data->match(noaddr);
}
}
ACLDestinationASNStrategy ACLDestinationASNStrategy::Instance_;
+