PageRenderTime 81ms CodeModel.GetById 30ms app.highlight 45ms RepoModel.GetById 1ms app.codeStats 1ms

/contrib/bind9/bin/dig/include/dig/dig.h

https://bitbucket.org/freebsd/freebsd-head/
C++ Header | 417 lines | 299 code | 59 blank | 59 comment | 0 complexity | af6d9fcd3045bc572c5f940d4ca9cf78 MD5 | raw file
  1/*
  2 * Copyright (C) 2004-2009, 2011  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
 91ISC_LANG_BEGINDECLS
 92
 93typedef struct dig_lookup dig_lookup_t;
 94typedef struct dig_query dig_query_t;
 95typedef struct dig_server dig_server_t;
 96#ifdef DIG_SIGCHASE
 97typedef struct dig_message dig_message_t;
 98#endif
 99typedef ISC_LIST(dig_server_t) dig_serverlist_t;
100typedef struct dig_searchlist dig_searchlist_t;
101
102/*% The dig_lookup structure */
103struct 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
135isc_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	dig_query_t *current_query;
172	dig_serverlist_t my_server_list;
173	dig_searchlist_t *origin;
174	dig_query_t *xfr_q;
175	isc_uint32_t retries;
176	int nsfound;
177	isc_uint16_t udpsize;
178	isc_int16_t edns;
179	isc_uint32_t ixfr_serial;
180	isc_buffer_t rdatabuf;
181	char rdatastore[MXNAME];
182	dst_context_t *tsigctx;
183	isc_buffer_t *querysig;
184	isc_uint32_t msgcounter;
185	dns_fixedname_t fdomain;
186};
187
188/*% The dig_query structure */
189struct dig_query {
190	dig_lookup_t *lookup;
191	isc_boolean_t waiting_connect,
192		pending_free,
193		waiting_senddone,
194		first_pass,
195		first_soa_rcvd,
196		second_rr_rcvd,
197		first_repeat_rcvd,
198		recv_made,
199		warn_id;
200	isc_uint32_t first_rr_serial;
201	isc_uint32_t second_rr_serial;
202	isc_uint32_t msg_count;
203	isc_uint32_t rr_count;
204	char *servname;
205	char *userarg;
206	isc_bufferlist_t sendlist,
207		recvlist,
208		lengthlist;
209	isc_buffer_t recvbuf,
210		lengthbuf,
211		slbuf;
212	char *recvspace,
213		lengthspace[4],
214		slspace[4];
215	isc_socket_t *sock;
216	ISC_LINK(dig_query_t) link;
217	isc_sockaddr_t sockaddr;
218	isc_time_t time_sent;
219	isc_uint64_t byte_count;
220	isc_buffer_t sendbuf;
221};
222
223struct dig_server {
224	char servername[MXNAME];
225	char userarg[MXNAME];
226	ISC_LINK(dig_server_t) link;
227};
228
229struct dig_searchlist {
230	char origin[MXNAME];
231	ISC_LINK(dig_searchlist_t) link;
232};
233#ifdef DIG_SIGCHASE
234struct dig_message {
235		dns_message_t *msg;
236		ISC_LINK(dig_message_t) link;
237};
238#endif
239
240typedef ISC_LIST(dig_searchlist_t) dig_searchlistlist_t;
241typedef ISC_LIST(dig_lookup_t) dig_lookuplist_t;
242
243/*
244 * Externals from dighost.c
245 */
246
247extern dig_lookuplist_t lookup_list;
248extern dig_serverlist_t server_list;
249extern dig_searchlistlist_t search_list;
250extern unsigned int extrabytes;
251
252extern isc_boolean_t check_ra, have_ipv4, have_ipv6, specified_source,
253	usesearch, showsearch, qr;
254extern in_port_t port;
255extern unsigned int timeout;
256extern isc_mem_t *mctx;
257extern dns_messageid_t id;
258extern int sendcount;
259extern int ndots;
260extern int lookup_counter;
261extern int exitcode;
262extern isc_sockaddr_t bind_address;
263extern char keynametext[MXNAME];
264extern char keyfile[MXNAME];
265extern char keysecret[MXNAME];
266extern dns_name_t *hmacname;
267extern unsigned int digestbits;
268#ifdef DIG_SIGCHASE
269extern char trustedkey[MXNAME];
270#endif
271extern dns_tsigkey_t *key;
272extern isc_boolean_t validated;
273extern isc_taskmgr_t *taskmgr;
274extern isc_task_t *global_task;
275extern isc_boolean_t free_now;
276extern isc_boolean_t debugging, memdebugging;
277
278extern char *progname;
279extern int tries;
280extern int fatalexit;
281#ifdef WITH_IDN
282extern int idnoptions;
283#endif
284
285/*
286 * Routines in dighost.c.
287 */
288isc_result_t
289get_address(char *host, in_port_t port, isc_sockaddr_t *sockaddr);
290
291int
292getaddresses(dig_lookup_t *lookup, const char *host, isc_result_t *resultp);
293
294isc_result_t
295get_reverse(char *reverse, size_t len, char *value, isc_boolean_t ip6_int,
296	    isc_boolean_t strict);
297
298ISC_PLATFORM_NORETURN_PRE void
299fatal(const char *format, ...)
300ISC_FORMAT_PRINTF(1, 2) ISC_PLATFORM_NORETURN_POST;
301
302void
303debug(const char *format, ...) ISC_FORMAT_PRINTF(1, 2);
304
305void
306check_result(isc_result_t result, const char *msg);
307
308void
309setup_lookup(dig_lookup_t *lookup);
310
311void
312destroy_lookup(dig_lookup_t *lookup);
313
314void
315do_lookup(dig_lookup_t *lookup);
316
317void
318start_lookup(void);
319
320void
321onrun_callback(isc_task_t *task, isc_event_t *event);
322
323int
324dhmain(int argc, char **argv);
325
326void
327setup_libs(void);
328
329void
330setup_system(void);
331
332isc_result_t
333parse_uint(isc_uint32_t *uip, const char *value, isc_uint32_t max,
334	   const char *desc);
335
336void
337parse_hmac(const char *hmacstr);
338
339dig_lookup_t *
340requeue_lookup(dig_lookup_t *lookold, isc_boolean_t servers);
341
342dig_lookup_t *
343make_empty_lookup(void);
344
345dig_lookup_t *
346clone_lookup(dig_lookup_t *lookold, isc_boolean_t servers);
347
348dig_server_t *
349make_server(const char *servname, const char *userarg);
350
351void
352flush_server_list(void);
353
354void
355set_nameserver(char *opt);
356
357void
358clone_server_list(dig_serverlist_t src,
359		  dig_serverlist_t *dest);
360
361void
362cancel_all(void);
363
364void
365destroy_libs(void);
366
367void
368set_search_domain(char *domain);
369
370#ifdef DIG_SIGCHASE
371void
372clean_trustedkey(void);
373#endif
374
375/*
376 * Routines to be defined in dig.c, host.c, and nslookup.c.
377 */
378#ifdef DIG_SIGCHASE
379isc_result_t
380printrdataset(dns_name_t *owner_name, dns_rdataset_t *rdataset,
381	      isc_buffer_t *target);
382#endif
383
384isc_result_t
385printmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers);
386/*%<
387 * Print the final result of the lookup.
388 */
389
390void
391received(int bytes, isc_sockaddr_t *from, dig_query_t *query);
392/*%<
393 * Print a message about where and when the response
394 * was received from, like the final comment in the
395 * output of "dig".
396 */
397
398void
399trying(char *frm, dig_lookup_t *lookup);
400
401void
402dighost_shutdown(void);
403
404char *
405next_token(char **stringp, const char *delim);
406
407#ifdef DIG_SIGCHASE
408/* Chasing functions */
409dns_rdataset_t *
410chase_scanname(dns_name_t *name, dns_rdatatype_t type, dns_rdatatype_t covers);
411void
412chase_sig(dns_message_t *msg);
413#endif
414
415ISC_LANG_ENDDECLS
416
417#endif