]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - 6/contrib/bind9/bin/dig/include/dig/dig.h
merge fix for boot-time hang on centos' xen
[FreeBSD/FreeBSD.git] / 6 / contrib / bind9 / bin / dig / include / dig / dig.h
1 /*
2  * Copyright (C) 2004-2007  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.71.2.6.2.18 2007/08/28 07:19:07 tbox Exp $ */
19
20 #ifndef DIG_H
21 #define DIG_H
22
23 #include <dns/rdatalist.h>
24
25 #include <dst/dst.h>
26
27 #include <isc/boolean.h>
28 #include <isc/buffer.h>
29 #include <isc/bufferlist.h>
30 #include <isc/formatcheck.h>
31 #include <isc/lang.h>
32 #include <isc/list.h>
33 #include <isc/mem.h>
34 #include <isc/print.h>
35 #include <isc/sockaddr.h>
36 #include <isc/socket.h>
37
38 #define MXSERV 20
39 #define MXNAME (DNS_NAME_MAXTEXT+1)
40 #define MXRD 32
41 #define BUFSIZE 512
42 #define COMMSIZE 0xffff
43 #ifndef RESOLV_CONF
44 #define RESOLV_CONF "/etc/resolv.conf"
45 #endif
46 #define OUTPUTBUF 32767
47 #define MAXRRLIMIT 0xffffffff
48 #define MAXTIMEOUT 0xffff
49 #define MAXTRIES 0xffffffff
50 #define MAXNDOTS 0xffff
51 #define MAXPORT 0xffff
52 #define MAXSERIAL 0xffffffff
53
54 /*
55  * Default timeout values
56  */
57 #define TCP_TIMEOUT 10
58 #define UDP_TIMEOUT 5
59
60 #define SERVER_TIMEOUT 1
61
62 #define LOOKUP_LIMIT 64
63 /*
64  * Lookup_limit is just a limiter, keeping too many lookups from being
65  * created.  It's job is mainly to prevent the program from running away
66  * in a tight loop of constant lookups.  It's value is arbitrary.
67  */
68
69 /*
70  * Defaults for the sigchase suboptions.  Consolidated here because
71  * these control the layout of dig_lookup_t (among other things).
72  */
73 #ifdef DIG_SIGCHASE
74 #ifndef DIG_SIGCHASE_BU
75 #define DIG_SIGCHASE_BU 1
76 #endif
77 #ifndef DIG_SIGCHASE_TD
78 #define DIG_SIGCHASE_TD 1
79 #endif
80 #endif
81
82 ISC_LANG_BEGINDECLS
83
84 typedef struct dig_lookup dig_lookup_t;
85 typedef struct dig_query dig_query_t;
86 typedef struct dig_server dig_server_t;
87 #ifdef DIG_SIGCHASE
88 typedef struct dig_message dig_message_t;
89 #endif
90 typedef ISC_LIST(dig_server_t) dig_serverlist_t;
91 typedef struct dig_searchlist dig_searchlist_t;
92
93 struct dig_lookup {
94         isc_boolean_t
95                 pending, /* Pending a successful answer */
96                 waiting_connect,
97                 doing_xfr,
98                 ns_search_only, /* dig +nssearch, host -C */
99                 identify, /* Append an "on server <foo>" message */
100                 identify_previous_line, /* Prepend a "Nameserver <foo>:"
101                                            message, with newline and tab */
102                 ignore,
103                 recurse,
104                 aaonly,
105                 adflag,
106                 cdflag,
107                 trace, /* dig +trace */
108                 trace_root, /* initial query for either +trace or +nssearch */
109                 tcp_mode,
110                 ip6_int,
111                 comments,
112                 stats,
113                 section_question,
114                 section_answer,
115                 section_authority,
116                 section_additional,
117                 servfail_stops,
118                 new_search,
119                 need_search,
120                 done_as_is,
121                 besteffort,
122                 dnssec;
123 #ifdef DIG_SIGCHASE
124 isc_boolean_t   sigchase;
125 #if DIG_SIGCHASE_TD
126         isc_boolean_t do_topdown,
127                 trace_root_sigchase,
128                 rdtype_sigchaseset,
129                 rdclass_sigchaseset;
130         /* Name we are going to validate RRset */
131         char textnamesigchase[MXNAME];
132 #endif
133 #endif
134         
135         char textname[MXNAME]; /* Name we're going to be looking up */
136         char cmdline[MXNAME];
137         dns_rdatatype_t rdtype;
138         dns_rdatatype_t qrdtype;
139 #if DIG_SIGCHASE_TD
140         dns_rdatatype_t rdtype_sigchase;
141         dns_rdatatype_t qrdtype_sigchase;
142         dns_rdataclass_t rdclass_sigchase;
143 #endif
144         dns_rdataclass_t rdclass;
145         isc_boolean_t rdtypeset;
146         isc_boolean_t rdclassset;
147         char namespace[BUFSIZE];
148         char onamespace[BUFSIZE];
149         isc_buffer_t namebuf;
150         isc_buffer_t onamebuf;
151         isc_buffer_t renderbuf;
152         char *sendspace;
153         dns_name_t *name;
154         isc_timer_t *timer;
155         isc_interval_t interval;
156         dns_message_t *sendmsg;
157         dns_name_t *oname;
158         ISC_LINK(dig_lookup_t) link;
159         ISC_LIST(dig_query_t) q;
160         dig_query_t *current_query;
161         dig_serverlist_t my_server_list;
162         dig_searchlist_t *origin;
163         dig_query_t *xfr_q;
164         isc_uint32_t retries;
165         int nsfound;
166         isc_uint16_t udpsize;
167         isc_uint32_t ixfr_serial;
168         isc_buffer_t rdatabuf;
169         char rdatastore[MXNAME];
170         dst_context_t *tsigctx;
171         isc_buffer_t *querysig;
172         isc_uint32_t msgcounter;
173 };
174
175 struct dig_query {
176         dig_lookup_t *lookup;
177         isc_boolean_t waiting_connect,
178                 pending_free,
179                 waiting_senddone,
180                 first_pass,
181                 first_soa_rcvd,
182                 second_rr_rcvd,
183                 first_repeat_rcvd,
184                 recv_made,
185                 warn_id;
186         isc_uint32_t first_rr_serial;
187         isc_uint32_t second_rr_serial;
188         isc_uint32_t msg_count;
189         isc_uint32_t rr_count;
190         char *servname;
191         char *userarg;
192         isc_bufferlist_t sendlist,
193                 recvlist,
194                 lengthlist;
195         isc_buffer_t recvbuf,
196                 lengthbuf,
197                 slbuf;
198         char *recvspace,
199                 lengthspace[4],
200                 slspace[4];
201         isc_socket_t *sock;
202         ISC_LINK(dig_query_t) link;
203         isc_sockaddr_t sockaddr;
204         isc_time_t time_sent;
205         isc_buffer_t sendbuf;
206 };
207
208 struct dig_server {
209         char servername[MXNAME];
210         char userarg[MXNAME];
211         ISC_LINK(dig_server_t) link;
212 };
213
214 struct dig_searchlist {
215         char origin[MXNAME];
216         ISC_LINK(dig_searchlist_t) link;
217 };
218 #ifdef DIG_SIGCHASE
219 struct dig_message {
220                 dns_message_t *msg;
221                 ISC_LINK(dig_message_t) link;
222 };
223 #endif
224
225 typedef ISC_LIST(dig_searchlist_t) dig_searchlistlist_t;
226 typedef ISC_LIST(dig_lookup_t) dig_lookuplist_t;
227
228 /*
229  * Externals from dighost.c
230  */
231
232 extern dig_lookuplist_t lookup_list;
233 extern dig_serverlist_t server_list;
234 extern dig_searchlistlist_t search_list;
235
236 extern isc_boolean_t have_ipv4, have_ipv6, specified_source,
237         usesearch, qr;
238 extern in_port_t port;
239 extern unsigned int timeout;
240 extern isc_mem_t *mctx;
241 extern dns_messageid_t id;
242 extern int sendcount;
243 extern int ndots;
244 extern int lookup_counter;
245 extern int exitcode;
246 extern isc_sockaddr_t bind_address;
247 extern char keynametext[MXNAME];
248 extern char keyfile[MXNAME];
249 extern char keysecret[MXNAME];
250 #ifdef DIG_SIGCHASE
251 extern char trustedkey[MXNAME];
252 #endif
253 extern dns_tsigkey_t *key;
254 extern isc_boolean_t validated;
255 extern isc_taskmgr_t *taskmgr;
256 extern isc_task_t *global_task;
257 extern isc_boolean_t free_now;
258 extern isc_boolean_t debugging, memdebugging;
259
260 extern char *progname;
261 extern int tries;
262 extern int fatalexit;
263
264 /*
265  * Routines in dighost.c.
266  */
267 void
268 get_address(char *host, in_port_t port, isc_sockaddr_t *sockaddr);
269
270 isc_result_t
271 get_reverse(char *reverse, size_t len, char *value, isc_boolean_t ip6_int,
272             isc_boolean_t strict);
273
274 void
275 fatal(const char *format, ...) ISC_FORMAT_PRINTF(1, 2);
276
277 void
278 debug(const char *format, ...) ISC_FORMAT_PRINTF(1, 2);
279
280 void
281 check_result(isc_result_t result, const char *msg);
282
283 void
284 setup_lookup(dig_lookup_t *lookup);
285
286 void
287 destroy_lookup(dig_lookup_t *lookup);
288
289 void
290 do_lookup(dig_lookup_t *lookup);
291
292 void
293 start_lookup(void);
294
295 void
296 onrun_callback(isc_task_t *task, isc_event_t *event);
297
298 int
299 dhmain(int argc, char **argv);
300
301 void
302 setup_libs(void);
303
304 void
305 setup_system(void);
306
307 dig_lookup_t *
308 requeue_lookup(dig_lookup_t *lookold, isc_boolean_t servers);
309
310 dig_lookup_t *
311 make_empty_lookup(void);
312
313 dig_lookup_t *
314 clone_lookup(dig_lookup_t *lookold, isc_boolean_t servers);
315
316 dig_server_t *
317 make_server(const char *servname, const char *userarg);
318
319 void
320 flush_server_list(void);
321
322 void
323 set_nameserver(char *opt);
324
325 void
326 clone_server_list(dig_serverlist_t src,
327                   dig_serverlist_t *dest);
328
329 void
330 cancel_all(void);
331
332 void
333 destroy_libs(void);
334
335 void
336 set_search_domain(char *domain);
337
338 #ifdef DIG_SIGCHASE
339 void
340 clean_trustedkey(void);
341 #endif
342
343 /*
344  * Routines to be defined in dig.c, host.c, and nslookup.c.
345  */
346 #ifdef DIG_SIGCHASE
347 isc_result_t
348 printrdataset(dns_name_t *owner_name, dns_rdataset_t *rdataset,
349               isc_buffer_t *target);
350 #endif
351
352 isc_result_t
353 printmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers);
354 /*
355  * Print the final result of the lookup.
356  */
357
358 void
359 received(int bytes, isc_sockaddr_t *from, dig_query_t *query);
360 /*
361  * Print a message about where and when the response
362  * was received from, like the final comment in the
363  * output of "dig".
364  */
365
366 void
367 trying(char *frm, dig_lookup_t *lookup);
368
369 void
370 dighost_shutdown(void);
371
372 char *
373 next_token(char **stringp, const char *delim);
374
375 #ifdef DIG_SIGCHASE
376 /* Chasing functions */
377 dns_rdataset_t *
378 chase_scanname(dns_name_t *name, dns_rdatatype_t type, dns_rdatatype_t covers);
379 void
380 chase_sig(dns_message_t *msg);
381 #endif
382
383 ISC_LANG_ENDDECLS
384
385 #endif