/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. /* $Id: dig.h,v 1.111.306.3 2011/12/07 17:23:55 each Exp $ */
  18. #ifndef DIG_H
  19. #define DIG_H
  20. /*! \file */
  21. #include <dns/rdatalist.h>
  22. #include <dst/dst.h>
  23. #include <isc/boolean.h>
  24. #include <isc/buffer.h>
  25. #include <isc/bufferlist.h>
  26. #include <isc/formatcheck.h>
  27. #include <isc/lang.h>
  28. #include <isc/list.h>
  29. #include <isc/mem.h>
  30. #include <isc/print.h>
  31. #include <isc/sockaddr.h>
  32. #include <isc/socket.h>
  33. #define MXSERV 20
  34. #define MXNAME (DNS_NAME_MAXTEXT+1)
  35. #define MXRD 32
  36. /*% Buffer Size */
  37. #define BUFSIZE 512
  38. #define COMMSIZE 0xffff
  39. #ifndef RESOLV_CONF
  40. /*% location of resolve.conf */
  41. #define RESOLV_CONF "/etc/resolv.conf"
  42. #endif
  43. /*% output buffer */
  44. #define OUTPUTBUF 32767
  45. /*% Max RR Limit */
  46. #define MAXRRLIMIT 0xffffffff
  47. #define MAXTIMEOUT 0xffff
  48. /*% Max number of tries */
  49. #define MAXTRIES 0xffffffff
  50. /*% Max number of dots */
  51. #define MAXNDOTS 0xffff
  52. /*% Max number of ports */
  53. #define MAXPORT 0xffff
  54. /*% Max serial number */
  55. #define MAXSERIAL 0xffffffff
  56. /*% Default TCP Timeout */
  57. #define TCP_TIMEOUT 10
  58. /*% Default UDP Timeout */
  59. #define UDP_TIMEOUT 5
  60. #define SERVER_TIMEOUT 1
  61. #define LOOKUP_LIMIT 64
  62. /*%
  63. * Lookup_limit is just a limiter, keeping too many lookups from being
  64. * created. It's job is mainly to prevent the program from running away
  65. * in a tight loop of constant lookups. It's value is arbitrary.
  66. */
  67. /*
  68. * Defaults for the sigchase suboptions. Consolidated here because
  69. * these control the layout of dig_lookup_t (among other things).
  70. */
  71. #ifdef DIG_SIGCHASE
  72. #ifndef DIG_SIGCHASE_BU
  73. #define DIG_SIGCHASE_BU 1
  74. #endif
  75. #ifndef DIG_SIGCHASE_TD
  76. #define DIG_SIGCHASE_TD 1
  77. #endif
  78. #endif
  79. ISC_LANG_BEGINDECLS
  80. typedef struct dig_lookup dig_lookup_t;
  81. typedef struct dig_query dig_query_t;
  82. typedef struct dig_server dig_server_t;
  83. #ifdef DIG_SIGCHASE
  84. typedef struct dig_message dig_message_t;
  85. #endif
  86. typedef ISC_LIST(dig_server_t) dig_serverlist_t;
  87. typedef struct dig_searchlist dig_searchlist_t;
  88. /*% The dig_lookup structure */
  89. struct dig_lookup {
  90. isc_boolean_t
  91. pending, /*%< Pending a successful answer */
  92. waiting_connect,
  93. doing_xfr,
  94. ns_search_only, /*%< dig +nssearch, host -C */
  95. identify, /*%< Append an "on server <foo>" message */
  96. identify_previous_line, /*% Prepend a "Nameserver <foo>:"
  97. message, with newline and tab */
  98. ignore,
  99. recurse,
  100. aaonly,
  101. adflag,
  102. cdflag,
  103. trace, /*% dig +trace */
  104. trace_root, /*% initial query for either +trace or +nssearch */
  105. tcp_mode,
  106. ip6_int,
  107. comments,
  108. stats,
  109. section_question,
  110. section_answer,
  111. section_authority,
  112. section_additional,
  113. servfail_stops,
  114. new_search,
  115. need_search,
  116. done_as_is,
  117. besteffort,
  118. dnssec,
  119. nsid; /*% Name Server ID (RFC 5001) */
  120. #ifdef DIG_SIGCHASE
  121. isc_boolean_t sigchase;
  122. #if DIG_SIGCHASE_TD
  123. isc_boolean_t do_topdown,
  124. trace_root_sigchase,
  125. rdtype_sigchaseset,
  126. rdclass_sigchaseset;
  127. /* Name we are going to validate RRset */
  128. char textnamesigchase[MXNAME];
  129. #endif
  130. #endif
  131. char textname[MXNAME]; /*% Name we're going to be looking up */
  132. char cmdline[MXNAME];
  133. dns_rdatatype_t rdtype;
  134. dns_rdatatype_t qrdtype;
  135. #if DIG_SIGCHASE_TD
  136. dns_rdatatype_t rdtype_sigchase;
  137. dns_rdatatype_t qrdtype_sigchase;
  138. dns_rdataclass_t rdclass_sigchase;
  139. #endif
  140. dns_rdataclass_t rdclass;
  141. isc_boolean_t rdtypeset;
  142. isc_boolean_t rdclassset;
  143. char namespace[BUFSIZE];
  144. char onamespace[BUFSIZE];
  145. isc_buffer_t namebuf;
  146. isc_buffer_t onamebuf;
  147. isc_buffer_t renderbuf;
  148. char *sendspace;
  149. dns_name_t *name;
  150. isc_timer_t *timer;
  151. isc_interval_t interval;
  152. dns_message_t *sendmsg;
  153. dns_name_t *oname;
  154. ISC_LINK(dig_lookup_t) link;
  155. ISC_LIST(dig_query_t) q;
  156. dig_query_t *current_query;
  157. dig_serverlist_t my_server_list;
  158. dig_searchlist_t *origin;
  159. dig_query_t *xfr_q;
  160. isc_uint32_t retries;
  161. int nsfound;
  162. isc_uint16_t udpsize;
  163. isc_int16_t edns;
  164. isc_uint32_t ixfr_serial;
  165. isc_buffer_t rdatabuf;
  166. char rdatastore[MXNAME];
  167. dst_context_t *tsigctx;
  168. isc_buffer_t *querysig;
  169. isc_uint32_t msgcounter;
  170. dns_fixedname_t fdomain;
  171. };
  172. /*% The dig_query structure */
  173. struct dig_query {
  174. dig_lookup_t *lookup;
  175. isc_boolean_t waiting_connect,
  176. pending_free,
  177. waiting_senddone,
  178. first_pass,
  179. first_soa_rcvd,
  180. second_rr_rcvd,
  181. first_repeat_rcvd,
  182. recv_made,
  183. warn_id;
  184. isc_uint32_t first_rr_serial;
  185. isc_uint32_t second_rr_serial;
  186. isc_uint32_t msg_count;
  187. isc_uint32_t rr_count;
  188. char *servname;
  189. char *userarg;
  190. isc_bufferlist_t sendlist,
  191. recvlist,
  192. lengthlist;
  193. isc_buffer_t recvbuf,
  194. lengthbuf,
  195. slbuf;
  196. char *recvspace,
  197. lengthspace[4],
  198. slspace[4];
  199. isc_socket_t *sock;
  200. ISC_LINK(dig_query_t) link;
  201. isc_sockaddr_t sockaddr;
  202. isc_time_t time_sent;
  203. isc_uint64_t byte_count;
  204. isc_buffer_t sendbuf;
  205. };
  206. struct dig_server {
  207. char servername[MXNAME];
  208. char userarg[MXNAME];
  209. ISC_LINK(dig_server_t) link;
  210. };
  211. struct dig_searchlist {
  212. char origin[MXNAME];
  213. ISC_LINK(dig_searchlist_t) link;
  214. };
  215. #ifdef DIG_SIGCHASE
  216. struct dig_message {
  217. dns_message_t *msg;
  218. ISC_LINK(dig_message_t) link;
  219. };
  220. #endif
  221. typedef ISC_LIST(dig_searchlist_t) dig_searchlistlist_t;
  222. typedef ISC_LIST(dig_lookup_t) dig_lookuplist_t;
  223. /*
  224. * Externals from dighost.c
  225. */
  226. extern dig_lookuplist_t lookup_list;
  227. extern dig_serverlist_t server_list;
  228. extern dig_searchlistlist_t search_list;
  229. extern unsigned int extrabytes;
  230. extern isc_boolean_t check_ra, have_ipv4, have_ipv6, specified_source,
  231. usesearch, showsearch, qr;
  232. extern in_port_t port;
  233. extern unsigned int timeout;
  234. extern isc_mem_t *mctx;
  235. extern dns_messageid_t id;
  236. extern int sendcount;
  237. extern int ndots;
  238. extern int lookup_counter;
  239. extern int exitcode;
  240. extern isc_sockaddr_t bind_address;
  241. extern char keynametext[MXNAME];
  242. extern char keyfile[MXNAME];
  243. extern char keysecret[MXNAME];
  244. extern dns_name_t *hmacname;
  245. extern unsigned int digestbits;
  246. #ifdef DIG_SIGCHASE
  247. extern char trustedkey[MXNAME];
  248. #endif
  249. extern dns_tsigkey_t *key;
  250. extern isc_boolean_t validated;
  251. extern isc_taskmgr_t *taskmgr;
  252. extern isc_task_t *global_task;
  253. extern isc_boolean_t free_now;
  254. extern isc_boolean_t debugging, memdebugging;
  255. extern char *progname;
  256. extern int tries;
  257. extern int fatalexit;
  258. #ifdef WITH_IDN
  259. extern int idnoptions;
  260. #endif
  261. /*
  262. * Routines in dighost.c.
  263. */
  264. isc_result_t
  265. get_address(char *host, in_port_t port, isc_sockaddr_t *sockaddr);
  266. int
  267. getaddresses(dig_lookup_t *lookup, const char *host, isc_result_t *resultp);
  268. isc_result_t
  269. get_reverse(char *reverse, size_t len, char *value, isc_boolean_t ip6_int,
  270. isc_boolean_t strict);
  271. ISC_PLATFORM_NORETURN_PRE void
  272. fatal(const char *format, ...)
  273. ISC_FORMAT_PRINTF(1, 2) ISC_PLATFORM_NORETURN_POST;
  274. void
  275. debug(const char *format, ...) ISC_FORMAT_PRINTF(1, 2);
  276. void
  277. check_result(isc_result_t result, const char *msg);
  278. void
  279. setup_lookup(dig_lookup_t *lookup);
  280. void
  281. destroy_lookup(dig_lookup_t *lookup);
  282. void
  283. do_lookup(dig_lookup_t *lookup);
  284. void
  285. start_lookup(void);
  286. void
  287. onrun_callback(isc_task_t *task, isc_event_t *event);
  288. int
  289. dhmain(int argc, char **argv);
  290. void
  291. setup_libs(void);
  292. void
  293. setup_system(void);
  294. isc_result_t
  295. parse_uint(isc_uint32_t *uip, const char *value, isc_uint32_t max,
  296. const char *desc);
  297. void
  298. parse_hmac(const char *hmacstr);
  299. dig_lookup_t *
  300. requeue_lookup(dig_lookup_t *lookold, isc_boolean_t servers);
  301. dig_lookup_t *
  302. make_empty_lookup(void);
  303. dig_lookup_t *
  304. clone_lookup(dig_lookup_t *lookold, isc_boolean_t servers);
  305. dig_server_t *
  306. make_server(const char *servname, const char *userarg);
  307. void
  308. flush_server_list(void);
  309. void
  310. set_nameserver(char *opt);
  311. void
  312. clone_server_list(dig_serverlist_t src,
  313. dig_serverlist_t *dest);
  314. void
  315. cancel_all(void);
  316. void
  317. destroy_libs(void);
  318. void
  319. set_search_domain(char *domain);
  320. #ifdef DIG_SIGCHASE
  321. void
  322. clean_trustedkey(void);
  323. #endif
  324. /*
  325. * Routines to be defined in dig.c, host.c, and nslookup.c.
  326. */
  327. #ifdef DIG_SIGCHASE
  328. isc_result_t
  329. printrdataset(dns_name_t *owner_name, dns_rdataset_t *rdataset,
  330. isc_buffer_t *target);
  331. #endif
  332. isc_result_t
  333. printmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers);
  334. /*%<
  335. * Print the final result of the lookup.
  336. */
  337. void
  338. received(int bytes, isc_sockaddr_t *from, dig_query_t *query);
  339. /*%<
  340. * Print a message about where and when the response
  341. * was received from, like the final comment in the
  342. * output of "dig".
  343. */
  344. void
  345. trying(char *frm, dig_lookup_t *lookup);
  346. void
  347. dighost_shutdown(void);
  348. char *
  349. next_token(char **stringp, const char *delim);
  350. #ifdef DIG_SIGCHASE
  351. /* Chasing functions */
  352. dns_rdataset_t *
  353. chase_scanname(dns_name_t *name, dns_rdatatype_t type, dns_rdatatype_t covers);
  354. void
  355. chase_sig(dns_message_t *msg);
  356. #endif
  357. ISC_LANG_ENDDECLS
  358. #endif