kres-gen.lua 9.61 KB
Newer Older
1
local ffi = require('ffi')
2 3 4 5
--[[ 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;
6 7
typedef void knot_db_t;
struct kr_cdb_api {};
8
struct lru {};
9 10 11 12 13 14 15

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);
16
typedef void (*trace_log_f) (const struct kr_query *, const char *, const char *);
17
typedef void (*trace_callback_f)(struct kr_request *);
18 19
typedef enum {KNOT_ANSWER, KNOT_AUTHORITY, KNOT_ADDITIONAL} knot_section_t;
typedef struct {
20 21 22
	uint16_t pos;
	uint16_t flags;
	uint16_t compress_ptr[16];
23 24
} knot_rrinfo_t;
typedef unsigned char knot_dname_t;
25 26 27 28 29
typedef struct {
	uint16_t len;
	uint8_t data[];
} knot_rdata_t;
typedef struct {
30 31
	uint16_t count;
	knot_rdata_t *rdata;
32 33 34 35 36 37 38 39 40 41
} knot_rdataset_t;
typedef struct {
	knot_dname_t *_owner;
	uint32_t _ttl;
	uint16_t type;
	uint16_t rclass;
	knot_rdataset_t rrs;
	void *additional;
} knot_rrset_t;
typedef struct knot_pkt knot_pkt_t;
42
typedef struct {
43 44 45 46
	uint8_t *ptr[15];
} knot_edns_options_t;
typedef struct {
	knot_pkt_t *pkt;
47 48
	uint16_t pos;
	uint16_t count;
49
} knot_pktsection_t;
50 51 52 53 54 55 56 57 58
struct knot_compr {
	uint8_t *wire;
	knot_rrinfo_t *rrinfo;
	struct {
		uint16_t pos;
		uint8_t labels;
	} suffix;
};
typedef struct knot_compr knot_compr_t;
59
struct knot_pkt {
60 61 62 63 64 65 66 67 68 69
	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;
70
	knot_edns_options_t *edns_opts;
71 72 73 74 75 76 77 78 79 80
	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;
81
	knot_compr_t compr;
82
};
83
typedef struct {
84
	void *root;
85
	struct knot_mm *pool;
86
} map_t;
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
struct kr_qflags {
	_Bool NO_MINIMIZE : 1;
	_Bool NO_THROTTLE : 1;
	_Bool NO_IPV6 : 1;
	_Bool NO_IPV4 : 1;
	_Bool TCP : 1;
	_Bool RESOLVED : 1;
	_Bool AWAIT_IPV4 : 1;
	_Bool AWAIT_IPV6 : 1;
	_Bool AWAIT_CUT : 1;
	_Bool SAFEMODE : 1;
	_Bool CACHED : 1;
	_Bool NO_CACHE : 1;
	_Bool EXPIRING : 1;
	_Bool ALLOW_LOCAL : 1;
	_Bool DNSSEC_WANT : 1;
	_Bool DNSSEC_BOGUS : 1;
	_Bool DNSSEC_INSECURE : 1;
105
	_Bool DNSSEC_CD : 1;
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
	_Bool STUB : 1;
	_Bool ALWAYS_CUT : 1;
	_Bool DNSSEC_WEXPAND : 1;
	_Bool PERMISSIVE : 1;
	_Bool STRICT : 1;
	_Bool BADCOOKIE_AGAIN : 1;
	_Bool CNAME : 1;
	_Bool REORDER_RR : 1;
	_Bool TRACE : 1;
	_Bool NO_0X20 : 1;
	_Bool DNSSEC_NODS : 1;
	_Bool DNSSEC_OPTOUT : 1;
	_Bool NONAUTH : 1;
	_Bool FORWARD : 1;
	_Bool DNS64_MARK : 1;
Vladimír Čunát's avatar
Vladimír Čunát committed
121
	_Bool CACHE_TRIED : 1;
122
	_Bool NO_NS_FOUND : 1;
123
};
124
typedef struct {
125 126 127
	knot_rrset_t **at;
	size_t len;
	size_t cap;
128
} rr_array_t;
Grigorii Demidov's avatar
Grigorii Demidov committed
129
struct ranked_rr_array_entry {
130 131 132
	uint32_t qry_uid;
	uint8_t rank;
	uint8_t revalidation_cnt;
133 134 135 136
	_Bool cached : 1;
	_Bool yielded : 1;
	_Bool to_wire : 1;
	_Bool expiring : 1;
137
	knot_rrset_t *rr;
Grigorii Demidov's avatar
Grigorii Demidov committed
138 139 140
};
typedef struct ranked_rr_array_entry ranked_rr_array_entry_t;
typedef struct {
141 142 143
	ranked_rr_array_entry_t **at;
	size_t len;
	size_t cap;
Grigorii Demidov's avatar
Grigorii Demidov committed
144
} ranked_rr_array_t;
145
typedef struct trie trie_t;
146
struct kr_zonecut {
147 148 149 150
	knot_dname_t *name;
	knot_rrset_t *key;
	knot_rrset_t *trust_anchor;
	struct kr_zonecut *parent;
151
	trie_t *nsset;
152
	knot_mm_t *pool;
153
};
154
typedef struct {
155 156 157
	struct kr_query **at;
	size_t len;
	size_t cap;
158 159
} kr_qarray_t;
struct kr_rplan {
160 161 162 163 164
	kr_qarray_t pending;
	kr_qarray_t resolved;
	struct kr_request *request;
	knot_mm_t *pool;
	uint32_t next_uid;
165
};
166
struct kr_request {
167 168 169 170 171 172 173 174 175
	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;
Vladimír Čunát's avatar
Vladimír Čunát committed
176
		_Bool tcp;
177
		size_t size;
178 179 180 181 182
	} qsource;
	struct {
		unsigned int rtt;
		const struct sockaddr *addr;
	} upstream;
183
	struct kr_qflags options;
184 185 186
	int state;
	ranked_rr_array_t answ_selected;
	ranked_rr_array_t auth_selected;
187
	ranked_rr_array_t add_selected;
188 189 190
	rr_array_t additional;
	_Bool answ_validated;
	_Bool auth_validated;
191
	uint8_t rank;
192 193
	struct kr_rplan rplan;
	int has_tls;
194
	trace_log_f trace_log;
195
	trace_callback_f trace_finish;
196
	int vars_ref;
197
	knot_mm_t pool;
198
};
199
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};
Vladimír Čunát's avatar
Vladimír Čunát committed
200
struct kr_cache {
201 202 203 204 205 206 207 208
	knot_db_t *db;
	const struct kr_cdb_api *api;
	struct {
		uint32_t hit;
		uint32_t miss;
		uint32_t insert;
		uint32_t delete;
	} stats;
Vladimír Čunát's avatar
Vladimír Čunát committed
209 210
	uint32_t ttl_min;
	uint32_t ttl_max;
211 212
	struct timeval checkpoint_walltime;
	uint64_t checkpoint_monotime;
213
};
Vladimír Čunát's avatar
Vladimír Čunát committed
214 215 216

