mirror of https://github.com/getdnsapi/getdns.git
Organise code in stub.c and add some utility methods.
This commit is contained in:
parent
d6d83b219d
commit
01adce8299
|
@ -703,6 +703,7 @@ set_os_defaults(struct getdns_context *context)
|
|||
|
||||
upstream = &context->upstreams->
|
||||
upstreams[context->upstreams->count++];
|
||||
fprintf(stderr, "[TLS]: OS: creating upstream %d, %p, with port %s with transport %d\n", (int)context->upstreams->count, (void*)upstream, port_str, base_transport);
|
||||
upstream_init(upstream, context->upstreams, result);
|
||||
upstream->dns_base_transport = base_transport;
|
||||
}
|
||||
|
@ -1487,6 +1488,7 @@ getdns_context_set_upstream_recursive_servers(struct getdns_context *context,
|
|||
getdns_return_t r;
|
||||
size_t count = 0;
|
||||
size_t i;
|
||||
//size_t upstreams_limit;
|
||||
getdns_upstreams *upstreams;
|
||||
char addrstr[1024], portstr[1024], *eos;
|
||||
struct addrinfo hints;
|
||||
|
@ -1507,25 +1509,17 @@ getdns_context_set_upstream_recursive_servers(struct getdns_context *context,
|
|||
hints.ai_addr = NULL;
|
||||
hints.ai_next = NULL;
|
||||
|
||||
/* TODO[TLS]: Resize on the fly to avoid hardcoding this*/
|
||||
upstreams = upstreams_create(context, count*3);
|
||||
//upstreams_limit = count;
|
||||
for (i = 0; i < count; i++) {
|
||||
/* Loop to create upstreams as needed*/
|
||||
getdns_base_transport_t base_transport = GETDNS_BASE_TRANSPORT_MIN;
|
||||
for (; base_transport < GETDNS_BASE_TRANSPORT_MAX; base_transport++) {
|
||||
getdns_dict *dict;
|
||||
getdns_bindata *address_type;
|
||||
getdns_bindata *address_data;
|
||||
uint32_t port;
|
||||
struct sockaddr_storage addr;
|
||||
|
||||
getdns_bindata *scope_id;
|
||||
struct addrinfo *ai;
|
||||
getdns_upstream *upstream;
|
||||
|
||||
port = getdns_port_array[base_transport];
|
||||
if (port == GETDNS_PORT_ZERO)
|
||||
continue;
|
||||
|
||||
upstream = &upstreams->upstreams[upstreams->count];
|
||||
if ((r = getdns_list_get_dict(upstream_list, i, &dict)))
|
||||
goto error;
|
||||
|
||||
|
@ -1535,26 +1529,23 @@ getdns_context_set_upstream_recursive_servers(struct getdns_context *context,
|
|||
if (address_type->size < 4)
|
||||
goto invalid_parameter;
|
||||
if (strncmp((char *)address_type->data, "IPv4", 4) == 0)
|
||||
upstream->addr.ss_family = AF_INET;
|
||||
addr.ss_family = AF_INET;
|
||||
else if (strncmp((char *)address_type->data, "IPv6", 4) == 0)
|
||||
upstream->addr.ss_family = AF_INET6;
|
||||
addr.ss_family = AF_INET6;
|
||||
else goto invalid_parameter;
|
||||
|
||||
if ((r = getdns_dict_get_bindata(
|
||||
dict, "address_data", &address_data)))
|
||||
goto error;
|
||||
if ((upstream->addr.ss_family == AF_INET &&
|
||||
if ((addr.ss_family == AF_INET &&
|
||||
address_data->size != 4) ||
|
||||
(upstream->addr.ss_family == AF_INET6 &&
|
||||
(addr.ss_family == AF_INET6 &&
|
||||
address_data->size != 16))
|
||||
goto invalid_parameter;
|
||||
if (inet_ntop(upstream->addr.ss_family, address_data->data,
|
||||
if (inet_ntop(addr.ss_family, address_data->data,
|
||||
addrstr, 1024) == NULL)
|
||||
goto invalid_parameter;
|
||||
|
||||
(void) getdns_dict_get_int(dict, "port", &port);
|
||||
(void) snprintf(portstr, 1024, "%d", (int)port);
|
||||
|
||||
if (getdns_dict_get_bindata(dict, "scope_id", &scope_id) ==
|
||||
GETDNS_RETURN_GOOD) {
|
||||
if (strlen(addrstr) + scope_id->size > 1022)
|
||||
|
@ -1565,12 +1556,37 @@ getdns_context_set_upstream_recursive_servers(struct getdns_context *context,
|
|||
eos[scope_id->size] = 0;
|
||||
}
|
||||
|
||||
/* Loop to create upstreams as needed*/
|
||||
getdns_base_transport_t base_transport = GETDNS_BASE_TRANSPORT_MIN;
|
||||
for (; base_transport < GETDNS_BASE_TRANSPORT_MAX; base_transport++) {
|
||||
uint32_t port;
|
||||
struct addrinfo *ai;
|
||||
port = getdns_port_array[base_transport];
|
||||
if (port == GETDNS_PORT_ZERO)
|
||||
continue;
|
||||
|
||||
/* TODO[TLS]:Respect the user port for TCP and STARTTLS, but for
|
||||
* now hardcode the TLS port */
|
||||
if (base_transport != GETDNS_BASE_TRANSPORT_TLS)
|
||||
(void) getdns_dict_get_int(dict, "port", &port);
|
||||
(void) snprintf(portstr, 1024, "%d", (int)port);
|
||||
|
||||
if (getaddrinfo(addrstr, portstr, &hints, &ai))
|
||||
goto invalid_parameter;
|
||||
|
||||
/* TODO[TLS]: Should probably check that the upstream doesn't
|
||||
* already exist (in case user has specified port explicitly)*/
|
||||
* already exist (in case user has specified TLS port explicitly and
|
||||
* to prevent duplicates) */
|
||||
|
||||
/* TODO[TLS]: Grow array when needed. This causes a crash later....
|
||||
if (upstreams->count == upstreams_limit)
|
||||
upstreams = upstreams_resize(
|
||||
upstreams, (upstreams_limit *= 2)); */
|
||||
|
||||
upstream = &upstreams->upstreams[upstreams->count];
|
||||
upstream->addr.ss_family = addr.ss_family;
|
||||
upstream_init(upstream, upstreams, ai);
|
||||
fprintf(stderr, "[TLS]: creating upstream %d, %p, with port %d with transport %d\n", (int)upstreams->count, (void*)upstream,(int)port, base_transport);
|
||||
upstream->dns_base_transport = base_transport;
|
||||
upstreams->count++;
|
||||
freeaddrinfo(ai);
|
||||
|
@ -1912,8 +1928,8 @@ getdns_context_prepare_for_resolution(struct getdns_context *context,
|
|||
}
|
||||
/* Block use of TLS ONLY in recursive mode as it won't work */
|
||||
/* TODO[TLS]: Check if TLS is the only option in the list*/
|
||||
if (context->resolution_type == GETDNS_RESOLUTION_RECURSING
|
||||
&& context->dns_transport == GETDNS_TRANSPORT_TLS_ONLY_KEEP_CONNECTIONS_OPEN)
|
||||
if (context->resolution_type == GETDNS_RESOLUTION_RECURSING &&
|
||||
context->dns_transport == GETDNS_TRANSPORT_TLS_ONLY_KEEP_CONNECTIONS_OPEN)
|
||||
return GETDNS_RETURN_BAD_CONTEXT;
|
||||
|
||||
if (context->resolution_type_set == context->resolution_type)
|
||||
|
|
|
@ -91,7 +91,7 @@ network_req_init(getdns_network_req *net_req, getdns_dns_req *owner,
|
|||
net_req->fd = -1;
|
||||
for (i = 0; i < GETDNS_BASE_TRANSPORT_MAX; i++)
|
||||
net_req->dns_base_transports[i] = owner->context->dns_base_transports[i];
|
||||
net_req->dns_base_transport = net_req->dns_base_transports;
|
||||
net_req->transport = 0;
|
||||
memset(&net_req->event, 0, sizeof(net_req->event));
|
||||
memset(&net_req->tcp, 0, sizeof(net_req->tcp));
|
||||
net_req->query_id = 0;
|
||||
|
|
1251
src/stub.c
1251
src/stub.c
File diff suppressed because it is too large
Load Diff
|
@ -169,7 +169,7 @@ typedef enum getdns_base_transport {
|
|||
GETDNS_BASE_TRANSPORT_NONE = 0,
|
||||
GETDNS_BASE_TRANSPORT_UDP,
|
||||
GETDNS_BASE_TRANSPORT_TCP_SINGLE, /* To be removed? */
|
||||
GETDNS_BASE_TRANSPORT_STARTTLS, /* Define before TCP to allow fallback when scheduling*/
|
||||
GETDNS_BASE_TRANSPORT_STARTTLS, /* Define before TCP to allow fallback */
|
||||
GETDNS_BASE_TRANSPORT_TCP,
|
||||
GETDNS_BASE_TRANSPORT_TLS,
|
||||
GETDNS_BASE_TRANSPORT_MAX
|
||||
|
@ -203,7 +203,7 @@ typedef struct getdns_network_req
|
|||
struct getdns_upstream *upstream;
|
||||
int fd;
|
||||
getdns_base_transport_t dns_base_transports[GETDNS_BASE_TRANSPORT_MAX];
|
||||
getdns_base_transport_t *dns_base_transport;
|
||||
int transport;
|
||||
getdns_eventloop_event event;
|
||||
getdns_tcp_state tcp;
|
||||
uint16_t query_id;
|
||||
|
|
Loading…
Reference in New Issue