From 971c43c6590dcaa63905190f82437802c57b5f11 Mon Sep 17 00:00:00 2001 From: Willem Toorop Date: Thu, 13 Feb 2020 15:33:13 +0100 Subject: [PATCH] Fix #432 answer_ipv4_address and answer_ipv6_address in reply and reponse dicts. I realise we also do not have intermediate_aliases yet... --- ChangeLog | 4 ++++ src/dict.c | 4 +++- src/util-internal.c | 53 +++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 58 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1240c339..de682fdd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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 * Migration of build system to cmake. Build now works on Ubuntu, Windows 10 and macOS. diff --git a/src/dict.c b/src/dict.c index 3a90f52c..66eabd46 100644 --- a/src/dict.c +++ b/src/dict.c @@ -1149,7 +1149,9 @@ getdns_pp_dict(gldns_buffer * buf, size_t indent, case t_bindata: if ((strcmp(item->node.key, "address_data") == 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 == 16 )) { diff --git a/src/util-internal.c b/src/util-internal.c index be919637..52897efa 100644 --- a/src/util-internal.c +++ b/src/util-internal.c @@ -725,6 +725,23 @@ _getdns_create_reply_dict(getdns_context *context, getdns_network_req *req, , answer_spc.rrset.name)) 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) goto success; @@ -1125,6 +1142,8 @@ _getdns_create_getdns_response(getdns_dns_req *completed_request) getdns_dict *netreq_debug; _srvs srvs = { 0, 0, NULL }; _getdns_rrset_spc answer_spc; + getdns_bindata *answer_ipv4_address = NULL; + getdns_bindata *answer_ipv6_address = NULL; /* info (bools) about dns_req */ int dnssec_return_status; @@ -1160,8 +1179,7 @@ _getdns_create_getdns_response(getdns_dns_req *completed_request) goto error_free_result; } } - if (getdns_dict_set_int(result, GETDNS_STR_KEY_ANSWER_TYPE, - GETDNS_NAMETYPE_DNS)) + if (getdns_dict_set_int(result, "answer_type", GETDNS_NAMETYPE_DNS)) goto error_free_result; 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 ; (netreq = *netreq_p) ; netreq_p++) { + getdns_bindata *tmp_ipv4_address; + getdns_bindata *tmp_ipv6_address; if (call_reporting && ( netreq->response_len || netreq->state == NET_REQ_TIMED_OUT)) { @@ -1233,6 +1253,27 @@ _getdns_create_getdns_response(getdns_dns_req *completed_request) result, "canonical_name", canonical_name)) 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 * 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)) 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 (_getdns_dict_set_this_list( result, "call_reporting", call_reporting))