2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-28 21:17:54 +00:00

Various changes (mostly small) picked up in code review

This commit is contained in:
Michael Sawyer 2000-08-01 00:53:20 +00:00
parent 1cd587d241
commit 082bc93d68
3 changed files with 129 additions and 86 deletions

View File

@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/ */
/* $Id: dig.c,v 1.80 2000/07/28 00:04:44 bwelling Exp $ */ /* $Id: dig.c,v 1.81 2000/08/01 00:53:16 mws Exp $ */
#include <config.h> #include <config.h>
#include <stdlib.h> #include <stdlib.h>
@ -224,6 +224,7 @@ received(int bytes, int frmsize, char *frm, dig_query_t *query) {
/* /*
* Callback from dighost.c to print that it is trying a server. * Callback from dighost.c to print that it is trying a server.
* Not used in dig. * Not used in dig.
* XXX print_trying
*/ */
void void
trying(int frmsize, char *frm, dig_lookup_t *lookup) { trying(int frmsize, char *frm, dig_lookup_t *lookup) {
@ -563,6 +564,7 @@ reorder_args(int argc, char *argv[]) {
* We're not using isc_commandline_parse() here since the command line * We're not using isc_commandline_parse() here since the command line
* syntax of dig is quite a bit different from that which can be described * syntax of dig is quite a bit different from that which can be described
* that routine. * that routine.
* XXX doc options
*/ */
static void static void
parse_args(isc_boolean_t is_batchfile, isc_boolean_t config_only, parse_args(isc_boolean_t is_batchfile, isc_boolean_t config_only,
@ -837,7 +839,7 @@ parse_args(isc_boolean_t is_batchfile, isc_boolean_t config_only,
} else { } else {
if (rc <= 1) { if (rc <= 1) {
show_usage(); show_usage();
exit (exitcode); exit(exitcode);
} }
ptr = rv[1]; ptr = rv[1];
rv++; rv++;
@ -859,7 +861,7 @@ parse_args(isc_boolean_t is_batchfile, isc_boolean_t config_only,
} else { } else {
if (rc <= 1) { if (rc <= 1) {
show_usage(); show_usage();
exit (exitcode); exit(exitcode);
} }
ptr = rv[1]; ptr = rv[1];
rv++; rv++;
@ -888,7 +890,7 @@ parse_args(isc_boolean_t is_batchfile, isc_boolean_t config_only,
} else { } else {
if (rc <= 1) { if (rc <= 1) {
show_usage(); show_usage();
exit (exitcode); exit(exitcode);
} }
batchname = rv[1]; batchname = rv[1];
rv++; rv++;
@ -900,7 +902,7 @@ parse_args(isc_boolean_t is_batchfile, isc_boolean_t config_only,
else { else {
if (rc <= 1) { if (rc <= 1) {
show_usage(); show_usage();
exit (exitcode); exit(exitcode);
} }
ptr = rv[1]; ptr = rv[1];
rv++; rv++;
@ -924,7 +926,7 @@ parse_args(isc_boolean_t is_batchfile, isc_boolean_t config_only,
else { else {
if (rc <= 1) { if (rc <= 1) {
show_usage(); show_usage();
exit (exitcode); exit(exitcode);
} }
ptr = rv[1]; ptr = rv[1];
rv++; rv++;
@ -937,7 +939,7 @@ parse_args(isc_boolean_t is_batchfile, isc_boolean_t config_only,
} else { } else {
if (rc <= 1) { if (rc <= 1) {
show_usage(); show_usage();
exit (exitcode); exit(exitcode);
} }
port = atoi(rv[1]); port = atoi(rv[1]);
rv++; rv++;
@ -946,14 +948,14 @@ parse_args(isc_boolean_t is_batchfile, isc_boolean_t config_only,
} else if (strncmp(rv[0], "-b", 2) == 0) { } else if (strncmp(rv[0], "-b", 2) == 0) {
if (rv[0][2] != 0) { if (rv[0][2] != 0) {
strncpy(address, &rv[0][2], strncpy(address, &rv[0][2],
MXRD); sizeof(address));
} else { } else {
if (rc <= 1) { if (rc <= 1) {
show_usage(); show_usage();
exit (exitcode); exit(exitcode);
} }
strncpy(address, rv[1], strncpy(address, rv[1],
MXRD); sizeof(address));
rv++; rv++;
rc--; rc--;
} }
@ -1002,6 +1004,9 @@ parse_args(isc_boolean_t is_batchfile, isc_boolean_t config_only,
rv++; rv++;
rc--; rc--;
} else { } else {
/*
* Anything which isn't an option
*/
tr.base = rv[0]; tr.base = rv[0];
tr.length = strlen(rv[0]); tr.length = strlen(rv[0]);
if (strncmp(rv[0], "ixfr=", 5) == 0) { if (strncmp(rv[0], "ixfr=", 5) == 0) {
@ -1024,7 +1029,8 @@ parse_args(isc_boolean_t is_batchfile, isc_boolean_t config_only,
continue; continue;
} }
if (!config_only) { if (!config_only) {
lookup=clone_lookup(default_lookup, ISC_TRUE); lookup = clone_lookup(default_lookup,
ISC_TRUE);
strncpy(lookup->textname, rv[0], MXNAME-1); strncpy(lookup->textname, rv[0], MXNAME-1);
lookup->trace_root = ISC_TF(lookup->trace || lookup->trace_root = ISC_TF(lookup->trace ||
lookup->ns_search_only); lookup->ns_search_only);
@ -1033,6 +1039,7 @@ parse_args(isc_boolean_t is_batchfile, isc_boolean_t config_only,
have_host = ISC_TRUE; have_host = ISC_TRUE;
debug("looking up %s", lookup->textname); debug("looking up %s", lookup->textname);
} }
/* XXX Error message */
} }
} }
/* /*
@ -1048,6 +1055,7 @@ parse_args(isc_boolean_t is_batchfile, isc_boolean_t config_only,
exitcode = 10; exitcode = 10;
fatal("Couldn't open specified batch file"); fatal("Couldn't open specified batch file");
} }
/* XXX Remove code dup from shutdown code */
if (fgets(batchline, sizeof(batchline), batchfp) != 0) { if (fgets(batchline, sizeof(batchline), batchfp) != 0) {
debug("batch line %s", batchline); debug("batch line %s", batchline);
bargc = 1; bargc = 1;
@ -1064,8 +1072,11 @@ parse_args(isc_boolean_t is_batchfile, isc_boolean_t config_only,
parse_args(ISC_TRUE, ISC_FALSE, bargc, (char **)bargv); parse_args(ISC_TRUE, ISC_FALSE, bargc, (char **)bargv);
} }
} }
/*
* If no lookup specified, search for root
*/
if ((lookup_list.head == NULL) && !config_only) { if ((lookup_list.head == NULL) && !config_only) {
lookup=clone_lookup(default_lookup, ISC_TRUE); lookup = clone_lookup(default_lookup, ISC_TRUE);
lookup->trace_root = ISC_TF(lookup->trace || lookup->trace_root = ISC_TF(lookup->trace ||
lookup->ns_search_only); lookup->ns_search_only);
lookup->new_search = ISC_TRUE; lookup->new_search = ISC_TRUE;

View File

@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/ */
/* $Id: dighost.c,v 1.104 2000/07/28 21:56:53 mws Exp $ */ /* $Id: dighost.c,v 1.105 2000/08/01 00:53:18 mws Exp $ */
/* /*
* Notice to programmers: Do not use this code as an example of how to * Notice to programmers: Do not use this code as an example of how to
@ -113,6 +113,7 @@ isc_uint32_t rr_limit = INT_MAX;
/* /*
* Apply and clear locks at the event level in global task. * Apply and clear locks at the event level in global task.
* Can I get rid of these using shutdown events? XXX
*/ */
#define LOCK_LOOKUP {\ #define LOCK_LOOKUP {\
debug("lock_lookup %s:%d", __FILE__, __LINE__);\ debug("lock_lookup %s:%d", __FILE__, __LINE__);\
@ -398,7 +399,7 @@ setup_text_key(void) {
if (result != ISC_R_SUCCESS) { if (result != ISC_R_SUCCESS) {
printf(";; Couldn't create key %s: %s\n", printf(";; Couldn't create key %s: %s\n",
keynametext, isc_result_totext(result)); keynametext, isc_result_totext(result));
goto SYSSETUP_FAIL; goto failure;
} }
secretsize = isc_buffer_usedlength(&secretbuf); secretsize = isc_buffer_usedlength(&secretbuf);
isc_stdtime_get(&now); isc_stdtime_get(&now);
@ -409,7 +410,7 @@ setup_text_key(void) {
if (result != ISC_R_SUCCESS) { if (result != ISC_R_SUCCESS) {
printf(";; Couldn't create key %s: %s\n", printf(";; Couldn't create key %s: %s\n",
keynametext, dns_result_totext(result)); keynametext, dns_result_totext(result));
goto SYSSETUP_FAIL; goto failure;
} }
result = dns_tsigkey_create(&keyname, dns_tsig_hmacmd5_name, result = dns_tsigkey_create(&keyname, dns_tsig_hmacmd5_name,
secretstore, secretsize, secretstore, secretsize,
@ -419,11 +420,10 @@ setup_text_key(void) {
printf(";; Couldn't create key %s: %s\n", printf(";; Couldn't create key %s: %s\n",
keynametext, dns_result_totext(result)); keynametext, dns_result_totext(result));
} }
SYSSETUP_FAIL: failure:
isc_mem_free(mctx, secretstore); isc_mem_free(mctx, secretstore);
dns_name_invalidate(&keyname); dns_name_invalidate(&keyname);
isc_buffer_free(&namebuf); isc_buffer_free(&namebuf);
return;
} }
@ -445,6 +445,9 @@ setup_file_key(void) {
keyfile, isc_result_totext(result)); keyfile, isc_result_totext(result));
goto failure; goto failure;
} }
/*
* Get key size in bits, convert to bytes, rounding up (?)
*/
secretlen = (dst_key_size(dstkey) + 7) >> 3; secretlen = (dst_key_size(dstkey) + 7) >> 3;
secretstore = isc_mem_allocate(mctx, secretlen); secretstore = isc_mem_allocate(mctx, secretlen);
if (secretstore == NULL) if (secretstore == NULL)
@ -495,13 +498,16 @@ setup_system(void) {
if (search == NULL) if (search == NULL)
fatal("Memory allocation failure in %s:%d", fatal("Memory allocation failure in %s:%d",
__FILE__, __LINE__); __FILE__, __LINE__);
strncpy(search->origin, fixeddomain, MXNAME - 1); strncpy(search->origin, fixeddomain,
sizeof(search->origin) - 1);
/* XXX Check ordering, with search -vs- domain */
ISC_LIST_PREPEND(search_list, search, link); ISC_LIST_PREPEND(search_list, search, link);
} }
free_now = ISC_FALSE; free_now = ISC_FALSE;
get_servers = ISC_TF(server_list.head == NULL); get_servers = ISC_TF(server_list.head == NULL);
fp = fopen(RESOLVCONF, "r"); fp = fopen(RESOLVCONF, "r");
/* XXX Use lwres resolv.conf reader */
if (fp != NULL) { if (fp != NULL) {
while (fgets(rcinput, MXNAME, fp) != 0) { while (fgets(rcinput, MXNAME, fp) != 0) {
ptr = strtok(rcinput, " \t\r\n"); ptr = strtok(rcinput, " \t\r\n");
@ -822,13 +828,11 @@ try_clear_lookup(dig_lookup_t *lookup) {
/* /*
* If we can, start the next lookup in the queue running. * If we can, start the next lookup in the queue running.
* This assumes that the lookup on the head of the queue hasn't been * This assumes that the lookup on the head of the queue hasn't been
* started yet. It also moves the lookup from the head of the queue * started yet. It also removes the lookup from the head of the queue,
* off, setting the current_lookup pointer pointing to it. * setting the current_lookup pointer pointing to it.
*/ */
void void
start_lookup(void) { start_lookup(void) {
dig_lookup_t *next;
debug("start_lookup()"); debug("start_lookup()");
if (cancel_now) if (cancel_now)
return; return;
@ -839,18 +843,17 @@ start_lookup(void) {
*/ */
INSIST(current_lookup == NULL); INSIST(current_lookup == NULL);
next = ISC_LIST_HEAD(lookup_list); current_lookup = ISC_LIST_HEAD(lookup_list);
current_lookup = next;
/* /*
* Put the current lookup somewhere so cancel_all can find it * Put the current lookup somewhere so cancel_all can find it
*/ */
if (next != NULL) { if (current_lookup != NULL) {
ISC_LIST_DEQUEUE(lookup_list, next, link); ISC_LIST_DEQUEUE(lookup_list, current_lookup, link);
setup_lookup(next); setup_lookup(current_lookup);
do_lookup(next); do_lookup(current_lookup);
} else { } else {
check_if_done(); check_if_done();
} }
} }
/* /*
@ -1043,7 +1046,7 @@ insert_soa(dig_lookup_t *lookup) {
soa.retry = 1; soa.retry = 1;
soa.expire = 1; soa.expire = 1;
soa.minimum = 1; soa.minimum = 1;
soa.common.rdclass = dns_rdataclass_in; soa.common.rdclass = lookup->rdclass;
soa.common.rdtype = dns_rdatatype_soa; soa.common.rdtype = dns_rdatatype_soa;
dns_name_init(&soa.origin, NULL); dns_name_init(&soa.origin, NULL);
@ -1053,11 +1056,12 @@ insert_soa(dig_lookup_t *lookup) {
dns_name_clone(lookup->name, &soa.mname); dns_name_clone(lookup->name, &soa.mname);
isc_buffer_init(&lookup->rdatabuf, lookup->rdatastore, isc_buffer_init(&lookup->rdatabuf, lookup->rdatastore,
MXNAME); sizeof(lookup->rdatastore));
result = dns_message_gettemprdata(lookup->sendmsg, &rdata); result = dns_message_gettemprdata(lookup->sendmsg, &rdata);
check_result(result, "dns_message_gettemprdata"); check_result(result, "dns_message_gettemprdata");
result = dns_rdata_fromstruct(rdata, dns_rdataclass_in,
result = dns_rdata_fromstruct(rdata, lookup->rdclass,
dns_rdatatype_soa, &soa, dns_rdatatype_soa, &soa,
&lookup->rdatabuf); &lookup->rdatabuf);
check_result(result, "isc_rdata_fromstruct"); check_result(result, "isc_rdata_fromstruct");
@ -1070,7 +1074,7 @@ insert_soa(dig_lookup_t *lookup) {
dns_rdatalist_init(rdatalist); dns_rdatalist_init(rdatalist);
rdatalist->type = dns_rdatatype_soa; rdatalist->type = dns_rdatatype_soa;
rdatalist->rdclass = dns_rdataclass_in; rdatalist->rdclass = lookup->rdclass;
rdatalist->covers = dns_rdatatype_soa; rdatalist->covers = dns_rdatatype_soa;
rdatalist->ttl = 1; rdatalist->ttl = 1;
ISC_LIST_INIT(rdatalist->rdata); ISC_LIST_INIT(rdatalist->rdata);
@ -1096,7 +1100,7 @@ insert_soa(dig_lookup_t *lookup) {
*/ */
void void
setup_lookup(dig_lookup_t *lookup) { setup_lookup(dig_lookup_t *lookup) {
isc_result_t result, res2; isc_result_t result;
int len; int len;
dig_server_t *serv; dig_server_t *serv;
dig_query_t *query; dig_query_t *query;
@ -1107,11 +1111,7 @@ setup_lookup(dig_lookup_t *lookup) {
REQUIRE(lookup != NULL); REQUIRE(lookup != NULL);
INSIST(!free_now); INSIST(!free_now);
debug("setup_lookup(%p)",lookup); debug("setup_lookup(%p)", lookup);
debug("setting up for looking up %s @%p->%p",
lookup->textname, lookup,
lookup->link.next);
result = dns_message_create(mctx, DNS_MESSAGE_INTENTRENDER, result = dns_message_create(mctx, DNS_MESSAGE_INTENTRENDER,
&lookup->sendmsg); &lookup->sendmsg);
@ -1136,23 +1136,25 @@ setup_lookup(dig_lookup_t *lookup) {
sizeof(lookup->onamespace)); sizeof(lookup->onamespace));
/* /*
* If the name has too many dots, rotce the origin to be NULL * If the name has too many dots, force the origin to be NULL
* (which produces a root lookup). Otherwise, take the origin * (which produces an absolute lookup). Otherwise, take the origin
* we have if there's one in the struct already. If it's NULL, * we have if there's one in the struct already. If it's NULL,
* take the first entry in the searchlist iff either usesearch * take the first entry in the searchlist iff either usesearch
* is TRUE or we got a domain line in the resolv.conf file. * is TRUE or we got a domain line in the resolv.conf file.
*/ */
/* XXX New search here? */
if ((count_dots(lookup->textname) >= ndots) || lookup->defname) if ((count_dots(lookup->textname) >= ndots) || lookup->defname)
lookup->origin = NULL; /* Force root lookup */ lookup->origin = NULL; /* Force abs lookup */
else if (lookup->origin == NULL && lookup->new_search && else if (lookup->origin == NULL && lookup->new_search &&
(usesearch || have_domain)) (usesearch || have_domain))
lookup -> origin = ISC_LIST_HEAD(search_list); lookup->origin = ISC_LIST_HEAD(search_list);
if (lookup->origin != NULL) { if (lookup->origin != NULL) {
debug("trying origin %s", lookup->origin->origin); debug("trying origin %s", lookup->origin->origin);
result = dns_message_gettempname(lookup->sendmsg, result = dns_message_gettempname(lookup->sendmsg,
&lookup->oname); &lookup->oname);
check_result(result, "dns_message_gettempname"); check_result(result, "dns_message_gettempname");
dns_name_init(lookup->oname, NULL); dns_name_init(lookup->oname, NULL);
/* XXX Helper funct to conv char* to name? */
len = strlen(lookup->origin->origin); len = strlen(lookup->origin->origin);
isc_buffer_init(&b, lookup->origin->origin, len); isc_buffer_init(&b, lookup->origin->origin, len);
isc_buffer_add(&b, len); isc_buffer_add(&b, len);
@ -1163,26 +1165,26 @@ setup_lookup(dig_lookup_t *lookup) {
&lookup->name); &lookup->name);
dns_message_puttempname(lookup->sendmsg, dns_message_puttempname(lookup->sendmsg,
&lookup->oname); &lookup->oname);
fatal("%s is not a legal name syntax (%s)", fatal("'%s' is not in legal name syntax (%s)",
lookup->origin->origin, lookup->origin->origin,
dns_result_totext(result)); dns_result_totext(result));
} }
if (!lookup->trace_root) { if (lookup->trace_root) {
dns_name_clone(dns_rootname, lookup->name);
} else {
len = strlen(lookup->textname); len = strlen(lookup->textname);
isc_buffer_init(&b, lookup->textname, len); isc_buffer_init(&b, lookup->textname, len);
isc_buffer_add(&b, len); isc_buffer_add(&b, len);
result = dns_name_fromtext(lookup->name, &b, result = dns_name_fromtext(lookup->name, &b,
lookup->oname, ISC_FALSE, lookup->oname, ISC_FALSE,
&lookup->namebuf); &lookup->namebuf);
} else { }
dns_name_clone(dns_rootname, lookup->name);
}
if (result != ISC_R_SUCCESS) { if (result != ISC_R_SUCCESS) {
dns_message_puttempname(lookup->sendmsg, dns_message_puttempname(lookup->sendmsg,
&lookup->name); &lookup->name);
dns_message_puttempname(lookup->sendmsg, dns_message_puttempname(lookup->sendmsg,
&lookup->oname); &lookup->oname);
fatal("%s is not a legal name syntax (%s)", fatal("'%s' is not in legal name syntax (%s)",
lookup->textname, dns_result_totext(result)); lookup->textname, dns_result_totext(result));
} }
dns_message_puttempname(lookup->sendmsg, &lookup->oname); dns_message_puttempname(lookup->sendmsg, &lookup->oname);
@ -1203,19 +1205,17 @@ setup_lookup(dig_lookup_t *lookup) {
dns_message_puttempname(lookup->sendmsg, dns_message_puttempname(lookup->sendmsg,
&lookup->name); &lookup->name);
isc_buffer_init(&b, store, MXNAME); isc_buffer_init(&b, store, MXNAME);
res2 = dns_name_totext(dns_rootname, ISC_FALSE, &b); fatal("'%s' is not a legal name syntax "
check_result(res2, "dns_name_totext"); "(%s)", lookup->textname,
isc_buffer_usedregion(&b, &r); dns_result_totext(result));
fatal("%s/%.*s is not a legal name syntax "
"(%s)", lookup->textname, (int)r.length,
(char *)r.base, dns_result_totext(result));
} }
} }
isc_buffer_init(&b, store, MXNAME); isc_buffer_init(&b, store, sizeof(store));
/* XXX Move some of this into function, dns_name_format. */
dns_name_totext(lookup->name, ISC_FALSE, &b); dns_name_totext(lookup->name, ISC_FALSE, &b);
isc_buffer_usedregion(&b, &r); isc_buffer_usedregion(&b, &r);
trying((int)r.length, (char *)r.base, lookup); trying((int)r.length, (char *)r.base, lookup);
ENSURE(dns_name_isabsolute(lookup->name)); INSIST(dns_name_isabsolute(lookup->name));
lookup->sendmsg->id = (unsigned short)(random() & 0xFFFF); lookup->sendmsg->id = (unsigned short)(random() & 0xFFFF);
lookup->sendmsg->opcode = dns_opcode_query; lookup->sendmsg->opcode = dns_opcode_query;
@ -1229,6 +1229,7 @@ setup_lookup(dig_lookup_t *lookup) {
lookup->sendmsg->flags |= DNS_MESSAGEFLAG_RD; lookup->sendmsg->flags |= DNS_MESSAGEFLAG_RD;
} }
/* XXX aaflag */
if (lookup->aaonly) { if (lookup->aaonly) {
debug("AA query"); debug("AA query");
lookup->sendmsg->flags |= DNS_MESSAGEFLAG_AA; lookup->sendmsg->flags |= DNS_MESSAGEFLAG_AA;
@ -1247,30 +1248,32 @@ setup_lookup(dig_lookup_t *lookup) {
dns_message_addname(lookup->sendmsg, lookup->name, dns_message_addname(lookup->sendmsg, lookup->name,
DNS_SECTION_QUESTION); DNS_SECTION_QUESTION);
if (lookup->trace_root) { if (lookup->trace_root)
lookup->rdtype = dns_rdatatype_soa; lookup->rdtype = dns_rdatatype_soa;
lookup->rdclass = dns_rdataclass_in;
}
if ((lookup->rdtype == dns_rdatatype_axfr) || if ((lookup->rdtype == dns_rdatatype_axfr) ||
(lookup->rdtype == dns_rdatatype_ixfr)) { (lookup->rdtype == dns_rdatatype_ixfr)) {
lookup->doing_xfr = ISC_TRUE; lookup->doing_xfr = ISC_TRUE;
/* /*
* Force TCP mode if we're doing an xfr. * Force TCP mode if we're doing an xfr.
* XXX UDP ixfr's would be useful
*/ */
lookup->tcp_mode = ISC_TRUE; lookup->tcp_mode = ISC_TRUE;
} }
add_question(lookup->sendmsg, lookup->name, lookup->rdclass, add_question(lookup->sendmsg, lookup->name, lookup->rdclass,
lookup->rdtype); lookup->rdtype);
/* XXX add_soa */
if (lookup->rdtype == dns_rdatatype_ixfr) if (lookup->rdtype == dns_rdatatype_ixfr)
insert_soa(lookup); insert_soa(lookup);
/* XXX Insist this? */
lookup->tsigctx = NULL;
lookup->querysig = NULL;
if (key != NULL) { if (key != NULL) {
debug("initializing keys"); debug("initializing keys");
result = dns_message_settsigkey(lookup->sendmsg, key); result = dns_message_settsigkey(lookup->sendmsg, key);
check_result(result, "dns_message_settsigkey"); check_result(result, "dns_message_settsigkey");
lookup->tsigctx = NULL;
lookup->querysig = NULL;
} }
lookup->sendspace = isc_mempool_get(commctx); lookup->sendspace = isc_mempool_get(commctx);
@ -1281,9 +1284,9 @@ setup_lookup(dig_lookup_t *lookup) {
isc_buffer_init(&lookup->sendbuf, lookup->sendspace, COMMSIZE); isc_buffer_init(&lookup->sendbuf, lookup->sendspace, COMMSIZE);
result = dns_message_renderbegin(lookup->sendmsg, &lookup->sendbuf); result = dns_message_renderbegin(lookup->sendmsg, &lookup->sendbuf);
check_result(result, "dns_message_renderbegin"); check_result(result, "dns_message_renderbegin");
if (lookup->udpsize > 0) { if (lookup->udpsize > 0)
add_opt(lookup->sendmsg, lookup->udpsize); add_opt(lookup->sendmsg, lookup->udpsize);
}
result = dns_message_rendersection(lookup->sendmsg, result = dns_message_rendersection(lookup->sendmsg,
DNS_SECTION_QUESTION, 0); DNS_SECTION_QUESTION, 0);
check_result(result, "dns_message_rendersection"); check_result(result, "dns_message_rendersection");
@ -1294,10 +1297,11 @@ setup_lookup(dig_lookup_t *lookup) {
check_result(result, "dns_message_renderend"); check_result(result, "dns_message_renderend");
debug("done rendering"); debug("done rendering");
/* XXX Insist? */
lookup->pending = ISC_FALSE; lookup->pending = ISC_FALSE;
serv = ISC_LIST_HEAD(lookup->my_server_list); for (serv = ISC_LIST_HEAD(lookup->my_server_list);
for (; serv != NULL; serv != NULL;
serv = ISC_LIST_NEXT(serv, link)) { serv = ISC_LIST_NEXT(serv, link)) {
query = isc_mem_allocate(mctx, sizeof(dig_query_t)); query = isc_mem_allocate(mctx, sizeof(dig_query_t));
if (query == NULL) if (query == NULL)
@ -1327,11 +1331,12 @@ setup_lookup(dig_lookup_t *lookup) {
ISC_LIST_ENQUEUE(lookup->q, query, link); ISC_LIST_ENQUEUE(lookup->q, query, link);
} }
/* XXX qrflag, print_query, etc... */
if (!ISC_LIST_EMPTY(lookup->q) && qr) { if (!ISC_LIST_EMPTY(lookup->q) && qr) {
printmessage(ISC_LIST_HEAD(lookup->q), lookup->sendmsg, printmessage(ISC_LIST_HEAD(lookup->q), lookup->sendmsg,
ISC_TRUE); ISC_TRUE);
} }
} }
/* /*
* Event handler for send completion. Track send counter, and clear out * Event handler for send completion. Track send counter, and clear out
@ -1416,7 +1421,6 @@ send_udp(dig_lookup_t *lookup, isc_boolean_t make_recv) {
&lookup->timer); &lookup->timer);
check_result(result, "isc_timer_create"); check_result(result, "isc_timer_create");
} }
} else { } else {
result = isc_timer_reset(lookup->timer, isc_timertype_once, result = isc_timer_reset(lookup->timer, isc_timertype_once,
NULL, &lookup->interval, NULL, &lookup->interval,
@ -1448,7 +1452,7 @@ send_udp(dig_lookup_t *lookup, isc_boolean_t make_recv) {
debug("sending a request"); debug("sending a request");
result = isc_time_now(&query->time_sent); result = isc_time_now(&query->time_sent);
check_result(result, "isc_time_now"); check_result(result, "isc_time_now");
ENSURE(query->sock != NULL); INSIST(query->sock != NULL);
result = isc_socket_sendtov(query->sock, &query->sendlist, result = isc_socket_sendtov(query->sock, &query->sendlist,
global_task, send_done, query, global_task, send_done, query,
&query->sockaddr, NULL); &query->sockaddr, NULL);
@ -1675,6 +1679,7 @@ connect_done(isc_task_t *task, isc_event_t *event) {
result = isc_sockaddr_totext(&query->sockaddr, b); result = isc_sockaddr_totext(&query->sockaddr, b);
check_result(result, "isc_sockaddr_totext"); check_result(result, "isc_sockaddr_totext");
isc_buffer_usedregion(b, &r); isc_buffer_usedregion(b, &r);
/* XXX isc_sockaddr_format */
if (sevent->result != ISC_R_CANCELED) if (sevent->result != ISC_R_CANCELED)
printf(";; Connection to %.*s(%s) for %s failed: " printf(";; Connection to %.*s(%s) for %s failed: "
"%s.\n", (int)r.length, r.base, "%s.\n", (int)r.length, r.base,
@ -1683,9 +1688,10 @@ connect_done(isc_task_t *task, isc_event_t *event) {
isc_socket_detach(&query->sock); isc_socket_detach(&query->sock);
sockcount--; sockcount--;
INSIST(sockcount >= 0); INSIST(sockcount >= 0);
/* XXX Clean up exitcodes */
if (exitcode < 7) if (exitcode < 7)
exitcode = 9; exitcode = 9;
debug("sockcount=%d",sockcount); debug("sockcount=%d", sockcount);
isc_buffer_free(&b); isc_buffer_free(&b);
query->waiting_connect = ISC_FALSE; query->waiting_connect = ISC_FALSE;
isc_event_free(&event); isc_event_free(&event);
@ -1921,7 +1927,6 @@ recv_done(isc_task_t *task, isc_event_t *event) {
isc_timer_touch(l->timer); isc_timer_touch(l->timer);
if ((!l->pending && !l->ns_search_only) if ((!l->pending && !l->ns_search_only)
|| cancel_now) { || cancel_now) {
debug("no longer pending. Got %s", debug("no longer pending. Got %s",
isc_result_totext(sevent->result)); isc_result_totext(sevent->result));
query->waiting_connect = ISC_FALSE; query->waiting_connect = ISC_FALSE;
@ -1941,7 +1946,6 @@ recv_done(isc_task_t *task, isc_event_t *event) {
check_result(result, "dns_message_create"); check_result(result, "dns_message_create");
if (key != NULL) { if (key != NULL) {
debug("querysig 1 is %p", l->querysig);
if (l->querysig == NULL) { if (l->querysig == NULL) {
debug("getting initial querysig"); debug("getting initial querysig");
result = dns_message_getquerytsig( result = dns_message_getquerytsig(
@ -1963,7 +1967,7 @@ recv_done(isc_task_t *task, isc_event_t *event) {
debug("before parse starts"); debug("before parse starts");
result = dns_message_parse(msg, b, ISC_TRUE); result = dns_message_parse(msg, b, ISC_TRUE);
if (result != ISC_R_SUCCESS) { if (result != ISC_R_SUCCESS) {
printf(";; Got bad UDP packet:\n"); printf(";; Got bad packet:\n");
hex_dump(b); hex_dump(b);
query->waiting_connect = ISC_FALSE; query->waiting_connect = ISC_FALSE;
if (!l->tcp_mode) { if (!l->tcp_mode) {
@ -1980,11 +1984,8 @@ recv_done(isc_task_t *task, isc_event_t *event) {
return; return;
} }
if (key != NULL) { if (key != NULL) {
debug("querysig 2 is %p", l->querysig);
debug("before verify");
result = dns_tsig_verify(&query->recvbuf, msg, result = dns_tsig_verify(&query->recvbuf, msg,
NULL, NULL); NULL, NULL);
debug("after verify");
if (result != ISC_R_SUCCESS) { if (result != ISC_R_SUCCESS) {
printf(";; Couldn't verify signature: %s\n", printf(";; Couldn't verify signature: %s\n",
dns_result_totext(result)); dns_result_totext(result));
@ -2043,14 +2044,25 @@ recv_done(isc_task_t *task, isc_event_t *event) {
(((dns_message_firstname(msg, (((dns_message_firstname(msg,
DNS_SECTION_ANSWER) DNS_SECTION_ANSWER)
== ISC_R_SUCCESS)) && == ISC_R_SUCCESS)) &&
!l->trace_root)) { !l->trace_root))
printmessage(query, msg, ISC_TRUE); printmessage(query, msg, ISC_TRUE);
}
if ((msg->rcode != 0) && if ((msg->rcode != 0) &&
(l->origin != NULL)) { (l->origin != NULL)) {
if (!next_origin(msg, query)) if (!next_origin(msg, query)) {
printmessage(query, msg, printmessage(query, msg,
ISC_TRUE); ISC_TRUE);
isc_buffer_init(&ab, abspace,
MXNAME);
result = isc_sockaddr_totext(
&sevent->address,
&ab);
check_result(result,
"isc_sockaddr_totext");
isc_buffer_usedregion(&ab, &r);
received(b->used, r.length,
(char *)r.base,
query);
}
} else { } else {
result = dns_message_firstname result = dns_message_firstname
(msg,DNS_SECTION_ANSWER); (msg,DNS_SECTION_ANSWER);
@ -2061,9 +2073,20 @@ recv_done(isc_task_t *task, isc_event_t *event) {
} }
} else if ((msg->rcode != 0) && } else if ((msg->rcode != 0) &&
(l->origin != NULL)) { (l->origin != NULL)) {
if (!next_origin(msg, query)) if (!next_origin(msg, query)) {
printmessage(query, msg, printmessage(query, msg,
ISC_TRUE); ISC_TRUE);
isc_buffer_init(&ab, abspace, MXNAME);
result = isc_sockaddr_totext(
&sevent->address,
&ab);
check_result(result,
"isc_sockaddr_totext");
isc_buffer_usedregion(&ab, &r);
received(b->used, r.length,
(char *)r.base,
query);
}
if (show_details) { if (show_details) {
printmessage(query, msg, ISC_TRUE); printmessage(query, msg, ISC_TRUE);
} }
@ -2132,6 +2155,7 @@ recv_done(isc_task_t *task, isc_event_t *event) {
/* /*
* In truth, we should never get into the CANCELED routine, since * In truth, we should never get into the CANCELED routine, since
* the cancel_lookup() routine clears the pending flag. * the cancel_lookup() routine clears the pending flag.
* XXX Is this true anymore, since the bulk changes?
*/ */
if (sevent->result == ISC_R_CANCELED) { if (sevent->result == ISC_R_CANCELED) {
debug("in recv cancel handler"); debug("in recv cancel handler");
@ -2204,9 +2228,9 @@ do_lookup_tcp(dig_lookup_t *lookup) {
debug("do_lookup_tcp()"); debug("do_lookup_tcp()");
lookup->pending = ISC_TRUE; lookup->pending = ISC_TRUE;
if (timeout != INT_MAX) { if (timeout != INT_MAX) {
if (timeout == 0) { if (timeout == 0)
local_timeout = TCP_TIMEOUT; local_timeout = TCP_TIMEOUT;
} else else
local_timeout = timeout; local_timeout = timeout;
debug("have local timeout of %d", local_timeout); debug("have local timeout of %d", local_timeout);
isc_interval_set(&lookup->interval, local_timeout, 0); isc_interval_set(&lookup->interval, local_timeout, 0);
@ -2223,7 +2247,7 @@ do_lookup_tcp(dig_lookup_t *lookup) {
query->waiting_connect = ISC_TRUE; query->waiting_connect = ISC_TRUE;
get_address(query->servname, port, &query->sockaddr); get_address(query->servname, port, &query->sockaddr);
ENSURE(query->sock == NULL); INSIST(query->sock == NULL);
result = isc_socket_create(socketmgr, result = isc_socket_create(socketmgr,
isc_sockaddr_pf(&query->sockaddr), isc_sockaddr_pf(&query->sockaddr),
isc_sockettype_tcp, &query->sock) ; isc_sockettype_tcp, &query->sock) ;
@ -2255,12 +2279,13 @@ do_lookup_udp(dig_lookup_t *lookup) {
isc_result_t result; isc_result_t result;
debug("do_lookup_udp()"); debug("do_lookup_udp()");
ENSURE(!lookup->tcp_mode); INSIST(!lookup->tcp_mode);
lookup->pending = ISC_TRUE; lookup->pending = ISC_TRUE;
for (query = ISC_LIST_HEAD(lookup->q); for (query = ISC_LIST_HEAD(lookup->q);
query != NULL; query != NULL;
query = ISC_LIST_NEXT(query, link)) { query = ISC_LIST_NEXT(query, link)) {
/* XXX Check the sense of this, need assertion? */
query->waiting_connect = ISC_FALSE; query->waiting_connect = ISC_FALSE;
get_address(query->servname, port, &query->sockaddr); get_address(query->servname, port, &query->sockaddr);
@ -2273,6 +2298,7 @@ do_lookup_udp(dig_lookup_t *lookup) {
if (specified_source) if (specified_source)
result = isc_socket_bind(query->sock, &bind_address); result = isc_socket_bind(query->sock, &bind_address);
else { else {
/* XXX Add this to lib, send gson mail. */
if (isc_sockaddr_pf(&query->sockaddr) == AF_INET) if (isc_sockaddr_pf(&query->sockaddr) == AF_INET)
isc_sockaddr_any(&bind_any); isc_sockaddr_any(&bind_any);
else else
@ -2306,6 +2332,7 @@ do_lookup(dig_lookup_t *lookup) {
void void
onrun_callback(isc_task_t *task, isc_event_t *event) { onrun_callback(isc_task_t *task, isc_event_t *event) {
UNUSED(task); UNUSED(task);
isc_event_free(&event); isc_event_free(&event);
LOCK_LOOKUP; LOCK_LOOKUP;
start_lookup(); start_lookup();

View File

@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/ */
/* $Id: dig.h,v 1.39 2000/07/27 19:06:12 mws Exp $ */ /* $Id: dig.h,v 1.40 2000/08/01 00:53:20 mws Exp $ */
#ifndef DIG_H #ifndef DIG_H
#define DIG_H #define DIG_H
@ -33,7 +33,12 @@
#include <isc/socket.h> #include <isc/socket.h>
#define MXSERV 6 #define MXSERV 6
/* XXXMWS Get MXNAME from name.h, or wherever */
#define MXNAME 1005 #define MXNAME 1005
/*
* MXNAME was decided upon on 7/31/00 at IETF by everyone.
* This may well NOT be true for bitstring labels.
*/
#define MXRD 32 #define MXRD 32
#define BUFSIZE 512 #define BUFSIZE 512
#define COMMSIZE 0xffff #define COMMSIZE 0xffff