From 0b094303f3e30007fd9fccc3df81f44cf2c49003 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Sat, 17 Oct 2020 21:28:56 +0200 Subject: ndb/dnsdebug: add -c flag to debug caching dns server behaviour --- sys/man/8/ndb | 5 ++++- sys/src/cmd/ndb/dnsdebug.c | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/sys/man/8/ndb b/sys/man/8/ndb index af4df056d..f6da3bbb8 100644 --- a/sys/man/8/ndb +++ b/sys/man/8/ndb @@ -97,7 +97,7 @@ query, ipquery, mkhash, mkdb, mkhosts, cs, csquery, dns, dnstcp, dnsquery, dnsde .br .B ndb/dnsdebug [ -.B -rx +.B -rxc ] [ .B -f .I dbfile @@ -758,6 +758,9 @@ to use the interface and .B /lib/ndb/external database file. +The +.B -c +option enables caching which is handy for debugging the dns code. .PP .I Ndb/dnsgetip resolves and prints A and AAAA records without consulting diff --git a/sys/src/cmd/ndb/dnsdebug.c b/sys/src/cmd/ndb/dnsdebug.c index 092e0c7b3..650e705d9 100644 --- a/sys/src/cmd/ndb/dnsdebug.c +++ b/sys/src/cmd/ndb/dnsdebug.c @@ -56,9 +56,16 @@ main(int argc, char *argv[]) case 'f': dbfile = EARGF(usage()); break; + case 'c': + cfg.cachedb = 1; + break; case 'r': cfg.resolver = 1; break; + case 'd': + debug = 1; + traceactivity = 1; + break; case 'x': dbfile = "/lib/ndb/external"; strcpy(mntpt, "/net.alt"); @@ -73,6 +80,7 @@ main(int argc, char *argv[]) fmtinstall('R', prettyrrfmt); opendatabase(); srand(truerand()); + db2cache(1); if(cfg.resolver) squirrelserveraddrs(); @@ -89,7 +97,6 @@ main(int argc, char *argv[]) p[Blinelen(&in)-1] = 0; n = tokenize(p, f, 3); if(n>=1) { - dnpurge(); /* flush the cache */ docmd(n, f); } } @@ -457,6 +464,12 @@ docmd(int n, char **f) name = type = nil; tmpsrv = 0; + if(strcmp(f[0], "refresh") == 0){ + db2cache(1); + dnageall(0); + return; + } + if(*f[0] == '@') { if(setserver(f[0]+1) < 0) return; @@ -483,6 +496,7 @@ docmd(int n, char **f) if(name == nil) return; + if(!cfg.cachedb) dnpurge(); /* flush the cache */ doquery(name, type); if(tmpsrv) -- cgit v1.2.3