dig.h 9.8 KB
Newer Older
1
/*
Tinderbox User's avatar
Tinderbox User committed
2
 * Copyright (C) 2004-2009, 2011-2014  Internet Systems Consortium, Inc. ("ISC")
Mark Andrews's avatar
Mark Andrews committed
3
 * Copyright (C) 2000-2003  Internet Software Consortium.
4
 *
Automatic Updater's avatar
Automatic Updater committed
5
 * Permission to use, copy, modify, and/or distribute this software for any
6 7
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
8
 *
Mark Andrews's avatar
Mark Andrews committed
9 10 11 12 13 14 15
 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
 * AND FITNESS.  IN NO EVENT SHALL ISC 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.
16 17 18 19 20
 */

#ifndef DIG_H
#define DIG_H

21 22
/*! \file */

Michael Sawyer's avatar
Michael Sawyer committed
23
#include <dns/rdatalist.h>
24

Michael Sawyer's avatar
Michael Sawyer committed
25
#include <dst/dst.h>
26

Michael Sawyer's avatar
Michael Sawyer committed
27
#include <isc/boolean.h>
28 29
#include <isc/buffer.h>
#include <isc/bufferlist.h>
30
#include <isc/formatcheck.h>
Michael Sawyer's avatar
Michael Sawyer committed
31
#include <isc/lang.h>
32
#include <isc/list.h>
Michael Sawyer's avatar
Michael Sawyer committed
33
#include <isc/mem.h>
34
#include <isc/print.h>
Michael Sawyer's avatar
Michael Sawyer committed
35 36
#include <isc/sockaddr.h>
#include <isc/socket.h>
37

38
#define MXSERV 20
39
#define MXNAME (DNS_NAME_MAXTEXT+1)
40
#define MXRD 32
41
/*% Buffer Size */
42
#define BUFSIZE 512
Michael Sawyer's avatar
Michael Sawyer committed
43
#define COMMSIZE 0xffff
44
#ifndef RESOLV_CONF
45
/*% location of resolve.conf */
46 47
#define RESOLV_CONF "/etc/resolv.conf"
#endif
48
/*% output buffer */
49
#define OUTPUTBUF 32767
50
/*% Max RR Limit */
51 52
#define MAXRRLIMIT 0xffffffff
#define MAXTIMEOUT 0xffff
53
/*% Max number of tries */
54
#define MAXTRIES 0xffffffff
55
/*% Max number of dots */
56
#define MAXNDOTS 0xffff
57
/*% Max number of ports */
58
#define MAXPORT 0xffff
59
/*% Max serial number */
60
#define MAXSERIAL 0xffffffff
61

62
/*% Default TCP Timeout */
63
#define TCP_TIMEOUT 10
64
/*% Default UDP Timeout */
65
#define UDP_TIMEOUT 5
66

Michael Sawyer's avatar
Michael Sawyer committed
67 68
#define SERVER_TIMEOUT 1

69
#define LOOKUP_LIMIT 64
70
/*%
71
 * Lookup_limit is just a limiter, keeping too many lookups from being
72 73 74
 * created.  It's job is mainly to prevent the program from running away
 * in a tight loop of constant lookups.  It's value is arbitrary.
 */
75

76 77 78 79 80 81 82 83 84 85 86 87 88
/*
 * Defaults for the sigchase suboptions.  Consolidated here because
 * these control the layout of dig_lookup_t (among other things).
 */
#ifdef DIG_SIGCHASE
#ifndef DIG_SIGCHASE_BU
#define DIG_SIGCHASE_BU 1
#endif
#ifndef DIG_SIGCHASE_TD
#define DIG_SIGCHASE_TD 1
#endif
#endif

89 90 91 92 93
ISC_LANG_BEGINDECLS

typedef struct dig_lookup dig_lookup_t;
typedef struct dig_query dig_query_t;
typedef struct dig_server dig_server_t;
Mark Andrews's avatar
Mark Andrews committed
94
#ifdef DIG_SIGCHASE
95 96
typedef struct dig_message dig_message_t;
#endif
97
typedef ISC_LIST(dig_server_t) dig_serverlist_t;
98
typedef struct dig_searchlist dig_searchlist_t;
99

