]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
list_local_zones and list_local_data.
authorWouter Wijngaards <wouter@nlnetlabs.nl>
Fri, 26 Feb 2010 16:14:00 +0000 (16:14 +0000)
committerWouter Wijngaards <wouter@nlnetlabs.nl>
Fri, 26 Feb 2010 16:14:00 +0000 (16:14 +0000)
git-svn-id: file:///svn/unbound/trunk@1996 be551aaa-1e26-0410-a405-d3ace91eadb9

daemon/remote.c
doc/Changelog
doc/unbound-control.8.in
services/localzone.c
services/localzone.h
smallapp/unbound-control.c

index 31f8849412d26e11824394d3220ec516e037e949..572f61c3c368741e9288a0c7e6e6957463169f2a 100644 (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);
index cb2219d2f164ad0cb2a88236811ba89c04454bef..685bcfd7a4856e10855b81244934322aba75fa1e 100644 (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
index 14fe8c07f73bb7fff7c69fbff55a73a1be26f66b..da2964aeb388a265429c786384baf2fcbf15f0f7 100644 (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 
index 9f20356a73822543c82e7554e7b4c073871a25b8..0a870e59d6a6e669e08aa377b6d9630510b97f5f 100644 (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)
index 8835c06df95c91903adfe2826fd757db13f6c962..ed05a583139abe1c9a65582f13a206e1b74e70b8 100644 (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.
index c0b7461c02daf4d7d48dbefd7b9ee746f47fdfd2..ed9c88bda0eab9fc02791b73f6f5f2eb7fe3fd35 100644 (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");