mirror of https://github.com/getdnsapi/getdns.git
Adding A and AAAA handling for get_address
This commit is contained in:
parent
c53c00ee2b
commit
da8dad5913
|
@ -31,7 +31,7 @@ all: libgetdns
|
|||
cd test && $(MAKE) $@
|
||||
cd example && $(MAKE) $@
|
||||
|
||||
libgetdns: sync.o context.o list.o dict.o convert.o general.o hostname.o service.o \
|
||||
libgetdns: sync.o context.o list.o dict.o convert.o general.o hostname.o service.o request-internal.o \
|
||||
validate_dnssec.o util-internal.o getdns_error.o
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) -shared -o libgetdns.so $?
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#include <stdlib.h>
|
||||
#include "context.h"
|
||||
#include "util-internal.h"
|
||||
#include "types-internal.h"
|
||||
#include <ldns/ldns.h>
|
||||
#include <event2/event.h>
|
||||
#include <unbound.h>
|
||||
|
@ -162,6 +163,26 @@ static getdns_return_t set_os_defaults(getdns_context_t context) {
|
|||
return GETDNS_RETURN_GOOD;
|
||||
}
|
||||
|
||||
static int transaction_id_cmp(const void* id1, const void* id2) {
|
||||
if (id1 == NULL && id2 == NULL) {
|
||||
return 0;
|
||||
} else if (id1 == NULL && id2 != NULL) {
|
||||
return 1;
|
||||
} else if (id1 != NULL && id2 == NULL) {
|
||||
return -1;
|
||||
} else {
|
||||
getdns_transaction_t t1 = *((const getdns_transaction_t*) id1);
|
||||
getdns_transaction_t t2 = *((const getdns_transaction_t*) id2);
|
||||
if (t1 == t2) {
|
||||
return 0;
|
||||
} else if (t1 < t2) {
|
||||
return -1;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* getdns_context_create
|
||||
*
|
||||
|
@ -193,9 +214,12 @@ getdns_return_t getdns_context_create(
|
|||
result->unbound_sync = ub_ctx_create_event(result->event_base_sync);
|
||||
/* create the async one also so options are kept up to date */
|
||||
result->unbound_async = ub_ctx_create_event(result->event_base_sync);
|
||||
|
||||
result->async_set = 0;
|
||||
result->resolution_type_set = 0;
|
||||
|
||||
result->outbound_requests = ldns_rbtree_create(transaction_id_cmp);
|
||||
|
||||
result->resolution_type = GETDNS_CONTEXT_RECURSING;
|
||||
result->namespaces = create_default_namespaces();
|
||||
|
||||
|
@ -258,6 +282,7 @@ getdns_context_destroy(
|
|||
|
||||
event_base_free(context->event_base_sync);
|
||||
|
||||
ldns_rbtree_free(context->outbound_requests);
|
||||
|
||||
free(context);
|
||||
return;
|
||||
|
@ -791,8 +816,8 @@ getdns_extension_set_libevent_base(
|
|||
ub_ctx_set_event(context->unbound_async, this_event_base);
|
||||
context->async_set = 1;
|
||||
} else {
|
||||
context->async_set = 0;
|
||||
ub_ctx_set_event(context->unbound_async, context->event_base_sync);
|
||||
context->async_set = 0;
|
||||
}
|
||||
return GETDNS_RETURN_GOOD;
|
||||
} /* getdns_extension_set_libevent_base */
|
||||
|
@ -856,4 +881,36 @@ getdns_return_t getdns_context_prepare_for_resolution(getdns_context_t context)
|
|||
return GETDNS_RETURN_GOOD;
|
||||
}
|
||||
|
||||
getdns_return_t getdns_context_track_outbound_request(getdns_dns_req* req) {
|
||||
if (!req) {
|
||||
return GETDNS_RETURN_GENERIC_ERROR;
|
||||
}
|
||||
getdns_context_t context = req->context;
|
||||
ldns_rbnode_t* node = context->memory_allocator(sizeof(ldns_rbnode_t));
|
||||
if (!node) {
|
||||
return GETDNS_RETURN_GENERIC_ERROR;
|
||||
}
|
||||
node->key = &(req->trans_id);
|
||||
node->data = req;
|
||||
if (!ldns_rbtree_insert(context->outbound_requests, node)) {
|
||||
/* free the node */
|
||||
context->memory_deallocator(node);
|
||||
return GETDNS_RETURN_GENERIC_ERROR;
|
||||
}
|
||||
return GETDNS_RETURN_GOOD;
|
||||
}
|
||||
|
||||
getdns_return_t getdns_context_clear_outbound_request(getdns_dns_req* req) {
|
||||
if (!req) {
|
||||
return GETDNS_RETURN_GENERIC_ERROR;
|
||||
}
|
||||
getdns_context_t context = req->context;
|
||||
ldns_rbnode_t* node = ldns_rbtree_delete(context->outbound_requests,
|
||||
&(req->trans_id));
|
||||
if (node) {
|
||||
context->memory_deallocator(node);
|
||||
}
|
||||
return GETDNS_RETURN_GOOD;
|
||||
}
|
||||
|
||||
/* getdns_context.c */
|
||||
|
|
|
@ -34,6 +34,8 @@
|
|||
|
||||
struct event_base;
|
||||
struct ub_ctx;
|
||||
struct ldns_rbtree_t;
|
||||
struct getdns_dns_req;
|
||||
|
||||
/** function pointer typedefs */
|
||||
typedef void (*getdns_update_callback)(getdns_context_t context, uint16_t changed_item);
|
||||
|
@ -72,11 +74,16 @@ struct getdns_context_t {
|
|||
struct ub_ctx *unbound_async;
|
||||
/* whether an async event base was set */
|
||||
uint8_t async_set;
|
||||
|
||||
/* which resolution type the contexts are configured for
|
||||
* 0 means nothing set
|
||||
*/
|
||||
uint8_t resolution_type_set;
|
||||
|
||||
/*
|
||||
* outbound requests -> transaction to getdns_dns_req
|
||||
*/
|
||||
struct ldns_rbtree_t* outbound_requests;
|
||||
} ;
|
||||
|
||||
/** internal functions **/
|
||||
|
@ -86,5 +93,10 @@ struct getdns_context_t {
|
|||
*/
|
||||
getdns_return_t getdns_context_prepare_for_resolution(getdns_context_t context);
|
||||
|
||||
/* track an outbound request */
|
||||
getdns_return_t getdns_context_track_outbound_request(struct getdns_dns_req* req);
|
||||
/* clear the outbound request from being tracked - does not cancel it */
|
||||
getdns_return_t getdns_context_clear_outbound_request(struct getdns_dns_req* req);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
172
src/general.c
172
src/general.c
|
@ -63,100 +63,142 @@
|
|||
#include <unbound-event.h>
|
||||
#include <ldns/ldns.h>
|
||||
#include "context.h"
|
||||
#include "types-internal.h"
|
||||
#include "util-internal.h"
|
||||
|
||||
/* stuff to make it compile pedantically */
|
||||
#define UNUSED_PARAM(x) ((void)(x))
|
||||
|
||||
typedef struct getdns_ub_req {
|
||||
struct ub_ctx *unbound;
|
||||
getdns_context_t context;
|
||||
char* name;
|
||||
void* userarg;
|
||||
getdns_callback_t callback;
|
||||
getdns_transaction_t transaction_id;
|
||||
} getdns_ub_req;
|
||||
/* declarations */
|
||||
static void ub_resolve_callback(void* arg, int err, ldns_buffer* result, int sec, char* bogus);
|
||||
static void handle_network_request_error(getdns_network_req* netreq, int err);
|
||||
static void handle_dns_request_complete(getdns_dns_req* dns_req);
|
||||
static int submit_network_request(getdns_network_req* netreq);
|
||||
|
||||
static void getdns_ub_req_free(getdns_ub_req* req) {
|
||||
free(req->name);
|
||||
free(req);
|
||||
/* cleanup and send an error to the user callback */
|
||||
static void handle_network_request_error(getdns_network_req* netreq, int err) {
|
||||
getdns_dns_req *dns_req = netreq->owner;
|
||||
getdns_context_t context = dns_req->context;
|
||||
getdns_transaction_t trans_id = dns_req->trans_id;
|
||||
getdns_callback_t cb = dns_req->user_callback;
|
||||
void* user_arg = dns_req->user_pointer;
|
||||
|
||||
/* clean up */
|
||||
getdns_context_clear_outbound_request(dns_req);
|
||||
dns_req_free(dns_req);
|
||||
|
||||
cb(context,
|
||||
GETDNS_CALLBACK_ERROR,
|
||||
NULL,
|
||||
user_arg,
|
||||
trans_id);
|
||||
}
|
||||
|
||||
void ub_resolve_callback(void* arg, int err, ldns_buffer* result, int sec, char* bogus) {
|
||||
getdns_ub_req* req = (getdns_ub_req*) arg;
|
||||
ldns_pkt* pkt = NULL;
|
||||
if (err) {
|
||||
req->callback(req->context,
|
||||
GETDNS_CALLBACK_ERROR,
|
||||
NULL,
|
||||
req->userarg,
|
||||
req->transaction_id);
|
||||
} else {
|
||||
/* parse */
|
||||
ldns_status r = ldns_buffer2pkt_wire(&pkt, result);
|
||||
if (r != LDNS_STATUS_OK) {
|
||||
req->callback(req->context,
|
||||
GETDNS_CALLBACK_ERROR,
|
||||
NULL,
|
||||
req->userarg,
|
||||
req->transaction_id);
|
||||
} else {
|
||||
getdns_dict* response = create_getdns_response(pkt);
|
||||
ldns_pkt_free(pkt);
|
||||
req->callback(req->context,
|
||||
/* cleanup and send the response to the user callback */
|
||||
static void handle_dns_request_complete(getdns_dns_req* dns_req) {
|
||||
getdns_dict* response = create_getdns_response(dns_req);
|
||||
|
||||
getdns_context_t context = dns_req->context;
|
||||
getdns_transaction_t trans_id = dns_req->trans_id;
|
||||
getdns_callback_t cb = dns_req->user_callback;
|
||||
void* user_arg = dns_req->user_pointer;
|
||||
|
||||
/* clean up the request */
|
||||
getdns_context_clear_outbound_request(dns_req);
|
||||
dns_req_free(dns_req);
|
||||
|
||||
cb(context,
|
||||
GETDNS_CALLBACK_COMPLETE,
|
||||
response,
|
||||
req->userarg,
|
||||
req->transaction_id);
|
||||
user_arg,
|
||||
trans_id);
|
||||
}
|
||||
|
||||
static int submit_network_request(getdns_network_req* netreq) {
|
||||
getdns_dns_req *dns_req = netreq->owner;
|
||||
netreq->state = NET_REQ_IN_FLIGHT;
|
||||
return ub_resolve_event(dns_req->unbound,
|
||||
dns_req->name,
|
||||
netreq->request_type,
|
||||
netreq->request_class,
|
||||
netreq,
|
||||
ub_resolve_callback,
|
||||
&(netreq->unbound_id));
|
||||
}
|
||||
|
||||
static void ub_resolve_callback(void* arg, int err, ldns_buffer* result, int sec, char* bogus) {
|
||||
getdns_network_req* netreq = (getdns_network_req*) arg;
|
||||
netreq->state = NET_REQ_FINISHED;
|
||||
if (err) {
|
||||
handle_network_request_error(netreq, err);
|
||||
} else {
|
||||
/* parse */
|
||||
ldns_status r = ldns_buffer2pkt_wire(&(netreq->result), result);
|
||||
if (r != LDNS_STATUS_OK) {
|
||||
handle_network_request_error(netreq, r);
|
||||
} else {
|
||||
/* is this the last request */
|
||||
if (!netreq->next) {
|
||||
/* finished */
|
||||
handle_dns_request_complete(netreq->owner);
|
||||
} else {
|
||||
/* not finished - update to next request and ship it */
|
||||
getdns_dns_req* dns_req = netreq->owner;
|
||||
dns_req->current_req = netreq->next;
|
||||
submit_network_request(netreq->next);
|
||||
}
|
||||
}
|
||||
}
|
||||
/* cleanup */
|
||||
getdns_ub_req_free(req);
|
||||
}
|
||||
|
||||
getdns_return_t
|
||||
getdns_general_ub(
|
||||
struct ub_ctx* unbound,
|
||||
getdns_general_ub(struct ub_ctx* unbound,
|
||||
getdns_context_t context,
|
||||
const char *name,
|
||||
uint16_t request_type,
|
||||
struct getdns_dict *extensions,
|
||||
void *userarg,
|
||||
getdns_transaction_t *transaction_id,
|
||||
getdns_callback_t callbackfn
|
||||
) {
|
||||
getdns_callback_t callbackfn) {
|
||||
|
||||
getdns_return_t gr;
|
||||
int r;
|
||||
int async_id = 0;
|
||||
|
||||
gr = getdns_context_prepare_for_resolution(context);
|
||||
if (gr != GETDNS_RETURN_GOOD) {
|
||||
return GETDNS_RETURN_BAD_CONTEXT;
|
||||
}
|
||||
|
||||
/* request state */
|
||||
getdns_ub_req* req = (getdns_ub_req*) malloc(sizeof(getdns_ub_req));
|
||||
req->unbound = unbound;
|
||||
req->context = context;
|
||||
req->name = strdup(name);
|
||||
req->userarg = userarg;
|
||||
req->callback = callbackfn;
|
||||
getdns_dns_req* req = dns_req_new(context,
|
||||
unbound,
|
||||
name,
|
||||
request_type,
|
||||
extensions);
|
||||
if (!req) {
|
||||
return GETDNS_RETURN_GENERIC_ERROR;
|
||||
}
|
||||
|
||||
getdns_context_prepare_for_resolution(context);
|
||||
req->user_pointer = userarg;
|
||||
req->user_callback = callbackfn;
|
||||
|
||||
/* TODO:
|
||||
setup root or stub
|
||||
handle immediate callback
|
||||
A + AAAA
|
||||
*/
|
||||
|
||||
r = ub_resolve_event(unbound, req->name, request_type,
|
||||
LDNS_RR_CLASS_IN, req, ub_resolve_callback,
|
||||
&async_id);
|
||||
|
||||
if (transaction_id) {
|
||||
*transaction_id = async_id;
|
||||
*transaction_id = req->trans_id;
|
||||
}
|
||||
req->transaction_id = async_id;
|
||||
|
||||
getdns_context_track_outbound_request(req);
|
||||
|
||||
/* issue the first network req */
|
||||
r = submit_network_request(req->first_req);
|
||||
|
||||
if (r != 0) {
|
||||
getdns_ub_req_free(req);
|
||||
/* clean up the request */
|
||||
getdns_context_clear_outbound_request(req);
|
||||
dns_req_free(req);
|
||||
return GETDNS_RETURN_GENERIC_ERROR;
|
||||
}
|
||||
return GETDNS_RETURN_GOOD;
|
||||
|
@ -166,16 +208,13 @@ getdns_general_ub(
|
|||
* getdns_general
|
||||
*/
|
||||
getdns_return_t
|
||||
getdns_general(
|
||||
getdns_context_t context,
|
||||
getdns_general(getdns_context_t context,
|
||||
const char *name,
|
||||
uint16_t request_type,
|
||||
struct getdns_dict *extensions,
|
||||
void *userarg,
|
||||
getdns_transaction_t *transaction_id,
|
||||
getdns_callback_t callback
|
||||
)
|
||||
{
|
||||
getdns_callback_t callback) {
|
||||
|
||||
if (!context || context->async_set == 0 ||
|
||||
callback == NULL) {
|
||||
|
@ -202,15 +241,12 @@ getdns_general(
|
|||
*
|
||||
*/
|
||||
getdns_return_t
|
||||
getdns_address(
|
||||
getdns_context_t context,
|
||||
getdns_address(getdns_context_t context,
|
||||
const char *name,
|
||||
struct getdns_dict *extensions,
|
||||
void *userarg,
|
||||
getdns_transaction_t *transaction_id,
|
||||
getdns_callback_t callback
|
||||
)
|
||||
{
|
||||
getdns_callback_t callback) {
|
||||
int cleanup_extensions = 0;
|
||||
if (!extensions) {
|
||||
extensions = getdns_dict_create();
|
||||
|
|
|
@ -39,36 +39,33 @@ void network_req_free(getdns_network_req* net_req) {
|
|||
if (!net_req) {
|
||||
return;
|
||||
}
|
||||
getdns_context_t context = net_req->context;
|
||||
if (net_req->pkt) {
|
||||
ldns_pkt_free(net_req->pkt);
|
||||
getdns_context_t context = net_req->owner->context;
|
||||
if (net_req->result) {
|
||||
ldns_pkt_free(net_req->result);
|
||||
}
|
||||
gd_free(net_req);
|
||||
}
|
||||
|
||||
getdns_network_req* network_req_new(getdns_context_t context,
|
||||
const char* name,
|
||||
getdns_network_req* network_req_new(getdns_dns_req* owner,
|
||||
uint16_t request_type,
|
||||
uint16_t request_class,
|
||||
struct getdns_dict* extensions) {
|
||||
getdns_network_req *net_req = NULL;
|
||||
ldns_pkt *pkt = NULL;
|
||||
net_req = gd_malloc(sizeof(getdns_network_req));
|
||||
|
||||
getdns_context_t context = owner->context;
|
||||
getdns_network_req* net_req = gd_malloc(sizeof(getdns_network_req));
|
||||
if (!net_req) {
|
||||
return NULL;
|
||||
}
|
||||
net_req->ns = NULL;
|
||||
net_req->pkt = NULL;
|
||||
net_req->context = context;
|
||||
net_req->request_type = request_type;
|
||||
net_req->result = NULL;
|
||||
net_req->next = NULL;
|
||||
|
||||
/* create ldns packet */
|
||||
pkt = create_new_pkt(context, name, request_type, extensions);
|
||||
if (!pkt) {
|
||||
/* free up the req */
|
||||
network_req_free(net_req);
|
||||
return NULL;
|
||||
}
|
||||
net_req->pkt = pkt;
|
||||
net_req->request_type = request_type;
|
||||
net_req->request_class = request_class;
|
||||
net_req->unbound_id = -1;
|
||||
net_req->state = NET_REQ_NOT_SENT;
|
||||
net_req->owner = owner;
|
||||
|
||||
/* TODO: records and other extensions */
|
||||
|
||||
return net_req;
|
||||
}
|
||||
|
@ -77,43 +74,86 @@ void dns_req_free(getdns_dns_req* req) {
|
|||
if (!req) {
|
||||
return;
|
||||
}
|
||||
getdns_network_req *net_req = NULL;
|
||||
getdns_context_t context = req->context;
|
||||
network_req_free(req->current_req);
|
||||
|
||||
/* free network requests */
|
||||
net_req = req->first_req;
|
||||
while (net_req) {
|
||||
getdns_network_req *next = net_req->next;
|
||||
network_req_free(net_req);
|
||||
net_req = next;
|
||||
}
|
||||
|
||||
/* free strduped name */
|
||||
free(req->name);
|
||||
|
||||
gd_free(req);
|
||||
}
|
||||
|
||||
/* create a new dns req to be submitted */
|
||||
getdns_dns_req* dns_req_new(getdns_context_t context,
|
||||
struct ub_ctx* unbound,
|
||||
const char* name,
|
||||
uint16_t request_type,
|
||||
struct getdns_dict *extensions,
|
||||
getdns_transaction_t *transaction_id) {
|
||||
struct getdns_dict *extensions) {
|
||||
|
||||
getdns_dns_req *result = NULL;
|
||||
getdns_network_req *net_req = NULL;
|
||||
getdns_network_req *req = NULL;
|
||||
getdns_return_t r;
|
||||
uint32_t both = GETDNS_EXTENSION_FALSE;
|
||||
|
||||
result = gd_malloc(sizeof(getdns_dns_req));
|
||||
if (result == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
result->name = strdup(name);
|
||||
result->context = context;
|
||||
result->unbound = unbound;
|
||||
result->current_req = NULL;
|
||||
result->pending_cb = 0;
|
||||
result->resolver_type = context->resolution_type;
|
||||
result->first_req = NULL;
|
||||
result->trans_id = ldns_get_random();
|
||||
|
||||
/* create the initial network request */
|
||||
net_req = network_req_new(context, name, request_type,
|
||||
getdns_dict_copy(extensions, &result->extensions);
|
||||
|
||||
/* will be set by caller */
|
||||
result->user_pointer = NULL;
|
||||
result->user_callback = NULL;
|
||||
|
||||
/* create the requests */
|
||||
req = network_req_new(result,
|
||||
request_type,
|
||||
LDNS_RR_CLASS_IN,
|
||||
extensions);
|
||||
if (!net_req) {
|
||||
if (!req) {
|
||||
dns_req_free(result);
|
||||
result = NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
result->trans_id = ldns_pkt_id(net_req->pkt);
|
||||
if (transaction_id) {
|
||||
*transaction_id = result->trans_id;
|
||||
}
|
||||
result->current_req = req;
|
||||
result->first_req = req;
|
||||
|
||||
result->current_req = net_req;
|
||||
net_req->owner = result;
|
||||
/* tack on A or AAAA if needed */
|
||||
r = getdns_dict_get_int(extensions,
|
||||
GETDNS_STR_EXTENSION_RETURN_BOTH_V4_AND_V6,
|
||||
&both);
|
||||
if (r == GETDNS_RETURN_GOOD &&
|
||||
both == GETDNS_EXTENSION_TRUE &&
|
||||
(request_type == GETDNS_RRTYPE_A || request_type == GETDNS_RRTYPE_AAAA)) {
|
||||
|
||||
uint16_t next_req_type = (request_type == GETDNS_RRTYPE_A) ? GETDNS_RRTYPE_AAAA : GETDNS_RRTYPE_A;
|
||||
getdns_network_req* next_req =
|
||||
network_req_new(result,
|
||||
next_req_type,
|
||||
LDNS_RR_CLASS_IN,
|
||||
extensions);
|
||||
if (!next_req) {
|
||||
dns_req_free(result);
|
||||
return NULL;
|
||||
}
|
||||
req->next = next_req;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -91,13 +91,13 @@ main()
|
|||
fprintf(stderr, "A bad domain name was used: %s. Exiting.", this_name);
|
||||
return(GETDNS_RETURN_GENERIC_ERROR);
|
||||
}
|
||||
dns_request_return = getdns_service(this_context, this_name, NULL, this_userarg, &this_transaction_id,
|
||||
this_callbackfn);
|
||||
if (dns_request_return == GETDNS_RETURN_BAD_DOMAIN_NAME)
|
||||
{
|
||||
fprintf(stderr, "A bad domain name was used: %s. Exiting.", this_name);
|
||||
return(GETDNS_RETURN_GENERIC_ERROR);
|
||||
}
|
||||
// dns_request_return = getdns_service(this_context, this_name, NULL, this_userarg, &this_transaction_id,
|
||||
// this_callbackfn);
|
||||
// if (dns_request_return == GETDNS_RETURN_BAD_DOMAIN_NAME)
|
||||
// {
|
||||
// fprintf(stderr, "A bad domain name was used: %s. Exiting.", this_name);
|
||||
// return(GETDNS_RETURN_GENERIC_ERROR);
|
||||
// }
|
||||
else
|
||||
{
|
||||
/* Call the event loop */
|
||||
|
|
|
@ -36,63 +36,61 @@
|
|||
|
||||
/* declarations */
|
||||
struct getdns_dns_req;
|
||||
struct getdns_nameserver;
|
||||
struct getdns_network_req;
|
||||
struct ub_ctx;
|
||||
|
||||
typedef struct getdns_nameserver {
|
||||
evutil_socket_t socket; /* a connected UDP socket */
|
||||
struct sockaddr_storage address;
|
||||
ev_socklen_t addrlen;
|
||||
typedef enum network_req_state_enum {
|
||||
NET_REQ_NOT_SENT,
|
||||
NET_REQ_IN_FLIGHT,
|
||||
NET_REQ_FINISHED
|
||||
} network_req_state;
|
||||
|
||||
int failed_times; /* number of times which we have given this server a chance */
|
||||
int timedout; /* number of times in a row a request has timed out */
|
||||
|
||||
struct event* event;
|
||||
|
||||
/* when we next probe this server. */
|
||||
/* Valid if state == 0 */
|
||||
/* Outstanding probe request for this nameserver, if any */
|
||||
struct getdns_dns_req *probe_request;
|
||||
char state; /* zero if we think that this server is down */
|
||||
char choked; /* true if we have an EAGAIN from this server's socket */
|
||||
char write_waiting; /* true if we are waiting for EV_WRITE events */
|
||||
|
||||
/* getdns context */
|
||||
getdns_context_t context;
|
||||
|
||||
/* Number of currently inflight requests: used
|
||||
* to track when we should add/del the event. */
|
||||
int requests_inflight;
|
||||
} getdns_nameserver;
|
||||
|
||||
/* network request - state for a single network request and referenced
|
||||
* by the the outbound_req
|
||||
*/
|
||||
/**
|
||||
* Request data for unbound
|
||||
**/
|
||||
typedef struct getdns_network_req {
|
||||
ldns_pkt *pkt; /* the dns packet data */
|
||||
uint16_t request_type; /* query type */
|
||||
|
||||
int reissue_count;
|
||||
int tx_count; /* the number of times that this packet has been sent */
|
||||
|
||||
/* not owned */
|
||||
getdns_nameserver *ns; /* the server which we sent to */
|
||||
|
||||
unsigned transmit_me :1; /* needs to be transmitted */
|
||||
|
||||
getdns_context_t context;
|
||||
|
||||
/* the async_id from unbound */
|
||||
int unbound_id;
|
||||
/* state var */
|
||||
network_req_state state;
|
||||
/* owner request (contains name) */
|
||||
struct getdns_dns_req* owner;
|
||||
|
||||
/* request type */
|
||||
uint16_t request_type;
|
||||
|
||||
/* request class */
|
||||
uint16_t request_class;
|
||||
|
||||
/* result */
|
||||
ldns_pkt* result;
|
||||
|
||||
/* next request to issue after this one */
|
||||
struct getdns_network_req* next;
|
||||
} getdns_network_req;
|
||||
|
||||
/* outbound request - manages recursion and stub reqs */
|
||||
/* dns request - manages a number of network requests and
|
||||
* the initial data passed to getdns_general
|
||||
*/
|
||||
typedef struct getdns_dns_req {
|
||||
|
||||
/* name */
|
||||
char *name;
|
||||
|
||||
/* current network request */
|
||||
struct getdns_network_req *current_req;
|
||||
|
||||
/* first request in list */
|
||||
struct getdns_network_req *first_req;
|
||||
|
||||
/* context that owns the request */
|
||||
getdns_context_t context;
|
||||
|
||||
uint16_t resolver_type;
|
||||
/* ub_ctx issuing the request */
|
||||
struct ub_ctx* unbound;
|
||||
|
||||
/* request extensions */
|
||||
getdns_dict *extensions;
|
||||
|
||||
/* callback data */
|
||||
getdns_callback_t user_callback;
|
||||
|
@ -100,12 +98,6 @@ typedef struct getdns_dns_req {
|
|||
|
||||
getdns_transaction_t trans_id; /* the transaction id */
|
||||
|
||||
|
||||
int pending_cb; /* Waiting for its callback to be invoked; not
|
||||
* owned by event base any more. */
|
||||
|
||||
/* search not supported.. yet */
|
||||
|
||||
} getdns_dns_req;
|
||||
|
||||
/* utility methods */
|
||||
|
@ -113,29 +105,23 @@ typedef struct getdns_dns_req {
|
|||
/* network request utilities */
|
||||
void network_req_free(getdns_network_req* net_req);
|
||||
|
||||
getdns_network_req* network_req_new(getdns_context_t context,
|
||||
const char* name,
|
||||
getdns_network_req* network_req_new(getdns_dns_req* owner,
|
||||
uint16_t request_type,
|
||||
uint16_t request_class,
|
||||
struct getdns_dict* extensions);
|
||||
|
||||
|
||||
/* dns request utils */
|
||||
getdns_dns_req* dns_req_new(getdns_context_t context,
|
||||
struct ub_ctx* unbound,
|
||||
const char* name,
|
||||
uint16_t request_type,
|
||||
struct getdns_dict *extensions,
|
||||
getdns_transaction_t *transaction_id);
|
||||
struct getdns_dict *extensions);
|
||||
|
||||
|
||||
void dns_req_free(getdns_dns_req* req);
|
||||
|
||||
/* nameserver utils */
|
||||
getdns_nameserver* nameserver_new_from_ip_dict(getdns_context_t context,
|
||||
getdns_dict* ip_dict);
|
||||
|
||||
void nameserver_free(getdns_nameserver* nameserver);
|
||||
|
||||
getdns_dict* nameserver_to_dict(getdns_nameserver* nameserver);
|
||||
|
||||
/* cancel the request */
|
||||
getdns_return_t dns_req_cancel(getdns_dns_req* req);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
*/
|
||||
|
||||
#include "util-internal.h"
|
||||
#include "types-internal.h"
|
||||
|
||||
getdns_return_t getdns_dict_util_set_string(getdns_dict* dict, char* name,
|
||||
const char* value) {
|
||||
|
@ -113,28 +114,8 @@ getdns_return_t sockaddr_to_dict(struct sockaddr_storage* address, getdns_dict**
|
|||
return GETDNS_RETURN_GOOD;
|
||||
}
|
||||
|
||||
/* TODO: flags */
|
||||
ldns_pkt *create_new_pkt(getdns_context_t context,
|
||||
const char* name,
|
||||
uint16_t request_type,
|
||||
struct getdns_dict* extensions) {
|
||||
ldns_pkt *pkt = NULL;
|
||||
ldns_rr_type type = (ldns_rr_type) request_type;
|
||||
uint16_t flags = 0;
|
||||
if (context->resolution_type == GETDNS_CONTEXT_STUB) {
|
||||
flags |= LDNS_RD;
|
||||
}
|
||||
ldns_pkt_query_new_frm_str(&pkt, name,
|
||||
type,
|
||||
LDNS_RR_CLASS_IN, flags);
|
||||
if (pkt) {
|
||||
/* id */
|
||||
ldns_pkt_set_id(pkt, ldns_get_random());
|
||||
}
|
||||
return pkt;
|
||||
}
|
||||
|
||||
getdns_dict *create_getdns_response(ldns_pkt* pkt) {
|
||||
getdns_dict *create_getdns_response(struct getdns_dns_req* completed_request) {
|
||||
ldns_pkt* pkt = completed_request->first_req->result;
|
||||
char* data = ldns_pkt2str(pkt);
|
||||
getdns_dict* result = getdns_dict_create();
|
||||
getdns_bindata bindata = {
|
||||
|
|
|
@ -35,18 +35,13 @@
|
|||
#include <ldns/ldns.h>
|
||||
#include "context.h"
|
||||
|
||||
struct getdns_dns_req;
|
||||
|
||||
/* convert an ip address dict to a sock storage */
|
||||
getdns_return_t dict_to_sockaddr(getdns_dict* ns, struct sockaddr_storage* output);
|
||||
getdns_return_t sockaddr_to_dict(struct sockaddr_storage* sockaddr, getdns_dict** output);
|
||||
|
||||
/* create a dns packet for the given request type and extensions */
|
||||
ldns_pkt *create_new_pkt(getdns_context_t context,
|
||||
const char* name,
|
||||
uint16_t request_type,
|
||||
struct getdns_dict* extensions);
|
||||
|
||||
getdns_dict *create_getdns_response(ldns_pkt* pkt);
|
||||
getdns_dict *create_getdns_response(struct getdns_dns_req* completed_request);
|
||||
|
||||
/* dict util */
|
||||
/* set a string as bindata */
|
||||
|
|
Loading…
Reference in New Issue