]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
allow access to cache object through context
authorMarek Vavruša <mvavrusa@cloudflare.com>
Thu, 4 Jan 2018 00:07:35 +0000 (16:07 -0800)
committerPetr Špaček <petr.spacek@nic.cz>
Thu, 4 Jan 2018 10:04:41 +0000 (11:04 +0100)
this surfaces the struct kr_cache through context variable,
it doesn't implement any API or documented interface for it,
so I just added a tests for the struct presence and introspection

daemon/lua/kres-gen.lua
daemon/lua/kres-gen.sh
tests/config/cache_test.lua

index ba31e5179fd6ce1b632c718b3ce88975a5651abd..76eb974306a331e9462d996ce0fca63f4deabde4 100644 (file)
@@ -3,6 +3,8 @@ local ffi = require('ffi')
 
 typedef struct knot_dump_style knot_dump_style_t;
 extern const knot_dump_style_t KNOT_DUMP_STYLE_DEFAULT;
+typedef void knot_db_t;
+struct kr_cdb_api {};
 
 typedef struct knot_mm {
        void *ctx, *alloc, *free;
@@ -163,6 +165,21 @@ struct kr_request {
        knot_mm_t pool;
 };
 enum kr_rank {KR_RANK_INITIAL, KR_RANK_OMIT, KR_RANK_TRY, KR_RANK_INDET = 4, KR_RANK_BOGUS, KR_RANK_MISMATCH, KR_RANK_MISSING, KR_RANK_INSECURE, KR_RANK_AUTH = 16, KR_RANK_SECURE = 32};
+struct kr_cache
+{
+       knot_db_t *db;
+       const struct kr_cdb_api *api;
+       struct {
+               uint32_t hit;
+               uint32_t miss;
+               uint32_t insert;
+               uint32_t delete;
+       } stats;
+
+       uint32_t ttl_min, ttl_max;
+       struct timeval last_clear_walltime;
+       uint64_t last_clear_monotime;
+};
 struct knot_rrset {
        knot_dname_t *_owner;
        uint16_t type;
@@ -203,6 +220,7 @@ struct kr_context {
        map_t trust_anchors;
        map_t negative_anchors;
        struct kr_zonecut root_hints;
+       struct kr_cache cache;
        char _stub[];
 };
 const char *knot_strerror(int code);
index 432e49e8c1f07aa585fbc83876aa6ecb45c9049f..d1bf4d362999eaf03c343728073de916d004439b 100755 (executable)
@@ -22,6 +22,8 @@ printf -- "--[[ This file is generated by ./kres-gen.sh ]] ffi.cdef[[\n"
 printf "
 typedef struct knot_dump_style knot_dump_style_t;
 extern const knot_dump_style_t KNOT_DUMP_STYLE_DEFAULT;
+typedef void knot_db_t;
+struct kr_cdb_api {};
 "
 
 # The generator doesn't work well with typedefs of functions.
@@ -58,6 +60,7 @@ typedef void (*map_free_f)(void *baton, void *ptr);
        struct kr_rplan
        struct kr_request
        enum kr_rank
+       struct kr_cache
 EOF
 
 genResType() {
@@ -74,7 +77,7 @@ printf "\t/* beware: hidden stub */\n};\n"
 
 genResType "struct kr_query"
 
-genResType "struct kr_context" | sed '/struct kr_cache/,$ d'
+genResType "struct kr_context" | sed '/kr_nsrep_lru_t/,$ d'
 printf "\tchar _stub[];\n};\n"
 
 ## libknot API
index 06f6f9210853c0b2bf8f421260b863923ba17b94..6cbe8ad329c3a4fb9b18c52f477f6e08421474db 100644 (file)
@@ -31,8 +31,17 @@ local function test_resize()
        is(cache.current_size, 50 * MB, 'cache was shrunk')
 end
 
+-- test access to cache through context
+local function test_context_cache()
+       local c = kres.context().cache
+       is(type(c), 'cdata', 'context has a cache object')
+       local s = c.stats
+       same({s.hit, s.miss, s.insert, s.delete}, {0, 0, 0, 0}, 'context cache stats works')
+end
+
 return {
        test_properties,
        test_stats,
        test_resize,
+       test_context_cache,
 }
\ No newline at end of file