]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
lib: moved RR stash to utils, prefixed
authorMarek Vavruša <marek.vavrusa@nic.cz>
Mon, 28 Sep 2015 16:03:53 +0000 (18:03 +0200)
committerMarek Vavruša <marek.vavrusa@nic.cz>
Mon, 28 Sep 2015 16:03:53 +0000 (18:03 +0200)
lib/layer/rrcache.c
lib/layer/validate.c
lib/lib.mk
lib/rrset_stash.c [deleted file]
lib/rrset_stash.h [deleted file]
lib/utils.c
lib/utils.h

index d440fdd47505249f68849eb149d65a4ce4dfe205..a15fdf2f8aaa6a8b51898f0227e81648f5cc0744 100644 (file)
@@ -25,7 +25,7 @@
 #include "lib/layer/iterate.h"
 #include "lib/cache.h"
 #include "lib/module.h"
-#include "lib/rrset_stash.h"
+#include "lib/utils.h"
 
 #define DEBUG_MSG(fmt...) QRDEBUG(kr_rplan_current(rplan), " rc ",  fmt)
 #define DEFAULT_MINTTL (5) /* Short-time "no data" retention to avoid bursts */
@@ -203,7 +203,7 @@ static void stash_glue(map_t *stash, knot_pkt_t *pkt, const knot_dname_t *ns_nam
                    !knot_dname_is_equal(rr->owner, ns_name)) {
                        continue;
                }
-               stash_add(pkt, stash, rr, pool);
+               kr_rrmap_add(stash, rr, pool);
        }
 }
 
@@ -214,7 +214,7 @@ static void stash_ds(struct kr_query *qry, knot_pkt_t *pkt, map_t *stash, mm_ctx
        for (unsigned i = 0; i < authority->count; ++i) {
                const knot_rrset_t *rr = knot_pkt_rr(authority, i);
                if (rr->type == KNOT_RRTYPE_DS || rr->type == KNOT_RRTYPE_RRSIG) {
-                       stash_add(pkt, stash, rr, pool);
+                       kr_rrmap_add(stash, rr, pool);
                }
        }
 }
@@ -233,7 +233,7 @@ static int stash_authority(struct kr_query *qry, knot_pkt_t *pkt, map_t *stash,
                        stash_glue(stash, pkt, knot_ns_name(&rr->rrs, 0), pool);
                }
                /* Stash record */
-               stash_add(pkt, stash, rr, pool);
+               kr_rrmap_add(stash, rr, pool);
        }
        return kr_ok();
 }
@@ -250,7 +250,7 @@ static int stash_answer(struct kr_query *qry, knot_pkt_t *pkt, map_t *stash, mm_
                    && rr->type != KNOT_RRTYPE_RRSIG) {
                        continue;
                }
