From: Grigorii Demidov Date: Mon, 19 Mar 2018 16:42:31 +0000 (+0100) Subject: daemon: time period which determines how long NS non-reachabilty will be cached made... X-Git-Tag: v2.2.0~1^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fb338c2a8046fc2c06325342dd5bea641af6d777;p=thirdparty%2Fknot-resolver.git daemon: time period which determines how long NS non-reachabilty will be cached made configurable --- diff --git a/daemon/bindings.c b/daemon/bindings.c index bdde5dfa5..361b66cc7 100644 --- a/daemon/bindings.c +++ b/daemon/bindings.c @@ -1117,6 +1117,39 @@ static int cache_get(lua_State *L) return 1; } +/** Set time interval for cleaning rtt cache. + * Servers with score >= KR_NS_TIMEOUTED will be cleaned after + * this interval ended up, so that they will be able to participate + * in NS elections again. */ +static int cache_touted_ns_clean_interval(lua_State *L) +{ + struct engine *engine = engine_luaget(L); + struct kr_context *ctx = &engine->resolver; + + /* Check parameters */ + int n = lua_gettop(L); + if (n < 1) { + lua_pushinteger(L, ctx->cache_rtt_tout_retry_interval); + return 1; + } + + if (!lua_isnumber(L, 1)) { + format_error(L, "expected 'cache.ns_tout(interval in ms)'"); + lua_error(L); + } + + lua_Number interval_lua = lua_tonumber(L, 1); + if (!(interval_lua >= 0 && interval_lua < UINT_MAX)) { + format_error(L, "invalid interval specified, it must be in range > 0, < " xstr(UINT_MAX)); + lua_error(L); + } + + ctx->cache_rtt_tout_retry_interval = interval_lua; + lua_pushinteger(L, ctx->cache_rtt_tout_retry_interval); + return 1; +} + + int lib_cache(lua_State *L) { static const luaL_Reg lib[] = { @@ -1131,6 +1164,7 @@ int lib_cache(lua_State *L) { "get", cache_get }, { "max_ttl", cache_max_ttl }, { "min_ttl", cache_min_ttl }, + { "ns_tout", cache_touted_ns_clean_interval }, { NULL, NULL } }; diff --git a/daemon/engine.c b/daemon/engine.c index a32b18d6f..e62d71135 100644 --- a/daemon/engine.c +++ b/daemon/engine.c @@ -585,6 +585,7 @@ static int init_resolver(struct engine *engine) engine->resolver.negative_anchors = map_make(NULL); engine->resolver.pool = engine->pool; engine->resolver.modules = &engine->modules; + engine->resolver.cache_rtt_tout_retry_interval = KR_NS_TIMEOUT_RETRY_INTERVAL; /* Create OPT RR */ engine->resolver.opt_rr = mm_alloc(engine->pool, sizeof(knot_rrset_t)); if (!engine->resolver.opt_rr) { diff --git a/lib/nsrep.c b/lib/nsrep.c index 9be90e46a..f7aae0d98 100644 --- a/lib/nsrep.c +++ b/lib/nsrep.c @@ -82,9 +82,11 @@ static void update_nsrep_set(struct kr_nsrep *ns, const knot_dname_t *name, uint #undef ADDR_SET -static unsigned eval_addr_set(pack_t *addr_set, kr_nsrep_rtt_lru_t *rtt_cache, - unsigned score, uint8_t *addr[], struct kr_qflags opts) +static unsigned eval_addr_set(pack_t *addr_set, struct kr_context *ctx, + unsigned score, uint8_t *addr[]) { + kr_nsrep_rtt_lru_t *rtt_cache = ctx->cache_rtt; + struct kr_qflags opts = ctx->options; /* Name server is better candidate if it has address record. */ uint8_t *it = pack_head(*addr_set); while (it != pack_tail(*addr_set)) { @@ -110,10 +112,10 @@ static unsigned eval_addr_set(pack_t *addr_set, kr_nsrep_rtt_lru_t *rtt_cache, elapsed = elapsed > UINT_MAX ? UINT_MAX : elapsed; /* If NS once was marked as "timeouted", * it won't participate in NS elections - * at least KR_NS_TIMEOUT_RETRY_INTERVAL milliseconds. */ + * at least ctx->cache_rtt_tout_retry_interval milliseconds. */ addr_score = cached->score; if (cached->score >= KR_NS_TIMEOUT && - elapsed > KR_NS_TIMEOUT_RETRY_INTERVAL) { + elapsed > ctx->cache_rtt_tout_retry_interval) { addr_score = KR_NS_LONG - 1; cached->score = addr_score; cached->tout_timestamp = 0; @@ -171,7 +173,7 @@ static int eval_nsrep(const char *k, void *v, void *baton) } } } else { - score = eval_addr_set(addr_set, ctx->cache_rtt, score, addr_choice, ctx->options); + score = eval_addr_set(addr_set, ctx, score, addr_choice); } /* Probabilistic bee foraging strategy (naive). @@ -286,7 +288,7 @@ int kr_nsrep_elect_addr(struct kr_query *qry, struct kr_context *ctx) } /* Evaluate addr list */ uint8_t *addr_choice[KR_NSREP_MAXADDR] = { NULL, }; - unsigned score = eval_addr_set(addr_set, ctx->cache_rtt, ns->score, addr_choice, ctx->options); + unsigned score = eval_addr_set(addr_set, ctx, ns->score, addr_choice); update_nsrep_set(ns, ns->name, addr_choice, score); return kr_ok(); } diff --git a/lib/resolve.h b/lib/resolve.h index 5ff492730..011679ec6 100644 --- a/lib/resolve.h +++ b/lib/resolve.h @@ -163,6 +163,7 @@ struct kr_context struct kr_zonecut root_hints; struct kr_cache cache; kr_nsrep_rtt_lru_t *cache_rtt; + unsigned cache_rtt_tout_retry_interval; kr_nsrep_lru_t *cache_rep; module_array_t *modules; /* The cookie context structure should not be held within the cookies