100
/*% The dig_lookup structure */
101
struct dig_lookup {
102
	isc_boolean_t
103
		pending, /*%< Pending a successful answer */
104
		waiting_connect,
105
		doing_xfr,
106 107 108
		ns_search_only, /*%< dig +nssearch, host -C */
		identify, /*%< Append an "on server <foo>" message */
		identify_previous_line, /*% Prepend a "Nameserver <foo>:"
Andreas Gustafsson's avatar
Andreas Gustafsson committed
109
					   message, with newline and tab */
Michael Sawyer's avatar
Michael Sawyer committed
110
		ignore,
111
		recurse,
112
		aaonly,
113 114
		adflag,
		cdflag,
115
		zflag,
116 117
		trace, /*% dig +trace */
		trace_root, /*% initial query for either +trace or +nssearch */
118
		tcp_mode,
119
		tcp_mode_set,
120
		ip6_int,
121 122 123 124 125
		comments,
		stats,
		section_question,
		section_answer,
		section_authority,
126
		section_additional,
127
		servfail_stops,
128
		new_search,
129 130
		need_search,
		done_as_is,
131
		besteffort,
132
		dnssec,
133
		expire,
134 135 136
#ifdef ISC_PLATFORM_USESIT
		sit,
#endif
137
		nsid,   /*% Name Server ID (RFC 5001) */
138 139
		header_only,
		ednsneg;
Mark Andrews's avatar
Mark Andrews committed
140
#ifdef DIG_SIGCHASE
141
isc_boolean_t	sigchase;
Mark Andrews's avatar
Mark Andrews committed
142
#if DIG_SIGCHASE_TD
143 144 145 146
	isc_boolean_t do_topdown,
		trace_root_sigchase,
		rdtype_sigchaseset,
		rdclass_sigchaseset;
147
	/* Name we are going to validate RRset */
148
	char textnamesigchase[MXNAME];
149 150
#endif
#endif
151

152
	char textname[MXNAME]; /*% Name we're going to be looking up */
153
	char cmdline[MXNAME];
154
	dns_rdatatype_t rdtype;
155
	dns_rdatatype_t qrdtype;
Mark Andrews's avatar
Mark Andrews committed
156
#if DIG_SIGCHASE_TD
157 158 159
	dns_rdatatype_t rdtype_sigchase;
	dns_rdatatype_t qrdtype_sigchase;
	dns_rdataclass_t rdclass_sigchase;
160
#endif
161
	dns_rdataclass_t rdclass;
Michael Sawyer's avatar
Michael Sawyer committed
162 163
	isc_boolean_t rdtypeset;
	isc_boolean_t rdclassset;
164
	char namespace[BUFSIZE];
165
	char onamespace[BUFSIZE];
166
	isc_buffer_t namebuf;
167
	isc_buffer_t onamebuf;
168
	isc_buffer_t renderbuf;
169
	char *sendspace;
170 171 172 173
	dns_name_t *name;
	isc_timer_t *timer;
	isc_interval_t interval;
	dns_message_t *sendmsg;
174
	dns_name_t *oname;
175 176
	ISC_LINK(dig_lookup_t) link;
	ISC_LIST(dig_query_t) q;
177
	ISC_LIST(dig_query_t) connecting;
Michael Sawyer's avatar
Michael Sawyer committed
178
	dig_query_t *current_query;
179
	dig_serverlist_t my_server_list;
180
	dig_searchlist_t *origin;
181
	dig_query_t *xfr_q;
182
	isc_uint32_t retries;
183
	int nsfound;
184
	isc_uint16_t udpsize;
185
	isc_int16_t edns;
Michael Sawyer's avatar
Michael Sawyer committed
186 187 188
	isc_uint32_t ixfr_serial;
	isc_buffer_t rdatabuf;
	char rdatastore[MXNAME];
189 190
	dst_context_t *tsigctx;
	isc_buffer_t *querysig;
191
	isc_uint32_t msgcounter;
192
	dns_fixedname_t fdomain;
Evan Hunt's avatar
Evan Hunt committed
193
	isc_sockaddr_t *ecs_addr;
194 195 196
#ifdef ISC_PLATFORM_USESIT
	char *sitvalue;
#endif
197 198
	dns_ednsopt_t *ednsopts;
	unsigned int ednsoptscnt;
199
	isc_dscp_t dscp;
200
	unsigned int ednsflags;
201 202
};

