]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
lib/rules: move parts from api.c to impl.h
authorVladimír Čunát <vladimir.cunat@nic.cz>
Mon, 22 May 2023 15:47:26 +0000 (17:47 +0200)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Mon, 12 Jun 2023 08:32:57 +0000 (10:32 +0200)
lib/rules/api.c
lib/rules/impl.h

index c207a05f99f870e2f03974f5cc4cc847d8c35ff9..1222f76b1160ad1c070b47d55f4a0071fefa183a 100644 (file)
@@ -9,20 +9,7 @@
 
 #include <stdlib.h>
 
-#include "lib/cache/impl.h"
-#undef VERBOSE_MSG
-#define VERBOSE_MSG(qry, ...) kr_log_q((qry), RULES,  ## __VA_ARGS__)
-
-struct kr_rules {
-       /* Database for storing the rules (LMDB). */
-       kr_cdb_pt db;                 /**< Storage instance */
-       const struct kr_cdb_api *api; /**< Storage engine */
-       struct kr_cdb_stats stats;
-};
-
 struct kr_rules *the_rules = NULL;
-#define ruledb_op(op, ...) \
-       the_rules->api->op(the_rules->db, &the_rules->stats, ## __VA_ARGS__)
 
 /* DB key-space summary
 
@@ -48,22 +35,6 @@ static const uint8_t KEY_ZONELIKE_A [1] = "a";
 static const uint8_t KEY_VIEW_SRC4[1] = "4";
 static const uint8_t KEY_VIEW_SRC6[1] = "6";
 
-/// Fill *variable_ptr from a knot_db_val_t and advance it (and kr_assert it fits).
-#define deserialize_fails_assert(val_ptr, variable_ptr) \
-       deserialize_fails_assert_f_(val_ptr, (variable_ptr), sizeof(*(variable_ptr)))
-static bool deserialize_fails_assert_f_(knot_db_val_t *val, void *var, size_t size)
-{
-       if (kr_fails_assert(val->len >= size))
-               return true;
-       memcpy(var, val->data, size);
-       val->len -= size;
-       // avoiding void* arithmetics complicates this
-       char *tmp = val->data;
-       tmp += size;
-       val->data = tmp;
-       return false;
-}
-
 static int answer_exact_match(struct kr_query *qry, knot_pkt_t *pkt, uint16_t type,
                const uint8_t *data, const uint8_t *data_bound);
 static int answer_zla_empty(val_zla_type_t type, struct kr_query *qry, knot_pkt_t *pkt,
@@ -157,9 +128,6 @@ int kr_rule_tag_add(const char *tag, kr_rule_tags_t *tagset)
 }
 
 
-//TODO later, maybe.  ATM it would be cumbersome to avoid void* arithmetics.
-#pragma GCC diagnostic ignored "-Wpointer-arith"
-
 int kr_rules_init(void)
 {
        kr_require(!the_rules);
index 88693596e764606fe5ca889a71b48256cbb460b2..1ce44993d00ee1a59545c040b0f00ebacfe86b46 100644 (file)
@@ -4,6 +4,12 @@
 #pragma once
 
 #include "lib/rules/api.h"
+#include "lib/utils.h"
+#include <libknot/packet/pkt.h>
+
+#include "lib/cache/impl.h"
+#undef VERBOSE_MSG
+#define VERBOSE_MSG(qry, ...) kr_log_q((qry), RULES,  ## __VA_ARGS__)
 
 #define RULE_TTL_DEFAULT ((uint32_t)10800)
 
@@ -53,4 +59,31 @@ int insert_trivial_zone(val_zla_type_t ztype, uint32_t ttl,
 
 extern /*const*/ char RULESET_DEFAULT[];
 
+/// Fill *variable_ptr from a knot_db_val_t and advance it (and kr_assert it fits).
+#define deserialize_fails_assert(val_ptr, variable_ptr) \
+       deserialize_fails_assert_f_(val_ptr, (variable_ptr), sizeof(*(variable_ptr)))
+static inline bool deserialize_fails_assert_f_(knot_db_val_t *val, void *var, size_t size)
+{
+       if (kr_fails_assert(val->len >= size))
+               return true;
+       memcpy(var, val->data, size);
+       val->len -= size;
+       // avoiding void* arithmetics complicates this
+       char *tmp = val->data;
+       tmp += size;
+       val->data = tmp;
+       return false;
+}
+
+struct kr_rules {
+       /* Database for storing the rules (LMDB). */
+       kr_cdb_pt db;                 /**< Storage instance */
+       const struct kr_cdb_api *api; /**< Storage engine */
+       struct kr_cdb_stats stats;
+};
+#define ruledb_op(op, ...) \
+       the_rules->api->op(the_rules->db, &the_rules->stats, ## __VA_ARGS__)
+
+//TODO later, maybe.  ATM it would be cumbersome to avoid void* arithmetics.
+#pragma GCC diagnostic ignored "-Wpointer-arith"