1 /* 2 * util/data/msgreply.h - store message and reply data. 3 * 4 * Copyright (c) 2007, NLnet Labs. All rights reserved. 5 * 6 * This software is open source. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 12 * Redistributions of source code must retain the above copyright notice, 13 * this list of conditions and the following disclaimer. 14 * 15 * Redistributions in binary form must reproduce the above copyright notice, 16 * this list of conditions and the following disclaimer in the documentation 17 * and/or other materials provided with the distribution. 18 * 19 * Neither the name of the NLNET LABS nor the names of its contributors may 20 * be used to endorse or promote products derived from this software without 21 * specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 29 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 */ 35 36 /** 37 * \file 38 * 39 * This file contains a data structure to store a message and its reply. 40 */ 41 42 #ifndef UTIL_DATA_MSGREPLY_H 43 #define UTIL_DATA_MSGREPLY_H 44 #include "util/storage/lruhash.h" 45 #include "util/data/packed_rrset.h" 46 struct sldns_buffer; 47 struct comm_reply; 48 struct alloc_cache; 49 struct iovec; 50 struct regional; 51 struct edns_data; 52 struct edns_option; 53 struct inplace_cb; 54 struct module_qstate; 55 struct module_env; 56 struct msg_parse; 57 struct rrset_parse; 58 struct local_rrset; 59 struct dns_msg; 60 61 /** calculate the prefetch TTL as 90% of original. Calculation 62 * without numerical overflow (uin32_t) */ 63 #define PREFETCH_TTL_CALC(ttl) ((ttl) - (ttl)/10) 64 65 /** 66 * Structure to store query information that makes answers to queries 67 * different. 68 */ 69 struct query_info { 70 /** 71 * Salient data on the query: qname, in wireformat. 72 * can be allocated or a pointer to outside buffer. 73 * User has to keep track on the status of this. 74 */ 75 uint8_t* qname; 76 /** length of qname (including last 0 octet) */ 77 size_t qname_len; 78 /** qtype, host byte order */ 79 uint16_t qtype; 80 /** qclass, host byte order */ 81 uint16_t qclass; 82 /** 83 * Alias local answer(s) for the qname. If 'qname' is an alias defined 84 * in a local zone, this field will be set to the corresponding local 85 * RRset when the alias is determined. 86 * In the initial implementation this can only be a single CNAME RR 87 * (or NULL), but it could possibly be extended to be a DNAME or a 88 * chain of aliases. 89 * Users of this structure are responsible to initialize this field 90 * to be NULL; otherwise other part of query handling code may be 91 * confused. 92 * Users also have to be careful about the lifetime of data. On return 93 * from local zone lookup, it may point to data derived from 94 * configuration that may be dynamically invalidated or data allocated 95 * in an ephemeral regional allocator. A deep copy of the data may 96 * have to be generated if it has to be kept during iterative 97 * resolution. */ 98 struct local_rrset* local_alias; 99 }; 100 101 /** 102 * Information to reference an rrset 103 */ 104 struct rrset_ref { 105 /** the key with lock, and ptr to packed data. */ 106 struct ub_packed_rrset_key* key; 107 /** id needed */ 108 rrset_id_type id; 109 }; 110 111 /** 112 * Structure to store DNS query and the reply packet. 113 * To use it, copy over the flags from reply and modify using flags from 114 * the query (RD,CD if not AA). prepend ID. 115 * 116 * Memory layout is: 117 * o struct 118 * o rrset_ref array 119 * o packed_rrset_key* array. 120 * 121 * Memory layout is sometimes not packed, when the message is synthesized, 122 * for easy of the generation. It is allocated packed when it is copied 123 * from the region allocation to the malloc allocation. 124 */ 125 struct reply_info { 126 /** the flags for the answer, host byte order. */ 127 uint16_t flags; 128 129 /** 130 * This flag informs unbound the answer is authoritative and 131 * the AA flag should be preserved. 132 */ 133 uint8_t authoritative; 134 135 /** 136 * Number of RRs in the query section. 137 * If qdcount is not 0, then it is 1, and the data that appears 138 * in the reply is the same as the query_info. 139 * Host byte order. 140 */ 141 uint8_t qdcount; 142 143 /** 32 bit padding to pad struct member alignment to 64 bits. */ 144 uint32_t padding; 145 146 /** 147 * TTL of the entire reply (for negative caching). 148 * only for use when there are 0 RRsets in this message. 149 * if there are RRsets, check those instead. 150 */ 151 time_t ttl; 152 153 /** 154 * TTL for prefetch. After it has expired, a prefetch is suitable. 155 * Smaller than the TTL, otherwise the prefetch would not happen. 156 */ 157 time_t prefetch_ttl; 158 159 /** 160 * Reply TTL extended with serve expired TTL, to limit time to serve 161 * expired message. 162 */ 163 time_t serve_expired_ttl; 164 165 /** 166 * The security status from DNSSEC validation of this message. 167 */ 168 enum sec_status security; 169 170 /** 171 * Number of RRsets in each section. 172 * The answer section. Add up the RRs in every RRset to calculate 173 * the number of RRs, and the count for the dns packet. 174 * The number of RRs in RRsets can change due to RRset updates. 175 */ 176 size_t an_numrrsets; 177 178 /** Count of authority section RRsets */ 179 size_t ns_numrrsets; 180 /** Count of additional section RRsets */ 181 size_t ar_numrrsets; 182 183 /** number of RRsets: an_numrrsets + ns_numrrsets + ar_numrrsets */ 184 size_t rrset_count; 185 186 /** 187 * List of pointers (only) to the rrsets in the order in which 188 * they appear in the reply message. 189 * Number of elements is ancount+nscount+arcount RRsets. 190 * This is a pointer to that array. 191 * Use the accessor function for access. 192 */ 193 struct ub_packed_rrset_key** rrsets; 194 195 /** 196 * Packed array of ids (see counts) and pointers to packed_rrset_key. 197 * The number equals ancount+nscount+arcount RRsets. 198 * These are sorted in ascending pointer, the locking order. So 199 * this list can be locked (and id, ttl checked), to see if 200 * all the data is available and recent enough. 201 * 202 * This is defined as an array of size 1, so that the compiler 203 * associates the identifier with this position in the structure. 204 * Array bound overflow on this array then gives access to the further 205 * elements of the array, which are allocated after the main structure. 206 * 207 * It could be more pure to define as array of size 0, ref[0]. 208 * But ref[1] may be less confusing for compilers. 209 * Use the accessor function for access. 210 */ 211 struct rrset_ref ref[1]; 212 }; 213 214 /** 215 * Structure to keep hash table entry for message replies. 216 */ 217 struct msgreply_entry { 218 /** the hash table key */ 219 struct query_info key; 220 /** the hash table entry, data is struct reply_info* */ 221 struct lruhash_entry entry; 222 }; 223 224 /** 225 * Constructor for replyinfo. 226 * @param region: where to allocate the results, pass NULL to use malloc. 227 * @param flags: flags for the replyinfo. 228 * @param qd: qd count 229 * @param ttl: TTL of replyinfo 230 * @param prettl: prefetch ttl 231 * @param expttl: serve expired ttl 232 * @param an: an count 233 * @param ns: ns count 234 * @param ar: ar count 235 * @param total: total rrset count (presumably an+ns+ar). 236 * @param sec: security status of the reply info. 237 * @return the reply_info base struct with the array for putting the rrsets 238 * in. The array has been zeroed. Returns NULL on malloc failure. 239 */ 240 struct reply_info* 241 construct_reply_info_base(struct regional* region, uint16_t flags, size_t qd, 242 time_t ttl, time_t prettl, time_t expttl, size_t an, size_t ns, 243 size_t ar, size_t total, enum sec_status sec); 244 245 /** 246 * Parse wire query into a queryinfo structure, return 0 on parse error. 247 * initialises the (prealloced) queryinfo structure as well. 248 * This query structure contains a pointer back info the buffer! 249 * This pointer avoids memory allocation. allocqname does memory allocation. 250 * @param m: the prealloced queryinfo structure to put query into. 251 * must be unused, or _clear()ed. 252 * @param query: the wireformat packet query. starts with ID. 253 * @return: 0 on format error. 254 */ 255 int query_info_parse(struct query_info* m, struct sldns_buffer* query); 256 257 /** 258 * Parse query reply. 259 * Fills in preallocated query_info structure (with ptr into buffer). 260 * Allocates reply_info and packed_rrsets. These are not yet added to any 261 * caches or anything, this is only parsing. Returns formerror on qdcount > 1. 262 * @param pkt: the packet buffer. Must be positioned after the query section. 263 * @param alloc: creates packed rrset key structures. 264 * @param rep: allocated reply_info is returned (only on no error). 265 * @param qinf: query_info is returned (only on no error). 266 * @param region: where to store temporary data (for parsing). 267 * @param edns: where to store edns information, does not need to be inited. 268 * @return: zero is OK, or DNS error code in case of error 269 * o FORMERR for parse errors. 270 * o SERVFAIL for memory allocation errors. 271 */ 272 int reply_info_parse(struct sldns_buffer* pkt, struct alloc_cache* alloc, 273 struct query_info* qinf, struct reply_info** rep, 274 struct regional* region, struct edns_data* edns); 275 276 /** 277 * Allocate and decompress parsed message and rrsets. 278 * @param pkt: for name decompression. 279 * @param msg: parsed message in scratch region. 280 * @param alloc: alloc cache for special rrset key structures. 281 * Not used if region!=NULL, it can be NULL in that case. 282 * @param qinf: where to store query info. 283 * qinf itself is allocated by the caller. 284 * @param rep: reply info is allocated and returned. 285 * @param region: if this parameter is NULL then malloc and the alloc is used. 286 * otherwise, everything is allocated in this region. 287 * In a region, no special rrset key structures are needed (not shared), 288 * and no rrset_ref array in the reply is built up. 289 * @return 0 if allocation failed. 290 */ 291 int parse_create_msg(struct sldns_buffer* pkt, struct msg_parse* msg, 292 struct alloc_cache* alloc, struct query_info* qinf, 293 struct reply_info** rep, struct regional* region); 294 295 /** get msg reply struct (in temp region) */ 296 struct reply_info* parse_reply_in_temp_region(struct sldns_buffer* pkt, 297 struct regional* region, struct query_info* qi); 298 299 /** 300 * Sorts the ref array. 301 * @param rep: reply info. rrsets must be filled in. 302 */ 303 void reply_info_sortref(struct reply_info* rep); 304 305 /** 306 * Set TTLs inside the replyinfo to absolute values. 307 * @param rep: reply info. rrsets must be filled in. 308 * Also refs must be filled in. 309 * @param timenow: the current time. 310 */ 311 void reply_info_set_ttls(struct reply_info* rep, time_t timenow); 312 313 /** 314 * Delete reply_info and packed_rrsets (while they are not yet added to the 315 * hashtables.). Returns rrsets to the alloc cache. 316 * @param rep: reply_info to delete. 317 * @param alloc: where to return rrset structures to. 318 */ 319 void reply_info_parsedelete(struct reply_info* rep, struct alloc_cache* alloc); 320 321 /** 322 * Compare two queryinfo structures, on query and type, class. 323 * It is _not_ sorted in canonical ordering. 324 * @param m1: struct query_info* , void* here to ease use as function pointer. 325 * @param m2: struct query_info* , void* here to ease use as function pointer. 326 * @return: 0 = same, -1 m1 is smaller, +1 m1 is larger. 327 */ 328 int query_info_compare(void* m1, void* m2); 329 330 /** clear out query info structure */ 331 void query_info_clear(struct query_info* m); 332 333 /** calculate size of struct query_info + reply_info */ 334 size_t msgreply_sizefunc(void* k, void* d); 335 336 /** delete msgreply_entry key structure */ 337 void query_entry_delete(void *q, void* arg); 338 339 /** delete reply_info data structure */ 340 void reply_info_delete(void* d, void* arg); 341 342 /** calculate hash value of query_info, lowercases the qname, 343 * uses CD flag for AAAA qtype */ 344 hashvalue_type query_info_hash(struct query_info *q, uint16_t flags); 345 346 /** 347 * Setup query info entry 348 * @param q: query info to copy. Emptied as if clear is called. 349 * @param r: reply to init data. 350 * @param h: hash value. 351 * @return: newly allocated message reply cache item. 352 */ 353 struct msgreply_entry* query_info_entrysetup(struct query_info* q, 354 struct reply_info* r, hashvalue_type h); 355 356 /** 357 * Copy reply_info and all rrsets in it and allocate. 358 * @param rep: what to copy, probably inside region, no ref[] array in it. 359 * @param alloc: how to allocate rrset keys. 360 * Not used if region!=NULL, it can be NULL in that case. 361 * @param region: if this parameter is NULL then malloc and the alloc is used. 362 * otherwise, everything is allocated in this region. 363 * In a region, no special rrset key structures are needed (not shared), 364 * and no rrset_ref array in the reply is built up. 365 * @return new reply info or NULL on memory error. 366 */ 367 struct reply_info* reply_info_copy(struct reply_info* rep, 368 struct alloc_cache* alloc, struct regional* region); 369 370 /** 371 * Allocate (special) rrset keys. 372 * @param rep: reply info in which the rrset keys to be allocated, rrset[] 373 * array should have bee allocated with NULL pointers. 374 * @param alloc: how to allocate rrset keys. 375 * Not used if region!=NULL, it can be NULL in that case. 376 * @param region: if this parameter is NULL then the alloc is used. 377 * otherwise, rrset keys are allocated in this region. 378 * In a region, no special rrset key structures are needed (not shared). 379 * and no rrset_ref array in the reply needs to be built up. 380 * @return 1 on success, 0 on error 381 */ 382 int reply_info_alloc_rrset_keys(struct reply_info* rep, 383 struct alloc_cache* alloc, struct regional* region); 384 385 /** 386 * Copy a parsed rrset into given key, decompressing and allocating rdata. 387 * @param pkt: packet for decompression 388 * @param msg: the parser message (for flags for trust). 389 * @param pset: the parsed rrset to copy. 390 * @param region: if NULL - malloc, else data is allocated in this region. 391 * @param pk: a freshly obtained rrsetkey structure. No dname is set yet, 392 * will be set on return. 393 * Note that TTL will still be relative on return. 394 * @return false on alloc failure. 395 */ 396 int parse_copy_decompress_rrset(struct sldns_buffer* pkt, struct msg_parse* msg, 397 struct rrset_parse *pset, struct regional* region, 398 struct ub_packed_rrset_key* pk); 399 400 /** 401 * Find final cname target in reply, the one matching qinfo. Follows CNAMEs. 402 * @param qinfo: what to start with. 403 * @param rep: looks in answer section of this message. 404 * @return: pointer dname, or NULL if not found. 405 */ 406 uint8_t* reply_find_final_cname_target(struct query_info* qinfo, 407 struct reply_info* rep); 408 409 /** 410 * Check if cname chain in cached reply is still valid. 411 * @param qinfo: query info with query name. 412 * @param rep: reply to check. 413 * @return: true if valid, false if invalid. 414 */ 415 int reply_check_cname_chain(struct query_info* qinfo, struct reply_info* rep); 416 417 /** 418 * Check security status of all RRs in the message. 419 * @param rep: reply to check 420 * @return: true if all RRs are secure. False if not. 421 * True if there are zero RRs. 422 */ 423 int reply_all_rrsets_secure(struct reply_info* rep); 424 425 /** 426 * Find answer rrset in reply, the one matching qinfo. Follows CNAMEs, so the 427 * result may have a different owner name. 428 * @param qinfo: what to look for. 429 * @param rep: looks in answer section of this message. 430 * @return: pointer to rrset, or NULL if not found. 431 */ 432 struct ub_packed_rrset_key* reply_find_answer_rrset(struct query_info* qinfo, 433 struct reply_info* rep); 434 435 /** 436 * Find rrset in reply, inside the answer section. Does not follow CNAMEs. 437 * @param rep: looks in answer section of this message. 438 * @param name: what to look for. 439 * @param namelen: length of name. 440 * @param type: looks for (host order). 441 * @param dclass: looks for (host order). 442 * @return: pointer to rrset, or NULL if not found. 443 */ 444 struct ub_packed_rrset_key* reply_find_rrset_section_an(struct reply_info* rep, 445 uint8_t* name, size_t namelen, uint16_t type, uint16_t dclass); 446 447 /** 448 * Find rrset in reply, inside the authority section. Does not follow CNAMEs. 449 * @param rep: looks in authority section of this message. 450 * @param name: what to look for. 451 * @param namelen: length of name. 452 * @param type: looks for (host order). 453 * @param dclass: looks for (host order). 454 * @return: pointer to rrset, or NULL if not found. 455 */ 456 struct ub_packed_rrset_key* reply_find_rrset_section_ns(struct reply_info* rep, 457 uint8_t* name, size_t namelen, uint16_t type, uint16_t dclass); 458 459 /** 460 * Find rrset in reply, inside any section. Does not follow CNAMEs. 461 * @param rep: looks in answer,authority and additional section of this message. 462 * @param name: what to look for. 463 * @param namelen: length of name. 464 * @param type: looks for (host order). 465 * @param dclass: looks for (host order). 466 * @return: pointer to rrset, or NULL if not found. 467 */ 468 struct ub_packed_rrset_key* reply_find_rrset(struct reply_info* rep, 469 uint8_t* name, size_t namelen, uint16_t type, uint16_t dclass); 470 471 /** 472 * Debug send the query info and reply info to the log in readable form. 473 * @param str: descriptive string printed with packet content. 474 * @param qinfo: query section. 475 * @param rep: rest of message. 476 */ 477 void log_dns_msg(const char* str, struct query_info* qinfo, 478 struct reply_info* rep); 479 480 /** 481 * Print string with neat domain name, type, class, 482 * status code from, and size of a query response. 483 * 484 * @param v: at what verbosity level to print this. 485 * @param qinf: query section. 486 * @param addr: address of the client. 487 * @param addrlen: length of the client address. 488 * @param dur: how long it took to complete the query. 489 * @param cached: whether or not the reply is coming from 490 * the cache, or an outside network. 491 * @param rmsg: sldns buffer packet. 492 */ 493 void log_reply_info(enum verbosity_value v, struct query_info *qinf, 494 struct sockaddr_storage *addr, socklen_t addrlen, struct timeval dur, 495 int cached, struct sldns_buffer *rmsg); 496 497 /** 498 * Print string with neat domain name, type, class from query info. 499 * @param v: at what verbosity level to print this. 500 * @param str: string of message. 501 * @param qinf: query info structure with name, type and class. 502 */ 503 void log_query_info(enum verbosity_value v, const char* str, 504 struct query_info* qinf); 505 506 /** 507 * Append edns option to edns data structure 508 * @param edns: the edns data structure to append the edns option to. 509 * @param region: region to allocate the new edns option. 510 * @param code: the edns option's code. 511 * @param len: the edns option's length. 512 * @param data: the edns option's data. 513 * @return false on failure. 514 */ 515 int edns_opt_append(struct edns_data* edns, struct regional* region, 516 uint16_t code, size_t len, uint8_t* data); 517 518 /** 519 * Append edns option to edns option list 520 * @param list: the edns option list to append the edns option to. 521 * @param code: the edns option's code. 522 * @param len: the edns option's length. 523 * @param data: the edns option's data. 524 * @param region: region to allocate the new edns option. 525 * @return false on failure. 526 */ 527 int edns_opt_list_append(struct edns_option** list, uint16_t code, size_t len, 528 uint8_t* data, struct regional* region); 529 530 /** 531 * Remove any option found on the edns option list that matches the code. 532 * @param list: the list of edns options. 533 * @param code: the opt code to remove. 534 * @return true when at least one edns option was removed, false otherwise. 535 */ 536 int edns_opt_list_remove(struct edns_option** list, uint16_t code); 537 538 /** 539 * Find edns option in edns list 540 * @param list: list of edns options (eg. edns.opt_list) 541 * @param code: opt code to find. 542 * @return NULL or the edns_option element. 543 */ 544 struct edns_option* edns_opt_list_find(struct edns_option* list, uint16_t code); 545 546 /** 547 * Call the registered functions in the inplace_cb_reply linked list. 548 * This function is going to get called while answering with a resolved query. 549 * @param env: module environment. 550 * @param qinfo: query info. 551 * @param qstate: module qstate. 552 * @param rep: Reply info. Could be NULL. 553 * @param rcode: return code. 554 * @param edns: edns data of the reply. 555 * @param repinfo: comm_reply. NULL. 556 * @param region: region to store data. 557 * @return false on failure (a callback function returned an error). 558 */ 559 int inplace_cb_reply_call(struct module_env* env, struct query_info* qinfo, 560 struct module_qstate* qstate, struct reply_info* rep, int rcode, 561 struct edns_data* edns, struct comm_reply* repinfo, struct regional* region); 562 563 /** 564 * Call the registered functions in the inplace_cb_reply_cache linked list. 565 * This function is going to get called while answering from cache. 566 * @param env: module environment. 567 * @param qinfo: query info. 568 * @param qstate: module qstate. NULL when replying from cache. 569 * @param rep: Reply info. 570 * @param rcode: return code. 571 * @param edns: edns data of the reply. Edns input can be found here. 572 * @param repinfo: comm_reply. Reply information for a communication point. 573 * @param region: region to store data. 574 * @return false on failure (a callback function returned an error). 575 */ 576 int inplace_cb_reply_cache_call(struct module_env* env, 577 struct query_info* qinfo, struct module_qstate* qstate, 578 struct reply_info* rep, int rcode, struct edns_data* edns, 579 struct comm_reply* repinfo, struct regional* region); 580 581 /** 582 * Call the registered functions in the inplace_cb_reply_local linked list. 583 * This function is going to get called while answering with local data. 584 * @param env: module environment. 585 * @param qinfo: query info. 586 * @param qstate: module qstate. NULL when replying from cache. 587 * @param rep: Reply info. 588 * @param rcode: return code. 589 * @param edns: edns data of the reply. Edns input can be found here. 590 * @param repinfo: comm_reply. Reply information for a communication point. 591 * @param region: region to store data. 592 * @return false on failure (a callback function returned an error). 593 */ 594 int inplace_cb_reply_local_call(struct module_env* env, 595 struct query_info* qinfo, struct module_qstate* qstate, 596 struct reply_info* rep, int rcode, struct edns_data* edns, 597 struct comm_reply* repinfo, struct regional* region); 598 599 /** 600 * Call the registered functions in the inplace_cb_reply linked list. 601 * This function is going to get called while answering with a servfail. 602 * @param env: module environment. 603 * @param qinfo: query info. 604 * @param qstate: module qstate. Contains the edns option lists. Could be NULL. 605 * @param rep: Reply info. NULL when servfail. 606 * @param rcode: return code. LDNS_RCODE_SERVFAIL. 607 * @param edns: edns data of the reply. Edns input can be found here if qstate 608 * is NULL. 609 * @param repinfo: comm_reply. Reply information for a communication point. 610 * @param region: region to store data. 611 * @return false on failure (a callback function returned an error). 612 */ 613 int inplace_cb_reply_servfail_call(struct module_env* env, 614 struct query_info* qinfo, struct module_qstate* qstate, 615 struct reply_info* rep, int rcode, struct edns_data* edns, 616 struct comm_reply* repinfo, struct regional* region); 617 618 /** 619 * Call the registered functions in the inplace_cb_query linked list. 620 * This function is going to get called just before sending a query to a 621 * nameserver. 622 * @param env: module environment. 623 * @param qinfo: query info. 624 * @param flags: flags of the query. 625 * @param addr: to which server to send the query. 626 * @param addrlen: length of addr. 627 * @param zone: name of the zone of the delegation point. wireformat dname. 628 * This is the delegation point name for which the server is deemed 629 * authoritative. 630 * @param zonelen: length of zone. 631 * @param qstate: module qstate. 632 * @param region: region to store data. 633 * @return false on failure (a callback function returned an error). 634 */ 635 int inplace_cb_query_call(struct module_env* env, struct query_info* qinfo, 636 uint16_t flags, struct sockaddr_storage* addr, socklen_t addrlen, 637 uint8_t* zone, size_t zonelen, struct module_qstate* qstate, 638 struct regional* region); 639 640 /** 641 * Call the registered functions in the inplace_cb_edns_back_parsed linked list. 642 * This function is going to get called after parsing the EDNS data on the 643 * reply from a nameserver. 644 * @param env: module environment. 645 * @param qstate: module qstate. 646 * @return false on failure (a callback function returned an error). 647 */ 648 int inplace_cb_edns_back_parsed_call(struct module_env* env, 649 struct module_qstate* qstate); 650 651 /** 652 * Call the registered functions in the inplace_cb_query_response linked list. 653 * This function is going to get called after receiving a reply from a 654 * nameserver. 655 * @param env: module environment. 656 * @param qstate: module qstate. 657 * @param response: received response 658 * @return false on failure (a callback function returned an error). 659 */ 660 int inplace_cb_query_response_call(struct module_env* env, 661 struct module_qstate* qstate, struct dns_msg* response); 662 663 /** 664 * Copy edns option list allocated to the new region 665 */ 666 struct edns_option* edns_opt_copy_region(struct edns_option* list, 667 struct regional* region); 668 669 /** 670 * Copy edns option list allocated with malloc 671 */ 672 struct edns_option* edns_opt_copy_alloc(struct edns_option* list); 673 674 /** 675 * Free edns option list allocated with malloc 676 */ 677 void edns_opt_list_free(struct edns_option* list); 678 679 /** 680 * Compare an edns option. (not entire list). Also compares contents. 681 */ 682 int edns_opt_compare(struct edns_option* p, struct edns_option* q); 683 684 /** 685 * Compare edns option lists, also the order and contents of edns-options. 686 */ 687 int edns_opt_list_compare(struct edns_option* p, struct edns_option* q); 688 689 #endif /* UTIL_DATA_MSGREPLY_H */ 690