From: Wouter Wijngaards Date: Fri, 26 Feb 2010 16:14:00 +0000 (+0000) Subject: list_local_zones and list_local_data. X-Git-Tag: release-1.4.2~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3c2fe2fe5e779e11cd49624f3822c388be9c4c12;p=thirdparty%2Funbound.git list_local_zones and list_local_data. git-svn-id: file:///svn/unbound/trunk@1996 be551aaa-1e26-0410-a405-d3ace91eadb9 --- diff --git a/daemon/remote.c b/daemon/remote.c index 31f884941..572f61c3c 100644 --- a/daemon/remote.c +++ b/daemon/remote.c @@ -1558,6 +1558,50 @@ do_list_stubs(SSL* ssl, struct worker* worker) } } +/** do the list_local_zones command */ +static void +do_list_local_zones(SSL* ssl, struct worker* worker) +{ + struct local_zones* zones = worker->daemon->local_zones; + struct local_zone* z; + char buf[257]; + lock_quick_lock(&zones->lock); + RBTREE_FOR(z, struct local_zone*, &zones->ztree) { + lock_rw_rdlock(&z->lock); + dname_str(z->name, buf); + (void)ssl_printf(ssl, "%s %s\n", buf, + local_zone_type2str(z->type)); + lock_rw_unlock(&z->lock); + } + lock_quick_unlock(&zones->lock); +} + +/** do the list_local_data command */ +static void +do_list_local_data(SSL* ssl, struct worker* worker) +{ + struct local_zones* zones = worker->daemon->local_zones; + struct local_zone* z; + struct local_data* d; + struct local_rrset* p; + lock_quick_lock(&zones->lock); + RBTREE_FOR(z, struct local_zone*, &zones->ztree) { + lock_rw_rdlock(&z->lock); + RBTREE_FOR(d, struct local_data*, &z->data) { + for(p = d->rrsets; p; p = p->next) { + ldns_rr_list* rr = packed_rrset_to_rr_list( + p->rrset, worker->env.scratch_buffer); + char* str = ldns_rr_list2str(rr); + (void)ssl_printf(ssl, "%s", str); + free(str); + ldns_rr_list_free(rr); + } + } + lock_rw_unlock(&z->lock); + } + lock_quick_unlock(&zones->lock); +} + /** tell other processes to execute the command */ void distribute_cmd(struct daemon_remote* rc, SSL* ssl, char* cmd) @@ -1611,6 +1655,12 @@ execute_cmd(struct daemon_remote* rc, SSL* ssl, char* cmd, } else if(strncmp(p, "list_stubs", 10) == 0) { do_list_stubs(ssl, worker); return; + } else if(strncmp(p, "list_local_zones", 16) == 0) { + do_list_local_zones(ssl, worker); + return; + } else if(strncmp(p, "list_local_data", 15) == 0) { + do_list_local_data(ssl, worker); + return; } else if(strncmp(p, "forward", 7) == 0) { /* must always distribute this cmd */ if(rc) distribute_cmd(rc, ssl, cmd); diff --git a/doc/Changelog b/doc/Changelog index cb2219d2f..685bcfd7a 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,6 +1,7 @@ 26 February 2010: Wouter - Fixup prototype for lexer cleanup in daemon code. - - unbound-control list_stubs and list_forwards. + - unbound-control list_stubs, list_forwards, list_local_zones and + list_local_data. 24 February 2010: Wouter - Fix scrubber bug that potentially let NS records through. Reported diff --git a/doc/unbound-control.8.in b/doc/unbound-control.8.in index 14fe8c07f..da2964aeb 100644 --- a/doc/unbound-control.8.in +++ b/doc/unbound-control.8.in @@ -162,6 +162,12 @@ This includes the root hints in use. .B list_forwards List the forward zones in use. These are printed zone by zone to the output. .TP +.B list_local_zones +List the local zones in use. These are printed one per line with zone type. +.TP +.B list_local_data +List the local data RRs in use. The resource records are printed. +.TP .B forward \fR[\fIoff\fR | \fIaddr ...\fR ] Setup forwarding mode. Configures if the server should ask other upstream nameservers, should go to the internet root nameservers itself, or show diff --git a/services/localzone.c b/services/localzone.c index 9f20356a7..0a870e59d 100644 --- a/services/localzone.c +++ b/services/localzone.c @@ -1141,6 +1141,19 @@ local_zones_answer(struct local_zones* zones, struct query_info* qinfo, return r; } +const char* local_zone_type2str(enum localzone_type t) +{ + switch(t) { + case local_zone_deny: return "deny"; + case local_zone_refuse: return "refuse"; + case local_zone_redirect: return "redirect"; + case local_zone_transparent: return "transparent"; + case local_zone_static: return "static"; + case local_zone_nodefault: return "nodefault"; + } + return "badtyped"; +} + int local_zone_str2type(const char* type, enum localzone_type* t) { if(strcmp(type, "deny") == 0) diff --git a/services/localzone.h b/services/localzone.h index 8835c06df..ed05a5831 100644 --- a/services/localzone.h +++ b/services/localzone.h @@ -233,6 +233,14 @@ int local_zones_answer(struct local_zones* zones, struct query_info* qinfo, */ int local_zone_str2type(const char* str, enum localzone_type* t); +/** + * Print localzone type to a string. Pointer to a constant string. + * + * @param t: local zone type. + * @return constant string that describes type. + */ +const char* local_zone_type2str(enum localzone_type t); + /** * Find zone that with exactly given name, class. * User must lock the tree or result zone. diff --git a/smallapp/unbound-control.c b/smallapp/unbound-control.c index c0b7461c0..ed9c88bda 100644 --- a/smallapp/unbound-control.c +++ b/smallapp/unbound-control.c @@ -86,8 +86,10 @@ usage() printf(" dump_requestlist show what is worked on\n"); printf(" set_option opt: val set option to value, no reload\n"); printf(" get_option opt get option value\n"); - printf(" list_stubs list stub-zones used\n"); - printf(" list_forwards list forward-zones used\n"); + printf(" list_stubs list stub-zones and root hints in use\n"); + printf(" list_forwards list forward-zones in use\n"); + printf(" list_local_zones list local-zones in use\n"); + printf(" list_local_data list local-data RRs in use\n"); printf(" forward [off | addr ...] without arg show forward setup\n"); printf(" or off to turn off root forwarding\n"); printf(" or give list of ip addresses\n");