aboutsummaryrefslogtreecommitdiff
path: root/util/module.h
diff options
context:
space:
mode:
Diffstat (limited to 'util/module.h')
-rw-r--r--util/module.h301
1 files changed, 291 insertions, 10 deletions
diff --git a/util/module.h b/util/module.h
index c3ce8a40eda2..0e27e6a56d71 100644
--- a/util/module.h
+++ b/util/module.h
@@ -178,6 +178,115 @@ struct iter_hints;
/** Maximum number of modules in operation */
#define MAX_MODULE 5
+/** Maximum number of known edns options */
+#define MAX_KNOWN_EDNS_OPTS 256
+
+enum inplace_cb_list_type {
+ /* Inplace callbacks for when a resolved reply is ready to be sent to the
+ * front.*/
+ inplace_cb_reply = 0,
+ /* Inplace callbacks for when a reply is given from the cache. */
+ inplace_cb_reply_cache,
+ /* Inplace callbacks for when a reply is given with local data
+ * (or Chaos reply). */
+ inplace_cb_reply_local,
+ /* Inplace callbacks for when the reply is servfail. */
+ inplace_cb_reply_servfail,
+ /* Inplace callbacks for when a query is ready to be sent to the back.*/
+ inplace_cb_query,
+ /* Total number of types. Used for array initialization.
+ * Should always be last. */
+ inplace_cb_types_total
+};
+
+
+/** Known edns option. Can be populated during modules' init. */
+struct edns_known_option {
+ /** type of this edns option */
+ uint16_t opt_code;
+ /** whether the option needs to bypass the cache stage */
+ int bypass_cache_stage;
+ /** whether the option needs mesh aggregation */
+ int no_aggregation;
+};
+
+/**
+ * Inplace callback function called before replying.
+ * Called as func(edns, qstate, opt_list_out, qinfo, reply_info, rcode,
+ * region, python_callback)
+ * Where:
+ * qinfo: the query info.
+ * qstate: the module state. NULL when calling before the query reaches the
+ * mesh states.
+ * rep: reply_info. Could be NULL.
+ * rcode: the return code.
+ * edns: the edns_data of the reply. When qstate is NULL, it is also used as
+ * the edns input.
+ * opt_list_out: the edns options list for the reply.
+ * region: region to store data.
+ * python_callback: only used for registering a python callback function.
+ */
+typedef int inplace_cb_reply_func_t(struct query_info* qinfo,
+ struct module_qstate* qstate, struct reply_info* rep, int rcode,
+ struct edns_data* edns, struct edns_option** opt_list_out,
+ struct regional* region, void* python_callback);
+
+/**
+ * Inplace callback list of registered routines to be called before replying
+ * with a resolved query.
+ */
+struct inplace_cb_reply {
+ /** next in list */
+ struct inplace_cb_reply* next;
+ /**
+ * Inplace callback routine for cache stage response.
+ * called as cb(qinfo, qstate, qinfo, reply_info, rcode, edns,
+ * opt_list_out, region, python_callback);
+ * python_callback is only used for registering a python callback function.
+ */
+ inplace_cb_reply_func_t* cb;
+ void* cb_arg;
+};
+
+/**
+ * Inplace callback function called before sending the query to a nameserver.
+ * Called as func(qinfo, flags, qstate, addr, addrlen, zone, zonelen, region,
+ * python_callback)
+ * Where:
+ * qinfo: query info.
+ * flags: flags of the query.
+ * qstate: query state.
+ * addr: to which server to send the query.
+ * addrlen: length of addr.
+ * zone: name of the zone of the delegation point. wireformat dname.
+ * This is the delegation point name for which the server is deemed
+ * authoritative.
+ * zonelen: length of zone.
+ * region: region to store data.
+ * python_callback: only used for registering a python callback function.
+ */
+typedef int inplace_cb_query_func_t(struct query_info* qinfo, uint16_t flags,
+ struct module_qstate* qstate, struct sockaddr_storage* addr,
+ socklen_t addrlen, uint8_t* zone, size_t zonelen, struct regional* region,
+ void* python_callback);
+
+/**
+ * Inplace callback list of registered routines to be called before quering a
+ * nameserver.
+ */
+struct inplace_cb_query {
+ /** next in list */
+ struct inplace_cb_query* next;
+ /**
+ * Inplace callback routine for cache stage response.
+ * called as cb(qinfo, flags, qstate, addr, addrlen, zone, zonelen,
+ * region, python_callback);
+ * python_callback is only used for registering a python callback function.
+ */
+ inplace_cb_query_func_t* cb;
+ void* cb_arg;
+};
+
/**
* Module environment.
* Services and data provided to the module.
@@ -202,10 +311,7 @@ struct module_env {
* will cause operate() to be called with event timeout or reply.
* The time until a timeout is calculated from roundtrip timing,
* several UDP retries are attempted.
- * @param qname: query name. (host order)
- * @param qnamelen: length in bytes of qname, including trailing 0.
- * @param qtype: query type. (host order)
- * @param qclass: query class. (host order)
+ * @param qinfo: query info.
* @param flags: host order flags word, with opcode and CD bit.
* @param dnssec: if set, EDNS record will have bits set.
* If EDNS_DO bit is set, DO bit is set in EDNS records.
@@ -214,23 +320,22 @@ struct module_env {
* EDNS, the answer is likely to be useless for this domain.
* @param nocaps: do not use caps_for_id, use the qname as given.
* (ignored if caps_for_id is disabled).
- * @param opt_list: set these EDNS options on the outgoing packet.
- * or NULL if none (the list is deep-copied).
* @param addr: where to.
* @param addrlen: length of addr.
* @param zone: delegation point name.
* @param zonelen: length of zone name.
+ * @param ssl_upstream: use SSL for upstream queries.
* @param q: wich query state to reactivate upon return.
* @return: false on failure (memory or socket related). no query was
* sent. Or returns an outbound entry with qsent and qstate set.
* This outbound_entry will be used on later module invocations
* that involve this query (timeout, error or reply).
*/
- struct outbound_entry* (*send_query)(uint8_t* qname, size_t qnamelen,
- uint16_t qtype, uint16_t qclass, uint16_t flags, int dnssec,
- int want_dnssec, int nocaps, struct edns_option* opt_list,
+ struct outbound_entry* (*send_query)(struct query_info* qinfo,
+ uint16_t flags, int dnssec, int want_dnssec, int nocaps,
struct sockaddr_storage* addr, socklen_t addrlen,
- uint8_t* zone, size_t zonelen, struct module_qstate* q);
+ uint8_t* zone, size_t zonelen, int ssl_upstream,
+ struct module_qstate* q);
/**
* Detach-subqueries.
@@ -335,6 +440,17 @@ struct module_env {
struct iter_hints* hints;
/** module specific data. indexed by module id. */
void* modinfo[MAX_MODULE];
+
+ /* Shared linked list of inplace callback functions */
+ void* inplace_cb_lists[inplace_cb_types_total];
+
+ /**
+ * Shared array of known edns options (size MAX_KNOWN_EDNS_OPTS).
+ * Filled by edns literate modules during init.
+ */
+ struct edns_known_option* edns_known_options;
+ /* Number of known edns options */
+ size_t edns_known_options_num;
};
/**
@@ -433,6 +549,19 @@ struct module_qstate {
struct mesh_state* mesh_info;
/** how many seconds before expiry is this prefetched (0 if not) */
time_t prefetch_leeway;
+
+ /** incoming edns options from the front end */
+ struct edns_option* edns_opts_front_in;
+ /** outgoing edns options to the back end */
+ struct edns_option* edns_opts_back_out;
+ /** incoming edns options from the back end */
+ struct edns_option* edns_opts_back_in;
+ /** outgoing edns options to the front end */
+ struct edns_option* edns_opts_front_out;
+ /** whether modules should answer from the cache */
+ int no_cache_lookup;
+ /** whether modules should store answer in the cache */
+ int no_cache_store;
};
/**
@@ -522,4 +651,156 @@ const char* strextstate(enum module_ext_state s);
*/
const char* strmodulevent(enum module_ev e);
+/**
+ * Initialize the edns known options by allocating the required space.
+ * @param env: the module environment.
+ * @return false on failure (no memory).
+ */
+int edns_known_options_init(struct module_env* env);
+
+/**
+ * Free the allocated space for the known edns options.
+ * @param env: the module environment.
+ */
+void edns_known_options_delete(struct module_env* env);
+
+/**
+ * Register a known edns option. Overwrite the flags if it is already
+ * registered. Used before creating workers to register known edns options.
+ * @param opt_code: the edns option code.
+ * @param bypass_cache_stage: whether the option interacts with the cache.
+ * @param no_aggregation: whether the option implies more specific
+ * aggregation.
+ * @param env: the module environment.
+ * @return true on success, false on failure (registering more options than
+ * allowed or trying to register after the environment is copied to the
+ * threads.)
+ */
+int edns_register_option(uint16_t opt_code, int bypass_cache_stage,
+ int no_aggregation, struct module_env* env);
+
+/**
+ * Register an inplace callback function called before replying with a resolved
+ * query.
+ * @param cb: pointer to the callback function.
+ * @param cb_arg: optional argument for the callback function.
+ * @param env: the module environment.
+ * @return true on success, false on failure (out of memory or trying to
+ * register after the environment is copied to the threads.)
+ */
+int inplace_cb_reply_register(inplace_cb_reply_func_t* cb, void* cb_arg,
+ struct module_env* env);
+
+/**
+ * Register an inplace callback function called before replying from the cache.
+ * @param cb: pointer to the callback function.
+ * @param cb_arg: optional argument for the callback function.
+ * @param env: the module environment.
+ * @return true on success, false on failure (out of memory or trying to
+ * register after the environment is copied to the threads.)
+ */
+int inplace_cb_reply_cache_register(inplace_cb_reply_func_t* cb, void* cb_arg,
+ struct module_env* env);
+
+/**
+ * Register an inplace callback function called before replying with local
+ * data or Chaos reply.
+ * @param cb: pointer to the callback function.
+ * @param cb_arg: optional argument for the callback function.
+ * @param env: the module environment.
+ * @return true on success, false on failure (out of memory or trying to
+ * register after the environment is copied to the threads.)
+ */
+int inplace_cb_reply_local_register(inplace_cb_reply_func_t* cb, void* cb_arg,
+ struct module_env* env);
+
+/**
+ * Register an inplace callback function called before replying with servfail.
+ * @param cb: pointer to the callback function.
+ * @param cb_arg: optional argument for the callback function.
+ * @param env: the module environment.
+ * @return true on success, false on failure (out of memory or trying to
+ * register after the environment is copied to the threads.)
+ */
+int inplace_cb_reply_servfail_register(inplace_cb_reply_func_t* cb,
+ void* cb_arg, struct module_env* env);
+
+/**
+ * Delete the inplace_cb_reply callback linked list.
+ * @param env: the module environment.
+ */
+void inplace_cb_reply_delete(struct module_env* env);
+
+/**
+ * Delete the inplace_cb_reply_cache callback linked list.
+ * @param env: the module environment.
+ */
+void inplace_cb_reply_cache_delete(struct module_env* env);
+
+/**
+ * Delete the inplace_cb_reply_servfail callback linked list.
+ * @param env: the module environment.
+ */
+void inplace_cb_reply_servfail_delete(struct module_env* env);
+
+/**
+ * Register an inplace callback function called before quering a nameserver.
+ * @param cb: pointer to the callback function.
+ * @param cb_arg: optional argument for the callback function.
+ * @param env: the module environment.
+ * @return true on success, false on failure (out of memory or trying to
+ * register after the environment is copied to the threads.)
+ */
+int inplace_cb_query_register(inplace_cb_query_func_t* cb, void* cb_arg,
+ struct module_env* env);
+
+/**
+ * Delete the inplace_cb_query callback linked list.
+ * @param env: the module environment.
+ */
+void inplace_cb_query_delete(struct module_env* env);
+
+/**
+ * Delete all the inplace callback linked lists.
+ * @param env: the module environment.
+ */
+void inplace_cb_lists_delete(struct module_env* env);
+
+/**
+ * Check if an edns option is known.
+ * @param opt_code: the edns option code.
+ * @param env: the module environment.
+ * @return pointer to registered option if the edns option is known,
+ * NULL otherwise.
+ */
+struct edns_known_option* edns_option_is_known(uint16_t opt_code,
+ struct module_env* env);
+
+/**
+ * Check if an edns option needs to bypass the reply from cache stage.
+ * @param list: the edns options.
+ * @param env: the module environment.
+ * @return true if an edns option needs to bypass the cache stage,
+ * false otherwise.
+ */
+int edns_bypass_cache_stage(struct edns_option* list,
+ struct module_env* env);
+
+/**
+ * Check if an edns option needs a unique mesh state.
+ * @param list: the edns options.
+ * @param env: the module environment.
+ * @return true if an edns option needs a unique mesh state,
+ * false otherwise.
+ */
+int edns_unique_mesh_state(struct edns_option* list, struct module_env* env);
+
+/**
+ * Log the known edns options.
+ * @param level: the desired verbosity level.
+ * @param env: the module environment.
+ */
+void log_edns_known_options(enum verbosity_value level,
+ struct module_env* env);
+
#endif /* UTIL_MODULE_H */