2013-08-12 16:38:05 -05:00
|
|
|
/**
|
2013-08-15 11:33:05 -05:00
|
|
|
*
|
2014-02-10 18:59:45 -06:00
|
|
|
* \file context.h
|
|
|
|
* @brief getdns context management functions
|
2013-08-15 11:33:05 -05:00
|
|
|
*
|
|
|
|
* Originally taken from the getdns API description pseudo implementation.
|
|
|
|
*
|
|
|
|
*/
|
2014-01-28 08:22:46 -06:00
|
|
|
|
|
|
|
/*
|
2014-02-25 07:12:33 -06:00
|
|
|
* Copyright (c) 2013, NLnet Labs, Verisign, Inc.
|
2014-01-28 08:22:46 -06:00
|
|
|
* All rights reserved.
|
2013-08-15 11:33:05 -05:00
|
|
|
*
|
2014-01-28 08:22:46 -06:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2014-02-25 07:23:19 -06:00
|
|
|
* * Neither the names of the copyright holders nor the
|
2014-01-28 08:22:46 -06:00
|
|
|
* names of its contributors may be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
2013-08-15 11:33:05 -05:00
|
|
|
*
|
2014-01-28 08:22:46 -06:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY
|
|
|
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2013-08-12 16:38:05 -05:00
|
|
|
*/
|
2014-01-28 08:22:46 -06:00
|
|
|
|
2013-08-12 16:38:05 -05:00
|
|
|
#ifndef _GETDNS_CONTEXT_H_
|
|
|
|
#define _GETDNS_CONTEXT_H_
|
|
|
|
|
2014-05-19 08:50:34 -05:00
|
|
|
#include "getdns/getdns.h"
|
|
|
|
#include "getdns/getdns_extra.h"
|
2014-10-06 16:04:12 -05:00
|
|
|
#include "config.h"
|
2013-12-08 15:56:34 -06:00
|
|
|
#include "types-internal.h"
|
2016-01-12 08:52:14 -06:00
|
|
|
#include "extension/default_eventloop.h"
|
2014-10-16 04:28:32 -05:00
|
|
|
#include "util/rbtree.h"
|
2016-03-01 09:29:37 -06:00
|
|
|
#include "ub_loop.h"
|
2016-07-13 07:50:44 -05:00
|
|
|
#include "server.h"
|
2017-03-09 07:36:20 -06:00
|
|
|
#ifdef HAVE_MDNS_SUPPORT
|
|
|
|
#include "util/lruhash.h"
|
|
|
|
#endif
|
2017-06-30 03:18:07 -05:00
|
|
|
#include "rr-iter.h"
|
2017-09-20 03:30:13 -05:00
|
|
|
#include "anchor.h"
|
2013-08-12 16:38:05 -05:00
|
|
|
|
2013-10-16 17:33:12 -05:00
|
|
|
struct getdns_dns_req;
|
2013-11-06 12:32:05 -06:00
|
|
|
struct ub_ctx;
|
2013-10-15 16:28:23 -05:00
|
|
|
|
2014-02-10 18:59:45 -06:00
|
|
|
enum filechgs { GETDNS_FCHG_ERRORS = -1
|
|
|
|
, GETDNS_FCHG_NOERROR = 0
|
|
|
|
, GETDNS_FCHG_NOCHANGES = 0
|
|
|
|
, GETDNS_FCHG_MTIME = 1
|
|
|
|
, GETDNS_FCHG_CTIME = 2};
|
|
|
|
|
2013-08-12 16:38:05 -05:00
|
|
|
/** function pointer typedefs */
|
2014-02-09 10:46:12 -06:00
|
|
|
typedef void (*getdns_update_callback) (struct getdns_context *,
|
|
|
|
getdns_context_code_t);
|
2013-08-12 16:38:05 -05:00
|
|
|
|
2015-04-02 07:42:26 -05:00
|
|
|
typedef void (*getdns_update_callback2) (struct getdns_context *,
|
|
|
|
getdns_context_code_t, void *userarg);
|
|
|
|
|
2014-02-10 18:59:45 -06:00
|
|
|
/* internal use only for detecting changes to system files */
|
|
|
|
struct filechg {
|
2017-12-12 05:24:31 -06:00
|
|
|
char fn[_GETDNS_PATH_MAX];
|
2014-02-10 18:59:45 -06:00
|
|
|
int changes;
|
|
|
|
int errors;
|
2017-12-12 05:24:31 -06:00
|
|
|
struct stat prevstat;
|
2014-02-10 18:59:45 -06:00
|
|
|
};
|
|
|
|
|
2015-04-19 11:16:58 -05:00
|
|
|
typedef enum getdns_tls_hs_state {
|
|
|
|
GETDNS_HS_NONE,
|
|
|
|
GETDNS_HS_WRITE,
|
|
|
|
GETDNS_HS_READ,
|
|
|
|
GETDNS_HS_DONE,
|
|
|
|
GETDNS_HS_FAILED
|
|
|
|
} getdns_tls_hs_state_t;
|
|
|
|
|
2016-06-23 09:53:51 -05:00
|
|
|
typedef enum getdns_conn_state {
|
|
|
|
GETDNS_CONN_CLOSED,
|
|
|
|
GETDNS_CONN_SETUP,
|
|
|
|
GETDNS_CONN_OPEN,
|
|
|
|
GETDNS_CONN_TEARDOWN,
|
|
|
|
GETDNS_CONN_BACKOFF
|
|
|
|
} getdns_conn_state_t;
|
|
|
|
|
2017-06-22 05:27:20 -05:00
|
|
|
typedef enum getdns_tasrc {
|
|
|
|
GETDNS_TASRC_NONE,
|
|
|
|
GETDNS_TASRC_ZONE,
|
2017-06-30 18:00:40 -05:00
|
|
|
GETDNS_TASRC_APP,
|
2017-06-30 03:18:07 -05:00
|
|
|
GETDNS_TASRC_FETCHING,
|
2017-06-28 13:35:30 -05:00
|
|
|
GETDNS_TASRC_XML,
|
2017-09-20 03:30:13 -05:00
|
|
|
GETDNS_TASRC_XML_UPDATE,
|
2017-06-28 13:35:30 -05:00
|
|
|
GETDNS_TASRC_FAILED
|
2017-06-22 05:27:20 -05:00
|
|
|
} getdns_tasrc;
|
|
|
|
|
2015-12-21 05:22:59 -06:00
|
|
|
typedef enum getdns_tsig_algo {
|
|
|
|
GETDNS_NO_TSIG = 0, /* Do not use tsig */
|
|
|
|
GETDNS_HMAC_MD5 = 1, /* 128 bits */
|
|
|
|
GETDNS_GSS_TSIG = 2, /* Not supported */
|
|
|
|
GETDNS_HMAC_SHA1 = 3, /* 160 bits */
|
|
|
|
GETDNS_HMAC_SHA224 = 4,
|
|
|
|
GETDNS_HMAC_SHA256 = 5,
|
|
|
|
GETDNS_HMAC_SHA384 = 6,
|
|
|
|
GETDNS_HMAC_SHA512 = 7
|
|
|
|
} getdns_tsig_algo;
|
|
|
|
|
2017-09-13 07:00:54 -05:00
|
|
|
|
2015-12-21 05:22:59 -06:00
|
|
|
typedef struct getdns_tsig_info {
|
|
|
|
getdns_tsig_algo alg;
|
|
|
|
const char *name;
|
|
|
|
size_t strlen_name;
|
|
|
|
const uint8_t *dname;
|
|
|
|
size_t dname_len;
|
|
|
|
size_t min_size; /* in # octets */
|
|
|
|
size_t max_size; /* Actual size in # octets */
|
|
|
|
} getdns_tsig_info;
|
|
|
|
|
|
|
|
const getdns_tsig_info *_getdns_get_tsig_info(getdns_tsig_algo tsig_alg);
|
|
|
|
|
2015-12-21 16:53:36 -06:00
|
|
|
/* for doing public key pinning of TLS-capable upstreams: */
|
|
|
|
typedef struct sha256_pin {
|
|
|
|
char pin[SHA256_DIGEST_LENGTH];
|
|
|
|
struct sha256_pin *next;
|
|
|
|
} sha256_pin_t;
|
|
|
|
|
2014-10-16 07:24:13 -05:00
|
|
|
typedef struct getdns_upstream {
|
2015-07-18 17:34:11 -05:00
|
|
|
/* backpointer to containing upstreams structure */
|
2014-10-17 17:25:41 -05:00
|
|
|
struct getdns_upstreams *upstreams;
|
|
|
|
|
|
|
|
socklen_t addr_len;
|
|
|
|
struct sockaddr_storage addr;
|
2016-08-05 08:10:55 -05:00
|
|
|
char addr_str[INET6_ADDRSTRLEN];
|
2014-10-17 17:25:41 -05:00
|
|
|
|
2017-03-22 04:52:55 -05:00
|
|
|
/**
|
|
|
|
* How is this upstream doing over UDP?
|
|
|
|
*
|
|
|
|
* to_retry = 1, back_off = 1, in context.c:upstream_init()
|
|
|
|
*
|
|
|
|
* When querying over UDP, first a upstream is selected which to_retry
|
|
|
|
* value > 0 in stub.c:upstream_select().
|
|
|
|
*
|
|
|
|
* Every time a udp request times out, to_retry is decreased, and if
|
|
|
|
* it reaches 0, it is set to minus back_off in
|
|
|
|
* stub.c:stub_next_upstream().
|
|
|
|
*
|
|
|
|
* to_retry will become > 0 again. because each time an upstream is
|
|
|
|
* selected for a UDP query in stub.c:upstream_select(), all to_retry
|
|
|
|
* counters <= 0 are incremented.
|
|
|
|
*
|
|
|
|
* On continuous failure, the stubs are less likely to be reselected,
|
|
|
|
* because each time to_retry is set to minus back_off, in
|
|
|
|
* stub.c:stub_next_upstream(), the back_off value is doubled.
|
|
|
|
*
|
|
|
|
* Finally, if all upstreams are failing, the upstreams with the
|
|
|
|
* smallest back_off value will be selected, and the back_off value
|
|
|
|
* decremented by one.
|
|
|
|
*/
|
|
|
|
int to_retry; /* (initialized to 1) */
|
|
|
|
int back_off; /* (initialized to 1) */
|
2016-12-05 12:05:04 -06:00
|
|
|
size_t udp_responses;
|
|
|
|
size_t udp_timeouts;
|
2014-10-17 17:25:41 -05:00
|
|
|
|
2016-06-23 09:53:51 -05:00
|
|
|
/* For stateful upstreams, need to share the connection and track the
|
|
|
|
activity on the connection */
|
2014-10-17 17:25:41 -05:00
|
|
|
int fd;
|
2015-06-19 12:28:29 -05:00
|
|
|
getdns_transport_list_t transport;
|
2014-10-17 17:25:41 -05:00
|
|
|
getdns_eventloop_event event;
|
|
|
|
getdns_eventloop *loop;
|
|
|
|
getdns_tcp_state tcp;
|
2016-06-23 09:53:51 -05:00
|
|
|
/* These are running totals or historical info */
|
|
|
|
size_t conn_completed;
|
|
|
|
size_t conn_shutdowns;
|
|
|
|
size_t conn_setup_failed;
|
2016-08-05 11:25:27 -05:00
|
|
|
time_t conn_retry_time;
|
2017-09-08 11:28:37 -05:00
|
|
|
uint16_t conn_backoff_interval;
|
2016-08-05 11:25:27 -05:00
|
|
|
size_t conn_backoffs;
|
2016-06-23 09:53:51 -05:00
|
|
|
size_t total_responses;
|
|
|
|
size_t total_timeouts;
|
2016-10-21 08:18:24 -05:00
|
|
|
getdns_auth_state_t best_tls_auth_state;
|
|
|
|
getdns_auth_state_t last_tls_auth_state;
|
2016-06-23 09:53:51 -05:00
|
|
|
/* These are per connection. */
|
|
|
|
getdns_conn_state_t conn_state;
|
|
|
|
size_t queries_sent;
|
|
|
|
size_t responses_received;
|
|
|
|
size_t responses_timeouts;
|
2016-07-21 12:24:18 -05:00
|
|
|
size_t keepalive_shutdown;
|
2016-06-23 09:53:51 -05:00
|
|
|
uint64_t keepalive_timeout;
|
2014-10-17 17:25:41 -05:00
|
|
|
|
2016-06-23 09:53:51 -05:00
|
|
|
/* Management of outstanding requests on stateful transports */
|
2014-10-17 17:25:41 -05:00
|
|
|
getdns_network_req *write_queue;
|
2014-10-18 07:32:55 -05:00
|
|
|
getdns_network_req *write_queue_last;
|
2016-06-23 09:53:51 -05:00
|
|
|
_getdns_rbtree_t netreq_by_query_id;
|
|
|
|
|
|
|
|
/* TLS specific connection handling*/
|
|
|
|
SSL* tls_obj;
|
|
|
|
SSL_SESSION* tls_session;
|
|
|
|
getdns_tls_hs_state_t tls_hs_state;
|
|
|
|
getdns_auth_state_t tls_auth_state;
|
|
|
|
unsigned tls_fallback_ok : 1;
|
2017-12-21 05:30:15 -06:00
|
|
|
char *tls_cipher_list;
|
2016-06-23 09:53:51 -05:00
|
|
|
/* Auth credentials*/
|
|
|
|
char tls_auth_name[256];
|
|
|
|
sha256_pin_t *tls_pubkey_pinset;
|
2015-03-22 10:50:48 -05:00
|
|
|
|
2016-03-23 16:13:31 -05:00
|
|
|
/* When requests have been scheduled asynchronously on an upstream
|
|
|
|
* that is kept open, and a synchronous call is then done with the
|
|
|
|
* upstream before all scheduled requests have been answered, answers
|
|
|
|
* for the asynchronous requests may be received on the open upstream.
|
|
|
|
* Those cannot be processed immediately, because then asynchronous
|
|
|
|
* callbacks will be fired as a side-effect.
|
|
|
|
*
|
|
|
|
* finished_dnsreqs is a list of dnsreqs for which answers have been
|
|
|
|
* received during a synchronous request. They will be processed
|
|
|
|
* when the asynchronous eventloop is run. For this the finished_event
|
|
|
|
* will be scheduled to the registered asynchronous event loop with a
|
|
|
|
* timeout of 1, so it will fire immediately (but not while scheduling)
|
|
|
|
* when the asynchronous eventloop is run.
|
|
|
|
*/
|
|
|
|
getdns_dns_req *finished_dnsreqs;
|
|
|
|
getdns_eventloop_event finished_event;
|
2016-06-23 09:53:51 -05:00
|
|
|
unsigned is_sync_loop : 1;
|
2016-03-23 16:13:31 -05:00
|
|
|
|
2015-03-22 10:50:48 -05:00
|
|
|
/* EDNS cookies */
|
|
|
|
uint32_t secret;
|
|
|
|
uint8_t client_cookie[8];
|
|
|
|
uint8_t prev_client_cookie[8];
|
|
|
|
uint8_t server_cookie[32];
|
|
|
|
|
|
|
|
unsigned has_client_cookie : 1;
|
|
|
|
unsigned has_prev_client_cookie : 1;
|
|
|
|
unsigned has_server_cookie : 1;
|
|
|
|
unsigned server_cookie_len : 5;
|
|
|
|
|
2015-12-21 05:22:59 -06:00
|
|
|
/* TSIG */
|
|
|
|
uint8_t tsig_dname[256];
|
|
|
|
size_t tsig_dname_len;
|
|
|
|
size_t tsig_size;
|
|
|
|
uint8_t tsig_key[256];
|
|
|
|
getdns_tsig_algo tsig_alg;
|
|
|
|
|
2014-10-16 07:24:13 -05:00
|
|
|
} getdns_upstream;
|
2014-09-30 08:12:48 -05:00
|
|
|
|
2017-06-26 17:23:22 -05:00
|
|
|
typedef struct getdns_log_config {
|
|
|
|
getdns_logfunc_type func;
|
|
|
|
void *userarg;
|
|
|
|
uint64_t system;
|
|
|
|
getdns_loglevel_type level;
|
|
|
|
} getdns_log_config;
|
|
|
|
|
2014-09-30 08:12:48 -05:00
|
|
|
typedef struct getdns_upstreams {
|
|
|
|
struct mem_funcs mf;
|
|
|
|
size_t referenced;
|
|
|
|
size_t count;
|
2016-06-23 09:53:51 -05:00
|
|
|
size_t current_udp;
|
2017-03-16 09:51:46 -05:00
|
|
|
size_t current_stateful;
|
2017-03-17 09:43:26 -05:00
|
|
|
uint16_t tls_backoff_time;
|
|
|
|
uint16_t tls_connection_retries;
|
2017-06-26 17:23:22 -05:00
|
|
|
getdns_log_config log;
|
2014-10-16 07:24:13 -05:00
|
|
|
getdns_upstream upstreams[];
|
2014-09-30 08:12:48 -05:00
|
|
|
} getdns_upstreams;
|
2013-08-12 16:38:05 -05:00
|
|
|
|
2017-06-30 03:18:07 -05:00
|
|
|
typedef enum tas_state {
|
|
|
|
TAS_LOOKUP_ADDRESSES = 0,
|
|
|
|
TAS_WRITE_GET_XML,
|
|
|
|
TAS_READ_XML_HDR,
|
|
|
|
TAS_READ_XML_DOC,
|
|
|
|
TAS_WRITE_GET_PS7,
|
|
|
|
TAS_READ_PS7_HDR,
|
|
|
|
TAS_READ_PS7_DOC,
|
2017-06-30 15:00:14 -05:00
|
|
|
TAS_DONE,
|
|
|
|
TAS_RETRY,
|
|
|
|
TAS_RETRY_GET_PS7,
|
|
|
|
TAS_RETRY_PS7_HDR,
|
|
|
|
TAS_RETRY_PS7_DOC,
|
|
|
|
TAS_RETRY_DONE
|
2017-06-30 03:18:07 -05:00
|
|
|
} tas_state;
|
|
|
|
|
2017-09-13 07:00:54 -05:00
|
|
|
typedef enum _getdns_property {
|
|
|
|
PROP_INHERIT = 0,
|
|
|
|
PROP_UNKNOWN = 1,
|
|
|
|
PROP_UNABLE = 2,
|
|
|
|
PROP_ABLE = 3
|
|
|
|
} _getdns_property;
|
|
|
|
|
2017-06-30 03:18:07 -05:00
|
|
|
typedef struct tas_connection {
|
|
|
|
getdns_eventloop *loop;
|
|
|
|
getdns_network_req *req;
|
|
|
|
_getdns_rrset_spc rrset_spc;
|
|
|
|
_getdns_rrset *rrset;
|
|
|
|
_getdns_rrtype_iter rr_spc;
|
|
|
|
_getdns_rrtype_iter *rr;
|
|
|
|
int fd;
|
|
|
|
getdns_eventloop_event event;
|
|
|
|
tas_state state;
|
|
|
|
getdns_tcp_state tcp;
|
2017-09-13 07:00:54 -05:00
|
|
|
char *http;
|
2017-06-30 03:18:07 -05:00
|
|
|
getdns_bindata xml;
|
|
|
|
} tas_connection;
|
|
|
|
|
2014-09-30 08:12:48 -05:00
|
|
|
struct getdns_context {
|
2013-11-05 14:03:44 -06:00
|
|
|
/* Context values */
|
2014-02-10 18:59:45 -06:00
|
|
|
getdns_resolution_t resolution_type;
|
|
|
|
getdns_namespace_t *namespaces;
|
2016-12-08 07:05:58 -06:00
|
|
|
size_t namespace_count;
|
2014-02-10 18:59:45 -06:00
|
|
|
uint64_t timeout;
|
2015-06-18 11:11:11 -05:00
|
|
|
uint64_t idle_timeout;
|
2014-02-10 18:59:45 -06:00
|
|
|
getdns_redirects_t follow_redirects;
|
2015-12-23 10:15:45 -06:00
|
|
|
getdns_list *dns_root_servers;
|
2016-03-14 05:33:06 -05:00
|
|
|
|
|
|
|
#if defined(HAVE_LIBUNBOUND) && !defined(HAVE_UB_CTX_SET_STUB)
|
2015-12-24 03:50:58 -06:00
|
|
|
char root_servers_fn[FILENAME_MAX];
|
2016-03-14 05:33:06 -05:00
|
|
|
#endif
|
2014-02-09 10:46:12 -06:00
|
|
|
getdns_append_name_t append_name;
|
2015-12-29 09:00:15 -06:00
|
|
|
/* Suffix buffer containing a list of (length byte | dname) where
|
|
|
|
* length bytes contains the length of the following dname.
|
|
|
|
* The last dname should be the zero byte.
|
|
|
|
*/
|
2015-12-29 10:34:14 -06:00
|
|
|
const uint8_t *suffixes;
|
2015-12-29 09:00:15 -06:00
|
|
|
/* Length of all suffixes in the suffix buffer */
|
2015-12-29 09:23:04 -06:00
|
|
|
size_t suffixes_len;
|
2017-06-30 03:18:07 -05:00
|
|
|
|
2015-06-30 07:43:52 -05:00
|
|
|
uint8_t *trust_anchors;
|
|
|
|
size_t trust_anchors_len;
|
2017-06-22 05:27:20 -05:00
|
|
|
getdns_tasrc trust_anchors_source;
|
2017-06-30 03:18:07 -05:00
|
|
|
|
|
|
|
tas_connection a;
|
|
|
|
tas_connection aaaa;
|
|
|
|
uint8_t tas_hdr_spc[512];
|
|
|
|
|
2017-09-22 05:25:56 -05:00
|
|
|
char *trust_anchors_url;
|
|
|
|
char *trust_anchors_verify_CA;
|
|
|
|
char *trust_anchors_verify_email;
|
2017-09-13 07:00:54 -05:00
|
|
|
|
2017-09-20 03:30:13 -05:00
|
|
|
_getdns_ksks root_ksk;
|
|
|
|
|
2017-09-21 10:06:29 -05:00
|
|
|
char *appdata_dir;
|
|
|
|
_getdns_property can_write_appdata;
|
|
|
|
|
2017-12-21 06:08:01 -06:00
|
|
|
char *tls_ca_path;
|
|
|
|
char *tls_ca_file;
|
2017-12-21 04:35:05 -06:00
|
|
|
char *tls_cipher_list;
|
2017-12-12 08:10:37 -06:00
|
|
|
|
2014-10-16 07:24:13 -05:00
|
|
|
getdns_upstreams *upstreams;
|
2014-09-30 08:12:48 -05:00
|
|
|
uint16_t limit_outstanding_queries;
|
|
|
|
uint32_t dnssec_allowed_skew;
|
2015-09-30 08:03:15 -05:00
|
|
|
getdns_tls_authentication_t tls_auth; /* What user requested for TLS*/
|
|
|
|
getdns_tls_authentication_t tls_auth_min; /* Derived minimum auth allowed*/
|
2017-03-17 11:53:03 -05:00
|
|
|
uint8_t round_robin_upstreams;
|
2017-03-17 09:43:26 -05:00
|
|
|
uint16_t tls_backoff_time;
|
|
|
|
uint16_t tls_connection_retries;
|
2013-10-16 17:33:12 -05:00
|
|
|
|
2015-06-19 12:28:29 -05:00
|
|
|
getdns_transport_list_t *dns_transports;
|
|
|
|
size_t dns_transport_count;
|
|
|
|
|
2013-11-05 14:03:44 -06:00
|
|
|
uint8_t edns_extended_rcode;
|
|
|
|
uint8_t edns_version;
|
|
|
|
uint8_t edns_do_bit;
|
2014-10-23 07:30:23 -05:00
|
|
|
int edns_maximum_udp_payload_size; /* -1 is unset */
|
2015-10-31 22:20:12 -05:00
|
|
|
uint8_t edns_client_subnet_private;
|
2015-10-31 23:51:46 -05:00
|
|
|
uint16_t tls_query_padding_blocksize;
|
2014-12-07 13:03:34 -06:00
|
|
|
SSL_CTX* tls_ctx;
|
2013-10-16 17:33:12 -05:00
|
|
|
|
2015-04-02 07:42:26 -05:00
|
|
|
getdns_update_callback update_callback;
|
|
|
|
getdns_update_callback2 update_callback2;
|
|
|
|
void *update_userarg;
|
2013-08-12 16:38:05 -05:00
|
|
|
|
2017-06-26 17:23:22 -05:00
|
|
|
getdns_log_config log;
|
|
|
|
|
2014-09-30 08:12:48 -05:00
|
|
|
int processing;
|
|
|
|
int destroying;
|
2014-02-20 15:17:41 -06:00
|
|
|
|
2013-12-08 17:05:18 -06:00
|
|
|
struct mem_funcs mf;
|
|
|
|
struct mem_funcs my_mf;
|
2013-12-08 16:15:57 -06:00
|
|
|
|
2015-08-19 03:47:46 -05:00
|
|
|
#ifdef HAVE_LIBUNBOUND
|
2014-09-12 07:44:53 -05:00
|
|
|
/* The underlying contexts that do the real work */
|
2014-01-21 14:31:22 -06:00
|
|
|
struct ub_ctx *unbound_ctx;
|
2015-07-09 17:05:26 -05:00
|
|
|
int unbound_ta_set;
|
2016-01-19 09:52:11 -06:00
|
|
|
#ifdef HAVE_UNBOUND_EVENT_API
|
2016-03-01 09:29:37 -06:00
|
|
|
_getdns_ub_loop ub_loop;
|
2016-01-19 09:52:11 -06:00
|
|
|
#endif
|
2015-08-19 03:47:46 -05:00
|
|
|
#endif
|
2014-09-23 06:36:26 -05:00
|
|
|
/* A tree to hold local host information*/
|
2015-08-19 09:07:01 -05:00
|
|
|
_getdns_rbtree_t local_hosts;
|
2015-06-30 07:43:52 -05:00
|
|
|
|
2013-11-05 14:03:44 -06:00
|
|
|
/* which resolution type the contexts are configured for
|
|
|
|
* 0 means nothing set
|
|
|
|
*/
|
2014-02-12 05:37:05 -06:00
|
|
|
getdns_resolution_t resolution_type_set;
|
2013-10-16 17:33:12 -05:00
|
|
|
|
2013-11-05 14:03:44 -06:00
|
|
|
/*
|
|
|
|
* outbound requests -> transaction to getdns_dns_req
|
|
|
|
*/
|
2015-08-19 09:07:01 -05:00
|
|
|
_getdns_rbtree_t outbound_requests;
|
2014-01-22 18:55:04 -06:00
|
|
|
|
2017-03-14 11:17:56 -05:00
|
|
|
/* network requests
|
|
|
|
*/
|
|
|
|
size_t netreqs_in_flight;
|
2017-03-15 09:16:42 -05:00
|
|
|
|
|
|
|
_getdns_rbtree_t pending_netreqs;
|
|
|
|
getdns_network_req *first_pending_netreq;
|
|
|
|
getdns_eventloop_event pending_timeout_event;
|
2017-03-14 11:17:56 -05:00
|
|
|
|
2016-07-13 07:50:44 -05:00
|
|
|
struct listen_set *server;
|
|
|
|
|
2014-10-08 08:42:33 -05:00
|
|
|
/* Event loop extension. */
|
|
|
|
getdns_eventloop *extension;
|
2015-08-19 03:47:46 -05:00
|
|
|
|
|
|
|
#ifdef HAVE_LIBUNBOUND
|
2014-10-08 08:42:33 -05:00
|
|
|
getdns_eventloop_event ub_event;
|
2016-03-17 10:49:05 -05:00
|
|
|
/* lock to prevent nested ub_event scheduling */
|
|
|
|
int ub_event_scheduling;
|
2015-08-19 03:47:46 -05:00
|
|
|
#endif
|
2014-09-30 08:12:48 -05:00
|
|
|
|
2014-10-06 16:04:12 -05:00
|
|
|
/* The default extension */
|
2016-01-12 08:52:14 -06:00
|
|
|
_getdns_default_eventloop default_eventloop;
|
2016-03-09 04:16:19 -06:00
|
|
|
_getdns_default_eventloop sync_eventloop;
|
2014-02-10 18:59:45 -06:00
|
|
|
|
2016-07-07 07:47:38 -05:00
|
|
|
/* request extension defaults */
|
|
|
|
getdns_dict *header;
|
|
|
|
getdns_dict *add_opt_parameters;
|
2016-12-08 09:36:23 -06:00
|
|
|
unsigned add_warning_for_bad_dns : 1;
|
|
|
|
unsigned dnssec_return_all_statuses : 1;
|
|
|
|
unsigned dnssec_return_full_validation_chain : 1;
|
|
|
|
unsigned dnssec_return_only_secure : 1;
|
|
|
|
unsigned dnssec_return_status : 1;
|
|
|
|
unsigned dnssec_return_validation_chain : 1;
|
2016-07-07 07:47:38 -05:00
|
|
|
#ifdef DNSSEC_ROADBLOCK_AVOIDANCE
|
2016-12-08 09:36:23 -06:00
|
|
|
unsigned dnssec_roadblock_avoidance : 1;
|
2016-07-07 07:47:38 -05:00
|
|
|
#endif
|
2016-12-08 09:36:23 -06:00
|
|
|
unsigned edns_cookies : 1;
|
|
|
|
unsigned return_api_information : 1; /* Not used */
|
|
|
|
unsigned return_both_v4_and_v6 : 1;
|
|
|
|
unsigned return_call_reporting : 1;
|
2016-07-07 07:47:38 -05:00
|
|
|
uint16_t specify_class;
|
|
|
|
|
2017-06-28 13:35:30 -05:00
|
|
|
/*
|
|
|
|
* Context for doing system queries.
|
|
|
|
* For example to resolve data.iana.org or to resolver the addresses
|
|
|
|
* of upstreams without specified addresses.
|
|
|
|
*/
|
|
|
|
getdns_context *sys_ctxt;
|
|
|
|
|
|
|
|
/* List of dnsreqs that want to be notified when we have fetched a
|
|
|
|
* trust anchor from data.iana.org.
|
|
|
|
*/
|
|
|
|
getdns_dns_req *ta_notify;
|
|
|
|
|
2014-02-10 18:59:45 -06:00
|
|
|
/*
|
|
|
|
* state data used to detect changes to the system config files
|
|
|
|
*/
|
2017-12-12 05:24:31 -06:00
|
|
|
struct filechg fchg_resolvconf;
|
|
|
|
struct filechg fchg_hosts;
|
2014-02-10 18:59:45 -06:00
|
|
|
|
2015-06-30 07:43:52 -05:00
|
|
|
uint8_t trust_anchors_spc[1024];
|
|
|
|
|
2016-01-12 08:52:14 -06:00
|
|
|
#ifdef USE_WINSOCK
|
|
|
|
/* We need to run WSAStartup() to be able to use getaddrinfo() */
|
|
|
|
WSADATA wsaData;
|
|
|
|
#endif
|
2017-01-20 21:44:05 -06:00
|
|
|
|
|
|
|
/* MDNS */
|
|
|
|
#ifdef HAVE_MDNS_SUPPORT
|
|
|
|
/*
|
|
|
|
* If supporting MDNS, context may be instantiated either in basic mode
|
|
|
|
* or in full mode. If working in extended mode, two multicast sockets are
|
|
|
|
* left open, for IPv4 and IPv6. Data can be received on either socket.
|
|
|
|
* The context also keeps a list of open queries, characterized by a
|
2017-02-06 22:23:35 -06:00
|
|
|
* name and an RR type, and a list of received answers, characterized
|
|
|
|
* by name, RR type and data value.
|
2017-01-20 21:44:05 -06:00
|
|
|
*/
|
2017-02-06 22:23:35 -06:00
|
|
|
int mdns_extended_support; /* 0 = no support, 1 = supported, 2 = initialization needed */
|
2017-02-13 22:28:46 -06:00
|
|
|
int mdns_connection_nb; /* typically 0 or 2 for IPv4 and IPv6 */
|
|
|
|
struct mdns_network_connection * mdns_connection;
|
|
|
|
struct lruhash * mdns_cache;
|
2017-01-20 21:44:05 -06:00
|
|
|
|
|
|
|
#endif /* HAVE_MDNS_SUPPORT */
|
2014-02-10 18:59:45 -06:00
|
|
|
}; /* getdns_context */
|
2013-08-12 16:38:05 -05:00
|
|
|
|
2017-06-26 17:23:22 -05:00
|
|
|
void _getdns_upstream_log(getdns_upstream *upstream, uint64_t system,
|
|
|
|
getdns_loglevel_type level, const char *fmt, ...);
|
|
|
|
|
|
|
|
void _getdns_context_log(getdns_context *context, uint64_t system,
|
|
|
|
getdns_loglevel_type level, const char *fmt, ...);
|
|
|
|
|
|
|
|
|
2013-10-16 13:45:43 -05:00
|
|
|
/** internal functions **/
|
|
|
|
/**
|
|
|
|
* Sets up the unbound contexts with stub or recursive behavior
|
|
|
|
* if needed.
|
2014-02-10 18:59:45 -06:00
|
|
|
* @param context previously initialized getdns_context
|
|
|
|
* @return GETDNS_RETURN_GOOD on success
|
2013-10-16 13:45:43 -05:00
|
|
|
*/
|
2017-09-28 15:17:36 -05:00
|
|
|
getdns_return_t _getdns_context_prepare_for_resolution(getdns_context *context);
|
2013-10-16 13:45:43 -05:00
|
|
|
|
2017-02-18 06:16:25 -06:00
|
|
|
/* Register a getdns_dns_req with context.
|
|
|
|
* - Without pluggable unbound event API,
|
|
|
|
* ub_fd() is scheduled when this was the first request.
|
|
|
|
*/
|
|
|
|
void _getdns_context_track_outbound_request(getdns_dns_req *dnsreq);
|
|
|
|
|
|
|
|
/* Deregister getdns_dns_req from the context.
|
|
|
|
* - Without pluggable unbound event API,
|
|
|
|
* ub_fd() is scheduled when this was the first request.
|
|
|
|
* - Potential timeout events will be cleared.
|
|
|
|
* - All associated getdns_dns_reqs (to get the validation chain)
|
|
|
|
* will be canceled.
|
|
|
|
*/
|
|
|
|
void _getdns_context_clear_outbound_request(getdns_dns_req *dnsreq);
|
|
|
|
|
|
|
|
/* Cancels and frees a getdns_dns_req (without calling user callbacks)
|
|
|
|
* - Deregisters getdns_dns_req with _getdns_context_clear_outbound_request()
|
|
|
|
* - Cancels associated getdns_network_reqs
|
|
|
|
* (by calling ub_cancel() or _getdns_cancel_stub_request())
|
|
|
|
* - Frees the getdns_dns_req
|
|
|
|
*/
|
|
|
|
void _getdns_context_cancel_request(getdns_dns_req *dnsreq);
|
|
|
|
|
|
|
|
/* Calls user callback (with GETDNS_CALLBACK_TIMEOUT + response dict), then
|
|
|
|
* cancels and frees the getdns_dns_req with _getdns_context_cancel_request()
|
|
|
|
*/
|
|
|
|
void _getdns_context_request_timed_out(getdns_dns_req *dnsreq);
|
2013-10-16 17:33:12 -05:00
|
|
|
|
2015-08-19 09:30:15 -05:00
|
|
|
struct getdns_bindata *_getdns_bindata_copy(
|
2015-12-07 09:43:41 -06:00
|
|
|
struct mem_funcs *mfs, size_t size, const uint8_t *data);
|
2013-11-11 16:10:22 -06:00
|
|
|
|
2015-08-19 09:30:15 -05:00
|
|
|
void _getdns_bindata_destroy(
|
2013-12-08 17:05:18 -06:00
|
|
|
struct mem_funcs *mfs,
|
2013-11-11 16:10:22 -06:00
|
|
|
struct getdns_bindata *bindata);
|
|
|
|
|
2014-09-23 06:36:26 -05:00
|
|
|
/* perform name resolution in /etc/hosts */
|
2015-08-19 09:30:15 -05:00
|
|
|
getdns_return_t _getdns_context_local_namespace_resolve(
|
2014-10-23 16:00:30 -05:00
|
|
|
getdns_dns_req* req, struct getdns_dict **response);
|
2014-09-23 06:36:26 -05:00
|
|
|
|
2015-08-19 09:22:38 -05:00
|
|
|
void _getdns_context_ub_read_cb(void *userarg);
|
2014-10-15 05:16:34 -05:00
|
|
|
|
2015-08-19 09:22:38 -05:00
|
|
|
void _getdns_upstreams_dereference(getdns_upstreams *upstreams);
|
2015-04-18 15:17:28 -05:00
|
|
|
|
2015-08-19 09:22:38 -05:00
|
|
|
void _getdns_upstream_shutdown(getdns_upstream *upstream);
|
2015-06-29 03:09:13 -05:00
|
|
|
|
2017-09-20 03:30:13 -05:00
|
|
|
FILE *_getdns_context_get_priv_fp(getdns_context *context, const char *fn);
|
2017-06-20 08:38:32 -05:00
|
|
|
uint8_t *_getdns_context_get_priv_file(getdns_context *context,
|
|
|
|
const char *fn, uint8_t *buf, size_t buf_len, size_t *file_sz);
|
|
|
|
|
2017-09-16 11:16:21 -05:00
|
|
|
int _getdns_context_write_priv_file(getdns_context *context,
|
2017-06-30 17:05:20 -05:00
|
|
|
const char *fn, getdns_bindata *content);
|
|
|
|
|
2017-09-16 11:16:21 -05:00
|
|
|
int _getdns_context_can_write_appdata(getdns_context *context);
|
|
|
|
|
2017-11-23 05:39:07 -06:00
|
|
|
getdns_context *_getdns_context_get_sys_ctxt(
|
|
|
|
getdns_context *context, getdns_eventloop *loop);
|
|
|
|
|
2013-11-06 12:32:05 -06:00
|
|
|
#endif /* _GETDNS_CONTEXT_H_ */
|