2 * util/module.h - DNS handling module interface
4 * Copyright (c) 2007, NLnet Labs. All rights reserved.
6 * This software is open source.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
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.
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.
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.
39 * This file contains the interface for DNS handling modules.
41 * The module interface uses the DNS modules as state machines. The
42 * state machines are activated in sequence to operate on queries. Once
43 * they are done, the reply is passed back. In the usual setup the mesh
44 * is the caller of the state machines and once things are done sends replies
45 * and invokes result callbacks.
47 * The module provides a number of functions, listed in the module_func_block.
48 * The module is inited and destroyed and memory usage queries, for the
49 * module as a whole, for entire-module state (such as a cache). And per-query
50 * functions are called, operate to move the state machine and cleanup of
51 * the per-query state.
53 * Most per-query state should simply be allocated in the query region.
54 * This is destroyed at the end of the query.
56 * The module environment contains services and information and caches
57 * shared by the modules and the rest of the system. It also contains
58 * function pointers for module-specific tasks (like sending queries).
60 * *** Example module calls for a normal query
62 * In this example, the query does not need recursion, all the other data
63 * can be found in the cache. This makes the example shorter.
65 * At the start of the program the iterator module is initialised.
66 * The iterator module sets up its global state, such as donotquery lists
67 * and private address trees.
69 * A query comes in, and a mesh entry is created for it. The mesh
70 * starts the resolution process. The validator module is the first
71 * in the list of modules, and it is started on this new query. The
72 * operate() function is called. The validator decides it needs not do
73 * anything yet until there is a result and returns wait_module, that
74 * causes the next module in the list to be started.
76 * The next module is the iterator. It is started on the passed query and
77 * decides to perform a lookup. For this simple example, the delegation
78 * point information is available, and all the iterator wants to do is
79 * send a UDP query. The iterator uses env.send_query() to send the
80 * query. Then the iterator suspends (returns from the operate call).
82 * When the UDP reply comes back (and on errors and timeouts), the
83 * operate function is called for the query, on the iterator module,
84 * with the event that there is a reply. The iterator decides that this
85 * is enough, the work is done. It returns the value finished from the
86 * operate call, which causes the previous module to be started.
88 * The previous module, the validator module, is started with the event
89 * that the iterator module is done. The validator decides to validate
90 * the query. Once it is done (which could take recursive lookups, but
91 * in this example no recursive lookups are needed), it returns from the
92 * operate function with finished.
94 * There is no previous module from the validator module, and the mesh
95 * takes this to mean that the query is finally done. The mesh invokes
96 * callbacks and sends packets to queriers.
98 * If other modules had been waiting (recursively) on the answer to this
99 * query, then the mesh will tell them about it. It calls the inform_super
100 * routine on all the waiting modules, and once that is done it calls all of
101 * them with the operate() call. During inform_super the query that is done
102 * still exists and information can be copied from it (but the module should
103 * not really re-entry codepoints and services). During the operate call
104 * the modules can use stored state to continue operation with the results.
105 * (network buffers are used to contain the answer packet during the
106 * inform_super phase, but after that the network buffers will be cleared
107 * of their contents so that other tasks can be performed).
109 * *** Example module calls for recursion
111 * A module is called in operate, and it decides that it wants to perform
112 * recursion. That is, it wants the full state-machine-list to operate on
113 * a different query. It calls env.attach_sub() to create a new query state.
114 * The routine returns the newly created state, and potentially the module
115 * can edit the module-states for the newly created query (i.e. pass along
116 * some information, like delegation points). The module then suspends,
117 * returns from the operate routine.
119 * The mesh meanwhile will have the newly created query (or queries) on
120 * a waiting list, and will call operate() on this query (or queries).
121 * It starts again at the start of the module list for them. The query
122 * (or queries) continue to operate their state machines, until they are
123 * done. When they are done the mesh calls inform_super on the module that
124 * wanted the recursion. After that the mesh calls operate() on the module
125 * that wanted to do the recursion, and during this phase the module could,
126 * for example, decide to create more recursions.
128 * If the module decides it no longer wants the recursive information
129 * it can call detach_subs. Those queries will still run to completion,
130 * potentially filling the cache with information. Inform_super is not
133 * The iterator module will fetch items from the cache, so a recursion
134 * attempt may complete very quickly if the item is in cache. The calling
135 * module has to wait for completion or eventual timeout. A recursive query
136 * that times out returns a servfail rcode (servfail is also returned for
137 * other errors during the lookup).
139 * Results are passed in the qstate, the rcode member is used to pass
140 * errors without requiring memory allocation, so that the code can continue
141 * in out-of-memory conditions. If the rcode member is 0 (NOERROR) then
142 * the dns_msg entry contains a filled out message. This message may
143 * also contain an rcode that is nonzero, but in this case additional
144 * information (query, additional) can be passed along.
146 * The rcode and dns_msg are used to pass the result from the the rightmost
147 * module towards the leftmost modules and then towards the user.
149 * If you want to avoid recursion-cycles where queries need other queries
150 * that need the first one, use detect_cycle() to see if that will happen.
154 #ifndef UTIL_MODULE_H
155 #define UTIL_MODULE_H
156 #include "util/storage/lruhash.h"
157 #include "util/data/msgreply.h"
158 #include "util/data/msgparse.h"
171 struct outside_network;
172 struct module_qstate;
177 struct val_neg_cache;
178 struct iter_forwards;
181 struct respip_client_info;
182 struct respip_addr_info;
184 /** Maximum number of modules in operation */
185 #define MAX_MODULE 16
187 /** Maximum number of known edns options */
188 #define MAX_KNOWN_EDNS_OPTS 256
190 enum inplace_cb_list_type {
191 /* Inplace callbacks for when a resolved reply is ready to be sent to the
193 inplace_cb_reply = 0,
194 /* Inplace callbacks for when a reply is given from the cache. */
195 inplace_cb_reply_cache,
196 /* Inplace callbacks for when a reply is given with local data
197 * (or Chaos reply). */
198 inplace_cb_reply_local,
199 /* Inplace callbacks for when the reply is servfail. */
200 inplace_cb_reply_servfail,
201 /* Inplace callbacks for when a query is ready to be sent to the back.*/
203 /* Inplace callback for when a reply is received from the back. */
204 inplace_cb_query_response,
205 /* Inplace callback for when EDNS is parsed on a reply received from the
207 inplace_cb_edns_back_parsed,
208 /* Total number of types. Used for array initialization.
209 * Should always be last. */
210 inplace_cb_types_total
214 /** Known edns option. Can be populated during modules' init. */
215 struct edns_known_option {
216 /** type of this edns option */
218 /** whether the option needs to bypass the cache stage */
219 int bypass_cache_stage;
220 /** whether the option needs mesh aggregation */
225 * Inplace callback list of registered routines to be called.
229 struct inplace_cb* next;
230 /** Inplace callback routine */
238 * Inplace callback function called before replying.
239 * Called as func(qinfo, qstate, rep, rcode, edns, opt_list_out, repinfo,
240 * region, id, python_callback)
242 * qinfo: the query info.
243 * qstate: the module state. NULL when calling before the query reaches the
245 * rep: reply_info. Could be NULL.
246 * rcode: the return code.
247 * edns: the edns_data of the reply. When qstate is NULL, it is also used as
249 * opt_list_out: the edns options list for the reply.
250 * repinfo: reply information for a communication point. NULL when calling
251 * during the mesh states; the same could be found from
252 * qstate->mesh_info->reply_list.
253 * region: region to store data.
255 * python_callback: only used for registering a python callback function.
257 typedef int inplace_cb_reply_func_type(struct query_info* qinfo,
258 struct module_qstate* qstate, struct reply_info* rep, int rcode,
259 struct edns_data* edns, struct edns_option** opt_list_out,
260 struct comm_reply* repinfo, struct regional* region, int id,
264 * Inplace callback function called before sending the query to a nameserver.
265 * Called as func(qinfo, flags, qstate, addr, addrlen, zone, zonelen, region,
266 * id, python_callback)
269 * flags: flags of the query.
270 * qstate: query state.
271 * addr: to which server to send the query.
272 * addrlen: length of addr.
273 * zone: name of the zone of the delegation point. wireformat dname.
274 * This is the delegation point name for which the server is deemed
276 * zonelen: length of zone.
277 * region: region to store data.
279 * python_callback: only used for registering a python callback function.
281 typedef int inplace_cb_query_func_type(struct query_info* qinfo, uint16_t flags,
282 struct module_qstate* qstate, struct sockaddr_storage* addr,
283 socklen_t addrlen, uint8_t* zone, size_t zonelen, struct regional* region,
284 int id, void* callback);
287 * Inplace callback function called after parsing edns on query reply.
288 * Called as func(qstate, id, cb_args)
290 * qstate: the query state.
292 * cb_args: argument passed when registering callback.
294 typedef int inplace_cb_edns_back_parsed_func_type(struct module_qstate* qstate,
295 int id, void* cb_args);
298 * Inplace callback function called after parsing query response.
299 * Called as func(qstate, response, id, cb_args)
301 * qstate: the query state.
302 * response: query response.
304 * cb_args: argument passed when registering callback.
306 typedef int inplace_cb_query_response_func_type(struct module_qstate* qstate,
307 struct dns_msg* response, int id, void* cb_args);
310 * Module environment.
311 * Services and data provided to the module.
315 /** config file with config options */
316 struct config_file* cfg;
317 /** shared message cache */
318 struct slabhash* msg_cache;
319 /** shared rrset cache */
320 struct rrset_cache* rrset_cache;
321 /** shared infrastructure cache (edns, lameness) */
322 struct infra_cache* infra_cache;
323 /** shared key cache */
324 struct key_cache* key_cache;
326 /* --- services --- */
328 * Send serviced DNS query to server. UDP/TCP and EDNS is handled.
329 * operate() should return with wait_reply. Later on a callback
330 * will cause operate() to be called with event timeout or reply.
331 * The time until a timeout is calculated from roundtrip timing,
332 * several UDP retries are attempted.
333 * @param qinfo: query info.
334 * @param flags: host order flags word, with opcode and CD bit.
335 * @param dnssec: if set, EDNS record will have bits set.
336 * If EDNS_DO bit is set, DO bit is set in EDNS records.
337 * If BIT_CD is set, CD bit is set in queries with EDNS records.
338 * @param want_dnssec: if set, the validator wants DNSSEC. Without
339 * EDNS, the answer is likely to be useless for this domain.
340 * @param nocaps: do not use caps_for_id, use the qname as given.
341 * (ignored if caps_for_id is disabled).
342 * @param addr: where to.
343 * @param addrlen: length of addr.
344 * @param zone: delegation point name.
345 * @param zonelen: length of zone name.
346 * @param ssl_upstream: use SSL for upstream queries.
347 * @param tls_auth_name: if ssl_upstream, use this name with TLS
349 * @param q: wich query state to reactivate upon return.
350 * @return: false on failure (memory or socket related). no query was
351 * sent. Or returns an outbound entry with qsent and qstate set.
352 * This outbound_entry will be used on later module invocations
353 * that involve this query (timeout, error or reply).
355 struct outbound_entry* (*send_query)(struct query_info* qinfo,
356 uint16_t flags, int dnssec, int want_dnssec, int nocaps,
357 struct sockaddr_storage* addr, socklen_t addrlen,
358 uint8_t* zone, size_t zonelen, int ssl_upstream,
359 char* tls_auth_name, struct module_qstate* q);
363 * Remove all sub-query references from this query state.
364 * Keeps super-references of those sub-queries correct.
365 * Updates stat items in mesh_area structure.
366 * @param qstate: used to find mesh state.
368 void (*detach_subs)(struct module_qstate* qstate);
372 * Creates it if it does not exist already.
373 * Keeps sub and super references correct.
374 * Updates stat items in mesh_area structure.
375 * Pass if it is priming query or not.
377 * o if error (malloc) happened.
378 * o need to initialise the new state (module init; it is a new state).
379 * so that the next run of the query with this module is successful.
380 * o no init needed, attachment successful.
382 * @param qstate: the state to find mesh state, and that wants to
383 * receive the results from the new subquery.
384 * @param qinfo: what to query for (copied).
385 * @param qflags: what flags to use (RD, CD flag or not).
386 * @param prime: if it is a (stub) priming query.
387 * @param valrec: validation lookup recursion, does not need validation
388 * @param newq: If the new subquery needs initialisation, it is
389 * returned, otherwise NULL is returned.
390 * @return: false on error, true if success (and init may be needed).
392 int (*attach_sub)(struct module_qstate* qstate,
393 struct query_info* qinfo, uint16_t qflags, int prime,
394 int valrec, struct module_qstate** newq);
397 * Add detached query.
398 * Creates it if it does not exist already.
399 * Does not make super/sub references.
400 * Performs a cycle detection - for double check - and fails if there is
402 * Updates stat items in mesh_area structure.
403 * Pass if it is priming query or not.
405 * o if error (malloc) happened.
406 * o need to initialise the new state (module init; it is a new state).
407 * so that the next run of the query with this module is successful.
408 * o no init needed, attachment successful.
409 * o added subquery, created if it did not exist already.
411 * @param qstate: the state to find mesh state, and that wants to receive
412 * the results from the new subquery.
413 * @param qinfo: what to query for (copied).
414 * @param qflags: what flags to use (RD / CD flag or not).
415 * @param prime: if it is a (stub) priming query.
416 * @param valrec: if it is a validation recursion query (lookup of key, DS).
417 * @param newq: If the new subquery needs initialisation, it is returned,
418 * otherwise NULL is returned.
419 * @param sub: The added mesh state, created if it did not exist already.
420 * @return: false on error, true if success (and init may be needed).
422 int (*add_sub)(struct module_qstate* qstate,
423 struct query_info* qinfo, uint16_t qflags, int prime,
424 int valrec, struct module_qstate** newq,
425 struct mesh_state** sub);
428 * Kill newly attached sub. If attach_sub returns newq for
429 * initialisation, but that fails, then this routine will cleanup and
430 * delete the freshly created sub.
431 * @param newq: the new subquery that is no longer needed.
434 void (*kill_sub)(struct module_qstate* newq);
437 * Detect if adding a dependency for qstate on name,type,class will
438 * create a dependency cycle.
439 * @param qstate: given mesh querystate.
440 * @param qinfo: query info for dependency.
441 * @param flags: query flags of dependency, RD/CD flags.
442 * @param prime: if dependency is a priming query or not.
443 * @param valrec: validation lookup recursion, does not need validation
444 * @return true if the name,type,class exists and the given
445 * qstate mesh exists as a dependency of that name. Thus
446 * if qstate becomes dependent on name,type,class then a
449 int (*detect_cycle)(struct module_qstate* qstate,
450 struct query_info* qinfo, uint16_t flags, int prime,
453 /** region for temporary usage. May be cleared after operate() call. */
454 struct regional* scratch;
455 /** buffer for temporary usage. May be cleared after operate() call. */
456 struct sldns_buffer* scratch_buffer;
457 /** internal data for daemon - worker thread. */
458 struct worker* worker;
459 /** the worker event base */
460 struct comm_base* worker_base;
461 /** the outside network */
462 struct outside_network* outnet;
463 /** mesh area with query state dependencies */
464 struct mesh_area* mesh;
465 /** allocation service */
466 struct alloc_cache* alloc;
467 /** random table to generate random numbers */
468 struct ub_randstate* rnd;
469 /** time in seconds, converted to integer */
471 /** time in microseconds. Relatively recent. */
472 struct timeval* now_tv;
473 /** is validation required for messages, controls client-facing
474 * validation status (AD bits) and servfails */
475 int need_to_validate;
476 /** trusted key storage; these are the configured keys, if not NULL,
477 * otherwise configured by validator. These are the trust anchors,
478 * and are not primed and ready for validation, but on the bright
479 * side, they are read only memory, thus no locks and fast. */
480 struct val_anchors* anchors;
481 /** negative cache, configured by the validator. if not NULL,
482 * contains NSEC record lookup trees. */
483 struct val_neg_cache* neg_cache;
484 /** the 5011-probe timer (if any) */
485 struct comm_timer* probe_timer;
487 struct auth_zones* auth_zones;
488 /** Mapping of forwarding zones to targets.
489 * iterator forwarder information. per-thread, created by worker */
490 struct iter_forwards* fwds;
492 * iterator forwarder information. per-thread, created by worker.
493 * The hints -- these aren't stored in the cache because they don't
494 * expire. The hints are always used to "prime" the cache. Note
495 * that both root hints and stub zone "hints" are stored in this
498 struct iter_hints* hints;
499 /** module specific data. indexed by module id. */
500 void* modinfo[MAX_MODULE];
502 /* Shared linked list of inplace callback functions */
503 struct inplace_cb* inplace_cb_lists[inplace_cb_types_total];
506 * Shared array of known edns options (size MAX_KNOWN_EDNS_OPTS).
507 * Filled by edns literate modules during init.
509 struct edns_known_option* edns_known_options;
510 /* Number of known edns options */
511 size_t edns_known_options_num;
513 /* Make every mesh state unique, do not aggregate mesh states. */
518 * External visible states of the module state machine
519 * Modules may also have an internal state.
520 * Modules are supposed to run to completion or until blocked.
522 enum module_ext_state {
523 /** initial state - new query */
524 module_state_initial = 0,
525 /** waiting for reply to outgoing network query */
527 /** module is waiting for another module */
529 /** module is waiting for another module; that other is restarted */
531 /** module is waiting for sub-query */
532 module_wait_subquery,
533 /** module could not finish the query */
535 /** module is finished with query */
540 * Events that happen to modules, that start or wakeup modules.
544 module_event_new = 0,
545 /** query passed by other module */
547 /** reply inbound from server */
549 /** no reply, timeout or other error */
550 module_event_noreply,
551 /** reply is there, but capitalisation check failed */
552 module_event_capsfail,
553 /** next module is done, and its reply is awaiting you */
554 module_event_moddone,
560 * Linked list of sockaddrs
561 * May be allocated such that only 'len' bytes of addr exist for the structure.
565 struct sock_list* next;
566 /** length of addr */
569 struct sockaddr_storage addr;
572 struct respip_action_info;
575 * Module state, per query.
577 struct module_qstate {
578 /** which query is being answered: name, type, class */
579 struct query_info qinfo;
580 /** flags uint16 from query */
581 uint16_t query_flags;
582 /** if this is a (stub or root) priming query (with hints) */
584 /** if this is a validation recursion query that does not get
585 * validation itself */
588 /** comm_reply contains server replies */
589 struct comm_reply* reply;
590 /** the reply message, with message for client and calling module */
591 struct dns_msg* return_msg;
592 /** the rcode, in case of error, instead of a reply message */
594 /** origin of the reply (can be NULL from cache, list for cnames) */
595 struct sock_list* reply_origin;
596 /** IP blacklist for queries */
597 struct sock_list* blacklist;
598 /** region for this query. Cleared when query process finishes. */
599 struct regional* region;
600 /** failure reason information if val-log-level is high */
601 struct config_strlist* errinf;
603 /** which module is executing */
606 enum module_ext_state ext_state[MAX_MODULE];
607 /** module specific data for query. indexed by module id. */
608 void* minfo[MAX_MODULE];
609 /** environment for this query */
610 struct module_env* env;
611 /** mesh related information for this query */
612 struct mesh_state* mesh_info;
613 /** how many seconds before expiry is this prefetched (0 if not) */
614 time_t prefetch_leeway;
616 /** incoming edns options from the front end */
617 struct edns_option* edns_opts_front_in;
618 /** outgoing edns options to the back end */
619 struct edns_option* edns_opts_back_out;
620 /** incoming edns options from the back end */
621 struct edns_option* edns_opts_back_in;
622 /** outgoing edns options to the front end */
623 struct edns_option* edns_opts_front_out;
624 /** whether modules should answer from the cache */
626 /** whether modules should store answer in the cache */
628 /** whether to refetch a fresh answer on finishing this state*/
630 /** whether the query (or a subquery) was ratelimited */
634 * Attributes of clients that share the qstate that may affect IP-based
637 struct respip_client_info* client_info;
639 /** Extended result of response-ip action processing, mainly
640 * for logging purposes. */
641 struct respip_action_info* respip_action_info;
643 /** whether the reply should be dropped */
648 * Module functionality block
650 struct module_func_block {
651 /** text string name of module */
655 * init the module. Called once for the global state.
656 * This is the place to apply settings from the config file.
657 * @param env: module environment.
658 * @param id: module id number.
661 int (*init)(struct module_env* env, int id);
664 * de-init, delete, the module. Called once for the global state.
665 * @param env: module environment.
666 * @param id: module id number.
668 void (*deinit)(struct module_env* env, int id);
671 * accept a new query, or work further on existing query.
672 * Changes the qstate->ext_state to be correct on exit.
673 * @param ev: event that causes the module state machine to
675 * @param qstate: the query state.
676 * Note that this method is not allowed to change the
677 * query state 'identity', that is query info, qflags,
678 * and priming status.
679 * Attach a subquery to get results to a different query.
680 * @param id: module id number that operate() is called on.
681 * @param outbound: if not NULL this event is due to the reply/timeout
682 * or error on this outbound query.
683 * @return: if at exit the ext_state is:
684 * o wait_module: next module is started. (with pass event).
685 * o error or finished: previous module is resumed.
686 * o otherwise it waits until that event happens (assumes
687 * the service routine to make subrequest or send message
690 void (*operate)(struct module_qstate* qstate, enum module_ev event,
691 int id, struct outbound_entry* outbound);
694 * inform super querystate about the results from this subquerystate.
695 * Is called when the querystate is finished. The method invoked is
696 * the one from the current module active in the super querystate.
697 * @param qstate: the query state that is finished.
698 * Examine return_rcode and return_reply in the qstate.
699 * @param id: module id for this module.
700 * This coincides with the current module for the super qstate.
701 * @param super: the super querystate that needs to be informed.
703 void (*inform_super)(struct module_qstate* qstate, int id,
704 struct module_qstate* super);
707 * clear module specific data
709 void (*clear)(struct module_qstate* qstate, int id);
712 * How much memory is the module specific data using.
713 * @param env: module environment.
714 * @param id: the module id.
715 * @return the number of bytes that are alloced.
717 size_t (*get_mem)(struct module_env* env, int id);
721 * Debug utility: module external qstate to string
722 * @param s: the state value.
723 * @return descriptive string.
725 const char* strextstate(enum module_ext_state s);
728 * Debug utility: module event to string
729 * @param e: the module event value.
730 * @return descriptive string.
732 const char* strmodulevent(enum module_ev e);
735 * Initialize the edns known options by allocating the required space.
736 * @param env: the module environment.
737 * @return false on failure (no memory).
739 int edns_known_options_init(struct module_env* env);
742 * Free the allocated space for the known edns options.
743 * @param env: the module environment.
745 void edns_known_options_delete(struct module_env* env);
748 * Register a known edns option. Overwrite the flags if it is already
749 * registered. Used before creating workers to register known edns options.
750 * @param opt_code: the edns option code.
751 * @param bypass_cache_stage: whether the option interacts with the cache.
752 * @param no_aggregation: whether the option implies more specific
754 * @param env: the module environment.
755 * @return true on success, false on failure (registering more options than
756 * allowed or trying to register after the environment is copied to the
759 int edns_register_option(uint16_t opt_code, int bypass_cache_stage,
760 int no_aggregation, struct module_env* env);
763 * Register an inplace callback function.
764 * @param cb: pointer to the callback function.
765 * @param type: inplace callback type.
766 * @param cbarg: argument for the callback function, or NULL.
767 * @param env: the module environment.
768 * @param id: module id.
769 * @return true on success, false on failure (out of memory or trying to
770 * register after the environment is copied to the threads.)
773 inplace_cb_register(void* cb, enum inplace_cb_list_type type, void* cbarg,
774 struct module_env* env, int id);
777 * Delete callback for specified type and module id.
778 * @param env: the module environment.
779 * @param type: inplace callback type.
780 * @param id: module id.
783 inplace_cb_delete(struct module_env* env, enum inplace_cb_list_type type,
787 * Delete all the inplace callback linked lists.
788 * @param env: the module environment.
790 void inplace_cb_lists_delete(struct module_env* env);
793 * Check if an edns option is known.
794 * @param opt_code: the edns option code.
795 * @param env: the module environment.
796 * @return pointer to registered option if the edns option is known,
799 struct edns_known_option* edns_option_is_known(uint16_t opt_code,
800 struct module_env* env);
803 * Check if an edns option needs to bypass the reply from cache stage.
804 * @param list: the edns options.
805 * @param env: the module environment.
806 * @return true if an edns option needs to bypass the cache stage,
809 int edns_bypass_cache_stage(struct edns_option* list,
810 struct module_env* env);
813 * Check if an unique mesh state is required. Might be triggered by EDNS option
814 * or set for the complete env.
815 * @param list: the edns options.
816 * @param env: the module environment.
817 * @return true if an edns option needs a unique mesh state,
820 int unique_mesh_state(struct edns_option* list, struct module_env* env);
823 * Log the known edns options.
824 * @param level: the desired verbosity level.
825 * @param env: the module environment.
827 void log_edns_known_options(enum verbosity_value level,
828 struct module_env* env);
831 * Copy state that may have happened in the subquery and is always relevant to
833 * @param qstate: query state that finished.
834 * @param id: module id.
835 * @param super: the qstate to inform.
837 void copy_state_to_super(struct module_qstate* qstate, int id,
838 struct module_qstate* super);
840 #endif /* UTIL_MODULE_H */