diff --git a/bin/lwresd/client.c b/bin/lwresd/client.c index 73553ebddb..8ce3e76091 100644 --- a/bin/lwresd/client.c +++ b/bin/lwresd/client.c @@ -43,6 +43,47 @@ DP(int level, char *format, ...) va_end(args); } +void +hexdump(char *msg, void *base, size_t len) +{ + unsigned char *p; + unsigned int cnt; + char buffer[180]; + char *n; + + p = base; + cnt = 0; + n = buffer; + *n = 0; + + printf("*** %s (%u bytes @ %p)\n", msg, len, base); + + while (cnt < len) { + if (cnt % 16 == 0) { + n = buffer; + n += sprintf(buffer, "%p: ", p); + } else if (cnt % 8 == 0) { + *n++ = ' '; + *n++ = '|'; + *n = 0; + } + n += sprintf(n, " %02x", *p++); + cnt++; + + if (cnt % 16 == 0) { + DP(80, buffer); + n = buffer; + *n = 0; + } + } + + if (n != buffer) { + DP(80, buffer); + n = buffer; + *n = 0; + } +} + static void clientmgr_can_die(clientmgr_t *cm) { @@ -288,9 +329,11 @@ client_initialize(client_t *client, clientmgr_t *cmgr) client->find = NULL; client->v4find = NULL; client->v6find = NULL; - client->find_wanted = 0; + client->options = 0; + client->byaddr = NULL; + ISC_LIST_APPEND(cmgr->idle, client, link); } diff --git a/bin/lwresd/client.h b/bin/lwresd/client.h index a48bd2b775..374df8f96d 100644 --- a/bin/lwresd/client.h +++ b/bin/lwresd/client.h @@ -65,6 +65,7 @@ struct client_s { */ unsigned char *sendbuf; isc_uint32_t sendlength; + isc_buffer_t recv_buffer; /* * gabn (get address by name) state info. @@ -75,7 +76,6 @@ struct client_s { unsigned int find_wanted; /* Addresses we want */ dns_fixedname_t target_name; lwres_gabnresponse_t gabn; - isc_buffer_t recv_buffer; /* * gnba (get name by address) state info. @@ -195,5 +195,6 @@ void client_init_gabn(client_t *); void client_init_gnba(client_t *); void DP(int level, char *format, ...); +void hexdump(char *msg, void *base, size_t len); #endif /* LWD_CLIENT_H */ diff --git a/bin/lwresd/process_gabn.c b/bin/lwresd/process_gabn.c index 59da4e79fd..ed578a15ec 100644 --- a/bin/lwresd/process_gabn.c +++ b/bin/lwresd/process_gabn.c @@ -41,47 +41,6 @@ #define NEED_V6(c) ((((c)->find_wanted & LWRES_ADDRTYPE_V6) != 0) \ && ((c)->v6find == NULL)) -static void -hexdump(char *msg, void *base, size_t len) -{ - unsigned char *p; - unsigned int cnt; - char buffer[180]; - char *n; - - p = base; - cnt = 0; - n = buffer; - *n = 0; - - printf("*** %s (%u bytes @ %p)\n", msg, len, base); - - while (cnt < len) { - if (cnt % 16 == 0) { - n = buffer; - n += sprintf(buffer, "%p: ", p); - } else if (cnt % 8 == 0) { - *n++ = ' '; - *n++ = '|'; - *n = 0; - } - n += sprintf(n, " %02x", *p++); - cnt++; - - if (cnt % 16 == 0) { - DP(80, buffer); - n = buffer; - *n = 0; - } - } - - if (n != buffer) { - DP(80, buffer); - n = buffer; - *n = 0; - } -} - static void start_find(client_t *); /* @@ -207,12 +166,11 @@ generate_reply(client_t *client) lwres_buffer_init(&b, client->buffer, LWRES_RECVLENGTH); lwres = lwres_gabnresponse_render(cm->lwctx, &client->gabn, &client->pkt, &b); - - hexdump("Sending to client", b.base, b.used); - if (lwres != LWRES_R_SUCCESS) goto out; + hexdump("Sending to client", b.base, b.used); + r.base = b.base; r.length = b.used; client->sendbuf = r.base; @@ -424,6 +382,8 @@ start_find(client_t *client) goto find_again; } + DP(50, "Find returned %d (%s)", result, isc_result_totext(result)); + /* * Did we get an error? */ diff --git a/bin/lwresd/process_gnba.c b/bin/lwresd/process_gnba.c index f314802b36..2f0eba8ffa 100644 --- a/bin/lwresd/process_gnba.c +++ b/bin/lwresd/process_gnba.c @@ -59,7 +59,7 @@ byaddr_done(isc_task_t *task, isc_event_t *event) bevent = (dns_byaddrevent_t *)event; gnba = &client->gnba; - DP(50, "byaddr event result = %s\n", + DP(50, "byaddr event result = %s", isc_result_totext(bevent->result)); if (bevent->result != ISC_R_SUCCESS) { @@ -76,12 +76,14 @@ byaddr_done(isc_task_t *task, isc_event_t *event) goto out; } - for (name = ISC_LIST_HEAD(bevent->names); - name != NULL; - name = ISC_LIST_NEXT(name, link)) { + name = ISC_LIST_HEAD(bevent->names); + while (name != NULL) { b = client->recv_buffer; result = dns_name_totext(name, ISC_TRUE, &client->recv_buffer); + DP(50, "***** Found name %.*s", + client->recv_buffer.used - b.used, + (char *)(b.base) + b.used); if (result != ISC_R_SUCCESS) goto out; if (gnba->realname == NULL) { @@ -90,12 +92,14 @@ byaddr_done(isc_task_t *task, isc_event_t *event) } else { naliases = gnba->naliases; if (naliases < LWRES_MAX_ALIASES) { - gnba->aliases[naliases] = (char *)(b.base) + b.used; - gnba->aliaslen[naliases] = client->recv_buffer.used - - b.used; + gnba->aliases[naliases] = + (char *)(b.base) + b.used; + gnba->aliaslen[naliases] = + client->recv_buffer.used - b.used; gnba->naliases++; } } + name = ISC_LIST_NEXT(name, link); } dns_byaddr_destroy(&client->byaddr); @@ -110,11 +114,9 @@ byaddr_done(isc_task_t *task, isc_event_t *event) lwres_buffer_init(&lwb, client->buffer, LWRES_RECVLENGTH); lwres = lwres_gnbaresponse_render(client->clientmgr->lwctx, - &client->gnba, &client->pkt, &lwb); + gnba, &client->pkt, &lwb); -#if 0 - hexdump("Sending to client", b.base, b.used); -#endif + hexdump("Sending to client", lwb.base, lwb.used); if (lwres != LWRES_R_SUCCESS) goto out;