From 1f9ad9e66e7d94d8bf380d7612aaa97e4b7bb104 Mon Sep 17 00:00:00 2001 From: Wouter Wijngaards Date: Thu, 6 Dec 2007 16:35:36 +0000 Subject: [PATCH] unbound-host works. git-svn-id: file:///svn/unbound/trunk@810 be551aaa-1e26-0410-a405-d3ace91eadb9 --- doc/Changelog | 1 + libunbound/worker.c | 18 +++++++++++++----- smallapp/unbound-host.c | 39 ++++++++++++++++++++++++--------------- 3 files changed, 38 insertions(+), 20 deletions(-) diff --git a/doc/Changelog b/doc/Changelog index 0e6a986d8..792a57a8e 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,6 +1,7 @@ 6 December 2007: Wouter - library resolution works in foreground mode, unbound-host app receives data. + - unbound-host prints rdata using ldns. 5 December 2007: Wouter - locking in context_new() inside the function. diff --git a/libunbound/worker.c b/libunbound/worker.c index 087d39d20..c0294aafd 100644 --- a/libunbound/worker.c +++ b/libunbound/worker.c @@ -47,6 +47,7 @@ #include "libunbound/unbound.h" #include "services/outside_network.h" #include "services/mesh.h" +#include "services/localzone.h" #include "services/cache/rrset.h" #include "services/outbound_list.h" #include "util/module.h" @@ -327,13 +328,20 @@ int libworker_fg(struct ub_val_ctx* ctx, struct ctx_query* q) qflags = BIT_RD; d.q = q; d.w = w; - if(!mesh_new_callback(w->env->mesh, &qinfo, qflags, &edns, - w->back->udp_buff, qid, libworker_fg_done_cb, &d)) { + if(local_zones_answer(ctx->local_zones, &qinfo, &edns, + w->back->udp_buff, w->env->scratch)) { + libworker_fg_done_cb(&d, LDNS_RCODE_NOERROR, + w->back->udp_buff, sec_status_insecure); + } + else { + if(!mesh_new_callback(w->env->mesh, &qinfo, qflags, &edns, + w->back->udp_buff, qid, libworker_fg_done_cb, &d)) { + free(qinfo.qname); + return UB_NOMEM; + } free(qinfo.qname); - return UB_NOMEM; + comm_base_dispatch(w->base); } - free(qinfo.qname); - comm_base_dispatch(w->base); libworker_delete(w); return UB_NOERROR; } diff --git a/smallapp/unbound-host.c b/smallapp/unbound-host.c index 0babe60d3..00e9e37a8 100644 --- a/smallapp/unbound-host.c +++ b/smallapp/unbound-host.c @@ -75,7 +75,7 @@ isip4(const char* nm, char** res) if(inet_pton(AF_INET, nm, &addr) <= 0) { return 0; } - snprintf(buf, sizeof(buf), "%u.%u.%u.%u.in-addr.arpa.", + snprintf(buf, sizeof(buf), "%u.%u.%u.%u.in-addr.arpa", ((uint8_t*)&addr)[3], ((uint8_t*)&addr)[2], ((uint8_t*)&addr)[1], ((uint8_t*)&addr)[0]); *res = strdup(buf); @@ -103,7 +103,7 @@ isip6(const char* nm, char** res) *p++ = hex[ (b&0xf0) >> 4 ]; *p++ = '.'; } - snprintf(buf+16*4, sizeof(buf)-16*4, "ip6.arpa."); + snprintf(buf+16*4, sizeof(buf)-16*4, "ip6.arpa"); *res = strdup(buf); return 1; } @@ -167,9 +167,9 @@ massage_class(const char* c) static const char* statstr(int sec, struct ub_val_result* result) { - if(sec) return "[secure]"; - if(result->bogus) return "[BOGUS (security failure)]"; - return "[insecure]"; + if(sec) return "(secure)"; + if(result->bogus) return "(BOGUS (security failure))]"; + return "(insecure)"; } /** nice string for type */ @@ -212,23 +212,30 @@ pretty_rcode(char* s, size_t len, int r) static void print_rd(int t, char* data, size_t len) { - /* size_t i, pos = 0; + uint8_t* rd = malloc(len+2); + ldns_rr* rr = ldns_rr_new(); ldns_status status; - ldns_rr* rr = ldns_rr_new_frm_type(t); + if(!rd || !rr) { + fprintf(stderr, "out of memory"); + exit(1); + } + ldns_rr_set_type(rr, t); + ldns_write_uint16(rd, len); + memmove(rd+2, data, len); ldns_rr_set_owner(rr, NULL); - status = ldns_wire2rdf(rr, (uint8_t*)data, len, &pos); + status = ldns_wire2rdf(rr, rd, len+2, &pos); if(status != LDNS_STATUS_OK) { + free(rd); printf("error_printing_data"); } - printf("len = %d\n", len); for(i=0; i