Deleted Added
full compact
outside_network.h (266114) outside_network.h (276605)
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

--- 31 unchanged lines hidden (view full) ---

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"
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

--- 31 unchanged lines hidden (view full) ---

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"
48struct pending;
49struct pending_timeout;
50struct ub_randstate;
51struct pending_tcp;
52struct waiting_tcp;
53struct waiting_udp;
54struct infra_cache;
55struct port_comm;
56struct port_if;
57struct sldns_buffer;
49struct pending;
50struct pending_timeout;
51struct ub_randstate;
52struct pending_tcp;
53struct waiting_tcp;
54struct waiting_udp;
55struct infra_cache;
56struct port_comm;
57struct port_if;
58struct sldns_buffer;
59struct serviced_query;
60struct dt_env;
58
59/**
60 * Send queries to outside servers and wait for answers from servers.
61 * Contains answer-listen sockets.
62 */
63struct outside_network {
64 /** Base for select calls */
65 struct comm_base* base;

--- 54 unchanged lines hidden (view full) ---

120 /** serviced queries, sorted by qbuf, addr, dnssec */
121 rbtree_t* serviced;
122 /** host cache, pointer but not owned by outnet. */
123 struct infra_cache* infra;
124 /** where to get random numbers */
125 struct ub_randstate* rnd;
126 /** ssl context to create ssl wrapped TCP with DNS connections */
127 void* sslctx;
61
62/**
63 * Send queries to outside servers and wait for answers from servers.
64 * Contains answer-listen sockets.
65 */
66struct outside_network {
67 /** Base for select calls */
68 struct comm_base* base;

--- 54 unchanged lines hidden (view full) ---

123 /** serviced queries, sorted by qbuf, addr, dnssec */
124 rbtree_t* serviced;
125 /** host cache, pointer but not owned by outnet. */
126 struct infra_cache* infra;
127 /** where to get random numbers */
128 struct ub_randstate* rnd;
129 /** ssl context to create ssl wrapped TCP with DNS connections */
130 void* sslctx;
131#ifdef USE_DNSTAP
132 /** dnstap environment */
133 struct dt_env* dtenv;
134#endif
128
129 /**
130 * Array of tcp pending used for outgoing TCP connections.
131 * Each can be used to establish a TCP connection with a server.
132 * The file descriptors are -1 if they are free, and need to be
133 * opened for the tcp connection. Can be used for ip4 and ip6.
134 */
135 struct pending_tcp **tcp_conns;
136 /** number of tcp communication points. */
137 size_t num_tcp;
135
136 /**
137 * Array of tcp pending used for outgoing TCP connections.
138 * Each can be used to establish a TCP connection with a server.
139 * The file descriptors are -1 if they are free, and need to be
140 * opened for the tcp connection. Can be used for ip4 and ip6.
141 */
142 struct pending_tcp **tcp_conns;
143 /** number of tcp communication points. */
144 size_t num_tcp;
145 /** number of tcp communication points in use. */
146 size_t num_tcp_outgoing;
138 /** list of tcp comm points that are free for use */
139 struct pending_tcp* tcp_free;
140 /** list of tcp queries waiting for a buffer */
141 struct waiting_tcp* tcp_wait_first;
142 /** last of waiting query list */
143 struct waiting_tcp* tcp_wait_last;
144};
145

--- 59 unchanged lines hidden (view full) ---

205 /** timeout event */
206 struct comm_timer* timer;
207 /** callback for the timeout, error or reply to the message */
208 comm_point_callback_t* cb;
209 /** callback user argument */
210 void* cb_arg;
211 /** the outside network it is part of */
212 struct outside_network* outnet;
147 /** list of tcp comm points that are free for use */
148 struct pending_tcp* tcp_free;
149 /** list of tcp queries waiting for a buffer */
150 struct waiting_tcp* tcp_wait_first;
151 /** last of waiting query list */
152 struct waiting_tcp* tcp_wait_last;
153};
154

--- 59 unchanged lines hidden (view full) ---

