xref: /minix/external/bsd/bind/dist/bin/dig/include/dig/dig.h (revision fb9c64b2)
1 /*	$NetBSD: dig.h,v 1.11 2015/07/08 17:28:55 christos Exp $	*/
2 
3 /*
4  * Copyright (C) 2004-2009, 2011-2015  Internet Systems Consortium, Inc. ("ISC")
5  * Copyright (C) 2000-2003  Internet Software Consortium.
6  *
7  * Permission to use, copy, modify, and/or distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17  * PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #ifndef DIG_H
21 #define DIG_H
22 
23 /*! \file */
24 
25 #include <dns/rdatalist.h>
26 
27 #include <dst/dst.h>
28 
29 #include <isc/boolean.h>
30 #include <isc/buffer.h>
31 #include <isc/bufferlist.h>
32 #include <isc/formatcheck.h>
33 #include <isc/lang.h>
34 #include <isc/list.h>
35 #include <isc/mem.h>
36 #include <isc/print.h>
37 #include <isc/sockaddr.h>
38 #include <isc/socket.h>
39 
40 #define MXSERV 20
41 #define MXNAME (DNS_NAME_MAXTEXT+1)
42 #define MXRD 32
43 /*% Buffer Size */
44 #define BUFSIZE 512
45 #define COMMSIZE 0xffff
46 #ifndef RESOLV_CONF
47 /*% location of resolve.conf */
48 #define RESOLV_CONF "/etc/resolv.conf"
49 #endif
50 /*% output buffer */
51 #define OUTPUTBUF 32767
52 /*% Max RR Limit */
53 #define MAXRRLIMIT 0xffffffff
54 #define MAXTIMEOUT 0xffff
55 /*% Max number of tries */
56 #define MAXTRIES 0xffffffff
57 /*% Max number of dots */
58 #define MAXNDOTS 0xffff
59 /*% Max number of ports */
60 #define MAXPORT 0xffff
61 /*% Max serial number */
62 #define MAXSERIAL 0xffffffff
63 
64 /*% Default TCP Timeout */
65 #define TCP_TIMEOUT 10
66 /*% Default UDP Timeout */
67 #define UDP_TIMEOUT 5
68 
69 #define SERVER_TIMEOUT 1
70 
71 #define LOOKUP_LIMIT 64
72 /*%
73  * Lookup_limit is just a limiter, keeping too many lookups from being
74  * created.  It's job is mainly to prevent the program from running away
75  * in a tight loop of constant lookups.  It's value is arbitrary.
76  */
77 
78 /*
79  * Defaults for the sigchase suboptions.  Consolidated here because
80  * these control the layout of dig_lookup_t (among other things).
81  */
82 #ifdef DIG_SIGCHASE
83 #ifndef DIG_SIGCHASE_BU
84 #define DIG_SIGCHASE_BU 1
85 #endif
86 #ifndef DIG_SIGCHASE_TD
87 #define DIG_SIGCHASE_TD 1
88 #endif
89 #endif
90 
91 ISC_LANG_BEGINDECLS
92 
93 typedef struct dig_lookup dig_lookup_t;
94 typedef struct dig_query dig_query_t;
95 typedef struct dig_server dig_server_t;
96 #ifdef DIG_SIGCHASE
97 typedef struct dig_message dig_message_t;
98 #endif
99 typedef ISC_LIST(dig_server_t) dig_serverlist_t;
100 typedef struct dig_searchlist dig_searchlist_t;
101 
102 /*% The dig_lookup structure */
103 struct dig_lookup {
104 	isc_boolean_t
105 		pending, /*%< Pending a successful answer */
106 		waiting_connect,
107 		doing_xfr,
108 		ns_search_only, /*%< dig +nssearch, host -C */
109 		identify, /*%< Append an "on server <foo>" message */
110 		identify_previous_line, /*% Prepend a "Nameserver <foo>:"
111 					   message, with newline and tab */
112 		ignore,
113 		recurse,
114 		aaonly,
115 		adflag,
116 		cdflag,
117 		trace, /*% dig +trace */
118 		trace_root, /*% initial query for either +trace or +nssearch */
119 		tcp_mode,
120 		tcp_mode_set,
121 		ip6_int,
122 		comments,
123 		stats,
124 		section_question,
125 		section_answer,
126 		section_authority,
127 		section_additional,
128 		servfail_stops,
129 		new_search,
130 		need_search,
131 		done_as_is,
132 		besteffort,
133 		dnssec,
134 		expire,
135 #ifdef ISC_PLATFORM_USESIT
136 		sit,
137 #endif
138 		nsid;   /*% Name Server ID (RFC 5001) */
139 #ifdef DIG_SIGCHASE
140 isc_boolean_t	sigchase;
141 #if DIG_SIGCHASE_TD
142 	isc_boolean_t do_topdown,
143 		trace_root_sigchase,
144 		rdtype_sigchaseset,
145 		rdclass_sigchaseset;
146 	/* Name we are going to validate RRset */
147 	char textnamesigchase[MXNAME];
148 #endif
149 #endif
150 
151 	char textname[MXNAME]; /*% Name we're going to be looking up */
152 	char cmdline[MXNAME];
153 	dns_rdatatype_t rdtype;
154 	dns_rdatatype_t qrdtype;
155 #if DIG_SIGCHASE_TD
156 	dns_rdatatype_t rdtype_sigchase;
157 	dns_rdatatype_t qrdtype_sigchase;
158 	dns_rdataclass_t rdclass_sigchase;
159 #endif
160 	dns_rdataclass_t rdclass;
161 	isc_boolean_t rdtypeset;
162 	isc_boolean_t rdclassset;
163 	char namespace[BUFSIZE];
164 	char onamespace[BUFSIZE];
165 	isc_buffer_t namebuf;
166 	isc_buffer_t onamebuf;
167 	isc_buffer_t renderbuf;
168 	char *sendspace;
169 	dns_name_t *name;
170 	isc_timer_t *timer;
171 	isc_interval_t interval;
172 	dns_message_t *sendmsg;
173 	dns_name_t *oname;
174 	ISC_LINK(dig_lookup_t) link;
175 	ISC_LIST(dig_query_t) q;
176 	ISC_LIST(dig_query_t) connecting;
177 	dig_query_t *current_query;
178 	dig_serverlist_t my_server_list;
179 	dig_searchlist_t *origin;
180 	dig_query_t *xfr_q;
181 	isc_uint32_t retries;
182 	int nsfound;
183 	isc_uint16_t udpsize;
184 	isc_int16_t edns;
185 	isc_uint32_t ixfr_serial;
186 	isc_buffer_t rdatabuf;
187 	char rdatastore[MXNAME];
188 	dst_context_t *tsigctx;
189 	isc_buffer_t *querysig;
190 	isc_uint32_t msgcounter;
191 	dns_fixedname_t fdomain;
192 	isc_sockaddr_t *ecs_addr;
193 #ifdef ISC_PLATFORM_USESIT
194 	char *sitvalue;
195 #endif
196 };
197 
198 /*% The dig_query structure */
199 struct dig_query {
200 	dig_lookup_t *lookup;
201 	isc_boolean_t waiting_connect,
202 		pending_free,
203 		waiting_senddone,
204 		first_pass,
205 		first_soa_rcvd,
206 		second_rr_rcvd,
207 		first_repeat_rcvd,
208 		recv_made,
209 		warn_id;
210 	isc_uint32_t first_rr_serial;
211 	isc_uint32_t second_rr_serial;
212 	isc_uint32_t msg_count;
213 	isc_uint32_t rr_count;
214 	isc_boolean_t ixfr_axfr;
215 	char *servname;
216 	char *userarg;
217 	isc_bufferlist_t sendlist,
218 		recvlist,
219 		lengthlist;
220 	isc_buffer_t recvbuf,
221 		lengthbuf,
222 		slbuf;
223 	char *recvspace,
224 		lengthspace[4],
225 		slspace[4];
226 	isc_socket_t *sock;
227 	ISC_LINK(dig_query_t) link;
228 	ISC_LINK(dig_query_t) clink;
229 	isc_sockaddr_t sockaddr;
230 	isc_time_t time_sent;
231 	isc_time_t time_recv;
232 	isc_uint64_t byte_count;
233 	isc_buffer_t sendbuf;
234 };
235 
236 struct dig_server {
237 	char servername[MXNAME];
238 	char userarg[MXNAME];
239 	ISC_LINK(dig_server_t) link;
240 };
241 
242 struct dig_searchlist {
243 	char origin[MXNAME];
244 	ISC_LINK(dig_searchlist_t) link;
245 };
246 #ifdef DIG_SIGCHASE
247 struct dig_message {
248 		dns_message_t *msg;
249 		ISC_LINK(dig_message_t) link;
250 };
251 #endif
252 
253 typedef ISC_LIST(dig_searchlist_t) dig_searchlistlist_t;
254 typedef ISC_LIST(dig_lookup_t) dig_lookuplist_t;
255 
256 /*
257  * Externals from dighost.c
258  */
259 
260 extern dig_lookuplist_t lookup_list;
261 extern dig_serverlist_t server_list;
262 extern dig_searchlistlist_t search_list;
263 extern unsigned int extrabytes;
264 
265 extern isc_boolean_t check_ra, have_ipv4, have_ipv6, specified_source,
266 	usesearch, showsearch, qr;
267 extern in_port_t port;
268 extern unsigned int timeout;
269 extern isc_mem_t *mctx;
270 extern int sendcount;
271 extern int ndots;
272 extern int lookup_counter;
273 extern int exitcode;
274 extern isc_sockaddr_t bind_address;
275 extern char keynametext[MXNAME];
276 extern char keyfile[MXNAME];
277 extern char keysecret[MXNAME];
278 extern dns_name_t *hmacname;
279 extern unsigned int digestbits;
280 #ifdef DIG_SIGCHASE
281 extern char trustedkey[MXNAME];
282 #endif
283 extern dns_tsigkey_t *key;
284 extern isc_boolean_t validated;
285 extern isc_taskmgr_t *taskmgr;
286 extern isc_task_t *global_task;
287 extern isc_boolean_t free_now;
288 extern isc_boolean_t debugging, debugtiming, memdebugging;
289 extern isc_boolean_t keep_open;
290 
291 extern const char *progname;
292 extern int tries;
293 extern int fatalexit;
294 #ifdef WITH_IDN
295 extern int idnoptions;
296 #endif
297 
298 /*
299  * Routines in dighost.c.
300  */
301 isc_result_t
302 get_address(char *host, in_port_t port, isc_sockaddr_t *sockaddr);
303 
304 int
305 getaddresses(dig_lookup_t *lookup, const char *host, isc_result_t *resultp);
306 
307 isc_result_t
308 get_reverse(char *reverse, size_t len, char *value, isc_boolean_t ip6_int,
309 	    isc_boolean_t strict);
310 
311 ISC_PLATFORM_NORETURN_PRE void
312 fatal(const char *format, ...)
313 ISC_FORMAT_PRINTF(1, 2) ISC_PLATFORM_NORETURN_POST;
314 
315 void
316 debug(const char *format, ...) ISC_FORMAT_PRINTF(1, 2);
317 
318 void
319 check_result(isc_result_t result, const char *msg);
320 
321 isc_boolean_t
322 setup_lookup(dig_lookup_t *lookup);
323 
324 void
325 destroy_lookup(dig_lookup_t *lookup);
326 
327 void
328 do_lookup(dig_lookup_t *lookup);
329 
330 void
331 start_lookup(void);
332 
333 void
334 onrun_callback(isc_task_t *task, isc_event_t *event);
335 
336 int
337 dhmain(int argc, char **argv);
338 
339 void
340 setup_libs(void);
341 
342 void
343 setup_system(void);
344 
345 isc_result_t
346 parse_uint(isc_uint32_t *uip, const char *value, isc_uint32_t max,
347 	   const char *desc);
348 
349 isc_result_t
350 parse_netprefix(isc_sockaddr_t **sap, const char *value);
351 
352 void
353 parse_hmac(const char *hmacstr);
354 
355 dig_lookup_t *
356 requeue_lookup(dig_lookup_t *lookold, isc_boolean_t servers);
357 
358 dig_lookup_t *
359 make_empty_lookup(void);
360 
361 dig_lookup_t *
362 clone_lookup(dig_lookup_t *lookold, isc_boolean_t servers);
363 
364 dig_server_t *
365 make_server(const char *servname, const char *userarg);
366 
367 void
368 flush_server_list(void);
369 
370 void
371 set_nameserver(char *opt);
372 
373 void
374 clone_server_list(dig_serverlist_t src,
375 		  dig_serverlist_t *dest);
376 
377 void
378 cancel_all(void);
379 
380 void
381 destroy_libs(void);
382 
383 void
384 set_search_domain(char *domain);
385 
386 #ifdef DIG_SIGCHASE
387 void
388 clean_trustedkey(void);
389 #endif
390 
391 /*
392  * Routines to be defined in dig.c, host.c, and nslookup.c.
393  */
394 #ifdef DIG_SIGCHASE
395 isc_result_t
396 printrdataset(dns_name_t *owner_name, dns_rdataset_t *rdataset,
397 	      isc_buffer_t *target);
398 #endif
399 
400 isc_result_t
401 printmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers);
402 /*%<
403  * Print the final result of the lookup.
404  */
405 
406 void
407 received(int bytes, isc_sockaddr_t *from, dig_query_t *query);
408 /*%<
409  * Print a message about where and when the response
410  * was received from, like the final comment in the
411  * output of "dig".
412  */
413 
414 void
415 trying(char *frm, dig_lookup_t *lookup);
416 
417 void
418 dighost_shutdown(void);
419 
420 char *
421 next_token(char **stringp, const char *delim);
422 
423 #ifdef DIG_SIGCHASE
424 /* Chasing functions */
425 dns_rdataset_t *
426 chase_scanname(dns_name_t *name, dns_rdatatype_t type, dns_rdatatype_t covers);
427 void
428 chase_sig(dns_message_t *msg);
429 #endif
430 
431 ISC_LANG_ENDDECLS
432 
433 #endif
434