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