mirror of https://github.com/getdnsapi/getdns.git
Prepare datastructs for tcp stub resolving
This commit is contained in:
parent
bd01b0b83e
commit
b62e2bb84c
|
@ -338,6 +338,26 @@ upstream_dict(getdns_context *context, struct getdns_upstream *upstream)
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
net_req_query_id_cmp(const void *id1, const void *id2)
|
||||||
|
{
|
||||||
|
return (int)((struct getdns_network_req *)id1)->query_id -
|
||||||
|
(int)((struct getdns_network_req *)id1)->query_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
upstream_init(struct getdns_upstream *upstream, struct addrinfo *ai)
|
||||||
|
{
|
||||||
|
assert(upstream && ai);
|
||||||
|
upstream->addr_len = ai->ai_addrlen;
|
||||||
|
(void) memcpy(&upstream->addr, ai->ai_addr, ai->ai_addrlen);
|
||||||
|
upstream->to_retry = 2;
|
||||||
|
upstream->tcp_fd = -1;
|
||||||
|
(void) memset(&upstream->tcp_event, 0, sizeof(upstream->tcp_event));
|
||||||
|
getdns_rbtree_init(&upstream->netreq_by_query_id,
|
||||||
|
net_req_query_id_cmp);
|
||||||
|
}
|
||||||
|
|
||||||
/*---------------------------------------- set_os_defaults
|
/*---------------------------------------- set_os_defaults
|
||||||
we use ldns to read the resolv.conf file - the ldns resolver is
|
we use ldns to read the resolv.conf file - the ldns resolver is
|
||||||
destroyed once the file is read
|
destroyed once the file is read
|
||||||
|
@ -440,11 +460,7 @@ set_os_defaults(struct getdns_context *context)
|
||||||
|
|
||||||
upstream = &context->upstreams->
|
upstream = &context->upstreams->
|
||||||
upstreams[context->upstreams->count++];
|
upstreams[context->upstreams->count++];
|
||||||
upstream->rtt = 1;
|
upstream_init(upstream, result);
|
||||||
upstream->tcp_fd = -1;
|
|
||||||
upstream->addr_len = result->ai_addrlen;
|
|
||||||
(void) memcpy(&upstream->addr,
|
|
||||||
result->ai_addr, result->ai_addrlen);
|
|
||||||
freeaddrinfo(result);
|
freeaddrinfo(result);
|
||||||
}
|
}
|
||||||
fclose(in);
|
fclose(in);
|
||||||
|
@ -1305,10 +1321,7 @@ getdns_context_set_upstream_recursive_servers(struct getdns_context *context,
|
||||||
if (getaddrinfo(addrstr, portstr, &hints, &ai))
|
if (getaddrinfo(addrstr, portstr, &hints, &ai))
|
||||||
goto invalid_parameter;
|
goto invalid_parameter;
|
||||||
|
|
||||||
upstream->rtt = 1;
|
upstream_init(upstream, ai);
|
||||||
upstream->tcp_fd = -1;
|
|
||||||
upstream->addr_len = ai->ai_addrlen;
|
|
||||||
(void) memcpy(&upstream->addr, ai->ai_addr, ai->ai_addrlen);
|
|
||||||
upstreams->count++;
|
upstreams->count++;
|
||||||
freeaddrinfo(ai);
|
freeaddrinfo(ai);
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,7 @@
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "types-internal.h"
|
#include "types-internal.h"
|
||||||
#include "extension/libmini_event.h"
|
#include "extension/libmini_event.h"
|
||||||
|
#include "util/rbtree.h"
|
||||||
|
|
||||||
struct getdns_dns_req;
|
struct getdns_dns_req;
|
||||||
struct ldns_rbtree_t;
|
struct ldns_rbtree_t;
|
||||||
|
@ -71,8 +72,10 @@ struct filechg {
|
||||||
struct getdns_upstream {
|
struct getdns_upstream {
|
||||||
socklen_t addr_len;
|
socklen_t addr_len;
|
||||||
struct sockaddr_storage addr;
|
struct sockaddr_storage addr;
|
||||||
int tcp_fd;
|
int to_retry;
|
||||||
int rtt;
|
int tcp_fd;
|
||||||
|
getdns_eventloop_event tcp_event;
|
||||||
|
getdns_rbtree_t netreq_by_query_id;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct getdns_upstreams {
|
typedef struct getdns_upstreams {
|
||||||
|
|
|
@ -40,6 +40,8 @@
|
||||||
#include <ldns/ldns.h>
|
#include <ldns/ldns.h>
|
||||||
#include "getdns/getdns.h"
|
#include "getdns/getdns.h"
|
||||||
#include "getdns/getdns_extra.h"
|
#include "getdns/getdns_extra.h"
|
||||||
|
#include "util/rbtree.h"
|
||||||
|
|
||||||
struct getdns_context;
|
struct getdns_context;
|
||||||
struct getdns_upstreams;
|
struct getdns_upstreams;
|
||||||
struct getdns_upstream;
|
struct getdns_upstream;
|
||||||
|
@ -153,6 +155,8 @@ typedef struct getdns_extension_format
|
||||||
**/
|
**/
|
||||||
typedef struct getdns_network_req
|
typedef struct getdns_network_req
|
||||||
{
|
{
|
||||||
|
/* For storage in upstream->netreq_by_query_id */
|
||||||
|
getdns_rbnode_t node;
|
||||||
/* the async_id from unbound */
|
/* the async_id from unbound */
|
||||||
int unbound_id;
|
int unbound_id;
|
||||||
/* state var */
|
/* state var */
|
||||||
|
|
Loading…
Reference in New Issue