214 /** timeout event */
215 struct comm_timer* timer;
216 /** callback for the timeout, error or reply to the message */
217 comm_point_callback_t* cb;
218 /** callback user argument */
219 void* cb_arg;
220 /** the outside network it is part of */
221 struct outside_network* outnet;
222 /** the corresponding serviced_query */
223 struct serviced_query* sq;
213
214 /*---- filled if udp pending is waiting -----*/
215 /** next in waiting list. */
216 struct pending* next_waiting;
217 /** timeout in msec */
218 int timeout;
219 /** The query itself, the query packet to send. */
220 uint8_t* pkt;

--- 81 unchanged lines hidden (view full) ---

302 * EDNS record. */
303 uint8_t* qbuf;
304 /** length of qbuf. */
305 size_t qbuflen;
306 /** If an EDNS section is included, the DO/CD bit will be turned on. */
307 int dnssec;
308 /** We want signatures, or else the answer is likely useless */
309 int want_dnssec;
224
225 /*---- filled if udp pending is waiting -----*/
226 /** next in waiting list. */
227 struct pending* next_waiting;
228 /** timeout in msec */
229 int timeout;
230 /** The query itself, the query packet to send. */
231 uint8_t* pkt;

--- 81 unchanged lines hidden (view full) ---

313 * EDNS record. */
314 uint8_t* qbuf;
315 /** length of qbuf. */
316 size_t qbuflen;
317 /** If an EDNS section is included, the DO/CD bit will be turned on. */
318 int dnssec;
319 /** We want signatures, or else the answer is likely useless */
320 int want_dnssec;
321 /** ignore capsforid */
322 int nocaps;
310 /** tcp upstream used, use tcp, or ssl_upstream for SSL */
311 int tcp_upstream, ssl_upstream;
312 /** where to send it */
313 struct sockaddr_storage addr;
314 /** length of addr field in use. */
315 socklen_t addrlen;
316 /** zone name, uncompressed domain name in wireformat */
317 uint8_t* zone;

--- 60 unchanged lines hidden (view full) ---

378 * @param numavailports: number of available ports in array.
379 * @param unwanted_threshold: when to take defensive action.
380 * @param unwanted_action: the action to take.
381 * @param unwanted_param: user parameter to action.
382 * @param do_udp: if udp is done.
383 * @param sslctx: context to create outgoing connections with (if enabled).
384 * @param delayclose: if not 0, udp sockets are delayed before timeout closure.
385 * msec to wait on timeouted udp sockets.
323 /** tcp upstream used, use tcp, or ssl_upstream for SSL */
324 int tcp_upstream, ssl_upstream;
325 /** where to send it */
326 struct sockaddr_storage addr;
327 /** length of addr field in use. */
328 socklen_t addrlen;
329 /** zone name, uncompressed domain name in wireformat */
330 uint8_t* zone;

--- 60 unchanged lines hidden (view full) ---

