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
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)) {
.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);
/** 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.
*/
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[] = {
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
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,
{ // 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 },
#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);
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",
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)
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();