"Bad OPT Version or TSIG Signature Failure"
};
-typedef struct _idns_query idns_query;
-
typedef struct _ns ns;
typedef struct _sp sp;
-typedef struct _nsvc nsvc;
+class idns_query
+{
+ CBDATA_CLASS(idns_query);
+
+public:
+ idns_query() :
+ sz(0),
+ query_id(0),
+ nsends(0),
+ need_vc(0),
+ permit_mdns(false),
+ pending(0),
+ callback(NULL),
+ callback_data(NULL),
+ attempt(0),
+ rcode(0),
+ queue(NULL),
+ slave(NULL),
+ master(NULL),
+ domain(0),
+ do_searchpath(0),
+ message(NULL),
+ ancount(0),
+ error(NULL)
+ {
+ memset(&hash, 0, sizeof(hash));
+ memset(&query, 0, sizeof(query));
+ *buf = 0;
+ *name = 0;
+ *orig = 0;
+ memset(&start_t, 0, sizeof(start_t));
+ memset(&sent_t, 0, sizeof(sent_t));
+ memset(&queue_t, 0, sizeof(queue_t));
+ }
+
+ ~idns_query() {
+ if (message)
+ rfc1035MessageDestroy(&message);
+ delete queue;
+ delete slave;
+ // master is just a back-reference
+ cbdataReferenceDone(callback_data);
+ }
-struct _idns_query {
hash_link hash;
rfc1035_query query;
char buf[RESOLV_BUFSZ];
int ancount;
const char *error;
};
+
InstanceIdDefinitions(idns_query, "dns");
-struct _nsvc {
+CBDATA_CLASS_INIT(idns_query);
+
+class nsvc
+{
+ CBDATA_CLASS(nsvc);
+
+public:
+ explicit nsvc(int nsv) : ns(nsv), msglen(0), read_msglen(0), msg(new MemBuf()), queue(new MemBuf()), busy(true) {}
+ ~nsvc();
+
int ns;
Comm::ConnectionPointer conn;
unsigned short msglen;
bool busy;
};
+CBDATA_CLASS_INIT(nsvc);
+
struct _ns {
Ip::Address S;
int nqueries;
int queries;
};
-CBDATA_TYPE(nsvc);
-CBDATA_TYPE(idns_query);
-
static ns *nameservers = NULL;
static sp *searchpath = NULL;
static int nns = 0;
idnsVCClosed(const CommCloseCbParams ¶ms)
{
nsvc * vc = (nsvc *)params.data;
- delete vc->queue;
- delete vc->msg;
- vc->conn = NULL;
- if (vc->ns < nns) // XXX: Dns::Shutdown may have freed nameservers[]
- nameservers[vc->ns].vc = NULL;
- cbdataFree(vc);
+ delete vc;
+}
+
+nsvc::~nsvc()
+{
+ delete queue;
+ delete msg;
+ if (ns < nns) // XXX: Dns::Shutdown may have freed nameservers[]
+ nameservers[ns].vc = NULL;
}
static void
idnsInitVC(int nsv)
{
- nsvc *vc = cbdataAlloc(nsvc);
+ nsvc *vc = new nsvc(nsv);
assert(nsv < nns);
assert(vc->conn == NULL); // MUST be NULL from the construction process!
nameservers[nsv].vc = vc;
- vc->ns = nsv;
- vc->queue = new MemBuf;
- vc->msg = new MemBuf;
- vc->busy = 1;
Comm::ConnectionPointer conn = new Comm::Connection();
while ( idns_query *q2 = q->slave ) {
debugs(78, 6, HERE << "Merging DNS results " << q->name << " A has " << n << " RR, AAAA has " << q2->ancount << " RR");
q->slave = q2->slave;
+ q2->slave = NULL;
if ( !q2->error ) {
if (n > 0) {
// two sets of RR need merging
error = NULL;
}
}
- rfc1035MessageDestroy(&q2->message);
- cbdataFree(q2);
+ delete q2;
}
debugs(78, 6, HERE << "Sending " << n << " (" << (error ? error : "OK") << ") DNS results to caller.");
while (q->queue) {
idns_query *q2 = q->queue;
q->queue = q2->queue;
+ q2->queue = NULL;
+
callback = q2->callback;
q2->callback = NULL;
if (cbdataReferenceValidDone(q2->callback_data, &cbdata))
callback(cbdata, answers, n, error);
- cbdataFree(q2);
+ delete q2;
}
if (q->hash.key) {
}
rfc1035MessageDestroy(&message);
- cbdataFree(q);
+ delete q;
}
static void
idnsGrokReply(const char *buf, size_t sz, int /*from_ns*/)
{
- int n;
rfc1035_message *message = NULL;
- idns_query *q;
- n = rfc1035MessageUnpack(buf, sz, &message);
+ int n = rfc1035MessageUnpack(buf, sz, &message);
if (message == NULL) {
debugs(78, DBG_IMPORTANT, "idnsGrokReply: Malformed DNS response");
debugs(78, 3, "idnsGrokReply: QID 0x" << std::hex << message->id << ", " << std::dec << n << " answers");
- q = idnsFindQuery(message->id);
+ idns_query *q = idnsFindQuery(message->id);
if (q == NULL) {
debugs(78, 3, "idnsGrokReply: Late response");
while (idns_query *slave = q->slave) {
dlinkDelete(&slave->lru, &lru_list);
q->slave = slave->slave;
- rfc1035MessageDestroy(&slave->message);
- cbdataFree(slave);
+ slave->slave = NULL;
+ delete slave;
}
// Build new query
{
static int init = 0;
- CBDATA_INIT_TYPE(nsvc);
- CBDATA_INIT_TYPE(idns_query);
-
if (DnsSocketA < 0 && DnsSocketB < 0) {
Ip::Address addrV6; // since we don't want to alter Config.Addrs.udp_* and dont have one of our own.
static int
idnsCachedLookup(const char *key, IDNSCB * callback, void *data)
{
- idns_query *q;
-
idns_query *old = (idns_query *) hash_lookup(idns_lookup_hash, key);
if (!old)
return 0;
- q = cbdataAlloc(idns_query);
- // idns_query is POD so no constructors are called after allocation
- q->xact_id.change();
+ idns_query *q = new idns_query;
// no query_id on this instance.
q->callback = callback;
-
q->callback_data = cbdataReference(data);
q->queue = old->queue;
-
old->queue = q;
return 1;
static void
idnsSendSlaveAAAAQuery(idns_query *master)
{
- idns_query *q = cbdataAlloc(idns_query);
+ idns_query *q = new idns_query;
memcpy(q->name, master->name, sizeof(q->name));
memcpy(q->orig, master->orig, sizeof(q->orig));
q->master = master;
q->query_id = idnsQueryID();
q->sz = rfc3596BuildAAAAQuery(q->name, q->buf, sizeof(q->buf), q->query_id, &q->query, Config.dns.packet_max);
- q->start_t = master->start_t;
- q->slave = master->slave;
debugs(78, 3, HERE << "buf is " << q->sz << " bytes for " << q->name <<
", id = 0x" << std::hex << q->query_id);
if (!q->sz) {
- cbdataFree(q);
+ delete q;
return;
}
+
+ q->start_t = master->start_t;
+ q->slave = master->slave;
+
idnsCheckMDNS(q);
master->slave = q;
idnsSendQuery(q);
if (idnsCachedLookup(name, callback, data))
return;
- idns_query *q = cbdataAlloc(idns_query);
- // idns_query is POD so no constructors are called after allocation
- q->xact_id.change();
+ idns_query *q = new idns_query;
q->query_id = idnsQueryID();
int nd = 0;
if (q->sz < 0) {
/* problem with query data -- query not sent */
callback(data, NULL, 0, "Internal error");
- cbdataFree(q);
+ delete q;
return;
}
if (Ip::EnableIpv6)
idnsSendSlaveAAAAQuery(q);
-
}
void
idnsPTRLookup(const Ip::Address &addr, IDNSCB * callback, void *data)
{
- idns_query *q;
-
char ip[MAX_IPSTRLEN];
addr.toStr(ip,MAX_IPSTRLEN);
- q = cbdataAlloc(idns_query);
-
- // idns_query is POD so no constructors are called after allocation
- q->xact_id.change();
+ idns_query *q = new idns_query;
q->query_id = idnsQueryID();
if (addr.isIPv6()) {
if (q->sz < 0) {
/* problem with query data -- query not sent */
callback(data, NULL, 0, "Internal error");
- cbdataFree(q);
+ delete q;
return;
}
if (idnsCachedLookup(q->query.name, callback, data)) {
- cbdataFree(q);
+ delete q;
return;
}