]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
hints: allow hints.get() to list all hints
authorVladimír Čunát <vladimir.cunat@nic.cz>
Tue, 29 Nov 2016 15:43:58 +0000 (16:43 +0100)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Tue, 29 Nov 2016 15:43:58 +0000 (16:43 +0100)
lib/zonecut.h
modules/hints/README.rst
modules/hints/hints.c

index 98432a571fa5c524cc2787bbd9ac8ce7cb191831..90d7747ae80b093c19beb871b30ce834e3d926eb 100644 (file)
@@ -32,7 +32,7 @@ struct kr_zonecut {
        knot_rrset_t* key;  /**< Zone cut DNSKEY. */
        knot_rrset_t* trust_anchor; /**< Current trust anchor. */
        struct kr_zonecut *parent; /**< Parent zone cut. */
-    map_t nsset;        /**< Map of nameserver => address_set. */
+       map_t nsset;        /**< Map of nameserver => address_set. */
        knot_mm_t *pool;     /**< Memory pool. */
 };
 
index e96c74b34cde73390c545483d65792ab4c301b1a..71f2e8eeb7da3b4a50e38487ac6b788589743993 100644 (file)
@@ -39,6 +39,7 @@ Properties
   :return: ``{ result: [address1, address2, ...] }``
 
   Return list of address record matching given name.
+  If no hostname is specified, all hints are returned in the table format used by ``hints.root()``.
 
 .. function:: hints.set(pair)
 
@@ -56,14 +57,14 @@ Properties
 
 .. function:: hints.root()
 
-  :return: ``{ ['a.root-servers.net'] = { '1.2.3.4', '5.6.7.8', ...}, ... }``
+  :return: ``{ ['a.root-servers.net.'] = { '1.2.3.4', '5.6.7.8', ...}, ... }``
 
   .. tip:: If no parameters are passed, returns current root hints set.
 
 .. function:: hints.root(root_hints)
 
   :param table root_hints: new set of root hints i.e. ``{['name'] = 'addr', ...}``
-  :return: ``{ ['a.root-servers.net'] = { '1.2.3.4', '5.6.7.8', ...}, ... }``
+  :return: ``{ ['a.root-servers.net.'] = { '1.2.3.4', '5.6.7.8', ...}, ... }``
 
   Replace current root hints and return the current table of root hints.
 
index 28341138cdcd8c59beeebeb1b9c1838680297399..cae6b1532936ea507f27cbed90bc491390572d7c 100644 (file)
@@ -394,8 +394,9 @@ static JsonNode *pack_addrs(pack_t *pack)
        return root;
 }
 
+static char* pack_hints(struct kr_zonecut *hints);
 /**
- * Retrieve address hint for given name.
+ * Retrieve address hints, either for given name or for all names.
  *
  * Input:  name
  * Output: { address1, address2, ... }
@@ -403,6 +404,11 @@ static JsonNode *pack_addrs(pack_t *pack)
 static char* hint_get(void *env, struct kr_module *module, const char *args)
 {
        struct kr_zonecut *hints = module->data;
+
+       if (!args) {
+               return pack_hints(hints);
+       }
+
        knot_dname_t key[KNOT_DNAME_MAXLEN];
        pack_t *pack = NULL;
        if (knot_dname_from_str(key, args, sizeof(key))) {
@@ -435,6 +441,17 @@ static int pack_hint(const char *k, void *v, void *baton)
        return kr_ok();
 }
 
+/** @internal Pack all hints into serialized JSON. */
+static char* pack_hints(struct kr_zonecut *hints) {
+       char *result = NULL;
+       JsonNode *root_node = json_mkobject();
+       if (map_walk(&hints->nsset, pack_hint, root_node) == 0) {
+               result = json_encode(root_node);
+       }
+       json_delete(root_node);
+       return result;
+}
+
 static void unpack_hint(struct kr_zonecut *root_hints, JsonNode *table, const char *name)
 {
        JsonNode *node = NULL;
@@ -467,13 +484,7 @@ static char* hint_root(void *env, struct kr_module *module, const char *args)
                json_delete(root_node);
        }
        /* Return current root hints */
-       char *result = NULL;
-       JsonNode *root_node = json_mkobject();
-       if (map_walk(&root_hints->nsset, pack_hint, root_node) == 0) {
-               result = json_encode(root_node);
-       }
-       json_delete(root_node);
-       return result;
+       return pack_hints(root_hints);
 }
 
 /*