-               stash_add(pkt, stash, rr, pool);
+               kr_rrmap_add(stash, rr, pool);
                /* Follow CNAME chain */
                if (rr->type == KNOT_RRTYPE_CNAME) {
                        cname = knot_cname_name(&rr->rrs);
index f282317e49fc94c2d9ef0dfd1ca0ab3d3bfe5230..9fb3f3c3853b4126948321551fca07a1d6471337 100644 (file)
@@ -31,7 +31,7 @@
 #include "lib/layer.h"
 #include "lib/resolve.h"
 #include "lib/rplan.h"
-#include "lib/rrset_stash.h"
+#include "lib/utils.h"
 #include "lib/defines.h"
 #include "lib/module.h"
 
@@ -87,7 +87,7 @@ static int validate_section(struct kr_query *qry, knot_pkt_t *answer,
                if ((rr->type == KNOT_RRTYPE_NS) && (section_id == KNOT_AUTHORITY)) {
                        continue;
                }
-               ret = stash_add(answer, &stash, rr, pool);
+               ret = kr_rrmap_add(&stash, rr, pool);
                if (ret != 0) {
                        goto fail;
                }
index 3a1f8e04d86728cac2f4cb83a0a23651b27023ce..1467cf3e81b8520c90b11d4d5a0d6ff924dc4f6f 100644 (file)
@@ -22,7 +22,6 @@ libkres_SOURCES := \
        lib/nsrep.c            \
        lib/module.c           \
        lib/resolve.c          \
-       lib/rrset_stash.c      \
        lib/zonecut.c          \
        lib/rplan.c            \
        lib/cache.c
@@ -43,7 +42,6 @@ libkres_HEADERS := \
        lib/nsrep.h            \
        lib/module.h           \
        lib/resolve.h          \
-       lib/rrset_stash.h      \
        lib/zonecut.h          \
        lib/rplan.h            \
        lib/cache.h
diff --git a/lib/rrset_stash.c b/lib/rrset_stash.c
deleted file mode 100644 (file)
index 6cb021b..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-/*  Copyright (C) 2014 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
-
-    This program is free software: you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation, either version 3 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <libknot/descriptor.h>
-#include <libknot/dname.h>
-#include <libknot/rrtype/rrsig.h>
-#include <stdio.h>
-
-#include "lib/defines.h"
-#include "lib/rrset_stash.h"
-
-int stash_add(const knot_pkt_t *pkt, map_t *stash, const knot_rrset_t *rr, mm_ctx_t *pool)
-{
-       (void) pkt;
-
-       /* Stash key = {[1] flags, [1-255] owner, [1-5] type, [1] \x00 } */
-       char key[9 + KNOT_DNAME_MAXLEN];
-       uint16_t rrtype = rr->type;
-       KEY_FLAG_SET(key, KEY_FLAG_NO);
-
-       /* Stash RRSIGs in a special cache, flag them and set type to its covering RR.
-        * This way it the stash won't merge RRSIGs together. */
-       if (rr->type == KNOT_RRTYPE_RRSIG) {
-               rrtype = knot_rrsig_type_covered(&rr->rrs, 0);
-               KEY_FLAG_SET(key, KEY_FLAG_RRSIG);
-       }
-
-       uint8_t *key_buf = (uint8_t *)key + 1;
-       int ret = knot_dname_to_wire(key_buf, rr->owner, KNOT_DNAME_MAXLEN);
-       if (ret <= 0) {
-               return ret;
-       }
-       knot_dname_to_lower(key_buf);
-       /* Must convert to string, as the key must not contain 0x00 */
-       ret = snprintf((char *)key_buf + ret - 1, sizeof(key) - KNOT_DNAME_MAXLEN, "%hu", rrtype);
-       if (ret <= 0 || ret >= KNOT_DNAME_MAXLEN) {
-               return kr_error(EILSEQ);
-       }
-
-       /* Check if already exists */
-       knot_rrset_t *stashed = map_get(stash, key);
-       if (!stashed) {
-               stashed = knot_rrset_copy(rr, pool);
-               if (!stashed) {
-                       return kr_error(ENOMEM);
-               }
-               return map_set(stash, key, stashed);
-       }
-       /* Merge rdataset */
-       return knot_rdataset_merge(&stashed->rrs, &rr->rrs, pool);
-}
diff --git a/lib/rrset_stash.h b/lib/rrset_stash.h
deleted file mode 100644 (file)
index 3e6387f..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-/*  Copyright (C) 2015 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
-
-    This program is free software: you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation, either version 3 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#pragma once
-
-#include <libknot/internal/mempattern.h>
-#include <libknot/packet/pkt.h>
-#include <libknot/rrset.h>
-
-#include "lib/generic/map.h"
-
-/* Stash key flags */
-#define KEY_FLAG_NO 0x01
-#define KEY_FLAG_RRSIG 0x02
-#define KEY_FLAG_SET(key, flag) key[0] = (flag);
-#define KEY_COVERING_RRSIG(key) (key[0] & KEY_FLAG_RRSIG)
-
-/**
- * Merges RRSets with matching owner name and type together.
- * @note RRSIG RRSets are merged according the type covered fields.
- * @param pkt   Packet which the rset belongs to.
- * @param stash Holds the merged RRSets.
- * @param rr    RRSet to be added.
- * @param pool  Memory pool.
- * @return      0 or an error
- */
-int stash_add(const knot_pkt_t *pkt, map_t *stash, const knot_rrset_t *rr, mm_ctx_t *pool);
index b2779f61c93b11d3b1d89ca5213aaacccc050b42..a5295ceb4a9f81fd8b222b13313304b075a2e954 100644 (file)
@@ -21,6 +21,9 @@
 #include <stdio.h>
 #include <arpa/inet.h>
 #include <sys/time.h>
+#include <libknot/descriptor.h>
+#include <libknot/dname.h>
+#include <libknot/rrtype/rrsig.h>
 
 #include "ccan/isaac/isaac.h"
 #include "lib/defines.h"
@@ -259,4 +262,50 @@ int kr_bitcmp(const char *a, const char *b, int bits)
                ret = ((uint8_t)(*a >> shift) - (uint8_t)(*b >> shift));
        }
        return ret;
