summaryrefslogtreecommitdiffstats
path: root/lib/rules
diff options
context:
space:
mode:
authorVladimír Čunát <vladimir.cunat@nic.cz>2023-05-22 17:47:26 +0200
committerVladimír Čunát <vladimir.cunat@nic.cz>2023-06-12 10:32:57 +0200
commit5d2ca3808e0f547f450e9854fc5072d39d59103f (patch)
tree8bb20b7885de188242a01d66cb683238692a1a6e /lib/rules
parentlib/rules: bugfix ZLA key for the root (diff)
downloadknot-resolver-5d2ca3808e0f547f450e9854fc5072d39d59103f.tar.xz
knot-resolver-5d2ca3808e0f547f450e9854fc5072d39d59103f.zip
lib/rules: move parts from api.c to impl.h
Diffstat (limited to 'lib/rules')
-rw-r--r--lib/rules/api.c32
-rw-r--r--lib/rules/impl.h33
2 files changed, 33 insertions, 32 deletions
diff --git a/lib/rules/api.c b/lib/rules/api.c
index c207a05f..1222f76b 100644
--- a/lib/rules/api.c
+++ b/lib/rules/api.c
@@ -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);
diff --git a/lib/rules/impl.h b/lib/rules/impl.h
index 88693596..1ce44993 100644
--- a/lib/rules/impl.h
+++ b/lib/rules/impl.h
@@ -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"