391 * @param numavailports: number of available ports in array.
392 * @param unwanted_threshold: when to take defensive action.
393 * @param unwanted_action: the action to take.
394 * @param unwanted_param: user parameter to action.
395 * @param do_udp: if udp is done.
396 * @param sslctx: context to create outgoing connections with (if enabled).
397 * @param delayclose: if not 0, udp sockets are delayed before timeout closure.
398 * msec to wait on timeouted udp sockets.
399 * @param dtenv: environment to send dnstap events with (if enabled).
386 * @return: the new structure (with no pending answers) or NULL on error.
387 */
388struct outside_network* outside_network_create(struct comm_base* base,
389 size_t bufsize, size_t num_ports, char** ifs, int num_ifs,
390 int do_ip4, int do_ip6, size_t num_tcp, struct infra_cache* infra,
391 struct ub_randstate* rnd, int use_caps_for_id, int* availports,
392 int numavailports, size_t unwanted_threshold,
393 void (*unwanted_action)(void*), void* unwanted_param, int do_udp,
400 * @return: the new structure (with no pending answers) or NULL on error.
401 */
402struct outside_network* outside_network_create(struct comm_base* base,
403 size_t bufsize, size_t num_ports, char** ifs, int num_ifs,
404 int do_ip4, int do_ip6, size_t num_tcp, struct infra_cache* infra,
405 struct ub_randstate* rnd, int use_caps_for_id, int* availports,
406 int numavailports, size_t unwanted_threshold,
407 void (*unwanted_action)(void*), void* unwanted_param, int do_udp,
394 void* sslctx, int delayclose);
408 void* sslctx, int delayclose, struct dt_env *dtenv);
395
396/**
397 * Delete outside_network structure.
398 * @param outnet: object to delete.
399 */
400void outside_network_delete(struct outside_network* outnet);
401
402/**
403 * Prepare for quit. Sends no more queries, even if queued up.
404 * @param outnet: object to prepare for removal
405 */
406void outside_network_quit_prepare(struct outside_network* outnet);
407
408/**
409 * Send UDP query, create pending answer.
410 * Changes the ID for the query to be random and unique for that destination.
409
410/**
411 * Delete outside_network structure.
412 * @param outnet: object to delete.
413 */
414void outside_network_delete(struct outside_network* outnet);
415
416/**
417 * Prepare for quit. Sends no more queries, even if queued up.
418 * @param outnet: object to prepare for removal
419 */
420void outside_network_quit_prepare(struct outside_network* outnet);
421
422/**
423 * Send UDP query, create pending answer.
424 * Changes the ID for the query to be random and unique for that destination.
411 * @param outnet: provides the event handling
425 * @param sq: serviced query.
412 * @param packet: wireformat query to send to destination.
426 * @param packet: wireformat query to send to destination.
413 * @param addr: address to send to.
414 * @param addrlen: length of addr.
415 * @param timeout: in milliseconds from now.
416 * @param callback: function to call on error, timeout or reply.
417 * @param callback_arg: user argument for callback function.
418 * @return: NULL on error for malloc or socket. Else the pending query object.
419 */
427 * @param timeout: in milliseconds from now.
428 * @param callback: function to call on error, timeout or reply.
429 * @param callback_arg: user argument for callback function.
430 * @return: NULL on error for malloc or socket. Else the pending query object.
431 */
420struct pending* pending_udp_query(struct outside_network* outnet,
421 struct sldns_buffer* packet, struct sockaddr_storage* addr,
422 socklen_t addrlen, int timeout, comm_point_callback_t* callback,
432struct pending* pending_udp_query(struct serviced_query* sq,
433 struct sldns_buffer* packet, int timeout, comm_point_callback_t* callback,
423 void* callback_arg);
424
425/**
426 * Send TCP query. May wait for TCP buffer. Selects ID to be random, and
427 * checks id.
434 void* callback_arg);
435
436/**
437 * Send TCP query. May wait for TCP buffer. Selects ID to be random, and
438 * checks id.
428 * @param outnet: provides the event handling.
439 * @param sq: serviced query.
429 * @param packet: wireformat query to send to destination. copied from.
440 * @param packet: wireformat query to send to destination. copied from.
430 * @param addr: address to send to.
431 * @param addrlen: length of addr.
432 * @param timeout: in seconds from now.
433 * Timer starts running now. Timer may expire if all buffers are used,
434 * without any query been sent to the server yet.
435 * @param callback: function to call on error, timeout or reply.
436 * @param callback_arg: user argument for callback function.
441 * @param timeout: in seconds from now.
442 * Timer starts running now. Timer may expire if all buffers are used,
443 * without any query been sent to the server yet.
444 * @param callback: function to call on error, timeout or reply.
445 * @param callback_arg: user argument for callback function.
437 * @param ssl_upstream: if the tcp connection must use SSL.
438 * @return: false on error for malloc or socket. Else the pending TCP object.
439 */
446 * @return: false on error for malloc or socket. Else the pending TCP object.
447 */
440struct waiting_tcp* pending_tcp_query(struct outside_network* outnet,
441 struct sldns_buffer* packet, struct sockaddr_storage* addr,
442 socklen_t addrlen, int timeout, comm_point_callback_t* callback,
443 void* callback_arg, int ssl_upstream);
448struct waiting_tcp* pending_tcp_query(struct serviced_query* sq,
449 struct sldns_buffer* packet, int timeout, comm_point_callback_t* callback,
450 void* callback_arg);
444
445/**
446 * Delete pending answer.
447 * @param outnet: outside network the pending query is part of.
448 * Internal feature: if outnet is NULL, p is not unlinked from rbtree.
449 * @param p: deleted
450 */
451void pending_delete(struct outside_network* outnet, struct pending* p);

--- 7 unchanged lines hidden (view full) ---

459 * @param qtype: rrset type to query (host format)
460 * @param qclass: query class. (host format)
461 * @param flags: flags u16 (host format), includes opcode, CD bit.
462 * @param dnssec: if set, DO bit is set in EDNS queries.
463 * If the value includes BIT_CD, CD bit is set when in EDNS queries.
464 * If the value includes BIT_DO, DO bit is set when in EDNS queries.
465 * @param want_dnssec: signatures are needed, without EDNS the answer is
466 * likely to be useless.
451
452/**
453 * Delete pending answer.
454 * @param outnet: outside network the pending query is part of.
455 * Internal feature: if outnet is NULL, p is not unlinked from rbtree.
456 * @param p: deleted
457 */
458void pending_delete(struct outside_network* outnet, struct pending* p);

--- 7 unchanged lines hidden (view full) ---

466 * @param qtype: rrset type to query (host format)
467 * @param qclass: query class. (host format)
468 * @param flags: flags u16 (host format), includes opcode, CD bit.
469 * @param dnssec: if set, DO bit is set in EDNS queries.
470 * If the value includes BIT_CD, CD bit is set when in EDNS queries.
471 * If the value includes BIT_DO, DO bit is set when in EDNS queries.
472 * @param want_dnssec: signatures are needed, without EDNS the answer is
473 * likely to be useless.
474 * @param nocaps: ignore use_caps_for_id and use unperturbed qname.
467 * @param tcp_upstream: use TCP for upstream queries.
468 * @param ssl_upstream: use SSL for upstream queries.
469 * @param callback: callback function.
470 * @param callback_arg: user argument to callback function.
471 * @param addr: to which server to send the query.
472 * @param addrlen: length of addr.
473 * @param zone: name of the zone of the delegation point. wireformat dname.
474 This is the delegation point name for which the server is deemed
475 authoritative.
476 * @param zonelen: length of zone.
477 * @param buff: scratch buffer to create query contents in. Empty on exit.
478 * @return 0 on error, or pointer to serviced query that is used to answer
479 * this serviced query may be shared with other callbacks as well.
480 */
481struct serviced_query* outnet_serviced_query(struct outside_network* outnet,
482 uint8_t* qname, size_t qnamelen, uint16_t qtype, uint16_t qclass,
475 * @param tcp_upstream: use TCP for upstream queries.
476 * @param ssl_upstream: use SSL for upstream queries.
477 * @param callback: callback function.
478 * @param callback_arg: user argument to callback function.
479 * @param addr: to which server to send the query.
480 * @param addrlen: length of addr.
481 * @param zone: name of the zone of the delegation point. wireformat dname.
482 This is the delegation point name for which the server is deemed
483 authoritative.
484 * @param zonelen: length of zone.
485 * @param buff: scratch buffer to create query contents in. Empty on exit.
486 * @return 0 on error, or pointer to serviced query that is used to answer
487 * this serviced query may be shared with other callbacks as well.
488 */
489struct serviced_query* outnet_serviced_query(struct outside_network* outnet,
490 uint8_t* qname, size_t qnamelen, uint16_t qtype, uint16_t qclass,
483 uint16_t flags, int dnssec, int want_dnssec, int tcp_upstream,
484 int ssl_upstream, struct sockaddr_storage* addr, socklen_t addrlen,
485 uint8_t* zone, size_t zonelen, comm_point_callback_t* callback,
486 void* callback_arg, struct sldns_buffer* buff);
491 uint16_t flags, int dnssec, int want_dnssec, int nocaps,
492 int tcp_upstream, int ssl_upstream, struct sockaddr_storage* addr,
493 socklen_t addrlen, uint8_t* zone, size_t zonelen,
494 comm_point_callback_t* callback, void* callback_arg,
495 struct sldns_buffer* buff);
487
488/**
489 * Remove service query callback.
490 * If that leads to zero callbacks, the query is completely cancelled.
491 * @param sq: serviced query to adjust.
492 * @param cb_arg: callback argument of callback that needs removal.
493 * same as the callback_arg to outnet_serviced_query().
494 */

--- 51 unchanged lines hidden ---
496
497/**
498 * Remove service query callback.
499 * If that leads to zero callbacks, the query is completely cancelled.
500 * @param sq: serviced query to adjust.
501 * @param cb_arg: callback argument of callback that needs removal.
502 * same as the callback_arg to outnet_serviced_query().
503 */

--- 51 unchanged lines hidden ---