-}
\ No newline at end of file
+}
+
+/* Set stashed RR flag */
+#define KEY_FLAG_SET(key, flag) key[0] = (flag);
+
+int kr_rrmap_add(map_t *stash, const knot_rrset_t *rr, mm_ctx_t *pool)
+{
+       if (!stash || !rr) {
+               return kr_error(EINVAL);
+       }
+
+       /* Stash key = {[1] flags, [1-255] owner, [1-5] type, [1] \x00 } */
+       char key[9 + KNOT_DNAME_MAXLEN];
+       uint16_t rrtype = rr->type;
+       KEY_FLAG_SET(key, KEY_FLAG_NO);
+
+       /* Stash RRSIGs in a special cache, flag them and set type to its covering RR.
+        * This way it the stash won't merge RRSIGs together. */
+       if (rr->type == KNOT_RRTYPE_RRSIG) {
+               rrtype = knot_rrsig_type_covered(&rr->rrs, 0);
+               KEY_FLAG_SET(key, KEY_FLAG_RRSIG);
+       }
+
+       uint8_t *key_buf = (uint8_t *)key + 1;
+       int ret = knot_dname_to_wire(key_buf, rr->owner, KNOT_DNAME_MAXLEN);
+       if (ret <= 0) {
+               return ret;
+       }
+       knot_dname_to_lower(key_buf);
+       /* Must convert to string, as the key must not contain 0x00 */
+       ret = snprintf((char *)key_buf + ret - 1, sizeof(key) - KNOT_DNAME_MAXLEN, "%hu", rrtype);
+       if (ret <= 0 || ret >= KNOT_DNAME_MAXLEN) {
+               return kr_error(EILSEQ);
+       }
+
+       /* Check if already exists */
+       knot_rrset_t *stashed = map_get(stash, key);
+       if (!stashed) {
+               stashed = knot_rrset_copy(rr, pool);
+               if (!stashed) {
+                       return kr_error(ENOMEM);
+               }
+               return map_set(stash, key, stashed);
+       }
+       /* Merge rdataset */
+       return knot_rdataset_merge(&stashed->rrs, &rr->rrs, pool);
+}
index ab1fa264a7947b81f014ff90d6704d22a8e4e042..a73d162319d38c558a12dccbe105b3467132582b 100644 (file)
@@ -20,6 +20,7 @@
 #include <sys/time.h>
 #include <netinet/in.h>
 #include <libknot/packet/pkt.h>
+#include "lib/generic/map.h"
 
 /*
  * General-purpose attributes.
@@ -109,4 +110,15 @@ int kr_straddr_family(const char *addr);
   * @warning 'dst' must be at least `sizeof(struct in6_addr)` long. */
 int kr_straddr_subnet(void *dst, const char *addr);
 /** Compare memory bitwise. */
-int kr_bitcmp(const char *a, const char *b, int bits);
\ No newline at end of file
+int kr_bitcmp(const char *a, const char *b, int bits);
+
+/** @internal RR map flags. */
+#define KEY_FLAG_NO 0x01
+#define KEY_FLAG_RRSIG 0x02
+#define KEY_COVERING_RRSIG(key) (key[0] & KEY_FLAG_RRSIG)
+
+/** @internal Merges RRSets with matching owner name and type together.
+ * @note RRSIG RRSets are merged according the type covered fields.
+ * @return 0 or an error
+ */
+int kr_rrmap_add(map_t *stash, const knot_rrset_t *rr, mm_ctx_t *pool);
\ No newline at end of file