dighost.c revision 6331b9a45efba4e4e71e66ce4e2613a3433d18b2
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Copyright (C) 2000 Internet Software Consortium.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Permission to use, copy, modify, and distribute this software for any
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * purpose with or without fee is hereby granted, provided that the above
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * copyright notice and this permission notice appear in all copies.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
0a45f098e446a7f41c2a71d9dd0fd8f459b49c34Brian Wellington/* $Id: dighost.c,v 1.74 2000/07/11 17:35:49 mws Exp $ */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Notice to programmers: Do not use this code as an example of how to
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * use the ISC library to perform DNS lookups. Dig and Host both operate
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * on the request level, since they allow fine-tuning of output and are
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * intended as debugging tools. As a result, they perform many of the
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * functions which could be better handled using the dns_resolver
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * functions in most applications.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#if (!(defined(HAVE_ADDRINFO) && defined(HAVE_GETADDRINFO)))
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonunsigned int timeout = 0;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington while (*s != '\0') {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (*s == '.')
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington unsigned int len;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington printf("Printing a buffer with length %d\n", r.length);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtoncheck_result(isc_result_t result, const char *msg) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington fatal("%s: %s", msg, isc_result_totext(result));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Tests if a field is a class, without needing isc libs
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * initialized. This list will have to be manually kept in
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellington * sync with what the libs support.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington const char *classlist[] = { "in", "hs", "chaos" };
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington for (i = 0; i < numclasses; i++)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Tests if a field is a type, without needing isc libs
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * initialized. This list will have to be manually kept in
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * sync with what the libs support.
8a63ecd93331cab4fd006f0556335d77abddd924Andreas Gustafsson const char *typelist[] = {"a", "ns", "md", "mf", "cname",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington for (i = 0; i < numtypes; i++) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonrequeue_lookup(dig_lookup_t *lookold, isc_boolean_t servers) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington looknew = isc_mem_allocate(mctx, sizeof(struct dig_lookup));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington fatal("Memory allocation failure in %s:%d",
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington strncpy(looknew->textname, lookold-> textname, MXNAME);
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington strncpy(looknew->rttext, lookold-> rttext, 32);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington strncpy(looknew->rctext, lookold-> rctext, 32);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington looknew->ixfr_serial = lookold->ixfr_serial;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington looknew->ns_search_only = lookold->ns_search_only;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington looknew->section_question = lookold->section_question;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington looknew->section_answer = lookold->section_answer;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington looknew->section_authority = lookold->section_authority;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington looknew->section_additional = lookold->section_additional;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington looknew->use_my_server_list = lookold->use_my_server_list;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington s = ISC_LIST_HEAD(lookold->my_server_list);
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington while (s != NULL) {
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington sizeof(struct dig_server));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ISC_LIST_ENQUEUE(looknew->my_server_list, srv,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "-> %p, new@%p -> %p",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookold, lookold->link.next, looknew, looknew->link.next);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ISC_LIST_INSERTAFTER(lookup_list, lookold, looknew, link);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "%p, new = %p, new -> %p",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington unsigned char *secretstore;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington debug("using fixed domain %s", fixeddomain);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington search = isc_mem_allocate(mctx, sizeof(struct dig_server));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington fatal("Memory allocation failure in %s:%d",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington strncpy(search->origin, fixeddomain, MXNAME - 1);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ISC_LIST_PREPEND(search_list, search, link);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington get_servers = ISC_TF(server_list.head == NULL);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington sizeof(struct dig_server));
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington "allocation "
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington "failure in "
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington } else if (strcasecmp(ptr, "options") == 0) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington } else if ((strcasecmp(ptr, "search") == 0)
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington mctx, sizeof(struct
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington "allocation "
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington "failure in %s:"
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington } else if ((strcasecmp(ptr, "domain") == 0) &&
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington mctx, sizeof(struct
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "allocation "
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "failure in %s:"
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington srv = isc_mem_allocate(mctx, sizeof(dig_server_t));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_tsigkeyring_create(mctx, &keyring);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington check_result(result, "dns_tsigkeyring_create");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = isc_buffer_allocate(mctx, &namebuf, MXNAME);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington check_result(result, "isc_buffer_allocate");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington secretstore = isc_mem_get(mctx, secretsize);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington fatal("Memory allocation failure in %s:%d",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_init(&secretsrc, keysecret, strlen(keysecret));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_add(&secretsrc, strlen(keysecret));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_init(&secretbuf, secretstore, secretsize);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = isc_lex_create(mctx, strlen(keysecret), &lex);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = isc_lex_openbuffer(lex, &secretsrc);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington check_result(result, "isc_lex_openbuffer");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = isc_base64_tobuffer(lex, &secretbuf, -1);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington secretsize = isc_buffer_usedlength(&secretbuf);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_name_fromtext(&keyname, namebuf,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_tsigkey_create(&keyname, dns_tsig_hmacmd5_name,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_mem_put(mctx, secretstore, secretsize);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_mem_put(mctx, secretstore, secretsize);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Warning: This is not particularly good randomness. We'll
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * just use random() now for getting id values, but doing so
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * does NOT insure that id's cann't be guessed.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = isc_taskmgr_create(mctx, 1, 0, &taskmgr);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington check_result(result, "isc_taskmgr_create");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = isc_task_create(taskmgr, 0, &global_task);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = isc_timermgr_create(mctx, &timermgr);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington check_result(result, "isc_timermgr_create");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = isc_socketmgr_create(mctx, &socketmgr);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington check_result(result, "isc_socketmgr_create");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington check_result(result, "isc_entropy_create");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonadd_opt(dns_message_t *msg, isc_uint16_t udpsize) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_message_gettemprdataset(msg, &rdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington check_result(result, "dns_message_gettemprdataset");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_message_gettemprdatalist(msg, &rdatalist);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington check_result(result, "dns_message_gettemprdatalist");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_message_gettemprdata(msg, &rdata);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington check_result(result, "dns_message_gettemprdata");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ISC_LIST_APPEND(rdatalist->rdata, rdata, link);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdatalist_tordataset(rdatalist, rdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_message_setopt(msg, rdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington check_result(result, "dns_message_setopt");
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonadd_question(dns_message_t *message, dns_name_t *name,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdataclass_t rdclass, dns_rdatatype_t rdtype)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_message_gettemprdataset(message, &rdataset);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington check_result(result, "dns_message_gettemprdataset()");
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dns_rdataset_makequestion(rdataset, rdclass, rdtype);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington ISC_LIST_APPEND(name->list, rdataset, link);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Return ISC_TRUE if we're in the process of shutting down on the
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington debug("lookup %s pending", lookup->pending ? "is" : "is not");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonfollowup_lookup(dns_message_t *msg, dig_query_t *query,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_message_firstname(msg,section);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington (query->lookup->trace || query->lookup->ns_search_only))
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington followup_lookup (msg, query, DNS_SECTION_AUTHORITY);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington debug("following up %s", query->lookup->textname);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_message_currentname(msg, section, &name);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset = ISC_LIST_NEXT(rdataset, link)) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "isc_buffer_allocate");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "dns_rdata_totext");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /* Initialize lookup if we've not yet */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington sizeof(struct dig_server));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "failure in %s:%d",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_message_nextname (msg, section);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if ((lookup == NULL) && (section == DNS_SECTION_ANSWER) &&
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington (query->lookup->trace || query->lookup->ns_search_only))
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington followup_lookup(msg, query, DNS_SECTION_AUTHORITY);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonnext_origin(dns_message_t *msg, dig_query_t *query) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington debug("following up %s", query->lookup->textname);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Then we just did rootorg; there's nothing left.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington debug("made it to the root with nowhere to go");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup = requeue_lookup(query->lookup, ISC_TRUE);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup->origin = ISC_LIST_NEXT(query->lookup->origin, link);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_init(&lookup->rdatabuf, lookup->rdatastore,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_message_gettemprdata(lookup->sendmsg, &rdata);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington check_result(result, "dns_message_gettemprdata");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_rdata_fromstruct(rdata, dns_rdataclass_in,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington check_result(result, "isc_rdata_fromstruct");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_message_gettemprdatalist(lookup->sendmsg, &rdatalist);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington check_result(result, "dns_message_gettemprdatalist");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_message_gettemprdataset(lookup->sendmsg, &rdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington check_result(result, "dns_message_gettemprdataset");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ISC_LIST_APPEND(rdatalist->rdata, rdata, link);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdatalist_tordataset(rdatalist, rdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_message_gettempname(lookup->sendmsg, &soaname);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington check_result(result, "dns_message_gettempname");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ISC_LIST_APPEND(soaname->list, rdataset, link);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_message_addname(lookup->sendmsg, soaname, DNS_SECTION_AUTHORITY);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington debug("setting up for looking up %s @%p->%p",
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington result = dns_message_create(mctx, DNS_MESSAGE_INTENTRENDER,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington check_result(result, "dns_message_create");
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington result = dns_message_gettempname(lookup->sendmsg, &lookup->name);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington check_result(result, "dns_message_gettempname");
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington isc_buffer_init(&lookup->namebuf, lookup->namespace,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington isc_buffer_init(&lookup->onamebuf, lookup->onamespace,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if ((count_dots(lookup->textname) >= ndots) || lookup->defname)
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington lookup->origin = NULL; /* Force root lookup */
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington debug("lookup->origin = %p", lookup->origin);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington debug("trying origin %s", lookup->origin->origin);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington result = dns_message_gettempname(lookup->sendmsg,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington check_result(result, "dns_message_gettempname");
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington isc_buffer_init(&b, lookup->origin->origin, len);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington result = dns_name_fromtext(lookup->oname, &b, dns_rootname,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington fatal("%s is not a legal name syntax (%s)",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_init(&b, lookup->textname, len);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_name_fromtext(lookup->name, &b,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_name_clone(dns_rootname, lookup->name);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington fatal("%s is not a legal name syntax (%s)",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup->textname, dns_result_totext(result));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_message_puttempname(lookup->sendmsg, &lookup->oname);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_init(&b, lookup->textname, len);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_name_fromtext(lookup->name, &b,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_name_clone(dns_rootname, lookup->name);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington res2 = dns_name_totext(dns_rootname, ISC_FALSE, &b);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington fatal("%s/%.*s is not a legal name syntax "
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington (char *)r.base, dns_result_totext(result));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_name_totext(lookup->name, ISC_FALSE, &b);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington trying((int)r.length, (char *)r.base, lookup);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup->sendmsg->id = (unsigned short)(random() & 0xFFFF);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup->sendmsg->opcode = dns_opcode_query;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * If this is a trace request, completely disallow recursion, since
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * it's meaningless for traces.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (lookup->recurse && !lookup->trace && !lookup->ns_search_only) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup->sendmsg->flags |= DNS_MESSAGEFLAG_RD;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup->sendmsg->flags |= DNS_MESSAGEFLAG_AA;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup->sendmsg->flags |= DNS_MESSAGEFLAG_AD;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup->sendmsg->flags |= DNS_MESSAGEFLAG_CD;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_message_addname(lookup->sendmsg, lookup->name,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_rdatatype_fromtext(&rdtype, (isc_textregion_t *)&tr);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington check_result(result, "dns_rdatatype_fromtext");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Force TCP mode if we're doing an xfr.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_rdataclass_fromtext(&rdclass, (isc_textregion_t *)&tr);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington check_result(result, "dns_rdataclass_fromtext");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington add_question(lookup->sendmsg, lookup->name, rdclass, rdtype);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_message_settsigkey(lookup->sendmsg, key);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington check_result(result, "dns_message_settsigkey");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_init(&lookup->sendbuf, lookup->sendspace, COMMSIZE);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_message_renderbegin(lookup->sendmsg, &lookup->sendbuf);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington check_result(result, "dns_message_renderbegin");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_message_rendersection(lookup->sendmsg,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington check_result(result, "dns_message_rendersection");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_message_rendersection(lookup->sendmsg,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington check_result(result, "dns_message_rendersection");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_message_renderend(lookup->sendmsg);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington check_result(result, "dns_message_renderend");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington serv = ISC_LIST_HEAD(lookup->my_server_list);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington query = isc_mem_allocate(mctx, sizeof(dig_query_t));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington fatal("Memory allocation failure in %s:%d",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington debug("create query %p linked to lookup %p",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_init(&query->recvbuf, query->recvspace, COMMSIZE);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_init(&query->lengthbuf, query->lengthspace, 2);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_init(&query->slbuf, query->slspace, 2);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington printmessage(ISC_LIST_HEAD(lookup->q), lookup->sendmsg,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonsend_done(isc_task_t *task, isc_event_t *event) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Return ISC_TRUE if we're in the process of shutting down
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_socket_cancel(query->sock, global_task,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonrecv_done(isc_task_t *task, isc_event_t *event);
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellingtonconnect_timeout(isc_task_t *task, isc_event_t *event);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington debug ("have local timeout of %d", local_timeout);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_interval_set(&lookup->interval, local_timeout, 0);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = isc_timer_create(timermgr, isc_timertype_once, NULL,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ISC_LIST_ENQUEUE(query->recvlist, &query->recvbuf, link);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington debug("recving with lookup=%p, query=%p, sock=%p",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = isc_socket_recvv(query->sock, &query->recvlist, 1,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ISC_LIST_ENQUEUE(query->sendlist, &lookup->sendbuf, link);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = isc_socket_sendtov(query->sock, &query->sendlist,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington check_result(result, "isc_socket_sendtov");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * connect_timeout is used for both UDP recieves and TCP connects.
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonconnect_timeout(isc_task_t *task, isc_event_t *event) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington REQUIRE(event->ev_type == ISC_TIMEREVENT_IDLE);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington result = isc_buffer_allocate(mctx, &b, 256);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington check_result(result, "isc_buffer_allocate");
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington result = isc_sockaddr_totext(&q->sockaddr, b);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington check_result(result, "isc_sockaddr_totext");
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington "for %s timed out. "
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington "Retrying %d.\n",
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington "server %.*s "
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington "for %s timed out. "
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington "Giving up.\n",
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtontcp_length_done(isc_task_t *task, isc_event_t *event) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington REQUIRE(event->ev_type == ISC_SOCKEVENT_RECVDONE);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington result = isc_buffer_allocate(mctx, &b, 256);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington check_result(result, "isc_buffer_allocate");
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington result = isc_sockaddr_totext(&query->sockaddr, b);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington check_result(result, "isc_sockaddr_totext");
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington printf("%.*s: %s\n", (int)r.length, r.base,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ISC_LIST_DEQUEUE(sevent->bufferlist, &query->lengthbuf, link);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington fatal("Length of %X was longer than I can handle!",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Even though the buffer was already init'ed, we need
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * to redo it now, to force the length we want.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_init(&query->recvbuf, query->recvspace, length);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ISC_LIST_ENQUEUE(query->recvlist, &query->recvbuf, link);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = isc_socket_recvv(query->sock, &query->recvlist, length, task,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington debug("resubmitted recv request with length %d", length);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonlaunch_next_query(dig_query_t *query, isc_boolean_t include_question) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington debug("ignoring launch_next_query because !pending");
if (include_question) {
link);
sendcount++;
isc_region_t r;
if (free_now) {
isc_buffer_usedregion(b, &r);
isc_buffer_free(&b);
static isc_boolean_t
return (ISC_TRUE);
return (ISC_FALSE);
static isc_boolean_t
isc_buffer_t b;
isc_region_t r;
return (ISC_TRUE);
#ifdef NEVER
&name);
return (ISC_TRUE);
goto next_rdata;
&soa,
mctx);
goto xfr_done;
goto next_rdata;
goto next_rdata;
isc_buffer_usedregion(&b, &r);
return (ISC_TRUE);
goto next_rdata;
goto xfr_done;
return (ISC_FALSE);
isc_region_t r;
dig_lookup_t *n;
unsigned int local_timeout;
if (free_now) {
if (free_now) {
sendcount--;
&msg);
hex_dump(b);
if (timeout == 0) {
local_timeout, 0);
NULL,
if ((show_details ||
== ISC_R_SUCCESS))) &&
if (show_details) {
== ISC_R_SUCCESS) &&
if (docancel) {
&ab);
== ISC_R_SUCCESS) ||
(char *)r.base,
query);
int result;
if (result != 0) {
port);
unsigned int local_timeout;
if (timeout == 0) {
sockcount++;
if (specified_source)
sockcount++;
if (specified_source)
start_lookup(void) {
if (free_now)
start_lookup();
free_lists(void) {
void *ptr;
dig_lookup_t *l;
dig_query_t *q;
dig_server_t *s;
dig_searchlist_t *o;
if (free_now)
while (l != NULL) {
q = ISC_LIST_HEAD(l->q);
while (q != NULL) {
sockcount--;
while (s != NULL) {
ptr = s;
while (o != NULL) {
ptr = o;
while (l != NULL) {
q = ISC_LIST_HEAD(l->q);
while (q != NULL) {
link);
link);
ptr = q;
if (l->use_my_server_list) {
while (s != NULL) {
ptr = s;
ptr = l;
if (is_dst_up) {