]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
lib/rules: move more declarations to impl.h
authorVladimír Čunát <vladimir.cunat@nic.cz>
Fri, 21 Apr 2023 09:42:35 +0000 (11:42 +0200)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Mon, 12 Jun 2023 08:32:28 +0000 (10:32 +0200)
lib/rules/api.c
lib/rules/impl.h

index 297d33024afe1bc1672db973b5b4384e7a2c0fc3..12472366ece1f680e6334546f53d7e2a0d31cdc3 100644 (file)
@@ -40,8 +40,7 @@ struct kr_rules *the_rules = NULL;
        -> action-rule string; see kr_view_insert_action()
  */
 
-#define KEY_RULESET_MAXLEN 16 /**< max. len of ruleset ID + 1(for kind) */
-static /*const*/ char RULESET_DEFAULT[] = "d";
+/*const*/ char RULESET_DEFAULT[] = "d";
 
 static const uint8_t KEY_EXACT_MATCH[1] = "e";
 static const uint8_t KEY_ZONELIKE_A [1] = "a";
@@ -49,19 +48,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";
 
-/** The first byte of zone-like apex value is its type. */
-typedef uint8_t val_zla_type_t;
-enum {
-       /** Empty zone. No data in DB value after this byte. */
-       VAL_ZLAT_EMPTY = 1,
-       /** Forced NXDOMAIN. */
-       VAL_ZLAT_NXDOMAIN,
-       /** Forced NODATA.  Does not apply on exact name (e.g. it's similar to DNAME) */
-       VAL_ZLAT_NODATA,
-       /** Redirect: anything beneath has the same data as apex (except NS+SOA). */
-       VAL_ZLAT_REDIRECT,
-};
-
 
 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);
@@ -235,11 +221,6 @@ static bool kr_rule_consume_tags(knot_db_val_t *val, const struct kr_request *re
 
 
 
-/** When constructing a key, it's convenient that the dname_lf ends on a fixed offset.
- * Convention: the end here is before the final '\0' byte (if any). */
-#define KEY_DNAME_END_OFFSET (KEY_RULESET_MAXLEN + KNOT_DNAME_MAXLEN)
-#define KEY_MAXLEN (KEY_DNAME_END_OFFSET + 64) //TODO: most of 64 is unused ATM
-
 /** Add name lookup format on the fixed end-position inside key_data.
  *
  * Note: key_data[KEY_DNAME_END_OFFSET] = '\0' even though
@@ -502,7 +483,7 @@ static int answer_exact_match(struct kr_query *qry, knot_pkt_t *pkt, uint16_t ty
 }
 
 
-static knot_db_val_t local_data_key(const knot_rrset_t *rrs, uint8_t key_data[KEY_MAXLEN],
+knot_db_val_t local_data_key(const knot_rrset_t *rrs, uint8_t key_data[KEY_MAXLEN],
                                        const char *ruleset_name)
 {
        knot_db_val_t key;
@@ -528,7 +509,11 @@ int kr_rule_local_data_ins(const knot_rrset_t *rrs, const knot_rdataset_t *sig_r
        // Construct the DB key.
        uint8_t key_data[KEY_MAXLEN];
        knot_db_val_t key = local_data_key(rrs, key_data, RULESET_DEFAULT);
-
+       return local_data_ins(key, rrs, sig_rds, tags);
+}
+int local_data_ins(knot_db_val_t key, const knot_rrset_t *rrs,
+                       const knot_rdataset_t *sig_rds, kr_rule_tags_t tags)
+{
        // Allocate the data in DB.
        const int rr_ssize = rdataset_dematerialize_size(&rrs->rrs);
        const int to_alloc = sizeof(tags) + sizeof(rrs->ttl) + rr_ssize
index 3c4f636e0fb6c603bc8f3ee077bcf82e6cc2ceac..81e1ab706669fe7b01d60e3364740b774181df45 100644 (file)
@@ -3,8 +3,50 @@
  */
 #pragma once
 
-#define RULE_TTL_DEFAULT ((uint16_t)10800)
+#include "lib/rules/api.h"
+
+#define RULE_TTL_DEFAULT ((uint32_t)10800)
 
 /** Insert all the default rules. in ./defaults.c */
 int rules_defaults_insert(void);
 
+/** Singleton struct used by the code in ./. */
+struct kr_rules;
+extern struct kr_rules *the_rules;
+
+#define KEY_RULESET_MAXLEN 16 /**< max. len of ruleset ID + 1(for kind) */
+/** When constructing a key, it's convenient that the dname_lf ends on a fixed offset.
+ * Convention: the end here is before the final '\0' byte (if any). */
+#define KEY_DNAME_END_OFFSET (KEY_RULESET_MAXLEN + KNOT_DNAME_MAXLEN)
+#define KEY_MAXLEN (KEY_DNAME_END_OFFSET + 64) //TODO: most of 64 is unused ATM
+
+/** Construct key for local_data_ins().  It's stored in `key_data`. */
+knot_db_val_t local_data_key(const knot_rrset_t *rrs, uint8_t key_data[KEY_MAXLEN],
+                                       const char *ruleset_name);
+/** Same as kr_rule_local_data_ins() but with precomputed `key`. */
+int local_data_ins(knot_db_val_t key, const knot_rrset_t *rrs,
+                       const knot_rdataset_t *sig_rds, kr_rule_tags_t tags);
+
+
+/** The first byte of zone-like apex value is its type. */
+typedef uint8_t val_zla_type_t;
+enum {
+       /** Empty zone. No data in DB value after this byte.
+        *
+        * TODO: add
+        *  - TTL (most likely, optional, 4B)
+        *  - SOA rdata (maybe, optional, remainder of DB value)
+        *  Same for _NXDOMAIN and _NODATA, too.
+        */
+       VAL_ZLAT_EMPTY = 1,
+       /** Forced NXDOMAIN. */
+       VAL_ZLAT_NXDOMAIN,
+       /** Forced NODATA.  Does not apply on exact name (e.g. it's similar to DNAME) */
+       VAL_ZLAT_NODATA,
+       /** Redirect: anything beneath has the same data as apex (except NS+SOA). */
+       VAL_ZLAT_REDIRECT,
+};
+
+extern /*const*/ char RULESET_DEFAULT[];
+
+