]> CyberLeo.Net >> Repos - FreeBSD/stable/8.git/blob - contrib/bind9/bin/dig/include/dig/dig.h
MFC r362623:
[FreeBSD/stable/8.git] / contrib / bind9 / bin / dig / include / dig / dig.h
1 /*
2  * Copyright (C) 2004-2009, 2011-2014  Internet Systems Consortium, Inc. ("ISC")
3  * Copyright (C) 2000-2003  Internet Software Consortium.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15  * PERFORMANCE OF THIS SOFTWARE.
16  */
17
18 /* $Id: dig.h,v 1.111.306.3 2011/12/07 17:23:55 each Exp $ */
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                 ip6_int,
121                 comments,
122                 stats,
123                 section_question,
124                 section_answer,
125                 section_authority,
126                 section_additional,
127                 servfail_stops,
128                 new_search,
129                 need_search,
130                 done_as_is,
131                 besteffort,
132                 dnssec,
133                 nsid;   /*% Name Server ID (RFC 5001) */
134 #ifdef DIG_SIGCHASE
135 isc_boolean_t   sigchase;
136 #if DIG_SIGCHASE_TD
137         isc_boolean_t do_topdown,
138                 trace_root_sigchase,
139                 rdtype_sigchaseset,
140                 rdclass_sigchaseset;
141         /* Name we are going to validate RRset */
142         char textnamesigchase[MXNAME];
143 #endif
144 #endif
145
146         char textname[MXNAME]; /*% Name we're going to be looking up */
147         char cmdline[MXNAME];
148         dns_rdatatype_t rdtype;
149         dns_rdatatype_t qrdtype;
150 #if DIG_SIGCHASE_TD
151         dns_rdatatype_t rdtype_sigchase;
152         dns_rdatatype_t qrdtype_sigchase;
153         dns_rdataclass_t rdclass_sigchase;
154 #endif
155         dns_rdataclass_t rdclass;
156         isc_boolean_t rdtypeset;
157         isc_boolean_t rdclassset;
158         char namespace[BUFSIZE];
159         char onamespace[BUFSIZE];
160         isc_buffer_t namebuf;
161         isc_buffer_t onamebuf;
162         isc_buffer_t renderbuf;
163         char *sendspace;
164         dns_name_t *name;
165         isc_timer_t *timer;
166         isc_interval_t interval;
167         dns_message_t *sendmsg;
168         dns_name_t *oname;
169         ISC_LINK(dig_lookup_t) link;
170         ISC_LIST(dig_query_t) q;
171         ISC_LIST(dig_query_t) connecting;
172         dig_query_t *current_query;
173         dig_serverlist_t my_server_list;
174         dig_searchlist_t *origin;
175         dig_query_t *xfr_q;
176         isc_uint32_t retries;
177         int nsfound;
178         isc_uint16_t udpsize;
179         isc_int16_t edns;
180         isc_uint32_t ixfr_serial;
181         isc_buffer_t rdatabuf;
182         char rdatastore[MXNAME];
183         dst_context_t *tsigctx;
184         isc_buffer_t *querysig;
185         isc_uint32_t msgcounter;
186         dns_fixedname_t fdomain;
187 };
188
189 /*% The dig_query structure */
190 struct dig_query {
191         dig_lookup_t *lookup;
192         isc_boolean_t waiting_connect,
193                 pending_free,
194                 waiting_senddone,
195                 first_pass,
196                 first_soa_rcvd,
197                 second_rr_rcvd,
198                 first_repeat_rcvd,
199                 recv_made,
200                 warn_id;
201         isc_uint32_t first_rr_serial;
202         isc_uint32_t second_rr_serial;
203         isc_uint32_t msg_count;
204         isc_uint32_t rr_count;
205         isc_boolean_t ixfr_axfr;
206         char *servname;
207         char *userarg;
208         isc_bufferlist_t sendlist,
209                 recvlist,
210                 lengthlist;
211         isc_buffer_t recvbuf,
212                 lengthbuf,
213                 slbuf;
214         char *recvspace,
215                 lengthspace[4],
216                 slspace[4];
217         isc_socket_t *sock;
218         ISC_LINK(dig_query_t) link;
219         ISC_LINK(dig_query_t) clink;
220         isc_sockaddr_t sockaddr;
221         isc_time_t time_sent;
222         isc_uint64_t byte_count;
223         isc_buffer_t sendbuf;
224 };
225
226 struct dig_server {
227         char servername[MXNAME];
228         char userarg[MXNAME];
229         ISC_LINK(dig_server_t) link;
230 };
231
232 struct dig_searchlist {
233         char origin[MXNAME];
234         ISC_LINK(dig_searchlist_t) link;
235 };
236 #ifdef DIG_SIGCHASE
237 struct dig_message {
238                 dns_message_t *msg;
239                 ISC_LINK(dig_message_t) link;
240 };
241 #endif
242
243 typedef ISC_LIST(dig_searchlist_t) dig_searchlistlist_t;
244 typedef ISC_LIST(dig_lookup_t) dig_lookuplist_t;
245
246 /*
247  * Externals from dighost.c
248  */
249
250 extern dig_lookuplist_t lookup_list;
251 extern dig_serverlist_t server_list;
252 extern dig_searchlistlist_t search_list;
253 extern unsigned int extrabytes;
254
255 extern isc_boolean_t check_ra, have_ipv4, have_ipv6, specified_source,
256         usesearch, showsearch, qr;
257 extern in_port_t port;
258 extern unsigned int timeout;
259 extern isc_mem_t *mctx;
260 extern dns_messageid_t id;
261 extern int sendcount;
262 extern int ndots;
263 extern int lookup_counter;
264 extern int exitcode;
265 extern isc_sockaddr_t bind_address;
266 extern char keynametext[MXNAME];
267 extern char keyfile[MXNAME];
268 extern char keysecret[MXNAME];
269 extern dns_name_t *hmacname;
270 extern unsigned int digestbits;
271 #ifdef DIG_SIGCHASE
272 extern char trustedkey[MXNAME];
273 #endif
274 extern dns_tsigkey_t *key;
275 extern isc_boolean_t validated;
276 extern isc_taskmgr_t *taskmgr;
277 extern isc_task_t *global_task;
278 extern isc_boolean_t free_now;
279 extern isc_boolean_t debugging, debugtiming, memdebugging;
280 extern isc_boolean_t keep_open;
281
282 extern char *progname;
283 extern int tries;
284 extern int fatalexit;
285 #ifdef WITH_IDN
286 extern int idnoptions;
287 #endif
288
289 /*
290  * Routines in dighost.c.
291  */
292 isc_result_t
293 get_address(char *host, in_port_t port, isc_sockaddr_t *sockaddr);
294
295 int
296 getaddresses(dig_lookup_t *lookup, const char *host, isc_result_t *resultp);
297
298 isc_result_t
299 get_reverse(char *reverse, size_t len, char *value, isc_boolean_t ip6_int,
300             isc_boolean_t strict);
301
302 ISC_PLATFORM_NORETURN_PRE void
303 fatal(const char *format, ...)
304 ISC_FORMAT_PRINTF(1, 2) ISC_PLATFORM_NORETURN_POST;
305
306 void
307 debug(const char *format, ...) ISC_FORMAT_PRINTF(1, 2);
308
309 void
310 check_result(isc_result_t result, const char *msg);
311
312 void
313 setup_lookup(dig_lookup_t *lookup);
314
315 void
316 destroy_lookup(dig_lookup_t *lookup);
317
318 void
319 do_lookup(dig_lookup_t *lookup);
320
321 void
322 start_lookup(void);
323
324 void
325 onrun_callback(isc_task_t *task, isc_event_t *event);
326
327 int
328 dhmain(int argc, char **argv);
329
330 void
331 setup_libs(void);
332
333 void
334 setup_system(void);
335
336 isc_result_t
337 parse_uint(isc_uint32_t *uip, const char *value, isc_uint32_t max,
338            const char *desc);
339
340 void
341 parse_hmac(const char *hmacstr);
342
343 dig_lookup_t *
344 requeue_lookup(dig_lookup_t *lookold, isc_boolean_t servers);
345
346 dig_lookup_t *
347 make_empty_lookup(void);
348
349 dig_lookup_t *
350 clone_lookup(dig_lookup_t *lookold, isc_boolean_t servers);
351
352 dig_server_t *
353 make_server(const char *servname, const char *userarg);
354
355 void
356 flush_server_list(void);
357
358 void
359 set_nameserver(char *opt);
360
361 void
362 clone_server_list(dig_serverlist_t src,
363                   dig_serverlist_t *dest);
364
365 void
366 cancel_all(void);
367
368 void
369 destroy_libs(void);
370
371 void
372 set_search_domain(char *domain);
373
374 #ifdef DIG_SIGCHASE
375 void
376 clean_trustedkey(void);
377 #endif
378
379 /*
380  * Routines to be defined in dig.c, host.c, and nslookup.c.
381  */
382 #ifdef DIG_SIGCHASE
383 isc_result_t
384 printrdataset(dns_name_t *owner_name, dns_rdataset_t *rdataset,
385               isc_buffer_t *target);
386 #endif
387
388 isc_result_t
389 printmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers);
390 /*%<
391  * Print the final result of the lookup.
392  */
393
394 void
395 received(int bytes, isc_sockaddr_t *from, dig_query_t *query);
396 /*%<
397  * Print a message about where and when the response
398  * was received from, like the final comment in the
399  * output of "dig".
400  */
401
402 void
403 trying(char *frm, dig_lookup_t *lookup);
404
405 void
406 dighost_shutdown(void);
407
408 char *
409 next_token(char **stringp, const char *delim);
410
411 #ifdef DIG_SIGCHASE
412 /* Chasing functions */
413 dns_rdataset_t *
414 chase_scanname(dns_name_t *name, dns_rdatatype_t type, dns_rdatatype_t covers);
415 void
416 chase_sig(dns_message_t *msg);
417 #endif
418
419 ISC_LANG_ENDDECLS
420
421 #endif