From 06bec6645b974e1f1850955b6caebe0420a5c548 Mon Sep 17 00:00:00 2001 From: John Dickinson Date: Thu, 22 May 2014 15:25:36 +0000 Subject: [PATCH] Added code to construct a fake packet to allow the RCODE to be returned when libunbound refuses a query --- src/util-internal.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/util-internal.c b/src/util-internal.c index dc23563b..1d92bc70 100644 --- a/src/util-internal.c +++ b/src/util-internal.c @@ -771,11 +771,22 @@ validate_extensions(struct getdns_dict * extensions) getdns_return_t getdns_apply_network_result(getdns_network_req* netreq, struct ub_result* ub_res) { - - ldns_status r = - ldns_wire2pkt(&(netreq->result), ub_res->answer_packet, ub_res->answer_len); - if (r != LDNS_STATUS_OK) { - return GETDNS_RETURN_GENERIC_ERROR; + if (ub_res->answer_packet == NULL) { + /* Likely to be because libunbound refused the request + * so ub_res->answer_packet=NULL, ub_res->answer_len=0 + * So we need to create an answer packet. + */ + netreq->result = ldns_pkt_query_new( + ldns_rdf_new_frm_str(LDNS_RDF_TYPE_DNAME, netreq->owner->name), + netreq->request_type, + netreq->request_class,LDNS_QR|LDNS_RD|LDNS_RA); + ldns_pkt_set_rcode(netreq->result, ub_res->rcode); + } else { + ldns_status r = + ldns_wire2pkt(&(netreq->result), ub_res->answer_packet, ub_res->answer_len); + if (r != LDNS_STATUS_OK) { + return GETDNS_RETURN_GENERIC_ERROR; + } } netreq->secure = ub_res->secure; netreq->bogus = ub_res->bogus;