Annotation of src/usr.bin/dig/dig.h, Revision 1.5
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;
224: extern dig_searchlistlist_t search_list;
225: extern unsigned int extrabytes;
226:
227: extern isc_boolean_t check_ra, have_ipv4, have_ipv6, specified_source,
228: usesearch, showsearch, qr;
229: extern in_port_t port;
230: extern unsigned int timeout;
231: extern int sendcount;
232: extern int ndots;
233: extern int lookup_counter;
234: extern int exitcode;
235: extern isc_sockaddr_t bind_address;
236: extern char keynametext[MXNAME];
237: extern char keyfile[MXNAME];
238: extern char keysecret[MXNAME];
239: extern dns_name_t *hmacname;
240: extern unsigned int digestbits;
241: extern dns_tsigkey_t *tsigkey;
242: extern isc_boolean_t validated;
243: extern isc_taskmgr_t *taskmgr;
244: extern isc_task_t *global_task;
245: extern isc_boolean_t free_now;
246: extern isc_boolean_t debugging, debugtiming;
247: extern isc_boolean_t keep_open;
248:
249: extern char *progname;
250: extern int tries;
251: extern int fatalexit;
252:
253: int host_main(int, char **);
254: int nslookup_main(int, char **);
255:
256: /*
257: * Routines in dighost.c.
258: */
259: isc_result_t
260: get_address(char *host, in_port_t port, isc_sockaddr_t *sockaddr);
261:
262: int
263: getaddresses(dig_lookup_t *lookup, const char *host, isc_result_t *resultp);
264:
265: isc_result_t
266: get_reverse(char *reverse, size_t len, char *value, isc_boolean_t ip6_int,
267: isc_boolean_t strict);
268:
269: __dead void
270: fatal(const char *format, ...)
1.5 ! florian 271: __attribute__((__format__(__printf__, 1, 2)));
1.1 florian 272:
273: void
1.5 ! florian 274: debug(const char *format, ...) __attribute__((__format__(__printf__, 1, 2)));
1.1 florian 275:
276: void
277: check_result(isc_result_t result, const char *msg);
278:
279: isc_boolean_t
280: setup_lookup(dig_lookup_t *lookup);
281:
282: void
283: destroy_lookup(dig_lookup_t *lookup);
284:
285: void
286: do_lookup(dig_lookup_t *lookup);
287:
288: void
289: start_lookup(void);
290:
291: void
292: onrun_callback(isc_task_t *task, isc_event_t *event);
293:
294: int
295: dhmain(int argc, char **argv);
296:
297: void
298: setup_libs(void);
299:
300: void
301: setup_system(isc_boolean_t ipv4only, isc_boolean_t ipv6only);
302:
303: isc_result_t
304: parse_uint(uint32_t *uip, const char *value, uint32_t max,
305: const char *desc);
306:
307: isc_result_t
308: parse_xint(uint32_t *uip, const char *value, uint32_t max,
309: const char *desc);
310:
311: isc_result_t
312: parse_netprefix(isc_sockaddr_t **sap, const char *value);
313:
314: void
315: parse_hmac(const char *hmacstr);
316:
317: dig_lookup_t *
318: requeue_lookup(dig_lookup_t *lookold, isc_boolean_t servers);
319:
320: dig_lookup_t *
321: make_empty_lookup(void);
322:
323: dig_lookup_t *
324: clone_lookup(dig_lookup_t *lookold, isc_boolean_t servers);
325:
326: dig_server_t *
327: make_server(const char *servname, const char *userarg);
328:
329: void
330: flush_server_list(void);
331:
332: void
333: set_nameserver(char *opt);
334:
335: void
336: clone_server_list(dig_serverlist_t src,
337: dig_serverlist_t *dest);
338:
339: void
340: cancel_all(void);
341:
342: void
343: destroy_libs(void);
344:
345: void
346: set_search_domain(char *domain);
347:
348: char *
349: next_token(char **stringp, const char *delim);
350:
351: /*
352: * Routines to be defined in dig.c, host.c, and nslookup.c. and
353: * then assigned to the appropriate function pointer
354: */
355:
356: extern isc_result_t
357: (*dighost_printmessage)(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers);
358: /*%<
359: * Print the final result of the lookup.
360: */
361:
362: extern void
363: (*dighost_received)(unsigned int bytes, isc_sockaddr_t *from, dig_query_t *query);
364: /*%<
365: * Print a message about where and when the response
366: * was received from, like the final comment in the
367: * output of "dig".
368: */
369:
370: extern void
371: (*dighost_trying)(char *frm, dig_lookup_t *lookup);
372:
373: extern void
374: (*dighost_shutdown)(void);
375:
376: void save_opt(dig_lookup_t *lookup, char *code, char *value);
377:
378: void setup_file_key(void);
379: void setup_text_key(void);
380:
381: /*
382: * Routines exported from dig.c for use by dig for iOS
383: */
384:
385: /*%<
386: * Call once only to set up libraries, parse global
387: * parameters and initial command line query parameters
388: */
389: void
390: dig_setup(int argc, char **argv);
391:
392: /*%<
393: * Call to supply new parameters for the next lookup
394: */
395: void
396: dig_query_setup(isc_boolean_t, isc_boolean_t, int argc, char **argv);
397:
398: /*%<
399: * set the main application event cycle running
400: */
401: void
402: dig_startup(void);
403:
404: /*%<
405: * Cleans up the application
406: */
407: void
408: dig_shutdown(void);
409:
410: #endif