xref: /freebsd/contrib/unbound/services/outside_network.h (revision 6132212808e8dccedc9e5d85fea4390c2f38059a)
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 
36 /**
37  * \file
38  *
39  * This file has functions to send queries to authoritative servers,
40  * and wait for the pending answer, with timeouts.
41  */
42 
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 
66 /**
67  * Send queries to outside servers and wait for answers from servers.
68  * Contains answer-listen sockets.
69  */
70 struct outside_network {
71 	/** Base for select calls */
72 	struct comm_base* base;
73 	/** pointer to time in seconds */
74 	time_t* now_secs;
75 	/** pointer to time in microseconds */
76 	struct timeval* now_tv;
77 
78 	/** buffer shared by UDP connections, since there is only one
79 	    datagram at any time. */
80 	struct sldns_buffer* udp_buff;
81 	/** serviced_callbacks malloc overhead when processing multiple
82 	 * identical serviced queries to the same server. */
83 	size_t svcd_overhead;
84 	/** use x20 bits to encode additional ID random bits */
85 	int use_caps_for_id;
86 	/** outside network wants to quit. Stop queued msgs from sent. */
87 	int want_to_quit;
88 
89 	/** number of unwanted replies received (for statistics) */
90 	size_t unwanted_replies;
91 	/** cumulative total of unwanted replies (for defense) */
92 	size_t unwanted_total;
93 	/** threshold when to take defensive action. If 0 then never. */
94 	size_t unwanted_threshold;
95 	/** what action to take, called when defensive action is needed */
96 	void (*unwanted_action)(void*);
97 	/** user param for action */
98 	void* unwanted_param;
99 
100 	/** linked list of available commpoints, unused file descriptors,
101 	 * for use as outgoing UDP ports. cp.fd=-1 in them. */
102 	struct port_comm* unused_fds;
103 	/** if udp is done */
104 	int do_udp;
105 	/** if udp is delay-closed (delayed answers do not meet closed port)*/
106 	int delayclose;
107 	/** timeout for delayclose */
108 	struct timeval delay_tv;
109 
110 	/** array of outgoing IP4 interfaces */
111 	struct port_if* ip4_ifs;
112 	/** number of outgoing IP4 interfaces */
113 	int num_ip4;
114 
115 	/** array of outgoing IP6 interfaces */
116 	struct port_if* ip6_ifs;
117 	/** number of outgoing IP6 interfaces */
118 	int num_ip6;
119 
120 	/** pending udp queries waiting to be sent out, waiting for fd */
121 	struct pending* udp_wait_first;
122 	/** last pending udp query in list */
123 	struct pending* udp_wait_last;
124 
125 	/** pending udp answers. sorted by id, addr */
126 	rbtree_type* pending;
127 	/** serviced queries, sorted by qbuf, addr, dnssec */
128 	rbtree_type* serviced;
129 	/** host cache, pointer but not owned by outnet. */
130 	struct infra_cache* infra;
131 	/** where to get random numbers */
132 	struct ub_randstate* rnd;
133 	/** ssl context to create ssl wrapped TCP with DNS connections */
134 	void* sslctx;
135 	/** if SNI will be used for TLS connections */
136 	int tls_use_sni;
137 #ifdef USE_DNSTAP
138 	/** dnstap environment */
139 	struct dt_env* dtenv;
140 #endif
141 	/** maximum segment size of tcp socket */
142 	int tcp_mss;
143 	/** IP_TOS socket option requested on the sockets */
144 	int ip_dscp;
145 
146 	/**
147 	 * Array of tcp pending used for outgoing TCP connections.
148 	 * Each can be used to establish a TCP connection with a server.
149 	 * The file descriptors are -1 if they are free, and need to be
150 	 * opened for the tcp connection. Can be used for ip4 and ip6.
151 	 */
152 	struct pending_tcp **tcp_conns;
153 	/** number of tcp communication points. */
154 	size_t num_tcp;
155 	/** number of tcp communication points in use. */
156 	size_t num_tcp_outgoing;
157 	/** list of tcp comm points that are free for use */
158 	struct pending_tcp* tcp_free;
159 	/** list of tcp queries waiting for a buffer */
160 	struct waiting_tcp* tcp_wait_first;
161 	/** last of waiting query list */
162 	struct waiting_tcp* tcp_wait_last;
163 };
164 
165 /**
166  * Outgoing interface. Ports available and currently used are tracked
167  * per interface
168  */
169 struct port_if {
170 	/** address ready to allocate new socket (except port no). */
171 	struct sockaddr_storage addr;
172 	/** length of addr field */
173 	socklen_t addrlen;
174 
175 	/** prefix length of network address (in bits), for randomisation.
176 	 * if 0, no randomisation. */
177 	int pfxlen;
178 
179 #ifndef DISABLE_EXPLICIT_PORT_RANDOMISATION
180 	/** the available ports array. These are unused.
181 	 * Only the first total-inuse part is filled. */
182 	int* avail_ports;
183 	/** the total number of available ports (size of the array) */
184 	int avail_total;
185 #endif
186 
187 	/** array of the commpoints currently in use.
188 	 * allocated for max number of fds, first part in use. */
189 	struct port_comm** out;
190 	/** max number of fds, size of out array */
191 	int maxout;
192 	/** number of commpoints (and thus also ports) in use */
193 	int inuse;
194 };
195 
196 /**
197  * Outgoing commpoint for UDP port.
198  */
199 struct port_comm {
200 	/** next in free list */
201 	struct port_comm* next;
202 	/** which port number (when in use) */
203 	int number;
204 	/** interface it is used in */
205 	struct port_if* pif;
206 	/** index in the out array of the interface */
207 	int index;
208 	/** number of outstanding queries on this port */
209 	int num_outstanding;
210 	/** UDP commpoint, fd=-1 if not in use */
211 	struct comm_point* cp;
212 };
213 
214 /**
215  * A query that has an answer pending for it.
216  */
217 struct pending {
218 	/** redblacktree entry, key is the pending struct(id, addr). */
219 	rbnode_type node;
220 	/** the ID for the query. int so that a value out of range can
221 	 * be used to signify a pending that is for certain not present in
222 	 * the rbtree. (and for which deletion is safe). */
223 	unsigned int id;
224 	/** remote address. */
225 	struct sockaddr_storage addr;
226 	/** length of addr field in use. */
227 	socklen_t addrlen;
228 	/** comm point it was sent on (and reply must come back on). */
229 	struct port_comm* pc;
230 	/** timeout event */
231 	struct comm_timer* timer;
232 	/** callback for the timeout, error or reply to the message */
233 	comm_point_callback_type* cb;
234 	/** callback user argument */
235 	void* cb_arg;
236 	/** the outside network it is part of */
237 	struct outside_network* outnet;
238 	/** the corresponding serviced_query */
239 	struct serviced_query* sq;
240 
241 	/*---- filled if udp pending is waiting -----*/
242 	/** next in waiting list. */
243 	struct pending* next_waiting;
244 	/** timeout in msec */
245 	int timeout;
246 	/** The query itself, the query packet to send. */
247 	uint8_t* pkt;
248 	/** length of query packet. */
249 	size_t pkt_len;
250 };
251 
252 /**
253  * Pending TCP query to server.
254  */
255 struct pending_tcp {
256 	/** next in list of free tcp comm points, or NULL. */
257 	struct pending_tcp* next_free;
258 	/** the ID for the query; checked in reply */
259 	uint16_t id;
260 	/** tcp comm point it was sent on (and reply must come back on). */
261 	struct comm_point* c;
262 	/** the query being serviced, NULL if the pending_tcp is unused. */
263 	struct waiting_tcp* query;
264 };
265 
266 /**
267  * Query waiting for TCP buffer.
268  */
269 struct waiting_tcp {
270 	/**
271 	 * next in waiting list.
272 	 * if pkt==0, this points to the pending_tcp structure.
273 	 */
274 	struct waiting_tcp* next_waiting;
275 	/** timeout event; timer keeps running whether the query is
276 	 * waiting for a buffer or the tcp reply is pending */
277 	struct comm_timer* timer;
278 	/** the outside network it is part of */
279 	struct outside_network* outnet;
280 	/** remote address. */
281 	struct sockaddr_storage addr;
282 	/** length of addr field in use. */
283 	socklen_t addrlen;
284 	/**
285 	 * The query itself, the query packet to send.
286 	 * allocated after the waiting_tcp structure.
287 	 * set to NULL when the query is serviced and it part of pending_tcp.
288 	 * if this is NULL, the next_waiting points to the pending_tcp.
289 	 */
290 	uint8_t* pkt;
291 	/** length of query packet. */
292 	size_t pkt_len;
293 	/** callback for the timeout, error or reply to the message */
294 	comm_point_callback_type* cb;
295 	/** callback user argument */
296 	void* cb_arg;
297 	/** if it uses ssl upstream */
298 	int ssl_upstream;
299 	/** ref to the tls_auth_name from the serviced_query */
300 	char* tls_auth_name;
301 };
302 
303 /**
304  * Callback to party interested in serviced query results.
305  */
306 struct service_callback {
307 	/** next in callback list */
308 	struct service_callback* next;
309 	/** callback function */
310 	comm_point_callback_type* cb;
311 	/** user argument for callback function */
312 	void* cb_arg;
313 };
314 
315 /** fallback size for fragmentation for EDNS in IPv4 */
316 #define EDNS_FRAG_SIZE_IP4 1472
317 /** fallback size for EDNS in IPv6, fits one fragment with ip6-tunnel-ids */
318 #define EDNS_FRAG_SIZE_IP6 1232
319 
320 /**
321  * Query service record.
322  * Contains query and destination. UDP, TCP, EDNS are all tried.
323  * complete with retries and timeouts. A number of interested parties can
324  * receive a callback.
325  */
326 struct serviced_query {
327 	/** The rbtree node, key is this record */
328 	rbnode_type node;
329 	/** The query that needs to be answered. Starts with flags u16,
330 	 * then qdcount, ..., including qname, qtype, qclass. Does not include
331 	 * EDNS record. */
332 	uint8_t* qbuf;
333 	/** length of qbuf. */
334 	size_t qbuflen;
335 	/** If an EDNS section is included, the DO/CD bit will be turned on. */
336 	int dnssec;
337 	/** We want signatures, or else the answer is likely useless */
338 	int want_dnssec;
339 	/** ignore capsforid */
340 	int nocaps;
341 	/** tcp upstream used, use tcp, or ssl_upstream for SSL */
342 	int tcp_upstream, ssl_upstream;
343 	/** the name of the tls authentication name, eg. 'ns.example.com'
344 	 * or NULL */
345 	char* tls_auth_name;
346 	/** where to send it */
347 	struct sockaddr_storage addr;
348 	/** length of addr field in use. */
349 	socklen_t addrlen;
350 	/** zone name, uncompressed domain name in wireformat */
351 	uint8_t* zone;
352 	/** length of zone name */
353 	size_t zonelen;
354 	/** qtype */
355 	int qtype;
356 	/** current status */
357 	enum serviced_query_status {
358 		/** initial status */
359 		serviced_initial,
360 		/** UDP with EDNS sent */
361 		serviced_query_UDP_EDNS,
362 		/** UDP without EDNS sent */
363 		serviced_query_UDP,
364 		/** TCP with EDNS sent */
365 		serviced_query_TCP_EDNS,
366 		/** TCP without EDNS sent */
367 		serviced_query_TCP,
368 		/** probe to test noEDNS0 (EDNS gives FORMERRorNOTIMP) */
369 		serviced_query_UDP_EDNS_fallback,
370 		/** probe to test TCP noEDNS0 (EDNS gives FORMERRorNOTIMP) */
371 		serviced_query_TCP_EDNS_fallback,
372 		/** send UDP query with EDNS1480 (or 1280) */
373 		serviced_query_UDP_EDNS_FRAG
374 	}
375 		/** variable with current status */
376 		status;
377 	/** true if serviced_query is scheduled for deletion already */
378 	int to_be_deleted;
379 	/** number of UDP retries */
380 	int retry;
381 	/** time last UDP was sent */
382 	struct timeval last_sent_time;
383 	/** rtt of last message */
384 	int last_rtt;
385 	/** do we know edns probe status already, for UDP_EDNS queries */
386 	int edns_lame_known;
387 	/** edns options to use for sending upstream packet */
388 	struct edns_option* opt_list;
389 	/** outside network this is part of */
390 	struct outside_network* outnet;
391 	/** list of interested parties that need callback on results. */
392 	struct service_callback* cblist;
393 	/** the UDP or TCP query that is pending, see status which */
394 	void* pending;
395 };
396 
397 /**
398  * Create outside_network structure with N udp ports.
399  * @param base: the communication base to use for event handling.
400  * @param bufsize: size for network buffers.
401  * @param num_ports: number of udp ports to open per interface.
402  * @param ifs: interface names (or NULL for default interface).
403  *    These interfaces must be able to access all authoritative servers.
404  * @param num_ifs: number of names in array ifs.
405  * @param do_ip4: service IP4.
406  * @param do_ip6: service IP6.
407  * @param num_tcp: number of outgoing tcp buffers to preallocate.
408  * @param dscp: DSCP to use.
409  * @param infra: pointer to infra cached used for serviced queries.
410  * @param rnd: stored to create random numbers for serviced queries.
411  * @param use_caps_for_id: enable to use 0x20 bits to encode id randomness.
412  * @param availports: array of available ports.
413  * @param numavailports: number of available ports in array.
414  * @param unwanted_threshold: when to take defensive action.
415  * @param unwanted_action: the action to take.
416  * @param unwanted_param: user parameter to action.
417  * @param tcp_mss: maximum segment size of tcp socket.
418  * @param do_udp: if udp is done.
419  * @param sslctx: context to create outgoing connections with (if enabled).
420  * @param delayclose: if not 0, udp sockets are delayed before timeout closure.
421  * 	msec to wait on timeouted udp sockets.
422  * @param tls_use_sni: if SNI is used for TLS connections.
423  * @param dtenv: environment to send dnstap events with (if enabled).
424  * @return: the new structure (with no pending answers) or NULL on error.
425  */
426 struct outside_network* outside_network_create(struct comm_base* base,
427 	size_t bufsize, size_t num_ports, char** ifs, int num_ifs,
428 	int do_ip4, int do_ip6, size_t num_tcp, int dscp, struct infra_cache* infra,
429 	struct ub_randstate* rnd, int use_caps_for_id, int* availports,
430 	int numavailports, size_t unwanted_threshold, int tcp_mss,
431 	void (*unwanted_action)(void*), void* unwanted_param, int do_udp,
432 	void* sslctx, int delayclose, int tls_use_sni, struct dt_env *dtenv);
433 
434 /**
435  * Delete outside_network structure.
436  * @param outnet: object to delete.
437  */
438 void outside_network_delete(struct outside_network* outnet);
439 
440 /**
441  * Prepare for quit. Sends no more queries, even if queued up.
442  * @param outnet: object to prepare for removal
443  */
444 void outside_network_quit_prepare(struct outside_network* outnet);
445 
446 /**
447  * Send UDP query, create pending answer.
448  * Changes the ID for the query to be random and unique for that destination.
449  * @param sq: serviced query.
450  * @param packet: wireformat query to send to destination.
451  * @param timeout: in milliseconds from now.
452  * @param callback: function to call on error, timeout or reply.
453  * @param callback_arg: user argument for callback function.
454  * @return: NULL on error for malloc or socket. Else the pending query object.
455  */
456 struct pending* pending_udp_query(struct serviced_query* sq,
457 	struct sldns_buffer* packet, int timeout, comm_point_callback_type* callback,
458 	void* callback_arg);
459 
460 /**
461  * Send TCP query. May wait for TCP buffer. Selects ID to be random, and
462  * checks id.
463  * @param sq: serviced query.
464  * @param packet: wireformat query to send to destination. copied from.
465  * @param timeout: in milliseconds from now.
466  *    Timer starts running now. Timer may expire if all buffers are used,
467  *    without any query been sent to the server yet.
468  * @param callback: function to call on error, timeout or reply.
469  * @param callback_arg: user argument for callback function.
470  * @return: false on error for malloc or socket. Else the pending TCP object.
471  */
472 struct waiting_tcp* pending_tcp_query(struct serviced_query* sq,
473 	struct sldns_buffer* packet, int timeout, comm_point_callback_type* callback,
474 	void* callback_arg);
475 
476 /**
477  * Delete pending answer.
478  * @param outnet: outside network the pending query is part of.
479  *    Internal feature: if outnet is NULL, p is not unlinked from rbtree.
480  * @param p: deleted
481  */
482 void pending_delete(struct outside_network* outnet, struct pending* p);
483 
484 /**
485  * Perform a serviced query to the authoritative servers.
486  * Duplicate efforts are detected, and EDNS, TCP and UDP retry is performed.
487  * @param outnet: outside network, with rbtree of serviced queries.
488  * @param qinfo: query info.
489  * @param flags: flags u16 (host format), includes opcode, CD bit.
490  * @param dnssec: if set, DO bit is set in EDNS queries.
491  *	If the value includes BIT_CD, CD bit is set when in EDNS queries.
492  *	If the value includes BIT_DO, DO bit is set when in EDNS queries.
493  * @param want_dnssec: signatures are needed, without EDNS the answer is
494  * 	likely to be useless.
495  * @param nocaps: ignore use_caps_for_id and use unperturbed qname.
496  * @param tcp_upstream: use TCP for upstream queries.
497  * @param ssl_upstream: use SSL for upstream queries.
498  * @param tls_auth_name: when ssl_upstream is true, use this name to check
499  * 	the server's peer certificate.
500  * @param addr: to which server to send the query.
501  * @param addrlen: length of addr.
502  * @param zone: name of the zone of the delegation point. wireformat dname.
503 	This is the delegation point name for which the server is deemed
504 	authoritative.
505  * @param zonelen: length of zone.
506  * @param qstate: module qstate. Mainly for inspecting the available
507  *	edns_opts_lists.
508  * @param callback: callback function.
509  * @param callback_arg: user argument to callback function.
510  * @param buff: scratch buffer to create query contents in. Empty on exit.
511  * @param env: the module environment.
512  * @return 0 on error, or pointer to serviced query that is used to answer
513  *	this serviced query may be shared with other callbacks as well.
514  */
515 struct serviced_query* outnet_serviced_query(struct outside_network* outnet,
516 	struct query_info* qinfo, uint16_t flags, int dnssec, int want_dnssec,
517 	int nocaps, int tcp_upstream, int ssl_upstream, char* tls_auth_name,
518 	struct sockaddr_storage* addr, socklen_t addrlen, uint8_t* zone,
519 	size_t zonelen, struct module_qstate* qstate,
520 	comm_point_callback_type* callback, void* callback_arg,
521 	struct sldns_buffer* buff, struct module_env* env);
522 
523 /**
524  * Remove service query callback.
525  * If that leads to zero callbacks, the query is completely cancelled.
526  * @param sq: serviced query to adjust.
527  * @param cb_arg: callback argument of callback that needs removal.
528  *	same as the callback_arg to outnet_serviced_query().
529  */
530 void outnet_serviced_query_stop(struct serviced_query* sq, void* cb_arg);
531 
532 /**
533  * Get memory size in use by outside network.
534  * Counts buffers and outstanding query (serviced queries) malloced data.
535  * @param outnet: outside network structure.
536  * @return size in bytes.
537  */
538 size_t outnet_get_mem(struct outside_network* outnet);
539 
540 /**
541  * Get memory size in use by serviced query while it is servicing callbacks.
542  * This takes into account the pre-deleted status of it; it will be deleted
543  * when the callbacks are done.
544  * @param sq: serviced query.
545  * @return size in bytes.
546  */
547 size_t serviced_get_mem(struct serviced_query* sq);
548 
549 /** get TCP file descriptor for address, returns -1 on failure,
550  * tcp_mss is 0 or maxseg size to set for TCP packets. */
551 int outnet_get_tcp_fd(struct sockaddr_storage* addr, socklen_t addrlen, int tcp_mss, int dscp);
552 
553 /**
554  * Create udp commpoint suitable for sending packets to the destination.
555  * @param outnet: outside_network with the comm_base it is attached to,
556  * 	with the outgoing interfaces chosen from, and rnd gen for random.
557  * @param cb: callback function for the commpoint.
558  * @param cb_arg: callback argument for cb.
559  * @param to_addr: intended destination.
560  * @param to_addrlen: length of to_addr.
561  * @return commpoint that you can comm_point_send_udp_msg with, or NULL.
562  */
563 struct comm_point* outnet_comm_point_for_udp(struct outside_network* outnet,
564 	comm_point_callback_type* cb, void* cb_arg,
565 	struct sockaddr_storage* to_addr, socklen_t to_addrlen);
566 
567 /**
568  * Create tcp commpoint suitable for communication to the destination.
569  * It also performs connect() to the to_addr.
570  * @param outnet: outside_network with the comm_base it is attached to,
571  * 	and the tcp_mss.
572  * @param cb: callback function for the commpoint.
573  * @param cb_arg: callback argument for cb.
574  * @param to_addr: intended destination.
575  * @param to_addrlen: length of to_addr.
576  * @param query: initial packet to send writing, in buffer.  It is copied
577  * 	to the commpoint buffer that is created.
578  * @param timeout: timeout for the TCP connection.
579  * 	timeout in milliseconds, or -1 for no (change to the) timeout.
580  *	So seconds*1000.
581  * @param ssl: set to true for TLS.
582  * @param host: hostname for host name verification of TLS (or NULL if no TLS).
583  * @return tcp_out commpoint, or NULL.
584  */
585 struct comm_point* outnet_comm_point_for_tcp(struct outside_network* outnet,
586 	comm_point_callback_type* cb, void* cb_arg,
587 	struct sockaddr_storage* to_addr, socklen_t to_addrlen,
588 	struct sldns_buffer* query, int timeout, int ssl, char* host);
589 
590 /**
591  * Create http commpoint suitable for communication to the destination.
592  * Creates the http request buffer. It also performs connect() to the to_addr.
593  * @param outnet: outside_network with the comm_base it is attached to,
594  * 	and the tcp_mss.
595  * @param cb: callback function for the commpoint.
596  * @param cb_arg: callback argument for cb.
597  * @param to_addr: intended destination.
598  * @param to_addrlen: length of to_addr.
599  * @param timeout: timeout for the TCP connection.
600  * 	timeout in milliseconds, or -1 for no (change to the) timeout.
601  *	So seconds*1000.
602  * @param ssl: set to true for https.
603  * @param host: hostname to use for the destination. part of http request.
604  * @param path: pathname to lookup, eg. name of the file on the destination.
605  * @return http_out commpoint, or NULL.
606  */
607 struct comm_point* outnet_comm_point_for_http(struct outside_network* outnet,
608 	comm_point_callback_type* cb, void* cb_arg,
609 	struct sockaddr_storage* to_addr, socklen_t to_addrlen, int timeout,
610 	int ssl, char* host, char* path);
611 
612 /** connect tcp connection to addr, 0 on failure */
613 int outnet_tcp_connect(int s, struct sockaddr_storage* addr, socklen_t addrlen);
614 
615 /** callback for incoming udp answers from the network */
616 int outnet_udp_cb(struct comm_point* c, void* arg, int error,
617 	struct comm_reply *reply_info);
618 
619 /** callback for pending tcp connections */
620 int outnet_tcp_cb(struct comm_point* c, void* arg, int error,
621 	struct comm_reply *reply_info);
622 
623 /** callback for udp timeout */
624 void pending_udp_timer_cb(void *arg);
625 
626 /** callback for udp delay for timeout */
627 void pending_udp_timer_delay_cb(void *arg);
628 
629 /** callback for outgoing TCP timer event */
630 void outnet_tcptimer(void* arg);
631 
632 /** callback for serviced query UDP answers */
633 int serviced_udp_callback(struct comm_point* c, void* arg, int error,
634         struct comm_reply* rep);
635 
636 /** TCP reply or error callback for serviced queries */
637 int serviced_tcp_callback(struct comm_point* c, void* arg, int error,
638         struct comm_reply* rep);
639 
640 /** compare function of pending rbtree */
641 int pending_cmp(const void* key1, const void* key2);
642 
643 /** compare function of serviced query rbtree */
644 int serviced_cmp(const void* key1, const void* key2);
645 
646 #endif /* OUTSIDE_NETWORK_H */
647