|
Electroneum
|
#include "util/rbtree.h"#include "util/netevent.h"#include "util/data/msgparse.h"#include "util/module.h"#include "services/modstack.h"

Go to the source code of this file.
Classes | |
| struct | mesh_area |
| struct | mesh_state |
| struct | mesh_state_ref |
| struct | mesh_reply |
| struct | mesh_cb |
Macros | |
| #define | MESH_MAX_ACTIVATION 3000 |
| #define | MESH_MAX_SUBSUB 1024 |
Typedefs | |
| typedef void(* | mesh_cb_func_type) (void *, int, struct sldns_buffer *, enum sec_status, char *) |
Functions | |
| struct mesh_area * | mesh_create (struct module_stack *stack, struct module_env *env) |
| void | mesh_delete (struct mesh_area *mesh) |
| void | mesh_new_client (struct mesh_area *mesh, struct query_info *qinfo, struct respip_client_info *cinfo, uint16_t qflags, struct edns_data *edns, struct comm_reply *rep, uint16_t qid) |
| int | mesh_new_callback (struct mesh_area *mesh, struct query_info *qinfo, uint16_t qflags, struct edns_data *edns, struct sldns_buffer *buf, uint16_t qid, mesh_cb_func_type cb, void *cb_arg) |
| void | mesh_new_prefetch (struct mesh_area *mesh, struct query_info *qinfo, uint16_t qflags, time_t leeway) |
| void | mesh_report_reply (struct mesh_area *mesh, struct outbound_entry *e, struct comm_reply *reply, int what) |
| void | mesh_detach_subs (struct module_qstate *qstate) |
| int | mesh_attach_sub (struct module_qstate *qstate, struct query_info *qinfo, uint16_t qflags, int prime, int valrec, struct module_qstate **newq) |
| int | mesh_add_sub (struct module_qstate *qstate, struct query_info *qinfo, uint16_t qflags, int prime, int valrec, struct module_qstate **newq, struct mesh_state **sub) |
| void | mesh_query_done (struct mesh_state *mstate) |
| void | mesh_walk_supers (struct mesh_area *mesh, struct mesh_state *mstate) |
| void | mesh_state_delete (struct module_qstate *qstate) |
| struct mesh_state * | mesh_state_create (struct module_env *env, struct query_info *qinfo, struct respip_client_info *cinfo, uint16_t qflags, int prime, int valrec) |
| int | mesh_state_is_unique (struct mesh_state *mstate) |
| void | mesh_state_make_unique (struct mesh_state *mstate) |
| void | mesh_state_cleanup (struct mesh_state *mstate) |
| void | mesh_delete_all (struct mesh_area *mesh) |
| struct mesh_state * | mesh_area_find (struct mesh_area *mesh, struct respip_client_info *cinfo, struct query_info *qinfo, uint16_t qflags, int prime, int valrec) |
| int | mesh_state_attachment (struct mesh_state *super, struct mesh_state *sub) |
| int | mesh_state_add_reply (struct mesh_state *s, struct edns_data *edns, struct comm_reply *rep, uint16_t qid, uint16_t qflags, const struct query_info *qinfo) |
| int | mesh_state_add_cb (struct mesh_state *s, struct edns_data *edns, struct sldns_buffer *buf, mesh_cb_func_type cb, void *cb_arg, uint16_t qid, uint16_t qflags) |
| void | mesh_run (struct mesh_area *mesh, struct mesh_state *mstate, enum module_ev ev, struct outbound_entry *e) |
| void | mesh_stats (struct mesh_area *mesh, const char *str) |
| void | mesh_stats_clear (struct mesh_area *mesh) |
| void | mesh_log_list (struct mesh_area *mesh) |
| size_t | mesh_get_mem (struct mesh_area *mesh) |
| int | mesh_detect_cycle (struct module_qstate *qstate, struct query_info *qinfo, uint16_t flags, int prime, int valrec) |
| int | mesh_state_compare (const void *ap, const void *bp) |
| int | mesh_state_ref_compare (const void *ap, const void *bp) |
| int | mesh_make_new_space (struct mesh_area *mesh, struct sldns_buffer *qbuf) |
| void | mesh_list_insert (struct mesh_state *m, struct mesh_state **fp, struct mesh_state **lp) |
| void | mesh_list_remove (struct mesh_state *m, struct mesh_state **fp, struct mesh_state **lp) |
This file contains functions to assist in dealing with a mesh of query states. This mesh is supposed to be thread-specific. It consists of query states (per qname, qtype, qclass) and connections between query states and the super and subquery states, and replies to send back to clients.
Definition in file mesh.h.
| #define MESH_MAX_ACTIVATION 3000 |
| #define MESH_MAX_SUBSUB 1024 |
| typedef void(* mesh_cb_func_type) (void *, int, struct sldns_buffer *, enum sec_status, char *) |
| int mesh_add_sub | ( | struct module_qstate * | qstate, |
| struct query_info * | qinfo, | ||
| uint16_t | qflags, | ||
| int | prime, | ||
| int | valrec, | ||
| struct module_qstate ** | newq, | ||
| struct mesh_state ** | sub | ||
| ) |
Add detached query. Creates it if it does not exist already. Does not make super/sub references. Performs a cycle detection - for double check - and fails if there is one. Updates stat items in mesh_area structure. Pass if it is priming query or not. return: o if error (malloc) happened. o need to initialise the new state (module init; it is a new state). so that the next run of the query with this module is successful. o no init needed, attachment successful. o added subquery, created if it did not exist already.
| qstate | the state to find mesh state, and that wants to receive the results from the new subquery. |
| qinfo | what to query for (copied). |
| qflags | what flags to use (RD / CD flag or not). |
| prime | if it is a (stub) priming query. |
| valrec | if it is a validation recursion query (lookup of key, DS). |
| newq | If the new subquery needs initialisation, it is returned, otherwise NULL is returned. |
| sub | The added mesh state, created if it did not exist already. |
| struct mesh_state* mesh_area_find | ( | struct mesh_area * | mesh, |
| struct respip_client_info * | cinfo, | ||
| struct query_info * | qinfo, | ||
| uint16_t | qflags, | ||
| int | prime, | ||
| int | valrec | ||
| ) |
Find a mesh state in the mesh area. Pass relevant flags.
| mesh | the mesh area to look in. |
| cinfo | if non-NULL client specific info that may affect IP-based actions that apply to the query result. |
| qinfo | what query |
| qflags | if RD / CD bit is set or not. |
| prime | if it is a priming query. |
| valrec | if it is a validation-recursion query. |
| int mesh_attach_sub | ( | struct module_qstate * | qstate, |
| struct query_info * | qinfo, | ||
| uint16_t | qflags, | ||
| int | prime, | ||
| int | valrec, | ||
| struct module_qstate ** | newq | ||
| ) |
Attach subquery. Creates it if it does not exist already. Keeps sub and super references correct. Performs a cycle detection - for double check - and fails if there is one. Also fails if the sub-sub-references become too large. Updates stat items in mesh_area structure. Pass if it is priming query or not. return: o if error (malloc) happened. o need to initialise the new state (module init; it is a new state). so that the next run of the query with this module is successful. o no init needed, attachment successful.
| qstate | the state to find mesh state, and that wants to receive the results from the new subquery. |
| qinfo | what to query for (copied). |
| qflags | what flags to use (RD / CD flag or not). |
| prime | if it is a (stub) priming query. |
| valrec | if it is a validation recursion query (lookup of key, DS). |
| newq | If the new subquery needs initialisation, it is returned, otherwise NULL is returned. |
| struct mesh_area* mesh_create | ( | struct module_stack * | stack, |
| struct module_env * | env | ||
| ) |
Allocate mesh, to empty.
| stack | module stack to activate, copied (as readonly reference). |
| env | environment for new queries. |
| void mesh_delete | ( | struct mesh_area * | mesh | ) |
Delete mesh, and all query states and replies in it.
| mesh | the mesh to delete. |
| void mesh_delete_all | ( | struct mesh_area * | mesh | ) |
Delete all mesh states from the mesh.
| mesh | the mesh area to clear |
| void mesh_detach_subs | ( | struct module_qstate * | qstate | ) |
Detach-subqueries. Remove all sub-query references from this query state. Keeps super-references of those sub-queries correct. Updates stat items in mesh_area structure.
| qstate | used to find mesh state. |
| int mesh_detect_cycle | ( | struct module_qstate * | qstate, |
| struct query_info * | qinfo, | ||
| uint16_t | flags, | ||
| int | prime, | ||
| int | valrec | ||
| ) |
Find cycle; see if the given mesh is in the targets sub, or sub-sub, ... trees. If the sub-sub structure is too large, it returns 'a cycle'=2.
| qstate | given mesh querystate. |
| qinfo | query info for dependency. |
| flags | query flags of dependency. |
| prime | if dependency is a priming query or not. |
| valrec | if it is a validation recursion query (lookup of key, DS). |
| size_t mesh_get_mem | ( | struct mesh_area * | mesh | ) |
Calculate memory size in use by mesh and all queries inside it.
| mesh | the mesh to examine. |
| void mesh_list_insert | ( | struct mesh_state * | m, |
| struct mesh_state ** | fp, | ||
| struct mesh_state ** | lp | ||
| ) |
Insert mesh state into a double linked list. Inserted at end.
| m | mesh state. |
| fp | pointer to the first-elem-pointer of the list. |
| lp | pointer to the last-elem-pointer of the list. |
| void mesh_list_remove | ( | struct mesh_state * | m, |
| struct mesh_state ** | fp, | ||
| struct mesh_state ** | lp | ||
| ) |
Remove mesh state from a double linked list. Remove from any position.
| m | mesh state. |
| fp | pointer to the first-elem-pointer of the list. |
| lp | pointer to the last-elem-pointer of the list. |
| void mesh_log_list | ( | struct mesh_area * | mesh | ) |
Print all the states in the mesh to the log.
| mesh | the mesh to print all states of. |
| int mesh_make_new_space | ( | struct mesh_area * | mesh, |
| struct sldns_buffer * | qbuf | ||
| ) |
Make space for another recursion state for a reply in the mesh
| mesh | mesh area |
| qbuf | query buffer to save if recursion is invoked to make space. This buffer is necessary, because the following sequence in calls can result in an overwrite of the incoming query: delete_other_mesh_query - iter_clean - serviced_delete - waiting udp query is sent - on error callback - callback sends SERVFAIL reply over the same network channel, and shared UDP buffer is overwritten. You can pass NULL if there is no buffer that must be backed up. |
| int mesh_new_callback | ( | struct mesh_area * | mesh, |
| struct query_info * | qinfo, | ||
| uint16_t | qflags, | ||
| struct edns_data * | edns, | ||
| struct sldns_buffer * | buf, | ||
| uint16_t | qid, | ||
| mesh_cb_func_type | cb, | ||
| void * | cb_arg | ||
| ) |
New query with callback. Create new query state if needed, and add mesh_cb to it. Will run the mesh area queries to process if a new query state is created.
| mesh | the mesh. |
| qinfo | query from client. |
| qflags | flags from client query. |
| edns | edns data from client query. |
| buf | buffer for reply contents. |
| qid | query id to reply with. |
| cb | callback function. |
| cb_arg | callback user arg. |
| void mesh_new_client | ( | struct mesh_area * | mesh, |
| struct query_info * | qinfo, | ||
| struct respip_client_info * | cinfo, | ||
| uint16_t | qflags, | ||
| struct edns_data * | edns, | ||
| struct comm_reply * | rep, | ||
| uint16_t | qid | ||
| ) |
New query incoming from clients. Create new query state if needed, and add mesh_reply to it. Returns error to client on malloc failures. Will run the mesh area queries to process if a new query state is created.
| mesh | the mesh. |
| qinfo | query from client. |
| cinfo | additional information associated with the query client. 'cinfo' itself is ephemeral but data pointed to by its members can be assumed to be valid and unchanged until the query processing is completed. |
| qflags | flags from client query. |
| edns | edns data from client query. |
| rep | where to reply to. |
| qid | query id to reply with. |
| void mesh_new_prefetch | ( | struct mesh_area * | mesh, |
| struct query_info * | qinfo, | ||
| uint16_t | qflags, | ||
| time_t | leeway | ||
| ) |
New prefetch message. Create new query state if needed. Will run the mesh area queries to process if a new query state is created.
| mesh | the mesh. |
| qinfo | query from client. |
| qflags | flags from client query. |
| leeway | TTL leeway what to expire earlier for this update. |
| void mesh_query_done | ( | struct mesh_state * | mstate | ) |
Query state is done, send messages to reply entries. Encode messages using reply entry values and the querystate (with original qinfo), using given reply_info. Pass errcode != 0 if an error reply is needed. If no reply entries, nothing is done. Must be called before a module can module_finished or return module_error. The module must handle the super query states itself as well.
| mstate | mesh state that is done. return_rcode and return_msg are used for replies. return_rcode: if not 0 (NOERROR) an error is sent back (and return_msg is ignored). return_msg: reply to encode and send back to clients. |
| void mesh_report_reply | ( | struct mesh_area * | mesh, |
| struct outbound_entry * | e, | ||
| struct comm_reply * | reply, | ||
| int | what | ||
| ) |
Handle new event from the wire. A serviced query has returned. The query state will be made runnable, and the mesh_area will process query states until processing is complete.
| mesh | the query mesh. |
| e | outbound entry, with query state to run and reply pointer. |
| reply | the comm point reply info. |
| what | NETEVENT_* error code (if not 0, what is wrong, TIMEOUT). |
| void mesh_run | ( | struct mesh_area * | mesh, |
| struct mesh_state * | mstate, | ||
| enum module_ev | ev, | ||
| struct outbound_entry * | e | ||
| ) |
Run the mesh. Run all runnable mesh states. Which can create new runnable mesh states. Until completion. Automatically called by mesh_report_reply and mesh_new_client as needed.
| mesh | mesh area. |
| mstate | first mesh state to run. |
| ev | event the mstate. Others get event_pass. |
| e | if a reply, its outbound entry. |
| int mesh_state_add_cb | ( | struct mesh_state * | s, |
| struct edns_data * | edns, | ||
| struct sldns_buffer * | buf, | ||
| mesh_cb_func_type | cb, | ||
| void * | cb_arg, | ||
| uint16_t | qid, | ||
| uint16_t | qflags | ||
| ) |
Create new callback structure and attach it to a mesh state. Does not update stat items in mesh area.
| s | the mesh state. |
| edns | edns data for reply (bufsize). |
| buf | buffer for reply |
| cb | callback to call with results. |
| cb_arg | callback user arg. |
| qid | ID of reply. |
| qflags | original query flags. |
| int mesh_state_add_reply | ( | struct mesh_state * | s, |
| struct edns_data * | edns, | ||
| struct comm_reply * | rep, | ||
| uint16_t | qid, | ||
| uint16_t | qflags, | ||
| const struct query_info * | qinfo | ||
| ) |
Create new reply structure and attach it to a mesh state. Does not update stat items in mesh area.
| s | the mesh state. |
| edns | edns data for reply (bufsize). |
| rep | comm point reply info. |
| qid | ID of reply. |
| qflags | original query flags. |
| qinfo | original query info. |
| int mesh_state_attachment | ( | struct mesh_state * | super, |
| struct mesh_state * | sub | ||
| ) |
Setup attachment super/sub relation between super and sub mesh state. The relation must not be present when calling the function. Does not update stat items in mesh_area.
| super | super state. |
| sub | sub state. |
| void mesh_state_cleanup | ( | struct mesh_state * | mstate | ) |
Cleanup a mesh state and its query state. Does not do rbtree or reference cleanup.
| mstate | mesh state to cleanup. Its pointer may no longer be used afterwards. Cleanup rbtrees before calling this function. |
| int mesh_state_compare | ( | const void * | ap, |
| const void * | bp | ||
| ) |
compare two mesh_states
| struct mesh_state* mesh_state_create | ( | struct module_env * | env, |
| struct query_info * | qinfo, | ||
| struct respip_client_info * | cinfo, | ||
| uint16_t | qflags, | ||
| int | prime, | ||
| int | valrec | ||
| ) |
Create and initialize a new mesh state and its query state Does not put the mesh state into rbtrees and so on.
| env | module environment to set. |
| qinfo | query info that the mesh is for. |
| cinfo | control info for the query client (can be NULL). |
| qflags | flags for query (RD / CD flag). |
| prime | if true, it is a priming query, set is_priming on mesh state. |
| valrec | if true, it is a validation recursion query, and sets is_valrec on the mesh state. |
| void mesh_state_delete | ( | struct module_qstate * | qstate | ) |
Delete mesh state, cleanup and also rbtrees and so on. Will detach from all super/subnodes.
| qstate | to remove. |
| int mesh_state_is_unique | ( | struct mesh_state * | mstate | ) |
Check if the mesh state is unique. A unique mesh state uses it's unique member to point to itself, else NULL.
| mstate | mesh state to check. |
| void mesh_state_make_unique | ( | struct mesh_state * | mstate | ) |
Make a mesh state unique. A unique mesh state uses it's unique member to point to itself.
| mstate | mesh state to check. |
| int mesh_state_ref_compare | ( | const void * | ap, |
| const void * | bp | ||
| ) |
compare two mesh references
| void mesh_stats | ( | struct mesh_area * | mesh, |
| const char * | str | ||
| ) |
Print some stats about the mesh to the log.
| mesh | the mesh to print it for. |
| str | descriptive string to go with it. |
| void mesh_stats_clear | ( | struct mesh_area * | mesh | ) |
Clear the stats that the mesh keeps (number of queries serviced)
| mesh | the mesh |
| void mesh_walk_supers | ( | struct mesh_area * | mesh, |
| struct mesh_state * | mstate | ||
| ) |
Call inform_super for the super query states that are interested in the results from this query state. These can then be changed for error or results. Called when a module is module_finished or returns module_error. The super query states become runnable with event module_event_pass, it calls the current module for the super with the inform_super event.
| mesh | mesh area to add newly runnable modules to. |
| mstate | the state that has results, used to find mesh state. |