Annotation of src/usr.bin/dig/dig.h, Revision 1.6
1.1 florian 1: /*
2: * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
3: *
4: * Permission to use, copy, modify, and/or distribute this software for any
5: * purpose with or without fee is hereby granted, provided that the above
6: * copyright notice and this permission notice appear in all copies.
7: *
8: * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
9: * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10: * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
11: * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12: * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
13: * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14: * PERFORMANCE OF THIS SOFTWARE.
15: */
16:
17: #ifndef DIG_H
18: #define DIG_H
19:
20: /*! \file */
21:
22: #include <dst/dst.h>
23:
24: #include <isc/boolean.h>
25: #include <isc/buffer.h>
1.5 florian 26:
1.1 florian 27: #include <isc/list.h>
1.3 jsg 28: #include <isc/time.h>
1.1 florian 29: #include <isc/sockaddr.h>
30: #include <isc/socket.h>
31:
32: #define MXSERV 20
33: #define MXNAME (DNS_NAME_MAXTEXT+1)
34: #define MXRD 32
35: /*% Buffer Size */
36: #define BUFSIZE 512
37: #define COMMSIZE 0xffff
38: #ifndef RESOLV_CONF
39: /*% location of resolve.conf */
40: #define RESOLV_CONF "/etc/resolv.conf"
41: #endif
42: /*% output buffer */
43: #define OUTPUTBUF 32767
44: /*% Max RR Limit */
45: #define MAXRRLIMIT 0xffffffff
46: #define MAXTIMEOUT 0xffff
47: /*% Max number of tries */
48: #define MAXTRIES 0xffffffff
49: /*% Max number of dots */
50: #define MAXNDOTS 0xffff
51: /*% Max number of ports */
52: #define MAXPORT 0xffff
53: /*% Max serial number */
54: #define MAXSERIAL 0xffffffff
55:
56: /*% Default TCP Timeout */
57: #define TCP_TIMEOUT 10
58: /*% Default UDP Timeout */
59: #define UDP_TIMEOUT 5
60:
61: #define SERVER_TIMEOUT 1
62:
63: #define LOOKUP_LIMIT 64
64: /*%
65: * Lookup_limit is just a limiter, keeping too many lookups from being
66: * created. It's job is mainly to prevent the program from running away
67: * in a tight loop of constant lookups. It's value is arbitrary.
68: */
69:
70: /*
71: * Defaults for the sigchase suboptions. Consolidated here because
72: * these control the layout of dig_lookup_t (among other things).
73: */
74:
75: typedef struct dig_lookup dig_lookup_t;
76: typedef struct dig_query dig_query_t;
77: typedef struct dig_server dig_server_t;
78: typedef ISC_LIST(dig_server_t) dig_serverlist_t;
79: typedef struct dig_searchlist dig_searchlist_t;
80:
81: /*% The dig_lookup structure */
82: struct dig_lookup {
83: isc_boolean_t
84: pending, /*%< Pending a successful answer */
85: waiting_connect,
86: doing_xfr,
87: ns_search_only, /*%< dig +nssearch, host -C */
88: identify, /*%< Append an "on server <foo>" message */
89: identify_previous_line, /*% Prepend a "Nameserver <foo>:"
90: message, with newline and tab */
91: ignore,
92: recurse,
93: aaonly,
94: adflag,
95: cdflag,
96: trace, /*% dig +trace */
97: trace_root, /*% initial query for either +trace or +nssearch */
98: tcp_mode,
99: tcp_mode_set,
100: ip6_int,
101: comments,
102: stats,
103: section_question,
104: section_answer,
105: section_authority,
106: section_additional,
107: servfail_stops,
108: new_search,
109: need_search,
110: done_as_is,
111: besteffort,
112: dnssec,
113: expire,
114: sit,
115: nsid, /*% Name Server ID (RFC 5001) */
116: ednsneg,
117: mapped,
118: idnout;
119:
120: char textname[MXNAME]; /*% Name we're going to be looking up */
121: char cmdline[MXNAME];
122: dns_rdatatype_t rdtype;
123: dns_rdatatype_t qrdtype;
124: dns_rdataclass_t rdclass;
125: isc_boolean_t rdtypeset;
126: isc_boolean_t rdclassset;
127: char name_space[BUFSIZE];
128: char oname_space[BUFSIZE];
129: isc_buffer_t namebuf;
130: isc_buffer_t onamebuf;
131: isc_buffer_t renderbuf;
132: char *sendspace;
133: dns_name_t *name;
134: interval_t interval;
135: dns_message_t *sendmsg;
136: dns_name_t *oname;
137: ISC_LINK(dig_lookup_t) link;
138: ISC_LIST(dig_query_t) q;
139: ISC_LIST(dig_query_t) connecting;
140: dig_query_t *current_query;
141: dig_serverlist_t my_server_list;
142: dig_searchlist_t *origin;
143: dig_query_t *xfr_q;
144: uint32_t retries;
145: int nsfound;
146: uint16_t udpsize;
147: int16_t edns;
148: uint32_t ixfr_serial;
149: isc_buffer_t rdatabuf;
150: char rdatastore[MXNAME];
151: dst_context_t *tsigctx;
152: isc_buffer_t *querysig;
153: uint32_t msgcounter;
154: dns_fixedname_t fdomain;
155: isc_sockaddr_t *ecs_addr;
156: char *sitvalue;
157: dns_ednsopt_t *ednsopts;
158: unsigned int ednsoptscnt;
159: unsigned int ednsflags;
160: dns_opcode_t opcode;
161: unsigned int eoferr;
162: };
163:
164: /*% The dig_query structure */
165: struct dig_query {
166: dig_lookup_t *lookup;
167: isc_boolean_t waiting_connect,
168: pending_free,
169: waiting_senddone,
170: first_pass,
171: first_soa_rcvd,
172: second_rr_rcvd,
173: first_repeat_rcvd,
174: recv_made,
175: warn_id,
176: timedout;
177: uint32_t first_rr_serial;
178: uint32_t second_rr_serial;
179: uint32_t msg_count;
180: uint32_t rr_count;
181: isc_boolean_t ixfr_axfr;
182: char *servname;
183: char *userarg;
184: isc_bufferlist_t sendlist,
185: recvlist,
186: lengthlist;
187: isc_buffer_t recvbuf,
188: lengthbuf,
189: slbuf;
190: char *recvspace,
191: lengthspace[4],
192: slspace[4];
193: isc_socket_t *sock;
194: ISC_LINK(dig_query_t) link;
195: ISC_LINK(dig_query_t) clink;
196: isc_sockaddr_t sockaddr;
197: isc_time_t time_sent;
198: isc_time_t time_recv;
199: uint64_t byte_count;
200: isc_buffer_t sendbuf;
201: isc_timer_t *timer;
202: };
203:
204: struct dig_server {
205: char servername[MXNAME];
206: char userarg[MXNAME];
207: ISC_LINK(dig_server_t) link;
208: };
209:
210: struct dig_searchlist {
211: char origin[MXNAME];
212: ISC_LINK(dig_searchlist_t) link;
213: };
214:
215: typedef ISC_LIST(dig_searchlist_t) dig_searchlistlist_t;
216: typedef ISC_LIST(dig_lookup_t) dig_lookuplist_t;
217:
218: /*
219: * Externals from dighost.c
220: */
221:
222: extern dig_lookuplist_t lookup_list;
223: extern dig_serverlist_t server_list;
1.6 ! florian 224: extern dig_serverlist_t root_hints_server_list;
1.1 florian 225: extern dig_searchlistlist_t search_list;
226: extern unsigned int extrabytes;
227:
228: extern isc_boolean_t check_ra, have_ipv4, have_ipv6, specified_source,
229: usesearch, showsearch, qr;
230: extern in_port_t port;
231: extern unsigned int timeout;
232: extern int sendcount;
233: extern int ndots;
234: extern int lookup_counter;
235: extern int exitcode;
236: extern isc_sockaddr_t bind_address;
237: extern char keynametext[MXNAME];
238: extern char keyfile[MXNAME];
239: extern char keysecret[MXNAME];
240: extern dns_name_t *hmacname;
241: extern unsigned int digestbits;
242: extern dns_tsigkey_t *tsigkey;
243: extern isc_boolean_t validated;
244: extern isc_taskmgr_t *taskmgr;
245: extern isc_task_t *global_task;
246: extern isc_boolean_t free_now;
247: extern isc_boolean_t debugging, debugtiming;
248: extern isc_boolean_t keep_open;
249:
250: extern char *progname;
251: extern int tries;
252: extern int fatalexit;
253:
254: int host_main(int, char **);
255: int nslookup_main(int, char **);
256:
257: /*
258: * Routines in dighost.c.
259: */
260: isc_result_t
261: get_address(char *host, in_port_t port, isc_sockaddr_t *sockaddr);
262:
263: int
264: getaddresses(dig_lookup_t *lookup, const char *host, isc_result_t *resultp);
265:
266: isc_result_t
267: get_reverse(char *reverse, size_t len, char *value, isc_boolean_t ip6_int,
268: isc_boolean_t strict);
269:
270: __dead void
271: fatal(const char *format, ...)
1.5 florian 272: __attribute__((__format__(__printf__, 1, 2)));
1.1 florian 273:
274: void
1.5 florian 275: debug(const char *format, ...) __attribute__((__format__(__printf__, 1, 2)));
1.1 florian 276:
277: void
278: check_result(isc_result_t result, const char *msg);
279:
280: isc_boolean_t
281: setup_lookup(dig_lookup_t *lookup);
282:
283: void
284: destroy_lookup(dig_lookup_t *lookup);
285:
286: void
287: do_lookup(dig_lookup_t *lookup);
288:
289: void
290: start_lookup(void);
291:
292: void
293: onrun_callback(isc_task_t *task, isc_event_t *event);
294:
295: int
296: dhmain(int argc, char **argv);
297:
298: void
299: setup_libs(void);
300:
301: void
302: setup_system(isc_boolean_t ipv4only, isc_boolean_t ipv6only);
303:
304: isc_result_t
305: parse_uint(uint32_t *uip, const char *value, uint32_t max,
306: const char *desc);
307:
308: isc_result_t
309: parse_xint(uint32_t *uip, const char *value, uint32_t max,
310: const char *desc);
311:
312: isc_result_t
313: parse_netprefix(isc_sockaddr_t **sap, const char *value);
314:
315: void
316: parse_hmac(const char *hmacstr);
317:
318: dig_lookup_t *
319: requeue_lookup(dig_lookup_t *lookold, isc_boolean_t servers);
320:
321: dig_lookup_t *
322: make_empty_lookup(void);
323:
324: dig_lookup_t *
325: clone_lookup(dig_lookup_t *lookold, isc_boolean_t servers);
326:
327: dig_server_t *
328: make_server(const char *servname, const char *userarg);
329:
330: void
331: flush_server_list(void);
332:
333: void
334: set_nameserver(char *opt);
335:
336: void
337: clone_server_list(dig_serverlist_t src,
338: dig_serverlist_t *dest);
339:
340: void
341: cancel_all(void);
342:
343: void
344: destroy_libs(void);
345:
346: void
347: set_search_domain(char *domain);
348:
349: char *
350: next_token(char **stringp, const char *delim);
351:
352: /*
353: * Routines to be defined in dig.c, host.c, and nslookup.c. and
354: * then assigned to the appropriate function pointer
355: */
356:
357: extern isc_result_t
358: (*dighost_printmessage)(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers);
359: /*%<
360: * Print the final result of the lookup.
361: */
362:
363: extern void
364: (*dighost_received)(unsigned int bytes, isc_sockaddr_t *from, dig_query_t *query);
365: /*%<
366: * Print a message about where and when the response
367: * was received from, like the final comment in the
368: * output of "dig".
369: */
370:
371: extern void
372: (*dighost_trying)(char *frm, dig_lookup_t *lookup);
373:
374: extern void
375: (*dighost_shutdown)(void);
376:
377: void save_opt(dig_lookup_t *lookup, char *code, char *value);
378:
379: void setup_file_key(void);
380: void setup_text_key(void);
381:
382: /*
383: * Routines exported from dig.c for use by dig for iOS
384: */
385:
386: /*%<
387: * Call once only to set up libraries, parse global
388: * parameters and initial command line query parameters
389: */
390: void
391: dig_setup(int argc, char **argv);
392:
393: /*%<
394: * Call to supply new parameters for the next lookup
395: */
396: void
397: dig_query_setup(isc_boolean_t, isc_boolean_t, int argc, char **argv);
398:
399: /*%<
400: * set the main application event cycle running
401: */
402: void
403: dig_startup(void);
404:
405: /*%<
406: * Cleans up the application
407: */
408: void
409: dig_shutdown(void);
410:
411: #endif