summaryrefslogtreecommitdiffstats
path: root/contrib/unbound/libunbound/libworker.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/unbound/libunbound/libworker.c')
-rw-r--r--contrib/unbound/libunbound/libworker.c41
1 files changed, 27 insertions, 14 deletions
diff --git a/contrib/unbound/libunbound/libworker.c b/contrib/unbound/libunbound/libworker.c
index 917a910..bd61cea 100644
--- a/contrib/unbound/libunbound/libworker.c
+++ b/contrib/unbound/libunbound/libworker.c
@@ -44,7 +44,9 @@
#include "config.h"
#include <ldns/dname.h>
#include <ldns/wire2host.h>
+#ifdef HAVE_SSL
#include <openssl/ssl.h>
+#endif
#include "libunbound/libworker.h"
#include "libunbound/context.h"
#include "libunbound/unbound.h"
@@ -88,7 +90,9 @@ libworker_delete(struct libworker* w)
ub_randfree(w->env->rnd);
free(w->env);
}
+#ifdef HAVE_SSL
SSL_CTX_free(w->sslctx);
+#endif
outside_network_delete(w->back);
comm_base_delete(w->base);
free(w);
@@ -407,15 +411,18 @@ fill_canon(struct ub_result* res, uint8_t* s)
/** fill data into result */
static int
fill_res(struct ub_result* res, struct ub_packed_rrset_key* answer,
- uint8_t* finalcname, struct query_info* rq)
+ uint8_t* finalcname, struct query_info* rq, struct reply_info* rep)
{
size_t i;
struct packed_rrset_data* data;
+ res->ttl = 0;
if(!answer) {
if(finalcname) {
if(!fill_canon(res, finalcname))
return 0; /* out of memory */
}
+ if(rep->rrset_count != 0)
+ res->ttl = (int)rep->ttl;
res->data = (char**)calloc(1, sizeof(char*));
res->len = (int*)calloc(1, sizeof(int));
return (res->data && res->len);
@@ -436,6 +443,21 @@ fill_res(struct ub_result* res, struct ub_packed_rrset_key* answer,
if(!res->data[i])
return 0; /* out of memory */
}
+ /* ttl for positive answers, from CNAME and answer RRs */
+ if(data->count != 0) {
+ size_t j;
+ res->ttl = (int)data->ttl;
+ for(j=0; j<rep->an_numrrsets; j++) {
+ struct packed_rrset_data* d =
+ (struct packed_rrset_data*)rep->rrsets[j]->
+ entry.data;
+ if((int)d->ttl < res->ttl)
+ res->ttl = (int)d->ttl;
+ }
+ }
+ /* ttl for negative answers */
+ if(data->count == 0 && rep->rrset_count != 0)
+ res->ttl = (int)rep->ttl;
res->data[data->count] = NULL;
res->len[data->count] = 0;
return 1;
@@ -455,7 +477,7 @@ libworker_enter_result(struct ub_result* res, ldns_buffer* buf,
return; /* error parsing buf, or out of memory */
}
if(!fill_res(res, reply_find_answer_rrset(&rq, rep),
- reply_find_final_cname_target(&rq, rep), &rq))
+ reply_find_final_cname_target(&rq, rep), &rq, rep))
return; /* out of memory */
/* rcode, havedata, nxdomain, secure, bogus */
res->rcode = (int)FLAGS_GET_RCODE(rep->flags);
@@ -643,6 +665,8 @@ libworker_bg_done_cb(void* arg, int rcode, ldns_buffer* buf, enum sec_status s,
return;
}
q->msg_security = s;
+ if(!buf)
+ buf = q->w->env->scratch_buffer;
if(rcode != 0) {
error_encode(buf, rcode, NULL, 0, BIT_RD, NULL);
}
@@ -703,17 +727,6 @@ void libworker_alloc_cleanup(void* arg)
slabhash_clear(w->env->msg_cache);
}
-/** compare outbound entry qstates */
-static int
-outbound_entry_compare(void* a, void* b)
-{
- struct outbound_entry* e1 = (struct outbound_entry*)a;
- struct outbound_entry* e2 = (struct outbound_entry*)b;
- if(e1->qstate == e2->qstate)
- return 1;
- return 0;
-}
-
struct outbound_entry* libworker_send_query(uint8_t* qname, size_t qnamelen,
uint16_t qtype, uint16_t qclass, uint16_t flags, int dnssec,
int want_dnssec, struct sockaddr_storage* addr, socklen_t addrlen,
@@ -729,7 +742,7 @@ struct outbound_entry* libworker_send_query(uint8_t* qname, size_t qnamelen,
qnamelen, qtype, qclass, flags, dnssec, want_dnssec,
q->env->cfg->tcp_upstream, q->env->cfg->ssl_upstream, addr,
addrlen, zone, zonelen, libworker_handle_service_reply, e,
- w->back->udp_buff, &outbound_entry_compare);
+ w->back->udp_buff);
if(!e->qsent) {
return NULL;
}
OpenPOWER on IntegriCloud