Merge from vendor branch LESS:
[dragonfly.git] / contrib / bind-9.3 / bin / dig / include / dig / dig.h
1 /*
2  * Copyright (C) 2004-2006  Internet Systems Consortium, Inc. ("ISC")
3  * Copyright (C) 2000-2003  Internet Software Consortium.
4  *
5  * Permission to use, copy, modify, and 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.14 2006/12/07 01:26:33 marka 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                 besteffort,
120                 dnssec;
121 #ifdef DIG_SIGCHASE
122 isc_boolean_t   sigchase;
123 #if DIG_SIGCHASE_TD
124         isc_boolean_t do_topdown,
125                 trace_root_sigchase,
126                 rdtype_sigchaseset,
127                 rdclass_sigchaseset;
128         /* Name we are going to validate RRset */
129         char textnamesigchase[MXNAME];
130 #endif
131 #endif
132         
133         char textname[MXNAME]; /* Name we're going to be looking up */
134         char cmdline[MXNAME];
135         dns_rdatatype_t rdtype;
136         dns_rdatatype_t qrdtype;
137 #if DIG_SIGCHASE_TD
138         dns_rdatatype_t rdtype_sigchase;
139         dns_rdatatype_t qrdtype_sigchase;
140         dns_rdataclass_t rdclass_sigchase;
141 #endif
142         dns_rdataclass_t rdclass;
143         isc_boolean_t rdtypeset;
144         isc_boolean_t rdclassset;
145         char namespace[BUFSIZE];
146         char onamespace[BUFSIZE];
147         isc_buffer_t namebuf;
148         isc_buffer_t onamebuf;
149         isc_buffer_t renderbuf;
150         char *sendspace;
151         dns_name_t *name;
152         isc_timer_t *timer;
153         isc_interval_t interval;
154         dns_message_t *sendmsg;
155         dns_name_t *oname;
156         ISC_LINK(dig_lookup_t) link;
157         ISC_LIST(dig_query_t) q;
158         dig_query_t *current_query;
159         dig_serverlist_t my_server_list;
160         dig_searchlist_t *origin;
161         dig_query_t *xfr_q;
162         isc_uint32_t retries;
163         int nsfound;
164         isc_uint16_t udpsize;
165         isc_uint32_t ixfr_serial;
166         isc_buffer_t rdatabuf;
167         char rdatastore[MXNAME];
168         dst_context_t *tsigctx;
169         isc_buffer_t *querysig;
170         isc_uint32_t msgcounter;
171 };
172
173 struct dig_query {
174         dig_lookup_t *lookup;
175         isc_boolean_t waiting_connect,
176                 pending_free,
177                 waiting_senddone,
178                 first_pass,
179                 first_soa_rcvd,
180                 second_rr_rcvd,
181                 first_repeat_rcvd,
182                 recv_made,
183                 warn_id;
184         isc_uint32_t first_rr_serial;
185         isc_uint32_t second_rr_serial;
186         isc_uint32_t msg_count;
187         isc_uint32_t rr_count;
188         char *servname;
189         char *userarg;
190         isc_bufferlist_t sendlist,
191                 recvlist,
192                 lengthlist;
193         isc_buffer_t recvbuf,
194                 lengthbuf,
195                 slbuf;
196         char *recvspace,
197                 lengthspace[4],
198                 slspace[4];
199         isc_socket_t *sock;
200         ISC_LINK(dig_query_t) link;
201         isc_sockaddr_t sockaddr;
202         isc_time_t time_sent;
203         isc_buffer_t sendbuf;
204 };
205
206 struct dig_server {
207         char servername[MXNAME];
208         char userarg[MXNAME];
209         ISC_LINK(dig_server_t) link;
210 };
211
212 struct dig_searchlist {
213         char origin[MXNAME];
214         ISC_LINK(dig_searchlist_t) link;
215 };
216 #ifdef DIG_SIGCHASE
217 struct dig_message {
218                 dns_message_t *msg;
219                 ISC_LINK(dig_message_t) link;
220 };
221 #endif
222
223 typedef ISC_LIST(dig_searchlist_t) dig_searchlistlist_t;
224 typedef ISC_LIST(dig_lookup_t) dig_lookuplist_t;
225
226 /*
227  * Externals from dighost.c
228  */
229
230 extern dig_lookuplist_t lookup_list;
231 extern dig_serverlist_t server_list;
232 extern dig_searchlistlist_t search_list;
233
234 extern isc_boolean_t have_ipv4, have_ipv6, specified_source,
235         usesearch, qr;
236 extern in_port_t port;
237 extern unsigned int timeout;
238 extern isc_mem_t *mctx;
239 extern dns_messageid_t id;
240 extern int sendcount;
241 extern int ndots;
242 extern int lookup_counter;
243 extern int exitcode;
244 extern isc_sockaddr_t bind_address;
245 extern char keynametext[MXNAME];
246 extern char keyfile[MXNAME];
247 extern char keysecret[MXNAME];
248 #ifdef DIG_SIGCHASE
249 extern char trustedkey[MXNAME];
250 #endif
251 extern dns_tsigkey_t *key;
252 extern isc_boolean_t validated;
253 extern isc_taskmgr_t *taskmgr;
254 extern isc_task_t *global_task;
255 extern isc_boolean_t free_now;
256 extern isc_boolean_t debugging, memdebugging;
257
258 extern char *progname;
259 extern int tries;
260 extern int fatalexit;
261
262 /*
263  * Routines in dighost.c.
264  */
265 void
266 get_address(char *host, in_port_t port, isc_sockaddr_t *sockaddr);
267
268 isc_result_t
269 get_reverse(char *reverse, size_t len, char *value, isc_boolean_t ip6_int,
270             isc_boolean_t strict);
271
272 void
273 fatal(const char *format, ...) ISC_FORMAT_PRINTF(1, 2);
274
275 void
276 debug(const char *format, ...) ISC_FORMAT_PRINTF(1, 2);
277
278 void
279 check_result(isc_result_t result, const char *msg);
280
281 void
282 setup_lookup(dig_lookup_t *lookup);
283
284 void
285 do_lookup(dig_lookup_t *lookup);
286
287 void
288 start_lookup(void);
289
290 void
291 onrun_callback(isc_task_t *task, isc_event_t *event);
292
293 int
294 dhmain(int argc, char **argv);
295
296 void
297 setup_libs(void);
298
299 void
300 setup_system(void);
301
302 dig_lookup_t *
303 requeue_lookup(dig_lookup_t *lookold, isc_boolean_t servers);
304
305 dig_lookup_t *
306 make_empty_lookup(void);
307
308 dig_lookup_t *
309 clone_lookup(dig_lookup_t *lookold, isc_boolean_t servers);
310
311 dig_server_t *
312 make_server(const char *servname, const char *userarg);
313
314 void
315 flush_server_list(void);
316
317 void
318 set_nameserver(char *opt);
319
320 void
321 clone_server_list(dig_serverlist_t src,
322                   dig_serverlist_t *dest);
323
324 void
325 cancel_all(void);
326
327 void
328 destroy_libs(void);
329
330 void
331 set_search_domain(char *domain);
332
333 #ifdef DIG_SIGCHASE
334 void
335 clean_trustedkey(void);
336 #endif
337
338 /*
339  * Routines to be defined in dig.c, host.c, and nslookup.c.
340  */
341 #ifdef DIG_SIGCHASE
342 isc_result_t
343 printrdataset(dns_name_t *owner_name, dns_rdataset_t *rdataset,
344               isc_buffer_t *target);
345 #endif
346
347 isc_result_t
348 printmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers);
349 /*
350  * Print the final result of the lookup.
351  */
352
353 void
354 received(int bytes, isc_sockaddr_t *from, dig_query_t *query);
355 /*
356  * Print a message about where and when the response
357  * was received from, like the final comment in the
358  * output of "dig".
359  */
360
361 void
362 trying(char *frm, dig_lookup_t *lookup);
363
364 void
365 dighost_shutdown(void);
366
367 char *
368 next_token(char **stringp, const char *delim);
369
370 #ifdef DIG_SIGCHASE
371 /* Chasing functions */
372 dns_rdataset_t *
373 chase_scanname(dns_name_t *name, dns_rdatatype_t type, dns_rdatatype_t covers);
374 void
375 chase_sig(dns_message_t *msg);
376 #endif
377
378 ISC_LANG_ENDDECLS
379
380 #endif