typedef int32_t (*kr_stale_cb)(int32_t ttl, const knot_dname_t *owner, uint16_t type,
				const struct kr_query *qry);
217 218 219

void kr_rrset_init(knot_rrset_t *rrset, knot_dname_t *owner,
			uint16_t type, uint16_t rclass, uint32_t ttl);
220
struct kr_nsrep {
221 222 223 224
	unsigned int score;
	unsigned int reputation;
	const knot_dname_t *name;
	struct kr_context *ctx;
225
	/* beware: hidden stub, to avoid hardcoding sockaddr lengths */
226
};
227
struct kr_query {
228 229 230 231 232
	struct kr_query *parent;
	knot_dname_t *sname;
	uint16_t stype;
	uint16_t sclass;
	uint16_t id;
233 234
	struct kr_qflags flags;
	struct kr_qflags forward_flags;
235 236 237
	uint32_t secret;
	uint16_t fails;
	uint16_t reorder;
Vitezslav Kriz's avatar
Vitezslav Kriz committed
238 239
	uint64_t creation_time_mono;
	uint64_t timestamp_mono;
240 241
	struct timeval timestamp;
	struct kr_zonecut zone_cut;
242 243
	struct kr_layer_pickle *deferred;
	uint32_t uid;
244
	struct kr_query *cname_parent;
245
	struct kr_request *request;
Vladimír Čunát's avatar
Vladimír Čunát committed
246
	kr_stale_cb stale_cb;
247
	struct kr_nsrep ns;
248 249
};
struct kr_context {
250
	struct kr_qflags options;
251 252 253 254
	knot_rrset_t *opt_rr;
	map_t trust_anchors;
	map_t negative_anchors;
	struct kr_zonecut root_hints;
255
	struct kr_cache cache;
256 257
	char _stub[];
};
Vladimír Čunát's avatar
Vladimír Čunát committed
258
const char *knot_strerror(int);
259
knot_dname_t *knot_dname_copy(const knot_dname_t *, knot_mm_t *);
260
knot_dname_t *knot_dname_from_str(uint8_t *, const char *, size_t);
261 262
_Bool knot_dname_is_equal(const knot_dname_t *, const knot_dname_t *);
_Bool knot_dname_is_sub(const knot_dname_t *, const knot_dname_t *);
263 264
size_t knot_dname_labels(const uint8_t *, const uint8_t *);
size_t knot_dname_size(const knot_dname_t *);
265
char *knot_dname_to_str(char *, const knot_dname_t *, size_t);
266
knot_rdata_t *knot_rdataset_at(const knot_rdataset_t *, uint16_t);
267
int knot_rdataset_merge(knot_rdataset_t *, const knot_rdataset_t *, knot_mm_t *);
268
int knot_rrset_add_rdata(knot_rrset_t *, const uint8_t *, uint16_t, knot_mm_t *);
269
int knot_rrset_txt_dump(const knot_rrset_t *, char **, size_t *, const knot_dump_style_t *);
270
int knot_rrset_txt_dump_data(const knot_rrset_t *, const size_t, char *, const size_t, const knot_dump_style_t *);
271
size_t knot_rrset_size(const knot_rrset_t *);
272 273
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);
274
int knot_pkt_put_rotate(knot_pkt_t *, uint16_t, const knot_rrset_t *, uint16_t, uint16_t);
Vladimír Čunát's avatar
Vladimír Čunát committed
275
knot_pkt_t *knot_pkt_new(void *, uint16_t, knot_mm_t *);
276
void knot_pkt_free(knot_pkt_t *);
Vladimír Čunát's avatar
Vladimír Čunát committed
277
int knot_pkt_parse(knot_pkt_t *, unsigned int);
278 279 280 281 282
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 *);
283
struct kr_query *kr_rplan_last(struct kr_rplan *);
284
int kr_nsrep_set(struct kr_query *, size_t, const struct sockaddr *);
Vladimír Čunát's avatar
Vladimír Čunát committed
285
uint32_t kr_rand_uint(uint32_t);
286
int kr_make_query(struct kr_query *, knot_pkt_t *);
287
void kr_pkt_make_auth_header(knot_pkt_t *);
288 289
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 *);
290
int kr_pkt_clear_payload(knot_pkt_t *);
291 292
uint16_t kr_pkt_qclass(const knot_pkt_t *);
uint16_t kr_pkt_qtype(const knot_pkt_t *);
293 294
uint32_t kr_rrsig_sig_inception(const knot_rdata_t *);
uint32_t kr_rrsig_sig_expiration(const knot_rdata_t *);
295 296 297
const char *kr_inaddr(const struct sockaddr *);
int kr_inaddr_family(const struct sockaddr *);
int kr_inaddr_len(const struct sockaddr *);
298
int kr_inaddr_str(const struct sockaddr *, char *, size_t *);
299
int kr_sockaddr_len(const struct sockaddr *);
300
uint16_t kr_inaddr_port(const struct sockaddr *);
301 302 303 304
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);
305
struct sockaddr *kr_straddr_socket(const char *, int);
306
int kr_ranked_rrarray_add(ranked_rr_array_t *, const knot_rrset_t *, uint8_t, _Bool, uint32_t, knot_mm_t *);
307 308
void kr_qflags_set(struct kr_qflags *, struct kr_qflags);
void kr_qflags_clear(struct kr_qflags *, struct kr_qflags);
309
int kr_zonecut_add(struct kr_zonecut *, const knot_dname_t *, const knot_rdata_t *);
310
_Bool kr_zonecut_is_empty(struct kr_zonecut *);
311
void kr_zonecut_set(struct kr_zonecut *, const knot_dname_t *);
312
uint64_t kr_now();
313 314
void lru_free_items_impl(struct lru *);
struct lru *lru_create_impl(unsigned int, knot_mm_t *, knot_mm_t *);
315
void *lru_get_impl(struct lru *, const char *, unsigned int, unsigned int, _Bool, _Bool *);
316 317 318 319 320 321 322 323
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);
324 325
int kr_cache_insert_rr(struct kr_cache *, const knot_rrset_t *, const knot_rrset_t *, uint8_t, uint32_t);
int kr_cache_sync(struct kr_cache *);
326
]]