203
/*% The dig_query structure */
204 205
struct dig_query {
	dig_lookup_t *lookup;
206
	isc_boolean_t waiting_connect,
207
		pending_free,
208
		waiting_senddone,
209
		first_pass,
Michael Sawyer's avatar
Michael Sawyer committed
210 211
		first_soa_rcvd,
		second_rr_rcvd,
Michael Sawyer's avatar
Michael Sawyer committed
212
		first_repeat_rcvd,
213 214
		recv_made,
		warn_id;
Michael Sawyer's avatar
Michael Sawyer committed
215 216
	isc_uint32_t first_rr_serial;
	isc_uint32_t second_rr_serial;
217
	isc_uint32_t msg_count;
218
	isc_uint32_t rr_count;
219
	isc_boolean_t ixfr_axfr;
220
	char *servname;
221
	char *userarg;
222 223 224 225
	isc_bufferlist_t sendlist,
		recvlist,
		lengthlist;
	isc_buffer_t recvbuf,
226 227
		lengthbuf,
		slbuf;
228
	char *recvspace,
229 230
		lengthspace[4],
		slspace[4];
231 232
	isc_socket_t *sock;
	ISC_LINK(dig_query_t) link;
233
	ISC_LINK(dig_query_t) clink;
234
	isc_sockaddr_t sockaddr;
235
	isc_time_t time_sent;
Mark Andrews's avatar
Mark Andrews committed
236
	isc_time_t time_recv;
237
	isc_uint64_t byte_count;
238
	isc_buffer_t sendbuf;
239 240 241 242
};

struct dig_server {
	char servername[MXNAME];
243
	char userarg[MXNAME];
244 245 246
	ISC_LINK(dig_server_t) link;
};

247 248 249 250
struct dig_searchlist {
	char origin[MXNAME];
	ISC_LINK(dig_searchlist_t) link;
};
Mark Andrews's avatar
Mark Andrews committed
251
#ifdef DIG_SIGCHASE
252
struct dig_message {
253
		dns_message_t *msg;
254 255 256
		ISC_LINK(dig_message_t) link;
};
#endif
257 258 259 260 261 262 263 264 265 266 267 268 269

typedef ISC_LIST(dig_searchlist_t) dig_searchlistlist_t;
typedef ISC_LIST(dig_lookup_t) dig_lookuplist_t;

/*
 * Externals from dighost.c
 */

extern dig_lookuplist_t lookup_list;
extern dig_serverlist_t server_list;
extern dig_searchlistlist_t search_list;
extern unsigned int extrabytes;

270
extern isc_boolean_t check_ra, have_ipv4, have_ipv6, specified_source,
271
	usesearch, showsearch, qr;
272 273 274 275 276 277 278 279 280 281 282
extern in_port_t port;
extern unsigned int timeout;
extern isc_mem_t *mctx;
extern int sendcount;
extern int ndots;
extern int lookup_counter;
extern int exitcode;
extern isc_sockaddr_t bind_address;
extern char keynametext[MXNAME];
extern char keyfile[MXNAME];
extern char keysecret[MXNAME];
283 284
extern dns_name_t *hmacname;
extern unsigned int digestbits;
285 286 287 288 289 290 291 292
#ifdef DIG_SIGCHASE
extern char trustedkey[MXNAME];
#endif
extern dns_tsigkey_t *key;
extern isc_boolean_t validated;
extern isc_taskmgr_t *taskmgr;
extern isc_task_t *global_task;
extern isc_boolean_t free_now;
293
extern isc_boolean_t debugging, debugtiming, memdebugging;
294
extern isc_boolean_t keep_open;
295 296 297 298

extern char *progname;
extern int tries;
extern int fatalexit;
299
extern isc_boolean_t verbose;
300 301 302
#ifdef WITH_IDN
extern int idnoptions;
#endif
303

David Lawrence's avatar
David Lawrence committed
304 305 306
/*
 * Routines in dighost.c.
 */
307
isc_result_t
308
get_address(char *host, in_port_t port, isc_sockaddr_t *sockaddr);
309

310
int
311
getaddresses(dig_lookup_t *lookup, const char *host, isc_result_t *resultp);
312

313
isc_result_t
314
get_reverse(char *reverse, size_t len, char *value, isc_boolean_t ip6_int,
315
	    isc_boolean_t strict);
