daemon/tls.c \
daemon/main.c
-kresd_DIST := daemon/lua/kres.lua daemon/lua/trust_anchors.lua
+kresd_DIST := daemon/lua/kres.lua daemon/lua/kres-gen.lua daemon/lua/trust_anchors.lua
# Embedded resources
%.inc: %.lua
# Targets
date := $(shell date +%F)
-daemon: $(kresd)
+daemon: $(kresd) $(kresd_DIST)
daemon-install: kresd-install bindings-install
ifneq ($(SED),)
$(SED) -e "s/@VERSION@/$(VERSION)/" -e "s/@DATE@/$(date)/" doc/kresd.8.in > doc/kresd.8
daemon-clean: kresd-clean
@$(RM) daemon/lua/*.inc
+daemon/lua/kres-gen.lua: | $(libkres)
+ @echo "WARNING: regenerating $@"
+ daemon/lua/kres-gen.sh > $@
+.DELETE_ON_ERROR: daemon/lua/kres-gen.lua
+
.PHONY: daemon daemon-install daemon-clean
--- /dev/null
+--[[ This file is generated by ./kres-gen.sh ]] ffi.cdef[[
+
+
+typedef struct knot_dump_style knot_dump_style_t;
+extern const knot_dump_style_t KNOT_DUMP_STYLE_DEFAULT;
+
+
+typedef struct knot_mm {
+ void *ctx, *alloc, *free;
+} knot_mm_t;
+
+typedef void *(*map_alloc_f)(void *, size_t);
+typedef void (*map_free_f)(void *baton, void *ptr);
+
+typedef enum {KNOT_ANSWER, KNOT_AUTHORITY, KNOT_ADDITIONAL} knot_section_t;
+typedef struct {
+ uint16_t pos;
+ uint16_t flags;
+ uint16_t compress_ptr[16];
+} knot_rrinfo_t;
+typedef unsigned char knot_dname_t;
+typedef unsigned char knot_rdata_t;
+typedef struct knot_rdataset knot_rdataset_t;
+struct knot_rdataset {
+ uint16_t rr_count;
+ knot_rdata_t *data;
+}
+;
+typedef struct knot_rrset knot_rrset_t;
+typedef struct {
+ struct knot_pkt *pkt;
+ uint16_t pos;
+ uint16_t count;
+} knot_pktsection_t;
+struct knot_pkt {
+ uint8_t *wire;
+ size_t size;
+ size_t max_size;
+ size_t parsed;
+ uint16_t reserved;
+ uint16_t qname_size;
+ uint16_t rrset_count;
+ uint16_t flags;
+ knot_rrset_t *opt_rr;
+ knot_rrset_t *tsig_rr;
+ struct {
+ uint8_t *pos;
+ size_t len;
+ } tsig_wire;
+ knot_section_t current;
+ knot_pktsection_t sections[3];
+ size_t rrset_allocd;
+ knot_rrinfo_t *rr_info;
+ knot_rrset_t *rr;
+ knot_mm_t mm;
+}
+;
+typedef struct knot_pkt knot_pkt_t;
+typedef struct {
+ void *root;
+ map_alloc_f malloc;
+ map_free_f free;
+ void *baton;
+} map_t;
+typedef struct {
+ knot_rrset_t **at;
+ size_t len;
+ size_t cap;
+} rr_array_t;
+struct kr_zonecut {
+ knot_dname_t *name;
+ knot_rrset_t *key;
+ knot_rrset_t *trust_anchor;
+ struct kr_zonecut *parent;
+ map_t nsset;
+ knot_mm_t *pool;
+}
+;
+typedef struct {
+ struct kr_query **at;
+ size_t len;
+ size_t cap;
+} kr_qarray_t;
+struct kr_rplan {
+ kr_qarray_t pending;
+ kr_qarray_t resolved;
+ struct kr_request *request;
+ knot_mm_t *pool;
+}
+;
+struct kr_request {
+ struct kr_context *ctx;
+ knot_pkt_t *answer;
+ struct kr_query *current_query;
+ struct {
+ const knot_rrset_t *key;
+ const struct sockaddr *addr;
+ const struct sockaddr *dst_addr;
+ const knot_pkt_t *packet;
+ const knot_rrset_t *opt;
+ } qsource;
+ struct {
+ unsigned int rtt;
+ const struct sockaddr *addr;
+ } upstream;
+ uint32_t options;
+ int state;
+ rr_array_t authority;
+ rr_array_t additional;
+ struct kr_rplan rplan;
+ int has_tls;
+ knot_mm_t pool;
+}
+;
+struct knot_rrset {
+ knot_dname_t *_owner;
+ uint16_t type;
+ uint16_t rclass;
+ knot_rdataset_t rrs;
+ void *additional;
+}
+;
+struct kr_query {
+ struct kr_query *parent;
+ knot_dname_t *sname;
+ uint16_t stype;
+ uint16_t sclass;
+ uint16_t id;
+ uint32_t flags;
+ uint32_t secret;
+ uint16_t fails;
+ uint16_t reorder;
+ struct timeval timestamp;
+ struct kr_zonecut zone_cut;
+ char _stub[];
+};
+struct kr_context {
+ uint32_t options;
+ knot_rrset_t *opt_rr;
+ map_t trust_anchors;
+ map_t negative_anchors;
+ struct kr_zonecut root_hints;
+ char _stub[];
+};
+struct query_flag {static const int NO_MINIMIZE = 1; static const int NO_THROTTLE = 2; static const int NO_IPV6 = 4; static const int NO_IPV4 = 8;
+ static const int TCP = 16; static const int RESOLVED = 32; static const int AWAIT_IPV4 = 64; static const int AWAIT_IPV6 = 128; static const int AWAIT_CUT = 256;
+ static const int SAFEMODE = 512; static const int CACHED = 1024; static const int NO_CACHE = 2048; static const int EXPIRING = 4096;
+ static const int ALLOW_LOCAL = 8192; static const int DNSSEC_WANT = 16384; static const int DNSSEC_BOGUS = 32768;
+ static const int DNSSEC_INSECURE = 65536; static const int STUB = 131072; static const int ALWAYS_CUT = 262144;
+ static const int DNSSEC_WEXPAND = 524288; static const int PERMISSIVE = 1048576; static const int STRICT = 2097152;
+ static const int BADCOOKIE_AGAIN = 4194304; static const int CNAME = 8388608; static const int REORDER_RR = 16777216;}
+;
+int knot_dname_size(const knot_dname_t *);
+knot_dname_t *knot_dname_from_str(uint8_t *, const char *, size_t);
+char *knot_dname_to_str(char *, const knot_dname_t *, size_t);
+uint16_t knot_rdata_rdlen(const knot_rdata_t *);
+uint8_t *knot_rdata_data(const knot_rdata_t *);
+knot_rdata_t *knot_rdataset_at(const knot_rdataset_t *, size_t);
+uint32_t knot_rrset_ttl(const knot_rrset_t *);
+int knot_rrset_txt_dump_data(const knot_rrset_t *, const size_t, char *, const size_t,
+ const knot_dump_style_t *);
+int knot_rrset_txt_dump(const knot_rrset_t *, char *, const size_t, const knot_dump_style_t *);
+const knot_dname_t *knot_pkt_qname(const knot_pkt_t *);
+uint16_t knot_pkt_qtype(const knot_pkt_t *);
+uint16_t knot_pkt_qclass(const knot_pkt_t *);
+int knot_pkt_begin(knot_pkt_t *, knot_section_t);
+int knot_pkt_put_question(knot_pkt_t *, const knot_dname_t *, uint16_t, uint16_t);
+const knot_rrset_t *knot_pkt_rr(const knot_pktsection_t *, uint16_t);
+const knot_pktsection_t *knot_pkt_section(const knot_pkt_t *, knot_section_t);
+struct kr_rplan *kr_resolve_plan(struct kr_request *);
+knot_mm_t *kr_resolve_pool(struct kr_request *);
+struct kr_query *kr_rplan_push(struct kr_rplan *, struct kr_query *, const knot_dname_t *, uint16_t, uint16_t);
+int kr_rplan_pop(struct kr_rplan *, struct kr_query *);
+struct kr_query *kr_rplan_resolved(struct kr_rplan *);
+int kr_nsrep_set(struct kr_query *, size_t, uint8_t *, size_t, int);
+unsigned int kr_rand_uint(unsigned int);
+int kr_pkt_put(knot_pkt_t *, const knot_dname_t *, uint32_t, uint16_t, uint16_t, const uint8_t *, uint16_t);
+int kr_pkt_recycle(knot_pkt_t *);
+const char *kr_inaddr(const struct sockaddr *);
+int kr_inaddr_family(const struct sockaddr *);
+int kr_inaddr_len(const struct sockaddr *);
+int kr_straddr_family(const char *);
+int kr_straddr_subnet(void *, const char *);
+int kr_bitcmp(const char *, const char *, int);
+int kr_family_len(int);
+int kr_rrarray_add(rr_array_t *, const knot_rrset_t *, knot_mm_t *);
+knot_rrset_t *kr_ta_get(map_t *, const knot_dname_t *);
+int kr_ta_add(map_t *, const knot_dname_t *, uint16_t, uint32_t, const uint8_t *, uint16_t);
+int kr_ta_del(map_t *, const knot_dname_t *);
+void kr_ta_clear(map_t *);
+_Bool kr_dnssec_key_ksk(const uint8_t *);
+_Bool kr_dnssec_key_revoked(const uint8_t *);
+int kr_dnssec_key_tag(uint16_t, const uint8_t *, size_t);
+int kr_dnssec_key_match(const uint8_t *, size_t, const uint8_t *, size_t);
+]]
--- /dev/null
+#!/bin/sh -e
+
+echo "--[[ This file is generated by ./kres-gen.sh ]] ffi.cdef[[
+"
+
+## Various types (mainly), from libknot and libkres
+
+echo "
+typedef struct knot_dump_style knot_dump_style_t;
+extern const knot_dump_style_t KNOT_DUMP_STYLE_DEFAULT;
+"
+
+# The generator doesn't work well with typedefs of functions.
+echo "
+typedef struct knot_mm {
+ void *ctx, *alloc, *free;
+} knot_mm_t;
+
+typedef void *(*map_alloc_f)(void *, size_t);
+typedef void (*map_free_f)(void *baton, void *ptr);
+"
+
+./scripts/gen-cdefs.sh libkres types <<-EOF
+ knot_section_t
+ knot_rrinfo_t
+ knot_dname_t
+ knot_rdata_t
+ knot_rdataset_t
+ struct knot_rdataset
+ knot_rrset_t
+ knot_pktsection_t
+ struct knot_pkt
+ knot_pkt_t
+ # generics
+ map_t
+ # libkres
+ rr_array_t
+ #struct ranked_rr_array_entry # TODO: prepared for vld-refactoring
+ #ranked_rr_array_entry_t
+ #ranked_rr_array_t
+ struct kr_zonecut
+ kr_qarray_t
+ struct kr_rplan
+ struct kr_request
+EOF
+
+genResType() {
+ echo "$1" | ./scripts/gen-cdefs.sh libkres types
+}
+
+# No simple way to fixup this rename in ./kres.lua AFAIK.
+genResType "struct knot_rrset" | sed 's/\<owner\>/_owner/'
+
+## Some definitions would need too many deps, so shorten them.
+
+genResType "struct kr_query" | sed '/struct kr_nsrep/,$ d'
+echo -e "\tchar _stub[];\n};"
+
+genResType "struct kr_context" | sed '/struct kr_cache/,$ d'
+echo -e "\tchar _stub[];\n};"
+
+# Getting struct query_flag is a bit complex.
+genResType "enum kr_query_flag" | sed -e 's/enum kr_query_flag/struct query_flag/' \
+ -e 's/QUERY_NO_THROTTLE/& = 2/' `# a special case for consecutive integers` \
+ -e 's@\<QUERY_\([A-Z_0-9]*\) = \([0-9]*\)@static const int \1 = \2;@g' \
+ -e 's/,//g'
+
+## libknot API
+./scripts/gen-cdefs.sh libknot functions <<-EOF
+# Domain names
+ knot_dname_size
+ knot_dname_from_str
+ knot_dname_to_str
+# Resource records
+ knot_rdata_rdlen
+ knot_rdata_data
+ knot_rdataset_at
+ knot_rrset_ttl
+ knot_rrset_txt_dump_data
+ knot_rrset_txt_dump
+# Packet
+ knot_pkt_qname
+ knot_pkt_qtype
+ knot_pkt_qclass
+ knot_pkt_begin
+ knot_pkt_put_question
+ knot_pkt_rr
+ knot_pkt_section
+EOF
+
+## libkres API
+./scripts/gen-cdefs.sh libkres functions <<-EOF
+# Resolution request
+ kr_resolve_plan
+ kr_resolve_pool
+# Resolution plan
+ kr_rplan_push
+ kr_rplan_pop
+ kr_rplan_resolved
+# Nameservers
+ kr_nsrep_set
+# Utils
+ kr_rand_uint
+ kr_pkt_put
+ kr_pkt_recycle
+ kr_inaddr
+ kr_inaddr_family
+ kr_inaddr_len
+ kr_straddr_family
+ kr_straddr_subnet
+ kr_bitcmp
+ kr_family_len
+ kr_rrarray_add
+# Trust anchors
+ kr_ta_get
+ kr_ta_add
+ kr_ta_del
+ kr_ta_clear
+# DNSSEC
+ kr_dnssec_key_ksk
+ kr_dnssec_key_revoked
+ kr_dnssec_key_tag
+ kr_dnssec_key_match
+EOF
+
+echo "]]"
+
-- LuaJIT ffi bindings for libkres, a DNS resolver library.
-- @note Since it's statically compiled, it expects to find the symbols in the C namespace.
-local ffi_ok, ffi = pcall(require, 'ffi')
+local ffi_ok
+ffi_ok, ffi = pcall(require, 'ffi')
if not ffi_ok then
local M = { error = 'FFI not available, resolver bindings disabled.' }
setmetatable(M, {__index = function(t,k,v) error(rawget(M, 'error')) end })
local C = ffi.C
local knot = ffi.load(libknot_SONAME)
+-- Various declarations that are very stable.
ffi.cdef[[
/*
struct pkt_section {
static const int ANSWER = 0;
static const int AUTHORITY = 1;
- static const int ADDITIONAL = 2;
+ static const int ADDITIONAL = 2;
};
struct pkt_rcode {
static const int NOERROR = 0;
static const int NOTZONE = 10;
static const int BADVERS = 16;
};
-struct query_flag {
- static const int NO_MINIMIZE = 1 << 0;
- static const int NO_THROTTLE = 1 << 1;
- static const int NO_IPV6 = 1 << 2;
- static const int NO_IPV4 = 1 << 3;
- static const int RESOLVED = 1 << 5;
- static const int AWAIT_CUT = 1 << 8;
- static const int CACHED = 1 << 10;
- static const int NO_CACHE = 1 << 11;
- static const int EXPIRING = 1 << 12;
- static const int DNSSEC_WANT = 1 << 14;
- static const int DNSSEC_BOGUS = 1 << 15;
- static const int DNSSEC_INSECURE = 1 << 16;
- static const int STUB = 1 << 17;
- static const int ALWAYS_CUT = 1 << 18;
- static const int PERMISSIVE = 1 << 20;
- static const int STRICT = 1 << 21;
- static const int BADCOOKIE_AGAIN = 1 << 22;
- static const int CNAME = 1 << 23;
- static const int REORDER_RR = 1 << 24;
-};
/*
* Data structures
uint8_t _stub[]; /* Do not touch */
};
-/* libknot */
-typedef struct {
- uint8_t _stub[]; /* Do not touch */
-} knot_dump_style_t;
-extern const knot_dump_style_t KNOT_DUMP_STYLE_DEFAULT;
-typedef int knot_section_t; /* Do not touch */
-typedef void knot_rrinfo_t; /* Do not touch */
-typedef uint8_t knot_dname_t;
-typedef uint8_t knot_rdata_t;
-typedef struct knot_rdataset {
- uint16_t count;
- knot_rdata_t *data;
-} knot_rdataset_t;
-typedef struct knot_rrset {
- knot_dname_t *_owner;
- uint16_t type;
- uint16_t class;
- knot_rdataset_t rr;
-} knot_rrset_t;
-typedef struct {
- struct knot_pkt *pkt;
- uint16_t pos;
- uint16_t count;
-} knot_pktsection_t;
-typedef struct { /* some names differ now in knot */
- uint8_t *wire;
- size_t size;
- size_t max_size;
- size_t parsed;
- uint16_t reserved;
- uint16_t qname_size;
- uint16_t rrset_count;
- uint16_t flags;
- knot_rrset_t *opt;
- knot_rrset_t *tsig;
- struct {
- uint8_t *pos;
- size_t len;
- } tsig_wire;
- knot_section_t _current;
- knot_pktsection_t _sections[3];
- size_t _rrset_allocd;
- knot_rrinfo_t *_rr_info;
- knot_rrset_t *_rr;
- uint8_t _stub[]; /* Do not touch */
-} knot_pkt_t;
-
-/* generics */
-typedef void *(*map_alloc_f)(void *, size_t);
-typedef void (*map_free_f)(void *baton, void *ptr);
-typedef struct {
- void *root;
- map_alloc_f malloc;
- map_free_f free;
- void *baton;
-} map_t;
-
-/* libkres */
-typedef struct {
- knot_rrset_t *at;
- size_t len;
- size_t cap;
-} rr_array_t;
-struct kr_zonecut {
- knot_dname_t *name;
- knot_rrset_t *key;
- knot_rrset_t *trust_anchor;
- uint8_t _stub[]; /* Do not touch */
-};
-struct kr_query {
- struct kr_query *parent;
- knot_dname_t *sname;
- uint16_t type;
- uint16_t class;
- uint16_t id;
- uint32_t flags;
- uint32_t secret;
- uint16_t fails;
- uint16_t reorder;
- struct timeval timestamp;
- struct kr_zonecut zone_cut;
- uint8_t _stub[]; /* Do not touch */
-};
-struct kr_rplan {
- uint8_t _stub[]; /* Do not touch */
-};
-struct kr_request {
- struct kr_context *ctx;
- knot_pkt_t *answer;
- struct kr_query *current_query;
- struct {
- const knot_rrset_t *key;
- const struct sockaddr *addr;
- const struct sockaddr *dst_addr;
- const knot_pkt_t *packet;
- const knot_rrset_t *opt;
- } qsource;
- struct {
- unsigned rtt;
- const struct sockaddr *addr;
- } upstream;
- uint32_t options;
- int state;
- rr_array_t authority;
- rr_array_t additional;
- uint8_t _stub[]; /* Do not touch */
-};
-struct kr_context
-{
- uint32_t options;
- knot_rrset_t *opt_rr;
- map_t trust_anchors;
- map_t negative_anchors;
- uint8_t _stub[]; /* Do not touch */
-};
-
/*
* libc APIs
*/
void free(void *ptr);
int inet_pton(int af, const char *src, void *dst);
-
-/*
- * libknot APIs
- */
-/* Domain names */
-int knot_dname_size(const knot_dname_t *name);
-knot_dname_t *knot_dname_from_str(uint8_t *dst, const char *name, size_t maxlen);
-char *knot_dname_to_str(char *dst, const knot_dname_t *name, size_t maxlen);
-/* Resource records */
-uint16_t knot_rdata_rdlen(const knot_rdata_t *rr);
-uint8_t *knot_rdata_data(const knot_rdata_t *rr);
-knot_rdata_t *knot_rdataset_at(const knot_rdataset_t *rrs, size_t pos);
-uint32_t knot_rrset_ttl(const knot_rrset_t *rrset);
-int knot_rrset_txt_dump_data(const knot_rrset_t *rrset, size_t pos, char *dst, size_t maxlen, const knot_dump_style_t *style);
-int knot_rrset_txt_dump(const knot_rrset_t *rrset, char *dst, size_t maxlen, const knot_dump_style_t *style);
-
-/* Packet */
-const knot_dname_t *knot_pkt_qname(const knot_pkt_t *pkt);
-uint16_t knot_pkt_qtype(const knot_pkt_t *pkt);
-uint16_t knot_pkt_qclass(const knot_pkt_t *pkt);
-int knot_pkt_begin(knot_pkt_t *pkt, int section_id);
-int knot_pkt_put_question(knot_pkt_t *pkt, const knot_dname_t *qname, uint16_t qclass, uint16_t qtype);
-const knot_rrset_t *knot_pkt_rr(const knot_pktsection_t *section, uint16_t i);
-const knot_pktsection_t *knot_pkt_section(const knot_pkt_t *pkt,
- knot_section_t section_id);
-
-/*
- * libkres API
- */
-/* Resolution request */
-struct kr_rplan *kr_resolve_plan(struct kr_request *request);
-void *kr_resolve_pool(struct kr_request *request);
-/* Resolution plan */
-struct kr_query *kr_rplan_push(struct kr_rplan *rplan, struct kr_query *parent,
- const knot_dname_t *name, uint16_t cls, uint16_t type);
-int kr_rplan_pop(struct kr_rplan *rplan, struct kr_query *qry);
-struct kr_query *kr_rplan_resolved(struct kr_rplan *rplan);
-struct kr_query *kr_rplan_next(struct kr_query *qry);
-/* Nameservers */
-int kr_nsrep_set(struct kr_query *qry, size_t index, uint8_t *addr, size_t addr_len, int port);
-/* Query */
-/* Utils */
-unsigned kr_rand_uint(unsigned max);
-int kr_pkt_put(knot_pkt_t *pkt, const knot_dname_t *name, uint32_t ttl,
- uint16_t rclass, uint16_t rtype, const uint8_t *rdata, uint16_t rdlen);
-int kr_pkt_recycle(knot_pkt_t *pkt);
-const char *kr_inaddr(const struct sockaddr *addr);
-int kr_inaddr_family(const struct sockaddr *addr);
-int kr_inaddr_len(const struct sockaddr *addr);
-int kr_straddr_family(const char *addr);
-int kr_straddr_subnet(void *dst, const char *addr);
-int kr_bitcmp(const char *a, const char *b, int bits);
-int kr_family_len(int family);
-int kr_rrarray_add(rr_array_t *array, const knot_rrset_t *rr, void *pool);
-/* Trust anchors */
-knot_rrset_t *kr_ta_get(map_t *trust_anchors, const knot_dname_t *name);
-int kr_ta_add(map_t *trust_anchors, const knot_dname_t *name, uint16_t type,
- uint32_t ttl, const uint8_t *rdata, uint16_t rdlen);
-int kr_ta_del(map_t *trust_anchors, const knot_dname_t *name);
-void kr_ta_clear(map_t *trust_anchors);
-/* DNSSEC */
-bool kr_dnssec_key_ksk(const uint8_t *dnskey_rdata);
-bool kr_dnssec_key_revoked(const uint8_t *dnskey_rdata);
-int kr_dnssec_key_tag(uint16_t rrtype, const uint8_t *rdata, size_t rdlen);
-int kr_dnssec_key_match(const uint8_t *key_a_rdata, size_t key_a_rdlen,
- const uint8_t *key_b_rdata, size_t key_b_rdlen);
]]
+require('kres-gen')
+
-- Constants
local query_flag = ffi.new('struct query_flag')
owner = function(rr) return ffi.string(rr._owner, knot.knot_dname_size(rr._owner)) end,
ttl = function(rr) return tonumber(knot.knot_rrset_ttl(rr)) end,
rdata = function(rr, i)
- local rdata = knot.knot_rdataset_at(rr.rr, i)
+ local rdata = knot.knot_rdataset_at(rr.rrs, i)
return ffi.string(knot.knot_rdata_data(rdata), knot.knot_rdata_rdlen(rdata))
end,
get = function(rr, i)
return {owner = rr:owner(),
ttl = rr:ttl(),
- class = tonumber(rr.class),
+ class = tonumber(rr.rclass),
type = tonumber(rr.type),
rdata = rr:rdata(i)}
end,
tostring = function(rr, i)
assert(ffi.istype(knot_rrset_t, rr))
- if rr.rr.count > 0 then
+ if rr.rrs.rr_count > 0 then
local ret
if i ~= nil then
ret = knot.knot_rrset_txt_dump_data(rr, i, rrset_buf, rrset_buflen, knot.KNOT_DUMP_STYLE_DEFAULT)
local section = knot.knot_pkt_section(pkt, section_id)
for i = 1, section.count do
local rrset = knot.knot_pkt_rr(section, i - 1)
- for k = 1, rrset.rr.count do
+ for k = 1, rrset.rrs.rr_count do
table.insert(records, rrset:get(k - 1))
end
end
-- Print information about current query
local current = req:current()
print(kres.dname2str(current.owner))
- print(current.type, current.class, current.id, current.flags)
+ print(current.stype, current.sclass, current.id, current.flags)
end
In layers that either begin or finalize, you can walk the list of resolved queries.
.. code-block:: lua
local last = req:resolved()
- print(last.type)
+ print(last.stype)
As described in the layers, you can not only retrieve information about current query, but also push new ones or pop old ones.
lib/zonecut.c: lib/root-hints.inc
lib/root-hints.inc:
+ @echo "WARNING: regenerating $@"
scripts/gen-root-hints.sh > $@
+.DELETE_ON_ERROR: lib/root-hints.inc
# Make library
ifeq ($(BUILDMODE), static)
X(BADCOOKIE_AGAIN, 1 << 22) /**< Query again because bad cookie returned. */ \
X(CNAME, 1 << 23) /**< Query response contains CNAME in answer section. */ \
X(REORDER_RR, 1 << 24) /**< Reorder cached RRs. */
+ /* 1 << 31 Used by ../modules/dns64/dns64.lua */
/** Query flags */
enum kr_query_flag {
end)
-- Disallow ANY queries
policy.add(function (req, query)
- if query.type == kres.type.ANY then
+ if query.stype == kres.type.ANY then
return policy.DROP
end
end)
-- LuaJIT ffi bindings for zscanner, a DNS zone parser.
-- Author: Marek Vavrusa <marek.vavrusa@nic.cz>
---
+-- FIXME: generate
local ffi = require('ffi')
local libzscanner = ffi.load(libzscanner_SONAME)
local nr_queries = #queries
for i = 1, nr_queries do
local entry = queries[i]
- local key = string.format('%s %s', entry.type, entry.name)
+ local key = string.format('%s %s', entry.stype, entry.name)
if not predict.queue[key] then
predict.queue[key] = 1
queued = queued + 1
local nr_samples = #queries
for i = 1, nr_samples do
local entry = queries[i]
- local key = string.format('%s %s', entry.type, entry.name)
+ local key = string.format('%s %s', entry.stype, entry.name)
current[key] = 1
end
predict.log[epoch_now] = current
--- /dev/null
+#!/bin/sh -e
+
+if [ "$2" != types ] && [ "$2" != functions ]; then
+ echo "Usage: $0 libkres (types|functions)" >&2
+ echo " and input identifiers, one per line." >&2
+ echo " You need debug symbols in the library." >&2
+ exit 1
+fi
+
+if type -P gdb >/dev/null; then :; else
+ echo "Failed to find gdb" >&2
+ exit 1
+fi
+
+library="$(PATH="$(pwd)/lib:$(pkg-config libknot --variable=libdir)" type -P "$1.so")"
+if [ -z "$library" ]; then
+ echo "$1 not found. Note: only .so platforms work currently." >&2
+ exit 1
+fi
+
+GDB="gdb -quiet -symbols=$library"
+
+grep -v '^#\|^$' | while read ident; do
+ output="$(
+ if [ "$2" == functions ]; then
+ $GDB --ex "info functions ^$ident\$" --ex quit \
+ | sed '1,/^All functions/ d; /^File .*:$/ d'
+ continue
+ fi
+ # else types
+ case "$ident" in
+ struct\ *|union\ *|enum\ *)
+ $GDB --ex "ptype $ident" --ex quit \
+ | sed '1d; 2s/type = /\n/'
+ echo ";"
+ ;;
+ *)
+ $GDB --ex "info types ^$ident\$" --ex quit \
+ | sed -e '1,/^File .*:$/ d' -e '/^File .*:$/,$ d'
+ # we need to stop early to remove ^^ multiple matches
+ ;;
+ esac
+ )"
+ # abort on empty output
+ if [ -z "$(echo "$output" | tr -d \n)" ]; then
+ echo "Failed to find cdef of $ident" >&2
+ exit 1
+ fi
+ echo "$output" | grep -v '^$'
+done
+
local section = pkt:rrsets(kres.section.ANSWER)
for i = 1, #section do
local rr = section[i]
- for k = 1, rr.rr.count do
+ for k = 1, rr.rrs.rr_count do
local rdata = rr:tostring(k - 1)
local owner = kres.dname2str(rr:owner())
if qverbose then