/*
- * $Id: dns_internal.cc,v 1.2 1999/04/14 06:35:34 wessels Exp $
+ * $Id: dns_internal.cc,v 1.3 1999/04/15 06:03:48 wessels Exp $
*
* DEBUG: section 78 DNS lookups; interacts with lib/rfc1035.c
* AUTHOR: Duane Wessels
static int nns_alloc = 0;
static int domain_socket = -1;
static dlink_list lru_list;
+static int event_queued = 0;
static OBJH idnsStats;
static void idnsAddNameserver(const char *buf);
static idns_query *idnsFindQuery(unsigned short id);
static void idnsGrokReply(const char *buf, size_t sz);
static PF idnsRead;
+static EVH idnsCheckQueue;
static void
idnsAddNameserver(const char *buf)
{
dlink_node *n;
idns_query *q;
+ int i;
storeAppendPrintf(sentry, "Internal DNS Statistics:\n");
storeAppendPrintf(sentry, "\nThe Queue:\n");
- storeAppendPrintf(sentry, " ID SIZE SENDS DELAY\n");
- storeAppendPrintf(sentry, "---- ---- ----- --------\n");
+ storeAppendPrintf(sentry, " ID SIZE SENDS DELAY\n");
+ storeAppendPrintf(sentry, "------ ---- ----- --------\n");
for (n = lru_list.head; n; n = n->next) {
q = n->data;
- storeAppendPrintf(sentry, "%#04hx %4d %5d %8.3f\n",
- q->id, q->sz, q->nsends,
- tvSubDsec(q->start, current_time));
+ storeAppendPrintf(sentry, "%#06hx %4d %5d %8.3f\n",
+ q->id, q->sz, q->nsends,
+ tvSubDsec(q->start_t, current_time));
+ }
+ storeAppendPrintf(sentry, "\nNameservers:\n");
+ storeAppendPrintf(sentry, "IP ADDRESS # QUERIES # REPLIES\n");
+ storeAppendPrintf(sentry, "--------------- --------- ---------\n");
+ for (i = 0; i < nns; i++) {
+ storeAppendPrintf(sentry, "%-15s %9d %9d\n",
+ inet_ntoa(nameservers[i].S.sin_addr),
+ nameservers[i].nqueries,
+ nameservers[i].nreplies);
}
}
q->buf,
q->sz);
q->nsends++;
+ q->sent_t = current_time;
+ nameservers[ns].nqueries++;
dlinkAdd(q, &q->lru, &lru_list);
+ if (!event_queued) {
+ eventAdd("idnsCheckQueue", idnsCheckQueue, NULL, 1.0, 1);
+ event_queued = 1;
+ }
}
static int
continue;
if (nameservers[i].S.sin_port != from->sin_port)
continue;
- return 1;
+ return i;
}
- return 0;
+ return -1;
}
static idns_query *
socklen_t from_len;
int max = 10;
static char rbuf[512];
+ int ns;
commSetSelect(fd, COMM_SELECT_READ, idnsRead, NULL, 0);
while (max--) {
from_len = sizeof(from);
fd,
len,
inet_ntoa(from.sin_addr));
- if (!idnsFromKnownNameserver(&from)) {
+ ns = idnsFromKnownNameserver(&from);
+ if (ns < 0) {
debug(78, 1) ("idnsRead: Reply from unknown nameserver [%s]\n",
inet_ntoa(from.sin_addr));
continue;
}
+ nameservers[ns].nreplies++;
idnsGrokReply(rbuf, len);
}
}
+static void
+idnsCheckQueue(void *unused)
+{
+ dlink_node *n;
+ idns_query *q;
+ event_queued = 0;
+ for (n = lru_list.tail; n; n = n->prev) {
+ q = n->data;
+ if (tvSubDsec(q->sent_t, current_time) < 5.0)
+ break;
+ debug(78, 1) ("idnsCheckQueue: ID %#04x timeout\n",
+ q->id);
+ dlinkDelete(&q->lru, &lru_list);
+ idnsSendQuery(q);
+ }
+}
+
/* ====================================================================== */
void
q->callback = callback;
q->callback_data = data;
cbdataLock(q->callback_data);
- q->start = current_time;
+ q->start_t = current_time;
idnsSendQuery(q);
}
/*
- * $Id: ipcache.cc,v 1.212 1999/04/14 06:35:46 wessels Exp $
+ * $Id: ipcache.cc,v 1.213 1999/04/15 06:03:49 wessels Exp $
*
* DEBUG: section 14 IP Cache
* AUTHOR: Harvest Derived
}
#else
static ipcache_entry *
-ipcacheParse(rfc1035_rr * answers, int na)
+ipcacheParse(rfc1035_rr * answers, int nr)
{
static ipcache_entry i;
+ int k;
+ int j;
+ int na = 0;
memset(&i, '\0', sizeof(i));
i.expires = squid_curtime;
i.status = IP_NEGATIVE_CACHED;
- if (na < 0) {
- debug(14, 1) ("ipcacheParse: Lookup failed\n");
- debug(14, 1) ("\trfc1035_errno = %d\n", rfc1035_errno);
+ if (nr < 0) {
+ debug(14, 1) ("ipcacheParse: Lookup failed (error %d)\n",
+ rfc1035_errno);
assert(rfc1035_error_message);
i.error_message = xstrdup(rfc1035_error_message);
- } else if (na == 0) {
+ return &i;
+ }
+ if (nr == 0) {
+ debug(14, 1) ("ipcacheParse: No DNS records\n");
+ i.error_message = xstrdup("No DNS records");
+ return &i;
+ }
+ assert(answers);
+ for (j = 0, k = 0; k < nr; k++) {
+ if (answers[k].type != RFC1035_TYPE_A)
+ continue;
+ if (answers[k].class != RFC1035_CLASS_IN)
+ continue;
+ na++;
+ }
+ if (na == 0) {
debug(14, 1) ("ipcacheParse: No Address records\n");
i.error_message = xstrdup("No Address records");
- } else {
- int k;
- int j;
- assert(answers);
- i.status = IP_CACHED;
- i.expires = squid_curtime + answers->ttl;
- i.addrs.in_addrs = xcalloc(na, sizeof(struct in_addr));
- i.addrs.bad_mask = xcalloc(na, sizeof(unsigned char));
- for (j = 0, k = 0; k < na; k++) {
- if (answers[k].type != RFC1035_TYPE_A)
- continue;
- if (answers[k].class != RFC1035_CLASS_IN)
- continue;
- assert(answers[k].rdlength == 4);
- xmemcpy(&i.addrs.in_addrs[j++], answers[k].rdata, 4);
- debug(14, 3) ("ipcacheParse: #%d %s\n",
- j - 1,
- inet_ntoa(i.addrs.in_addrs[j - 1]));
- }
- i.addrs.count = (unsigned char) j;
+ return &i;
}
+ i.status = IP_CACHED;
+ i.addrs.in_addrs = xcalloc(na, sizeof(struct in_addr));
+ i.addrs.bad_mask = xcalloc(na, sizeof(unsigned char));
+ i.addrs.count = (unsigned char) na;
+ for (j = 0, k = 0; k < nr; k++) {
+ if (answers[k].type != RFC1035_TYPE_A)
+ continue;
+ if (answers[k].class != RFC1035_CLASS_IN)
+ continue;
+ if (j == 0)
+ i.expires = squid_curtime + answers[k].ttl;
+ assert(answers[k].rdlength == 4);
+ xmemcpy(&i.addrs.in_addrs[j++], answers[k].rdata, 4);
+ debug(14, 3) ("ipcacheParse: #%d %s\n",
+ j - 1,
+ inet_ntoa(i.addrs.in_addrs[j - 1]));
+ }
+ assert(j == na);
return &i;
}
#endif