mirror of https://github.com/getdnsapi/getdns.git
Miscelaneous cleanups
as a consequence of ldns elemination with local-hosts
This commit is contained in:
parent
4b7ae8d0bc
commit
c02f895358
|
@ -219,11 +219,12 @@ add_local_host(getdns_context *context, getdns_dict *address, const char *str)
|
|||
}
|
||||
|
||||
static getdns_dict *
|
||||
sockaddr2addr_dict(getdns_context *context, struct sockaddr *sa)
|
||||
sockaddr_dict(getdns_context *context, struct sockaddr *sa)
|
||||
{
|
||||
getdns_dict *address = getdns_dict_create_with_context(context);
|
||||
char addrstr[1024], *b;
|
||||
getdns_bindata bindata;
|
||||
uint16_t port;
|
||||
|
||||
if (!address)
|
||||
return NULL;
|
||||
|
@ -238,10 +239,9 @@ sockaddr2addr_dict(getdns_context *context, struct sockaddr *sa)
|
|||
if ((getdns_dict_set_bindata(address,"address_data",&bindata)))
|
||||
break;
|
||||
|
||||
if (((struct sockaddr_in *)sa)->sin_port != 0 &&
|
||||
((struct sockaddr_in *)sa)->sin_port != 53 &&
|
||||
getdns_dict_set_int(address, "port",
|
||||
(uint32_t)((struct sockaddr_in *)sa)->sin_port))
|
||||
port = ntohs(((struct sockaddr_in *)sa)->sin_port);
|
||||
if (port != 0 && port != 53 &&
|
||||
getdns_dict_set_int(address, "port", (uint32_t)port))
|
||||
break;
|
||||
|
||||
return address;
|
||||
|
@ -255,10 +255,9 @@ sockaddr2addr_dict(getdns_context *context, struct sockaddr *sa)
|
|||
if ((getdns_dict_set_bindata(address,"address_data",&bindata)))
|
||||
break;
|
||||
|
||||
if (((struct sockaddr_in6 *)sa)->sin6_port != 0 &&
|
||||
((struct sockaddr_in6 *)sa)->sin6_port != 53 &&
|
||||
getdns_dict_set_int(address, "port",
|
||||
(uint32_t)((struct sockaddr_in *)sa)->sin_port))
|
||||
port = ntohs(((struct sockaddr_in6 *)sa)->sin6_port);
|
||||
if (port != 0 && port != 53 &&
|
||||
getdns_dict_set_int(address, "port", (uint32_t)port))
|
||||
break;
|
||||
|
||||
/* Try to get scope_id too */
|
||||
|
@ -279,7 +278,7 @@ sockaddr2addr_dict(getdns_context *context, struct sockaddr *sa)
|
|||
}
|
||||
|
||||
static getdns_dict *
|
||||
str2addr_dict(getdns_context *context, const char *str)
|
||||
str_addr_dict(getdns_context *context, const char *str)
|
||||
{
|
||||
static struct addrinfo hints = { .ai_family = AF_UNSPEC
|
||||
, .ai_flags = AI_NUMERICHOST };
|
||||
|
@ -289,7 +288,7 @@ str2addr_dict(getdns_context *context, const char *str)
|
|||
if (getaddrinfo(str, NULL, &hints, &ai))
|
||||
return NULL;
|
||||
|
||||
address = sockaddr2addr_dict(context, ai->ai_addr);
|
||||
address = sockaddr_dict(context, ai->ai_addr);
|
||||
freeaddrinfo(ai);
|
||||
|
||||
return address;
|
||||
|
@ -353,7 +352,7 @@ create_local_hosts(getdns_context *context)
|
|||
if (address)
|
||||
getdns_dict_destroy(address);
|
||||
if (!(address =
|
||||
str2addr_dict(context, start_of_word)))
|
||||
str_addr_dict(context, start_of_word)))
|
||||
/* Unparseable address */
|
||||
break; /* skip to next line */
|
||||
} else
|
||||
|
@ -478,12 +477,6 @@ upstreams_dereference(getdns_upstreams *upstreams)
|
|||
GETDNS_FREE(upstreams->mf, upstreams);
|
||||
}
|
||||
|
||||
static size_t
|
||||
upstream_addr_len(getdns_upstream *upstream)
|
||||
{
|
||||
return upstream->addr.ss_family == AF_INET ? 4 : 16;
|
||||
}
|
||||
|
||||
static uint8_t*
|
||||
upstream_addr(getdns_upstream *upstream)
|
||||
{
|
||||
|
@ -527,31 +520,6 @@ upstream_ntop_buf(getdns_upstream *upstream, char *buf, size_t len)
|
|||
"@%d", (int)upstream_port(upstream));
|
||||
}
|
||||
|
||||
static getdns_dict *
|
||||
upstream_dict(getdns_context *context, getdns_upstream *upstream)
|
||||
{
|
||||
getdns_dict *r = getdns_dict_create_with_context(context);
|
||||
char addrstr[1024], *b;
|
||||
getdns_bindata bindata;
|
||||
|
||||
getdns_dict_util_set_string(r, "address_type",
|
||||
upstream->addr.ss_family == AF_INET ? "IPv4" : "IPv6");
|
||||
|
||||
bindata.size = upstream_addr_len(upstream);
|
||||
bindata.data = upstream_addr(upstream);
|
||||
getdns_dict_set_bindata(r, "address_data", &bindata);
|
||||
|
||||
if (upstream_port(upstream) != 53)
|
||||
getdns_dict_set_int(r, "port", upstream_port(upstream));
|
||||
|
||||
(void) getnameinfo((struct sockaddr *)&upstream->addr,
|
||||
upstream->addr_len, addrstr, 1024, NULL, 0, NI_NUMERICHOST);
|
||||
if ((b = strchr(addrstr, '%')))
|
||||
getdns_dict_util_set_string(r, "scope_id", b+1);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static int
|
||||
net_req_query_id_cmp(const void *id1, const void *id2)
|
||||
{
|
||||
|
@ -2036,7 +2004,8 @@ priv_get_context_settings(getdns_context* context) {
|
|||
for (i = 0; i < context->upstreams->count; i++) {
|
||||
getdns_dict *d;
|
||||
upstream = &context->upstreams->upstreams[i];
|
||||
d = upstream_dict(context, upstream);
|
||||
d = sockaddr_dict(context,
|
||||
(struct sockaddr *)&upstream->addr);
|
||||
r |= getdns_list_set_dict(upstreams, i, d);
|
||||
getdns_dict_destroy(d);
|
||||
}
|
||||
|
@ -2334,7 +2303,7 @@ getdns_context_get_upstream_recursive_servers(getdns_context *context,
|
|||
for (i = 0; i < context->upstreams->count; i++) {
|
||||
getdns_dict *d;
|
||||
upstream = &context->upstreams->upstreams[i];
|
||||
d = upstream_dict(context, upstream);
|
||||
d = sockaddr_dict(context, (struct sockaddr *)&upstream->addr);
|
||||
r |= getdns_list_set_dict(upstreams, i, d);
|
||||
getdns_dict_destroy(d);
|
||||
}
|
||||
|
|
|
@ -37,7 +37,6 @@
|
|||
#define TYPES_INTERNAL_H_
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <ldns/ldns.h>
|
||||
#include "getdns/getdns.h"
|
||||
#include "getdns/getdns_extra.h"
|
||||
#include "util/rbtree.h"
|
||||
|
|
|
@ -37,7 +37,6 @@
|
|||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <ldns/rbtree.h>
|
||||
#include <unbound.h>
|
||||
#include "getdns/getdns.h"
|
||||
#include "dict.h"
|
||||
|
@ -205,62 +204,6 @@ create_list_from_rr_list(struct getdns_context *context, ldns_rr_list * rr_list)
|
|||
return result;
|
||||
}
|
||||
|
||||
/* helper to add the ipv4 or ipv6 bin data to the list of addrs */
|
||||
static getdns_return_t
|
||||
add_only_addresses(struct getdns_list * addrs, ldns_rr_list * rr_list)
|
||||
{
|
||||
int r = GETDNS_RETURN_GOOD;
|
||||
size_t i = 0;
|
||||
size_t item_idx = 0;
|
||||
|
||||
r = getdns_list_get_length(addrs, &item_idx);
|
||||
for (i = 0; r == GETDNS_RETURN_GOOD &&
|
||||
i < ldns_rr_list_rr_count(rr_list); ++i) {
|
||||
ldns_rr *rr = ldns_rr_list_rr(rr_list, i);
|
||||
size_t j = 0;
|
||||
size_t rd_count = ldns_rr_rd_count(rr);
|
||||
for (j = 0; r == GETDNS_RETURN_GOOD && j < rd_count; ++j) {
|
||||
ldns_rdf *rdf = ldns_rr_rdf(rr, j);
|
||||
if (ldns_rdf_get_type(rdf) != LDNS_RDF_TYPE_A &&
|
||||
ldns_rdf_get_type(rdf) != LDNS_RDF_TYPE_AAAA) {
|
||||
continue;
|
||||
}
|
||||
struct getdns_dict *this_address =
|
||||
getdns_dict_create_with_extended_memory_functions(
|
||||
addrs->mf.mf_arg,
|
||||
addrs->mf.mf.ext.malloc,
|
||||
addrs->mf.mf.ext.realloc,
|
||||
addrs->mf.mf.ext.free);
|
||||
if (this_address == NULL) {
|
||||
r = GETDNS_RETURN_MEMORY_ERROR;
|
||||
break;
|
||||
}
|
||||
struct getdns_bindata rbin =
|
||||
{ ldns_rdf_size(rdf), ldns_rdf_data(rdf) };
|
||||
r = getdns_dict_set_bindata(this_address,
|
||||
GETDNS_STR_ADDRESS_TYPE,
|
||||
( ldns_rdf_get_type(rdf) == LDNS_RDF_TYPE_A
|
||||
? &IPv4_str_bindata : &IPv6_str_bindata));
|
||||
if (r != GETDNS_RETURN_GOOD) {
|
||||
getdns_dict_destroy(this_address);
|
||||
break;
|
||||
}
|
||||
|
||||
r = getdns_dict_set_bindata(this_address,
|
||||
GETDNS_STR_ADDRESS_DATA, &rbin);
|
||||
if (r != GETDNS_RETURN_GOOD) {
|
||||
getdns_dict_destroy(this_address);
|
||||
break;
|
||||
}
|
||||
|
||||
r = getdns_list_set_dict(addrs, item_idx++,
|
||||
this_address);
|
||||
getdns_dict_destroy(this_address);
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
getdns_dict *
|
||||
priv_getdns_rr_iter2rr_dict(getdns_context *context, priv_getdns_rr_iter *i)
|
||||
{
|
||||
|
@ -905,80 +848,6 @@ error_free_result:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
/*This method can be used when e.g. a local lookup has been performed and the
|
||||
result is simply a list of addresses (not a DNS packet)*/
|
||||
struct getdns_dict *
|
||||
create_getdns_response_from_rr_list(struct getdns_dns_req * completed_request,
|
||||
ldns_rr_list * response_list)
|
||||
{
|
||||
struct getdns_dict *result = getdns_dict_create_with_context(completed_request->context);
|
||||
struct getdns_list *replies_full = getdns_list_create_with_context(
|
||||
completed_request->context);
|
||||
struct getdns_list *replies_tree = getdns_list_create_with_context(
|
||||
completed_request->context);
|
||||
struct getdns_list *just_addrs = NULL;
|
||||
uint8_t canonical_name_space[256];
|
||||
getdns_bindata bindata = { 256, canonical_name_space };
|
||||
getdns_return_t r = 0;
|
||||
|
||||
/* NOTE: With DNS packet, we ignore any DNSSEC related extensions since we
|
||||
don't populate the replies full or tree at all*/
|
||||
|
||||
just_addrs = getdns_list_create_with_context(completed_request->context);
|
||||
|
||||
do {
|
||||
if ((r = gldns_str2wire_dname_buf(completed_request->name,
|
||||
bindata.data, &bindata.size)))
|
||||
break;
|
||||
if ((r = getdns_dict_set_bindata(result,
|
||||
GETDNS_STR_KEY_CANONICAL_NM, &bindata)))
|
||||
break;
|
||||
|
||||
/* For local lookups we don't set an answer_type as there isn't a
|
||||
suitable one*/
|
||||
|
||||
r = add_only_addresses(just_addrs, response_list);
|
||||
if (r != GETDNS_RETURN_GOOD) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (r != GETDNS_RETURN_GOOD)
|
||||
break;
|
||||
|
||||
r = getdns_dict_set_list(result, GETDNS_STR_KEY_REPLIES_TREE,
|
||||
replies_tree);
|
||||
if (r != GETDNS_RETURN_GOOD)
|
||||
break;
|
||||
|
||||
r = getdns_dict_set_list(result, GETDNS_STR_KEY_REPLIES_FULL,
|
||||
replies_full);
|
||||
if (r != GETDNS_RETURN_GOOD)
|
||||
break;
|
||||
|
||||
r = getdns_dict_set_list(result, GETDNS_STR_KEY_JUST_ADDRS,
|
||||
just_addrs);
|
||||
if (r != GETDNS_RETURN_GOOD) {
|
||||
break;
|
||||
}
|
||||
|
||||
r = getdns_dict_set_int(result, GETDNS_STR_KEY_STATUS,
|
||||
GETDNS_RESPSTATUS_GOOD);
|
||||
} while (0);
|
||||
|
||||
/* cleanup */
|
||||
getdns_list_destroy(replies_tree);
|
||||
getdns_list_destroy(replies_full);
|
||||
getdns_list_destroy(just_addrs);
|
||||
|
||||
if (r != 0) {
|
||||
getdns_dict_destroy(result);
|
||||
result = NULL;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* reverse an IP address for PTR lookup
|
||||
* @param address_data IP address to reverse
|
||||
|
|
|
@ -122,9 +122,6 @@ getdns_return_t sockaddr_to_dict(struct getdns_context *context,
|
|||
|
||||
struct getdns_dns_req;
|
||||
struct getdns_dict *create_getdns_response(struct getdns_dns_req *completed_request);
|
||||
struct getdns_dict *create_getdns_response_from_rr_list(struct getdns_dns_req * completed_request,
|
||||
ldns_rr_list * response_list);
|
||||
|
||||
char *reverse_address(struct getdns_bindata *address_data);
|
||||
|
||||
getdns_return_t validate_dname(const char* dname);
|
||||
|
|
Loading…
Reference in New Issue