summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVladimír Čunát <vladimir.cunat@nic.cz>2023-08-23 11:58:39 +0200
committerVladimír Čunát <vladimir.cunat@nic.cz>2023-09-12 12:12:55 +0200
commitfffdc6222e08e34eaf29d50eecb6e5c500a1bf78 (patch)
treeb2b76c970fc30f131da67d34a46348cbe7868a9d
parentdatamodel: /local-data/subtrees/*: drop parts that are not implemented (diff)
downloadknot-resolver-fffdc6222e08e34eaf29d50eecb6e5c500a1bf78.tar.xz
knot-resolver-fffdc6222e08e34eaf29d50eecb6e5c500a1bf78.zip
modules/hints,lib/rules: rework TTL defaults
It was a bit wide, with 5s and 3h, and distinction between these two "groups" of rules was a bit random wrt. TTL choice. Now: 5m for user's rules and 1h for RFC-default rules. I found it relatively hard to choose defaults, but at least for user-supplied rules it's trivial to configure a different default.
-rw-r--r--lib/rules/api.c11
-rw-r--r--lib/rules/api.h1
-rw-r--r--lib/rules/defaults.c12
-rw-r--r--lib/rules/impl.h2
-rw-r--r--lib/rules/zonefile.c2
-rw-r--r--modules/hints/hints.c3
6 files changed, 19 insertions, 12 deletions
diff --git a/lib/rules/api.c b/lib/rules/api.c
index 8ff809d2..e2992c01 100644
--- a/lib/rules/api.c
+++ b/lib/rules/api.c
@@ -11,7 +11,12 @@
struct kr_rules *the_rules = NULL;
-const uint32_t KR_RULE_TTL_DEFAULT = RULE_TTL_DEFAULT;
+/* The default TTL value is a compromise and probably of little practical impact.
+ * - answering from local rules should be quite cheap,
+ * so very high values are not expected to bring any improvements
+ * - on the other hand, rules are not expected to change very dynamically
+ */
+const uint32_t KR_RULE_TTL_DEFAULT = 300;
/* DB key-space summary
@@ -405,7 +410,7 @@ int rule_local_data_answer(struct kr_query *qry, knot_pkt_t *pkt)
return RET_CONT_CACHE;
}
// The other types optionally specify TTL.
- uint32_t ttl = RULE_TTL_DEFAULT;
+ uint32_t ttl = KR_RULE_TTL_DEFAULT;
if (val.len >= sizeof(ttl)) // allow omitting -> can't kr_assert
deserialize_fails_assert(&val, &ttl);
if (kr_fails_assert(val.len == 0)) {
@@ -793,7 +798,7 @@ int kr_rule_local_subtree(const knot_dname_t *apex, enum kr_rule_sub_t type,
.data = NULL,
.len = sizeof(tags) + sizeof(ztype),
};
- const bool has_ttl = ttl != RULE_TTL_DEFAULT;
+ const bool has_ttl = ttl != KR_RULE_TTL_DEFAULT;
if (has_ttl)
val.len += sizeof(ttl);
int ret = ruledb_op(write, &key, &val, 1);
diff --git a/lib/rules/api.h b/lib/rules/api.h
index 44a4f3b8..7998560f 100644
--- a/lib/rules/api.h
+++ b/lib/rules/api.h
@@ -58,6 +58,7 @@ int kr_view_select_action(const struct kr_request *req, knot_db_val_t *selected)
/** Default TTL for answers from local data rules.
*
+ * This applies to rules defined by the user, not the default rules.
* Some types of rules save space when using this default.
* This definition exists mainly for usage from lua.
*/
diff --git a/lib/rules/defaults.c b/lib/rules/defaults.c
index bd50b5f6..bd21fa10 100644
--- a/lib/rules/defaults.c
+++ b/lib/rules/defaults.c
@@ -10,6 +10,10 @@
if ((ret) < 0) { kr_assert(false); return kr_error((ret)); } \
} while (false)
+/** RFC-defined local zones should be quite static,
+ * so we use a higher TTL separate from KR_RULE_TTL_DEFAULT. */
+#define TTL ((uint32_t)3600)
+
int rules_defaults_insert(void)
{
static const char * names[] = {
@@ -137,7 +141,7 @@ int rules_defaults_insert(void)
const knot_dname_t *dname =
knot_dname_from_str(name_buf, names[i], sizeof(name_buf));
int ret = kr_rule_local_subtree(dname, KR_RULE_SUB_EMPTY,
- RULE_TTL_DEFAULT, KR_RULE_TAGS_ALL);
+ TTL, KR_RULE_TAGS_ALL);
CHECK_RET(ret);
/* The double conversion is perhaps a bit wasteful, but it should be rare. */
/* LATER: add extra info with explanation? policy module had an ADDITIONAL
@@ -149,12 +153,12 @@ int rules_defaults_insert(void)
knot_dname_t localhost_dname[] = "\x09localhost\0";
{ // forward localhost
int ret = kr_rule_local_subtree(localhost_dname, KR_RULE_SUB_REDIRECT,
- RULE_TTL_DEFAULT, KR_RULE_TAGS_ALL);
+ TTL, KR_RULE_TAGS_ALL);
CHECK_RET(ret);
knot_rrset_t rr = {
.owner = localhost_dname,
- .ttl = RULE_TTL_DEFAULT,
+ .ttl = TTL,
.rclass = KNOT_CLASS_IN,
.rrs = { 0 },
.additional = NULL,
@@ -183,7 +187,7 @@ int rules_defaults_insert(void)
{ // reverse localhost; LATER: the situation isn't ideal with NXDOMAIN + some exact matches
knot_rrset_t rr = {
.owner = localhost_dname,
- .ttl = RULE_TTL_DEFAULT,
+ .ttl = TTL,
.type = KNOT_RRTYPE_PTR,
.rclass = KNOT_CLASS_IN,
.rrs = { 0 },
diff --git a/lib/rules/impl.h b/lib/rules/impl.h
index 1ff78140..0d7de513 100644
--- a/lib/rules/impl.h
+++ b/lib/rules/impl.h
@@ -11,8 +11,6 @@
#undef VERBOSE_MSG
#define VERBOSE_MSG(qry, ...) kr_log_q((qry), RULES, ## __VA_ARGS__)
-#define RULE_TTL_DEFAULT ((uint32_t)10800)
-
/** Insert all the default rules. in ./defaults.c */
int rules_defaults_insert(void);
diff --git a/lib/rules/zonefile.c b/lib/rules/zonefile.c
index da53675f..d29ae35e 100644
--- a/lib/rules/zonefile.c
+++ b/lib/rules/zonefile.c
@@ -215,7 +215,7 @@ int kr_rule_zonefile(const struct kr_rule_zonefile_config *c)
zs_scanner_t s_storage, *s = &s_storage;
/* zs_init(), zs_set_input_file(), zs_set_processing() returns -1 in case of error,
* so don't print error code as it meaningless. */
- uint32_t ttl = c->ttl ? c->ttl : RULE_TTL_DEFAULT; // 0 would be nonsense
+ uint32_t ttl = c->ttl ? c->ttl : KR_RULE_TTL_DEFAULT; // 0 would be nonsense
int ret = zs_init(s, NULL, KNOT_CLASS_IN, ttl);
if (ret) {
kr_log_error(RULES, "error initializing zone scanner instance, error: %i (%s)\n",
diff --git a/modules/hints/hints.c b/modules/hints/hints.c
index c422bce0..eaefaae4 100644
--- a/modules/hints/hints.c
+++ b/modules/hints/hints.c
@@ -33,7 +33,6 @@ struct hints_data {
bool use_nodata; /**< See hint_use_nodata() description, exposed via lua. */
uint32_t ttl; /**< TTL used for the hints, exposed via lua. */
};
-static const uint32_t HINTS_TTL_DEFAULT = 5;
/** Useful for returning from module properties. */
static char * bool2jsonstr(bool val)
@@ -299,7 +298,7 @@ int hints_init(struct kr_module *module)
if (!data)
return kr_error(ENOMEM);
data->use_nodata = true;
- data->ttl = HINTS_TTL_DEFAULT;
+ data->ttl = KR_RULE_TTL_DEFAULT;
module->data = data;
return kr_ok();