Fix #432 answer_ipv4_address and answer_ipv6_address

in reply and reponse dicts.
I realise we also do not have intermediate_aliases yet...
This commit is contained in:
Willem Toorop 2020-02-13 15:33:13 +01:00
parent f33a4b2d4e
commit 971c43c659
3 changed files with 58 additions and 3 deletions

View File

@ -1,3 +1,7 @@
* 2020-02-??: Versopm 1.6.0
* answer_ipv4_address and answer_ipv6_address in reply and response
dicts.
* 2019-12-20: Version 1.6.0-beta.1 * 2019-12-20: Version 1.6.0-beta.1
* Migration of build system to cmake. Build now works on Ubuntu, * Migration of build system to cmake. Build now works on Ubuntu,
Windows 10 and macOS. Windows 10 and macOS.

View File

@ -1149,7 +1149,9 @@ getdns_pp_dict(gldns_buffer * buf, size_t indent,
case t_bindata: case t_bindata:
if ((strcmp(item->node.key, "address_data") == 0 || if ((strcmp(item->node.key, "address_data") == 0 ||
strcmp(item->node.key, "ipv4_address") == 0 || strcmp(item->node.key, "ipv4_address") == 0 ||
strcmp(item->node.key, "ipv6_address") == 0 ) && strcmp(item->node.key, "ipv6_address") == 0 ||
strcmp(item->node.key, "answer_ipv4_address") == 0 ||
strcmp(item->node.key, "answer_ipv6_address") == 0) &&
(item->i.data.bindata->size == 4 || (item->i.data.bindata->size == 4 ||
item->i.data.bindata->size == 16 )) { item->i.data.bindata->size == 16 )) {

View File

@ -725,6 +725,23 @@ _getdns_create_reply_dict(getdns_context *context, getdns_network_req *req,
, answer_spc.rrset.name)) , answer_spc.rrset.name))
goto error; goto error;
if (!req->upstream)
;
else if (req->upstream->addr.ss_family == AF_INET) {
struct sockaddr_in *addr = (struct sockaddr_in *) &req->upstream->addr;
if (_getdns_dict_set_const_bindata(result,
"answer_ipv4_address", sizeof(addr->sin_addr)
, (uint8_t *) & (addr->sin_addr)))
goto error;
}
else if (req->upstream->addr.ss_family == AF_INET6) {
struct sockaddr_in6 *addr = (struct sockaddr_in6 *) &req->upstream->addr;
if (_getdns_dict_set_const_bindata(result,
"answer_ipv6_address", sizeof(addr->sin6_addr)
, (uint8_t *) & (addr->sin6_addr)))
goto error;
}
if (!req->owner->add_warning_for_bad_dns) if (!req->owner->add_warning_for_bad_dns)
goto success; goto success;
@ -1125,6 +1142,8 @@ _getdns_create_getdns_response(getdns_dns_req *completed_request)
getdns_dict *netreq_debug; getdns_dict *netreq_debug;
_srvs srvs = { 0, 0, NULL }; _srvs srvs = { 0, 0, NULL };
_getdns_rrset_spc answer_spc; _getdns_rrset_spc answer_spc;
getdns_bindata *answer_ipv4_address = NULL;
getdns_bindata *answer_ipv6_address = NULL;
/* info (bools) about dns_req */ /* info (bools) about dns_req */
int dnssec_return_status; int dnssec_return_status;
@ -1160,8 +1179,7 @@ _getdns_create_getdns_response(getdns_dns_req *completed_request)
goto error_free_result; goto error_free_result;
} }
} }
if (getdns_dict_set_int(result, GETDNS_STR_KEY_ANSWER_TYPE, if (getdns_dict_set_int(result, "answer_type", GETDNS_NAMETYPE_DNS))
GETDNS_NAMETYPE_DNS))
goto error_free_result; goto error_free_result;
if (!(replies_full = getdns_list_create_with_context(context))) if (!(replies_full = getdns_list_create_with_context(context)))
@ -1176,6 +1194,8 @@ _getdns_create_getdns_response(getdns_dns_req *completed_request)
for ( netreq_p = completed_request->netreqs for ( netreq_p = completed_request->netreqs
; (netreq = *netreq_p) ; netreq_p++) { ; (netreq = *netreq_p) ; netreq_p++) {
getdns_bindata *tmp_ipv4_address;
getdns_bindata *tmp_ipv6_address;
if (call_reporting && ( netreq->response_len if (call_reporting && ( netreq->response_len
|| netreq->state == NET_REQ_TIMED_OUT)) { || netreq->state == NET_REQ_TIMED_OUT)) {
@ -1233,6 +1253,27 @@ _getdns_create_getdns_response(getdns_dns_req *completed_request)
result, "canonical_name", canonical_name)) result, "canonical_name", canonical_name))
goto error; goto error;
} }
if (!getdns_dict_get_bindata(
reply, "answer_ipv4_address", &tmp_ipv4_address)) {
if (!answer_ipv4_address)
answer_ipv4_address = tmp_ipv4_address;
else if (tmp_ipv4_address->size != answer_ipv4_address->size
|| memcmp( tmp_ipv4_address->data
, answer_ipv4_address->data
, answer_ipv4_address->size))
answer_ipv4_address = NULL;
}
if (!getdns_dict_get_bindata(
reply, "answer_ipv6_address", &tmp_ipv6_address)) {
if (!answer_ipv6_address)
answer_ipv6_address = tmp_ipv6_address;
else if (tmp_ipv6_address->size != answer_ipv6_address->size
|| memcmp( tmp_ipv6_address->data
, answer_ipv6_address->data
, answer_ipv6_address->size))
answer_ipv6_address = NULL;
}
/* TODO: Check instead if canonical_name for request_type /* TODO: Check instead if canonical_name for request_type
* is in the answer section. * is in the answer section.
*/ */
@ -1269,6 +1310,14 @@ _getdns_create_getdns_response(getdns_dns_req *completed_request)
completed_request->name_len, completed_request->name)) completed_request->name_len, completed_request->name))
goto error; goto error;
if (answer_ipv4_address &&
getdns_dict_set_bindata(result, "answer_ipv4_address", answer_ipv4_address))
goto error;
if (answer_ipv6_address &&
getdns_dict_set_bindata(result, "answer_ipv6_address", answer_ipv6_address))
goto error;
if (call_reporting) { if (call_reporting) {
if (_getdns_dict_set_this_list( if (_getdns_dict_set_this_list(
result, "call_reporting", call_reporting)) result, "call_reporting", call_reporting))