Commit Diff
Diff:
ce12744aeaf395f55d2780a7dd411d19fdd43492
09fdca2378471d8cff1156f65973c7c0f10a6719
Commit:
09fdca2378471d8cff1156f65973c7c0f10a6719
Tree:
ee326fba84c06825099c54f9d5f2c48b3e01fba4
Author:
pbug <pbug@delphinusdns.org>
Committer:
pbug <pbug@delphinusdns.org>
Date:
Sat Sep 25 13:18:58 2010 UTC
Message:
* reply ns type records tested on OpenBSD
blob - c2efd191c3d5d34bd342fe31efe8666bd29146c2
blob + 3c23cd375ae1362950103ff10d17e4f080f2b2a9
--- recurse.c
+++ recurse.c
@@ -50,6 +50,7 @@ void reply_raw(DB *db, struct recurses *sr, struct dom
void reply_raw_noerror(DB *, struct recurses *, struct domain *, int *);
extern void build_reply(struct sreply *reply, int so, char *buf, int len, struct question *q, struct sockaddr *sa, socklen_t slen, struct domain *sd1, struct domain *sd2, u_int8_t region, int istcp, int wildcard, struct recurses *sr);
extern void reply_a(struct sreply *, DB *);
+extern void reply_ns(struct sreply *, DB *);
extern int memcasecmp(u_char *, u_char *, int);
extern int get_soa(DB *, struct question *, struct domain *, int);
extern void reply_noerror(struct sreply *);
@@ -67,7 +68,7 @@ struct recurseentry {
} *rn1, *rn2, *rnp;
-static const char rcsid[] = "$Id: recurse.c,v 1.17 2010/09/25 11:58:59 pbug Exp $";
+static const char rcsid[] = "$Id: recurse.c,v 1.18 2010/09/25 13:18:58 pbug Exp $";
/*
* INIT_RECURSE - initialize the recurse singly linked list
@@ -1508,6 +1509,9 @@ reply_raw(DB *db, struct recurses *sr, struct domain *
switch (ntohs(sr->question->hdr->qtype)) {
case DNS_TYPE_A:
reply_a(&sreply, db);
+ break;
+ case DNS_TYPE_NS:
+ reply_ns(&sreply, db);
break;
default:
syslog(LOG_ERR, "other types have not been implemented yet");
blob - 72b3110853ec110e1ed763e89b9002bcf812800a
blob + 9859bf4eea6beb0854276064e9314550fdec7f2b
--- reply.c
+++ reply.c
@@ -75,7 +75,7 @@ struct collects {
} *cn1, *cn2, *cnp;
-static const char rcsid[] = "$Id: reply.c,v 1.29 2010/09/25 11:58:59 pbug Exp $";
+static const char rcsid[] = "$Id: reply.c,v 1.30 2010/09/25 13:18:58 pbug Exp $";
/*
* REPLY_A() - replies a DNS question (*q) on socket (so)
@@ -610,14 +610,17 @@ reply_ns(struct sreply *sreply, DB *db)
SET_DNS_REPLY(odh);
- switch (sd->ns_type) {
- case 0:
- SET_DNS_AUTHORITATIVE(odh);
- break;
- default:
- SET_DNS_RECURSION(odh);
- break;
- }
+ if (sreply->sr == NULL) {
+ switch (sd->ns_type) {
+ case 0:
+ SET_DNS_AUTHORITATIVE(odh);
+ break;
+ default:
+ SET_DNS_RECURSION(odh);
+ break;
+ }
+ } else
+ SET_DNS_RECURSION_AVAIL(odh);
HTONS(odh->query);
@@ -648,7 +651,10 @@ reply_ns(struct sreply *sreply, DB *db)
answer->name[1] = 0x0c;
answer->type = htons(DNS_TYPE_NS);
answer->class = q->hdr->qclass;
- answer->ttl = htonl(sd->ttl);
+ if (sreply->sr != NULL)
+ answer->ttl = htonl(sd->ttl - (time(NULL) - sd->created));
+ else
+ answer->ttl = htonl(sd->ttl);
name = sd->ns[pos % mod]->nsserver;
namelen = sd->ns[pos % mod]->nslen;
@@ -748,24 +754,29 @@ reply_ns(struct sreply *sreply, DB *db)
}
out:
- if (istcp) {
- char *tmpbuf;
-
- tmpbuf = malloc(outlen + 2);
- if (tmpbuf == NULL) {
- syslog(LOG_INFO, "malloc: %m");
- }
- plen = (u_int16_t *)tmpbuf;
- *plen = htons(outlen);
-
- memcpy(&tmpbuf[2], reply, outlen);
- if (send(so, tmpbuf, outlen + 2, 0) < 0) {
- syslog(LOG_INFO, "send: %m");
- }
- free(tmpbuf);
+ if (sreply->sr != NULL) {
+ reply_raw2(so, reply, outlen, sreply->sr);
} else {
- if (sendto(so, reply, outlen, 0, sa, salen) < 0) {
- syslog(LOG_INFO, "sendto: %m");
+
+ if (istcp) {
+ char *tmpbuf;
+
+ tmpbuf = malloc(outlen + 2);
+ if (tmpbuf == NULL) {
+ syslog(LOG_INFO, "malloc: %m");
+ }
+ plen = (u_int16_t *)tmpbuf;
+ *plen = htons(outlen);
+
+ memcpy(&tmpbuf[2], reply, outlen);
+ if (send(so, tmpbuf, outlen + 2, 0) < 0) {
+ syslog(LOG_INFO, "send: %m");
+ }
+ free(tmpbuf);
+ } else {
+ if (sendto(so, reply, outlen, 0, sa, salen) < 0) {
+ syslog(LOG_INFO, "sendto: %m");
+ }
}
}
repomaster@centroid.eu