shithub: riscv

Download patch

ref: 2dc97202de20c3e5b89e66d16e102ea393a19b6c
parent: 4821c261c4cea895ddcbd7c70bc71103c9a2763b
author: cinap_lenrek <[email protected]>
date: Sun Jun 26 20:36:04 EDT 2016

ndb/dns: purge db records on refresh for resolvers, remove old debug and testing code

when ndb/dns runs as a resolver only (cfg.cachedb == 0),
we still want to purge the "local#" db records to reread
dns server configuration or react to changed ip addresses.

removing old poolcheck and dncheck code, these bugs have
been fixed a long time ago.

--- a/sys/src/cmd/ndb/dblookup.c
+++ b/sys/src/cmd/ndb/dblookup.c
@@ -579,24 +579,7 @@
 	return 0;
 }
 
-
 /*
- *  read the all the soa's from the database to determine area's.
- *  this is only used when we're not caching the database.
- */
-static void
-dbfile2area(Ndb *db)
-{
-	Ndbtuple *t;
-
-	if(debug)
-		dnslog("rereading %s", db->file);
-	Bseek(&db->b, 0, 0);
-	while(t = ndbparse(db))
-		ndbfree(t);
-}
-
-/*
  *  read the database into the cache
  */
 static void
@@ -750,23 +733,23 @@
 		/* reload straddle-server configuration */
 		loaddomsrvs();
 
-		if(cfg.cachedb){
-			/* mark all db records as timed out */
-			dnagedb();
+		/* mark all db records as timed out */
+		dnagedb();
 
+		if(cfg.cachedb){
 			/* read in new entries */
 			for(ndb = db; ndb; ndb = ndb->next)
 				dbfile2cache(ndb);
+		}
 
-			/* mark as authoritative anything in our domain */
-			dnauthdb();
+		/*
+		 * mark as authoritative anything in our domain,
+		 * delete timed out db records
+		 */
+		dnauthdb();
 
-			/* remove old entries */
-			dnageall(1);
-		} else
-			/* read all the soa's to get database defaults */
-			for(ndb = db; ndb; ndb = ndb->next)
-				dbfile2area(ndb);
+		/* remove old entries */
+		dnageall(1);
 
 		doit = 0;
 		lastyoungest = youngest;
--- a/sys/src/cmd/ndb/dn.c
+++ b/sys/src/cmd/ndb/dn.c
@@ -1,7 +1,6 @@
 #include <u.h>
 #include <libc.h>
 #include <ip.h>
-#include <pool.h>
 #include <ctype.h>
 #include "dns.h"
 
@@ -702,15 +701,10 @@
 	}
 	unlock(&dnvars);
 
-	dncheck();
-
 	db2cache(needrefresh);
-	dncheck();
 
 	dnageall(0);
 
-	dncheck();
-
 	/* let others back in */
 	lastclean = now;
 	needrefresh = 0;
@@ -1546,39 +1540,6 @@
 		alarm(0);
 		longjmp(req->mret, 1);
 	}
-}
-
-/*
- *  chasing down double free's
- */
-void
-dncheck(void)
-{
-	int i;
-	DN *dp;
-	RR *rp;
-
-	if(!testing)
-		return;
-
-	lock(&dnlock);
-	poolcheck(mainmem);
-	for(i = 0; i < HTLEN; i++)
-		for(dp = ht[i]; dp; dp = dp->next){
-			assert(dp->magic == DNmagic);
-			for(rp = dp->rr; rp; rp = rp->next){
-				assert(rp->magic == RRmagic);
-				assert(rp->cached);
-				assert(rp->owner == dp);
-				/* also check for duplicate rrs */
-				if (rronlist(rp, rp->next)) {
-					dnslog("%R duplicates its next chain "
-						"(%R); aborting", rp, rp->next);
-					abort();
-				}
-			}
-		}
-	unlock(&dnlock);
 }
 
 static int
--- a/sys/src/cmd/ndb/dns.c
+++ b/sys/src/cmd/ndb/dns.c
@@ -4,7 +4,6 @@
 #include <fcall.h>
 #include <bio.h>
 #include <ip.h>
-#include <pool.h>
 #include "dns.h"
 
 enum
@@ -69,7 +68,6 @@
 ulong	now;
 vlong	nowns;
 int	sendnotifies;
-int	testing;
 char	*trace;
 int	traceactivity;
 char	*zonerefreshprogram;
@@ -107,7 +105,7 @@
 void
 usage(void)
 {
-	fprint(2, "usage: %s [-FnorRst] [-a maxage] [-f ndb-file] [-N target] "
+	fprint(2, "usage: %s [-FnorRs] [-a maxage] [-f ndb-file] [-N target] "
 		"[-T forwip] [-x netmtpt] [-z refreshprog]\n", argv0);
 	exits("usage");
 }
@@ -158,9 +156,6 @@
 		cfg.serve = 1;		/* serve network */
 		cfg.cachedb = 1;
 		break;
-	case 't':
-		testing = 1;
-		break;
 	case 'T':
 		addforwtarg(EARGF(usage()));
 		break;
@@ -178,9 +173,6 @@
 	if(argc != 0)
 		usage();
 
-	if(testing)
-		mainmem->flags |= POOL_NOREUSE | POOL_ANTAGONISM;
-	mainmem->flags |= POOL_ANTAGONISM;
 	rfork(RFREND|RFNOTEG);
 
 	cfg.inside = (*mntpt == '\0' || strcmp(mntpt, "/net") == 0);
@@ -206,9 +198,6 @@
 		sysfatal("%s exists; another dns instance is running",
 			servefile);
 	free(dir);
-//	unmount(servefile, mntpt);
-//	remove(servefile);
-
 	mountinit(servefile, mntpt);	/* forks, parent exits */
 
 	srand(now*getpid());
@@ -733,12 +722,8 @@
 	send = 1;
 	if(strcmp(job->request.data, "debug")==0)
 		debug ^= 1;
-	else if(strcmp(job->request.data, "testing")==0)
-		testing ^= 1;
 	else if(strcmp(job->request.data, "dump")==0)
 		dndump("/lib/ndb/dnsdump");
-	else if(strcmp(job->request.data, "poolcheck")==0)
-		poolcheck(mainmem);
 	else if(strcmp(job->request.data, "refresh")==0)
 		needrefresh = 1;
 	else if(strcmp(job->request.data, "restart")==0)
--- a/sys/src/cmd/ndb/dns.h
+++ b/sys/src/cmd/ndb/dns.h
@@ -448,7 +448,6 @@
 void	dnagedb(void);
 void	dnagenever(DN *);
 void	dnauthdb(void);
-void	dncheck(void);
 void	dndump(char*);
 void	dnget(void);
 void	dninit(void);