]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
lib: implemented deletion for zonecut
authorMarek Vavruša <marek.vavrusa@nic.cz>
Sun, 19 Apr 2015 19:28:40 +0000 (21:28 +0200)
committerMarek Vavruša <marek.vavrusa@nic.cz>
Sun, 19 Apr 2015 19:28:40 +0000 (21:28 +0200)
lib/zonecut.c
lib/zonecut.h

index 5e229e6dda5991a96cd45755f4030d4c313c5b10..fdfebed3e4c91eb370d228544099902b6d4f73a7 100644 (file)
@@ -112,11 +112,10 @@ int kr_zonecut_add(struct kr_zonecut *cut, const knot_dname_t *ns, const knot_rd
        }
 
        /* Fetch/insert nameserver. */
-       const char *key = (const char *)ns;
-       pack_t *pack = map_get(&cut->nsset, key);
+       pack_t *pack = kr_zonecut_find(cut, ns);
        if (pack == NULL) {
                pack = mm_alloc(cut->pool, sizeof(*pack));
-               if (!pack || (map_set(&cut->nsset, key, pack) != 0)) {
+               if (!pack || (map_set(&cut->nsset, (const char *)ns, pack) != 0)) {
                        mm_free(cut->pool, pack);
                        return kr_error(ENOMEM);
                }
@@ -143,9 +142,7 @@ int kr_zonecut_del(struct kr_zonecut *cut, const knot_dname_t *ns, const knot_rd
        }
 
        /* Find the address list. */
-       const char *key = (const char *)ns;
-       map_t *nsset = &cut->nsset;
-       pack_t *pack = map_get(nsset, key);
+       pack_t *pack = kr_zonecut_find(cut, ns);
        if (pack == NULL) {
                return kr_error(ENOENT);
        }
@@ -154,13 +151,24 @@ int kr_zonecut_del(struct kr_zonecut *cut, const knot_dname_t *ns, const knot_rd
        int ret = pack_obj_del(pack, knot_rdata_data(rdata), knot_rdata_rdlen(rdata));
        if (pack->len == 0) {
                /* No servers left, remove NS from the set. */
-               free_addr_set(key, pack, cut->pool);
-               return map_del(nsset, key);
+               free_addr_set((const char *)ns, pack, cut->pool);
+               return map_del(&cut->nsset, (const char *)ns);
        }
 
        return ret;
 }
 
+pack_t *kr_zonecut_find(struct kr_zonecut *cut, const knot_dname_t *ns)
+{
+       if (cut == NULL || ns == NULL) {
+               return NULL;
+       }
+
+       const char *key = (const char *)ns;
+       map_t *nsset = &cut->nsset;
+       return map_get(nsset, key);
+}
+
 int kr_zonecut_set_sbelt(struct kr_zonecut *cut)
 {
        if (cut == NULL) {
index d7e4163d8e61123e28ab10f4d829449b922f75a5..ed2cf3765a515d3bc55669702ef6698e5db0f7e3 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "lib/cache.h"
 #include "lib/generic/map.h"
+#include "lib/generic/pack.h"
 
 struct kr_rplan;
 
@@ -51,7 +52,6 @@ void kr_zonecut_deinit(struct kr_zonecut *cut);
 
 /**
  * Reset zone cut to given name and clear address list.
- * @note This preserves already-allocated memory.
  * @note This clears the address list even if the name doesn't change.
  * @param cut  zone cut to be set
  * @param name new zone cut name
@@ -80,6 +80,18 @@ int kr_zonecut_add(struct kr_zonecut *cut, const knot_dname_t *ns, const knot_rd
  */
 int kr_zonecut_del(struct kr_zonecut *cut, const knot_dname_t *ns, const knot_rdata_t *rdata);
 
+/**
+ * Find nameserver address list in the zone cut.
+ *
+ * @note This can be used for membership test, a non-null pack is returned
+ *       if the nameserver name exists.
+ * 
+ * @param  cut
+ * @param  ns    name server name
+ * @return       pack of addresses or NULL
+ */
+pack_t *kr_zonecut_find(struct kr_zonecut *cut, const knot_dname_t *ns);
+
 /**
  * Populate zone cut with a root zone using SBELT :rfc:`1034`
  *