Electroneum
mesh.h
Go to the documentation of this file.
1 /*
2  * services/mesh.h - deal with mesh of query states and handle events for that.
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 
46 #ifndef SERVICES_MESH_H
47 #define SERVICES_MESH_H
48 
49 #include "util/rbtree.h"
50 #include "util/netevent.h"
51 #include "util/data/msgparse.h"
52 #include "util/module.h"
53 #include "services/modstack.h"
54 struct sldns_buffer;
55 struct mesh_state;
56 struct mesh_reply;
57 struct mesh_cb;
58 struct query_info;
59 struct reply_info;
60 struct outbound_entry;
61 struct timehist;
62 struct respip_client_info;
63 
68 #define MESH_MAX_ACTIVATION 3000
69 
75 #define MESH_MAX_SUBSUB 1024
76 
80 struct mesh_area {
84  struct module_env* env;
85 
90 
103 
108 
114  size_t replies_sent;
116  struct timeval replies_sum_wait;
120  size_t ans_secure;
122  size_t ans_bogus;
124  size_t ans_rcode[16];
126  size_t ans_nodata;
127 
131 
137 
144  struct timeval jostle_max;
145 };
146 
156 struct mesh_state {
163  struct module_qstate s;
167  struct mesh_cb* cb_list;
176 
178  struct mesh_state* prev;
180  struct mesh_state* next;
186 
189 };
190 
199  struct mesh_state* s;
200 };
201 
205 struct mesh_reply {
207  struct mesh_reply* next;
211  struct edns_data edns;
213  struct timeval start_time;
222 };
223 
228 typedef void (*mesh_cb_func_type)(void*, int, struct sldns_buffer*, enum sec_status,
229  char*);
230 
234 struct mesh_cb {
236  struct mesh_cb* next;
238  struct edns_data edns;
244  struct sldns_buffer* buf;
245 
251  void* cb_arg;
252 };
253 
254 /* ------------------- Functions for worker -------------------- */
255 
262 struct mesh_area* mesh_create(struct module_stack* stack,
263  struct module_env* env);
264 
269 void mesh_delete(struct mesh_area* mesh);
270 
287 void mesh_new_client(struct mesh_area* mesh, struct query_info* qinfo,
288  struct respip_client_info* cinfo, uint16_t qflags,
289  struct edns_data* edns, struct comm_reply* rep, uint16_t qid);
290 
306 int mesh_new_callback(struct mesh_area* mesh, struct query_info* qinfo,
307  uint16_t qflags, struct edns_data* edns, struct sldns_buffer* buf,
308  uint16_t qid, mesh_cb_func_type cb, void* cb_arg);
309 
319 void mesh_new_prefetch(struct mesh_area* mesh, struct query_info* qinfo,
320  uint16_t qflags, time_t leeway);
321 
332 void mesh_report_reply(struct mesh_area* mesh, struct outbound_entry* e,
333  struct comm_reply* reply, int what);
334 
335 /* ------------------- Functions for module environment --------------- */
336 
344 void mesh_detach_subs(struct module_qstate* qstate);
345 
370 int mesh_attach_sub(struct module_qstate* qstate, struct query_info* qinfo,
371  uint16_t qflags, int prime, int valrec, struct module_qstate** newq);
372 
398 int mesh_add_sub(struct module_qstate* qstate, struct query_info* qinfo,
399  uint16_t qflags, int prime, int valrec, struct module_qstate** newq,
400  struct mesh_state** sub);
401 
417 void mesh_query_done(struct mesh_state* mstate);
418 
430 void mesh_walk_supers(struct mesh_area* mesh, struct mesh_state* mstate);
431 
437 void mesh_state_delete(struct module_qstate* qstate);
438 
439 /* ------------------- Functions for mesh -------------------- */
440 
453 struct mesh_state* mesh_state_create(struct module_env* env,
454  struct query_info* qinfo, struct respip_client_info* cinfo,
455  uint16_t qflags, int prime, int valrec);
456 
463 int mesh_state_is_unique(struct mesh_state* mstate);
464 
470 void mesh_state_make_unique(struct mesh_state* mstate);
471 
478 void mesh_state_cleanup(struct mesh_state* mstate);
479 
484 void mesh_delete_all(struct mesh_area* mesh);
485 
498 struct mesh_state* mesh_area_find(struct mesh_area* mesh,
499  struct respip_client_info* cinfo, struct query_info* qinfo,
500  uint16_t qflags, int prime, int valrec);
501 
510 int mesh_state_attachment(struct mesh_state* super, struct mesh_state* sub);
511 
523 int mesh_state_add_reply(struct mesh_state* s, struct edns_data* edns,
524  struct comm_reply* rep, uint16_t qid, uint16_t qflags,
525  const struct query_info* qinfo);
526 
539 int mesh_state_add_cb(struct mesh_state* s, struct edns_data* edns,
540  struct sldns_buffer* buf, mesh_cb_func_type cb, void* cb_arg,
541  uint16_t qid, uint16_t qflags);
542 
552 void mesh_run(struct mesh_area* mesh, struct mesh_state* mstate,
553  enum module_ev ev, struct outbound_entry* e);
554 
560 void mesh_stats(struct mesh_area* mesh, const char* str);
561 
566 void mesh_stats_clear(struct mesh_area* mesh);
567 
572 void mesh_log_list(struct mesh_area* mesh);
573 
579 size_t mesh_get_mem(struct mesh_area* mesh);
580 
595 int mesh_detect_cycle(struct module_qstate* qstate, struct query_info* qinfo,
596  uint16_t flags, int prime, int valrec);
597 
599 int mesh_state_compare(const void* ap, const void* bp);
600 
602 int mesh_state_ref_compare(const void* ap, const void* bp);
603 
616 int mesh_make_new_space(struct mesh_area* mesh, struct sldns_buffer* qbuf);
617 
624 void mesh_list_insert(struct mesh_state* m, struct mesh_state** fp,
625  struct mesh_state** lp);
626 
633 void mesh_list_remove(struct mesh_state* m, struct mesh_state** fp,
634  struct mesh_state** lp);
635 
636 #endif /* SERVICES_MESH_H */
struct comm_reply query_reply
Definition: mesh.h:209
struct mesh_cb * next
Definition: mesh.h:236
mesh_list_select
Definition: mesh.h:182
size_t mesh_get_mem(struct mesh_area *mesh)
uint16_t qid
Definition: mesh.h:215
Definition: mesh.h:80
void mesh_new_prefetch(struct mesh_area *mesh, struct query_info *qinfo, uint16_t qflags, time_t leeway)
void mesh_delete_all(struct mesh_area *mesh)
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)
struct timeval replies_sum_wait
Definition: mesh.h:116
Definition: outbound_list.h:61
rbtree_type all
Definition: mesh.h:89
int mesh_state_is_unique(struct mesh_state *mstate)
uint16_t qflags
Definition: mesh.h:217
size_t num_reply_states
Definition: mesh.h:96
struct local_rrset * local_alias
Definition: mesh.h:221
struct edns_data edns
Definition: mesh.h:211
struct mesh_state * s
Definition: mesh.h:199
size_t num_detached_states
Definition: mesh.h:100
struct mesh_state * jostle_first
Definition: mesh.h:140
void mesh_report_reply(struct mesh_area *mesh, struct outbound_entry *e, struct comm_reply *reply, int what)
uint16_t qid
Definition: mesh.h:240
void mesh_run(struct mesh_area *mesh, struct mesh_state *mstate, enum module_ev ev, struct outbound_entry *e)
struct mesh_reply * next
Definition: mesh.h:207
unsigned short uint16_t
Definition: stdint.h:125
struct timehist * histogram
Definition: mesh.h:118
rbtree_type run
Definition: mesh.h:87
void mesh_delete(struct mesh_area *mesh)
int mesh_state_compare(const void *ap, const void *bp)
unsigned char uint8_t
Definition: stdint.h:124
mesh_cb_func_type cb
Definition: mesh.h:249
void mesh_query_done(struct mesh_state *mstate)
void mesh_state_delete(struct module_qstate *qstate)
rbtree_type sub_set
Definition: mesh.h:173
size_t stats_dropped
Definition: mesh.h:112
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)
size_t num_activated
Definition: mesh.h:175
struct module_env * env
Definition: mesh.h:84
void mesh_stats(struct mesh_area *mesh, const char *str)
int mesh_detect_cycle(struct module_qstate *qstate, struct query_info *qinfo, uint16_t flags, int prime, int valrec)
struct mesh_cb * cb_list
Definition: mesh.h:167
uint8_t replies_sent
Definition: mesh.h:188
int mesh_attach_sub(struct module_qstate *qstate, struct query_info *qinfo, uint16_t qflags, int prime, int valrec, struct module_qstate **newq)
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)
size_t ans_nodata
Definition: mesh.h:126
void mesh_detach_subs(struct module_qstate *qstate)
size_t ans_secure
Definition: mesh.h:120
struct mesh_state * forever_last
Definition: mesh.h:136
int mesh_state_attachment(struct mesh_state *super, struct mesh_state *sub)
struct sldns_buffer * buf
Definition: mesh.h:244
sec_status
Definition: packed_rrset.h:176
struct sldns_buffer * qbuf_bak
Definition: mesh.h:130
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)
size_t num_reply_addrs
Definition: mesh.h:92
size_t replies_sent
Definition: mesh.h:114
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)
module_ev
Definition: module.h:536
size_t num_forever_states
Definition: mesh.h:102
uint16_t qflags
Definition: mesh.h:242
void mesh_list_remove(struct mesh_state *m, struct mesh_state **fp, struct mesh_state **lp)
const char * buf
Definition: slow_memmem.cpp:74
size_t ans_bogus
Definition: mesh.h:122
struct mesh_reply * reply_list
Definition: mesh.h:165
void mesh_walk_supers(struct mesh_area *mesh, struct mesh_state *mstate)
void mesh_list_insert(struct mesh_state *m, struct mesh_state **fp, struct mesh_state **lp)
struct mesh_state * prev
Definition: mesh.h:178
void(* mesh_cb_func_type)(void *, int, struct sldns_buffer *, enum sec_status, char *)
Definition: mesh.h:228
rbtree_type super_set
Definition: mesh.h:170
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)
size_t max_reply_states
Definition: mesh.h:105
struct mesh_state * unique
Definition: mesh.h:185
int mesh_make_new_space(struct mesh_area *mesh, struct sldns_buffer *qbuf)
size_t stats_jostled
Definition: mesh.h:110
uint8_t * qname
Definition: mesh.h:219
struct module_stack mods
Definition: mesh.h:82
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)
void mesh_stats_clear(struct mesh_area *mesh)
struct mesh_state * jostle_last
Definition: mesh.h:142
rbnode_type run_node
Definition: mesh.h:160
struct mesh_state * next
Definition: mesh.h:180
rbnode_type node
Definition: mesh.h:158
struct timeval jostle_max
Definition: mesh.h:144
struct timeval start_time
Definition: mesh.h:213
size_t max_forever_states
Definition: mesh.h:107
void * cb_arg
Definition: mesh.h:251
void mesh_state_make_unique(struct mesh_state *mstate)
struct mesh_state * forever_first
Definition: mesh.h:134
int mesh_state_ref_compare(const void *ap, const void *bp)
size_t ans_rcode[16]
Definition: mesh.h:124
void mesh_state_cleanup(struct mesh_state *mstate)
enum mesh_state::mesh_list_select list_select
rbnode_type node
Definition: mesh.h:197
void mesh_log_list(struct mesh_area *mesh)
struct mesh_area * mesh_create(struct module_stack *stack, struct module_env *env)
struct module_qstate s
Definition: mesh.h:163
struct edns_data edns
Definition: mesh.h:238
Definition: mesh.h:234