dig.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004-2009, 2011-2015  Internet Systems Consortium, Inc. ("ISC")
00003  * Copyright (C) 2000-2003  Internet Software Consortium.
00004  *
00005  * Permission to use, copy, modify, and/or distribute this software for any
00006  * purpose with or without fee is hereby granted, provided that the above
00007  * copyright notice and this permission notice appear in all copies.
00008  *
00009  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
00010  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
00011  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
00012  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
00013  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
00014  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
00015  * PERFORMANCE OF THIS SOFTWARE.
00016  */
00017 
00018 #ifndef DIG_H
00019 #define DIG_H
00020 
00021 /*! \file */
00022 
00023 #include <dns/rdatalist.h>
00024 
00025 #include <dst/dst.h>
00026 
00027 #include <isc/boolean.h>
00028 #include <isc/buffer.h>
00029 #include <isc/bufferlist.h>
00030 #include <isc/formatcheck.h>
00031 #include <isc/lang.h>
00032 #include <isc/list.h>
00033 #include <isc/mem.h>
00034 #include <isc/print.h>
00035 #include <isc/sockaddr.h>
00036 #include <isc/socket.h>
00037 
00038 #define MXSERV 20
00039 #define MXNAME (DNS_NAME_MAXTEXT+1)
00040 #define MXRD 32
00041 /*% Buffer Size */
00042 #define BUFSIZE 512
00043 #define COMMSIZE 0xffff
00044 #ifndef RESOLV_CONF
00045 /*% location of resolve.conf */
00046 #define RESOLV_CONF "/etc/resolv.conf"
00047 #endif
00048 /*% output buffer */
00049 #define OUTPUTBUF 32767
00050 /*% Max RR Limit */
00051 #define MAXRRLIMIT 0xffffffff
00052 #define MAXTIMEOUT 0xffff
00053 /*% Max number of tries */
00054 #define MAXTRIES 0xffffffff
00055 /*% Max number of dots */
00056 #define MAXNDOTS 0xffff
00057 /*% Max number of ports */
00058 #define MAXPORT 0xffff
00059 /*% Max serial number */
00060 #define MAXSERIAL 0xffffffff
00061 
00062 /*% Default TCP Timeout */
00063 #define TCP_TIMEOUT 10
00064 /*% Default UDP Timeout */
00065 #define UDP_TIMEOUT 5
00066 
00067 #define SERVER_TIMEOUT 1
00068 
00069 #define LOOKUP_LIMIT 64
00070 /*%
00071  * Lookup_limit is just a limiter, keeping too many lookups from being
00072  * created.  It's job is mainly to prevent the program from running away
00073  * in a tight loop of constant lookups.  It's value is arbitrary.
00074  */
00075 
00076 /*
00077  * Defaults for the sigchase suboptions.  Consolidated here because
00078  * these control the layout of dig_lookup_t (among other things).
00079  */
00080 #ifdef DIG_SIGCHASE
00081 #ifndef DIG_SIGCHASE_BU
00082 #define DIG_SIGCHASE_BU 1
00083 #endif
00084 #ifndef DIG_SIGCHASE_TD
00085 #define DIG_SIGCHASE_TD 1
00086 #endif
00087 #endif
00088 
00089 ISC_LANG_BEGINDECLS
00090 
00091 typedef struct dig_lookup dig_lookup_t;
00092 typedef struct dig_query dig_query_t;
00093 typedef struct dig_server dig_server_t;
00094 #ifdef DIG_SIGCHASE
00095 typedef struct dig_message dig_message_t;
00096 #endif
00097 typedef ISC_LIST(dig_server_t) dig_serverlist_t;
00098 typedef struct dig_searchlist dig_searchlist_t;
00099 
00100 /*% The dig_lookup structure */
00101 struct dig_lookup {
00102         isc_boolean_t
00103                 pending, /*%< Pending a successful answer */
00104                 waiting_connect,
00105                 doing_xfr,
00106                 ns_search_only, /*%< dig +nssearch, host -C */
00107                 identify, /*%< Append an "on server <foo>" message */
00108                 identify_previous_line, /*% Prepend a "Nameserver <foo>:"
00109                                            message, with newline and tab */
00110                 ignore,
00111                 recurse,
00112                 aaonly,
00113                 adflag,
00114                 cdflag,
00115                 zflag,
00116                 trace, /*% dig +trace */
00117                 trace_root, /*% initial query for either +trace or +nssearch */
00118                 tcp_mode,
00119                 tcp_mode_set,
00120                 ip6_int,
00121                 comments,
00122                 stats,
00123                 section_question,
00124                 section_answer,
00125                 section_authority,
00126                 section_additional,
00127                 servfail_stops,
00128                 new_search,
00129                 need_search,
00130                 done_as_is,
00131                 besteffort,
00132                 dnssec,
00133                 expire,
00134 #ifdef ISC_PLATFORM_USESIT
00135                 sit,
00136 #endif
00137                 nsid,   /*% Name Server ID (RFC 5001) */
00138                 header_only,
00139                 ednsneg;
00140 #ifdef DIG_SIGCHASE
00141 isc_boolean_t   sigchase;
00142 #if DIG_SIGCHASE_TD
00143         isc_boolean_t do_topdown,
00144                 trace_root_sigchase,
00145                 rdtype_sigchaseset,
00146                 rdclass_sigchaseset;
00147         /* Name we are going to validate RRset */
00148         char textnamesigchase[MXNAME];
00149 #endif
00150 #endif
00151 
00152         char textname[MXNAME]; /*% Name we're going to be looking up */
00153         char cmdline[MXNAME];
00154         dns_rdatatype_t rdtype;
00155         dns_rdatatype_t qrdtype;
00156 #if DIG_SIGCHASE_TD
00157         dns_rdatatype_t rdtype_sigchase;
00158         dns_rdatatype_t qrdtype_sigchase;
00159         dns_rdataclass_t rdclass_sigchase;
00160 #endif
00161         dns_rdataclass_t rdclass;
00162         isc_boolean_t rdtypeset;
00163         isc_boolean_t rdclassset;
00164         char namespace[BUFSIZE];
00165         char onamespace[BUFSIZE];
00166         isc_buffer_t namebuf;
00167         isc_buffer_t onamebuf;
00168         isc_buffer_t renderbuf;
00169         char *sendspace;
00170         dns_name_t *name;
00171         isc_timer_t *timer;
00172         isc_interval_t interval;
00173         dns_message_t *sendmsg;
00174         dns_name_t *oname;
00175         ISC_LINK(dig_lookup_t) link;
00176         ISC_LIST(dig_query_t) q;
00177         ISC_LIST(dig_query_t) connecting;
00178         dig_query_t *current_query;
00179         dig_serverlist_t my_server_list;
00180         dig_searchlist_t *origin;
00181         dig_query_t *xfr_q;
00182         isc_uint32_t retries;
00183         int nsfound;
00184         isc_uint16_t udpsize;
00185         isc_int16_t edns;
00186         isc_uint32_t ixfr_serial;
00187         isc_buffer_t rdatabuf;
00188         char rdatastore[MXNAME];
00189         dst_context_t *tsigctx;
00190         isc_buffer_t *querysig;
00191         isc_uint32_t msgcounter;
00192         dns_fixedname_t fdomain;
00193         isc_sockaddr_t *ecs_addr;
00194 #ifdef ISC_PLATFORM_USESIT
00195         char *sitvalue;
00196 #endif
00197         dns_ednsopt_t *ednsopts;
00198         unsigned int ednsoptscnt;
00199         isc_dscp_t dscp;
00200         unsigned int ednsflags;
00201 };
00202 
00203 /*% The dig_query structure */
00204 struct dig_query {
00205         dig_lookup_t *lookup;
00206         isc_boolean_t waiting_connect,
00207                 pending_free,
00208                 waiting_senddone,
00209                 first_pass,
00210                 first_soa_rcvd,
00211                 second_rr_rcvd,
00212                 first_repeat_rcvd,
00213                 recv_made,
00214                 warn_id;
00215         isc_uint32_t first_rr_serial;
00216         isc_uint32_t second_rr_serial;
00217         isc_uint32_t msg_count;
00218         isc_uint32_t rr_count;
00219         isc_boolean_t ixfr_axfr;
00220         char *servname;
00221         char *userarg;
00222         isc_bufferlist_t sendlist,
00223                 recvlist,
00224                 lengthlist;
00225         isc_buffer_t recvbuf,
00226                 lengthbuf,
00227                 slbuf;
00228         char *recvspace,
00229                 lengthspace[4],
00230                 slspace[4];
00231         isc_socket_t *sock;
00232         ISC_LINK(dig_query_t) link;
00233         ISC_LINK(dig_query_t) clink;
00234         isc_sockaddr_t sockaddr;
00235         isc_time_t time_sent;
00236         isc_time_t time_recv;
00237         isc_uint64_t byte_count;
00238         isc_buffer_t sendbuf;
00239 };
00240 
00241 struct dig_server {
00242         char servername[MXNAME];
00243         char userarg[MXNAME];
00244         ISC_LINK(dig_server_t) link;
00245 };
00246 
00247 struct dig_searchlist {
00248         char origin[MXNAME];
00249         ISC_LINK(dig_searchlist_t) link;
00250 };
00251 #ifdef DIG_SIGCHASE
00252 struct dig_message {
00253                 dns_message_t *msg;
00254                 ISC_LINK(dig_message_t) link;
00255 };
00256 #endif
00257 
00258 typedef ISC_LIST(dig_searchlist_t) dig_searchlistlist_t;
00259 typedef ISC_LIST(dig_lookup_t) dig_lookuplist_t;
00260 
00261 /*
00262  * Externals from dighost.c
00263  */
00264 
00265 extern dig_lookuplist_t lookup_list;
00266 extern dig_serverlist_t server_list;
00267 extern dig_searchlistlist_t search_list;
00268 extern unsigned int extrabytes;
00269 
00270 extern isc_boolean_t check_ra, have_ipv4, have_ipv6, specified_source,
00271         usesearch, showsearch, qr;
00272 extern in_port_t port;
00273 extern unsigned int timeout;
00274 extern isc_mem_t *mctx;
00275 extern int sendcount;
00276 extern int ndots;
00277 extern int lookup_counter;
00278 extern int exitcode;
00279 extern isc_sockaddr_t bind_address;
00280 extern char keynametext[MXNAME];
00281 extern char keyfile[MXNAME];
00282 extern char keysecret[MXNAME];
00283 extern dns_name_t *hmacname;
00284 extern unsigned int digestbits;
00285 #ifdef DIG_SIGCHASE
00286 extern char trustedkey[MXNAME];
00287 #endif
00288 extern dns_tsigkey_t *key;
00289 extern isc_boolean_t validated;
00290 extern isc_taskmgr_t *taskmgr;
00291 extern isc_task_t *global_task;
00292 extern isc_boolean_t free_now;
00293 extern isc_boolean_t debugging, debugtiming, memdebugging;
00294 extern isc_boolean_t keep_open;
00295 
00296 extern char *progname;
00297 extern int tries;
00298 extern int fatalexit;
00299 extern isc_boolean_t verbose;
00300 #ifdef WITH_IDN
00301 extern int idnoptions;
00302 #endif
00303 
00304 /*
00305  * Routines in dighost.c.
00306  */
00307 isc_result_t
00308 get_address(char *host, in_port_t myport, isc_sockaddr_t *sockaddr);
00309 
00310 int
00311 getaddresses(dig_lookup_t *lookup, const char *host, isc_result_t *resultp);
00312 
00313 isc_result_t
00314 get_reverse(char *reverse, size_t len, char *value, isc_boolean_t ip6_int,
00315             isc_boolean_t strict);
00316 
00317 ISC_PLATFORM_NORETURN_PRE void
00318 fatal(const char *format, ...)
00319 ISC_FORMAT_PRINTF(1, 2) ISC_PLATFORM_NORETURN_POST;
00320 
00321 void
00322 debug(const char *format, ...) ISC_FORMAT_PRINTF(1, 2);
00323 
00324 void
00325 check_result(isc_result_t result, const char *msg);
00326 
00327 isc_boolean_t
00328 setup_lookup(dig_lookup_t *lookup);
00329 
00330 void
00331 destroy_lookup(dig_lookup_t *lookup);
00332 
00333 void
00334 do_lookup(dig_lookup_t *lookup);
00335 
00336 void
00337 start_lookup(void);
00338 
00339 void
00340 onrun_callback(isc_task_t *task, isc_event_t *event);
00341 
00342 int
00343 dhmain(int argc, char **argv);
00344 
00345 void
00346 setup_libs(void);
00347 
00348 void
00349 setup_system(void);
00350 
00351 isc_result_t
00352 parse_uint(isc_uint32_t *uip, const char *value, isc_uint32_t max,
00353            const char *desc);
00354 
00355 isc_result_t
00356 parse_xint(isc_uint32_t *uip, const char *value, isc_uint32_t max,
00357            const char *desc);
00358 
00359 isc_result_t
00360 parse_netprefix(isc_sockaddr_t **sap, const char *value);
00361 
00362 void
00363 parse_hmac(const char *hmacstr);
00364 
00365 dig_lookup_t *
00366 requeue_lookup(dig_lookup_t *lookold, isc_boolean_t servers);
00367 
00368 dig_lookup_t *
00369 make_empty_lookup(void);
00370 
00371 dig_lookup_t *
00372 clone_lookup(dig_lookup_t *lookold, isc_boolean_t servers);
00373 
00374 dig_server_t *
00375 make_server(const char *servname, const char *userarg);
00376 
00377 void
00378 flush_server_list(void);
00379 
00380 void
00381 set_nameserver(char *opt);
00382 
00383 void
00384 clone_server_list(dig_serverlist_t src,
00385                   dig_serverlist_t *dest);
00386 
00387 void
00388 cancel_all(void);
00389 
00390 void
00391 destroy_libs(void);
00392 
00393 void
00394 set_search_domain(char *domain);
00395 
00396 #ifdef DIG_SIGCHASE
00397 void
00398 clean_trustedkey(void);
00399 #endif
00400 
00401 /*
00402  * Routines to be defined in dig.c, host.c, and nslookup.c.
00403  */
00404 #ifdef DIG_SIGCHASE
00405 isc_result_t
00406 printrdataset(dns_name_t *owner_name, dns_rdataset_t *rdataset,
00407               isc_buffer_t *target);
00408 #endif
00409 
00410 isc_result_t
00411 printmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers);
00412 /*%<
00413  * Print the final result of the lookup.
00414  */
00415 
00416 void
00417 received(int bytes, isc_sockaddr_t *from, dig_query_t *query);
00418 /*%<
00419  * Print a message about where and when the response
00420  * was received from, like the final comment in the
00421  * output of "dig".
00422  */
00423 
00424 void
00425 trying(char *frm, dig_lookup_t *lookup);
00426 
00427 void
00428 dighost_shutdown(void);
00429 
00430 char *
00431 next_token(char **stringp, const char *delim);
00432 
00433 #ifdef DIG_SIGCHASE
00434 /* Chasing functions */
00435 dns_rdataset_t *
00436 chase_scanname(dns_name_t *name, dns_rdatatype_t type, dns_rdatatype_t covers);
00437 void
00438 chase_sig(dns_message_t *msg);
00439 #endif
00440 
00441 void save_opt(dig_lookup_t *lookup, char *code, char *value);
00442 
00443 void setup_file_key(void);
00444 void setup_text_key(void);
00445 
00446 ISC_LANG_ENDDECLS
00447 
00448 #endif

Generated on Tue Apr 28 17:40:53 2015 by Doxygen 1.5.4 for BIND9 Internals 9.11.0pre-alpha