This file has functions to send queries to authoritative servers, and wait for the pending answer, with timeouts. More...
Data Structures | |
| struct | outside_network |
| Send queries to outside servers and wait for answers from servers. More... | |
| struct | port_if |
| Outgoing interface. More... | |
| struct | port_comm |
| Outgoing commpoint for UDP port. More... | |
| struct | pending |
| A query that has an answer pending for it. More... | |
| struct | pending_tcp |
| Pending TCP query to server. More... | |
| struct | waiting_tcp |
| Query waiting for TCP buffer. More... | |
| struct | service_callback |
| Callback to party interested in serviced query results. More... | |
| struct | serviced_query |
| Query service record. More... | |
Defines | |
| #define | EDNS_FRAG_SIZE_IP4 1480 |
| fallback size for fragmentation for EDNS in IPv4 | |
| #define | EDNS_FRAG_SIZE_IP6 1260 |
| fallback size for EDNS in IPv6, fits one fragment with ip6-tunnel-ids | |
Functions | |
| 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, void(*unwanted_action)(void *), void *unwanted_param, int do_udp, void *sslctx) |
| Create outside_network structure with N udp ports. | |
| void | outside_network_delete (struct outside_network *outnet) |
| Delete outside_network structure. | |
| void | outside_network_quit_prepare (struct outside_network *outnet) |
| Prepare for quit. | |
| struct pending * | pending_udp_query (struct outside_network *outnet, ldns_buffer *packet, struct sockaddr_storage *addr, socklen_t addrlen, int timeout, comm_point_callback_t *callback, void *callback_arg) |
| Send UDP query, create pending answer. | |
| struct waiting_tcp * | pending_tcp_query (struct outside_network *outnet, ldns_buffer *packet, struct sockaddr_storage *addr, socklen_t addrlen, int timeout, comm_point_callback_t *callback, void *callback_arg, int ssl_upstream) |
| Send TCP query. | |
| void | pending_delete (struct outside_network *outnet, struct pending *p) |
| Delete pending answer. | |
| struct serviced_query * | outnet_serviced_query (struct outside_network *outnet, uint8_t *qname, size_t qnamelen, uint16_t qtype, uint16_t qclass, uint16_t flags, int dnssec, int want_dnssec, int tcp_upstream, int ssl_upstream, struct sockaddr_storage *addr, socklen_t addrlen, uint8_t *zone, size_t zonelen, comm_point_callback_t *callback, void *callback_arg, ldns_buffer *buff, int(*arg_compare)(void *, void *)) |
| Perform a serviced query to the authoritative servers. | |
| void | outnet_serviced_query_stop (struct serviced_query *sq, void *cb_arg) |
| Remove service query callback. | |
| size_t | outnet_get_mem (struct outside_network *outnet) |
| Get memory size in use by outside network. | |
| size_t | serviced_get_mem (struct serviced_query *sq) |
| Get memory size in use by serviced query while it is servicing callbacks. | |
| int | outnet_udp_cb (struct comm_point *c, void *arg, int error, struct comm_reply *reply_info) |
| callback for incoming udp answers from the network | |
| int | outnet_tcp_cb (struct comm_point *c, void *arg, int error, struct comm_reply *reply_info) |
| callback for pending tcp connections | |
| void | pending_udp_timer_cb (void *arg) |
| callback for udp timeout | |
| void | outnet_tcptimer (void *arg) |
| callback for outgoing TCP timer event | |
| int | serviced_udp_callback (struct comm_point *c, void *arg, int error, struct comm_reply *rep) |
| callback for serviced query UDP answers | |
| int | serviced_tcp_callback (struct comm_point *c, void *arg, int error, struct comm_reply *rep) |
| TCP reply or error callback for serviced queries. | |
| int | pending_cmp (const void *key1, const void *key2) |
| compare function of pending rbtree | |
| int | serviced_cmp (const void *key1, const void *key2) |
| compare function of serviced query rbtree | |
This file has functions to send queries to authoritative servers, and wait for the pending answer, with timeouts.
| 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, | ||
| void(*)(void *) | unwanted_action, | ||
| void * | unwanted_param, | ||
| int | do_udp, | ||
| void * | sslctx | ||
| ) | [read] |
Create outside_network structure with N udp ports.
| base,: | the communication base to use for event handling. |
| bufsize,: | size for network buffers. |
| num_ports,: | number of udp ports to open per interface. |
| ifs,: | interface names (or NULL for default interface). These interfaces must be able to access all authoritative servers. |
| num_ifs,: | number of names in array ifs. |
| do_ip4,: | service IP4. |
| do_ip6,: | service IP6. |
| num_tcp,: | number of outgoing tcp buffers to preallocate. |
| infra,: | pointer to infra cached used for serviced queries. |
| rnd,: | stored to create random numbers for serviced queries. |
| use_caps_for_id,: | enable to use 0x20 bits to encode id randomness. |
| availports,: | array of available ports. |
| numavailports,: | number of available ports in array. |
| unwanted_threshold,: | when to take defensive action. |
| unwanted_action,: | the action to take. |
| unwanted_param,: | user parameter to action. |
| do_udp,: | if udp is done. |
| sslctx,: | context to create outgoing connections with (if enabled). |
References log_err(), comm_base_timept(), outside_network::now_secs, outside_network::now_tv, outside_network::base, outside_network::num_tcp, outside_network::infra, outside_network::rnd, outside_network::sslctx, outside_network::svcd_overhead, outside_network::want_to_quit, outside_network::unwanted_threshold, outside_network::unwanted_action, outside_network::unwanted_param, outside_network::use_caps_for_id, outside_network::do_udp, outside_network_delete(), calc_num46(), outside_network::num_ip4, outside_network::num_ip6, outside_network::ip4_ifs, outside_network::ip6_ifs, outside_network::udp_buff, outside_network::pending, rbtree_create(), pending_cmp(), outside_network::serviced, serviced_cmp(), create_pending_tcp(), port_comm::cp, comm_point_create_udp(), outnet_udp_cb(), port_comm::next, outside_network::unused_fds, setup_if(), str_is_ip6(), and replay_runtime::infra.
Referenced by worker_init(), and libworker_setup().
| void outside_network_delete | ( | struct outside_network * | outnet | ) |
Delete outside_network structure.
| outnet,: | object to delete. |
References outside_network::want_to_quit, outside_network::pending, traverse_postorder(), pending_node_del(), outside_network::serviced, serviced_node_del(), outside_network::udp_buff, outside_network::unused_fds, port_comm::next, comm_point_delete(), port_comm::cp, outside_network::ip4_ifs, outside_network::num_ip4, port_if::inuse, port_if::avail_ports, port_if::out, outside_network::ip6_ifs, outside_network::num_ip6, outside_network::tcp_conns, outside_network::num_tcp, pending_tcp::c, waiting_tcp_delete(), pending_tcp::query, outside_network::tcp_wait_first, waiting_tcp::next_waiting, outside_network::udp_wait_first, pending::next_waiting, and pending_delete().
Referenced by worker_delete(), libworker_delete(), and outside_network_create().
| void outside_network_quit_prepare | ( | struct outside_network * | outnet | ) |
Prepare for quit.
Sends no more queries, even if queued up.
| outnet,: | object to prepare for removal |
References outside_network::want_to_quit.
Referenced by worker_delete(), and libworker_delete().
| struct pending* pending_udp_query | ( | struct outside_network * | outnet, |
| ldns_buffer * | packet, | ||
| struct sockaddr_storage * | addr, | ||
| socklen_t | addrlen, | ||
| int | timeout, | ||
| comm_point_callback_t * | callback, | ||
| void * | callback_arg | ||
| ) | [read] |
Send UDP query, create pending answer.
Changes the ID for the query to be random and unique for that destination.
| outnet,: | provides the event handling |
| packet,: | wireformat query to send to destination. |
| addr,: | address to send to. |
| addrlen,: | length of addr. |
| timeout,: | in milliseconds from now. |
| callback,: | function to call on error, timeout or reply. |
| callback_arg,: | user argument for callback function. |
References pending::outnet, pending::addrlen, pending::addr, pending::cb, pending::cb_arg, pending::node, rbnode_t::key, pending::timer, comm_timer_create(), outside_network::base, pending_udp_timer_cb(), outside_network::unused_fds, verbose(), VERB_ALGO, pending::timeout, pending::pkt_len, pending::pkt, memdup(), comm_timer_delete(), outside_network::udp_wait_last, pending::next_waiting, outside_network::udp_wait_first, randomize_and_send_udp(), pending_delete(), log_assert, log_err(), fatal_exit(), log_pkt(), replay_runtime::now, replay_moment::evt_type, replay_moment::addrlen, sockaddr_cmp(), replay_moment::addr, find_match(), replay_moment::match, log_info(), replay_moment::time_step, repevt_string(), advance_moment(), and replay_runtime::pending_list.
Referenced by serviced_udp_send().
| struct waiting_tcp* pending_tcp_query | ( | struct outside_network * | outnet, |
| ldns_buffer * | packet, | ||
| struct sockaddr_storage * | addr, | ||
| socklen_t | addrlen, | ||
| int | timeout, | ||
| comm_point_callback_t * | callback, | ||
| void * | callback_arg, | ||
| int | ssl_upstream | ||
| ) | [read] |
Send TCP query.
May wait for TCP buffer. Selects ID to be random, and checks id.
| outnet,: | provides the event handling. |
| packet,: | wireformat query to send to destination. copied from. |
| addr,: | address to send to. |
| addrlen,: | length of addr. |
| timeout,: | in seconds from now. Timer starts running now. Timer may expire if all buffers are used, without any query been sent to the server yet. |
| callback,: | function to call on error, timeout or reply. |
| callback_arg,: | user argument for callback function. |
| ssl_upstream,: | if the tcp connection must use SSL. |
References outside_network::tcp_free, waiting_tcp::timer, comm_timer_create(), outside_network::base, outnet_tcptimer(), waiting_tcp::pkt, waiting_tcp::pkt_len, ub_random(), outside_network::rnd, waiting_tcp::addr, waiting_tcp::addrlen, waiting_tcp::outnet, waiting_tcp::cb, waiting_tcp::cb_arg, waiting_tcp::ssl_upstream, comm_timer_set(), outnet_tcp_take_into_use(), waiting_tcp_delete(), waiting_tcp::next_waiting, outside_network::tcp_wait_last, outside_network::tcp_wait_first, log_assert, log_err(), fatal_exit(), log_pkt(), replay_runtime::now, replay_moment::evt_type, replay_moment::addrlen, sockaddr_cmp(), replay_moment::addr, find_match(), replay_moment::match, log_info(), replay_moment::time_step, repevt_string(), advance_moment(), and replay_runtime::pending_list.
Referenced by serviced_tcp_initiate(), and serviced_tcp_send().
| void pending_delete | ( | struct outside_network * | outnet, |
| struct pending * | p | ||
| ) |
Delete pending answer.
| outnet,: | outside network the pending query is part of. Internal feature: if outnet is NULL, p is not unlinked from rbtree. |
| p,: | deleted |
References outside_network::udp_wait_first, pending::next_waiting, outside_network::udp_wait_last, log_assert, rbtree_delete(), outside_network::pending, pending::node, rbnode_t::key, pending::timer, comm_timer_delete(), and pending::pkt.
Referenced by outnet_send_wait_udp(), outnet_udp_cb(), pending_udp_timer_cb(), pending_node_del(), outside_network_delete(), pending_udp_query(), and serviced_delete().
| struct serviced_query* outnet_serviced_query | ( | struct outside_network * | outnet, |
| uint8_t * | qname, | ||
| size_t | qnamelen, | ||
| uint16_t | qtype, | ||
| uint16_t | qclass, | ||
| uint16_t | flags, | ||
| int | dnssec, | ||
| int | want_dnssec, | ||
| int | tcp_upstream, | ||
| int | ssl_upstream, | ||
| struct sockaddr_storage * | addr, | ||
| socklen_t | addrlen, | ||
| uint8_t * | zone, | ||
| size_t | zonelen, | ||
| comm_point_callback_t * | callback, | ||
| void * | callback_arg, | ||
| ldns_buffer * | buff, | ||
| int(*)(void *, void *) | arg_compare | ||
| ) | [read] |
Perform a serviced query to the authoritative servers.
Duplicate efforts are detected, and EDNS, TCP and UDP retry is performed.
| outnet,: | outside network, with rbtree of serviced queries. |
| qname,: | what qname to query. |
| qnamelen,: | length of qname in octets including 0 root label. |
| qtype,: | rrset type to query (host format) |
| qclass,: | query class. (host format) |
| flags,: | flags u16 (host format), includes opcode, CD bit. |
| dnssec,: | if set, DO bit is set in EDNS queries. If the value includes BIT_CD, CD bit is set when in EDNS queries. If the value includes BIT_DO, DO bit is set when in EDNS queries. |
| want_dnssec,: | signatures are needed, without EDNS the answer is likely to be useless. |
| tcp_upstream,: | use TCP for upstream queries. |
| ssl_upstream,: | use SSL for upstream queries. |
| callback,: | callback function. |
| callback_arg,: | user argument to callback function. |
| addr,: | to which server to send the query. |
| addrlen,: | length of addr. |
| zone,: | name of the zone of the delegation point. wireformat dname. This is the delegation point name for which the server is deemed authoritative. |
| zonelen,: | length of zone. |
| buff,: | scratch buffer to create query contents in. Empty on exit. |
| arg_compare,: | function to compare callback args, return true if identical. It is given the callback_arg and args that are listed. |
References service_callback::cb, serviced_gen_query(), lookup_serviced(), callback_list_find(), serviced_create(), outside_network::do_udp, serviced_udp_send(), rbtree_delete(), outside_network::serviced, serviced_query::qbuf, serviced_query::zone, serviced_tcp_send(), service_callback::cb_arg, service_callback::next, serviced_query::cblist, outside_network::base, log_assert, log_nametypeclass(), VERB_OPS, dname_str(), verbose(), BIT_RD, BIT_CD, edns_data::edns_present, edns_data::ext_rcode, edns_data::edns_version, EDNS_ADVERTISED_VERSION, edns_data::udp_size, EDNS_ADVERTISED_SIZE, edns_data::bits, EDNS_DO, attach_edns_record(), UDP_AUTH_QUERY_TIMEOUT, log_err(), fatal_exit(), replay_runtime::now, replay_moment::evt_type, replay_moment::addrlen, sockaddr_cmp(), replay_moment::addr, find_match(), replay_moment::match, log_info(), replay_moment::time_step, repevt_string(), advance_moment(), and replay_runtime::pending_list.
Referenced by worker_send_query(), and libworker_send_query().
| void outnet_serviced_query_stop | ( | struct serviced_query * | sq, |
| void * | cb_arg | ||
| ) |
Remove service query callback.
If that leads to zero callbacks, the query is completely cancelled.
| sq,: | serviced query to adjust. |
| cb_arg,: | callback argument of callback that needs removal. same as the callback_arg to outnet_serviced_query(). |
References callback_list_remove(), serviced_query::cblist, serviced_query::to_be_deleted, rbtree_delete(), serviced_query::outnet, outside_network::serviced, log_assert, serviced_delete(), fake_pending::runtime, replay_runtime::pending_list, fake_pending::cb_arg, log_info(), fake_pending::next, fake_pending::buffer, and fake_pending::pkt.
Referenced by outbound_list_clear(), and outbound_list_remove().
| size_t outnet_get_mem | ( | struct outside_network * | outnet | ) |
Get memory size in use by outside network.
Counts buffers and outstanding query (serviced queries) malloced data.
| outnet,: | outside network structure. |
References outside_network::base, outside_network::udp_buff, outside_network::unused_fds, port_comm::next, comm_point_get_mem(), port_comm::cp, outside_network::num_ip4, if_get_mem(), outside_network::ip4_ifs, outside_network::num_ip6, outside_network::ip6_ifs, outside_network::udp_wait_first, pending::next_waiting, waiting_udp_get_mem(), outside_network::num_tcp, outside_network::tcp_conns, pending_tcp::c, pending_tcp::query, waiting_tcp_get_mem(), outside_network::tcp_wait_first, waiting_tcp::next_waiting, outside_network::pending, rbtree_t::count, outside_network::serviced, outside_network::svcd_overhead, RBTREE_FOR, serviced_query::qbuflen, serviced_query::cblist, and service_callback::next.
Referenced by worker_mem_report().
| size_t serviced_get_mem | ( | struct serviced_query * | sq | ) |
Get memory size in use by serviced query while it is servicing callbacks.
This takes into account the pre-deleted status of it; it will be deleted when the callbacks are done.
| sq,: | serviced query. |
References serviced_query::qbuflen, serviced_query::cblist, service_callback::next, serviced_query::status, and comm_timer_get_mem().
Referenced by worker_mem_report().