Re: "djbdns and nxdspecial patch"

Mark Johnson <[email protected]> Mon, 26 Apr 2010 21:26:07 -0500
Newsgroups gmane.network.djbdns
Message-ID <[email protected]>
On Mon, Apr 26, 2010 at 12:51 PM, Marco Spiga <[email protected]> wrote:
> I wait with hope....

I think these are the bits you want relative to stock djbdns-1.05:

diff -r -u djbdns-1.05.orig/dnscache.c djbdns-1.05.nxdspecial/dnscache.c
--- djbdns-1.05.orig/dnscache.c	2010-04-26 21:01:31.000000000 -0500
+++ djbdns-1.05.nxdspecial/dnscache.c	2010-04-26 21:19:53.000000000 -0500
@@ -389,6 +389,7 @@
 int main()
 {
   char *x;
+  char nxdip[4];
   unsigned long cachesize;

   x = env_get("IP");
@@ -436,6 +437,13 @@
   if (env_get("FORWARDONLY"))
     query_forwardonly();

+  x = env_get("NXDSPECIAL");
+  if (x) {
+    if (!ip4_scan(x,nxdip))
+      strerr_die3x(111,FATAL,"unable to parse NXDSPECIAL IP address ",x);
+    query_nxdspecial(nxdip);
+  }
+
   if (!roots_init())
     strerr_die2sys(111,FATAL,"unable to read servers: ");

diff -r -u djbdns-1.05.orig/query.c djbdns-1.05.nxdspecial/query.c
--- djbdns-1.05.orig/query.c	2010-04-26 21:01:31.000000000 -0500
+++ djbdns-1.05.nxdspecial/query.c	2010-04-26 21:21:55.000000000 -0500
@@ -20,6 +20,15 @@
   flagforwardonly = 1;
 }

+static int flagnxdspecial = 0;
+static char nxdip[4];
+
+void query_nxdspecial(const char ip[4])
+{
+  byte_copy(nxdip,4,ip);
+  flagnxdspecial = 1;
+}
+
 static void cachegeneric(const char type[2],const char *d,const char
*data,unsigned int datalen,uint32 ttl)
 {
   unsigned int len;
@@ -695,7 +704,12 @@
     NXDOMAIN:
     if (z->level) goto LOWERLEVEL;
     if (!rqa(z)) goto DIE;
-    response_nxdomain();
+    if (flagnxdspecial && typematch(DNS_T_A,dtype)) {
+      if (!response_rstart(d,DNS_T_A,rcode == 3 ? soattl : ttl)) goto DIE;
+      if (!response_addbytes(nxdip,4)) goto DIE;
+      response_rfinish(RESPONSE_ANSWER);
+    } else
+      response_nxdomain();
     cleanup(z);
     return 1;
   }
diff -r -u djbdns-1.05.orig/query.h djbdns-1.05.nxdspecial/query.h
--- djbdns-1.05.orig/query.h	2010-04-26 21:01:31.000000000 -0500
+++ djbdns-1.05.nxdspecial/query.h	2010-04-26 21:02:52.000000000 -0500
@@ -28,5 +28,6 @@
 extern int query_get(struct query *,iopause_fd *,struct taia *);

 extern void query_forwardonly(void);
+extern void query_nxdspecial(const char *);

 #endif

Note that I hocked that from:

http://www.google.com/codesearch/p?hl=en#-v3yBnCJ60Q/Mirror/linuxpackages/Slackware-10.2/robert/djbdns/source/jumbo-p13.patch&q=nxdspecial&sa=N&cd=1&ct=rc

Perhaps that will jog Dan Peterson's memory.  Dan, does that look right to you?