From: Vladimír Čunát Date: Mon, 5 Feb 2018 18:36:41 +0000 (+0100) Subject: lua: fix a mistake in kr_query, and simplify serve_stale X-Git-Tag: v2.1.0~4^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a02f44115dbec5f1e9c6ea6fa0f8fcc584dcb172;p=thirdparty%2Fknot-resolver.git lua: fix a mistake in kr_query, and simplify serve_stale Fields after kr_nsrep got offset; fortunately only new fields were added in there, unused from lua so far. --- diff --git a/config.mk b/config.mk index 42dae2a8d..9c21b0703 100644 --- a/config.mk +++ b/config.mk @@ -3,7 +3,7 @@ MAJOR := 2 MINOR := 0 PATCH := 0 EXTRA := -ABIVER := 5 +ABIVER := 6 BUILDMODE := dynamic HARDENING := yes diff --git a/daemon/lua/kres-gen.lua b/daemon/lua/kres-gen.lua index d4e3f5c22..629fe899a 100644 --- a/daemon/lua/kres-gen.lua +++ b/daemon/lua/kres-gen.lua @@ -201,7 +201,7 @@ struct kr_nsrep { unsigned int reputation; const knot_dname_t *name; struct kr_context *ctx; - /* beware: hidden stub */ + /* beware: hidden stub, to avoid hardcoding sockaddr lengths */ }; struct kr_query { struct kr_query *parent; @@ -218,12 +218,12 @@ struct kr_query { uint64_t timestamp_mono; struct timeval timestamp; struct kr_zonecut zone_cut; - struct kr_nsrep ns; struct kr_layer_pickle *deferred; uint32_t uid; struct kr_query *cname_parent; struct kr_request *request; kr_stale_cb stale_cb; + struct kr_nsrep ns; }; struct kr_context { struct kr_qflags options; @@ -286,7 +286,6 @@ struct sockaddr *kr_straddr_socket(const char *, int); int kr_ranked_rrarray_add(ranked_rr_array_t *, const knot_rrset_t *, uint8_t, _Bool, uint32_t, knot_mm_t *); void kr_qflags_set(struct kr_qflags *, struct kr_qflags); void kr_qflags_clear(struct kr_qflags *, struct kr_qflags); -void kr_query_set_stale_cb(struct kr_query *, kr_stale_cb); int kr_zonecut_add(struct kr_zonecut *, const knot_dname_t *, const knot_rdata_t *); void kr_zonecut_set(struct kr_zonecut *, const knot_dname_t *); uint64_t kr_now(); diff --git a/daemon/lua/kres-gen.sh b/daemon/lua/kres-gen.sh index caf4383cd..5e911f5cb 100755 --- a/daemon/lua/kres-gen.sh +++ b/daemon/lua/kres-gen.sh @@ -80,7 +80,7 @@ genResType "struct knot_rrset" | sed 's/\/_owner/' ## Some definitions would need too many deps, so shorten them. genResType "struct kr_nsrep" | sed '/union/,$ d' -printf "\t/* beware: hidden stub */\n};\n" +printf "\t/* beware: hidden stub, to avoid hardcoding sockaddr lengths */\n};\n" genResType "struct kr_query" @@ -153,7 +153,6 @@ EOF kr_ranked_rrarray_add kr_qflags_set kr_qflags_clear - kr_query_set_stale_cb kr_zonecut_add kr_zonecut_set kr_now diff --git a/lib/rplan.c b/lib/rplan.c index a21e05a76..e18d96a13 100644 --- a/lib/rplan.c +++ b/lib/rplan.c @@ -27,11 +27,6 @@ #define QUERY_PROVIDES(q, name, cls, type) \ ((q)->sclass == (cls) && (q)->stype == type && knot_dname_is_equal((q)->sname, name)) -void kr_query_set_stale_cb(struct kr_query *qry, kr_stale_cb cb) -{ - qry->stale_cb = cb; -} - inline static unsigned char chars_or(const unsigned char a, const unsigned char b) { return a | b; diff --git a/lib/rplan.h b/lib/rplan.h index 6e54a6a40..4be0d8e64 100644 --- a/lib/rplan.h +++ b/lib/rplan.h @@ -78,10 +78,6 @@ void kr_qflags_clear(struct kr_qflags *fl1, struct kr_qflags fl2); */ typedef int32_t (*kr_stale_cb)(int32_t ttl, const knot_dname_t *owner, uint16_t type, const struct kr_query *qry); -/** Trivial wrapper to set kr_query::stale_cb. - * For some unknown reason, direct setting via lua doesn't work. */ -KR_EXPORT -void kr_query_set_stale_cb(struct kr_query *qry, kr_stale_cb cb); /** * Single query representation. @@ -103,13 +99,14 @@ struct kr_query { * query to upstream resolver (milliseconds). */ struct timeval timestamp; /**< Real time for TTL+DNSSEC checks (.tv_sec only). */ struct kr_zonecut zone_cut; - struct kr_nsrep ns; struct kr_layer_pickle *deferred; uint32_t uid; /**< Query iteration number, unique within the kr_rplan. */ /** Pointer to the query that originated this one because of following a CNAME (or NULL). */ struct kr_query *cname_parent; struct kr_request *request; /**< Parent resolution request. */ kr_stale_cb stale_cb; /**< See the type */ + /* Beware: this must remain the last, because of lua bindings. */ + struct kr_nsrep ns; }; /** @cond internal Array of queries. */ diff --git a/modules/serve_stale/serve_stale.lua b/modules/serve_stale/serve_stale.lua index c0527666e..c8677ba1e 100644 --- a/modules/serve_stale/serve_stale.lua +++ b/modules/serve_stale/serve_stale.lua @@ -28,7 +28,7 @@ M.layer = { local deadline = qry.creation_time_mono + M.timeout if now > deadline then --log('[ ][stal] => deadline has passed') - ffi.C.kr_query_set_stale_cb(qry, M.callback) + qry.stale_cb = M.callback -- TODO: probably start the same request that doesn't stale-serve, -- but first we need some detection of non-interactive / internal requests. -- resolve(kres.dname2str(qry.sname), qry.stype, qry.sclass)