mirror of https://github.com/getdnsapi/getdns.git
Allow for name only upstream specification
This commit is contained in:
parent
8821c1c8cf
commit
b86f149523
|
@ -245,14 +245,6 @@ add_WIN_cacerts_to_openssl_store(SSL_CTX* tls_ctx)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static uint8_t*
|
|
||||||
upstream_addr(getdns_upstream *upstream)
|
|
||||||
{
|
|
||||||
return upstream->addr.ss_family == AF_INET
|
|
||||||
? (void *)&((struct sockaddr_in*)&upstream->addr)->sin_addr
|
|
||||||
: (void *)&((struct sockaddr_in6*)&upstream->addr)->sin6_addr;
|
|
||||||
}
|
|
||||||
|
|
||||||
static in_port_t
|
static in_port_t
|
||||||
upstream_port(getdns_upstream *upstream)
|
upstream_port(getdns_upstream *upstream)
|
||||||
{
|
{
|
||||||
|
@ -966,10 +958,11 @@ upstream_init(getdns_upstream *upstream,
|
||||||
{
|
{
|
||||||
upstream->upstreams = parent;
|
upstream->upstreams = parent;
|
||||||
|
|
||||||
upstream->addr_len = ai->ai_addrlen;
|
if (ai) {
|
||||||
(void) memcpy(&upstream->addr, ai->ai_addr, ai->ai_addrlen);
|
upstream->addr_len = ai->ai_addrlen;
|
||||||
inet_ntop(upstream->addr.ss_family, upstream_addr(upstream),
|
(void) memcpy(&upstream->addr, ai->ai_addr, ai->ai_addrlen);
|
||||||
upstream->addr_str, INET6_ADDRSTRLEN);
|
} else
|
||||||
|
upstream->addr_len = 0;
|
||||||
|
|
||||||
/* How is this upstream doing on connections? */
|
/* How is this upstream doing on connections? */
|
||||||
upstream->conn_completed = 0;
|
upstream->conn_completed = 0;
|
||||||
|
@ -2763,8 +2756,8 @@ getdns_context_set_dnssec_allowed_skew(struct getdns_context *context,
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
getdns_return_t
|
getdns_return_t
|
||||||
getdns_context_set_upstream_recursive_servers(struct getdns_context *context,
|
getdns_context_set_upstream_recursive_servers(getdns_context *context,
|
||||||
struct getdns_list *upstream_list)
|
getdns_list *upstream_list)
|
||||||
{
|
{
|
||||||
getdns_return_t r;
|
getdns_return_t r;
|
||||||
size_t count = 0;
|
size_t count = 0;
|
||||||
|
@ -2798,6 +2791,7 @@ getdns_context_set_upstream_recursive_servers(struct getdns_context *context,
|
||||||
getdns_dict *dict;
|
getdns_dict *dict;
|
||||||
getdns_bindata *address_type;
|
getdns_bindata *address_type;
|
||||||
getdns_bindata *address_data;
|
getdns_bindata *address_data;
|
||||||
|
getdns_bindata *name = NULL;
|
||||||
getdns_bindata *tls_auth_name;
|
getdns_bindata *tls_auth_name;
|
||||||
struct sockaddr_storage addr;
|
struct sockaddr_storage addr;
|
||||||
|
|
||||||
|
@ -2829,10 +2823,11 @@ getdns_context_set_upstream_recursive_servers(struct getdns_context *context,
|
||||||
dict, "address_type",&address_type))) {
|
dict, "address_type",&address_type))) {
|
||||||
/* Just address_data is also okay */
|
/* Just address_data is also okay */
|
||||||
if ((r = getdns_dict_get_bindata(
|
if ((r = getdns_dict_get_bindata(
|
||||||
dict, "address_data", &address_data)))
|
dict, "address_data", &address_data))) {
|
||||||
goto error;
|
if ((r = getdns_dict_get_bindata(
|
||||||
|
dict, "name", &name)))
|
||||||
if (address_data->size == 4)
|
goto error;
|
||||||
|
} else if (address_data->size == 4)
|
||||||
addr.ss_family = AF_INET;
|
addr.ss_family = AF_INET;
|
||||||
else if (address_data->size == 16)
|
else if (address_data->size == 16)
|
||||||
addr.ss_family = AF_INET6;
|
addr.ss_family = AF_INET6;
|
||||||
|
@ -2856,7 +2851,13 @@ getdns_context_set_upstream_recursive_servers(struct getdns_context *context,
|
||||||
address_data->size != 16))
|
address_data->size != 16))
|
||||||
goto invalid_parameter;
|
goto invalid_parameter;
|
||||||
}
|
}
|
||||||
if (inet_ntop(addr.ss_family, address_data->data,
|
if (name) {
|
||||||
|
if (name->size >= sizeof(addrstr))
|
||||||
|
goto invalid_parameter;
|
||||||
|
(void) memcpy(addrstr, name->data, name->size);
|
||||||
|
addrstr[name->size] = 0;
|
||||||
|
|
||||||
|
} else if (inet_ntop(addr.ss_family, address_data->data,
|
||||||
addrstr, 1024) == NULL)
|
addrstr, 1024) == NULL)
|
||||||
goto invalid_parameter;
|
goto invalid_parameter;
|
||||||
|
|
||||||
|
@ -2949,10 +2950,13 @@ getdns_context_set_upstream_recursive_servers(struct getdns_context *context,
|
||||||
}
|
}
|
||||||
(void) snprintf(portstr, 1024, "%d", (int)port);
|
(void) snprintf(portstr, 1024, "%d", (int)port);
|
||||||
|
|
||||||
if (getaddrinfo(addrstr, portstr, &hints, &ai))
|
if (!name) {
|
||||||
goto invalid_parameter;
|
if (getaddrinfo(addrstr, portstr, &hints, &ai))
|
||||||
if (!ai)
|
goto invalid_parameter;
|
||||||
continue;
|
if (!ai)
|
||||||
|
continue;
|
||||||
|
} else
|
||||||
|
ai = NULL;
|
||||||
|
|
||||||
/* TODO[TLS]: Should probably check that the upstream doesn't
|
/* TODO[TLS]: Should probably check that the upstream doesn't
|
||||||
* already exist (in case user has specified TLS port explicitly and
|
* already exist (in case user has specified TLS port explicitly and
|
||||||
|
@ -2960,6 +2964,8 @@ getdns_context_set_upstream_recursive_servers(struct getdns_context *context,
|
||||||
|
|
||||||
upstream = &upstreams->upstreams[upstreams->count];
|
upstream = &upstreams->upstreams[upstreams->count];
|
||||||
upstream->addr.ss_family = addr.ss_family;
|
upstream->addr.ss_family = addr.ss_family;
|
||||||
|
(void)strncpy(upstream->addr_str, addrstr
|
||||||
|
, sizeof(upstream->addr_str));
|
||||||
upstream_init(upstream, upstreams, ai);
|
upstream_init(upstream, upstreams, ai);
|
||||||
upstream->transport = getdns_upstream_transports[j];
|
upstream->transport = getdns_upstream_transports[j];
|
||||||
if (getdns_upstream_transports[j] == GETDNS_TRANSPORT_TLS) {
|
if (getdns_upstream_transports[j] == GETDNS_TRANSPORT_TLS) {
|
||||||
|
@ -3012,7 +3018,8 @@ getdns_context_set_upstream_recursive_servers(struct getdns_context *context,
|
||||||
upstream->tsig_size = 0;
|
upstream->tsig_size = 0;
|
||||||
}
|
}
|
||||||
upstreams->count++;
|
upstreams->count++;
|
||||||
freeaddrinfo(ai);
|
if (ai)
|
||||||
|
freeaddrinfo(ai);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_getdns_upstreams_dereference(context->upstreams);
|
_getdns_upstreams_dereference(context->upstreams);
|
||||||
|
@ -3351,6 +3358,14 @@ cancel_outstanding_requests(getdns_context* context)
|
||||||
|
|
||||||
#ifndef STUB_NATIVE_DNSSEC
|
#ifndef STUB_NATIVE_DNSSEC
|
||||||
|
|
||||||
|
static uint8_t*
|
||||||
|
upstream_addr(getdns_upstream *upstream)
|
||||||
|
{
|
||||||
|
return upstream->addr.ss_family == AF_INET
|
||||||
|
? (void *)&((struct sockaddr_in*)&upstream->addr)->sin_addr
|
||||||
|
: (void *)&((struct sockaddr_in6*)&upstream->addr)->sin6_addr;
|
||||||
|
}
|
||||||
|
|
||||||
static uint32_t *
|
static uint32_t *
|
||||||
upstream_scope_id(getdns_upstream *upstream)
|
upstream_scope_id(getdns_upstream *upstream)
|
||||||
{
|
{
|
||||||
|
|
|
@ -140,7 +140,7 @@ typedef struct getdns_upstream {
|
||||||
|
|
||||||
socklen_t addr_len;
|
socklen_t addr_len;
|
||||||
struct sockaddr_storage addr;
|
struct sockaddr_storage addr;
|
||||||
char addr_str[INET6_ADDRSTRLEN];
|
char addr_str[1024];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* How is this upstream doing over UDP?
|
* How is this upstream doing over UDP?
|
||||||
|
|
|
@ -1083,6 +1083,7 @@ _getdns_ipaddr_dict_mf(struct mem_funcs *mf, const char *ipstr)
|
||||||
uint8_t buf[sizeof(struct in6_addr)];
|
uint8_t buf[sizeof(struct in6_addr)];
|
||||||
getdns_bindata addr;
|
getdns_bindata addr;
|
||||||
|
|
||||||
|
addr.size = 0;
|
||||||
addr.data = buf;
|
addr.data = buf;
|
||||||
|
|
||||||
if (!r) return NULL;
|
if (!r) return NULL;
|
||||||
|
@ -1147,14 +1148,16 @@ _getdns_ipaddr_dict_mf(struct mem_funcs *mf, const char *ipstr)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
getdns_dict_util_set_string(r, "address_type", "IPv4");
|
if (inet_pton(AF_INET, ipstr, buf) <= 0)
|
||||||
addr.size = 4;
|
getdns_dict_util_set_string(r, "name", ipstr);
|
||||||
if (inet_pton(AF_INET, ipstr, buf) <= 0) {
|
|
||||||
getdns_dict_destroy(r);
|
else {
|
||||||
return NULL;
|
addr.size = 4;
|
||||||
|
getdns_dict_util_set_string(r, "address_type", "IPv4");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
getdns_dict_set_bindata(r, "address_data", &addr);
|
if (addr.size)
|
||||||
|
getdns_dict_set_bindata(r, "address_data", &addr);
|
||||||
if (*portstr)
|
if (*portstr)
|
||||||
getdns_dict_set_int(r, "port", (int32_t)atoi(portstr));
|
getdns_dict_set_int(r, "port", (int32_t)atoi(portstr));
|
||||||
if (*tls_portstr)
|
if (*tls_portstr)
|
||||||
|
|
|
@ -604,7 +604,9 @@ getdns_return_t parse_args(int argc, char **argv)
|
||||||
|
|
||||||
for (i = 1; i < argc; i++) {
|
for (i = 1; i < argc; i++) {
|
||||||
arg = argv[i];
|
arg = argv[i];
|
||||||
if ((t = get_rrtype(arg)) >= 0) {
|
if (( (*arg >= 'a' && *arg <= 'z')
|
||||||
|
|| (*arg >= 'A' && *arg <= 'Z'))
|
||||||
|
&& (t = get_rrtype(arg)) >= 0) {
|
||||||
request_type = t;
|
request_type = t;
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -650,7 +652,9 @@ getdns_return_t parse_args(int argc, char **argv)
|
||||||
getdns_get_errorstr_by_id(r));
|
getdns_get_errorstr_by_id(r));
|
||||||
|
|
||||||
else if ((r = getdns_dict_get_bindata(
|
else if ((r = getdns_dict_get_bindata(
|
||||||
upstream, "address_data", &address))) {
|
upstream, "address_data", &address)) &&
|
||||||
|
(r = getdns_dict_get_bindata(
|
||||||
|
upstream, "name", &address))) {
|
||||||
|
|
||||||
fprintf(stderr, "\"%s\" did not translate to "
|
fprintf(stderr, "\"%s\" did not translate to "
|
||||||
"an IP dict: %s\n", arg + 1,
|
"an IP dict: %s\n", arg + 1,
|
||||||
|
|
Loading…
Reference in New Issue