2000-04-26 18:34:17 +00:00
|
|
|
/*
|
2001-01-09 22:01:04 +00:00
|
|
|
* Copyright (C) 2000, 2001 Internet Software Consortium.
|
2000-08-01 01:33:37 +00:00
|
|
|
*
|
2000-04-26 18:34:17 +00:00
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
2000-08-01 01:33:37 +00:00
|
|
|
*
|
2000-07-27 09:55:03 +00:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
|
|
|
|
* DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
|
|
|
|
* INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
|
|
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
|
|
|
|
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
|
|
|
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
2000-04-26 18:34:17 +00:00
|
|
|
*/
|
|
|
|
|
2001-07-22 18:06:40 +00:00
|
|
|
/* $Id: dighost.c,v 1.208 2001/07/22 18:06:40 bwelling Exp $ */
|
2000-06-06 18:49:06 +00:00
|
|
|
|
2000-05-08 22:51:08 +00:00
|
|
|
/*
|
|
|
|
* Notice to programmers: Do not use this code as an example of how to
|
|
|
|
* use the ISC library to perform DNS lookups. Dig and Host both operate
|
|
|
|
* on the request level, since they allow fine-tuning of output and are
|
|
|
|
* intended as debugging tools. As a result, they perform many of the
|
|
|
|
* functions which could be better handled using the dns_resolver
|
|
|
|
* functions in most applications.
|
|
|
|
*/
|
|
|
|
|
2000-04-26 18:34:17 +00:00
|
|
|
#include <config.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
2000-06-15 19:05:30 +00:00
|
|
|
#include <string.h>
|
2000-07-06 01:02:42 +00:00
|
|
|
#include <limits.h>
|
2000-04-26 18:34:17 +00:00
|
|
|
|
2000-10-23 23:13:21 +00:00
|
|
|
#include <dns/byaddr.h>
|
2000-10-11 17:44:18 +00:00
|
|
|
#include <dns/fixedname.h>
|
2000-04-26 18:34:17 +00:00
|
|
|
#include <dns/message.h>
|
2000-05-30 22:27:27 +00:00
|
|
|
#include <dns/name.h>
|
2000-12-02 04:44:51 +00:00
|
|
|
#ifdef DNS_OPT_NEWCODES
|
2000-10-11 17:44:18 +00:00
|
|
|
#include <dns/opt.h>
|
2000-12-02 04:44:51 +00:00
|
|
|
#endif /* DNS_OPT_NEWCODES */
|
2000-04-26 18:34:17 +00:00
|
|
|
#include <dns/rdata.h>
|
|
|
|
#include <dns/rdataclass.h>
|
2000-06-21 17:48:32 +00:00
|
|
|
#include <dns/rdatalist.h>
|
2000-05-08 14:38:29 +00:00
|
|
|
#include <dns/rdataset.h>
|
2000-06-21 17:48:32 +00:00
|
|
|
#include <dns/rdatastruct.h>
|
2000-04-26 18:34:17 +00:00
|
|
|
#include <dns/rdatatype.h>
|
|
|
|
#include <dns/result.h>
|
2000-06-06 00:43:17 +00:00
|
|
|
#include <dns/tsig.h>
|
2000-10-11 17:44:18 +00:00
|
|
|
|
2000-06-12 19:33:30 +00:00
|
|
|
#include <dst/dst.h>
|
2000-07-05 19:31:26 +00:00
|
|
|
|
2000-06-21 17:48:32 +00:00
|
|
|
#include <isc/app.h>
|
|
|
|
#include <isc/base64.h>
|
|
|
|
#include <isc/entropy.h>
|
|
|
|
#include <isc/lang.h>
|
2000-10-23 23:13:21 +00:00
|
|
|
#include <isc/netaddr.h>
|
2000-06-21 17:48:32 +00:00
|
|
|
#include <isc/netdb.h>
|
2000-11-20 13:02:18 +00:00
|
|
|
#include <isc/print.h>
|
2000-06-23 20:57:19 +00:00
|
|
|
#include <isc/result.h>
|
2000-06-21 17:48:32 +00:00
|
|
|
#include <isc/string.h>
|
|
|
|
#include <isc/task.h>
|
|
|
|
#include <isc/timer.h>
|
|
|
|
#include <isc/types.h>
|
|
|
|
#include <isc/util.h>
|
2000-06-12 19:33:30 +00:00
|
|
|
|
2000-04-26 18:34:17 +00:00
|
|
|
#include <dig/dig.h>
|
|
|
|
|
2001-01-18 22:21:31 +00:00
|
|
|
#ifdef HAVE_ADDRINFO
|
|
|
|
#ifdef HAVE_GETADDRINFO
|
|
|
|
#ifdef HAVE_GAISTRERROR
|
|
|
|
#define USE_GETADDRINFO
|
2001-07-22 06:03:06 +00:00
|
|
|
#define HAVE_H_ERRNO
|
2001-01-18 22:21:31 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2001-07-22 06:03:06 +00:00
|
|
|
#ifndef HAVE_H_ERRNO
|
|
|
|
#define HAVE_H_ERRNO
|
2001-01-18 22:21:31 +00:00
|
|
|
extern int h_errno;
|
|
|
|
#endif
|
|
|
|
|
2000-04-26 18:34:17 +00:00
|
|
|
ISC_LIST(dig_lookup_t) lookup_list;
|
2000-07-14 16:35:30 +00:00
|
|
|
dig_serverlist_t server_list;
|
2000-05-02 23:23:12 +00:00
|
|
|
ISC_LIST(dig_searchlist_t) search_list;
|
2000-04-26 18:34:17 +00:00
|
|
|
|
2000-07-05 19:31:26 +00:00
|
|
|
isc_boolean_t
|
2000-11-21 21:35:32 +00:00
|
|
|
have_ipv4 = ISC_FALSE,
|
2000-07-05 19:31:26 +00:00
|
|
|
have_ipv6 = ISC_FALSE,
|
|
|
|
specified_source = ISC_FALSE,
|
|
|
|
free_now = ISC_FALSE,
|
2000-07-14 17:57:27 +00:00
|
|
|
cancel_now = ISC_FALSE,
|
2000-07-05 19:31:26 +00:00
|
|
|
usesearch = ISC_FALSE,
|
|
|
|
qr = ISC_FALSE,
|
2001-01-18 05:12:44 +00:00
|
|
|
is_dst_up = ISC_FALSE;
|
2000-05-03 20:27:13 +00:00
|
|
|
in_port_t port = 53;
|
2000-07-10 17:25:59 +00:00
|
|
|
unsigned int timeout = 0;
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_mem_t *mctx = NULL;
|
|
|
|
isc_taskmgr_t *taskmgr = NULL;
|
2000-05-26 22:03:00 +00:00
|
|
|
isc_task_t *global_task = NULL;
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_timermgr_t *timermgr = NULL;
|
|
|
|
isc_socketmgr_t *socketmgr = NULL;
|
2000-05-19 17:54:04 +00:00
|
|
|
isc_sockaddr_t bind_address;
|
2000-06-08 21:18:24 +00:00
|
|
|
isc_sockaddr_t bind_any;
|
2000-04-26 18:34:17 +00:00
|
|
|
isc_buffer_t rootbuf;
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
int sendcount = 0;
|
2000-07-13 00:32:20 +00:00
|
|
|
int recvcount = 0;
|
2000-05-24 23:39:30 +00:00
|
|
|
int sockcount = 0;
|
2000-05-02 23:23:12 +00:00
|
|
|
int ndots = -1;
|
2000-07-18 01:28:20 +00:00
|
|
|
int tries = 2;
|
2000-05-06 01:16:07 +00:00
|
|
|
int lookup_counter = 0;
|
2001-01-18 05:12:44 +00:00
|
|
|
|
2000-08-03 17:43:06 +00:00
|
|
|
/*
|
|
|
|
* Exit Codes:
|
|
|
|
* 0 Everything went well, including things like NXDOMAIN
|
|
|
|
* 1 Usage error
|
|
|
|
* 7 Got too many RR's or Names
|
|
|
|
* 8 Couldn't open batch file
|
|
|
|
* 9 No reply from server
|
|
|
|
* 10 Internal error
|
|
|
|
*/
|
|
|
|
int exitcode = 0;
|
2000-06-06 00:43:17 +00:00
|
|
|
char keynametext[MXNAME];
|
2000-07-19 17:52:27 +00:00
|
|
|
char keyfile[MXNAME] = "";
|
2000-07-05 19:31:26 +00:00
|
|
|
char keysecret[MXNAME] = "";
|
2000-06-06 00:43:17 +00:00
|
|
|
dns_name_t keyname;
|
|
|
|
isc_buffer_t *namebuf = NULL;
|
|
|
|
dns_tsigkey_t *key = NULL;
|
2000-06-06 18:49:06 +00:00
|
|
|
isc_boolean_t validated = ISC_TRUE;
|
2000-06-12 19:33:30 +00:00
|
|
|
isc_entropy_t *entp = NULL;
|
2000-07-13 01:49:44 +00:00
|
|
|
isc_mempool_t *commctx = NULL;
|
2000-06-06 22:50:44 +00:00
|
|
|
isc_boolean_t debugging = ISC_FALSE;
|
2000-10-13 22:55:50 +00:00
|
|
|
isc_boolean_t memdebugging = ISC_FALSE;
|
2000-07-05 23:28:32 +00:00
|
|
|
char *progname = NULL;
|
2000-07-14 17:57:27 +00:00
|
|
|
isc_mutex_t lookup_lock;
|
2000-07-14 20:14:36 +00:00
|
|
|
dig_lookup_t *current_lookup = NULL;
|
2000-07-14 17:57:27 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Apply and clear locks at the event level in global task.
|
2000-08-01 00:53:20 +00:00
|
|
|
* Can I get rid of these using shutdown events? XXX
|
2000-07-14 17:57:27 +00:00
|
|
|
*/
|
|
|
|
#define LOCK_LOOKUP {\
|
2000-12-11 19:24:30 +00:00
|
|
|
debug("lock_lookup %s:%d", __FILE__, __LINE__);\
|
|
|
|
check_result(isc_mutex_lock((&lookup_lock)), "isc_mutex_lock");\
|
|
|
|
debug("success");\
|
2000-07-14 17:57:27 +00:00
|
|
|
}
|
|
|
|
#define UNLOCK_LOOKUP {\
|
2000-12-11 19:24:30 +00:00
|
|
|
debug("unlock_lookup %s:%d", __FILE__, __LINE__);\
|
|
|
|
check_result(isc_mutex_unlock((&lookup_lock)),\
|
|
|
|
"isc_mutex_unlock");\
|
2000-07-14 17:57:27 +00:00
|
|
|
}
|
2000-06-06 22:50:44 +00:00
|
|
|
|
2000-07-13 00:32:20 +00:00
|
|
|
static void
|
2000-05-12 01:02:37 +00:00
|
|
|
cancel_lookup(dig_lookup_t *lookup);
|
|
|
|
|
2000-07-18 18:51:40 +00:00
|
|
|
static void
|
|
|
|
recv_done(isc_task_t *task, isc_event_t *event);
|
|
|
|
|
|
|
|
static void
|
|
|
|
connect_timeout(isc_task_t *task, isc_event_t *event);
|
|
|
|
|
2001-06-15 01:26:14 +00:00
|
|
|
static void
|
|
|
|
launch_next_query(dig_query_t *query, isc_boolean_t include_question);
|
|
|
|
|
2000-09-21 23:47:41 +00:00
|
|
|
char *
|
2000-09-21 12:25:43 +00:00
|
|
|
next_token(char **stringp, const char *delim) {
|
|
|
|
char *res;
|
|
|
|
|
|
|
|
do {
|
|
|
|
res = strsep(stringp, delim);
|
|
|
|
if (res == NULL)
|
|
|
|
break;
|
|
|
|
} while (*res == '\0');
|
|
|
|
return (res);
|
2000-12-11 19:24:30 +00:00
|
|
|
}
|
2000-09-21 12:25:43 +00:00
|
|
|
|
2000-05-02 23:23:12 +00:00
|
|
|
static int
|
|
|
|
count_dots(char *string) {
|
|
|
|
char *s;
|
2000-07-05 19:31:26 +00:00
|
|
|
int i = 0;
|
2000-05-02 23:23:12 +00:00
|
|
|
|
|
|
|
s = string;
|
2000-07-05 19:31:26 +00:00
|
|
|
while (*s != '\0') {
|
2000-05-02 23:23:12 +00:00
|
|
|
if (*s == '.')
|
|
|
|
i++;
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
return (i);
|
|
|
|
}
|
|
|
|
|
2000-04-26 18:34:17 +00:00
|
|
|
static void
|
2000-04-26 19:36:40 +00:00
|
|
|
hex_dump(isc_buffer_t *b) {
|
2000-04-26 18:34:17 +00:00
|
|
|
unsigned int len;
|
|
|
|
isc_region_t r;
|
|
|
|
|
2000-09-13 00:55:13 +00:00
|
|
|
isc_buffer_usedregion(b, &r);
|
2000-04-26 18:34:17 +00:00
|
|
|
|
2000-09-13 00:55:13 +00:00
|
|
|
printf("%d bytes\n", r.length);
|
2000-07-05 19:31:26 +00:00
|
|
|
for (len = 0; len < r.length; len++) {
|
2000-04-26 18:34:17 +00:00
|
|
|
printf("%02x ", r.base[len]);
|
2000-10-19 17:30:14 +00:00
|
|
|
if (len % 16 == 15)
|
2000-04-26 18:34:17 +00:00
|
|
|
printf("\n");
|
|
|
|
}
|
2000-10-20 05:03:31 +00:00
|
|
|
if (len % 16 != 0)
|
2000-04-26 18:34:17 +00:00
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
2000-10-23 23:13:21 +00:00
|
|
|
|
|
|
|
isc_result_t
|
2000-12-11 03:28:52 +00:00
|
|
|
get_reverse(char *reverse, char *value, isc_boolean_t nibble) {
|
2000-10-23 23:13:21 +00:00
|
|
|
int adrs[4];
|
|
|
|
char working[MXNAME];
|
2001-02-16 00:04:18 +00:00
|
|
|
int remaining;
|
2000-10-23 23:13:21 +00:00
|
|
|
int i, n;
|
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
result = DNS_R_BADDOTTEDQUAD;
|
2000-12-07 19:56:05 +00:00
|
|
|
reverse[0] = 0;
|
2000-10-23 23:13:21 +00:00
|
|
|
|
|
|
|
debug("get_reverse(%s)", value);
|
|
|
|
if (strspn(value, "0123456789.") == strlen(value)) {
|
|
|
|
n = sscanf(value, "%d.%d.%d.%d",
|
|
|
|
&adrs[0], &adrs[1],
|
|
|
|
&adrs[2], &adrs[3]);
|
|
|
|
if (n == 0) {
|
|
|
|
return (DNS_R_BADDOTTEDQUAD);
|
|
|
|
}
|
2001-02-16 00:04:18 +00:00
|
|
|
reverse[MXNAME - 1] = 0;
|
2000-10-23 23:13:21 +00:00
|
|
|
for (i = n - 1; i >= 0; i--) {
|
2001-02-16 00:04:18 +00:00
|
|
|
snprintf(working, sizeof(working), "%d.",
|
2000-10-23 23:13:21 +00:00
|
|
|
adrs[i]);
|
2001-02-16 00:04:18 +00:00
|
|
|
remaining = MXNAME - strlen(reverse) - 1;
|
|
|
|
strncat(reverse, working, remaining);
|
2000-10-23 23:13:21 +00:00
|
|
|
}
|
2001-02-16 00:04:18 +00:00
|
|
|
remaining = MXNAME - strlen(reverse) - 1;
|
|
|
|
strncat(reverse, "in-addr.arpa.", remaining);
|
2000-10-23 23:13:21 +00:00
|
|
|
result = ISC_R_SUCCESS;
|
|
|
|
} else if (strspn(value, "0123456789abcdefABCDEF:")
|
|
|
|
== strlen(value)) {
|
|
|
|
isc_netaddr_t addr;
|
|
|
|
dns_fixedname_t fname;
|
|
|
|
dns_name_t *name;
|
|
|
|
isc_buffer_t b;
|
|
|
|
|
|
|
|
addr.family = AF_INET6;
|
|
|
|
n = inet_pton(AF_INET6, value, &addr.type.in6);
|
|
|
|
if (n <= 0)
|
|
|
|
return (DNS_R_BADDOTTEDQUAD);
|
|
|
|
dns_fixedname_init(&fname);
|
|
|
|
name = dns_fixedname_name(&fname);
|
|
|
|
result = dns_byaddr_createptrname(&addr, nibble,
|
|
|
|
name);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
return (result);
|
|
|
|
isc_buffer_init(&b, reverse, MXNAME);
|
|
|
|
result = dns_name_totext(name, ISC_FALSE, &b);
|
|
|
|
isc_buffer_putuint8(&b, 0);
|
|
|
|
}
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
2000-04-26 18:34:17 +00:00
|
|
|
void
|
2000-06-01 18:49:22 +00:00
|
|
|
fatal(const char *format, ...) {
|
2000-04-26 18:34:17 +00:00
|
|
|
va_list args;
|
|
|
|
|
2000-07-13 02:14:17 +00:00
|
|
|
fprintf(stderr, "%s: ", progname);
|
2000-08-01 01:33:37 +00:00
|
|
|
va_start(args, format);
|
2000-04-26 18:34:17 +00:00
|
|
|
vfprintf(stderr, format, args);
|
|
|
|
va_end(args);
|
|
|
|
fprintf(stderr, "\n");
|
2000-08-03 17:43:06 +00:00
|
|
|
if (exitcode < 10)
|
|
|
|
exitcode = 10;
|
2000-05-08 22:51:08 +00:00
|
|
|
exit(exitcode);
|
2000-04-26 18:34:17 +00:00
|
|
|
}
|
|
|
|
|
2000-04-29 00:12:56 +00:00
|
|
|
void
|
2000-06-01 18:49:22 +00:00
|
|
|
debug(const char *format, ...) {
|
2000-04-29 00:12:56 +00:00
|
|
|
va_list args;
|
|
|
|
|
2000-06-06 22:50:44 +00:00
|
|
|
if (debugging) {
|
2000-08-01 01:33:37 +00:00
|
|
|
va_start(args, format);
|
2000-06-06 22:50:44 +00:00
|
|
|
vfprintf(stderr, format, args);
|
|
|
|
va_end(args);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
2000-04-29 00:12:56 +00:00
|
|
|
}
|
|
|
|
|
2000-05-05 18:22:16 +00:00
|
|
|
void
|
2000-06-01 18:49:22 +00:00
|
|
|
check_result(isc_result_t result, const char *msg) {
|
2000-05-08 22:51:08 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-04-26 18:34:17 +00:00
|
|
|
fatal("%s: %s", msg, isc_result_totext(result));
|
2000-05-08 22:51:08 +00:00
|
|
|
}
|
2000-04-26 18:34:17 +00:00
|
|
|
}
|
|
|
|
|
2000-07-18 18:51:40 +00:00
|
|
|
/*
|
|
|
|
* Create a server structure, which is part of the lookup structure.
|
|
|
|
* This is little more than a linked list of servers to query in hopes
|
|
|
|
* of finding the answer the user is looking for
|
|
|
|
*/
|
2000-07-14 16:35:30 +00:00
|
|
|
dig_server_t *
|
|
|
|
make_server(const char *servname) {
|
|
|
|
dig_server_t *srv;
|
|
|
|
|
|
|
|
REQUIRE(servname != NULL);
|
|
|
|
|
2000-10-20 02:21:58 +00:00
|
|
|
debug("make_server(%s)", servname);
|
2000-07-14 16:35:30 +00:00
|
|
|
srv = isc_mem_allocate(mctx, sizeof(struct dig_server));
|
|
|
|
if (srv == NULL)
|
|
|
|
fatal("Memory allocation failure in %s:%d",
|
|
|
|
__FILE__, __LINE__);
|
|
|
|
strncpy(srv->servername, servname, MXNAME);
|
2000-10-19 22:49:34 +00:00
|
|
|
srv->servername[MXNAME-1] = 0;
|
2000-10-20 02:21:58 +00:00
|
|
|
ISC_LINK_INIT(srv, link);
|
2000-07-14 16:35:30 +00:00
|
|
|
return (srv);
|
|
|
|
}
|
|
|
|
|
2000-08-01 01:33:37 +00:00
|
|
|
/*
|
2000-07-18 18:51:40 +00:00
|
|
|
* Produce a cloned server list. The dest list must have already had
|
|
|
|
* ISC_LIST_INIT applied.
|
|
|
|
*/
|
2000-07-14 16:35:30 +00:00
|
|
|
void
|
2000-08-01 01:33:37 +00:00
|
|
|
clone_server_list(dig_serverlist_t src,
|
2000-07-14 16:35:30 +00:00
|
|
|
dig_serverlist_t *dest)
|
|
|
|
{
|
|
|
|
dig_server_t *srv, *newsrv;
|
|
|
|
|
|
|
|
debug("clone_server_list()");
|
|
|
|
srv = ISC_LIST_HEAD(src);
|
|
|
|
while (srv != NULL) {
|
|
|
|
newsrv = make_server(srv->servername);
|
2000-10-23 17:49:05 +00:00
|
|
|
ISC_LINK_INIT(newsrv, link);
|
2000-07-14 16:35:30 +00:00
|
|
|
ISC_LIST_ENQUEUE(*dest, newsrv, link);
|
|
|
|
srv = ISC_LIST_NEXT(srv, link);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-07-18 18:51:40 +00:00
|
|
|
/*
|
|
|
|
* Create an empty lookup structure, which holds all the information needed
|
|
|
|
* to get an answer to a user's question. This structure contains two
|
|
|
|
* linked lists: the server list (servers to query) and the query list
|
|
|
|
* (outstanding queries which have been made to the listed servers).
|
|
|
|
*/
|
2000-07-05 19:31:26 +00:00
|
|
|
dig_lookup_t *
|
2000-07-13 18:52:58 +00:00
|
|
|
make_empty_lookup(void) {
|
2000-05-12 01:02:37 +00:00
|
|
|
dig_lookup_t *looknew;
|
|
|
|
|
2000-09-21 22:46:39 +00:00
|
|
|
debug("make_empty_lookup()");
|
2000-05-12 01:02:37 +00:00
|
|
|
|
2000-07-13 00:32:20 +00:00
|
|
|
INSIST(!free_now);
|
2000-05-22 22:56:31 +00:00
|
|
|
|
2000-07-05 19:31:26 +00:00
|
|
|
looknew = isc_mem_allocate(mctx, sizeof(struct dig_lookup));
|
2000-05-12 01:02:37 +00:00
|
|
|
if (looknew == NULL)
|
2000-07-05 19:31:26 +00:00
|
|
|
fatal("Memory allocation failure in %s:%d",
|
2000-05-12 01:02:37 +00:00
|
|
|
__FILE__, __LINE__);
|
2000-07-13 18:52:58 +00:00
|
|
|
looknew->pending = ISC_TRUE;
|
2000-09-30 00:06:08 +00:00
|
|
|
looknew->textname[0] = 0;
|
2001-02-15 23:44:08 +00:00
|
|
|
looknew->cmdline[0] = 0;
|
2001-02-13 23:12:17 +00:00
|
|
|
looknew->rdtype = dns_rdatatype_a;
|
|
|
|
looknew->rdclass = dns_rdataclass_in;
|
2000-12-08 17:06:52 +00:00
|
|
|
looknew->rdtypeset = ISC_FALSE;
|
|
|
|
looknew->rdclassset = ISC_FALSE;
|
2000-07-13 01:22:38 +00:00
|
|
|
looknew->sendspace = NULL;
|
2000-07-05 19:31:26 +00:00
|
|
|
looknew->sendmsg = NULL;
|
|
|
|
looknew->name = NULL;
|
|
|
|
looknew->oname = NULL;
|
2000-05-12 01:02:37 +00:00
|
|
|
looknew->timer = NULL;
|
|
|
|
looknew->xfr_q = NULL;
|
2000-09-21 22:46:39 +00:00
|
|
|
looknew->current_query = NULL;
|
2000-07-13 18:52:58 +00:00
|
|
|
looknew->doing_xfr = ISC_FALSE;
|
|
|
|
looknew->ixfr_serial = ISC_FALSE;
|
|
|
|
looknew->trace = ISC_FALSE;
|
|
|
|
looknew->trace_root = ISC_FALSE;
|
|
|
|
looknew->identify = ISC_FALSE;
|
2001-02-13 23:12:17 +00:00
|
|
|
looknew->identify_previous_line = ISC_FALSE;
|
2000-09-13 00:03:28 +00:00
|
|
|
looknew->ignore = ISC_FALSE;
|
2000-09-28 23:02:28 +00:00
|
|
|
looknew->servfail_stops = ISC_FALSE;
|
2000-10-13 17:54:00 +00:00
|
|
|
looknew->besteffort = ISC_TRUE;
|
2000-11-13 21:34:03 +00:00
|
|
|
looknew->dnssec = ISC_FALSE;
|
2000-07-13 18:52:58 +00:00
|
|
|
looknew->udpsize = 0;
|
|
|
|
looknew->recurse = ISC_TRUE;
|
2000-07-13 21:12:21 +00:00
|
|
|
looknew->aaonly = ISC_FALSE;
|
2000-07-13 18:52:58 +00:00
|
|
|
looknew->adflag = ISC_FALSE;
|
|
|
|
looknew->cdflag = ISC_FALSE;
|
|
|
|
looknew->ns_search_only = ISC_FALSE;
|
2001-02-13 23:12:17 +00:00
|
|
|
looknew->ns_search_only_leafnode = ISC_FALSE;
|
2000-07-13 18:52:58 +00:00
|
|
|
looknew->origin = NULL;
|
|
|
|
looknew->querysig = NULL;
|
|
|
|
looknew->retries = tries;
|
|
|
|
looknew->nsfound = 0;
|
|
|
|
looknew->tcp_mode = ISC_FALSE;
|
2000-08-14 19:11:05 +00:00
|
|
|
looknew->nibble = ISC_FALSE;
|
2000-07-13 18:52:58 +00:00
|
|
|
looknew->comments = ISC_TRUE;
|
|
|
|
looknew->stats = ISC_TRUE;
|
|
|
|
looknew->section_question = ISC_TRUE;
|
|
|
|
looknew->section_answer = ISC_TRUE;
|
|
|
|
looknew->section_authority = ISC_TRUE;
|
|
|
|
looknew->section_additional = ISC_TRUE;
|
|
|
|
looknew->new_search = ISC_FALSE;
|
2000-10-19 21:49:49 +00:00
|
|
|
#ifdef DNS_OPT_NEWCODES_LIVE
|
2000-10-11 17:44:18 +00:00
|
|
|
looknew->zonename[0] = 0;
|
|
|
|
looknew->viewname[0] = 0;
|
2000-10-19 21:49:49 +00:00
|
|
|
#endif /* DNS_OPT_NEWCODES_LIVE */
|
2000-10-20 02:21:58 +00:00
|
|
|
ISC_LINK_INIT(looknew, link);
|
2000-07-13 18:52:58 +00:00
|
|
|
ISC_LIST_INIT(looknew->q);
|
2000-07-14 16:35:30 +00:00
|
|
|
ISC_LIST_INIT(looknew->my_server_list);
|
2000-07-13 18:52:58 +00:00
|
|
|
return (looknew);
|
|
|
|
}
|
|
|
|
|
2000-07-14 16:35:30 +00:00
|
|
|
/*
|
2000-07-18 18:51:40 +00:00
|
|
|
* Clone a lookup, perhaps copying the server list. This does not clone
|
|
|
|
* the query list, since it will be regenerated by the setup_lookup()
|
|
|
|
* function, nor does it queue up the new lookup for processing.
|
2000-07-14 16:35:30 +00:00
|
|
|
* Caution: If you don't clone the servers, you MUST clone the server
|
|
|
|
* list seperately from somewhere else, or construct it by hand.
|
|
|
|
*/
|
2000-07-13 18:52:58 +00:00
|
|
|
dig_lookup_t *
|
|
|
|
clone_lookup(dig_lookup_t *lookold, isc_boolean_t servers) {
|
|
|
|
dig_lookup_t *looknew;
|
|
|
|
|
|
|
|
debug("clone_lookup()");
|
|
|
|
|
|
|
|
INSIST(!free_now);
|
|
|
|
|
|
|
|
looknew = make_empty_lookup();
|
|
|
|
INSIST(looknew != NULL);
|
2001-02-17 01:05:30 +00:00
|
|
|
strncpy(looknew->textname, lookold->textname, MXNAME);
|
2001-02-15 23:44:08 +00:00
|
|
|
strncpy(looknew->cmdline, lookold->cmdline, MXNAME);
|
2001-01-08 23:50:34 +00:00
|
|
|
looknew->textname[MXNAME-1] = 0;
|
2000-07-18 01:28:20 +00:00
|
|
|
looknew->rdtype = lookold->rdtype;
|
|
|
|
looknew->rdclass = lookold->rdclass;
|
2000-12-08 17:50:47 +00:00
|
|
|
looknew->rdtypeset = lookold->rdtypeset;
|
|
|
|
looknew->rdclassset = lookold->rdclassset;
|
2000-05-12 01:02:37 +00:00
|
|
|
looknew->doing_xfr = lookold->doing_xfr;
|
2000-06-02 18:45:33 +00:00
|
|
|
looknew->ixfr_serial = lookold->ixfr_serial;
|
2000-05-12 01:02:37 +00:00
|
|
|
looknew->trace = lookold->trace;
|
|
|
|
looknew->trace_root = lookold->trace_root;
|
|
|
|
looknew->identify = lookold->identify;
|
2001-02-13 23:12:17 +00:00
|
|
|
looknew->identify_previous_line = lookold->identify_previous_line;
|
2000-09-13 00:03:28 +00:00
|
|
|
looknew->ignore = lookold->ignore;
|
2000-09-28 23:02:28 +00:00
|
|
|
looknew->servfail_stops = lookold->servfail_stops;
|
2000-10-13 17:54:00 +00:00
|
|
|
looknew->besteffort = lookold->besteffort;
|
2000-11-13 21:34:03 +00:00
|
|
|
looknew->dnssec = lookold->dnssec;
|
2000-05-12 01:02:37 +00:00
|
|
|
looknew->udpsize = lookold->udpsize;
|
|
|
|
looknew->recurse = lookold->recurse;
|
2000-12-11 19:24:30 +00:00
|
|
|
looknew->aaonly = lookold->aaonly;
|
2000-06-16 18:00:05 +00:00
|
|
|
looknew->adflag = lookold->adflag;
|
|
|
|
looknew->cdflag = lookold->cdflag;
|
2000-05-12 01:02:37 +00:00
|
|
|
looknew->ns_search_only = lookold->ns_search_only;
|
2001-02-13 23:12:17 +00:00
|
|
|
looknew->ns_search_only_leafnode = lookold->ns_search_only_leafnode;
|
2000-05-12 01:02:37 +00:00
|
|
|
looknew->tcp_mode = lookold->tcp_mode;
|
|
|
|
looknew->comments = lookold->comments;
|
|
|
|
looknew->stats = lookold->stats;
|
|
|
|
looknew->section_question = lookold->section_question;
|
|
|
|
looknew->section_answer = lookold->section_answer;
|
|
|
|
looknew->section_authority = lookold->section_authority;
|
|
|
|
looknew->section_additional = lookold->section_additional;
|
2000-09-21 22:46:39 +00:00
|
|
|
looknew->retries = lookold->retries;
|
2000-10-19 21:49:49 +00:00
|
|
|
#ifdef DNS_OPT_NEWCODES_LIVE
|
2001-02-17 01:05:30 +00:00
|
|
|
strncpy(looknew->viewname, lookold->viewname, MXNAME);
|
|
|
|
strncpy(looknew->zonename, lookold->zonename, MXNAME);
|
2000-10-19 21:49:49 +00:00
|
|
|
#endif /* DNS_OPT_NEWCODES_LIVE */
|
2000-05-12 01:02:37 +00:00
|
|
|
|
2000-07-14 16:35:30 +00:00
|
|
|
if (servers)
|
|
|
|
clone_server_list(lookold->my_server_list,
|
|
|
|
&looknew->my_server_list);
|
2000-07-13 18:52:58 +00:00
|
|
|
return (looknew);
|
|
|
|
}
|
|
|
|
|
2000-07-18 18:51:40 +00:00
|
|
|
/*
|
|
|
|
* Requeue a lookup for further processing, perhaps copying the server
|
|
|
|
* list. The new lookup structure is returned to the caller, and is
|
|
|
|
* queued for processing. If servers are not cloned in the requeue, they
|
|
|
|
* must be added before allowing the current event to complete, since the
|
|
|
|
* completion of the event may result in the next entry on the lookup
|
|
|
|
* queue getting run.
|
|
|
|
*/
|
2000-07-13 18:52:58 +00:00
|
|
|
dig_lookup_t *
|
|
|
|
requeue_lookup(dig_lookup_t *lookold, isc_boolean_t servers) {
|
|
|
|
dig_lookup_t *looknew;
|
|
|
|
|
|
|
|
debug("requeue_lookup()");
|
|
|
|
|
|
|
|
lookup_counter++;
|
|
|
|
if (lookup_counter > LOOKUP_LIMIT)
|
|
|
|
fatal("Too many lookups");
|
|
|
|
|
|
|
|
looknew = clone_lookup(lookold, servers);
|
|
|
|
INSIST(looknew != NULL);
|
|
|
|
|
2000-07-05 23:28:32 +00:00
|
|
|
debug("before insertion, init@%p "
|
2000-07-05 19:31:26 +00:00
|
|
|
"-> %p, new@%p -> %p",
|
|
|
|
lookold, lookold->link.next, looknew, looknew->link.next);
|
2000-07-14 21:33:03 +00:00
|
|
|
ISC_LIST_PREPEND(lookup_list, looknew, link);
|
2000-07-05 23:28:32 +00:00
|
|
|
debug("after insertion, init -> "
|
2000-08-01 01:33:37 +00:00
|
|
|
"%p, new = %p, new -> %p",
|
2000-07-05 19:31:26 +00:00
|
|
|
lookold, looknew, looknew->link.next);
|
2000-05-12 01:02:37 +00:00
|
|
|
return (looknew);
|
2000-08-01 01:33:37 +00:00
|
|
|
}
|
2000-05-12 01:02:37 +00:00
|
|
|
|
2000-07-19 17:52:27 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
setup_text_key(void) {
|
|
|
|
isc_result_t result;
|
|
|
|
isc_buffer_t secretbuf;
|
|
|
|
int secretsize;
|
|
|
|
unsigned char *secretstore;
|
|
|
|
isc_stdtime_t now;
|
|
|
|
|
|
|
|
debug("setup_text_key()");
|
|
|
|
result = isc_buffer_allocate(mctx, &namebuf, MXNAME);
|
|
|
|
check_result(result, "isc_buffer_allocate");
|
|
|
|
dns_name_init(&keyname, NULL);
|
|
|
|
check_result(result, "dns_name_init");
|
|
|
|
isc_buffer_putstr(namebuf, keynametext);
|
|
|
|
secretsize = strlen(keysecret) * 3 / 4;
|
2000-07-20 17:58:59 +00:00
|
|
|
secretstore = isc_mem_allocate(mctx, secretsize);
|
2000-07-19 17:52:27 +00:00
|
|
|
if (secretstore == NULL)
|
|
|
|
fatal("Memory allocation failure in %s:%d",
|
|
|
|
__FILE__, __LINE__);
|
|
|
|
isc_buffer_init(&secretbuf, secretstore, secretsize);
|
2001-03-22 00:07:07 +00:00
|
|
|
result = isc_base64_decodestring(keysecret, &secretbuf);
|
2000-07-19 17:52:27 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
printf(";; Couldn't create key %s: %s\n",
|
|
|
|
keynametext, isc_result_totext(result));
|
2000-08-01 00:53:20 +00:00
|
|
|
goto failure;
|
2000-07-19 17:52:27 +00:00
|
|
|
}
|
|
|
|
secretsize = isc_buffer_usedlength(&secretbuf);
|
|
|
|
isc_stdtime_get(&now);
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2000-07-19 17:52:27 +00:00
|
|
|
result = dns_name_fromtext(&keyname, namebuf,
|
|
|
|
dns_rootname, ISC_FALSE,
|
|
|
|
namebuf);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
printf(";; Couldn't create key %s: %s\n",
|
|
|
|
keynametext, dns_result_totext(result));
|
2000-08-01 00:53:20 +00:00
|
|
|
goto failure;
|
2000-07-19 17:52:27 +00:00
|
|
|
}
|
|
|
|
result = dns_tsigkey_create(&keyname, dns_tsig_hmacmd5_name,
|
|
|
|
secretstore, secretsize,
|
|
|
|
ISC_TRUE, NULL, now, now, mctx,
|
2000-07-21 22:26:08 +00:00
|
|
|
NULL, &key);
|
2000-07-19 17:52:27 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
printf(";; Couldn't create key %s: %s\n",
|
|
|
|
keynametext, dns_result_totext(result));
|
|
|
|
}
|
2000-08-01 00:53:20 +00:00
|
|
|
failure:
|
2000-07-20 17:58:59 +00:00
|
|
|
isc_mem_free(mctx, secretstore);
|
2000-07-19 17:52:27 +00:00
|
|
|
dns_name_invalidate(&keyname);
|
|
|
|
isc_buffer_free(&namebuf);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
setup_file_key(void) {
|
|
|
|
isc_result_t result;
|
|
|
|
isc_buffer_t secretbuf;
|
|
|
|
unsigned char *secretstore = NULL;
|
|
|
|
int secretlen;
|
|
|
|
dst_key_t *dstkey = NULL;
|
|
|
|
isc_stdtime_t now;
|
|
|
|
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2000-07-19 17:52:27 +00:00
|
|
|
debug("setup_file_key()");
|
|
|
|
result = dst_key_fromnamedfile(keyfile, DST_TYPE_PRIVATE,
|
|
|
|
mctx, &dstkey);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
fprintf(stderr, "Couldn't read key from %s: %s\n",
|
|
|
|
keyfile, isc_result_totext(result));
|
|
|
|
goto failure;
|
|
|
|
}
|
2000-08-01 00:53:20 +00:00
|
|
|
/*
|
|
|
|
* Get key size in bits, convert to bytes, rounding up (?)
|
|
|
|
*/
|
2000-07-19 17:52:27 +00:00
|
|
|
secretlen = (dst_key_size(dstkey) + 7) >> 3;
|
|
|
|
secretstore = isc_mem_allocate(mctx, secretlen);
|
|
|
|
if (secretstore == NULL)
|
|
|
|
fatal("out of memory");
|
|
|
|
isc_buffer_init(&secretbuf, secretstore, secretlen);
|
|
|
|
result = dst_key_tobuffer(dstkey, &secretbuf);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
fprintf(stderr, "Couldn't read key from %s: %s\n",
|
|
|
|
keyfile, isc_result_totext(result));
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
isc_stdtime_get(&now);
|
|
|
|
dns_name_init(&keyname, NULL);
|
|
|
|
dns_name_clone(dst_key_name(dstkey), &keyname);
|
|
|
|
result = dns_tsigkey_create(&keyname, dns_tsig_hmacmd5_name,
|
|
|
|
secretstore, secretlen,
|
|
|
|
ISC_TRUE, NULL, now, now, mctx,
|
2000-07-21 22:26:08 +00:00
|
|
|
NULL, &key);
|
2000-07-19 17:52:27 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
printf(";; Couldn't create key %s: %s\n",
|
|
|
|
keynametext, dns_result_totext(result));
|
|
|
|
}
|
|
|
|
failure:
|
|
|
|
if (dstkey != NULL)
|
|
|
|
dst_key_free(&dstkey);
|
|
|
|
if (secretstore != NULL)
|
|
|
|
isc_mem_free(mctx, secretstore);
|
|
|
|
}
|
|
|
|
|
2001-01-18 05:12:44 +00:00
|
|
|
static dig_searchlist_t *
|
|
|
|
make_searchlist_entry(char *domain) {
|
|
|
|
dig_searchlist_t *search;
|
|
|
|
search = isc_mem_allocate(mctx, sizeof(*search));
|
|
|
|
if (search == NULL)
|
|
|
|
fatal("Memory allocation failure in %s:%d",
|
|
|
|
__FILE__, __LINE__);
|
|
|
|
strncpy(search->origin, domain, MXNAME);
|
|
|
|
search->origin[MXNAME-1] = 0;
|
|
|
|
ISC_LINK_INIT(search, link);
|
|
|
|
return (search);
|
|
|
|
}
|
|
|
|
|
2000-07-18 18:51:40 +00:00
|
|
|
/*
|
|
|
|
* Setup the system as a whole, reading key information and resolv.conf
|
|
|
|
* settings.
|
|
|
|
*/
|
2000-05-09 18:05:13 +00:00
|
|
|
void
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
setup_system(void) {
|
2000-04-26 18:34:17 +00:00
|
|
|
char rcinput[MXNAME];
|
|
|
|
FILE *fp;
|
|
|
|
char *ptr;
|
|
|
|
dig_server_t *srv;
|
2001-01-16 23:15:55 +00:00
|
|
|
dig_searchlist_t *search, *domain = NULL;
|
2000-05-02 23:23:12 +00:00
|
|
|
isc_boolean_t get_servers;
|
2000-09-21 11:53:16 +00:00
|
|
|
char *input;
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2000-07-05 19:31:26 +00:00
|
|
|
debug("setup_system()");
|
2000-06-21 01:40:42 +00:00
|
|
|
|
2000-05-09 18:05:13 +00:00
|
|
|
free_now = ISC_FALSE;
|
2000-05-24 03:10:24 +00:00
|
|
|
get_servers = ISC_TF(server_list.head == NULL);
|
2000-07-05 19:31:26 +00:00
|
|
|
fp = fopen(RESOLVCONF, "r");
|
2000-08-01 00:53:20 +00:00
|
|
|
/* XXX Use lwres resolv.conf reader */
|
2001-01-18 05:12:44 +00:00
|
|
|
if (fp == NULL)
|
|
|
|
goto no_file;
|
|
|
|
|
|
|
|
while (fgets(rcinput, MXNAME, fp) != 0) {
|
|
|
|
input = rcinput;
|
|
|
|
ptr = next_token(&input, " \t\r\n");
|
|
|
|
if (ptr != NULL) {
|
|
|
|
if (get_servers &&
|
|
|
|
strcasecmp(ptr, "nameserver") == 0) {
|
|
|
|
debug("got a nameserver line");
|
|
|
|
ptr = next_token(&input, " \t\r\n");
|
|
|
|
if (ptr != NULL) {
|
|
|
|
srv = make_server(ptr);
|
|
|
|
ISC_LIST_APPEND(server_list, srv, link);
|
|
|
|
}
|
|
|
|
} else if (strcasecmp(ptr, "options") == 0) {
|
|
|
|
ptr = next_token(&input, " \t\r\n");
|
|
|
|
if (ptr != NULL) {
|
|
|
|
if((strncasecmp(ptr, "ndots:",
|
|
|
|
6) == 0) &&
|
|
|
|
(ndots == -1)) {
|
|
|
|
ndots = atoi(
|
|
|
|
&ptr[6]);
|
|
|
|
debug("ndots is %d.",
|
|
|
|
ndots);
|
2000-05-03 20:27:13 +00:00
|
|
|
}
|
2000-04-26 18:34:17 +00:00
|
|
|
}
|
2001-01-18 05:12:44 +00:00
|
|
|
} else if (strcasecmp(ptr, "search") == 0){
|
|
|
|
while ((ptr = next_token(&input, " \t\r\n"))
|
|
|
|
!= NULL) {
|
|
|
|
debug("adding search %s", ptr);
|
|
|
|
search = make_searchlist_entry(ptr);
|
|
|
|
ISC_LIST_INITANDAPPEND(search_list,
|
|
|
|
search, link);
|
|
|
|
}
|
|
|
|
} else if (strcasecmp(ptr, "domain") == 0) {
|
|
|
|
while ((ptr = next_token(&input, " \t\r\n"))
|
|
|
|
!= NULL) {
|
|
|
|
if (domain != NULL)
|
|
|
|
isc_mem_free(mctx, domain);
|
|
|
|
domain = make_searchlist_entry(ptr);
|
|
|
|
}
|
2000-04-26 18:34:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-01-18 05:12:44 +00:00
|
|
|
fclose(fp);
|
|
|
|
no_file:
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
|
2001-01-18 05:12:44 +00:00
|
|
|
if (ISC_LIST_EMPTY(search_list) && domain != NULL) {
|
2001-01-16 23:15:55 +00:00
|
|
|
ISC_LIST_INITANDAPPEND(search_list, domain, link);
|
2001-01-18 05:12:44 +00:00
|
|
|
domain = NULL;
|
|
|
|
}
|
|
|
|
if (domain != NULL)
|
|
|
|
isc_mem_free(mctx, domain);
|
|
|
|
|
2000-05-02 23:23:12 +00:00
|
|
|
if (ndots == -1)
|
|
|
|
ndots = 1;
|
|
|
|
|
2000-04-26 18:34:17 +00:00
|
|
|
if (server_list.head == NULL) {
|
2000-07-14 16:35:30 +00:00
|
|
|
srv = make_server("127.0.0.1");
|
2000-04-26 18:34:17 +00:00
|
|
|
ISC_LIST_APPEND(server_list, srv, link);
|
|
|
|
}
|
2000-05-02 23:23:12 +00:00
|
|
|
|
2000-07-19 17:52:27 +00:00
|
|
|
if (keyfile[0] != 0)
|
|
|
|
setup_file_key();
|
|
|
|
else if (keysecret[0] != 0)
|
|
|
|
setup_text_key();
|
2000-04-26 18:34:17 +00:00
|
|
|
}
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2001-01-18 05:12:44 +00:00
|
|
|
static void
|
|
|
|
clear_searchlist(void) {
|
|
|
|
dig_searchlist_t *search;
|
|
|
|
while ((search = ISC_LIST_HEAD(search_list)) != NULL) {
|
|
|
|
ISC_LIST_UNLINK(search_list, search, link);
|
|
|
|
isc_mem_free(mctx, search);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Override the search list derived from resolv.conf by 'domain'.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
set_search_domain(char *domain) {
|
|
|
|
dig_searchlist_t *search;
|
|
|
|
|
|
|
|
clear_searchlist();
|
|
|
|
search = make_searchlist_entry(domain);
|
|
|
|
ISC_LIST_APPEND(search_list, search, link);
|
|
|
|
}
|
|
|
|
|
2000-07-18 18:51:40 +00:00
|
|
|
/*
|
|
|
|
* Setup the ISC and DNS libraries for use by the system.
|
|
|
|
*/
|
2000-05-09 18:05:13 +00:00
|
|
|
void
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
setup_libs(void) {
|
2000-04-26 18:34:17 +00:00
|
|
|
isc_result_t result;
|
|
|
|
|
2000-07-05 19:31:26 +00:00
|
|
|
debug("setup_libs()");
|
2000-05-12 01:02:37 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Warning: This is not particularly good randomness. We'll
|
|
|
|
* just use random() now for getting id values, but doing so
|
|
|
|
* does NOT insure that id's cann't be guessed.
|
|
|
|
*/
|
2000-07-05 19:31:26 +00:00
|
|
|
srandom(getpid() + (int)&setup_libs);
|
2000-05-12 01:02:37 +00:00
|
|
|
|
2000-04-26 18:34:17 +00:00
|
|
|
result = isc_net_probeipv4();
|
2000-11-21 21:35:32 +00:00
|
|
|
if (result == ISC_R_SUCCESS)
|
|
|
|
have_ipv4 = ISC_TRUE;
|
2000-04-26 18:34:17 +00:00
|
|
|
|
|
|
|
result = isc_net_probeipv6();
|
|
|
|
if (result == ISC_R_SUCCESS)
|
2000-07-05 19:31:26 +00:00
|
|
|
have_ipv6 = ISC_TRUE;
|
2000-11-21 21:35:32 +00:00
|
|
|
if (!have_ipv6 && !have_ipv4)
|
|
|
|
fatal("can't find either v4 or v6 networking");
|
2000-04-26 18:34:17 +00:00
|
|
|
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
result = isc_mem_create(0, 0, &mctx);
|
|
|
|
check_result(result, "isc_mem_create");
|
2000-04-26 18:34:17 +00:00
|
|
|
|
2000-07-05 19:31:26 +00:00
|
|
|
result = isc_taskmgr_create(mctx, 1, 0, &taskmgr);
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
check_result(result, "isc_taskmgr_create");
|
2000-04-26 18:34:17 +00:00
|
|
|
|
2000-07-05 19:31:26 +00:00
|
|
|
result = isc_task_create(taskmgr, 0, &global_task);
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
check_result(result, "isc_task_create");
|
2000-04-26 18:34:17 +00:00
|
|
|
|
2000-07-05 19:31:26 +00:00
|
|
|
result = isc_timermgr_create(mctx, &timermgr);
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
check_result(result, "isc_timermgr_create");
|
2000-04-26 18:34:17 +00:00
|
|
|
|
2000-07-05 19:31:26 +00:00
|
|
|
result = isc_socketmgr_create(mctx, &socketmgr);
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
check_result(result, "isc_socketmgr_create");
|
2000-06-12 19:33:30 +00:00
|
|
|
|
2000-07-05 19:31:26 +00:00
|
|
|
result = isc_entropy_create(mctx, &entp);
|
2000-06-12 19:33:30 +00:00
|
|
|
check_result(result, "isc_entropy_create");
|
|
|
|
|
2000-07-05 19:31:26 +00:00
|
|
|
result = dst_lib_init(mctx, entp, 0);
|
2000-06-12 19:33:30 +00:00
|
|
|
check_result(result, "dst_lib_init");
|
|
|
|
is_dst_up = ISC_TRUE;
|
2000-07-13 01:49:44 +00:00
|
|
|
|
|
|
|
result = isc_mempool_create(mctx, COMMSIZE, &commctx);
|
|
|
|
check_result(result, "isc_mempool_create");
|
|
|
|
isc_mempool_setname(commctx, "COMMPOOL");
|
|
|
|
/*
|
|
|
|
* 6 and 2 set as reasonable parameters for 3 or 4 nameserver
|
|
|
|
* systems.
|
|
|
|
*/
|
|
|
|
isc_mempool_setfreemax(commctx, 6);
|
|
|
|
isc_mempool_setfillcount(commctx, 2);
|
2000-07-14 17:57:27 +00:00
|
|
|
|
|
|
|
result = isc_mutex_init(&lookup_lock);
|
|
|
|
check_result(result, "isc_mutex_init");
|
2000-09-14 20:11:48 +00:00
|
|
|
|
|
|
|
dns_result_register();
|
2000-04-26 18:34:17 +00:00
|
|
|
}
|
|
|
|
|
2000-07-18 18:51:40 +00:00
|
|
|
/*
|
|
|
|
* Add EDNS0 option record to a message. Currently, the only supported
|
|
|
|
* option is UDP buffer size.
|
|
|
|
*/
|
2000-05-08 22:51:08 +00:00
|
|
|
static void
|
2000-12-02 05:13:37 +00:00
|
|
|
add_opt(dns_message_t *msg, isc_uint16_t udpsize, isc_boolean_t dnssec
|
|
|
|
#ifdef DNS_OPT_NEWCODES_LIVE
|
|
|
|
, dns_optlist_t optlist
|
|
|
|
#endif /* DNS_OPT_NEWCODES_LIVE */
|
|
|
|
)
|
2000-11-13 21:34:03 +00:00
|
|
|
{
|
2000-05-08 22:51:08 +00:00
|
|
|
dns_rdataset_t *rdataset = NULL;
|
|
|
|
dns_rdatalist_t *rdatalist = NULL;
|
|
|
|
dns_rdata_t *rdata = NULL;
|
|
|
|
isc_result_t result;
|
2000-10-19 21:49:49 +00:00
|
|
|
#ifdef DNS_OPT_NEWCODES_LIVE
|
2000-10-11 17:44:18 +00:00
|
|
|
isc_buffer_t *rdatabuf = NULL;
|
|
|
|
unsigned int i, optsize = 0;
|
2000-10-19 21:49:49 +00:00
|
|
|
#endif /* DNS_OPT_NEWCODES_LIVE */
|
2000-05-08 22:51:08 +00:00
|
|
|
|
2000-07-05 19:31:26 +00:00
|
|
|
debug("add_opt()");
|
2000-05-08 22:51:08 +00:00
|
|
|
result = dns_message_gettemprdataset(msg, &rdataset);
|
2000-07-05 19:31:26 +00:00
|
|
|
check_result(result, "dns_message_gettemprdataset");
|
|
|
|
dns_rdataset_init(rdataset);
|
2000-05-08 22:51:08 +00:00
|
|
|
result = dns_message_gettemprdatalist(msg, &rdatalist);
|
2000-07-05 19:31:26 +00:00
|
|
|
check_result(result, "dns_message_gettemprdatalist");
|
2000-05-08 22:51:08 +00:00
|
|
|
result = dns_message_gettemprdata(msg, &rdata);
|
2000-07-05 19:31:26 +00:00
|
|
|
check_result(result, "dns_message_gettemprdata");
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2000-07-05 23:28:32 +00:00
|
|
|
debug("setting udp size of %d", udpsize);
|
2000-05-08 22:51:08 +00:00
|
|
|
rdatalist->type = dns_rdatatype_opt;
|
|
|
|
rdatalist->covers = 0;
|
|
|
|
rdatalist->rdclass = udpsize;
|
|
|
|
rdatalist->ttl = 0;
|
2000-11-13 21:34:03 +00:00
|
|
|
if (dnssec)
|
|
|
|
rdatalist->ttl = DNS_MESSAGEEXTFLAG_DO;
|
2000-05-08 22:51:08 +00:00
|
|
|
rdata->data = NULL;
|
|
|
|
rdata->length = 0;
|
2000-10-19 21:49:49 +00:00
|
|
|
#ifdef DNS_OPT_NEWCODES_LIVE
|
2001-01-08 23:50:34 +00:00
|
|
|
for (i = 0; i < optlist.used; i++)
|
2000-10-11 17:44:18 +00:00
|
|
|
optsize += optlist.attrs[i].value.length + 4;
|
|
|
|
result = isc_buffer_allocate(mctx, &rdatabuf, optsize);
|
|
|
|
check_result(result, "isc_buffer_allocate");
|
|
|
|
result = dns_opt_add(rdata, &optlist, rdatabuf);
|
|
|
|
check_result(result, "dns_opt_add");
|
|
|
|
dns_message_takebuffer(msg, &rdatabuf);
|
2000-10-19 21:49:49 +00:00
|
|
|
#endif /* DNS_OPT_NEWCODES_LIVE */
|
2000-05-08 22:51:08 +00:00
|
|
|
ISC_LIST_INIT(rdatalist->rdata);
|
|
|
|
ISC_LIST_APPEND(rdatalist->rdata, rdata, link);
|
|
|
|
dns_rdatalist_tordataset(rdatalist, rdataset);
|
|
|
|
result = dns_message_setopt(msg, rdataset);
|
2000-07-05 19:31:26 +00:00
|
|
|
check_result(result, "dns_message_setopt");
|
2000-05-08 22:51:08 +00:00
|
|
|
}
|
|
|
|
|
2000-07-18 18:51:40 +00:00
|
|
|
/*
|
2000-08-01 01:33:37 +00:00
|
|
|
* Add a question section to a message, asking for the specified name,
|
2000-07-18 18:51:40 +00:00
|
|
|
* type, and class.
|
|
|
|
*/
|
2000-04-26 18:34:17 +00:00
|
|
|
static void
|
2000-07-05 23:28:32 +00:00
|
|
|
add_question(dns_message_t *message, dns_name_t *name,
|
|
|
|
dns_rdataclass_t rdclass, dns_rdatatype_t rdtype)
|
2000-04-26 18:34:17 +00:00
|
|
|
{
|
|
|
|
dns_rdataset_t *rdataset;
|
|
|
|
isc_result_t result;
|
|
|
|
|
2000-08-01 01:33:37 +00:00
|
|
|
debug("add_question()");
|
2000-04-26 18:34:17 +00:00
|
|
|
rdataset = NULL;
|
|
|
|
result = dns_message_gettemprdataset(message, &rdataset);
|
|
|
|
check_result(result, "dns_message_gettemprdataset()");
|
|
|
|
dns_rdataset_init(rdataset);
|
|
|
|
dns_rdataset_makequestion(rdataset, rdclass, rdtype);
|
|
|
|
ISC_LIST_APPEND(name->list, rdataset, link);
|
|
|
|
}
|
|
|
|
|
2000-07-05 23:28:32 +00:00
|
|
|
/*
|
2000-07-18 18:51:40 +00:00
|
|
|
* Check if we're done with all the queued lookups, which is true iff
|
|
|
|
* all sockets, sends, and recvs are accounted for (counters == 0),
|
|
|
|
* and the lookup list is empty.
|
|
|
|
* If we are done, pass control back out to dighost_shutdown() (which is
|
|
|
|
* part of dig.c, host.c, or nslookup.c) to either shutdown the system as
|
|
|
|
* a whole or reseed the lookup list.
|
2000-07-05 23:28:32 +00:00
|
|
|
*/
|
2000-07-13 00:32:20 +00:00
|
|
|
static void
|
|
|
|
check_if_done(void) {
|
|
|
|
debug("check_if_done()");
|
2000-08-02 22:39:01 +00:00
|
|
|
debug("list %s", ISC_LIST_EMPTY(lookup_list) ? "empty" : "full");
|
2000-08-03 18:23:16 +00:00
|
|
|
if (ISC_LIST_EMPTY(lookup_list) && current_lookup == NULL &&
|
|
|
|
sendcount == 0) {
|
2000-08-02 14:38:51 +00:00
|
|
|
INSIST(sockcount == 0);
|
|
|
|
INSIST(recvcount == 0);
|
2000-07-13 00:32:20 +00:00
|
|
|
debug("shutting down");
|
|
|
|
dighost_shutdown();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clear out a query when we're done with it. WARNING: This routine
|
|
|
|
* WILL invalidate the query pointer.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
clear_query(dig_query_t *query) {
|
|
|
|
dig_lookup_t *lookup;
|
|
|
|
|
|
|
|
REQUIRE(query != NULL);
|
|
|
|
|
2000-11-21 20:52:24 +00:00
|
|
|
debug("clear_query(%p)", query);
|
2000-07-13 18:52:58 +00:00
|
|
|
|
2000-07-13 00:32:20 +00:00
|
|
|
lookup = query->lookup;
|
2000-07-14 17:57:27 +00:00
|
|
|
|
2000-09-21 22:46:39 +00:00
|
|
|
if (lookup->current_query == query)
|
|
|
|
lookup->current_query = NULL;
|
|
|
|
|
2000-07-13 00:32:20 +00:00
|
|
|
ISC_LIST_UNLINK(lookup->q, query, link);
|
|
|
|
if (ISC_LINK_LINKED(&query->recvbuf, link))
|
|
|
|
ISC_LIST_DEQUEUE(query->recvlist, &query->recvbuf,
|
|
|
|
link);
|
|
|
|
if (ISC_LINK_LINKED(&query->lengthbuf, link))
|
|
|
|
ISC_LIST_DEQUEUE(query->lengthlist, &query->lengthbuf,
|
|
|
|
link);
|
2000-07-13 01:22:38 +00:00
|
|
|
INSIST(query->recvspace != NULL);
|
2000-07-13 22:53:51 +00:00
|
|
|
if (query->sock != NULL) {
|
|
|
|
isc_socket_detach(&query->sock);
|
|
|
|
sockcount--;
|
|
|
|
debug("sockcount=%d", sockcount);
|
|
|
|
}
|
2000-07-13 01:49:44 +00:00
|
|
|
isc_mempool_put(commctx, query->recvspace);
|
2000-07-13 00:32:20 +00:00
|
|
|
isc_buffer_invalidate(&query->recvbuf);
|
|
|
|
isc_buffer_invalidate(&query->lengthbuf);
|
|
|
|
isc_mem_free(mctx, query);
|
|
|
|
}
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2000-07-18 18:51:40 +00:00
|
|
|
/*
|
|
|
|
* Try and clear out a lookup if we're done with it. Return ISC_TRUE if
|
|
|
|
* the lookup was successfully cleared. If ISC_TRUE is returned, the
|
|
|
|
* lookup pointer has been invalidated.
|
|
|
|
*/
|
2000-07-05 23:28:32 +00:00
|
|
|
static isc_boolean_t
|
2000-07-13 00:32:20 +00:00
|
|
|
try_clear_lookup(dig_lookup_t *lookup) {
|
|
|
|
dig_server_t *s;
|
2000-07-13 22:53:51 +00:00
|
|
|
dig_query_t *q;
|
2000-07-13 00:32:20 +00:00
|
|
|
void *ptr;
|
|
|
|
|
|
|
|
REQUIRE(lookup != NULL);
|
|
|
|
|
2000-07-13 18:52:58 +00:00
|
|
|
debug("try_clear_lookup(%p)", lookup);
|
|
|
|
|
|
|
|
if (ISC_LIST_HEAD(lookup->q) != NULL) {
|
2000-07-13 22:53:51 +00:00
|
|
|
if (debugging) {
|
|
|
|
q = ISC_LIST_HEAD(lookup->q);
|
|
|
|
while (q != NULL) {
|
2000-09-13 00:12:16 +00:00
|
|
|
debug("query to %s still pending",
|
2000-07-13 22:53:51 +00:00
|
|
|
q->servname);
|
|
|
|
q = ISC_LIST_NEXT(q, link);
|
|
|
|
}
|
2000-07-13 00:32:20 +00:00
|
|
|
return (ISC_FALSE);
|
2000-07-13 22:53:51 +00:00
|
|
|
}
|
2000-07-13 18:52:58 +00:00
|
|
|
}
|
2000-07-13 00:32:20 +00:00
|
|
|
/*
|
|
|
|
* At this point, we know there are no queries on the lookup,
|
|
|
|
* so can make it go away also.
|
|
|
|
*/
|
2000-07-14 20:14:36 +00:00
|
|
|
debug("cleared");
|
2000-07-14 16:35:30 +00:00
|
|
|
s = ISC_LIST_HEAD(lookup->my_server_list);
|
|
|
|
while (s != NULL) {
|
|
|
|
debug("freeing server %p belonging to %p",
|
|
|
|
s, lookup);
|
|
|
|
ptr = s;
|
|
|
|
s = ISC_LIST_NEXT(s, link);
|
2000-08-01 01:33:37 +00:00
|
|
|
ISC_LIST_DEQUEUE(lookup->my_server_list,
|
2000-07-14 16:35:30 +00:00
|
|
|
(dig_server_t *)ptr, link);
|
|
|
|
isc_mem_free(mctx, ptr);
|
2000-07-13 00:32:20 +00:00
|
|
|
}
|
|
|
|
if (lookup->sendmsg != NULL)
|
|
|
|
dns_message_destroy(&lookup->sendmsg);
|
|
|
|
if (lookup->querysig != NULL) {
|
|
|
|
debug("freeing buffer %p", lookup->querysig);
|
|
|
|
isc_buffer_free(&lookup->querysig);
|
|
|
|
}
|
|
|
|
if (lookup->timer != NULL)
|
|
|
|
isc_timer_detach(&lookup->timer);
|
2000-08-01 01:33:37 +00:00
|
|
|
if (lookup->sendspace != NULL)
|
2000-07-14 20:14:36 +00:00
|
|
|
isc_mempool_put(commctx, lookup->sendspace);
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2000-07-14 20:14:36 +00:00
|
|
|
isc_mem_free(mctx, lookup);
|
2000-07-13 00:32:20 +00:00
|
|
|
return (ISC_TRUE);
|
2000-08-01 01:33:37 +00:00
|
|
|
}
|
|
|
|
|
2000-07-13 00:32:20 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
2000-08-01 00:53:20 +00:00
|
|
|
* started yet. It also removes the lookup from the head of the queue,
|
|
|
|
* setting the current_lookup pointer pointing to it.
|
2000-07-13 00:32:20 +00:00
|
|
|
*/
|
2000-07-14 20:14:36 +00:00
|
|
|
void
|
|
|
|
start_lookup(void) {
|
|
|
|
debug("start_lookup()");
|
2000-07-14 17:57:27 +00:00
|
|
|
if (cancel_now)
|
|
|
|
return;
|
2000-07-14 20:14:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If there's a current lookup running, we really shouldn't get
|
|
|
|
* here.
|
|
|
|
*/
|
|
|
|
INSIST(current_lookup == NULL);
|
|
|
|
|
2000-08-01 00:53:20 +00:00
|
|
|
current_lookup = ISC_LIST_HEAD(lookup_list);
|
2000-07-14 20:14:36 +00:00
|
|
|
/*
|
|
|
|
* Put the current lookup somewhere so cancel_all can find it
|
|
|
|
*/
|
2000-08-01 00:53:20 +00:00
|
|
|
if (current_lookup != NULL) {
|
|
|
|
ISC_LIST_DEQUEUE(lookup_list, current_lookup, link);
|
|
|
|
setup_lookup(current_lookup);
|
|
|
|
do_lookup(current_lookup);
|
2000-07-13 00:32:20 +00:00
|
|
|
} else {
|
|
|
|
check_if_done();
|
2000-08-01 00:53:20 +00:00
|
|
|
}
|
2000-07-13 00:32:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-07-18 18:51:40 +00:00
|
|
|
* If we can, clear the current lookup and start the next one running.
|
|
|
|
* This calls try_clear_lookup, so may invalidate the lookup pointer.
|
2000-07-13 00:32:20 +00:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
check_next_lookup(dig_lookup_t *lookup) {
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2000-07-13 00:32:20 +00:00
|
|
|
INSIST(!free_now);
|
2000-05-22 22:56:31 +00:00
|
|
|
|
2000-07-13 22:53:51 +00:00
|
|
|
debug("check_next_lookup(%p)", lookup);
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2000-07-27 19:06:12 +00:00
|
|
|
if (ISC_LIST_HEAD(lookup->q) != NULL) {
|
|
|
|
debug("still have a worker");
|
2000-07-13 00:32:20 +00:00
|
|
|
return;
|
2000-07-27 19:06:12 +00:00
|
|
|
}
|
2000-07-14 20:14:36 +00:00
|
|
|
if (try_clear_lookup(lookup)) {
|
|
|
|
current_lookup = NULL;
|
|
|
|
start_lookup();
|
|
|
|
}
|
2000-05-12 01:02:37 +00:00
|
|
|
}
|
|
|
|
|
2000-07-18 18:51:40 +00:00
|
|
|
/*
|
|
|
|
* Create and queue a new lookup as a followup to the current lookup,
|
|
|
|
* based on the supplied message and section. This is used in trace and
|
|
|
|
* name server search modes to start a new lookup using servers from
|
2001-02-13 23:12:17 +00:00
|
|
|
* NS records in a reply. Returns the number of followup lookups made.
|
2000-07-18 18:51:40 +00:00
|
|
|
*/
|
2001-02-13 23:12:17 +00:00
|
|
|
static int
|
2000-05-06 01:16:07 +00:00
|
|
|
followup_lookup(dns_message_t *msg, dig_query_t *query,
|
|
|
|
dns_section_t section) {
|
2000-04-28 21:41:19 +00:00
|
|
|
dig_lookup_t *lookup = NULL;
|
|
|
|
dig_server_t *srv = NULL;
|
|
|
|
dns_rdataset_t *rdataset = NULL;
|
2000-10-25 04:26:57 +00:00
|
|
|
dns_rdata_t rdata = DNS_RDATA_INIT;
|
2000-04-28 21:41:19 +00:00
|
|
|
dns_name_t *name = NULL;
|
|
|
|
isc_result_t result, loopresult;
|
|
|
|
isc_buffer_t *b = NULL;
|
|
|
|
isc_region_t r;
|
2000-05-06 01:16:07 +00:00
|
|
|
isc_boolean_t success = ISC_FALSE;
|
2000-04-28 21:41:19 +00:00
|
|
|
int len;
|
2001-02-13 23:12:17 +00:00
|
|
|
int numLookups = 0;
|
2000-04-28 21:41:19 +00:00
|
|
|
|
2000-07-13 00:32:20 +00:00
|
|
|
INSIST(!free_now);
|
|
|
|
|
2000-08-01 01:33:37 +00:00
|
|
|
debug("followup_lookup()");
|
2000-11-21 20:52:24 +00:00
|
|
|
result = dns_message_firstname(msg, section);
|
2000-07-14 17:57:27 +00:00
|
|
|
|
2000-04-28 21:41:19 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-07-05 23:28:32 +00:00
|
|
|
debug("firstname returned %s",
|
2000-04-28 21:41:19 +00:00
|
|
|
isc_result_totext(result));
|
2000-05-06 01:16:07 +00:00
|
|
|
if ((section == DNS_SECTION_ANSWER) &&
|
2000-06-22 22:37:31 +00:00
|
|
|
(query->lookup->trace || query->lookup->ns_search_only))
|
2001-02-13 23:12:17 +00:00
|
|
|
numLookups +=
|
|
|
|
followup_lookup(msg, query, DNS_SECTION_AUTHORITY);
|
|
|
|
return numLookups;
|
2000-04-28 21:41:19 +00:00
|
|
|
}
|
|
|
|
|
2000-07-05 23:28:32 +00:00
|
|
|
debug("following up %s", query->lookup->textname);
|
2000-04-28 21:41:19 +00:00
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
name = NULL;
|
2000-05-06 01:16:07 +00:00
|
|
|
dns_message_currentname(msg, section, &name);
|
2000-04-28 21:41:19 +00:00
|
|
|
for (rdataset = ISC_LIST_HEAD(name->list);
|
|
|
|
rdataset != NULL;
|
|
|
|
rdataset = ISC_LIST_NEXT(rdataset, link)) {
|
|
|
|
loopresult = dns_rdataset_first(rdataset);
|
|
|
|
while (loopresult == ISC_R_SUCCESS) {
|
|
|
|
dns_rdataset_current(rdataset, &rdata);
|
2000-07-05 23:28:32 +00:00
|
|
|
debug("got rdata with type %d",
|
2000-05-06 01:16:07 +00:00
|
|
|
rdata.type);
|
|
|
|
if ((rdata.type == dns_rdatatype_ns) &&
|
|
|
|
(!query->lookup->trace_root ||
|
2000-07-13 22:53:51 +00:00
|
|
|
(query->lookup->nsfound < MXSERV)))
|
2000-05-06 01:16:07 +00:00
|
|
|
{
|
|
|
|
query->lookup->nsfound++;
|
2000-04-28 21:41:19 +00:00
|
|
|
result = isc_buffer_allocate(mctx, &b,
|
|
|
|
BUFSIZE);
|
2000-07-05 19:31:26 +00:00
|
|
|
check_result(result,
|
2000-04-28 21:41:19 +00:00
|
|
|
"isc_buffer_allocate");
|
2000-07-05 19:31:26 +00:00
|
|
|
result = dns_rdata_totext(&rdata,
|
|
|
|
NULL,
|
|
|
|
b);
|
|
|
|
check_result(result,
|
2000-04-28 21:41:19 +00:00
|
|
|
"dns_rdata_totext");
|
|
|
|
isc_buffer_usedregion(b, &r);
|
|
|
|
len = r.length-1;
|
|
|
|
if (len >= MXNAME)
|
|
|
|
len = MXNAME-1;
|
|
|
|
/* Initialize lookup if we've not yet */
|
2000-07-05 23:28:32 +00:00
|
|
|
debug("found NS %d %.*s",
|
2000-04-28 21:41:19 +00:00
|
|
|
(int)r.length, (int)r.length,
|
|
|
|
(char *)r.base);
|
2001-02-13 23:12:17 +00:00
|
|
|
numLookups++;
|
2000-05-06 01:16:07 +00:00
|
|
|
if (!success) {
|
|
|
|
success = ISC_TRUE;
|
|
|
|
lookup_counter++;
|
2000-07-13 22:53:51 +00:00
|
|
|
cancel_lookup(query->lookup);
|
2000-05-12 01:02:37 +00:00
|
|
|
lookup = requeue_lookup
|
|
|
|
(query->lookup,
|
|
|
|
ISC_FALSE);
|
2000-05-06 01:16:07 +00:00
|
|
|
lookup->doing_xfr = ISC_FALSE;
|
|
|
|
if (section ==
|
2000-06-22 22:37:31 +00:00
|
|
|
DNS_SECTION_ANSWER) {
|
|
|
|
lookup->trace =
|
2000-05-06 01:16:07 +00:00
|
|
|
ISC_FALSE;
|
2000-06-22 22:37:31 +00:00
|
|
|
lookup->ns_search_only =
|
|
|
|
ISC_FALSE;
|
2001-06-11 18:08:16 +00:00
|
|
|
} else {
|
2000-06-22 22:37:31 +00:00
|
|
|
lookup->trace =
|
2000-05-06 01:16:07 +00:00
|
|
|
query->
|
|
|
|
lookup->trace;
|
2000-06-22 22:37:31 +00:00
|
|
|
lookup->ns_search_only =
|
|
|
|
query->
|
|
|
|
lookup->ns_search_only;
|
2001-02-13 23:12:17 +00:00
|
|
|
lookup->ns_search_only_leafnode =
|
|
|
|
query->
|
|
|
|
lookup->ns_search_only_leafnode;
|
2000-06-22 22:37:31 +00:00
|
|
|
}
|
2000-05-06 01:16:07 +00:00
|
|
|
lookup->trace_root = ISC_FALSE;
|
|
|
|
}
|
2000-09-30 00:06:08 +00:00
|
|
|
r.base[len] = 0;
|
2000-08-17 01:23:42 +00:00
|
|
|
srv = make_server((char *)r.base);
|
2000-07-14 16:35:30 +00:00
|
|
|
debug("adding server %s",
|
2000-09-30 00:06:08 +00:00
|
|
|
srv->servername);
|
2000-04-28 21:41:19 +00:00
|
|
|
ISC_LIST_APPEND
|
|
|
|
(lookup->my_server_list,
|
|
|
|
srv, link);
|
2000-07-05 19:31:26 +00:00
|
|
|
isc_buffer_free(&b);
|
2000-04-28 21:41:19 +00:00
|
|
|
}
|
2000-10-31 03:22:05 +00:00
|
|
|
dns_rdata_reset(&rdata);
|
2000-04-28 21:41:19 +00:00
|
|
|
loopresult = dns_rdataset_next(rdataset);
|
|
|
|
}
|
|
|
|
}
|
2000-07-13 02:14:17 +00:00
|
|
|
result = dns_message_nextname(msg, section);
|
2000-05-06 01:16:07 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
break;
|
2000-04-28 21:41:19 +00:00
|
|
|
}
|
2000-05-06 01:16:07 +00:00
|
|
|
if ((lookup == NULL) && (section == DNS_SECTION_ANSWER) &&
|
2000-06-22 22:37:31 +00:00
|
|
|
(query->lookup->trace || query->lookup->ns_search_only))
|
2001-02-13 23:12:17 +00:00
|
|
|
numLookups +=
|
|
|
|
followup_lookup(msg, query, DNS_SECTION_AUTHORITY);
|
|
|
|
|
|
|
|
return numLookups;
|
2000-04-28 21:41:19 +00:00
|
|
|
}
|
|
|
|
|
2000-07-18 18:51:40 +00:00
|
|
|
/*
|
2001-01-18 05:12:44 +00:00
|
|
|
* Create and queue a new lookup using the next origin from the search
|
2000-07-18 18:51:40 +00:00
|
|
|
* list, read in setup_system().
|
2001-01-18 05:12:44 +00:00
|
|
|
*
|
|
|
|
* Return ISC_TRUE iff there was another searchlist entry.
|
2000-07-18 18:51:40 +00:00
|
|
|
*/
|
2000-07-24 18:07:03 +00:00
|
|
|
static isc_boolean_t
|
2000-05-02 23:23:12 +00:00
|
|
|
next_origin(dns_message_t *msg, dig_query_t *query) {
|
|
|
|
dig_lookup_t *lookup;
|
|
|
|
|
2000-07-05 19:31:26 +00:00
|
|
|
UNUSED(msg);
|
2000-05-02 23:23:12 +00:00
|
|
|
|
2000-07-13 00:32:20 +00:00
|
|
|
INSIST(!free_now);
|
|
|
|
|
2000-08-01 01:33:37 +00:00
|
|
|
debug("next_origin()");
|
2000-07-05 23:28:32 +00:00
|
|
|
debug("following up %s", query->lookup->textname);
|
2000-05-02 23:23:12 +00:00
|
|
|
|
2000-07-24 18:07:03 +00:00
|
|
|
if (!usesearch)
|
|
|
|
/*
|
|
|
|
* We're not using a search list, so don't even think
|
|
|
|
* about finding the next entry.
|
|
|
|
*/
|
|
|
|
return (ISC_FALSE);
|
|
|
|
if (query->lookup->origin == NULL)
|
2000-07-05 19:31:26 +00:00
|
|
|
/*
|
|
|
|
* Then we just did rootorg; there's nothing left.
|
|
|
|
*/
|
2000-07-24 18:07:03 +00:00
|
|
|
return (ISC_FALSE);
|
2000-07-13 22:53:51 +00:00
|
|
|
cancel_lookup(query->lookup);
|
2000-05-12 01:02:37 +00:00
|
|
|
lookup = requeue_lookup(query->lookup, ISC_TRUE);
|
2000-05-03 23:07:30 +00:00
|
|
|
lookup->origin = ISC_LIST_NEXT(query->lookup->origin, link);
|
2000-07-24 18:07:03 +00:00
|
|
|
return (ISC_TRUE);
|
2000-05-02 23:23:12 +00:00
|
|
|
}
|
|
|
|
|
2000-07-18 18:51:40 +00:00
|
|
|
/*
|
|
|
|
* Insert an SOA record into the sendmessage in a lookup. Used for
|
|
|
|
* creating IXFR queries.
|
|
|
|
*/
|
2000-06-02 18:45:33 +00:00
|
|
|
static void
|
|
|
|
insert_soa(dig_lookup_t *lookup) {
|
|
|
|
isc_result_t result;
|
|
|
|
dns_rdata_soa_t soa;
|
|
|
|
dns_rdata_t *rdata = NULL;
|
|
|
|
dns_rdatalist_t *rdatalist = NULL;
|
|
|
|
dns_rdataset_t *rdataset = NULL;
|
|
|
|
dns_name_t *soaname = NULL;
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2000-07-05 19:31:26 +00:00
|
|
|
debug("insert_soa()");
|
2000-06-02 18:45:33 +00:00
|
|
|
soa.mctx = mctx;
|
|
|
|
soa.serial = lookup->ixfr_serial;
|
|
|
|
soa.refresh = 1;
|
|
|
|
soa.retry = 1;
|
|
|
|
soa.expire = 1;
|
|
|
|
soa.minimum = 1;
|
2000-08-01 00:53:20 +00:00
|
|
|
soa.common.rdclass = lookup->rdclass;
|
2000-06-02 18:45:33 +00:00
|
|
|
soa.common.rdtype = dns_rdatatype_soa;
|
|
|
|
|
|
|
|
dns_name_init(&soa.origin, NULL);
|
|
|
|
dns_name_init(&soa.mname, NULL);
|
|
|
|
|
|
|
|
dns_name_clone(lookup->name, &soa.origin);
|
|
|
|
dns_name_clone(lookup->name, &soa.mname);
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2000-06-02 18:45:33 +00:00
|
|
|
isc_buffer_init(&lookup->rdatabuf, lookup->rdatastore,
|
2000-08-01 00:53:20 +00:00
|
|
|
sizeof(lookup->rdatastore));
|
2000-06-02 18:45:33 +00:00
|
|
|
|
|
|
|
result = dns_message_gettemprdata(lookup->sendmsg, &rdata);
|
|
|
|
check_result(result, "dns_message_gettemprdata");
|
2000-08-01 00:53:20 +00:00
|
|
|
|
|
|
|
result = dns_rdata_fromstruct(rdata, lookup->rdclass,
|
2000-06-02 18:45:33 +00:00
|
|
|
dns_rdatatype_soa, &soa,
|
|
|
|
&lookup->rdatabuf);
|
|
|
|
check_result(result, "isc_rdata_fromstruct");
|
|
|
|
|
|
|
|
result = dns_message_gettemprdatalist(lookup->sendmsg, &rdatalist);
|
|
|
|
check_result(result, "dns_message_gettemprdatalist");
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2000-06-02 18:45:33 +00:00
|
|
|
result = dns_message_gettemprdataset(lookup->sendmsg, &rdataset);
|
|
|
|
check_result(result, "dns_message_gettemprdataset");
|
|
|
|
|
|
|
|
dns_rdatalist_init(rdatalist);
|
|
|
|
rdatalist->type = dns_rdatatype_soa;
|
2000-08-01 00:53:20 +00:00
|
|
|
rdatalist->rdclass = lookup->rdclass;
|
2000-06-02 18:45:33 +00:00
|
|
|
rdatalist->covers = dns_rdatatype_soa;
|
|
|
|
rdatalist->ttl = 1;
|
|
|
|
ISC_LIST_INIT(rdatalist->rdata);
|
|
|
|
ISC_LIST_APPEND(rdatalist->rdata, rdata, link);
|
|
|
|
|
|
|
|
dns_rdataset_init(rdataset);
|
|
|
|
dns_rdatalist_tordataset(rdatalist, rdataset);
|
|
|
|
|
|
|
|
result = dns_message_gettempname(lookup->sendmsg, &soaname);
|
|
|
|
check_result(result, "dns_message_gettempname");
|
|
|
|
dns_name_init(soaname, NULL);
|
|
|
|
dns_name_clone(lookup->name, soaname);
|
|
|
|
ISC_LIST_INIT(soaname->list);
|
|
|
|
ISC_LIST_APPEND(soaname->list, rdataset, link);
|
|
|
|
dns_message_addname(lookup->sendmsg, soaname, DNS_SECTION_AUTHORITY);
|
|
|
|
}
|
|
|
|
|
2000-07-18 18:51:40 +00:00
|
|
|
/*
|
|
|
|
* Setup the supplied lookup structure, making it ready to start sending
|
|
|
|
* queries to servers. Create and initialize the message to be sent as
|
|
|
|
* well as the query structures and buffer space for the replies. If the
|
|
|
|
* server list is empty, clone it from the system default list.
|
|
|
|
*/
|
2000-04-26 18:34:17 +00:00
|
|
|
void
|
|
|
|
setup_lookup(dig_lookup_t *lookup) {
|
2000-08-01 00:53:20 +00:00
|
|
|
isc_result_t result;
|
2000-04-26 18:34:17 +00:00
|
|
|
int len;
|
|
|
|
dig_server_t *serv;
|
|
|
|
dig_query_t *query;
|
2000-05-02 23:23:12 +00:00
|
|
|
isc_region_t r;
|
2000-04-26 18:34:17 +00:00
|
|
|
isc_buffer_t b;
|
2001-03-05 21:15:47 +00:00
|
|
|
dns_compress_t cctx;
|
2000-05-02 23:23:12 +00:00
|
|
|
char store[MXNAME];
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2000-07-05 19:31:26 +00:00
|
|
|
REQUIRE(lookup != NULL);
|
2000-07-13 00:32:20 +00:00
|
|
|
INSIST(!free_now);
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2000-08-01 00:53:20 +00:00
|
|
|
debug("setup_lookup(%p)", lookup);
|
2000-04-26 18:34:17 +00:00
|
|
|
|
|
|
|
result = dns_message_create(mctx, DNS_MESSAGE_INTENTRENDER,
|
|
|
|
&lookup->sendmsg);
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
check_result(result, "dns_message_create");
|
2000-04-26 18:34:17 +00:00
|
|
|
|
2000-05-24 23:39:30 +00:00
|
|
|
if (lookup->new_search) {
|
2000-07-05 23:28:32 +00:00
|
|
|
debug("resetting lookup counter.");
|
2000-05-24 19:49:51 +00:00
|
|
|
lookup_counter = 0;
|
2000-05-24 23:39:30 +00:00
|
|
|
}
|
2000-04-26 18:34:17 +00:00
|
|
|
|
2000-07-14 16:35:30 +00:00
|
|
|
if (ISC_LIST_EMPTY(lookup->my_server_list)) {
|
|
|
|
debug("cloning server list");
|
|
|
|
clone_server_list(server_list, &lookup->my_server_list);
|
|
|
|
}
|
2000-04-26 18:34:17 +00:00
|
|
|
result = dns_message_gettempname(lookup->sendmsg, &lookup->name);
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
check_result(result, "dns_message_gettempname");
|
|
|
|
dns_name_init(lookup->name, NULL);
|
2000-04-26 18:34:17 +00:00
|
|
|
|
2000-07-05 19:31:26 +00:00
|
|
|
isc_buffer_init(&lookup->namebuf, lookup->namespace,
|
|
|
|
sizeof(lookup->namespace));
|
|
|
|
isc_buffer_init(&lookup->onamebuf, lookup->onamespace,
|
|
|
|
sizeof(lookup->onamespace));
|
2000-05-02 23:23:12 +00:00
|
|
|
|
2000-07-24 18:07:03 +00:00
|
|
|
/*
|
2000-08-01 00:53:20 +00:00
|
|
|
* If the name has too many dots, force the origin to be NULL
|
|
|
|
* (which produces an absolute lookup). Otherwise, take the origin
|
2000-07-24 18:07:03 +00:00
|
|
|
* we have if there's one in the struct already. If it's NULL,
|
|
|
|
* take the first entry in the searchlist iff either usesearch
|
|
|
|
* is TRUE or we got a domain line in the resolv.conf file.
|
|
|
|
*/
|
2000-08-01 00:53:20 +00:00
|
|
|
/* XXX New search here? */
|
2001-01-18 05:12:44 +00:00
|
|
|
if ((count_dots(lookup->textname) >= ndots) || !usesearch)
|
2000-08-01 00:53:20 +00:00
|
|
|
lookup->origin = NULL; /* Force abs lookup */
|
2001-01-18 05:12:44 +00:00
|
|
|
else if (lookup->origin == NULL && lookup->new_search && usesearch) {
|
|
|
|
lookup->origin = ISC_LIST_HEAD(search_list);
|
2000-10-23 17:49:05 +00:00
|
|
|
}
|
2000-05-02 23:23:12 +00:00
|
|
|
if (lookup->origin != NULL) {
|
2000-07-05 23:28:32 +00:00
|
|
|
debug("trying origin %s", lookup->origin->origin);
|
2000-05-02 23:23:12 +00:00
|
|
|
result = dns_message_gettempname(lookup->sendmsg,
|
|
|
|
&lookup->oname);
|
|
|
|
check_result(result, "dns_message_gettempname");
|
|
|
|
dns_name_init(lookup->oname, NULL);
|
2000-08-01 00:53:20 +00:00
|
|
|
/* XXX Helper funct to conv char* to name? */
|
2000-07-05 19:31:26 +00:00
|
|
|
len = strlen(lookup->origin->origin);
|
2000-05-02 23:23:12 +00:00
|
|
|
isc_buffer_init(&b, lookup->origin->origin, len);
|
|
|
|
isc_buffer_add(&b, len);
|
2000-05-03 23:07:30 +00:00
|
|
|
result = dns_name_fromtext(lookup->oname, &b, dns_rootname,
|
2000-05-02 23:23:12 +00:00
|
|
|
ISC_FALSE, &lookup->onamebuf);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-07-05 19:31:26 +00:00
|
|
|
dns_message_puttempname(lookup->sendmsg,
|
2000-05-02 23:23:12 +00:00
|
|
|
&lookup->name);
|
|
|
|
dns_message_puttempname(lookup->sendmsg,
|
|
|
|
&lookup->oname);
|
2000-08-01 00:53:20 +00:00
|
|
|
fatal("'%s' is not in legal name syntax (%s)",
|
2000-05-02 23:23:12 +00:00
|
|
|
lookup->origin->origin,
|
|
|
|
dns_result_totext(result));
|
|
|
|
}
|
2000-08-01 00:53:20 +00:00
|
|
|
if (lookup->trace_root) {
|
|
|
|
dns_name_clone(dns_rootname, lookup->name);
|
|
|
|
} else {
|
2000-07-05 19:31:26 +00:00
|
|
|
len = strlen(lookup->textname);
|
2000-05-06 01:16:07 +00:00
|
|
|
isc_buffer_init(&b, lookup->textname, len);
|
|
|
|
isc_buffer_add(&b, len);
|
|
|
|
result = dns_name_fromtext(lookup->name, &b,
|
2000-08-01 01:33:37 +00:00
|
|
|
lookup->oname, ISC_FALSE,
|
2000-05-06 01:16:07 +00:00
|
|
|
&lookup->namebuf);
|
2000-08-01 00:53:20 +00:00
|
|
|
}
|
2000-05-02 23:23:12 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
dns_message_puttempname(lookup->sendmsg,
|
|
|
|
&lookup->name);
|
|
|
|
dns_message_puttempname(lookup->sendmsg,
|
|
|
|
&lookup->oname);
|
2000-08-01 00:53:20 +00:00
|
|
|
fatal("'%s' is not in legal name syntax (%s)",
|
2000-05-02 23:23:12 +00:00
|
|
|
lookup->textname, dns_result_totext(result));
|
|
|
|
}
|
|
|
|
dns_message_puttempname(lookup->sendmsg, &lookup->oname);
|
|
|
|
} else {
|
2000-07-05 23:28:32 +00:00
|
|
|
debug("using root origin");
|
2000-05-06 01:16:07 +00:00
|
|
|
if (!lookup->trace_root) {
|
2000-07-05 19:31:26 +00:00
|
|
|
len = strlen(lookup->textname);
|
2000-05-06 01:16:07 +00:00
|
|
|
isc_buffer_init(&b, lookup->textname, len);
|
|
|
|
isc_buffer_add(&b, len);
|
|
|
|
result = dns_name_fromtext(lookup->name, &b,
|
|
|
|
dns_rootname,
|
|
|
|
ISC_FALSE,
|
|
|
|
&lookup->namebuf);
|
|
|
|
} else {
|
2000-07-05 23:28:32 +00:00
|
|
|
dns_name_clone(dns_rootname, lookup->name);
|
2000-05-06 01:16:07 +00:00
|
|
|
}
|
2000-05-02 23:23:12 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
dns_message_puttempname(lookup->sendmsg,
|
|
|
|
&lookup->name);
|
|
|
|
isc_buffer_init(&b, store, MXNAME);
|
2001-01-08 19:50:32 +00:00
|
|
|
fatal("'%s' is not a legal name "
|
2000-08-01 00:53:20 +00:00
|
|
|
"(%s)", lookup->textname,
|
|
|
|
dns_result_totext(result));
|
2000-05-02 23:23:12 +00:00
|
|
|
}
|
2000-08-01 01:33:37 +00:00
|
|
|
}
|
2000-08-01 00:53:20 +00:00
|
|
|
isc_buffer_init(&b, store, sizeof(store));
|
|
|
|
/* XXX Move some of this into function, dns_name_format. */
|
2000-05-02 23:23:12 +00:00
|
|
|
dns_name_totext(lookup->name, ISC_FALSE, &b);
|
2000-07-05 19:31:26 +00:00
|
|
|
isc_buffer_usedregion(&b, &r);
|
2000-05-02 23:23:12 +00:00
|
|
|
trying((int)r.length, (char *)r.base, lookup);
|
2000-08-01 00:53:20 +00:00
|
|
|
INSIST(dns_name_isabsolute(lookup->name));
|
2000-04-26 18:34:17 +00:00
|
|
|
|
2000-05-24 03:10:24 +00:00
|
|
|
lookup->sendmsg->id = (unsigned short)(random() & 0xFFFF);
|
2000-04-26 18:34:17 +00:00
|
|
|
lookup->sendmsg->opcode = dns_opcode_query;
|
2000-06-07 00:13:57 +00:00
|
|
|
lookup->msgcounter = 0;
|
2000-05-24 03:10:24 +00:00
|
|
|
/*
|
|
|
|
* If this is a trace request, completely disallow recursion, since
|
|
|
|
* it's meaningless for traces.
|
|
|
|
*/
|
2000-06-22 22:37:31 +00:00
|
|
|
if (lookup->recurse && !lookup->trace && !lookup->ns_search_only) {
|
2000-07-05 23:28:32 +00:00
|
|
|
debug("recursive query");
|
2000-04-26 18:34:17 +00:00
|
|
|
lookup->sendmsg->flags |= DNS_MESSAGEFLAG_RD;
|
2000-05-03 20:27:13 +00:00
|
|
|
}
|
2000-04-26 18:34:17 +00:00
|
|
|
|
2000-08-01 00:53:20 +00:00
|
|
|
/* XXX aaflag */
|
2000-07-13 21:12:21 +00:00
|
|
|
if (lookup->aaonly) {
|
|
|
|
debug("AA query");
|
|
|
|
lookup->sendmsg->flags |= DNS_MESSAGEFLAG_AA;
|
|
|
|
}
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2000-06-16 18:00:05 +00:00
|
|
|
if (lookup->adflag) {
|
2000-07-05 19:31:26 +00:00
|
|
|
debug("AD query");
|
2000-06-16 18:00:05 +00:00
|
|
|
lookup->sendmsg->flags |= DNS_MESSAGEFLAG_AD;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lookup->cdflag) {
|
2000-07-05 19:31:26 +00:00
|
|
|
debug("CD query");
|
2000-06-16 18:00:05 +00:00
|
|
|
lookup->sendmsg->flags |= DNS_MESSAGEFLAG_CD;
|
|
|
|
}
|
|
|
|
|
2000-04-26 18:34:17 +00:00
|
|
|
dns_message_addname(lookup->sendmsg, lookup->name,
|
|
|
|
DNS_SECTION_QUESTION);
|
2000-06-02 18:45:33 +00:00
|
|
|
|
2000-08-01 00:53:20 +00:00
|
|
|
if (lookup->trace_root)
|
2000-07-18 01:28:20 +00:00
|
|
|
lookup->rdtype = dns_rdatatype_soa;
|
2000-08-01 00:53:20 +00:00
|
|
|
|
2000-07-18 01:28:20 +00:00
|
|
|
if ((lookup->rdtype == dns_rdatatype_axfr) ||
|
|
|
|
(lookup->rdtype == dns_rdatatype_ixfr)) {
|
2000-04-26 18:34:17 +00:00
|
|
|
lookup->doing_xfr = ISC_TRUE;
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
/*
|
|
|
|
* Force TCP mode if we're doing an xfr.
|
2000-08-01 00:53:20 +00:00
|
|
|
* XXX UDP ixfr's would be useful
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
*/
|
2000-05-12 01:02:37 +00:00
|
|
|
lookup->tcp_mode = ISC_TRUE;
|
2000-04-26 18:34:17 +00:00
|
|
|
}
|
2000-12-08 17:06:52 +00:00
|
|
|
|
2000-07-18 01:28:20 +00:00
|
|
|
add_question(lookup->sendmsg, lookup->name, lookup->rdclass,
|
|
|
|
lookup->rdtype);
|
2000-04-26 18:34:17 +00:00
|
|
|
|
2000-08-01 00:53:20 +00:00
|
|
|
/* XXX add_soa */
|
2000-07-18 01:28:20 +00:00
|
|
|
if (lookup->rdtype == dns_rdatatype_ixfr)
|
2000-06-02 18:45:33 +00:00
|
|
|
insert_soa(lookup);
|
|
|
|
|
2000-08-01 00:53:20 +00:00
|
|
|
/* XXX Insist this? */
|
|
|
|
lookup->tsigctx = NULL;
|
|
|
|
lookup->querysig = NULL;
|
2000-06-06 00:43:17 +00:00
|
|
|
if (key != NULL) {
|
2000-07-05 23:28:32 +00:00
|
|
|
debug("initializing keys");
|
2000-06-06 00:43:17 +00:00
|
|
|
result = dns_message_settsigkey(lookup->sendmsg, key);
|
|
|
|
check_result(result, "dns_message_settsigkey");
|
|
|
|
}
|
|
|
|
|
2000-07-13 01:49:44 +00:00
|
|
|
lookup->sendspace = isc_mempool_get(commctx);
|
2000-07-13 01:22:38 +00:00
|
|
|
if (lookup->sendspace == NULL)
|
|
|
|
fatal("memory allocation failure");
|
|
|
|
|
2001-03-05 21:15:47 +00:00
|
|
|
result = dns_compress_init(&cctx, -1, mctx);
|
|
|
|
check_result(result, "dns_compress_init");
|
|
|
|
|
2000-07-05 23:28:32 +00:00
|
|
|
debug("starting to render the message");
|
2000-06-06 00:43:17 +00:00
|
|
|
isc_buffer_init(&lookup->sendbuf, lookup->sendspace, COMMSIZE);
|
2001-03-05 21:15:47 +00:00
|
|
|
result = dns_message_renderbegin(lookup->sendmsg, &cctx,
|
|
|
|
&lookup->sendbuf);
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
check_result(result, "dns_message_renderbegin");
|
2000-10-20 05:03:31 +00:00
|
|
|
#ifndef DNS_OPT_NEWCODES_LIVE
|
2000-11-13 21:34:03 +00:00
|
|
|
if (lookup->udpsize > 0 || lookup->dnssec) {
|
2000-10-20 05:03:31 +00:00
|
|
|
#else /* DNS_OPT_NEWCODES_LIVE */
|
2000-11-13 21:34:03 +00:00
|
|
|
if (lookup->udpsize > 0 || || lookup->dnssec ||
|
2001-01-08 23:50:34 +00:00
|
|
|
lookup->zonename[0] != 0 || lookup->viewname[0] != 0) {
|
2000-10-11 17:44:18 +00:00
|
|
|
dns_fixedname_t fname;
|
|
|
|
isc_buffer_t namebuf, *wirebuf = NULL;
|
2001-03-05 21:15:47 +00:00
|
|
|
dns_compress_t zcctx;
|
2000-10-11 17:44:18 +00:00
|
|
|
dns_optlist_t optlist;
|
|
|
|
dns_optattr_t optattr[2];
|
2000-12-02 05:13:37 +00:00
|
|
|
#endif /* DNS_OPT_NEWCODES_LIVE */
|
2000-10-11 17:44:18 +00:00
|
|
|
|
|
|
|
if (lookup->udpsize == 0)
|
|
|
|
lookup->udpsize = 2048;
|
2000-12-02 05:13:37 +00:00
|
|
|
|
|
|
|
#ifdef DNS_OPT_NEWCODES_LIVE
|
2000-10-11 17:44:18 +00:00
|
|
|
optlist.size = 2;
|
|
|
|
optlist.used = 0;
|
|
|
|
optlist.next = 0;
|
|
|
|
optlist.attrs = optattr;
|
|
|
|
|
|
|
|
if (lookup->zonename[0] != 0) {
|
|
|
|
optattr[optlist.used].code = DNS_OPTCODE_ZONE;
|
|
|
|
dns_fixedname_init(&fname);
|
|
|
|
isc_buffer_init(&namebuf, lookup->zonename,
|
|
|
|
strlen(lookup->zonename));
|
|
|
|
isc_buffer_add(&namebuf, strlen(lookup->zonename));
|
|
|
|
result = dns_name_fromtext(&(fname.name), &namebuf,
|
|
|
|
dns_rootname, ISC_FALSE,
|
|
|
|
NULL);
|
|
|
|
check_result(result, "; illegal zone option");
|
2001-03-05 21:15:47 +00:00
|
|
|
result = dns_compress_init(&zcctx, 0, mctx);
|
2000-10-11 17:44:18 +00:00
|
|
|
check_result(result, "dns_compress_init");
|
|
|
|
result = isc_buffer_allocate(mctx, &wirebuf,
|
|
|
|
MXNAME);
|
|
|
|
check_result(result, "isc_buffer_allocate");
|
2001-03-05 21:15:47 +00:00
|
|
|
result = dns_name_towire(&(fname.name), &zcctx,
|
2000-10-11 17:44:18 +00:00
|
|
|
wirebuf);
|
|
|
|
check_result(result, "dns_name_towire");
|
|
|
|
optattr[optlist.used].value.base =
|
|
|
|
isc_buffer_base(wirebuf);
|
|
|
|
optattr[optlist.used].value.length =
|
2000-12-11 19:24:30 +00:00
|
|
|
isc_buffer_usedlength(wirebuf);
|
2000-10-11 17:44:18 +00:00
|
|
|
optlist.used++;
|
2001-03-05 21:15:47 +00:00
|
|
|
dns_compress_invalidate(&zcctx);
|
2000-10-11 17:44:18 +00:00
|
|
|
}
|
|
|
|
if (lookup->viewname[0] != 0) {
|
|
|
|
optattr[optlist.used].code = DNS_OPTCODE_VIEW;
|
|
|
|
optattr[optlist.used].value.base =
|
|
|
|
lookup->viewname;
|
|
|
|
optattr[optlist.used].value.length =
|
|
|
|
strlen(lookup->viewname);
|
|
|
|
optlist.used++;
|
|
|
|
}
|
2000-11-13 21:34:03 +00:00
|
|
|
add_opt(lookup->sendmsg, lookup->udpsize, lookup->dnssec,
|
|
|
|
optlist);
|
2000-10-11 17:44:18 +00:00
|
|
|
if (wirebuf != NULL)
|
|
|
|
isc_buffer_free(&wirebuf);
|
2000-12-02 05:13:37 +00:00
|
|
|
#else /* DNS_OPT_NEWCODES_LIVE */
|
|
|
|
add_opt(lookup->sendmsg, lookup->udpsize, lookup->dnssec);
|
2000-10-20 05:03:31 +00:00
|
|
|
#endif /* DNS_OPT_NEWCODES_LIVE */
|
2000-10-11 17:44:18 +00:00
|
|
|
}
|
2000-08-01 00:53:20 +00:00
|
|
|
|
2000-04-26 18:34:17 +00:00
|
|
|
result = dns_message_rendersection(lookup->sendmsg,
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
DNS_SECTION_QUESTION, 0);
|
|
|
|
check_result(result, "dns_message_rendersection");
|
2000-06-02 18:45:33 +00:00
|
|
|
result = dns_message_rendersection(lookup->sendmsg,
|
|
|
|
DNS_SECTION_AUTHORITY, 0);
|
|
|
|
check_result(result, "dns_message_rendersection");
|
2000-04-26 18:34:17 +00:00
|
|
|
result = dns_message_renderend(lookup->sendmsg);
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
check_result(result, "dns_message_renderend");
|
2000-07-05 23:28:32 +00:00
|
|
|
debug("done rendering");
|
2000-04-26 18:34:17 +00:00
|
|
|
|
2001-03-05 21:15:47 +00:00
|
|
|
dns_compress_invalidate(&cctx);
|
|
|
|
|
2001-01-08 20:50:04 +00:00
|
|
|
/*
|
|
|
|
* Force TCP mode if the request is larger than 512 bytes.
|
|
|
|
*/
|
|
|
|
if (isc_buffer_usedlength(&lookup->sendbuf) > 512)
|
|
|
|
lookup->tcp_mode = ISC_TRUE;
|
|
|
|
|
2000-04-26 18:34:17 +00:00
|
|
|
lookup->pending = ISC_FALSE;
|
|
|
|
|
2000-08-01 00:53:20 +00:00
|
|
|
for (serv = ISC_LIST_HEAD(lookup->my_server_list);
|
|
|
|
serv != NULL;
|
2000-04-26 18:34:17 +00:00
|
|
|
serv = ISC_LIST_NEXT(serv, link)) {
|
|
|
|
query = isc_mem_allocate(mctx, sizeof(dig_query_t));
|
|
|
|
if (query == NULL)
|
2000-05-24 03:10:24 +00:00
|
|
|
fatal("Memory allocation failure in %s:%d",
|
|
|
|
__FILE__, __LINE__);
|
2000-07-05 23:28:32 +00:00
|
|
|
debug("create query %p linked to lookup %p",
|
2000-06-29 07:43:46 +00:00
|
|
|
query, lookup);
|
2000-04-26 18:34:17 +00:00
|
|
|
query->lookup = lookup;
|
|
|
|
query->waiting_connect = ISC_FALSE;
|
2000-09-21 22:46:39 +00:00
|
|
|
query->recv_made = ISC_FALSE;
|
2000-04-26 18:34:17 +00:00
|
|
|
query->first_pass = ISC_TRUE;
|
|
|
|
query->first_soa_rcvd = ISC_FALSE;
|
2000-06-02 18:45:33 +00:00
|
|
|
query->second_rr_rcvd = ISC_FALSE;
|
2001-04-26 17:20:07 +00:00
|
|
|
query->first_repeat_rcvd = ISC_FALSE;
|
2001-04-26 05:27:18 +00:00
|
|
|
query->first_rr_serial = 0;
|
2000-06-02 18:45:33 +00:00
|
|
|
query->second_rr_serial = 0;
|
2000-04-26 18:34:17 +00:00
|
|
|
query->servname = serv->servername;
|
2000-07-20 19:41:44 +00:00
|
|
|
query->rr_count = 0;
|
2000-10-20 02:21:58 +00:00
|
|
|
ISC_LINK_INIT(query, link);
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
ISC_LIST_INIT(query->recvlist);
|
|
|
|
ISC_LIST_INIT(query->lengthlist);
|
2000-04-26 18:34:17 +00:00
|
|
|
query->sock = NULL;
|
2000-07-13 01:49:44 +00:00
|
|
|
query->recvspace = isc_mempool_get(commctx);
|
2000-07-13 01:22:38 +00:00
|
|
|
if (query->recvspace == NULL)
|
|
|
|
fatal("memory allocation failure");
|
2000-04-26 18:34:17 +00:00
|
|
|
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_buffer_init(&query->recvbuf, query->recvspace, COMMSIZE);
|
|
|
|
isc_buffer_init(&query->lengthbuf, query->lengthspace, 2);
|
|
|
|
isc_buffer_init(&query->slbuf, query->slspace, 2);
|
2000-04-26 18:34:17 +00:00
|
|
|
|
2000-10-23 17:49:05 +00:00
|
|
|
ISC_LINK_INIT(query, link);
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
ISC_LIST_ENQUEUE(lookup->q, query, link);
|
2000-04-26 18:34:17 +00:00
|
|
|
}
|
2000-08-01 00:53:20 +00:00
|
|
|
/* XXX qrflag, print_query, etc... */
|
2000-05-08 22:51:08 +00:00
|
|
|
if (!ISC_LIST_EMPTY(lookup->q) && qr) {
|
2000-07-05 19:31:26 +00:00
|
|
|
printmessage(ISC_LIST_HEAD(lookup->q), lookup->sendmsg,
|
|
|
|
ISC_TRUE);
|
2000-05-08 22:51:08 +00:00
|
|
|
}
|
2000-08-01 00:53:20 +00:00
|
|
|
}
|
2000-04-26 18:34:17 +00:00
|
|
|
|
2000-07-18 18:51:40 +00:00
|
|
|
/*
|
|
|
|
* Event handler for send completion. Track send counter, and clear out
|
|
|
|
* the query if the send was canceled.
|
|
|
|
*/
|
2000-04-26 18:34:17 +00:00
|
|
|
static void
|
2000-08-02 19:49:57 +00:00
|
|
|
send_done(isc_task_t *_task, isc_event_t *event) {
|
2000-07-13 22:53:51 +00:00
|
|
|
REQUIRE(event->ev_type == ISC_SOCKEVENT_SENDDONE);
|
|
|
|
|
2000-08-02 19:49:57 +00:00
|
|
|
UNUSED(_task);
|
2000-05-26 00:48:18 +00:00
|
|
|
|
2000-07-14 17:57:27 +00:00
|
|
|
LOCK_LOOKUP;
|
2000-07-13 22:53:51 +00:00
|
|
|
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_event_free(&event);
|
2000-04-29 00:12:56 +00:00
|
|
|
|
|
|
|
debug("send_done()");
|
2000-07-13 00:32:20 +00:00
|
|
|
sendcount--;
|
2000-08-02 19:52:28 +00:00
|
|
|
debug("sendcount=%d", sendcount);
|
2000-07-13 00:32:20 +00:00
|
|
|
INSIST(sendcount >= 0);
|
2000-08-03 18:26:22 +00:00
|
|
|
check_if_done();
|
2000-07-14 17:57:27 +00:00
|
|
|
UNLOCK_LOOKUP;
|
2000-04-26 18:34:17 +00:00
|
|
|
}
|
|
|
|
|
2000-07-18 18:51:40 +00:00
|
|
|
/*
|
|
|
|
* Cancel a lookup, sending isc_socket_cancel() requests to all outstanding
|
|
|
|
* IO sockets. The cancel handlers should take care of cleaning up the
|
|
|
|
* query and lookup structures
|
|
|
|
*/
|
2000-09-26 17:21:25 +00:00
|
|
|
static void
|
2000-04-26 19:36:40 +00:00
|
|
|
cancel_lookup(dig_lookup_t *lookup) {
|
2000-09-21 22:46:39 +00:00
|
|
|
dig_query_t *query, *next;
|
2000-04-26 18:34:17 +00:00
|
|
|
|
2000-04-29 00:12:56 +00:00
|
|
|
debug("cancel_lookup()");
|
2000-09-21 22:46:39 +00:00
|
|
|
query = ISC_LIST_HEAD(lookup->q);
|
|
|
|
while (query != NULL) {
|
|
|
|
next = ISC_LIST_NEXT(query, link);
|
2000-05-24 23:39:30 +00:00
|
|
|
if (query->sock != NULL) {
|
2000-05-26 22:03:00 +00:00
|
|
|
isc_socket_cancel(query->sock, global_task,
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
ISC_SOCKCANCEL_ALL);
|
2000-07-13 00:32:20 +00:00
|
|
|
check_if_done();
|
2000-09-21 22:46:39 +00:00
|
|
|
} else {
|
|
|
|
clear_query(query);
|
2000-04-26 18:34:17 +00:00
|
|
|
}
|
2000-09-21 22:46:39 +00:00
|
|
|
query = next;
|
2000-04-26 18:34:17 +00:00
|
|
|
}
|
2000-09-21 22:46:39 +00:00
|
|
|
if (lookup->timer != NULL)
|
|
|
|
isc_timer_detach(&lookup->timer);
|
2000-05-12 01:02:37 +00:00
|
|
|
lookup->pending = ISC_FALSE;
|
|
|
|
lookup->retries = 0;
|
2000-04-26 18:34:17 +00:00
|
|
|
}
|
|
|
|
|
2000-07-18 01:28:20 +00:00
|
|
|
static void
|
2000-09-21 22:46:39 +00:00
|
|
|
bringup_timer(dig_query_t *query, unsigned int default_timeout) {
|
|
|
|
dig_lookup_t *l;
|
2000-07-10 17:25:59 +00:00
|
|
|
unsigned int local_timeout;
|
2000-09-21 22:46:39 +00:00
|
|
|
isc_result_t result;
|
2000-05-02 23:23:12 +00:00
|
|
|
|
2000-09-21 22:46:39 +00:00
|
|
|
debug("bringup_timer()");
|
2000-07-18 01:28:20 +00:00
|
|
|
/*
|
|
|
|
* If the timer already exists, that means we're calling this
|
2000-08-01 01:33:37 +00:00
|
|
|
* a second time (for a retry). Don't need to recreate it,
|
2000-07-18 01:28:20 +00:00
|
|
|
* just reset it.
|
|
|
|
*/
|
2000-09-21 22:46:39 +00:00
|
|
|
l = query->lookup;
|
|
|
|
if (ISC_LIST_NEXT(query, link) != NULL)
|
|
|
|
local_timeout = SERVER_TIMEOUT;
|
|
|
|
else {
|
|
|
|
if (timeout == 0) {
|
|
|
|
local_timeout = default_timeout;
|
|
|
|
} else
|
|
|
|
local_timeout = timeout;
|
|
|
|
}
|
|
|
|
debug("have local timeout of %d", local_timeout);
|
|
|
|
isc_interval_set(&l->interval, local_timeout, 0);
|
|
|
|
if (l->timer != NULL)
|
|
|
|
isc_timer_detach(&l->timer);
|
|
|
|
result = isc_timer_create(timermgr,
|
|
|
|
isc_timertype_once,
|
|
|
|
NULL,
|
|
|
|
&l->interval,
|
|
|
|
global_task,
|
|
|
|
connect_timeout,
|
|
|
|
l, &l->timer);
|
|
|
|
check_result(result, "isc_timer_create");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
connect_done(isc_task_t *task, isc_event_t *event);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unlike send_udp, this can't be called multiple times with the same
|
|
|
|
* query. When we retry TCP, we requeue the whole lookup, which should
|
|
|
|
* start anew.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
send_tcp_connect(dig_query_t *query) {
|
|
|
|
isc_result_t result;
|
|
|
|
dig_query_t *next;
|
|
|
|
dig_lookup_t *l;
|
|
|
|
|
|
|
|
debug("send_tcp_connect(%lx)", query);
|
|
|
|
|
|
|
|
l = query->lookup;
|
|
|
|
query->waiting_connect = ISC_TRUE;
|
|
|
|
query->lookup->current_query = query;
|
2000-09-21 23:02:34 +00:00
|
|
|
get_address(query->servname, port, &query->sockaddr);
|
2000-09-21 22:46:39 +00:00
|
|
|
|
|
|
|
if (specified_source &&
|
|
|
|
(isc_sockaddr_pf(&query->sockaddr) !=
|
|
|
|
isc_sockaddr_pf(&bind_address))) {
|
|
|
|
printf(";; Skipping server %s, incompatible "
|
|
|
|
"address family\n", query->servname);
|
|
|
|
query->waiting_connect = ISC_FALSE;
|
|
|
|
next = ISC_LIST_NEXT(query, link);
|
|
|
|
l = query->lookup;
|
|
|
|
clear_query(query);
|
|
|
|
if (next == NULL) {
|
|
|
|
printf(";; No acceptable nameservers\n");
|
|
|
|
check_next_lookup(l);
|
|
|
|
return;
|
2000-07-18 01:28:20 +00:00
|
|
|
}
|
2000-09-21 22:46:39 +00:00
|
|
|
send_tcp_connect(next);
|
|
|
|
return;
|
2000-07-05 23:28:32 +00:00
|
|
|
}
|
2000-09-21 22:46:39 +00:00
|
|
|
INSIST(query->sock == NULL);
|
|
|
|
result = isc_socket_create(socketmgr,
|
|
|
|
isc_sockaddr_pf(&query->sockaddr),
|
|
|
|
isc_sockettype_tcp, &query->sock) ;
|
|
|
|
check_result(result, "isc_socket_create");
|
|
|
|
sockcount++;
|
2000-11-21 20:52:24 +00:00
|
|
|
debug("sockcount=%d", sockcount);
|
2000-09-21 22:46:39 +00:00
|
|
|
if (specified_source)
|
|
|
|
result = isc_socket_bind(query->sock, &bind_address);
|
|
|
|
else {
|
2000-11-21 21:35:32 +00:00
|
|
|
if ((isc_sockaddr_pf(&query->sockaddr) == AF_INET) &&
|
|
|
|
have_ipv4)
|
2000-09-21 22:46:39 +00:00
|
|
|
isc_sockaddr_any(&bind_any);
|
|
|
|
else
|
|
|
|
isc_sockaddr_any6(&bind_any);
|
|
|
|
result = isc_socket_bind(query->sock, &bind_any);
|
|
|
|
}
|
|
|
|
check_result(result, "isc_socket_bind");
|
|
|
|
bringup_timer(query, TCP_TIMEOUT);
|
|
|
|
result = isc_socket_connect(query->sock, &query->sockaddr,
|
|
|
|
global_task, connect_done, query);
|
|
|
|
check_result(result, "isc_socket_connect");
|
|
|
|
/*
|
2001-02-13 23:12:17 +00:00
|
|
|
* If we're at the endgame of a nameserver search, we need to
|
|
|
|
* immediately bring up all the queries. Do it here.
|
2000-09-21 22:46:39 +00:00
|
|
|
*/
|
2001-02-13 23:12:17 +00:00
|
|
|
if (l->ns_search_only_leafnode) {
|
2000-09-21 22:46:39 +00:00
|
|
|
debug("sending next, since searching");
|
|
|
|
next = ISC_LIST_NEXT(query, link);
|
|
|
|
if (next != NULL)
|
|
|
|
send_tcp_connect(next);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send a UDP packet to the remote nameserver, possible starting the
|
|
|
|
* recv action as well. Also make sure that the timer is running and
|
|
|
|
* is properly reset.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
send_udp(dig_query_t *query) {
|
|
|
|
dig_lookup_t *l = NULL;
|
|
|
|
dig_query_t *next;
|
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
debug("send_udp(%lx)", query);
|
|
|
|
|
|
|
|
l = query->lookup;
|
|
|
|
bringup_timer(query, UDP_TIMEOUT);
|
|
|
|
l->current_query = query;
|
|
|
|
debug("working on lookup %p, query %p",
|
|
|
|
query->lookup, query);
|
|
|
|
if (!query->recv_made) {
|
|
|
|
/* XXX Check the sense of this, need assertion? */
|
|
|
|
query->waiting_connect = ISC_FALSE;
|
2000-09-21 23:02:34 +00:00
|
|
|
get_address(query->servname, port, &query->sockaddr);
|
2000-09-21 22:46:39 +00:00
|
|
|
|
|
|
|
result = isc_socket_create(socketmgr,
|
|
|
|
isc_sockaddr_pf(&query->sockaddr),
|
|
|
|
isc_sockettype_udp, &query->sock);
|
|
|
|
check_result(result, "isc_socket_create");
|
|
|
|
sockcount++;
|
|
|
|
debug("sockcount=%d", sockcount);
|
|
|
|
if (specified_source) {
|
|
|
|
result = isc_socket_bind(query->sock, &bind_address);
|
|
|
|
} else {
|
|
|
|
isc_sockaddr_anyofpf(&bind_any,
|
|
|
|
isc_sockaddr_pf(&query->sockaddr));
|
|
|
|
result = isc_socket_bind(query->sock, &bind_any);
|
2000-07-18 01:28:20 +00:00
|
|
|
}
|
2000-09-21 22:46:39 +00:00
|
|
|
check_result(result, "isc_socket_bind");
|
|
|
|
|
|
|
|
query->recv_made = ISC_TRUE;
|
2000-10-23 17:49:05 +00:00
|
|
|
ISC_LINK_INIT(&query->recvbuf, link);
|
2000-09-21 22:46:39 +00:00
|
|
|
ISC_LIST_ENQUEUE(query->recvlist, &query->recvbuf,
|
2000-07-18 01:28:20 +00:00
|
|
|
link);
|
2000-09-21 22:46:39 +00:00
|
|
|
debug("recving with lookup=%p, query=%p, sock=%p",
|
|
|
|
query->lookup, query,
|
|
|
|
query->sock);
|
|
|
|
result = isc_socket_recvv(query->sock,
|
|
|
|
&query->recvlist, 1,
|
|
|
|
global_task, recv_done,
|
|
|
|
query);
|
|
|
|
check_result(result, "isc_socket_recvv");
|
|
|
|
recvcount++;
|
|
|
|
debug("recvcount=%d", recvcount);
|
|
|
|
}
|
|
|
|
ISC_LIST_INIT(query->sendlist);
|
2000-10-23 17:49:05 +00:00
|
|
|
ISC_LINK_INIT(&l->sendbuf, link);
|
2000-09-21 22:46:39 +00:00
|
|
|
ISC_LIST_ENQUEUE(query->sendlist, &l->sendbuf,
|
|
|
|
link);
|
|
|
|
debug("sending a request");
|
|
|
|
result = isc_time_now(&query->time_sent);
|
|
|
|
check_result(result, "isc_time_now");
|
|
|
|
INSIST(query->sock != NULL);
|
|
|
|
result = isc_socket_sendtov(query->sock, &query->sendlist,
|
|
|
|
global_task, send_done, query,
|
|
|
|
&query->sockaddr, NULL);
|
|
|
|
check_result(result, "isc_socket_sendtov");
|
|
|
|
sendcount++;
|
|
|
|
/*
|
2001-02-13 23:12:17 +00:00
|
|
|
* If we're at the endgame of a nameserver search, we need to
|
|
|
|
* immediately bring up all the queries. Do it here.
|
2000-09-21 22:46:39 +00:00
|
|
|
*/
|
2001-02-13 23:12:17 +00:00
|
|
|
if (l->ns_search_only_leafnode) {
|
2000-09-21 22:46:39 +00:00
|
|
|
debug("sending next, since searching");
|
|
|
|
next = ISC_LIST_NEXT(query, link);
|
|
|
|
if (next != NULL)
|
|
|
|
send_udp(next);
|
2000-05-02 23:23:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-07-05 19:31:26 +00:00
|
|
|
/*
|
2000-07-18 18:51:40 +00:00
|
|
|
* IO timeout handler, used for both connect and recv timeouts. If
|
|
|
|
* retries are still allowed, either resend the UDP packet or queue a
|
|
|
|
* new TCP lookup. Otherwise, cancel the lookup.
|
2000-07-05 19:31:26 +00:00
|
|
|
*/
|
2000-04-26 18:34:17 +00:00
|
|
|
static void
|
2000-04-26 19:36:40 +00:00
|
|
|
connect_timeout(isc_task_t *task, isc_event_t *event) {
|
2000-09-21 22:46:39 +00:00
|
|
|
dig_lookup_t *l=NULL;
|
|
|
|
dig_query_t *query=NULL, *cq;
|
2000-04-26 18:34:17 +00:00
|
|
|
|
2000-07-18 01:28:20 +00:00
|
|
|
UNUSED(task);
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
REQUIRE(event->ev_type == ISC_TIMEREVENT_IDLE);
|
2000-04-26 18:34:17 +00:00
|
|
|
|
2000-04-29 00:12:56 +00:00
|
|
|
debug("connect_timeout()");
|
|
|
|
|
2000-07-14 17:57:27 +00:00
|
|
|
LOCK_LOOKUP;
|
2000-09-21 22:46:39 +00:00
|
|
|
l = event->ev_arg;
|
|
|
|
query = l->current_query;
|
2000-05-25 19:32:11 +00:00
|
|
|
isc_event_free(&event);
|
|
|
|
|
2000-07-18 01:28:20 +00:00
|
|
|
INSIST(!free_now);
|
2000-09-21 22:46:39 +00:00
|
|
|
|
|
|
|
if ((query != NULL) && (query->lookup->current_query != NULL) &&
|
|
|
|
(ISC_LIST_NEXT(query->lookup->current_query, link) != NULL)) {
|
|
|
|
debug("trying next server...");
|
|
|
|
cq = query->lookup->current_query;
|
|
|
|
if (!l->tcp_mode)
|
|
|
|
send_udp(ISC_LIST_NEXT(cq, link));
|
|
|
|
else
|
|
|
|
send_tcp_connect(ISC_LIST_NEXT(cq, link));
|
|
|
|
UNLOCK_LOOKUP;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (l->retries > 1) {
|
|
|
|
if (!l->tcp_mode) {
|
|
|
|
l->retries--;
|
|
|
|
debug("resending UDP request to first server");
|
|
|
|
send_udp(ISC_LIST_HEAD(l->q));
|
2000-07-18 01:28:20 +00:00
|
|
|
} else {
|
2000-09-21 22:46:39 +00:00
|
|
|
debug("making new TCP request, %d tries left",
|
|
|
|
l->retries);
|
|
|
|
cancel_lookup(l);
|
|
|
|
l->retries--;
|
|
|
|
requeue_lookup(l, ISC_TRUE);
|
2000-04-26 18:34:17 +00:00
|
|
|
}
|
2001-06-11 18:08:16 +00:00
|
|
|
} else {
|
2000-11-21 20:52:24 +00:00
|
|
|
fputs(l->cmdline, stdout);
|
2000-08-02 14:38:51 +00:00
|
|
|
printf(";; connection timed out; no servers could be "
|
|
|
|
"reached\n");
|
2000-09-21 22:46:39 +00:00
|
|
|
cancel_lookup(l);
|
2001-06-11 18:20:43 +00:00
|
|
|
if (exitcode < 9)
|
|
|
|
exitcode = 9;
|
2000-07-18 01:28:20 +00:00
|
|
|
}
|
2000-07-14 17:57:27 +00:00
|
|
|
UNLOCK_LOOKUP;
|
2000-04-26 18:34:17 +00:00
|
|
|
}
|
|
|
|
|
2000-07-18 18:51:40 +00:00
|
|
|
/*
|
|
|
|
* Event handler for the TCP recv which gets the length header of TCP
|
|
|
|
* packets. Start the next recv of length bytes.
|
|
|
|
*/
|
2000-04-26 18:34:17 +00:00
|
|
|
static void
|
2000-08-01 01:33:37 +00:00
|
|
|
tcp_length_done(isc_task_t *task, isc_event_t *event) {
|
2000-04-26 18:34:17 +00:00
|
|
|
isc_socketevent_t *sevent;
|
|
|
|
isc_buffer_t *b=NULL;
|
|
|
|
isc_region_t r;
|
|
|
|
isc_result_t result;
|
|
|
|
dig_query_t *query=NULL;
|
2000-07-13 18:52:58 +00:00
|
|
|
dig_lookup_t *l;
|
2000-04-26 18:34:17 +00:00
|
|
|
isc_uint16_t length;
|
|
|
|
|
2000-04-29 00:12:56 +00:00
|
|
|
REQUIRE(event->ev_type == ISC_SOCKEVENT_RECVDONE);
|
2000-07-13 00:32:20 +00:00
|
|
|
INSIST(!free_now);
|
2000-04-29 00:12:56 +00:00
|
|
|
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
UNUSED(task);
|
2000-04-26 18:34:17 +00:00
|
|
|
|
2000-04-29 00:12:56 +00:00
|
|
|
debug("tcp_length_done()");
|
2000-05-22 22:56:31 +00:00
|
|
|
|
2000-07-14 17:57:27 +00:00
|
|
|
LOCK_LOOKUP;
|
2000-08-01 01:33:37 +00:00
|
|
|
sevent = (isc_socketevent_t *)event;
|
2000-04-26 18:34:17 +00:00
|
|
|
query = event->ev_arg;
|
|
|
|
|
2000-07-13 18:52:58 +00:00
|
|
|
recvcount--;
|
|
|
|
INSIST(recvcount >= 0);
|
|
|
|
|
2000-04-26 18:34:17 +00:00
|
|
|
if (sevent->result == ISC_R_CANCELED) {
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_event_free(&event);
|
2000-07-13 18:52:58 +00:00
|
|
|
l = query->lookup;
|
|
|
|
clear_query(query);
|
|
|
|
check_next_lookup(l);
|
2000-07-14 21:33:03 +00:00
|
|
|
UNLOCK_LOOKUP;
|
2000-04-26 18:34:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (sevent->result != ISC_R_SUCCESS) {
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
result = isc_buffer_allocate(mctx, &b, 256);
|
|
|
|
check_result(result, "isc_buffer_allocate");
|
2000-04-26 18:34:17 +00:00
|
|
|
result = isc_sockaddr_totext(&query->sockaddr, b);
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
check_result(result, "isc_sockaddr_totext");
|
|
|
|
isc_buffer_usedregion(b, &r);
|
2000-08-02 14:38:51 +00:00
|
|
|
printf(";; communications error to %.*s: %s\n",
|
|
|
|
(int)r.length, r.base,
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_result_totext(sevent->result));
|
|
|
|
isc_buffer_free(&b);
|
2000-07-27 18:36:59 +00:00
|
|
|
l = query->lookup;
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_socket_detach(&query->sock);
|
2000-07-13 00:32:20 +00:00
|
|
|
sockcount--;
|
2000-11-21 20:52:24 +00:00
|
|
|
debug("sockcount=%d", sockcount);
|
2000-07-13 00:32:20 +00:00
|
|
|
INSIST(sockcount >= 0);
|
2000-05-26 00:48:18 +00:00
|
|
|
isc_event_free(&event);
|
2000-07-27 18:36:59 +00:00
|
|
|
clear_query(query);
|
|
|
|
check_next_lookup(l);
|
2000-07-14 21:33:03 +00:00
|
|
|
UNLOCK_LOOKUP;
|
2000-04-26 18:34:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
b = ISC_LIST_HEAD(sevent->bufferlist);
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
ISC_LIST_DEQUEUE(sevent->bufferlist, &query->lengthbuf, link);
|
2000-04-26 18:34:17 +00:00
|
|
|
length = isc_buffer_getuint16(b);
|
2001-06-14 21:40:02 +00:00
|
|
|
if (length == 0) {
|
2000-07-05 19:31:26 +00:00
|
|
|
isc_event_free(&event);
|
2001-06-14 21:40:02 +00:00
|
|
|
launch_next_query(query, ISC_FALSE);
|
|
|
|
UNLOCK_LOOKUP;
|
|
|
|
return;
|
2000-04-29 00:12:56 +00:00
|
|
|
}
|
2001-06-14 21:40:02 +00:00
|
|
|
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
/*
|
|
|
|
* Even though the buffer was already init'ed, we need
|
|
|
|
* to redo it now, to force the length we want.
|
|
|
|
*/
|
|
|
|
isc_buffer_invalidate(&query->recvbuf);
|
|
|
|
isc_buffer_init(&query->recvbuf, query->recvspace, length);
|
|
|
|
ENSURE(ISC_LIST_EMPTY(query->recvlist));
|
2000-10-23 17:49:05 +00:00
|
|
|
ISC_LINK_INIT(&query->recvbuf, link);
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
ISC_LIST_ENQUEUE(query->recvlist, &query->recvbuf, link);
|
2000-07-05 19:31:26 +00:00
|
|
|
debug("recving with lookup=%p, query=%p",
|
2000-06-29 07:43:46 +00:00
|
|
|
query->lookup, query);
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
result = isc_socket_recvv(query->sock, &query->recvlist, length, task,
|
|
|
|
recv_done, query);
|
|
|
|
check_result(result, "isc_socket_recvv");
|
2000-07-13 00:32:20 +00:00
|
|
|
recvcount++;
|
2000-08-01 01:33:37 +00:00
|
|
|
debug("resubmitted recv request with length %d, recvcount=%d",
|
2000-07-13 00:32:20 +00:00
|
|
|
length, recvcount);
|
2000-05-26 00:48:18 +00:00
|
|
|
isc_event_free(&event);
|
2000-07-14 17:57:27 +00:00
|
|
|
UNLOCK_LOOKUP;
|
2000-04-26 18:34:17 +00:00
|
|
|
}
|
|
|
|
|
2000-07-18 18:51:40 +00:00
|
|
|
/*
|
|
|
|
* For transfers that involve multiple recvs (XFR's in particular),
|
|
|
|
* launch the next recv.
|
|
|
|
*/
|
2000-04-26 18:34:17 +00:00
|
|
|
static void
|
|
|
|
launch_next_query(dig_query_t *query, isc_boolean_t include_question) {
|
|
|
|
isc_result_t result;
|
2000-07-13 22:53:51 +00:00
|
|
|
dig_lookup_t *l;
|
2000-04-26 18:34:17 +00:00
|
|
|
|
2000-07-13 00:32:20 +00:00
|
|
|
INSIST(!free_now);
|
2000-04-29 00:12:56 +00:00
|
|
|
|
2000-07-13 00:32:20 +00:00
|
|
|
debug("launch_next_query()");
|
2000-05-22 22:56:31 +00:00
|
|
|
|
2000-04-26 18:34:17 +00:00
|
|
|
if (!query->lookup->pending) {
|
2000-07-05 23:28:32 +00:00
|
|
|
debug("ignoring launch_next_query because !pending");
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_socket_detach(&query->sock);
|
2000-07-13 00:32:20 +00:00
|
|
|
sockcount--;
|
|
|
|
debug("sockcount=%d", sockcount);
|
|
|
|
INSIST(sockcount >= 0);
|
2000-04-26 18:34:17 +00:00
|
|
|
query->waiting_connect = ISC_FALSE;
|
2000-07-13 22:53:51 +00:00
|
|
|
l = query->lookup;
|
|
|
|
clear_query(query);
|
|
|
|
check_next_lookup(l);
|
2000-04-26 18:34:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_buffer_clear(&query->slbuf);
|
|
|
|
isc_buffer_clear(&query->lengthbuf);
|
2001-06-30 04:43:47 +00:00
|
|
|
isc_buffer_putuint16(&query->slbuf, (isc_uint16_t) query->lookup->sendbuf.used);
|
2000-07-18 01:28:20 +00:00
|
|
|
ISC_LIST_INIT(query->sendlist);
|
2000-10-23 17:49:05 +00:00
|
|
|
ISC_LINK_INIT(&query->slbuf, link);
|
2000-04-26 18:34:17 +00:00
|
|
|
ISC_LIST_ENQUEUE(query->sendlist, &query->slbuf, link);
|
2000-04-29 01:39:32 +00:00
|
|
|
if (include_question) {
|
2000-10-23 17:49:05 +00:00
|
|
|
ISC_LINK_INIT(&query->lookup->sendbuf, link);
|
2000-04-26 18:34:17 +00:00
|
|
|
ISC_LIST_ENQUEUE(query->sendlist, &query->lookup->sendbuf,
|
|
|
|
link);
|
2000-04-29 01:39:32 +00:00
|
|
|
}
|
2000-10-23 17:49:05 +00:00
|
|
|
ISC_LINK_INIT(&query->lengthbuf, link);
|
2000-04-26 18:34:17 +00:00
|
|
|
ISC_LIST_ENQUEUE(query->lengthlist, &query->lengthbuf, link);
|
|
|
|
|
2000-05-26 22:03:00 +00:00
|
|
|
result = isc_socket_recvv(query->sock, &query->lengthlist, 0,
|
|
|
|
global_task, tcp_length_done, query);
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
check_result(result, "isc_socket_recvv");
|
2000-07-13 00:32:20 +00:00
|
|
|
recvcount++;
|
|
|
|
debug("recvcount=%d",recvcount);
|
2000-04-29 00:12:56 +00:00
|
|
|
if (!query->first_soa_rcvd) {
|
2000-07-18 18:51:40 +00:00
|
|
|
debug("sending a request in launch_next_query");
|
2000-05-02 23:23:12 +00:00
|
|
|
result = isc_time_now(&query->time_sent);
|
|
|
|
check_result(result, "isc_time_now");
|
2000-05-26 22:03:00 +00:00
|
|
|
result = isc_socket_sendv(query->sock, &query->sendlist,
|
|
|
|
global_task, send_done, query);
|
2000-07-13 00:32:20 +00:00
|
|
|
check_result(result, "isc_socket_sendv");
|
|
|
|
sendcount++;
|
|
|
|
debug("sendcount=%d", sendcount);
|
2000-04-29 00:12:56 +00:00
|
|
|
}
|
2000-04-26 18:34:17 +00:00
|
|
|
query->waiting_connect = ISC_FALSE;
|
2000-07-18 18:51:40 +00:00
|
|
|
#if 0
|
2000-04-26 18:34:17 +00:00
|
|
|
check_next_lookup(query->lookup);
|
2000-07-18 18:51:40 +00:00
|
|
|
#endif
|
2000-04-26 18:34:17 +00:00
|
|
|
return;
|
|
|
|
}
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2000-07-18 18:51:40 +00:00
|
|
|
/*
|
|
|
|
* Event handler for TCP connect complete. Make sure the connection was
|
|
|
|
* successful, then pass into launch_next_query to actually send the
|
|
|
|
* question.
|
|
|
|
*/
|
2000-04-26 18:34:17 +00:00
|
|
|
static void
|
2000-04-26 19:36:40 +00:00
|
|
|
connect_done(isc_task_t *task, isc_event_t *event) {
|
2000-04-26 18:34:17 +00:00
|
|
|
isc_result_t result;
|
2000-07-05 19:31:26 +00:00
|
|
|
isc_socketevent_t *sevent = NULL;
|
2000-09-21 22:46:39 +00:00
|
|
|
dig_query_t *query = NULL, *next;
|
2000-07-13 21:01:00 +00:00
|
|
|
dig_lookup_t *l;
|
2000-07-05 19:31:26 +00:00
|
|
|
isc_buffer_t *b = NULL;
|
2000-04-26 18:34:17 +00:00
|
|
|
isc_region_t r;
|
|
|
|
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
UNUSED(task);
|
2000-04-26 18:34:17 +00:00
|
|
|
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
REQUIRE(event->ev_type == ISC_SOCKEVENT_CONNECT);
|
2000-07-13 00:32:20 +00:00
|
|
|
INSIST(!free_now);
|
2000-04-29 00:12:56 +00:00
|
|
|
|
2000-07-05 19:31:26 +00:00
|
|
|
debug("connect_done()");
|
2000-05-25 19:32:11 +00:00
|
|
|
|
2000-07-14 17:57:27 +00:00
|
|
|
LOCK_LOOKUP;
|
2000-04-26 18:34:17 +00:00
|
|
|
sevent = (isc_socketevent_t *)event;
|
|
|
|
query = sevent->ev_arg;
|
|
|
|
|
2000-07-14 17:57:27 +00:00
|
|
|
INSIST(query->waiting_connect);
|
2000-04-26 18:34:17 +00:00
|
|
|
|
|
|
|
query->waiting_connect = ISC_FALSE;
|
|
|
|
|
2000-09-14 20:11:48 +00:00
|
|
|
if (sevent->result == ISC_R_CANCELED) {
|
|
|
|
debug("in cancel handler");
|
|
|
|
isc_socket_detach(&query->sock);
|
|
|
|
sockcount--;
|
|
|
|
INSIST(sockcount >= 0);
|
|
|
|
debug("sockcount=%d", sockcount);
|
|
|
|
query->waiting_connect = ISC_FALSE;
|
|
|
|
isc_event_free(&event);
|
|
|
|
l = query->lookup;
|
|
|
|
clear_query(query);
|
|
|
|
check_next_lookup(l);
|
|
|
|
UNLOCK_LOOKUP;
|
|
|
|
return;
|
|
|
|
}
|
2000-04-26 18:34:17 +00:00
|
|
|
if (sevent->result != ISC_R_SUCCESS) {
|
2000-07-13 22:53:51 +00:00
|
|
|
debug("unsuccessful connection: %s",
|
|
|
|
isc_result_totext(sevent->result));
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
result = isc_buffer_allocate(mctx, &b, 256);
|
|
|
|
check_result(result, "isc_buffer_allocate");
|
2000-04-26 18:34:17 +00:00
|
|
|
result = isc_sockaddr_totext(&query->sockaddr, b);
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
check_result(result, "isc_sockaddr_totext");
|
|
|
|
isc_buffer_usedregion(b, &r);
|
2000-08-01 00:53:20 +00:00
|
|
|
/* XXX isc_sockaddr_format */
|
2000-07-13 22:53:51 +00:00
|
|
|
if (sevent->result != ISC_R_CANCELED)
|
|
|
|
printf(";; Connection to %.*s(%s) for %s failed: "
|
|
|
|
"%s.\n", (int)r.length, r.base,
|
|
|
|
query->servname, query->lookup->textname,
|
|
|
|
isc_result_totext(sevent->result));
|
2000-07-13 21:01:00 +00:00
|
|
|
isc_socket_detach(&query->sock);
|
|
|
|
sockcount--;
|
|
|
|
INSIST(sockcount >= 0);
|
2000-08-01 00:53:20 +00:00
|
|
|
/* XXX Clean up exitcodes */
|
2000-08-03 17:43:06 +00:00
|
|
|
if (exitcode < 9)
|
2000-05-08 22:51:08 +00:00
|
|
|
exitcode = 9;
|
2000-08-01 00:53:20 +00:00
|
|
|
debug("sockcount=%d", sockcount);
|
2000-04-26 18:34:17 +00:00
|
|
|
isc_buffer_free(&b);
|
|
|
|
query->waiting_connect = ISC_FALSE;
|
2000-05-26 00:48:18 +00:00
|
|
|
isc_event_free(&event);
|
2000-07-13 21:01:00 +00:00
|
|
|
l = query->lookup;
|
2000-09-21 22:46:39 +00:00
|
|
|
if (l->current_query != NULL)
|
|
|
|
next = ISC_LIST_NEXT(l->current_query, link);
|
|
|
|
else
|
|
|
|
next = NULL;
|
2000-07-13 21:01:00 +00:00
|
|
|
clear_query(query);
|
2000-09-21 22:46:39 +00:00
|
|
|
if (next != NULL) {
|
|
|
|
bringup_timer(next, TCP_TIMEOUT);
|
|
|
|
send_tcp_connect(next);
|
|
|
|
} else {
|
|
|
|
check_next_lookup(l);
|
|
|
|
}
|
2000-07-14 17:57:27 +00:00
|
|
|
UNLOCK_LOOKUP;
|
2000-04-26 18:34:17 +00:00
|
|
|
return;
|
|
|
|
}
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
launch_next_query(query, ISC_TRUE);
|
2000-05-26 00:48:18 +00:00
|
|
|
isc_event_free(&event);
|
2000-07-14 17:57:27 +00:00
|
|
|
UNLOCK_LOOKUP;
|
2000-04-26 18:34:17 +00:00
|
|
|
}
|
|
|
|
|
2000-06-30 22:53:07 +00:00
|
|
|
/*
|
2000-07-18 18:51:40 +00:00
|
|
|
* Check if the ongoing XFR needs more data before it's complete, using
|
|
|
|
* the semantics of IXFR and AXFR protocols. Much of the complexity of
|
|
|
|
* this routine comes from determining when an IXFR is complete.
|
2000-07-20 19:41:44 +00:00
|
|
|
* ISC_FALSE means more data is on the way, and the recv has been issued.
|
2000-06-30 22:53:07 +00:00
|
|
|
*/
|
|
|
|
static isc_boolean_t
|
2000-06-02 18:45:33 +00:00
|
|
|
check_for_more_data(dig_query_t *query, dns_message_t *msg,
|
|
|
|
isc_socketevent_t *sevent)
|
|
|
|
{
|
|
|
|
dns_rdataset_t *rdataset = NULL;
|
2000-10-25 04:26:57 +00:00
|
|
|
dns_rdata_t rdata = DNS_RDATA_INIT;
|
2000-06-02 18:45:33 +00:00
|
|
|
dns_rdata_soa_t soa;
|
|
|
|
isc_result_t result;
|
|
|
|
|
2000-07-05 19:31:26 +00:00
|
|
|
debug("check_for_more_data()");
|
2000-06-02 18:45:33 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* By the time we're in this routine, we know we're doing
|
|
|
|
* either an AXFR or IXFR. If there's no second_rr_type,
|
|
|
|
* then we don't yet know which kind of answer we got back
|
|
|
|
* from the server. Here, we're going to walk through the
|
|
|
|
* rr's in the message, acting as necessary whenever we hit
|
|
|
|
* an SOA rr.
|
|
|
|
*/
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2000-06-02 18:45:33 +00:00
|
|
|
result = dns_message_firstname(msg, DNS_SECTION_ANSWER);
|
2000-06-06 22:50:44 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
puts("; Transfer failed.");
|
2000-06-30 22:53:07 +00:00
|
|
|
return (ISC_TRUE);
|
2000-06-06 22:50:44 +00:00
|
|
|
}
|
2000-06-02 18:45:33 +00:00
|
|
|
do {
|
2000-08-03 17:43:06 +00:00
|
|
|
dns_name_t *name;
|
|
|
|
name = NULL;
|
2000-06-02 18:45:33 +00:00
|
|
|
dns_message_currentname(msg, DNS_SECTION_ANSWER,
|
|
|
|
&name);
|
2000-11-08 01:23:27 +00:00
|
|
|
for (rdataset = ISC_LIST_HEAD(name->list);
|
2000-06-02 18:45:33 +00:00
|
|
|
rdataset != NULL;
|
|
|
|
rdataset = ISC_LIST_NEXT(rdataset, link)) {
|
|
|
|
result = dns_rdataset_first(rdataset);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
continue;
|
|
|
|
do {
|
2000-07-20 19:41:44 +00:00
|
|
|
query->rr_count++;
|
2000-10-31 03:22:05 +00:00
|
|
|
dns_rdata_reset(&rdata);
|
2000-06-02 18:45:33 +00:00
|
|
|
dns_rdataset_current(rdataset, &rdata);
|
|
|
|
/*
|
|
|
|
* If this is the first rr, make sure
|
|
|
|
* it's an SOA
|
|
|
|
*/
|
|
|
|
if ((!query->first_soa_rcvd) &&
|
|
|
|
(rdata.type != dns_rdatatype_soa)) {
|
|
|
|
puts("; Transfer failed. "
|
|
|
|
"Didn't start with "
|
|
|
|
"SOA answer.");
|
2000-06-30 22:53:07 +00:00
|
|
|
return (ISC_TRUE);
|
2000-06-02 18:45:33 +00:00
|
|
|
}
|
|
|
|
if ((!query->second_rr_rcvd) &&
|
|
|
|
(rdata.type != dns_rdatatype_soa)) {
|
|
|
|
query->second_rr_rcvd = ISC_TRUE;
|
|
|
|
query->second_rr_serial = 0;
|
2000-07-05 23:28:32 +00:00
|
|
|
debug("got the second rr as nonsoa");
|
2000-06-02 18:45:33 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the record is anything except an SOA
|
|
|
|
* now, just continue on...
|
|
|
|
*/
|
|
|
|
if (rdata.type != dns_rdatatype_soa)
|
2000-07-05 19:31:26 +00:00
|
|
|
goto next_rdata;
|
2000-06-02 18:45:33 +00:00
|
|
|
/* Now we have an SOA. Work with it. */
|
2000-07-05 23:28:32 +00:00
|
|
|
debug("got an SOA");
|
2000-06-02 18:45:33 +00:00
|
|
|
result = dns_rdata_tostruct(&rdata,
|
|
|
|
&soa,
|
|
|
|
mctx);
|
|
|
|
check_result(result,
|
|
|
|
"dns_rdata_tostruct");
|
|
|
|
if (!query->first_soa_rcvd) {
|
|
|
|
query->first_soa_rcvd =
|
|
|
|
ISC_TRUE;
|
|
|
|
query->first_rr_serial =
|
|
|
|
soa.serial;
|
2000-07-05 23:28:32 +00:00
|
|
|
debug("this is the first %d",
|
2000-06-06 00:43:17 +00:00
|
|
|
query->lookup->ixfr_serial);
|
2000-06-02 18:45:33 +00:00
|
|
|
if (query->lookup->ixfr_serial >=
|
|
|
|
soa.serial) {
|
|
|
|
dns_rdata_freestruct(&soa);
|
2000-08-03 17:43:06 +00:00
|
|
|
goto doexit;
|
2000-06-02 18:45:33 +00:00
|
|
|
}
|
|
|
|
dns_rdata_freestruct(&soa);
|
2000-07-05 19:31:26 +00:00
|
|
|
goto next_rdata;
|
2000-06-02 18:45:33 +00:00
|
|
|
}
|
2000-07-28 21:56:53 +00:00
|
|
|
if (query->lookup->rdtype ==
|
|
|
|
dns_rdatatype_axfr) {
|
|
|
|
debug("doing axfr, got second SOA");
|
|
|
|
dns_rdata_freestruct(&soa);
|
2000-08-03 17:43:06 +00:00
|
|
|
goto doexit;
|
2000-07-28 21:56:53 +00:00
|
|
|
}
|
2000-06-02 18:45:33 +00:00
|
|
|
if (!query->second_rr_rcvd) {
|
2000-07-28 21:56:53 +00:00
|
|
|
if (soa.serial ==
|
|
|
|
query->first_rr_serial) {
|
|
|
|
debug("doing ixfr, got "
|
|
|
|
"empty zone");
|
|
|
|
dns_rdata_freestruct(&soa);
|
2000-08-03 17:43:06 +00:00
|
|
|
goto doexit;
|
2000-07-28 21:56:53 +00:00
|
|
|
}
|
2000-07-05 23:28:32 +00:00
|
|
|
debug("this is the second %d",
|
2000-06-06 00:43:17 +00:00
|
|
|
query->lookup->ixfr_serial);
|
2000-06-02 18:45:33 +00:00
|
|
|
query->second_rr_rcvd = ISC_TRUE;
|
|
|
|
query->second_rr_serial =
|
|
|
|
soa.serial;
|
2000-06-27 23:18:14 +00:00
|
|
|
dns_rdata_freestruct(&soa);
|
2000-07-05 19:31:26 +00:00
|
|
|
goto next_rdata;
|
2000-06-02 18:45:33 +00:00
|
|
|
}
|
|
|
|
if (query->second_rr_serial == 0) {
|
|
|
|
/*
|
|
|
|
* If the second RR was a non-SOA
|
|
|
|
* record, and we're getting any
|
|
|
|
* other SOA, then this is an
|
|
|
|
* AXFR, and we're done.
|
|
|
|
*/
|
2000-07-05 23:28:32 +00:00
|
|
|
debug("done, since axfr");
|
2000-06-02 18:45:33 +00:00
|
|
|
dns_rdata_freestruct(&soa);
|
2000-08-03 17:43:06 +00:00
|
|
|
goto doexit;
|
2000-06-02 18:45:33 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* If we get to this point, we're doing an
|
|
|
|
* IXFR and have to start really looking
|
|
|
|
* at serial numbers.
|
|
|
|
*/
|
2000-06-06 00:43:17 +00:00
|
|
|
if (query->first_rr_serial == soa.serial) {
|
2000-07-05 23:28:32 +00:00
|
|
|
debug("got a match for ixfr");
|
2000-06-02 18:45:33 +00:00
|
|
|
if (!query->first_repeat_rcvd) {
|
|
|
|
query->first_repeat_rcvd =
|
|
|
|
ISC_TRUE;
|
|
|
|
dns_rdata_freestruct(&soa);
|
2000-07-05 19:31:26 +00:00
|
|
|
goto next_rdata;
|
2000-06-02 18:45:33 +00:00
|
|
|
}
|
2000-07-05 23:28:32 +00:00
|
|
|
debug("done with ixfr");
|
2000-06-02 18:45:33 +00:00
|
|
|
dns_rdata_freestruct(&soa);
|
2000-08-03 17:43:06 +00:00
|
|
|
goto doexit;
|
2000-06-02 18:45:33 +00:00
|
|
|
}
|
2000-07-05 23:28:32 +00:00
|
|
|
debug("meaningless soa %d",
|
2000-06-06 00:43:17 +00:00
|
|
|
soa.serial);
|
2000-06-02 18:45:33 +00:00
|
|
|
dns_rdata_freestruct(&soa);
|
2000-07-05 19:31:26 +00:00
|
|
|
next_rdata:
|
2000-06-02 18:45:33 +00:00
|
|
|
result = dns_rdataset_next(rdataset);
|
|
|
|
} while (result == ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
result = dns_message_nextname(msg, DNS_SECTION_ANSWER);
|
|
|
|
} while (result == ISC_R_SUCCESS);
|
|
|
|
launch_next_query(query, ISC_FALSE);
|
2000-06-30 22:53:07 +00:00
|
|
|
return (ISC_FALSE);
|
2001-03-28 03:09:47 +00:00
|
|
|
doexit:
|
2001-07-22 18:06:40 +00:00
|
|
|
received(0, &sevent->address, query);
|
2001-03-28 03:09:47 +00:00
|
|
|
return (ISC_TRUE);
|
2000-06-02 18:45:33 +00:00
|
|
|
}
|
2000-04-26 18:34:17 +00:00
|
|
|
|
2000-07-18 18:51:40 +00:00
|
|
|
/*
|
|
|
|
* Event handler for recv complete. Perform whatever actions are necessary,
|
|
|
|
* based on the specifics of the user's request.
|
|
|
|
*/
|
2000-04-26 18:34:17 +00:00
|
|
|
static void
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
recv_done(isc_task_t *task, isc_event_t *event) {
|
|
|
|
isc_socketevent_t *sevent = NULL;
|
|
|
|
dig_query_t *query = NULL;
|
|
|
|
isc_buffer_t *b = NULL;
|
|
|
|
dns_message_t *msg = NULL;
|
2000-04-26 18:34:17 +00:00
|
|
|
isc_result_t result;
|
2000-07-13 00:32:20 +00:00
|
|
|
dig_lookup_t *n, *l;
|
2000-06-30 22:53:07 +00:00
|
|
|
isc_boolean_t docancel = ISC_FALSE;
|
2000-07-10 17:25:59 +00:00
|
|
|
unsigned int local_timeout;
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2000-07-05 19:31:26 +00:00
|
|
|
UNUSED(task);
|
2000-07-13 00:32:20 +00:00
|
|
|
INSIST(!free_now);
|
2000-04-26 18:34:17 +00:00
|
|
|
|
2000-07-05 19:31:26 +00:00
|
|
|
debug("recv_done()");
|
2000-05-25 19:32:11 +00:00
|
|
|
|
2000-07-14 17:57:27 +00:00
|
|
|
LOCK_LOOKUP;
|
2000-07-13 00:32:20 +00:00
|
|
|
recvcount--;
|
|
|
|
debug("recvcount=%d", recvcount);
|
|
|
|
INSIST(recvcount >= 0);
|
2000-05-22 22:56:31 +00:00
|
|
|
|
2000-05-12 18:45:38 +00:00
|
|
|
query = event->ev_arg;
|
2000-07-05 23:28:32 +00:00
|
|
|
debug("lookup=%p, query=%p", query->lookup, query);
|
2000-04-29 00:12:56 +00:00
|
|
|
|
2000-07-13 00:32:20 +00:00
|
|
|
l = query->lookup;
|
2000-04-29 00:12:56 +00:00
|
|
|
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
REQUIRE(event->ev_type == ISC_SOCKEVENT_RECVDONE);
|
2000-04-26 18:34:17 +00:00
|
|
|
sevent = (isc_socketevent_t *)event;
|
|
|
|
|
2000-07-13 00:32:20 +00:00
|
|
|
if ((l->tcp_mode) && (l->timer != NULL))
|
|
|
|
isc_timer_touch(l->timer);
|
2001-02-13 23:12:17 +00:00
|
|
|
if ((!l->pending && !l->ns_search_only && !l->ns_search_only_leafnode)
|
2000-07-14 17:57:27 +00:00
|
|
|
|| cancel_now) {
|
2000-07-05 23:28:32 +00:00
|
|
|
debug("no longer pending. Got %s",
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_result_totext(sevent->result));
|
2000-04-26 18:34:17 +00:00
|
|
|
query->waiting_connect = ISC_FALSE;
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2000-05-26 00:48:18 +00:00
|
|
|
isc_event_free(&event);
|
2000-07-13 00:32:20 +00:00
|
|
|
clear_query(query);
|
|
|
|
check_next_lookup(l);
|
2000-07-14 17:57:27 +00:00
|
|
|
UNLOCK_LOOKUP;
|
2000-04-26 18:34:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sevent->result == ISC_R_SUCCESS) {
|
|
|
|
b = ISC_LIST_HEAD(sevent->bufferlist);
|
|
|
|
ISC_LIST_DEQUEUE(sevent->bufferlist, &query->recvbuf, link);
|
|
|
|
result = dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE,
|
|
|
|
&msg);
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
check_result(result, "dns_message_create");
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2000-06-07 00:13:57 +00:00
|
|
|
if (key != NULL) {
|
2000-07-13 00:32:20 +00:00
|
|
|
if (l->querysig == NULL) {
|
2000-07-05 23:28:32 +00:00
|
|
|
debug("getting initial querysig");
|
2000-06-06 22:50:44 +00:00
|
|
|
result = dns_message_getquerytsig(
|
2000-07-13 00:32:20 +00:00
|
|
|
l->sendmsg,
|
|
|
|
mctx, &l->querysig);
|
2000-06-06 22:50:44 +00:00
|
|
|
check_result(result,
|
|
|
|
"dns_message_getquerytsig");
|
|
|
|
}
|
|
|
|
result = dns_message_setquerytsig(msg,
|
2000-07-13 00:32:20 +00:00
|
|
|
l->querysig);
|
2000-06-06 18:49:06 +00:00
|
|
|
check_result(result, "dns_message_setquerytsig");
|
|
|
|
result = dns_message_settsigkey(msg, key);
|
|
|
|
check_result(result, "dns_message_settsigkey");
|
2000-07-13 00:32:20 +00:00
|
|
|
msg->tsigctx = l->tsigctx;
|
2000-08-01 01:33:37 +00:00
|
|
|
if (l->msgcounter != 0)
|
2000-06-06 22:50:44 +00:00
|
|
|
msg->tcp_continuation = 1;
|
2000-07-13 00:32:20 +00:00
|
|
|
l->msgcounter++;
|
2000-06-06 18:49:06 +00:00
|
|
|
}
|
2000-07-05 23:28:32 +00:00
|
|
|
debug("before parse starts");
|
2000-10-13 17:54:00 +00:00
|
|
|
if (l->besteffort)
|
|
|
|
result = dns_message_parse(msg, b,
|
|
|
|
DNS_MESSAGEPARSE_PRESERVEORDER
|
|
|
|
|DNS_MESSAGEPARSE_BESTEFFORT);
|
|
|
|
else
|
|
|
|
result = dns_message_parse(msg, b,
|
2000-10-12 01:16:12 +00:00
|
|
|
DNS_MESSAGEPARSE_PRESERVEORDER);
|
2000-10-13 17:54:00 +00:00
|
|
|
if (result != ISC_R_SUCCESS &&
|
|
|
|
result != DNS_R_RECOVERABLE ) {
|
2000-09-11 19:38:22 +00:00
|
|
|
printf(";; Got bad packet: %s\n",
|
|
|
|
dns_result_totext(result));
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
hex_dump(b);
|
2000-05-12 01:02:37 +00:00
|
|
|
query->waiting_connect = ISC_FALSE;
|
|
|
|
dns_message_destroy(&msg);
|
2000-05-26 00:48:18 +00:00
|
|
|
isc_event_free(&event);
|
2000-07-13 00:32:20 +00:00
|
|
|
clear_query(query);
|
|
|
|
cancel_lookup(l);
|
|
|
|
check_next_lookup(l);
|
2000-07-14 17:57:27 +00:00
|
|
|
UNLOCK_LOOKUP;
|
2000-05-12 01:02:37 +00:00
|
|
|
return;
|
|
|
|
}
|
2000-10-13 17:54:00 +00:00
|
|
|
if (result == DNS_R_RECOVERABLE)
|
|
|
|
printf(";; Warning: Message parser reports malformed "
|
|
|
|
"message packet.\n");
|
2000-09-13 00:03:28 +00:00
|
|
|
if (((msg->flags & DNS_MESSAGEFLAG_TC) != 0)
|
2000-09-13 08:02:11 +00:00
|
|
|
&& ! l->ignore && !l->tcp_mode) {
|
2000-09-11 19:38:22 +00:00
|
|
|
printf(";; Truncated, retrying in TCP mode.\n");
|
|
|
|
n = requeue_lookup(l, ISC_TRUE);
|
|
|
|
n->tcp_mode = ISC_TRUE;
|
|
|
|
dns_message_destroy(&msg);
|
|
|
|
isc_event_free(&event);
|
|
|
|
clear_query(query);
|
|
|
|
cancel_lookup(l);
|
|
|
|
check_next_lookup(l);
|
|
|
|
UNLOCK_LOOKUP;
|
|
|
|
return;
|
|
|
|
}
|
2000-09-25 23:10:00 +00:00
|
|
|
if ((msg->rcode == dns_rcode_servfail) &&
|
2000-09-28 23:02:28 +00:00
|
|
|
l->servfail_stops) {
|
2000-09-25 23:10:00 +00:00
|
|
|
dig_query_t *next = ISC_LIST_NEXT(query, link);
|
|
|
|
if (l->current_query == query)
|
|
|
|
l->current_query = NULL;
|
|
|
|
if (next != NULL) {
|
|
|
|
debug("sending query %lx\n", next);
|
|
|
|
if (l->tcp_mode)
|
|
|
|
send_tcp_connect(next);
|
|
|
|
else
|
|
|
|
send_udp(next);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* If our query is at the head of the list and there
|
|
|
|
* is no next, we're the only one left, so fall
|
|
|
|
* through to print the message.
|
|
|
|
*/
|
|
|
|
if ((ISC_LIST_HEAD(l->q) != query) ||
|
|
|
|
(ISC_LIST_NEXT(query, link) != NULL)) {
|
|
|
|
printf(";; Got SERVFAIL reply from %s, "
|
|
|
|
"trying next server\n",
|
|
|
|
query->servname);
|
|
|
|
clear_query(query);
|
|
|
|
check_next_lookup(l);
|
|
|
|
dns_message_destroy(&msg);
|
|
|
|
isc_event_free(&event);
|
|
|
|
UNLOCK_LOOKUP;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2000-09-11 19:38:22 +00:00
|
|
|
|
2000-06-07 00:13:57 +00:00
|
|
|
if (key != NULL) {
|
2000-06-06 18:49:06 +00:00
|
|
|
result = dns_tsig_verify(&query->recvbuf, msg,
|
2000-07-21 22:26:08 +00:00
|
|
|
NULL, NULL);
|
2000-06-06 18:49:06 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-07-05 19:31:26 +00:00
|
|
|
printf(";; Couldn't verify signature: %s\n",
|
|
|
|
dns_result_totext(result));
|
2000-06-06 18:49:06 +00:00
|
|
|
validated = ISC_FALSE;
|
|
|
|
}
|
2000-07-13 00:32:20 +00:00
|
|
|
l->tsigctx = msg->tsigctx;
|
|
|
|
if (l->querysig != NULL) {
|
2000-07-05 23:28:32 +00:00
|
|
|
debug("freeing querysig buffer %p",
|
2000-07-13 00:32:20 +00:00
|
|
|
l->querysig);
|
|
|
|
isc_buffer_free(&l->querysig);
|
2000-06-06 22:50:44 +00:00
|
|
|
}
|
2000-06-07 00:13:57 +00:00
|
|
|
result = dns_message_getquerytsig(msg, mctx,
|
2000-07-13 00:32:20 +00:00
|
|
|
&l->querysig);
|
2000-06-06 22:50:44 +00:00
|
|
|
check_result(result,"dns_message_getquerytsig");
|
2000-07-13 00:32:20 +00:00
|
|
|
debug("querysig 3 is %p", l->querysig);
|
2000-06-06 18:49:06 +00:00
|
|
|
}
|
2000-07-05 23:28:32 +00:00
|
|
|
debug("after parse");
|
2000-07-13 00:32:20 +00:00
|
|
|
if (l->xfr_q == NULL) {
|
|
|
|
l->xfr_q = query;
|
2000-07-10 17:25:59 +00:00
|
|
|
/*
|
|
|
|
* Once we are in the XFR message, increase
|
|
|
|
* the timeout to much longer, so brief network
|
|
|
|
* outages won't cause the XFR to abort
|
|
|
|
*/
|
2000-07-11 17:35:49 +00:00
|
|
|
if ((timeout != INT_MAX) &&
|
2000-07-14 21:33:03 +00:00
|
|
|
(l->timer != NULL) &&
|
|
|
|
l->doing_xfr ) {
|
2000-07-10 17:25:59 +00:00
|
|
|
if (timeout == 0) {
|
2000-07-13 00:32:20 +00:00
|
|
|
if (l->tcp_mode)
|
2000-07-10 17:25:59 +00:00
|
|
|
local_timeout = TCP_TIMEOUT;
|
|
|
|
else
|
|
|
|
local_timeout = UDP_TIMEOUT;
|
|
|
|
} else {
|
2000-07-11 17:35:49 +00:00
|
|
|
if (timeout < (INT_MAX / 4))
|
2000-07-10 17:25:59 +00:00
|
|
|
local_timeout = timeout * 4;
|
|
|
|
else
|
|
|
|
local_timeout = INT_MAX;
|
|
|
|
}
|
2000-07-12 00:22:57 +00:00
|
|
|
debug("have local timeout of %d",
|
2000-08-01 01:33:37 +00:00
|
|
|
local_timeout);
|
2000-07-13 00:32:20 +00:00
|
|
|
isc_interval_set(&l->interval,
|
2000-07-10 17:25:59 +00:00
|
|
|
local_timeout, 0);
|
2000-07-13 00:32:20 +00:00
|
|
|
result = isc_timer_reset(l->timer,
|
2000-07-10 17:25:59 +00:00
|
|
|
isc_timertype_once,
|
|
|
|
NULL,
|
2000-07-13 00:32:20 +00:00
|
|
|
&l->interval,
|
2000-07-10 17:25:59 +00:00
|
|
|
ISC_FALSE);
|
2000-07-11 17:49:02 +00:00
|
|
|
check_result(result, "isc_timer_reset");
|
2000-07-10 17:25:59 +00:00
|
|
|
}
|
|
|
|
}
|
2000-07-13 00:32:20 +00:00
|
|
|
if (l->xfr_q == query) {
|
|
|
|
if ((l->trace)||
|
|
|
|
(l->ns_search_only)) {
|
2000-07-05 23:28:32 +00:00
|
|
|
debug("in TRACE code");
|
2000-09-27 00:02:02 +00:00
|
|
|
printmessage(query, msg, ISC_TRUE);
|
2000-05-04 21:40:47 +00:00
|
|
|
if ((msg->rcode != 0) &&
|
2000-07-13 00:32:20 +00:00
|
|
|
(l->origin != NULL)) {
|
2000-08-01 00:53:20 +00:00
|
|
|
if (!next_origin(msg, query)) {
|
2000-07-24 18:07:03 +00:00
|
|
|
printmessage(query, msg,
|
|
|
|
ISC_TRUE);
|
2001-01-24 19:28:34 +00:00
|
|
|
received(b->used,
|
|
|
|
&sevent->address,
|
2000-08-01 00:53:20 +00:00
|
|
|
query);
|
|
|
|
}
|
2000-05-06 01:16:07 +00:00
|
|
|
} else {
|
|
|
|
result = dns_message_firstname
|
|
|
|
(msg,DNS_SECTION_ANSWER);
|
2001-02-13 23:12:17 +00:00
|
|
|
if (l->ns_search_only)
|
|
|
|
{
|
|
|
|
if ((result != ISC_R_SUCCESS) || l->trace_root)
|
|
|
|
{
|
2001-02-15 23:44:08 +00:00
|
|
|
/*
|
|
|
|
* We didn't get an
|
2001-02-13 23:12:17 +00:00
|
|
|
* answer section,
|
|
|
|
* or else this is
|
|
|
|
* the first initial
|
|
|
|
* SOA query (in which
|
|
|
|
* case we will in fact
|
|
|
|
* get an answer
|
|
|
|
* section but it won't
|
|
|
|
* be the right one).
|
|
|
|
* In either case,
|
|
|
|
* our next query
|
2001-02-15 23:44:08 +00:00
|
|
|
* should be an NS.
|
|
|
|
*/
|
2001-02-13 23:12:17 +00:00
|
|
|
l->rdtype = dns_rdatatype_ns;
|
2001-06-11 18:08:16 +00:00
|
|
|
} else {
|
2001-02-15 23:44:08 +00:00
|
|
|
/*
|
|
|
|
* We got an answer
|
2001-02-13 23:12:17 +00:00
|
|
|
* section for our
|
|
|
|
* NS query! Yay!
|
|
|
|
* Now we shift gears,
|
|
|
|
* set the leafnode bit
|
|
|
|
* and look for SOAs
|
|
|
|
* in all the servers
|
|
|
|
* we got back in our
|
2001-02-15 23:44:08 +00:00
|
|
|
* answer section.
|
|
|
|
*/
|
2001-02-13 23:12:17 +00:00
|
|
|
l->rdtype = dns_rdatatype_soa;
|
|
|
|
l->ns_search_only_leafnode = ISC_TRUE;
|
|
|
|
if (followup_lookup(msg, query,
|
|
|
|
DNS_SECTION_ANSWER) == 0)
|
|
|
|
{
|
|
|
|
docancel = ISC_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-05-06 01:16:07 +00:00
|
|
|
if ((result != ISC_R_SUCCESS) ||
|
2000-07-13 00:32:20 +00:00
|
|
|
l->trace_root)
|
2001-02-13 23:12:17 +00:00
|
|
|
{
|
2001-02-15 23:44:08 +00:00
|
|
|
/*
|
|
|
|
* This is executed regardless
|
|
|
|
* of whether we're doing
|
|
|
|
* ns_search_only, but because
|
2001-02-13 23:12:17 +00:00
|
|
|
* of the way the logic works,
|
|
|
|
* it's mutually exclusive
|
|
|
|
* with the other call to
|
|
|
|
* followup_lookup above. This
|
|
|
|
* is a good thing because we
|
|
|
|
* want to call followup_lookup
|
|
|
|
* at most once per query.
|
|
|
|
*
|
|
|
|
* The idea here is that
|
|
|
|
* if we didn't get an answer
|
|
|
|
* section (or if it's the
|
|
|
|
* initial root query) then
|
|
|
|
* we want to take whatever is
|
|
|
|
* in the authority section and
|
2001-02-15 23:44:08 +00:00
|
|
|
* follow up with them.
|
|
|
|
*/
|
2001-02-13 23:12:17 +00:00
|
|
|
if (followup_lookup(msg, query,
|
|
|
|
DNS_SECTION_AUTHORITY)
|
|
|
|
== 0)
|
|
|
|
{
|
|
|
|
docancel = ISC_TRUE;
|
|
|
|
}
|
|
|
|
}
|
2000-05-06 01:16:07 +00:00
|
|
|
}
|
2000-05-04 21:40:47 +00:00
|
|
|
} else if ((msg->rcode != 0) &&
|
2000-07-13 00:32:20 +00:00
|
|
|
(l->origin != NULL)) {
|
2000-08-01 00:53:20 +00:00
|
|
|
if (!next_origin(msg, query)) {
|
2000-07-24 18:07:03 +00:00
|
|
|
printmessage(query, msg,
|
|
|
|
ISC_TRUE);
|
2001-01-24 19:28:34 +00:00
|
|
|
received(b->used,
|
|
|
|
&sevent->address,
|
2000-08-01 00:53:20 +00:00
|
|
|
query);
|
|
|
|
}
|
2000-05-02 23:23:12 +00:00
|
|
|
} else {
|
2000-10-19 22:49:34 +00:00
|
|
|
printmessage(query, msg, ISC_TRUE);
|
2000-04-28 21:41:19 +00:00
|
|
|
}
|
2000-07-05 19:31:26 +00:00
|
|
|
} else if ((dns_message_firstname(msg, DNS_SECTION_ANSWER)
|
2000-05-06 01:16:07 +00:00
|
|
|
== ISC_R_SUCCESS) &&
|
2001-02-13 23:12:17 +00:00
|
|
|
(l->ns_search_only || l->ns_search_only_leafnode) &&
|
2000-07-13 00:32:20 +00:00
|
|
|
!l->trace_root ) {
|
2000-07-05 19:31:26 +00:00
|
|
|
printmessage(query, msg, ISC_TRUE);
|
2000-04-26 18:34:17 +00:00
|
|
|
}
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2000-07-13 00:32:20 +00:00
|
|
|
if (l->pending)
|
2000-07-05 23:28:32 +00:00
|
|
|
debug("still pending.");
|
2000-07-13 00:32:20 +00:00
|
|
|
if (l->doing_xfr) {
|
|
|
|
if (query != l->xfr_q) {
|
2000-07-05 19:31:26 +00:00
|
|
|
dns_message_destroy(&msg);
|
2000-05-31 23:51:14 +00:00
|
|
|
isc_event_free (&event);
|
|
|
|
query->waiting_connect = ISC_FALSE;
|
2000-07-14 17:57:27 +00:00
|
|
|
UNLOCK_LOOKUP;
|
2000-05-31 23:51:14 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-02-17 00:41:03 +00:00
|
|
|
if (! docancel)
|
|
|
|
docancel = check_for_more_data(query, msg, sevent);
|
2000-06-30 22:53:07 +00:00
|
|
|
if (docancel) {
|
|
|
|
dns_message_destroy(&msg);
|
2000-07-13 00:32:20 +00:00
|
|
|
clear_query(query);
|
|
|
|
cancel_lookup(l);
|
2000-07-18 01:28:20 +00:00
|
|
|
check_next_lookup(l);
|
2000-06-30 22:53:07 +00:00
|
|
|
}
|
2000-07-05 23:28:32 +00:00
|
|
|
if (msg != NULL)
|
|
|
|
dns_message_destroy(&msg);
|
|
|
|
isc_event_free(&event);
|
2001-06-11 18:08:16 +00:00
|
|
|
} else {
|
2000-05-02 23:23:12 +00:00
|
|
|
if ((msg->rcode == 0) ||
|
2000-07-13 00:32:20 +00:00
|
|
|
(l->origin == NULL)) {
|
2001-01-24 19:28:34 +00:00
|
|
|
received(b->used,
|
|
|
|
&sevent->address,
|
2000-07-24 18:07:03 +00:00
|
|
|
query);
|
2000-05-02 23:23:12 +00:00
|
|
|
}
|
2001-03-14 23:13:57 +00:00
|
|
|
if (!(query->lookup->ns_search_only ||
|
|
|
|
query->lookup->ns_search_only_leafnode))
|
2001-02-13 23:12:17 +00:00
|
|
|
query->lookup->pending = ISC_FALSE;
|
2001-03-14 23:13:57 +00:00
|
|
|
if (!(query->lookup->ns_search_only ||
|
|
|
|
query->lookup->ns_search_only_leafnode) ||
|
2001-02-13 23:12:17 +00:00
|
|
|
query->lookup->trace_root || docancel) {
|
2000-06-30 22:53:07 +00:00
|
|
|
dns_message_destroy(&msg);
|
2000-07-13 00:32:20 +00:00
|
|
|
cancel_lookup(l);
|
2000-05-06 01:16:07 +00:00
|
|
|
}
|
2000-07-05 23:28:32 +00:00
|
|
|
if (msg != NULL)
|
|
|
|
dns_message_destroy(&msg);
|
|
|
|
isc_event_free(&event);
|
2000-07-13 00:32:20 +00:00
|
|
|
clear_query(query);
|
|
|
|
check_next_lookup(l);
|
2000-04-26 18:34:17 +00:00
|
|
|
}
|
2000-07-14 17:57:27 +00:00
|
|
|
UNLOCK_LOOKUP;
|
2000-04-26 18:34:17 +00:00
|
|
|
return;
|
|
|
|
}
|
2000-07-05 19:31:26 +00:00
|
|
|
/*
|
|
|
|
* In truth, we should never get into the CANCELED routine, since
|
|
|
|
* the cancel_lookup() routine clears the pending flag.
|
2000-08-01 00:53:20 +00:00
|
|
|
* XXX Is this true anymore, since the bulk changes?
|
2000-07-05 19:31:26 +00:00
|
|
|
*/
|
2000-04-26 18:34:17 +00:00
|
|
|
if (sevent->result == ISC_R_CANCELED) {
|
2000-07-13 22:53:51 +00:00
|
|
|
debug("in recv cancel handler");
|
2000-04-26 18:34:17 +00:00
|
|
|
query->waiting_connect = ISC_FALSE;
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_event_free(&event);
|
2000-07-13 00:32:20 +00:00
|
|
|
clear_query(query);
|
|
|
|
check_next_lookup(l);
|
2000-07-14 17:57:27 +00:00
|
|
|
UNLOCK_LOOKUP;
|
2000-04-26 18:34:17 +00:00
|
|
|
return;
|
|
|
|
}
|
2000-08-02 14:38:51 +00:00
|
|
|
printf(";; communications error: %s\n",
|
|
|
|
isc_result_totext(sevent->result));
|
|
|
|
isc_socket_detach(&query->sock);
|
|
|
|
sockcount--;
|
2000-11-21 20:52:24 +00:00
|
|
|
debug("sockcount=%d", sockcount);
|
2000-08-02 14:38:51 +00:00
|
|
|
INSIST(sockcount >= 0);
|
|
|
|
isc_event_free(&event);
|
|
|
|
clear_query(query);
|
|
|
|
check_next_lookup(l);
|
|
|
|
UNLOCK_LOOKUP;
|
|
|
|
return;
|
2000-04-26 18:34:17 +00:00
|
|
|
}
|
|
|
|
|
2000-07-18 18:51:40 +00:00
|
|
|
/*
|
|
|
|
* Turn a name into an address, using system-supplied routines. This is
|
|
|
|
* used in looking up server names, etc... and needs to use system-supplied
|
|
|
|
* routines, since they may be using a non-DNS system for these lookups.
|
|
|
|
*/
|
2000-05-16 17:53:35 +00:00
|
|
|
void
|
2000-09-21 23:02:34 +00:00
|
|
|
get_address(char *host, in_port_t port, isc_sockaddr_t *sockaddr) {
|
2000-04-26 18:34:17 +00:00
|
|
|
struct in_addr in4;
|
|
|
|
struct in6_addr in6;
|
2001-01-18 22:21:31 +00:00
|
|
|
#ifdef USE_GETADDRINFO
|
2001-02-24 20:53:26 +00:00
|
|
|
struct addrinfo *res = NULL, hints;
|
2000-06-15 19:05:30 +00:00
|
|
|
int result;
|
|
|
|
#else
|
2000-04-26 18:34:17 +00:00
|
|
|
struct hostent *he;
|
2000-06-15 19:05:30 +00:00
|
|
|
#endif
|
2000-04-26 18:34:17 +00:00
|
|
|
|
2000-04-29 00:12:56 +00:00
|
|
|
debug("get_address()");
|
|
|
|
|
2000-11-21 21:35:32 +00:00
|
|
|
/*
|
|
|
|
* Assume we have v4 if we don't have v6, since setup_libs
|
|
|
|
* fatal()'s out if we don't have either.
|
|
|
|
*/
|
2000-04-29 01:39:32 +00:00
|
|
|
if (have_ipv6 && inet_pton(AF_INET6, host, &in6) == 1)
|
2000-04-26 18:34:17 +00:00
|
|
|
isc_sockaddr_fromin6(sockaddr, &in6, port);
|
2000-04-29 01:39:32 +00:00
|
|
|
else if (inet_pton(AF_INET, host, &in4) == 1)
|
2000-04-26 18:34:17 +00:00
|
|
|
isc_sockaddr_fromin(sockaddr, &in4, port);
|
|
|
|
else {
|
2001-01-18 22:21:31 +00:00
|
|
|
#ifdef USE_GETADDRINFO
|
2001-02-24 20:53:26 +00:00
|
|
|
memset(&hints, 0, sizeof(hints));
|
|
|
|
if (!have_ipv6)
|
|
|
|
hints.ai_family = PF_INET;
|
|
|
|
else if (!have_ipv4)
|
|
|
|
hints.ai_family = PF_INET6;
|
|
|
|
else
|
|
|
|
hints.ai_family = PF_UNSPEC;
|
2000-09-12 22:42:17 +00:00
|
|
|
debug ("before getaddrinfo()");
|
2001-01-17 00:48:19 +00:00
|
|
|
isc_app_block();
|
2001-02-24 20:53:26 +00:00
|
|
|
result = getaddrinfo(host, NULL, &hints, &res);
|
2001-01-17 00:48:19 +00:00
|
|
|
isc_app_unblock();
|
2000-06-15 19:05:30 +00:00
|
|
|
if (result != 0) {
|
2000-07-05 19:31:26 +00:00
|
|
|
fatal("Couldn't find server '%s': %s",
|
|
|
|
host, gai_strerror(result));
|
2000-06-15 19:05:30 +00:00
|
|
|
}
|
2001-03-05 21:15:47 +00:00
|
|
|
memcpy(&sockaddr->type.sa, res->ai_addr, res->ai_addrlen);
|
2000-06-15 19:05:30 +00:00
|
|
|
sockaddr->length = res->ai_addrlen;
|
|
|
|
isc_sockaddr_setport(sockaddr, port);
|
2000-06-15 22:08:44 +00:00
|
|
|
freeaddrinfo(res);
|
2000-06-15 19:05:30 +00:00
|
|
|
#else
|
2000-09-12 22:42:17 +00:00
|
|
|
debug ("before gethostbyname()");
|
2001-01-17 00:48:19 +00:00
|
|
|
isc_app_block();
|
2000-04-29 01:39:32 +00:00
|
|
|
he = gethostbyname(host);
|
2001-01-17 00:48:19 +00:00
|
|
|
isc_app_unblock();
|
2000-04-26 18:34:17 +00:00
|
|
|
if (he == NULL)
|
2000-07-05 19:31:26 +00:00
|
|
|
fatal("Couldn't find server '%s' (h_errno=%d)",
|
|
|
|
host, h_errno);
|
2000-04-26 18:34:17 +00:00
|
|
|
INSIST(he->h_addrtype == AF_INET);
|
|
|
|
isc_sockaddr_fromin(sockaddr,
|
|
|
|
(struct in_addr *)(he->h_addr_list[0]),
|
|
|
|
port);
|
2000-06-15 19:05:30 +00:00
|
|
|
#endif
|
2000-04-26 18:34:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-07-18 18:51:40 +00:00
|
|
|
/*
|
|
|
|
* Initiate either a TCP or UDP lookup
|
|
|
|
*/
|
2000-05-12 01:02:37 +00:00
|
|
|
void
|
|
|
|
do_lookup(dig_lookup_t *lookup) {
|
|
|
|
|
2000-07-05 19:31:26 +00:00
|
|
|
REQUIRE(lookup != NULL);
|
2000-05-12 01:02:37 +00:00
|
|
|
|
2000-07-05 19:31:26 +00:00
|
|
|
debug("do_lookup()");
|
2000-09-21 22:46:39 +00:00
|
|
|
lookup->pending = ISC_TRUE;
|
2000-05-12 01:02:37 +00:00
|
|
|
if (lookup->tcp_mode)
|
2000-09-21 22:46:39 +00:00
|
|
|
send_tcp_connect(ISC_LIST_HEAD(lookup->q));
|
2000-05-12 01:02:37 +00:00
|
|
|
else
|
2000-09-21 22:46:39 +00:00
|
|
|
send_udp(ISC_LIST_HEAD(lookup->q));
|
2000-05-12 01:02:37 +00:00
|
|
|
}
|
|
|
|
|
2000-07-18 18:51:40 +00:00
|
|
|
/*
|
|
|
|
* Start everything in action upon task startup.
|
|
|
|
*/
|
2000-07-10 18:02:31 +00:00
|
|
|
void
|
|
|
|
onrun_callback(isc_task_t *task, isc_event_t *event) {
|
|
|
|
UNUSED(task);
|
2000-08-01 00:53:20 +00:00
|
|
|
|
2000-07-10 18:02:31 +00:00
|
|
|
isc_event_free(&event);
|
2000-07-14 17:57:27 +00:00
|
|
|
LOCK_LOOKUP;
|
2000-07-10 18:02:31 +00:00
|
|
|
start_lookup();
|
2000-07-14 17:57:27 +00:00
|
|
|
UNLOCK_LOOKUP;
|
2000-07-10 18:02:31 +00:00
|
|
|
}
|
|
|
|
|
2000-07-13 00:32:20 +00:00
|
|
|
/*
|
2000-07-18 18:51:40 +00:00
|
|
|
* Make everything on the lookup queue go away. Mainly used by the
|
|
|
|
* SIGINT handler.
|
2000-07-13 00:32:20 +00:00
|
|
|
*/
|
2000-07-14 17:57:27 +00:00
|
|
|
void
|
2000-07-13 00:32:20 +00:00
|
|
|
cancel_all(void) {
|
2000-07-14 20:14:36 +00:00
|
|
|
dig_lookup_t *l, *n;
|
2000-09-22 23:21:32 +00:00
|
|
|
dig_query_t *q, *nq;
|
2000-04-26 18:34:17 +00:00
|
|
|
|
2000-07-13 02:14:17 +00:00
|
|
|
debug("cancel_all()");
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2000-07-14 17:57:27 +00:00
|
|
|
LOCK_LOOKUP;
|
|
|
|
if (free_now) {
|
|
|
|
UNLOCK_LOOKUP;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
cancel_now = ISC_TRUE;
|
2000-07-14 20:14:36 +00:00
|
|
|
if (current_lookup != NULL) {
|
|
|
|
if (current_lookup->timer != NULL)
|
|
|
|
isc_timer_detach(¤t_lookup->timer);
|
|
|
|
q = ISC_LIST_HEAD(current_lookup->q);
|
2000-04-26 18:34:17 +00:00
|
|
|
while (q != NULL) {
|
2000-07-05 23:28:32 +00:00
|
|
|
debug("cancelling query %p, belonging to %p",
|
2000-07-14 20:14:36 +00:00
|
|
|
q, current_lookup);
|
2000-09-22 23:21:32 +00:00
|
|
|
nq = ISC_LIST_NEXT(q, link);
|
2000-04-28 21:41:19 +00:00
|
|
|
if (q->sock != NULL) {
|
|
|
|
isc_socket_cancel(q->sock, NULL,
|
|
|
|
ISC_SOCKCANCEL_ALL);
|
2000-09-22 23:21:32 +00:00
|
|
|
} else {
|
|
|
|
clear_query (q);
|
2000-04-28 21:41:19 +00:00
|
|
|
}
|
2000-09-22 23:21:32 +00:00
|
|
|
q = nq;
|
2000-04-28 21:41:19 +00:00
|
|
|
}
|
2000-07-14 20:14:36 +00:00
|
|
|
}
|
|
|
|
l = ISC_LIST_HEAD(lookup_list);
|
|
|
|
while (l != NULL) {
|
|
|
|
n = ISC_LIST_NEXT(l, link);
|
|
|
|
ISC_LIST_DEQUEUE(lookup_list, l, link);
|
|
|
|
try_clear_lookup(l);
|
|
|
|
l = n;
|
2000-04-26 18:34:17 +00:00
|
|
|
}
|
2000-07-14 17:57:27 +00:00
|
|
|
UNLOCK_LOOKUP;
|
2000-07-13 00:32:20 +00:00
|
|
|
}
|
|
|
|
|
2000-07-18 18:51:40 +00:00
|
|
|
/*
|
2000-08-01 01:33:37 +00:00
|
|
|
* Destroy all of the libs we are using, and get everything ready for a
|
2000-07-18 18:51:40 +00:00
|
|
|
* clean shutdown.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
destroy_libs(void) {
|
2000-07-13 00:32:20 +00:00
|
|
|
void *ptr;
|
|
|
|
dig_server_t *s;
|
|
|
|
|
2000-07-18 18:51:40 +00:00
|
|
|
debug("destroy_libs()");
|
|
|
|
if (global_task != NULL) {
|
|
|
|
debug("freeing task");
|
|
|
|
isc_task_detach(&global_task);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* The taskmgr_destroy() call blocks until all events are cleared
|
|
|
|
* from the task.
|
|
|
|
*/
|
|
|
|
if (taskmgr != NULL) {
|
2000-07-21 23:04:44 +00:00
|
|
|
debug("freeing taskmgr");
|
2000-07-18 18:51:40 +00:00
|
|
|
isc_taskmgr_destroy(&taskmgr);
|
2000-12-11 19:24:30 +00:00
|
|
|
}
|
2000-07-18 18:51:40 +00:00
|
|
|
LOCK_LOOKUP;
|
2000-07-13 00:32:20 +00:00
|
|
|
REQUIRE(sockcount == 0);
|
|
|
|
REQUIRE(recvcount == 0);
|
|
|
|
REQUIRE(sendcount == 0);
|
|
|
|
|
|
|
|
INSIST(ISC_LIST_HEAD(lookup_list) == NULL);
|
2000-07-14 20:14:36 +00:00
|
|
|
INSIST(current_lookup == NULL);
|
2000-07-13 00:32:20 +00:00
|
|
|
INSIST(!free_now);
|
|
|
|
|
|
|
|
free_now = ISC_TRUE;
|
|
|
|
|
2000-04-26 18:34:17 +00:00
|
|
|
s = ISC_LIST_HEAD(server_list);
|
|
|
|
while (s != NULL) {
|
2000-07-05 23:28:32 +00:00
|
|
|
debug("freeing global server %p", s);
|
2000-04-26 18:34:17 +00:00
|
|
|
ptr = s;
|
|
|
|
s = ISC_LIST_NEXT(s, link);
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_mem_free(mctx, ptr);
|
2000-04-26 18:34:17 +00:00
|
|
|
}
|
2001-01-18 05:12:44 +00:00
|
|
|
clear_searchlist();
|
2000-07-13 01:49:44 +00:00
|
|
|
if (commctx != NULL) {
|
|
|
|
debug("freeing commctx");
|
|
|
|
isc_mempool_destroy(&commctx);
|
|
|
|
}
|
2000-06-06 18:49:06 +00:00
|
|
|
if (socketmgr != NULL) {
|
2000-07-05 23:28:32 +00:00
|
|
|
debug("freeing socketmgr");
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_socketmgr_destroy(&socketmgr);
|
2000-06-06 18:49:06 +00:00
|
|
|
}
|
|
|
|
if (timermgr != NULL) {
|
2000-07-05 23:28:32 +00:00
|
|
|
debug("freeing timermgr");
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_timermgr_destroy(&timermgr);
|
2000-06-06 18:49:06 +00:00
|
|
|
}
|
|
|
|
if (key != NULL) {
|
2000-07-05 23:28:32 +00:00
|
|
|
debug("freeing key %p", key);
|
2000-06-06 00:43:17 +00:00
|
|
|
dns_tsigkey_detach(&key);
|
2000-06-06 18:49:06 +00:00
|
|
|
}
|
2000-06-06 00:43:17 +00:00
|
|
|
if (namebuf != NULL)
|
|
|
|
isc_buffer_free(&namebuf);
|
2000-06-12 19:33:30 +00:00
|
|
|
|
2000-06-30 22:53:07 +00:00
|
|
|
if (is_dst_up) {
|
2000-07-05 23:28:32 +00:00
|
|
|
debug("destroy DST lib");
|
2000-06-30 22:53:07 +00:00
|
|
|
dst_lib_destroy();
|
|
|
|
is_dst_up = ISC_FALSE;
|
|
|
|
}
|
|
|
|
if (entp != NULL) {
|
2000-07-05 23:28:32 +00:00
|
|
|
debug("detach from entropy");
|
2000-06-30 22:53:07 +00:00
|
|
|
isc_entropy_detach(&entp);
|
|
|
|
}
|
2000-07-14 17:57:27 +00:00
|
|
|
|
2000-08-28 05:06:18 +00:00
|
|
|
UNLOCK_LOOKUP;
|
2000-08-26 01:42:34 +00:00
|
|
|
DESTROYLOCK(&lookup_lock);
|
2000-10-19 22:49:34 +00:00
|
|
|
if (memdebugging != 0)
|
2000-07-14 17:57:27 +00:00
|
|
|
isc_mem_stats(mctx, stderr);
|
|
|
|
if (mctx != NULL)
|
2000-08-01 01:33:37 +00:00
|
|
|
isc_mem_destroy(&mctx);
|
2000-07-14 17:57:27 +00:00
|
|
|
}
|