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