Re-enabled stub resolution

Also re-indented the prepare_for_resolution and ub_setup_stub functions
Sorry for that.
This commit is contained in:
Willem Toorop 2014-02-12 12:37:05 +01:00
parent a3f50a6d86
commit 340655330b
3 changed files with 161 additions and 126 deletions

View File

@ -1111,19 +1111,35 @@ getdns_cancel_callback(struct getdns_context *context,
return getdns_context_cancel_request(context, transaction_id, 1);
} /* getdns_cancel_callback */
static void
ub_setup_stub(struct ub_ctx *ctx, struct getdns_list * upstreams, size_t count)
static getdns_return_t
ub_setup_stub(struct ub_ctx *ctx, struct getdns_list * upstreams)
{
size_t i;
size_t count;
struct getdns_dict *dict;
struct getdns_bindata *address_string;
getdns_return_t r;
r = getdns_list_get_length(upstreams, &count);
if (r != GETDNS_RETURN_GOOD)
return r;
if (count == 0)
return GETDNS_RETURN_BAD_CONTEXT;
/* reset forwarding servers */
ub_ctx_set_fwd(ctx, NULL);
(void) ub_ctx_set_fwd(ctx, NULL);
for (i = 0; i < count; ++i) {
struct getdns_dict *dict = NULL;
char *ip_str = NULL;
getdns_list_get_dict(upstreams, i, &dict);
getdns_dict_util_get_string(dict, GETDNS_STR_ADDRESS_STRING,
&ip_str);
ub_ctx_set_fwd(ctx, ip_str);
r = getdns_list_get_dict(upstreams, i, &dict);
if (r != GETDNS_RETURN_GOOD)
break;
r = getdns_dict_get_bindata(dict, GETDNS_STR_ADDRESS_STRING,
&address_string);
if (r != GETDNS_RETURN_GOOD)
break;
(void) ub_ctx_set_fwd(ctx, (char *)address_string->data);
}
/* Allow lookups of:
*/
@ -1180,60 +1196,75 @@ ub_setup_stub(struct ub_ctx *ctx, struct getdns_list * upstreams, size_t count)
/* - reverse IPv6 Example Prefix */
(void)ub_ctx_zone_remove(ctx, "8.B.D.0.1.0.0.2.ip6.arpa.");
return r;
}
static getdns_return_t
priv_getdns_ns_dns_setup(struct getdns_context *context)
{
assert(context);
switch (context->resolution_type) {
case GETDNS_RESOLUTION_STUB:
return ub_setup_stub(context->unbound_ctx,
context->upstream_list);
case GETDNS_RESOLUTION_RECURSING:
/* TODO: use the root servers via root hints file */
(void) ub_ctx_set_fwd(context->unbound_ctx, NULL);
return GETDNS_RETURN_GOOD;
}
return GETDNS_RETURN_BAD_CONTEXT;
}
getdns_return_t
getdns_context_prepare_for_resolution(struct getdns_context *context, int usenamespaces)
getdns_context_prepare_for_resolution(struct getdns_context *context,
int usenamespaces)
{
int i;
size_t upstream_len = 0;
getdns_return_t r;
RETURN_IF_NULL(context, GETDNS_RETURN_INVALID_PARAMETER);
if (context->resolution_type_set == context->resolution_type)
{
/* already set and no config changes have caused this to be bad. */
return GETDNS_RETURN_BAD_CONTEXT;
}
/* already set and no config changes
* have caused this to be bad.
*/
return GETDNS_RETURN_GOOD;
/* TODO: respect namespace order (unbound always uses local first if cfg
* the spec calls for us to treat the namespace list as ordered
* so we need to respect that order
*/
if(usenamespaces == 0)
{
ub_setup_stub(context->unbound_ctx, context->upstream_list,
upstream_len);
}
else
{
for(i=0; i<context->namespace_count; i++)
{
if(context->namespaces[i] == GETDNS_NAMESPACE_LOCALNAMES)
{
ub_ctx_hosts(context->unbound_ctx, NULL);
}
else if(context->namespaces[i] == GETDNS_NAMESPACE_DNS)
{
if (context->resolution_type == GETDNS_RESOLUTION_STUB)
{
getdns_return_t r =
getdns_list_get_length(context->upstream_list, &upstream_len);
if (r != GETDNS_RETURN_GOOD || upstream_len == 0)
return GETDNS_RETURN_BAD_CONTEXT;
} else if (context->resolution_type == GETDNS_RESOLUTION_RECURSING)
{
/* TODO: use the root servers via root hints file */
ub_ctx_set_fwd(context->unbound_ctx, NULL);
} else
return GETDNS_RETURN_BAD_CONTEXT;
} /* DNS */
} /* for i */
} /* if usenamespaces = 0 else */
if (! usenamespaces) {
r = priv_getdns_ns_dns_setup(context);
if (r == GETDNS_RETURN_GOOD)
context->resolution_type_set = context->resolution_type;
return r;
}
return GETDNS_RETURN_GOOD;
r = GETDNS_RETURN_GOOD;
for (i = 0; i < context->namespace_count; i++) {
switch (context->namespaces[i]) {
case GETDNS_NAMESPACE_LOCALNAMES:
(void) ub_ctx_hosts(context->unbound_ctx, NULL);
break;
case GETDNS_NAMESPACE_DNS:
r = priv_getdns_ns_dns_setup(context);
break;
default:
r = GETDNS_RETURN_BAD_CONTEXT;
break;
}
if (r != GETDNS_RETURN_GOOD)
return r; /* try again later (resolution_type_set) */
}
context->resolution_type_set = context->resolution_type;
return r;
} /* getdns_context_prepare_for_resolution */
getdns_return_t

View File

@ -95,7 +95,7 @@ struct getdns_context {
/* which resolution type the contexts are configured for
* 0 means nothing set
*/
uint8_t resolution_type_set;
getdns_resolution_t resolution_type_set;
/*
* outbound requests -> transaction to getdns_dns_req

View File

@ -77,33 +77,37 @@ getdns_general_sync(struct getdns_context *context,
struct getdns_dict *extensions,
struct getdns_dict **response)
{
getdns_dns_req *req;
getdns_return_t response_status;
RETURN_IF_NULL(context, GETDNS_RETURN_INVALID_PARAMETER);
RETURN_IF_NULL(response, GETDNS_RETURN_INVALID_PARAMETER);
RETURN_IF_NULL(name, GETDNS_RETURN_INVALID_PARAMETER);
response_status = validate_dname(name);
if (response_status != GETDNS_RETURN_GOOD) {
if (response_status != GETDNS_RETURN_GOOD)
return response_status;
}
response_status = validate_extensions(extensions);
if (response_status == GETDNS_RETURN_GOOD) {
if (response_status != GETDNS_RETURN_GOOD)
return response_status;
/* general, so without dns lookup (no namespaces) */;
response_status = getdns_context_prepare_for_resolution(context, 0);
if (response_status != GETDNS_RETURN_GOOD)
return response_status;
/* for each netreq we call ub_ctx_resolve */
/* request state */
getdns_dns_req *req = dns_req_new(context,
name,
request_type,
extensions);
if (!req) {
return GETDNS_RETURN_GENERIC_ERROR;
}
req = dns_req_new(context, name, request_type, extensions);
if (!req)
return GETDNS_RETURN_MEMORY_ERROR;
response_status = submit_request_sync(req);
if (response_status != GETDNS_RETURN_GOOD) {
dns_req_free(req);
return response_status;
}
if (response_status == GETDNS_RETURN_GOOD)
*response = create_getdns_response(req);
dns_req_free(req);
}
return response_status;
}