Electroneum
outside_network.h
Go to the documentation of this file.
1 /*
2  * services/outside_network.h - listen to answers from the network
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 
43 #ifndef OUTSIDE_NETWORK_H
44 #define OUTSIDE_NETWORK_H
45 
46 #include "util/rbtree.h"
47 #include "util/netevent.h"
48 #include "dnstap/dnstap_config.h"
49 struct pending;
50 struct pending_timeout;
51 struct ub_randstate;
52 struct pending_tcp;
53 struct waiting_tcp;
54 struct waiting_udp;
55 struct infra_cache;
56 struct port_comm;
57 struct port_if;
58 struct sldns_buffer;
59 struct serviced_query;
60 struct dt_env;
61 struct edns_option;
62 struct module_env;
63 struct module_qstate;
64 struct query_info;
65 
72  struct comm_base* base;
74  time_t* now_secs;
76  struct timeval* now_tv;
77 
83  size_t svcd_overhead;
88 
96  void (*unwanted_action)(void*);
99 
104  int do_udp;
108  struct timeval delay_tv;
109 
111  struct port_if* ip4_ifs;
113  int num_ip4;
114 
116  struct port_if* ip6_ifs;
118  int num_ip6;
119 
124 
132  struct ub_randstate* rnd;
134  void* sslctx;
135 #ifdef USE_DNSTAP
136 
137  struct dt_env* dtenv;
138 #endif
139 
140  int tcp_mss;
141 
150  size_t num_tcp;
159 };
160 
165 struct port_if {
169  socklen_t addrlen;
170 
173  int pfxlen;
174 
180 
183  struct port_comm** out;
185  int maxout;
187  int inuse;
188 };
189 
193 struct port_comm {
195  struct port_comm* next;
197  int number;
199  struct port_if* pif;
201  int index;
205  struct comm_point* cp;
206 };
207 
211 struct pending {
217  unsigned int id;
221  socklen_t addrlen;
223  struct port_comm* pc;
225  struct comm_timer* timer;
229  void* cb_arg;
234 
235  /*---- filled if udp pending is waiting -----*/
239  int timeout;
243  size_t pkt_len;
244 };
245 
249 struct pending_tcp {
255  struct comm_point* c;
258 };
259 
263 struct waiting_tcp {
271  struct comm_timer* timer;
277  socklen_t addrlen;
286  size_t pkt_len;
290  void* cb_arg;
295 };
296 
306  void* cb_arg;
307 };
308 
310 #define EDNS_FRAG_SIZE_IP4 1472
311 
312 #define EDNS_FRAG_SIZE_IP6 1232
313 
328  size_t qbuflen;
330  int dnssec;
334  int nocaps;
343  socklen_t addrlen;
347  size_t zonelen;
349  int qtype;
370  }
372  status;
376  int retry;
378  struct timeval last_sent_time;
380  int last_rtt;
390  void* pending;
391 };
392 
421  size_t bufsize, size_t num_ports, char** ifs, int num_ifs,
422  int do_ip4, int do_ip6, size_t num_tcp, struct infra_cache* infra,
423  struct ub_randstate* rnd, int use_caps_for_id, int* availports,
424  int numavailports, size_t unwanted_threshold, int tcp_mss,
425  void (*unwanted_action)(void*), void* unwanted_param, int do_udp,
426  void* sslctx, int delayclose, struct dt_env *dtenv);
427 
432 void outside_network_delete(struct outside_network* outnet);
433 
438 void outside_network_quit_prepare(struct outside_network* outnet);
439 
451  struct sldns_buffer* packet, int timeout, comm_point_callback_type* callback,
452  void* callback_arg);
453 
466 struct waiting_tcp* pending_tcp_query(struct serviced_query* sq,
467  struct sldns_buffer* packet, int timeout, comm_point_callback_type* callback,
468  void* callback_arg);
469 
476 void pending_delete(struct outside_network* outnet, struct pending* p);
477 
510  struct query_info* qinfo, uint16_t flags, int dnssec, int want_dnssec,
511  int nocaps, int tcp_upstream, int ssl_upstream, char* tls_auth_name,
512  struct sockaddr_storage* addr, socklen_t addrlen, uint8_t* zone,
513  size_t zonelen, struct module_qstate* qstate,
514  comm_point_callback_type* callback, void* callback_arg,
515  struct sldns_buffer* buff, struct module_env* env);
516 
524 void outnet_serviced_query_stop(struct serviced_query* sq, void* cb_arg);
525 
532 size_t outnet_get_mem(struct outside_network* outnet);
533 
541 size_t serviced_get_mem(struct serviced_query* sq);
542 
545 int outnet_get_tcp_fd(struct sockaddr_storage* addr, socklen_t addrlen, int tcp_mss);
546 
558  comm_point_callback_type* cb, void* cb_arg,
559  struct sockaddr_storage* to_addr, socklen_t to_addrlen);
560 
578  comm_point_callback_type* cb, void* cb_arg,
579  struct sockaddr_storage* to_addr, socklen_t to_addrlen,
580  struct sldns_buffer* query, int timeout);
581 
600  comm_point_callback_type* cb, void* cb_arg,
601  struct sockaddr_storage* to_addr, socklen_t to_addrlen, int timeout,
602  int ssl, char* host, char* path);
603 
605 int outnet_tcp_connect(int s, struct sockaddr_storage* addr, socklen_t addrlen);
606 
608 int outnet_udp_cb(struct comm_point* c, void* arg, int error,
609  struct comm_reply *reply_info);
610 
612 int outnet_tcp_cb(struct comm_point* c, void* arg, int error,
613  struct comm_reply *reply_info);
614 
616 void pending_udp_timer_cb(void *arg);
617 
619 void pending_udp_timer_delay_cb(void *arg);
620 
622 void outnet_tcptimer(void* arg);
623 
625 int serviced_udp_callback(struct comm_point* c, void* arg, int error,
626  struct comm_reply* rep);
627 
629 int serviced_tcp_callback(struct comm_point* c, void* arg, int error,
630  struct comm_reply* rep);
631 
633 int pending_cmp(const void* key1, const void* key2);
634 
636 int serviced_cmp(const void* key1, const void* key2);
637 
638 #endif /* OUTSIDE_NETWORK_H */
struct sockaddr_storage addr
struct port_if * ip4_ifs
rbnode_type node
struct port_if * pif
rbnode_type node
struct outside_network * outside_network_create(struct comm_base *base, size_t bufsize, size_t num_ports, char **ifs, int num_ifs, int do_ip4, int do_ip6, size_t num_tcp, struct infra_cache *infra, struct ub_randstate *rnd, int use_caps_for_id, int *availports, int numavailports, size_t unwanted_threshold, int tcp_mss, void(*unwanted_action)(void *), void *unwanted_param, int do_udp, void *sslctx, int delayclose, struct dt_env *dtenv)
int outnet_tcp_connect(int s, struct sockaddr_storage *addr, socklen_t addrlen)
char * tls_auth_name
struct port_comm * unused_fds
comm_point_callback_type * cb
struct pending * udp_wait_first
size_t unwanted_threshold
struct outside_network * outnet
void outnet_tcptimer(void *arg)
struct waiting_tcp * tcp_wait_last
struct comm_timer * timer
enum serviced_query::serviced_query_status status
struct infra_cache * infra
struct edns_option * opt_list
struct comm_point * outnet_comm_point_for_http(struct outside_network *outnet, comm_point_callback_type *cb, void *cb_arg, struct sockaddr_storage *to_addr, socklen_t to_addrlen, int timeout, int ssl, char *host, char *path)
void * cb_arg
Definition: netevent.h:303
struct comm_point * cp
socklen_t addrlen
struct comm_point * outnet_comm_point_for_udp(struct outside_network *outnet, comm_point_callback_type *cb, void *cb_arg, struct sockaddr_storage *to_addr, socklen_t to_addrlen)
void pending_udp_timer_delay_cb(void *arg)
struct comm_point * c
int outnet_tcp_cb(struct comm_point *c, void *arg, int error, struct comm_reply *reply_info)
void(* unwanted_action)(void *)
unsigned short uint16_t
Definition: stdint.h:125
int comm_point_callback_type(struct comm_point *, void *, int, struct comm_reply *)
Definition: netevent.h:76
rbtree_type * serviced
struct timeval last_sent_time
socklen_t addrlen
struct port_comm * pc
unsigned char uint8_t
Definition: stdint.h:124
struct serviced_query * outnet_serviced_query(struct outside_network *outnet, struct query_info *qinfo, uint16_t flags, int dnssec, int want_dnssec, int nocaps, int tcp_upstream, int ssl_upstream, char *tls_auth_name, struct sockaddr_storage *addr, socklen_t addrlen, uint8_t *zone, size_t zonelen, struct module_qstate *qstate, comm_point_callback_type *callback, void *callback_arg, struct sldns_buffer *buff, struct module_env *env)
struct pending_tcp ** tcp_conns
rbtree_type * pending
void * cb_arg
int pending_cmp(const void *key1, const void *key2)
void outnet_serviced_query_stop(struct serviced_query *sq, void *cb_arg)
int serviced_cmp(const void *key1, const void *key2)
struct pending_tcp * tcp_free
struct waiting_tcp * query
struct outside_network * outnet
void pending_udp_timer_cb(void *arg)
struct outside_network * outnet
struct port_if * ip6_ifs
struct sockaddr_storage addr
uint8_t * pkt
int * avail_ports
struct pending * pending_udp_query(struct serviced_query *sq, struct sldns_buffer *packet, int timeout, comm_point_callback_type *callback, void *callback_arg)
struct ub_randstate * rnd
comm_point_callback_type * cb
struct service_callback * cblist
void * ssl
Definition: netevent.h:191
int outnet_get_tcp_fd(struct sockaddr_storage *addr, socklen_t addrlen, int tcp_mss)
struct timeval * now_tv
struct port_comm ** out
void outside_network_quit_prepare(struct outside_network *outnet)
struct pending_tcp * next_free
struct waiting_tcp * next_waiting
struct timeval delay_tv
struct waiting_tcp * pending_tcp_query(struct serviced_query *sq, struct sldns_buffer *packet, int timeout, comm_point_callback_type *callback, void *callback_arg)
size_t serviced_get_mem(struct serviced_query *sq)
size_t outnet_get_mem(struct outside_network *outnet)
struct waiting_tcp * tcp_wait_first
uint8_t * pkt
void outside_network_delete(struct outside_network *outnet)
struct comm_point * outnet_comm_point_for_tcp(struct outside_network *outnet, comm_point_callback_type *cb, void *cb_arg, struct sockaddr_storage *to_addr, socklen_t to_addrlen, struct sldns_buffer *query, int timeout)
comm_point_callback_type * cb
int serviced_tcp_callback(struct comm_point *c, void *arg, int error, struct comm_reply *rep)
struct pending * udp_wait_last
struct service_callback * next
unsigned int id
struct sockaddr_storage addr
int outnet_udp_cb(struct comm_point *c, void *arg, int error, struct comm_reply *reply_info)
struct timeval * timeout
Definition: netevent.h:162
struct comm_base * base
struct pending * next_waiting
int serviced_udp_callback(struct comm_point *c, void *arg, int error, struct comm_reply *rep)
error
Tracks LMDB error codes.
Definition: error.h:44
size_t pkt_len
socklen_t addrlen
struct serviced_query * sq
struct sldns_buffer * udp_buff
void pending_delete(struct outside_network *outnet, struct pending *p)
struct port_comm * next
struct sockaddr_storage addr
struct comm_timer * timer