]> CyberLeo.Net >> Repos - FreeBSD/stable/9.git/blob - contrib/bind9/bin/dig/include/dig/dig.h
MFC 253983, 253984:
[FreeBSD/stable/9.git] / contrib / bind9 / bin / dig / include / dig / dig.h
1 /*
2  * Copyright (C) 2004-2009, 2011, 2012  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         char *servname;
206         char *userarg;
207         isc_bufferlist_t sendlist,
208                 recvlist,
209                 lengthlist;
210         isc_buffer_t recvbuf,
211                 lengthbuf,
212                 slbuf;
213         char *recvspace,
214                 lengthspace[4],
215                 slspace[4];
216         isc_socket_t *sock;
217         ISC_LINK(dig_query_t) link;
218         ISC_LINK(dig_query_t) clink;
219         isc_sockaddr_t sockaddr;
220         isc_time_t time_sent;
221         isc_uint64_t byte_count;
222         isc_buffer_t sendbuf;
223 };
224
225 struct dig_server {
226         char servername[MXNAME];
227         char userarg[MXNAME];
228         ISC_LINK(dig_server_t) link;
229 };
230
231 struct dig_searchlist {
232         char origin[MXNAME];
233         ISC_LINK(dig_searchlist_t) link;
234 };
235 #ifdef DIG_SIGCHASE
236 struct dig_message {
237                 dns_message_t *msg;
238                 ISC_LINK(dig_message_t) link;
239 };
240 #endif
241
242 typedef ISC_LIST(dig_searchlist_t) dig_searchlistlist_t;
243 typedef ISC_LIST(dig_lookup_t) dig_lookuplist_t;
244
245 /*
246  * Externals from dighost.c
247  */
248
249 extern dig_lookuplist_t lookup_list;
250 extern dig_serverlist_t server_list;
251 extern dig_searchlistlist_t search_list;
252 extern unsigned int extrabytes;
253
254 extern isc_boolean_t check_ra, have_ipv4, have_ipv6, specified_source,
255         usesearch, showsearch, qr;
256 extern in_port_t port;
257 extern unsigned int timeout;
258 extern isc_mem_t *mctx;
259 extern dns_messageid_t id;
260 extern int sendcount;
261 extern int ndots;
262 extern int lookup_counter;
263 extern int exitcode;
264 extern isc_sockaddr_t bind_address;
265 extern char keynametext[MXNAME];
266 extern char keyfile[MXNAME];
267 extern char keysecret[MXNAME];
268 extern dns_name_t *hmacname;
269 extern unsigned int digestbits;
270 #ifdef DIG_SIGCHASE
271 extern char trustedkey[MXNAME];
272 #endif
273 extern dns_tsigkey_t *key;
274 extern isc_boolean_t validated;
275 extern isc_taskmgr_t *taskmgr;
276 extern isc_task_t *global_task;
277 extern isc_boolean_t free_now;
278 extern isc_boolean_t debugging, memdebugging;
279
280 extern char *progname;
281 extern int tries;
282 extern int fatalexit;
283 #ifdef WITH_IDN
284 extern int idnoptions;
285 #endif
286
287 /*
288  * Routines in dighost.c.
289  */
290 isc_result_t
291 get_address(char *host, in_port_t port, isc_sockaddr_t *sockaddr);
292
293 int
294 getaddresses(dig_lookup_t *lookup, const char *host, isc_result_t *resultp);
295
296 isc_result_t
297 get_reverse(char *reverse, size_t len, char *value, isc_boolean_t ip6_int,
298             isc_boolean_t strict);
299
300 ISC_PLATFORM_NORETURN_PRE void
301 fatal(const char *format, ...)
302 ISC_FORMAT_PRINTF(1, 2) ISC_PLATFORM_NORETURN_POST;
303
304 void
305 debug(const char *format, ...) ISC_FORMAT_PRINTF(1, 2);
306
307 void
308 check_result(isc_result_t result, const char *msg);
309
310 void
311 setup_lookup(dig_lookup_t *lookup);
312
313 void
314 destroy_lookup(dig_lookup_t *lookup);
315
316 void
317 do_lookup(dig_lookup_t *lookup);
318
319 void
320 start_lookup(void);
321
322 void
323 onrun_callback(isc_task_t *task, isc_event_t *event);
324
325 int
326 dhmain(int argc, char **argv);
327
328 void
329 setup_libs(void);
330
331 void
332 setup_system(void);
333
334 isc_result_t
335 parse_uint(isc_uint32_t *uip, const char *value, isc_uint32_t max,
336            const char *desc);
337
338 void
339 parse_hmac(const char *hmacstr);
340
341 dig_lookup_t *
342 requeue_lookup(dig_lookup_t *lookold, isc_boolean_t servers);
343
344 dig_lookup_t *
345 make_empty_lookup(void);
346
347 dig_lookup_t *
348 clone_lookup(dig_lookup_t *lookold, isc_boolean_t servers);
349
350 dig_server_t *
351 make_server(const char *servname, const char *userarg);
352
353 void
354 flush_server_list(void);
355
356 void
357 set_nameserver(char *opt);
358
359 void
360 clone_server_list(dig_serverlist_t src,
361                   dig_serverlist_t *dest);
362
363 void
364 cancel_all(void);
365
366 void
367 destroy_libs(void);
368
369 void
370 set_search_domain(char *domain);
371
372 #ifdef DIG_SIGCHASE
373 void
374 clean_trustedkey(void);
375 #endif
376
377 /*
378  * Routines to be defined in dig.c, host.c, and nslookup.c.
379  */
380 #ifdef DIG_SIGCHASE
381 isc_result_t
382 printrdataset(dns_name_t *owner_name, dns_rdataset_t *rdataset,
383               isc_buffer_t *target);
384 #endif
385
386 isc_result_t
387 printmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers);
388 /*%<
389  * Print the final result of the lookup.
390  */
391
392 void
393 received(int bytes, isc_sockaddr_t *from, dig_query_t *query);
394 /*%<
395  * Print a message about where and when the response
396  * was received from, like the final comment in the
397  * output of "dig".
398  */
399
400 void
401 trying(char *frm, dig_lookup_t *lookup);
402
403 void
404 dighost_shutdown(void);
405
406 char *
407 next_token(char **stringp, const char *delim);
408
409 #ifdef DIG_SIGCHASE
410 /* Chasing functions */
411 dns_rdataset_t *
412 chase_scanname(dns_name_t *name, dns_rdatatype_t type, dns_rdatatype_t covers);
413 void
414 chase_sig(dns_message_t *msg);
415 #endif
416
417 ISC_LANG_ENDDECLS
418
419 #endif