316

Francis Dupont's avatar
Francis Dupont committed
317 318 319
ISC_PLATFORM_NORETURN_PRE void
fatal(const char *format, ...)
ISC_FORMAT_PRINTF(1, 2) ISC_PLATFORM_NORETURN_POST;
320

321
void
322
debug(const char *format, ...) ISC_FORMAT_PRINTF(1, 2);
323

324
void
David Lawrence's avatar
David Lawrence committed
325
check_result(isc_result_t result, const char *msg);
326

327
isc_boolean_t
328
setup_lookup(dig_lookup_t *lookup);
329

330 331 332
void
destroy_lookup(dig_lookup_t *lookup);

333
void
334
do_lookup(dig_lookup_t *lookup);
335

336
void
337 338
start_lookup(void);

339 340 341
void
onrun_callback(isc_task_t *task, isc_event_t *event);

342 343
int
dhmain(int argc, char **argv);
344

345 346
void
setup_libs(void);
347

348 349
void
setup_system(void);
350

351 352 353 354
isc_result_t
parse_uint(isc_uint32_t *uip, const char *value, isc_uint32_t max,
	   const char *desc);

355 356 357 358
isc_result_t
parse_xint(isc_uint32_t *uip, const char *value, isc_uint32_t max,
	   const char *desc);

Evan Hunt's avatar
Evan Hunt committed
359 360 361
isc_result_t
parse_netprefix(isc_sockaddr_t **sap, const char *value);

362 363 364
void
parse_hmac(const char *hmacstr);

David Lawrence's avatar
David Lawrence committed
365 366
dig_lookup_t *
requeue_lookup(dig_lookup_t *lookold, isc_boolean_t servers);
367

368 369 370 371 372 373
dig_lookup_t *
make_empty_lookup(void);

dig_lookup_t *
clone_lookup(dig_lookup_t *lookold, isc_boolean_t servers);

374
dig_server_t *
375
make_server(const char *servname, const char *userarg);
376

377 378 379 380 381 382
void
flush_server_list(void);

void
set_nameserver(char *opt);

383
void
384
clone_server_list(dig_serverlist_t src,
385
		  dig_serverlist_t *dest);
386

387 388 389 390 391 392
void
cancel_all(void);

void
destroy_libs(void);

393 394 395
void
set_search_domain(char *domain);

Mark Andrews's avatar
Mark Andrews committed
396
#ifdef DIG_SIGCHASE
397 398 399 400
void
clean_trustedkey(void);
#endif

David Lawrence's avatar
David Lawrence committed
401
/*
402
 * Routines to be defined in dig.c, host.c, and nslookup.c.
David Lawrence's avatar
David Lawrence committed
403
 */
Mark Andrews's avatar
Mark Andrews committed
404
#ifdef DIG_SIGCHASE
405 406 407 408
isc_result_t
printrdataset(dns_name_t *owner_name, dns_rdataset_t *rdataset,
	      isc_buffer_t *target);
#endif
409

410
isc_result_t
David Lawrence's avatar
David Lawrence committed
411
printmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers);
412
/*%<
413 414
 * Print the final result of the lookup.
 */
415

416
void
417
received(int bytes, isc_sockaddr_t *from, dig_query_t *query);
418
/*%<
419 420 421 422
 * Print a message about where and when the response
 * was received from, like the final comment in the
 * output of "dig".
 */
423

424
void
Brian Wellington's avatar
Brian Wellington committed
425
trying(char *frm, dig_lookup_t *lookup);
426

427 428
void
dighost_shutdown(void);
429

Mark Andrews's avatar
Mark Andrews committed
430 431 432
char *
next_token(char **stringp, const char *delim);

Mark Andrews's avatar
Mark Andrews committed
433
#ifdef DIG_SIGCHASE
434 435 436 437 438 439 440
/* Chasing functions */
dns_rdataset_t *
chase_scanname(dns_name_t *name, dns_rdatatype_t type, dns_rdatatype_t covers);
void
chase_sig(dns_message_t *msg);
#endif

441 442
void save_opt(dig_lookup_t *lookup, char *code, char *value);

443 444 445
void setup_file_key(void);
void setup_text_key(void);

446 447 448
ISC_LANG_ENDDECLS

#endif