mirror of https://github.com/getdnsapi/getdns.git
Default values for extensions in context
This commit is contained in:
parent
e0eb39a295
commit
d0f01b6bc4
|
@ -1272,6 +1272,27 @@ getdns_context_create_with_extended_memory_functions(
|
|||
_getdns_default_eventloop_init(&result->default_eventloop);
|
||||
_getdns_default_eventloop_init(&result->sync_eventloop);
|
||||
|
||||
/* request extension defaults
|
||||
*/
|
||||
result->header = NULL;
|
||||
result->add_opt_parameters = NULL;
|
||||
result->add_warning_for_bad_dns = 0;
|
||||
result->dnssec_return_all_statuses = 0;
|
||||
result->dnssec_return_full_validation_chain = 0;
|
||||
result->dnssec_return_only_secure = 0;
|
||||
result->dnssec_return_status = 0;
|
||||
result->dnssec_return_validation_chain = 0;
|
||||
#ifdef DNSSEC_ROADBLOCK_AVOIDANCE
|
||||
result->dnssec_roadblock_avoidance = 0;
|
||||
#endif
|
||||
result->edns_cookies = 0;
|
||||
result->return_api_information = 0;
|
||||
result->return_both_v4_and_v6 = 0;
|
||||
result->return_call_reporting = 0;
|
||||
result->specify_class = GETDNS_RRCLASS_IN;
|
||||
|
||||
/* state data used to detect changes to the system config files
|
||||
*/
|
||||
result->fchg_resolvconf = NULL;
|
||||
result->fchg_hosts = NULL;
|
||||
|
||||
|
@ -1291,7 +1312,6 @@ getdns_context_create_with_extended_memory_functions(
|
|||
result->tls_auth = GETDNS_AUTHENTICATION_NONE;
|
||||
result->tls_auth_min = GETDNS_AUTHENTICATION_NONE;
|
||||
result->limit_outstanding_queries = 0;
|
||||
result->return_dnssec_status = GETDNS_EXTENSION_FALSE;
|
||||
|
||||
/* unbound context is initialized here */
|
||||
/* Unbound needs SSL to be init'ed this early when TLS is used. However we
|
||||
|
@ -1401,8 +1421,7 @@ getdns_context_destroy(struct getdns_context *context)
|
|||
if (context->tls_ctx)
|
||||
SSL_CTX_free(context->tls_ctx);
|
||||
|
||||
if (context->dns_root_servers)
|
||||
getdns_list_destroy(context->dns_root_servers);
|
||||
getdns_list_destroy(context->dns_root_servers);
|
||||
|
||||
#if defined(HAVE_LIBUNBOUND) && !defined(HAVE_UB_CTX_SET_STUB)
|
||||
if (context->root_servers_fn[0])
|
||||
|
@ -1419,6 +1438,10 @@ getdns_context_destroy(struct getdns_context *context)
|
|||
_getdns_traverse_postorder(&context->local_hosts,
|
||||
destroy_local_host, context);
|
||||
|
||||
|
||||
getdns_dict_destroy(context->header);
|
||||
getdns_dict_destroy(context->add_opt_parameters);
|
||||
|
||||
#ifdef USE_WINSOCK
|
||||
WSACleanup();
|
||||
#endif
|
||||
|
@ -3416,7 +3439,7 @@ getdns_context_set_return_dnssec_status(getdns_context* context, int enabled) {
|
|||
enabled != GETDNS_EXTENSION_FALSE) {
|
||||
return GETDNS_RETURN_INVALID_PARAMETER;
|
||||
}
|
||||
context->return_dnssec_status = enabled;
|
||||
context->dnssec_return_status = enabled == GETDNS_EXTENSION_TRUE;
|
||||
return GETDNS_RETURN_GOOD;
|
||||
}
|
||||
|
||||
|
|
|
@ -250,8 +250,6 @@ struct getdns_context {
|
|||
/* A tree to hold local host information*/
|
||||
_getdns_rbtree_t local_hosts;
|
||||
|
||||
int return_dnssec_status;
|
||||
|
||||
/* which resolution type the contexts are configured for
|
||||
* 0 means nothing set
|
||||
*/
|
||||
|
@ -275,6 +273,24 @@ struct getdns_context {
|
|||
_getdns_default_eventloop default_eventloop;
|
||||
_getdns_default_eventloop sync_eventloop;
|
||||
|
||||
/* request extension defaults */
|
||||
getdns_dict *header;
|
||||
getdns_dict *add_opt_parameters;
|
||||
int add_warning_for_bad_dns : 1;
|
||||
int dnssec_return_all_statuses : 1;
|
||||
int dnssec_return_full_validation_chain : 1;
|
||||
int dnssec_return_only_secure : 1;
|
||||
int dnssec_return_status : 1;
|
||||
int dnssec_return_validation_chain : 1;
|
||||
#ifdef DNSSEC_ROADBLOCK_AVOIDANCE
|
||||
int dnssec_roadblock_avoidance : 1;
|
||||
#endif
|
||||
int edns_cookies : 1;
|
||||
int return_api_information : 1; /* Not used */
|
||||
int return_both_v4_and_v6 : 1;
|
||||
int return_call_reporting : 1;
|
||||
uint16_t specify_class;
|
||||
|
||||
/*
|
||||
* state data used to detect changes to the system config files
|
||||
*/
|
||||
|
|
|
@ -85,20 +85,20 @@ getdns_dict *dnssec_ok_checking_disabled_avoid_roadblocks
|
|||
|
||||
|
||||
static int
|
||||
is_extension_set(getdns_dict *extensions, const char *extension)
|
||||
is_extension_set(getdns_dict *extensions, const char *name, int default_value)
|
||||
{
|
||||
getdns_return_t r;
|
||||
uint32_t value;
|
||||
|
||||
if (! extensions)
|
||||
return 0;
|
||||
else if (extensions == dnssec_ok_checking_disabled
|
||||
if ( ! extensions
|
||||
|| extensions == dnssec_ok_checking_disabled
|
||||
|| extensions == dnssec_ok_checking_disabled_roadblock_avoidance
|
||||
|| extensions == dnssec_ok_checking_disabled_avoid_roadblocks)
|
||||
return 0;
|
||||
|
||||
r = getdns_dict_get_int(extensions, extension, &value);
|
||||
return r == GETDNS_RETURN_GOOD && value == GETDNS_EXTENSION_TRUE;
|
||||
r = getdns_dict_get_int(extensions, name, &value);
|
||||
return r == GETDNS_RETURN_GOOD ? ( value == GETDNS_EXTENSION_TRUE )
|
||||
: default_value;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -206,6 +206,8 @@ network_req_init(getdns_network_req *net_req, getdns_dns_req *owner,
|
|||
buf = netreq_reset(net_req);
|
||||
gldns_buffer_init_frm_data(
|
||||
&gbuf, net_req->query, net_req->wire_data_sz - 2);
|
||||
if (owner->context->header)
|
||||
_getdns_reply_dict2wire(owner->context->header, &gbuf, 1);
|
||||
_getdns_reply_dict2wire(extensions, &gbuf, 1);
|
||||
if (dnssec_extension_set) /* We will do validation ourselves */
|
||||
GLDNS_CD_SET(net_req->query);
|
||||
|
@ -658,28 +660,32 @@ getdns_dns_req *
|
|||
_getdns_dns_req_new(getdns_context *context, getdns_eventloop *loop,
|
||||
const char *name, uint16_t request_type, getdns_dict *extensions)
|
||||
{
|
||||
int dnssec_return_status
|
||||
= context->return_dnssec_status == GETDNS_EXTENSION_TRUE
|
||||
|| is_extension_set(extensions, "dnssec_return_status");
|
||||
int dnssec_return_only_secure
|
||||
= is_extension_set(extensions, "dnssec_return_only_secure");
|
||||
int dnssec_return_all_statuses
|
||||
= is_extension_set(extensions, "dnssec_return_all_statuses");
|
||||
int dnssec_return_full_validation_chain
|
||||
= is_extension_set(extensions, "dnssec_return_full_validation_chain");
|
||||
int dnssec_return_validation_chain
|
||||
= is_extension_set(extensions, "dnssec_return_validation_chain");
|
||||
int edns_cookies
|
||||
= is_extension_set(extensions, "edns_cookies");
|
||||
int dnssec_return_status = is_extension_set(
|
||||
extensions, "dnssec_return_status",
|
||||
context->dnssec_return_status);
|
||||
int dnssec_return_only_secure = is_extension_set(
|
||||
extensions, "dnssec_return_only_secure",
|
||||
context->dnssec_return_only_secure);
|
||||
int dnssec_return_all_statuses = is_extension_set(
|
||||
extensions, "dnssec_return_all_statuses",
|
||||
context->dnssec_return_all_statuses);
|
||||
int dnssec_return_full_validation_chain = is_extension_set(
|
||||
extensions, "dnssec_return_full_validation_chain",
|
||||
context->dnssec_return_full_validation_chain);
|
||||
int dnssec_return_validation_chain = is_extension_set(
|
||||
extensions, "dnssec_return_validation_chain",
|
||||
context->dnssec_return_validation_chain);
|
||||
int edns_cookies = is_extension_set(
|
||||
extensions, "edns_cookies",
|
||||
context->edns_cookies);
|
||||
#ifdef DNSSEC_ROADBLOCK_AVOIDANCE
|
||||
int avoid_dnssec_roadblocks
|
||||
= (extensions == dnssec_ok_checking_disabled_avoid_roadblocks);
|
||||
int dnssec_roadblock_avoidance
|
||||
= is_extension_set(extensions, "dnssec_roadblock_avoidance")
|
||||
int dnssec_roadblock_avoidance = avoid_dnssec_roadblocks
|
||||
|| (extensions == dnssec_ok_checking_disabled_roadblock_avoidance)
|
||||
|| avoid_dnssec_roadblocks;
|
||||
|| is_extension_set(extensions, "dnssec_roadblock_avoidance",
|
||||
context->dnssec_roadblock_avoidance);
|
||||
#endif
|
||||
|
||||
int dnssec_extension_set = dnssec_return_status
|
||||
|| dnssec_return_only_secure || dnssec_return_all_statuses
|
||||
|| dnssec_return_validation_chain
|
||||
|
@ -713,9 +719,9 @@ _getdns_dns_req_new(getdns_context *context, getdns_eventloop *loop,
|
|||
int with_opt;
|
||||
|
||||
getdns_dns_req *result = NULL;
|
||||
uint32_t klass = GLDNS_RR_CLASS_IN;
|
||||
int a_aaaa_query =
|
||||
is_extension_set(extensions, "return_both_v4_and_v6") &&
|
||||
uint32_t klass = context->specify_class;
|
||||
int a_aaaa_query = is_extension_set(extensions,
|
||||
"return_both_v4_and_v6", context->return_both_v4_and_v6) &&
|
||||
( request_type == GETDNS_RRTYPE_A ||
|
||||
request_type == GETDNS_RRTYPE_AAAA );
|
||||
/* Reserve for the buffer at least one more byte
|
||||
|
@ -732,7 +738,10 @@ _getdns_dns_req_new(getdns_context *context, getdns_eventloop *loop,
|
|||
|
||||
have_add_opt_parameters = getdns_dict_get_dict(extensions,
|
||||
"add_opt_parameters", &add_opt_parameters) == GETDNS_RETURN_GOOD;
|
||||
|
||||
if (!have_add_opt_parameters && context->add_opt_parameters) {
|
||||
add_opt_parameters = context->add_opt_parameters;
|
||||
have_add_opt_parameters = 1;
|
||||
}
|
||||
if (dnssec_extension_set) {
|
||||
edns_maximum_udp_payload_size = -1;
|
||||
edns_extended_rcode = 0;
|
||||
|
@ -895,10 +904,10 @@ _getdns_dns_req_new(getdns_context *context, getdns_eventloop *loop,
|
|||
#endif
|
||||
result->edns_client_subnet_private = context->edns_client_subnet_private;
|
||||
result->tls_query_padding_blocksize = context->tls_query_padding_blocksize;
|
||||
result->return_call_reporting =
|
||||
is_extension_set(extensions, "return_call_reporting");
|
||||
result->add_warning_for_bad_dns =
|
||||
is_extension_set(extensions, "add_warning_for_bad_dns");
|
||||
result->return_call_reporting = is_extension_set(extensions,
|
||||
"return_call_reporting" , context->return_call_reporting);
|
||||
result->add_warning_for_bad_dns = is_extension_set(extensions,
|
||||
"add_warning_for_bad_dns", context->add_warning_for_bad_dns);
|
||||
|
||||
/* will be set by caller */
|
||||
result->user_pointer = NULL;
|
||||
|
|
Loading…
Reference in New Issue