]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
nitpicks around older changes for stale-serving
authorVladimír Čunát <vladimir.cunat@nic.cz>
Wed, 21 Mar 2018 09:40:36 +0000 (10:40 +0100)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Wed, 21 Nov 2018 13:26:58 +0000 (14:26 +0100)
daemon/bindings.c
lib/generic/lru.h
lib/nsrep.c

index 6b4948e8b99f8dfd6cb951b14f11c9f2cc46f2a7..259c6c7a4d75d1a10766924d5c7baab5f6f9c432 100644 (file)
@@ -1242,8 +1242,8 @@ static int cache_ns_tout(lua_State *L)
                lua_error(L);
        }
 
-       lua_Number interval_lua = lua_tonumber(L, 1);
-       if (!(interval_lua >= 0 && interval_lua < UINT_MAX)) {
+       lua_Integer interval_lua = lua_tointeger(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);
        }
index 61f3ce085866dada7dfcdc9aebc0bfaf160202a8..b5c9bcd6939e9cfac731fd9ce4c1636f803f09c8 100644 (file)
  * @param table pointer to LRU
  * @param key_ lookup key
  * @param len_ key lengthkeys
- * @param res  pointer to bool to store result of operation
+ * @param is_new pointer to bool to store result of operation
  *             (true if entry is newly added, false otherwise; can be NULL).
  * @return pointer to data or NULL (can be even if memory could be allocated!)
  */
-#define lru_get_new(table, key_, len_, res) \
+#define lru_get_new(table, key_, len_, is_new) \
        (__typeof__((table)->pdata_t)) \
                lru_get_impl(&(table)->lru, (key_), (len_), \
-               sizeof(*(table)->pdata_t), true, res)
+               sizeof(*(table)->pdata_t), true, is_new)
 
 /**
  * @brief Apply a function to every item in LRU.
index f5ef21ce3a19c699b091a345287250065262372d..ee5f341918901a7bb2cb4f81939716da69df48b0 100644 (file)
@@ -94,8 +94,8 @@ static unsigned eval_addr_set(const pack_t *addr_set, struct kr_context *ctx,
        uint64_t now = kr_now();
 
        /* Name server is better candidate if it has address record. */
-       uint8_t *it = pack_head(*addr_set);
-       while (it != pack_tail(*addr_set)) {
+       for (uint8_t *it = pack_head(*addr_set); it != pack_tail(*addr_set);
+                                               it = pack_obj_next(it)) {
                void *val = pack_obj_val(it);
                size_t len = pack_obj_len(it);
                unsigned favour = 0;
@@ -112,10 +112,10 @@ static unsigned eval_addr_set(const pack_t *addr_set, struct kr_context *ctx,
                }
 
                if (!is_valid) {
-                       goto get_next_iterator;
+                       continue;
                }
 
-               /* Get RTT for this address (if known) */
+               /* Get score for the current address. */
                kr_nsrep_rtt_lru_entry_t *cached = rtt_cache ?
                                                   lru_get_try(rtt_cache, val, len) :
                                                   NULL;
@@ -167,8 +167,6 @@ static unsigned eval_addr_set(const pack_t *addr_set, struct kr_context *ctx,
                                break;
                        }
                }
-       get_next_iterator:
-               it = pack_obj_next(it);
        }
 
        /* At this point, rtt_cache_entry_ptr contains up to KR_NSREP_MAXADDR
@@ -380,7 +378,7 @@ int kr_nsrep_elect_addr(struct kr_query *qry, struct kr_context *ctx)
 int kr_nsrep_update_rtt(struct kr_nsrep *ns, const struct sockaddr *addr,
                        unsigned score, kr_nsrep_rtt_lru_t *cache, int umode)
 {
-       if (!cache || umode > KR_NS_MAX) {
+       if (!cache || umode > KR_NS_MAX || umode < 0) {
                return kr_error(EINVAL);
        }
 
@@ -409,15 +407,10 @@ int kr_nsrep_update_rtt(struct kr_nsrep *ns, const struct sockaddr *addr,
        if (score <= KR_NS_GLUED) {
                score = KR_NS_GLUED + 1;
        }
-       /* First update is always set unless KR_NS_UPDATE_NORESET mode used. */
-       if (is_new_entry) {
-               if (umode == KR_NS_UPDATE_NORESET) {
-                       /* Zero initial value. */
-                       cur->score = 0;
-               } else {
-                       /* Force KR_NS_RESET otherwise. */
-                       umode = KR_NS_RESET;
-               }
+       /* If there's nothing to update, we reset it unless KR_NS_UPDATE_NORESET
+        * mode was requested.  New items are zeroed by LRU automatically. */
+       if (is_new_entry && umode != KR_NS_UPDATE_NORESET) {
+               umode = KR_NS_RESET;
        }
        unsigned new_score = 0;
        /* Update score, by default smooth over last two measurements. */
@@ -428,7 +421,7 @@ int kr_nsrep_update_rtt(struct kr_nsrep *ns, const struct sockaddr *addr,
        case KR_NS_RESET:  new_score = score; break;
        case KR_NS_ADD:    new_score = MIN(KR_NS_MAX_SCORE - 1, cur->score + score); break;
        case KR_NS_MAX:    new_score = MAX(cur->score, score); break;
-       default: break;
+       default:           return kr_error(EINVAL);
        }
        /* Score limits */
        if (new_score > KR_NS_MAX_SCORE) {