list_local_zones and list_local_data.

git-svn-id: file:///svn/unbound/trunk@1996 be551aaa-1e26-0410-a405-d3ace91eadb9
This commit is contained in:
Wouter Wijngaards 2010-02-26 16:14:00 +00:00
parent 51cc8aadd6
commit 3c2fe2fe5e
6 changed files with 83 additions and 3 deletions

View file

@ -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);

View file

@ -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

View file

@ -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

View file

@ -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)

View file

@ -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.

View file

@ -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");