dighost.c revision 00d527364a76b17e9202e1f62e714e8cd33fe933
8e5fce1f9ceba17dd7e3ff0eb287e1e999c14249Mark Andrews * Copyright (C) 2000 Internet Software Consortium.
ec5347e2c775f027573ce5648b910361aa926c01Automatic Updater * Permission to use, copy, modify, and distribute this software for any
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * purpose with or without fee is hereby granted, provided that the above
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * copyright notice and this permission notice appear in all copies.
0c865fa57d3b9b072c2878b09fad17c732be2eb9Mark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
0c865fa57d3b9b072c2878b09fad17c732be2eb9Mark Andrews * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
0c865fa57d3b9b072c2878b09fad17c732be2eb9Mark Andrews * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
0c865fa57d3b9b072c2878b09fad17c732be2eb9Mark Andrews * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
0c865fa57d3b9b072c2878b09fad17c732be2eb9Mark Andrews * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
0c865fa57d3b9b072c2878b09fad17c732be2eb9Mark Andrews * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
0c865fa57d3b9b072c2878b09fad17c732be2eb9Mark Andrews * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉/* $Id: dighost.c,v 1.110 2000/08/02 22:39:01 gson Exp $ */
5597be9bb88de138dfec9fa9176708443813925eTatuya JINMEI 神明達哉 * Notice to programmers: Do not use this code as an example of how to
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * use the ISC library to perform DNS lookups. Dig and Host both operate
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * on the request level, since they allow fine-tuning of output and are
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * intended as debugging tools. As a result, they perform many of the
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * functions which could be better handled using the dns_resolver
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * functions in most applications.
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉#if (!(defined(HAVE_ADDRINFO) && defined(HAVE_GETADDRINFO)))
5597be9bb88de138dfec9fa9176708443813925eTatuya JINMEI 神明達哉unsigned int timeout = 0;
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * Apply and clear locks at the event level in global task.
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * Can I get rid of these using shutdown events? XXX
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 debug("lock_lookup %s:%d", __FILE__, __LINE__);\
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 check_result(isc_mutex_lock((&lookup_lock)), "isc_mutex_lock");\
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 debug("unlock_lookup %s:%d", __FILE__, __LINE__);\
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 check_result(isc_mutex_unlock((&lookup_lock)),\
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 "isc_mutex_unlock");\
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉recv_done(isc_task_t *task, isc_event_t *event);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉connect_timeout(isc_task_t *task, isc_event_t *event);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 while (*s != '\0') {
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 if (*s == '.')
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 printf("Printing a buffer with length %d\n", r.length);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉check_result(isc_result_t result, const char *msg) {
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 fatal("%s: %s", msg, isc_result_totext(result));
0d8971a4b8abed599ec9d9b7d1b51b8de8038ce2Shane Kerr * Create a server structure, which is part of the lookup structure.
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * This is little more than a linked list of servers to query in hopes
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * of finding the answer the user is looking for
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 srv = isc_mem_allocate(mctx, sizeof(struct dig_server));
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 fatal("Memory allocation failure in %s:%d",
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 strncpy(srv->servername, servname, MXNAME);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * Produce a cloned server list. The dest list must have already had
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * ISC_LIST_INIT applied.
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * Create an empty lookup structure, which holds all the information needed
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * to get an answer to a user's question. This structure contains two
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * linked lists: the server list (servers to query) and the query list
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * (outstanding queries which have been made to the listed servers).
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 looknew = isc_mem_allocate(mctx, sizeof(struct dig_lookup));
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 fatal("Memory allocation failure in %s:%d",
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * Clone a lookup, perhaps copying the server list. This does not clone
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * the query list, since it will be regenerated by the setup_lookup()
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * function, nor does it queue up the new lookup for processing.
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * Caution: If you don't clone the servers, you MUST clone the server
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * list seperately from somewhere else, or construct it by hand.
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉clone_lookup(dig_lookup_t *lookold, isc_boolean_t servers) {
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 strncpy(looknew->textname, lookold-> textname, MXNAME);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 looknew->ixfr_serial = lookold->ixfr_serial;
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 looknew->trace_root = lookold->trace_root;
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 looknew->ns_search_only = lookold->ns_search_only;
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 looknew->section_question = lookold->section_question;
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 looknew->section_answer = lookold->section_answer;
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 looknew->section_authority = lookold->section_authority;
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 looknew->section_additional = lookold->section_additional;
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 clone_server_list(lookold->my_server_list,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * Requeue a lookup for further processing, perhaps copying the server
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * list. The new lookup structure is returned to the caller, and is
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * queued for processing. If servers are not cloned in the requeue, they
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * must be added before allowing the current event to complete, since the
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * completion of the event may result in the next entry on the lookup
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * queue getting run.
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉requeue_lookup(dig_lookup_t *lookold, isc_boolean_t servers) {
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 looknew = clone_lookup(lookold, servers);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 "-> %p, new@%p -> %p",
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 lookold, lookold->link.next, looknew, looknew->link.next);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 ISC_LIST_PREPEND(lookup_list, looknew, link);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 "%p, new = %p, new -> %p",
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 result = isc_buffer_allocate(mctx, &namebuf, MXNAME);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 check_result(result, "isc_buffer_allocate");
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 secretstore = isc_mem_allocate(mctx, secretsize);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 fatal("Memory allocation failure in %s:%d",
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 isc_buffer_init(&secretbuf, secretstore, secretsize);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 result = isc_base64_decodestring(mctx, keysecret,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 printf(";; Couldn't create key %s: %s\n",
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 secretsize = isc_buffer_usedlength(&secretbuf);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 result = dns_name_fromtext(&keyname, namebuf,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 printf(";; Couldn't create key %s: %s\n",
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 result = dns_tsigkey_create(&keyname, dns_tsig_hmacmd5_name,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 printf(";; Couldn't create key %s: %s\n",
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 result = dst_key_fromnamedfile(keyfile, DST_TYPE_PRIVATE,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 fprintf(stderr, "Couldn't read key from %s: %s\n",
9a6522317c97e5487cea816173f63a0e5b4e428aTatuya JINMEI 神明達哉 * Get key size in bits, convert to bytes, rounding up (?)
9a6522317c97e5487cea816173f63a0e5b4e428aTatuya JINMEI 神明達哉 secretlen = (dst_key_size(dstkey) + 7) >> 3;
9a6522317c97e5487cea816173f63a0e5b4e428aTatuya JINMEI 神明達哉 secretstore = isc_mem_allocate(mctx, secretlen);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 isc_buffer_init(&secretbuf, secretstore, secretlen);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 result = dst_key_tobuffer(dstkey, &secretbuf);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 fprintf(stderr, "Couldn't read key from %s: %s\n",
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 dns_name_clone(dst_key_name(dstkey), &keyname);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 result = dns_tsigkey_create(&keyname, dns_tsig_hmacmd5_name,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 printf(";; Couldn't create key %s: %s\n",
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * Setup the system as a whole, reading key information and resolv.conf
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 debug("using fixed domain %s", fixeddomain);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 search = isc_mem_allocate(mctx, sizeof(struct dig_server));
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 fatal("Memory allocation failure in %s:%d",
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 /* XXX Check ordering, with search -vs- domain */
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 ISC_LIST_PREPEND(search_list, search, link);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 get_servers = ISC_TF(server_list.head == NULL);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 /* XXX Use lwres resolv.conf reader */
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 while (fgets(rcinput, MXNAME, fp) != 0) {
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 } else if (strcasecmp(ptr, "options") == 0) {
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 } else if (strcasecmp(ptr, "search") == 0){
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 mctx, sizeof(struct
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 "failure in %s:"
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 } else if ((strcasecmp(ptr, "domain") == 0) &&
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 mctx, sizeof(struct
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 "failure in %s:"
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 else if (keysecret[0] != 0)
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * Setup the ISC and DNS libraries for use by the system.
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * Warning: This is not particularly good randomness. We'll
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * just use random() now for getting id values, but doing so
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * does NOT insure that id's cann't be guessed.
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 check_result(result, "isc_net_probeipv4");
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 result = isc_taskmgr_create(mctx, 1, 0, &taskmgr);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 check_result(result, "isc_taskmgr_create");
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 result = isc_task_create(taskmgr, 0, &global_task);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 result = isc_timermgr_create(mctx, &timermgr);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 check_result(result, "isc_timermgr_create");
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 result = isc_socketmgr_create(mctx, &socketmgr);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 check_result(result, "isc_socketmgr_create");
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 result = isc_entropy_create(mctx, &entp);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 check_result(result, "isc_entropy_create");
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 result = isc_mempool_create(mctx, COMMSIZE, &commctx);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 check_result(result, "isc_mempool_create");
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 isc_mempool_setname(commctx, "COMMPOOL");
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * 6 and 2 set as reasonable parameters for 3 or 4 nameserver
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * Add EDNS0 option record to a message. Currently, the only supported
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * option is UDP buffer size.
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉add_opt(dns_message_t *msg, isc_uint16_t udpsize) {
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 result = dns_message_gettemprdataset(msg, &rdataset);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 check_result(result, "dns_message_gettemprdataset");
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 result = dns_message_gettemprdatalist(msg, &rdatalist);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 check_result(result, "dns_message_gettemprdatalist");
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 result = dns_message_gettemprdata(msg, &rdata);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater check_result(result, "dns_message_gettemprdata");
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 debug("setting udp size of %d", udpsize);
0d8971a4b8abed599ec9d9b7d1b51b8de8038ce2Shane Kerr * Add a question section to a message, asking for the specified name,
0d8971a4b8abed599ec9d9b7d1b51b8de8038ce2Shane Kerr * type, and class.
0d8971a4b8abed599ec9d9b7d1b51b8de8038ce2Shane Kerradd_question(dns_message_t *message, dns_name_t *name,
0d8971a4b8abed599ec9d9b7d1b51b8de8038ce2Shane Kerr dns_rdataclass_t rdclass, dns_rdatatype_t rdtype)
602784c4ceb4f36f614afe5da80c7964eb9a766cShane Kerr result = dns_message_gettemprdataset(message, &rdataset);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 check_result(result, "dns_message_gettemprdataset()");
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 dns_rdataset_makequestion(rdataset, rdclass, rdtype);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 ISC_LIST_APPEND(name->list, rdataset, link);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * Check if we're done with all the queued lookups, which is true iff
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * all sockets, sends, and recvs are accounted for (counters == 0),
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * and the lookup list is empty.
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * If we are done, pass control back out to dighost_shutdown() (which is
0d8971a4b8abed599ec9d9b7d1b51b8de8038ce2Shane Kerr * part of dig.c, host.c, or nslookup.c) to either shutdown the system as
0d8971a4b8abed599ec9d9b7d1b51b8de8038ce2Shane Kerr * a whole or reseed the lookup list.
0d8971a4b8abed599ec9d9b7d1b51b8de8038ce2Shane Kerr debug("list %s", ISC_LIST_EMPTY(lookup_list) ? "empty" : "full");
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 if (ISC_LIST_EMPTY(lookup_list) && current_lookup == NULL) {
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * Clear out a query when we're done with it. WARNING: This routine
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * WILL invalidate the query pointer.
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 if (ISC_LINK_LINKED(&query->recvbuf, link))
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 ISC_LIST_DEQUEUE(query->recvlist, &query->recvbuf,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 if (ISC_LINK_LINKED(&query->lengthbuf, link))
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 ISC_LIST_DEQUEUE(query->lengthlist, &query->lengthbuf,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 isc_mempool_put(commctx, query->recvspace);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 isc_buffer_invalidate(&query->lengthbuf);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * Try and clear out a lookup if we're done with it. Return ISC_TRUE if
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * the lookup was successfully cleared. If ISC_TRUE is returned, the
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * lookup pointer has been invalidated.
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 while (q != NULL) {
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * At this point, we know there are no queries on the lookup,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * so can make it go away also.
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 s = ISC_LIST_HEAD(lookup->my_server_list);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 while (s != NULL) {
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 debug("freeing server %p belonging to %p",
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 debug("freeing buffer %p", lookup->querysig);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 isc_mempool_put(commctx, lookup->sendspace);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * If we can, start the next lookup in the queue running.
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * This assumes that the lookup on the head of the queue hasn't been
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * started yet. It also removes the lookup from the head of the queue,
602784c4ceb4f36f614afe5da80c7964eb9a766cShane Kerr * setting the current_lookup pointer pointing to it.
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * If there's a current lookup running, we really shouldn't get
9a6522317c97e5487cea816173f63a0e5b4e428aTatuya JINMEI 神明達哉 current_lookup = ISC_LIST_HEAD(lookup_list);
602784c4ceb4f36f614afe5da80c7964eb9a766cShane Kerr * Put the current lookup somewhere so cancel_all can find it
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 ISC_LIST_DEQUEUE(lookup_list, current_lookup, link);
9a6522317c97e5487cea816173f63a0e5b4e428aTatuya JINMEI 神明達哉 * If we can, clear the current lookup and start the next one running.
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * This calls try_clear_lookup, so may invalidate the lookup pointer.
602784c4ceb4f36f614afe5da80c7964eb9a766cShane Kerr * Create and queue a new lookup as a followup to the current lookup,
602784c4ceb4f36f614afe5da80c7964eb9a766cShane Kerr * based on the supplied message and section. This is used in trace and
602784c4ceb4f36f614afe5da80c7964eb9a766cShane Kerr * name server search modes to start a new lookup using servers from
ff5ac6d4213e3e2f3f6a93db8c5e65cc170a7e2bEvan Hunt * NS records in a reply.
602784c4ceb4f36f614afe5da80c7964eb9a766cShane Kerrfollowup_lookup(dns_message_t *msg, dig_query_t *query,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 (query->lookup->trace || query->lookup->ns_search_only))
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 followup_lookup(msg, query, DNS_SECTION_AUTHORITY);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 debug("following up %s", query->lookup->textname);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 dns_message_currentname(msg, section, &name);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 for (rdataset = ISC_LIST_HEAD(name->list);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 rdataset = ISC_LIST_NEXT(rdataset, link)) {
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 loopresult = dns_rdataset_first(rdataset);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 "isc_buffer_allocate");
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 "dns_rdata_totext");
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 /* Initialize lookup if we've not yet */
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 if ((lookup == NULL) && (section == DNS_SECTION_ANSWER) &&
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 (query->lookup->trace || query->lookup->ns_search_only))
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 followup_lookup(msg, query, DNS_SECTION_AUTHORITY);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * Create and queue a new lookup using the next origin from the origin
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * list, read in setup_system().
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉next_origin(dns_message_t *msg, dig_query_t *query) {
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 debug("following up %s", query->lookup->textname);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * We're not using a search list, so don't even think
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * about finding the next entry.
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * Then we just did rootorg; there's nothing left.
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 lookup = requeue_lookup(query->lookup, ISC_TRUE);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 lookup->origin = ISC_LIST_NEXT(query->lookup->origin, link);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * Insert an SOA record into the sendmessage in a lookup. Used for
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * creating IXFR queries.
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 dns_name_clone(lookup->name, &soa.origin);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 dns_name_clone(lookup->name, &soa.mname);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 isc_buffer_init(&lookup->rdatabuf, lookup->rdatastore,
18d0b5e54be891a1aa938c165b6d439859121ec8Mark Andrews result = dns_message_gettemprdata(lookup->sendmsg, &rdata);
18d0b5e54be891a1aa938c165b6d439859121ec8Mark Andrews check_result(result, "dns_message_gettemprdata");
18d0b5e54be891a1aa938c165b6d439859121ec8Mark Andrews result = dns_rdata_fromstruct(rdata, lookup->rdclass,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 check_result(result, "isc_rdata_fromstruct");
18d0b5e54be891a1aa938c165b6d439859121ec8Mark Andrews result = dns_message_gettemprdatalist(lookup->sendmsg, &rdatalist);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 check_result(result, "dns_message_gettemprdatalist");
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 result = dns_message_gettemprdataset(lookup->sendmsg, &rdataset);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 check_result(result, "dns_message_gettemprdataset");
9a6522317c97e5487cea816173f63a0e5b4e428aTatuya JINMEI 神明達哉 ISC_LIST_APPEND(rdatalist->rdata, rdata, link);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 dns_rdatalist_tordataset(rdatalist, rdataset);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 result = dns_message_gettempname(lookup->sendmsg, &soaname);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 check_result(result, "dns_message_gettempname");
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 ISC_LIST_APPEND(soaname->list, rdataset, link);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 dns_message_addname(lookup->sendmsg, soaname, DNS_SECTION_AUTHORITY);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * Setup the supplied lookup structure, making it ready to start sending
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * queries to servers. Create and initialize the message to be sent as
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * well as the query structures and buffer space for the replies. If the
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * server list is empty, clone it from the system default list.
9a6522317c97e5487cea816173f63a0e5b4e428aTatuya JINMEI 神明達哉 result = dns_message_create(mctx, DNS_MESSAGE_INTENTRENDER,
9a6522317c97e5487cea816173f63a0e5b4e428aTatuya JINMEI 神明達哉 check_result(result, "dns_message_create");
0d8971a4b8abed599ec9d9b7d1b51b8de8038ce2Shane Kerr clone_server_list(server_list, &lookup->my_server_list);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 result = dns_message_gettempname(lookup->sendmsg, &lookup->name);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 check_result(result, "dns_message_gettempname");
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 isc_buffer_init(&lookup->namebuf, lookup->namespace,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 isc_buffer_init(&lookup->onamebuf, lookup->onamespace,
9a6522317c97e5487cea816173f63a0e5b4e428aTatuya JINMEI 神明達哉 * If the name has too many dots, force the origin to be NULL
9a6522317c97e5487cea816173f63a0e5b4e428aTatuya JINMEI 神明達哉 * (which produces an absolute lookup). Otherwise, take the origin
9a6522317c97e5487cea816173f63a0e5b4e428aTatuya JINMEI 神明達哉 * we have if there's one in the struct already. If it's NULL,
9a6522317c97e5487cea816173f63a0e5b4e428aTatuya JINMEI 神明達哉 * take the first entry in the searchlist iff either usesearch
9a6522317c97e5487cea816173f63a0e5b4e428aTatuya JINMEI 神明達哉 * is TRUE or we got a domain line in the resolv.conf file.
9a6522317c97e5487cea816173f63a0e5b4e428aTatuya JINMEI 神明達哉 /* XXX New search here? */
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 if ((count_dots(lookup->textname) >= ndots) || lookup->defname)
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 lookup->origin = NULL; /* Force abs lookup */
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 else if (lookup->origin == NULL && lookup->new_search &&
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 lookup->origin = ISC_LIST_HEAD(search_list);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 debug("trying origin %s", lookup->origin->origin);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 result = dns_message_gettempname(lookup->sendmsg,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 check_result(result, "dns_message_gettempname");
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 /* XXX Helper funct to conv char* to name? */
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 isc_buffer_init(&b, lookup->origin->origin, len);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 result = dns_name_fromtext(lookup->oname, &b, dns_rootname,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 dns_name_clone(dns_rootname, lookup->name);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 isc_buffer_init(&b, lookup->textname, len);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 result = dns_name_fromtext(lookup->name, &b,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 fatal("'%s' is not in legal name syntax (%s)",
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 lookup->textname, dns_result_totext(result));
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 dns_message_puttempname(lookup->sendmsg, &lookup->oname);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 isc_buffer_init(&b, lookup->textname, len);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 result = dns_name_fromtext(lookup->name, &b,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 dns_name_clone(dns_rootname, lookup->name);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 isc_buffer_init(&b, store, sizeof(store));
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 /* XXX Move some of this into function, dns_name_format. */
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 dns_name_totext(lookup->name, ISC_FALSE, &b);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 trying((int)r.length, (char *)r.base, lookup);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 INSIST(dns_name_isabsolute(lookup->name));
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 lookup->sendmsg->id = (unsigned short)(random() & 0xFFFF);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 lookup->sendmsg->opcode = dns_opcode_query;
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * If this is a trace request, completely disallow recursion, since
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * it's meaningless for traces.
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 if (lookup->recurse && !lookup->trace && !lookup->ns_search_only) {
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 lookup->sendmsg->flags |= DNS_MESSAGEFLAG_RD;
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 /* XXX aaflag */
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 lookup->sendmsg->flags |= DNS_MESSAGEFLAG_AA;
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 lookup->sendmsg->flags |= DNS_MESSAGEFLAG_AD;
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 lookup->sendmsg->flags |= DNS_MESSAGEFLAG_CD;
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 dns_message_addname(lookup->sendmsg, lookup->name,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 if ((lookup->rdtype == dns_rdatatype_axfr) ||
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 (lookup->rdtype == dns_rdatatype_ixfr)) {
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * Force TCP mode if we're doing an xfr.
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * XXX UDP ixfr's would be useful
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 add_question(lookup->sendmsg, lookup->name, lookup->rdclass,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 /* XXX add_soa */
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 if (lookup->rdtype == dns_rdatatype_ixfr)
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 /* XXX Insist this? */
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 result = dns_message_settsigkey(lookup->sendmsg, key);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 check_result(result, "dns_message_settsigkey");
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 lookup->sendspace = isc_mempool_get(commctx);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 isc_buffer_init(&lookup->sendbuf, lookup->sendspace, COMMSIZE);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 result = dns_message_renderbegin(lookup->sendmsg, &lookup->sendbuf);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 check_result(result, "dns_message_renderbegin");
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 add_opt(lookup->sendmsg, lookup->udpsize);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 result = dns_message_rendersection(lookup->sendmsg,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 check_result(result, "dns_message_rendersection");
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 result = dns_message_rendersection(lookup->sendmsg,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 check_result(result, "dns_message_rendersection");
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 result = dns_message_renderend(lookup->sendmsg);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 check_result(result, "dns_message_renderend");
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 /* XXX Insist? */
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 for (serv = ISC_LIST_HEAD(lookup->my_server_list);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 query = isc_mem_allocate(mctx, sizeof(dig_query_t));
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 fatal("Memory allocation failure in %s:%d",
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 debug("create query %p linked to lookup %p",
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 query->recvspace = isc_mempool_get(commctx);
9a6522317c97e5487cea816173f63a0e5b4e428aTatuya JINMEI 神明達哉 isc_buffer_init(&query->recvbuf, query->recvspace, COMMSIZE);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 isc_buffer_init(&query->lengthbuf, query->lengthspace, 2);
24875d713b228dd51e542c71e75ac9fa2f982e0eMark Andrews isc_buffer_init(&query->slbuf, query->slspace, 2);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 ISC_LIST_ENQUEUE(lookup->q, query, link);
9a6522317c97e5487cea816173f63a0e5b4e428aTatuya JINMEI 神明達哉 /* XXX qrflag, print_query, etc... */
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 printmessage(ISC_LIST_HEAD(lookup->q), lookup->sendmsg,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * Event handler for send completion. Track send counter, and clear out
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * the query if the send was canceled.
9a6522317c97e5487cea816173f63a0e5b4e428aTatuya JINMEI 神明達哉send_done(isc_task_t *_task, isc_event_t *event) {
9a6522317c97e5487cea816173f63a0e5b4e428aTatuya JINMEI 神明達哉 REQUIRE(event->ev_type == ISC_SOCKEVENT_SENDDONE);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * Cancel a lookup, sending isc_socket_cancel() requests to all outstanding
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * IO sockets. The cancel handlers should take care of cleaning up the
0d8971a4b8abed599ec9d9b7d1b51b8de8038ce2Shane Kerr * query and lookup structures
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 isc_socket_cancel(query->sock, global_task,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Send a UDP packet to the remote nameserver, possible starting the
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * recv action as well. Also make sure that the timer is running and
1e844d04a716346f08ec027e365ce43e7b360c51Shane Kerr * is properly reset.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updatersend_udp(dig_lookup_t *lookup, isc_boolean_t make_recv) {
1e844d04a716346f08ec027e365ce43e7b360c51Shane Kerr * If the timer already exists, that means we're calling this
0d8971a4b8abed599ec9d9b7d1b51b8de8038ce2Shane Kerr * a second time (for a retry). Don't need to recreate it,
1e844d04a716346f08ec027e365ce43e7b360c51Shane Kerr * just reset it.
9a6522317c97e5487cea816173f63a0e5b4e428aTatuya JINMEI 神明達哉 debug("have local timeout of %d", local_timeout);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_interval_set(&lookup->interval, local_timeout, 0);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 check_result(result, "isc_timer_create");
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 result = isc_timer_reset(lookup->timer, isc_timertype_once,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 ISC_LIST_ENQUEUE(query->recvlist, &query->recvbuf,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 debug("recving with lookup=%p, query=%p, sock=%p",
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 check_result(result, "isc_socket_recvv");
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 ISC_LIST_ENQUEUE(query->sendlist, &lookup->sendbuf,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 result = isc_time_now(&query->time_sent);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 result = isc_socket_sendtov(query->sock, &query->sendlist,
9a6522317c97e5487cea816173f63a0e5b4e428aTatuya JINMEI 神明達哉 check_result(result, "isc_socket_sendtov");
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * IO timeout handler, used for both connect and recv timeouts. If
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * retries are still allowed, either resend the UDP packet or queue a
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * new TCP lookup. Otherwise, cancel the lookup.
9a6522317c97e5487cea816173f63a0e5b4e428aTatuya JINMEI 神明達哉connect_timeout(isc_task_t *task, isc_event_t *event) {
5597be9bb88de138dfec9fa9176708443813925eTatuya JINMEI 神明達哉 REQUIRE(event->ev_type == ISC_TIMEREVENT_IDLE);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 printf(";; connection timed out; no servers could be "
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * Event handler for the TCP recv which gets the length header of TCP
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * packets. Start the next recv of length bytes.
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉tcp_length_done(isc_task_t *task, isc_event_t *event) {
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 REQUIRE(event->ev_type == ISC_SOCKEVENT_RECVDONE);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 result = isc_buffer_allocate(mctx, &b, 256);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 check_result(result, "isc_buffer_allocate");
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 result = isc_sockaddr_totext(&query->sockaddr, b);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 check_result(result, "isc_sockaddr_totext");
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 printf(";; communications error to %.*s: %s\n",
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 ISC_LIST_DEQUEUE(sevent->bufferlist, &query->lengthbuf, link);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 fatal("Length of %X was longer than I can handle!",
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * Even though the buffer was already init'ed, we need
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * to redo it now, to force the length we want.
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 isc_buffer_init(&query->recvbuf, query->recvspace, length);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 ISC_LIST_ENQUEUE(query->recvlist, &query->recvbuf, link);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 debug("recving with lookup=%p, query=%p",
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 result = isc_socket_recvv(query->sock, &query->recvlist, length, task,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 check_result(result, "isc_socket_recvv");
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 debug("resubmitted recv request with length %d, recvcount=%d",
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * For transfers that involve multiple recvs (XFR's in particular),
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * launch the next recv.
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉launch_next_query(dig_query_t *query, isc_boolean_t include_question) {
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 debug("ignoring launch_next_query because !pending");
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 isc_buffer_putuint16(&query->slbuf, query->lookup->sendbuf.used);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 ISC_LIST_ENQUEUE(query->sendlist, &query->slbuf, link);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 ISC_LIST_ENQUEUE(query->sendlist, &query->lookup->sendbuf,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 ISC_LIST_ENQUEUE(query->lengthlist, &query->lengthbuf, link);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 result = isc_socket_recvv(query->sock, &query->lengthlist, 0,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 check_result(result, "isc_socket_recvv");
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 debug("sending a request in launch_next_query");
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 result = isc_time_now(&query->time_sent);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 result = isc_socket_sendv(query->sock, &query->sendlist,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 check_result(result, "isc_socket_sendv");
a1cc4108f61d1fd2a57810242b06dd929eaab4bdMark Andrews * Event handler for TCP connect complete. Make sure the connection was
a1cc4108f61d1fd2a57810242b06dd929eaab4bdMark Andrews * successful, then pass into launch_next_query to actually send the
0d8971a4b8abed599ec9d9b7d1b51b8de8038ce2Shane Kerrconnect_done(isc_task_t *task, isc_event_t *event) {
9a6522317c97e5487cea816173f63a0e5b4e428aTatuya JINMEI 神明達哉 REQUIRE(event->ev_type == ISC_SOCKEVENT_CONNECT);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 result = isc_buffer_allocate(mctx, &b, 256);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 check_result(result, "isc_buffer_allocate");
9a6522317c97e5487cea816173f63a0e5b4e428aTatuya JINMEI 神明達哉 result = isc_sockaddr_totext(&query->sockaddr, b);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 check_result(result, "isc_sockaddr_totext");
5183f9d9daa139cbf000c12709877f62e79dfb14Evan Hunt /* XXX isc_sockaddr_format */
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 printf(";; Connection to %.*s(%s) for %s failed: "
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 query->servname, query->lookup->textname,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 /* XXX Clean up exitcodes */
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * Check if the ongoing XFR needs more data before it's complete, using
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * the semantics of IXFR and AXFR protocols. Much of the complexity of
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * this routine comes from determining when an IXFR is complete.
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * ISC_FALSE means more data is on the way, and the recv has been issued.
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉check_for_more_data(dig_query_t *query, dns_message_t *msg,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * By the time we're in this routine, we know we're doing
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * either an AXFR or IXFR. If there's no second_rr_type,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * then we don't yet know which kind of answer we got back
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * from the server. Here, we're going to walk through the
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * rr's in the message, acting as necessary whenever we hit
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 result = dns_message_firstname(msg, DNS_SECTION_ANSWER);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 dns_message_currentname(msg, DNS_SECTION_ANSWER,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 for (rdataset = ISC_LIST_HEAD(name->list);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 rdataset = ISC_LIST_NEXT(rdataset, link)) {
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * If this is the first rr, make sure
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 "Didn't start with "
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 "SOA answer.");
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * If the record is anything except an SOA
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * now, just continue on...
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 /* Now we have an SOA. Work with it. */
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 "dns_rdata_tostruct");
goto xfr_done;
goto xfr_done;
goto next_rdata;
isc_buffer_usedregion(&b, &r);
if (atlimit) {
return (ISC_TRUE);
goto next_rdata;
goto xfr_done;
if (atlimit)
goto xfr_done;
return (ISC_FALSE);
isc_region_t r;
dig_lookup_t *n, *l;
unsigned int local_timeout;
recvcount--;
|| cancel_now) {
&msg);
l->sendmsg,
l->querysig);
if (l->msgcounter != 0)
l->msgcounter++;
hex_dump(b);
if (!l->tcp_mode) {
cancel_lookup(l);
l->querysig);
&l->querysig);
l->doing_xfr ) {
if (timeout == 0) {
if (l->tcp_mode)
local_timeout, 0);
NULL,
&l->interval,
if ((l->trace)||
(l->ns_search_only)) {
if (show_details ||
== ISC_R_SUCCESS)) &&
!l->trace_root))
ISC_TRUE);
MXNAME);
&ab);
(char *)r.base,
query);
l->trace_root)
ISC_TRUE);
&ab);
(char *)r.base,
query);
if (show_details) {
l->doing_xfr)
== ISC_R_SUCCESS) &&
l->ns_search_only &&
!l->trace_root ) {
if (l->pending)
if (l->doing_xfr) {
if (docancel) {
cancel_lookup(l);
&ab);
(char *)r.base,
query);
cancel_lookup(l);
sockcount--;
int result;
if (result != 0) {
port);
unsigned int local_timeout;
if (timeout == 0)
sockcount++;
if (specified_source)
sockcount++;
if (specified_source)
start_lookup();
cancel_all(void) {
dig_lookup_t *l, *n;
dig_query_t *q;
if (free_now) {
while (q != NULL) {
q, current_lookup);
while (l != NULL) {
try_clear_lookup(l);
destroy_libs(void) {
void *ptr;
dig_server_t *s;
dig_searchlist_t *o;
while (s != NULL) {
ptr = s;
while (o != NULL) {
ptr = o;
if (is_dst_up) {
if (isc_mem_debugging != 0)