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"
|
2014-10-08 08:42:33 -05:00
|
|
|
#include "extension/libmini_event.h"
|
2014-10-16 04:28:32 -05:00
|
|
|
#include "util/rbtree.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
|
|
|
#define GETDNS_FN_RESOLVCONF "/etc/resolv.conf"
|
|
|
|
#define GETDNS_FN_HOSTS "/etc/hosts"
|
|
|
|
|
|
|
|
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 {
|
|
|
|
char *fn;
|
|
|
|
int changes;
|
|
|
|
int errors;
|
|
|
|
struct stat *prevstat;
|
|
|
|
};
|
|
|
|
|
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;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
/* How is this upstream doing? */
|
2015-06-24 12:49:34 -05:00
|
|
|
size_t writes_done;
|
2015-06-29 03:09:13 -05:00
|
|
|
size_t responses_received;
|
2014-10-17 17:25:41 -05:00
|
|
|
int to_retry;
|
|
|
|
int back_off;
|
|
|
|
|
|
|
|
/* For sharing a TCP socket to this upstream */
|
|
|
|
int fd;
|
2015-06-19 12:28:29 -05:00
|
|
|
getdns_transport_list_t transport;
|
2015-04-29 13:20:25 -05:00
|
|
|
SSL* tls_obj;
|
2015-04-19 11:16:58 -05:00
|
|
|
getdns_tls_hs_state_t tls_hs_state;
|
2014-10-17 17:25:41 -05:00
|
|
|
getdns_eventloop_event event;
|
|
|
|
getdns_eventloop *loop;
|
|
|
|
getdns_tcp_state tcp;
|
2015-09-04 03:56:30 -05:00
|
|
|
char tls_auth_name[256];
|
2015-09-29 06:09:39 -05:00
|
|
|
size_t tls_auth_failed;
|
2014-10-17 17:25:41 -05:00
|
|
|
|
|
|
|
/* Pipelining of TCP network requests */
|
|
|
|
getdns_network_req *write_queue;
|
2014-10-18 07:32:55 -05:00
|
|
|
getdns_network_req *write_queue_last;
|
2015-08-19 09:07:01 -05:00
|
|
|
_getdns_rbtree_t netreq_by_query_id;
|
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;
|
|
|
|
|
2014-10-16 07:24:13 -05:00
|
|
|
} getdns_upstream;
|
2014-09-30 08:12:48 -05:00
|
|
|
|
|
|
|
typedef struct getdns_upstreams {
|
|
|
|
struct mem_funcs mf;
|
|
|
|
size_t referenced;
|
|
|
|
size_t count;
|
2014-10-16 07:24:13 -05:00
|
|
|
size_t current;
|
|
|
|
getdns_upstream upstreams[];
|
2014-09-30 08:12:48 -05:00
|
|
|
} getdns_upstreams;
|
2013-08-12 16:38:05 -05:00
|
|
|
|
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;
|
|
|
|
int namespace_count;
|
|
|
|
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;
|
|
|
|
struct getdns_list *dns_root_servers;
|
2014-02-09 10:46:12 -06:00
|
|
|
getdns_append_name_t append_name;
|
2014-02-10 18:59:45 -06:00
|
|
|
struct getdns_list *suffix;
|
2015-06-30 07:43:52 -05:00
|
|
|
uint8_t *trust_anchors;
|
|
|
|
size_t trust_anchors_len;
|
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*/
|
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;
|
|
|
|
size_t dns_transport_current;
|
|
|
|
|
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
|
|
|
|
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;
|
2015-08-19 03:47:46 -05:00
|
|
|
#endif
|
2014-10-23 07:14:55 -05:00
|
|
|
|
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
|
|
|
|
2014-09-30 08:12:48 -05:00
|
|
|
int return_dnssec_status;
|
2013-10-16 17:33:12 -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
|
|
|
|
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;
|
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 */
|
2015-08-19 09:26:39 -05:00
|
|
|
_getdns_mini_event mini_event;
|
2014-02-10 18:59:45 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* state data used to detect changes to the system config files
|
|
|
|
*/
|
|
|
|
struct filechg *fchg_resolvconf;
|
|
|
|
struct filechg *fchg_hosts;
|
|
|
|
|
2015-06-30 07:43:52 -05:00
|
|
|
uint8_t trust_anchors_spc[1024];
|
|
|
|
|
2014-02-10 18:59:45 -06:00
|
|
|
}; /* getdns_context */
|
2013-08-12 16:38:05 -05:00
|
|
|
|
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
|
|
|
|
* @param usenamespaces if 0 then only use the DNS, else use context namespace list
|
|
|
|
* @return GETDNS_RETURN_GOOD on success
|
2013-10-16 13:45:43 -05:00
|
|
|
*/
|
2015-08-19 09:30:15 -05:00
|
|
|
getdns_return_t _getdns_context_prepare_for_resolution(struct getdns_context *context,
|
2014-02-10 18:59:45 -06:00
|
|
|
int usenamespaces);
|
2013-10-16 13:45:43 -05:00
|
|
|
|
2013-10-16 17:33:12 -05:00
|
|
|
/* track an outbound request */
|
2015-08-19 09:30:15 -05:00
|
|
|
getdns_return_t _getdns_context_track_outbound_request(struct getdns_dns_req
|
2013-11-05 14:03:44 -06:00
|
|
|
*req);
|
2013-10-16 17:33:12 -05:00
|
|
|
/* clear the outbound request from being tracked - does not cancel it */
|
2015-08-19 09:30:15 -05:00
|
|
|
getdns_return_t _getdns_context_clear_outbound_request(struct getdns_dns_req
|
2013-11-05 14:03:44 -06:00
|
|
|
*req);
|
2014-03-05 21:13:37 -06:00
|
|
|
|
2015-08-19 09:30:15 -05:00
|
|
|
getdns_return_t _getdns_context_request_timed_out(struct getdns_dns_req
|
2014-03-05 21:13:37 -06:00
|
|
|
*req);
|
|
|
|
|
2013-10-18 12:55:31 -05:00
|
|
|
/* cancel callback internal - flag to indicate if req should be freed and callback fired */
|
2015-08-19 09:30:15 -05:00
|
|
|
getdns_return_t _getdns_context_cancel_request(struct getdns_context *context,
|
2013-11-05 14:03:44 -06:00
|
|
|
getdns_transaction_t transaction_id, int fire_callback);
|
2013-10-16 17:33:12 -05:00
|
|
|
|
2015-08-19 09:30:15 -05:00
|
|
|
char *_getdns_strdup(const struct mem_funcs *mfs, const char *str);
|
2013-11-11 16:10:22 -06:00
|
|
|
|
2015-08-19 09:30:15 -05:00
|
|
|
struct getdns_bindata *_getdns_bindata_copy(
|
2013-12-08 17:05:18 -06:00
|
|
|
struct mem_funcs *mfs,
|
2013-11-11 16:10:22 -06:00
|
|
|
const struct getdns_bindata *src);
|
|
|
|
|
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:33:19 -05:00
|
|
|
int _getdns_filechg_check(struct getdns_context *context, struct filechg *fchg);
|
2014-02-10 18:59:45 -06: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
|
|
|
|
2013-11-06 12:32:05 -06:00
|
|
|
#endif /* _GETDNS_CONTEXT_H_ */
|