[BACK]Return to dig.h CVS log [TXT][DIR] Up to [local] / src / usr.bin / dig

Annotation of src/usr.bin/dig/dig.h, Revision 1.3

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>
                     26: #include <isc/formatcheck.h>
                     27: #include <isc/lang.h>
                     28: #include <isc/list.h>
1.3     ! jsg        29: #include <isc/time.h>
1.1       florian    30: #include <isc/sockaddr.h>
                     31: #include <isc/socket.h>
                     32:
                     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:
                     57: /*% Default TCP Timeout */
                     58: #define TCP_TIMEOUT 10
                     59: /*% Default UDP Timeout */
                     60: #define UDP_TIMEOUT 5
                     61:
                     62: #define SERVER_TIMEOUT 1
                     63:
                     64: #define LOOKUP_LIMIT 64
                     65: /*%
                     66:  * Lookup_limit is just a limiter, keeping too many lookups from being
                     67:  * created.  It's job is mainly to prevent the program from running away
                     68:  * in a tight loop of constant lookups.  It's value is arbitrary.
                     69:  */
                     70:
                     71: /*
                     72:  * Defaults for the sigchase suboptions.  Consolidated here because
                     73:  * these control the layout of dig_lookup_t (among other things).
                     74:  */
                     75:
                     76: ISC_LANG_BEGINDECLS
                     77:
                     78: typedef struct dig_lookup dig_lookup_t;
                     79: typedef struct dig_query dig_query_t;
                     80: typedef struct dig_server dig_server_t;
                     81: typedef ISC_LIST(dig_server_t) dig_serverlist_t;
                     82: typedef struct dig_searchlist dig_searchlist_t;
                     83:
                     84: /*% The dig_lookup structure */
                     85: struct dig_lookup {
                     86:        isc_boolean_t
                     87:                pending, /*%< Pending a successful answer */
                     88:                waiting_connect,
                     89:                doing_xfr,
                     90:                ns_search_only, /*%< dig +nssearch, host -C */
                     91:                identify, /*%< Append an "on server <foo>" message */
                     92:                identify_previous_line, /*% Prepend a "Nameserver <foo>:"
                     93:                                           message, with newline and tab */
                     94:                ignore,
                     95:                recurse,
                     96:                aaonly,
                     97:                adflag,
                     98:                cdflag,
                     99:                trace, /*% dig +trace */
                    100:                trace_root, /*% initial query for either +trace or +nssearch */
                    101:                tcp_mode,
                    102:                tcp_mode_set,
                    103:                ip6_int,
                    104:                comments,
                    105:                stats,
                    106:                section_question,
                    107:                section_answer,
                    108:                section_authority,
                    109:                section_additional,
                    110:                servfail_stops,
                    111:                new_search,
                    112:                need_search,
                    113:                done_as_is,
                    114:                besteffort,
                    115:                dnssec,
                    116:                expire,
                    117:                sit,
                    118:                nsid,   /*% Name Server ID (RFC 5001) */
                    119:                ednsneg,
                    120:                mapped,
                    121:                idnout;
                    122:
                    123:        char textname[MXNAME]; /*% Name we're going to be looking up */
                    124:        char cmdline[MXNAME];
                    125:        dns_rdatatype_t rdtype;
                    126:        dns_rdatatype_t qrdtype;
                    127:        dns_rdataclass_t rdclass;
                    128:        isc_boolean_t rdtypeset;
                    129:        isc_boolean_t rdclassset;
                    130:        char name_space[BUFSIZE];
                    131:        char oname_space[BUFSIZE];
                    132:        isc_buffer_t namebuf;
                    133:        isc_buffer_t onamebuf;
                    134:        isc_buffer_t renderbuf;
                    135:        char *sendspace;
                    136:        dns_name_t *name;
                    137:        interval_t interval;
                    138:        dns_message_t *sendmsg;
                    139:        dns_name_t *oname;
                    140:        ISC_LINK(dig_lookup_t) link;
                    141:        ISC_LIST(dig_query_t) q;
                    142:        ISC_LIST(dig_query_t) connecting;
                    143:        dig_query_t *current_query;
                    144:        dig_serverlist_t my_server_list;
                    145:        dig_searchlist_t *origin;
                    146:        dig_query_t *xfr_q;
                    147:        uint32_t retries;
                    148:        int nsfound;
                    149:        uint16_t udpsize;
                    150:        int16_t edns;
                    151:        uint32_t ixfr_serial;
                    152:        isc_buffer_t rdatabuf;
                    153:        char rdatastore[MXNAME];
                    154:        dst_context_t *tsigctx;
                    155:        isc_buffer_t *querysig;
                    156:        uint32_t msgcounter;
                    157:        dns_fixedname_t fdomain;
                    158:        isc_sockaddr_t *ecs_addr;
                    159:        char *sitvalue;
                    160:        dns_ednsopt_t *ednsopts;
                    161:        unsigned int ednsoptscnt;
                    162:        unsigned int ednsflags;
                    163:        dns_opcode_t opcode;
                    164:        unsigned int eoferr;
                    165: };
                    166:
                    167: /*% The dig_query structure */
                    168: struct dig_query {
                    169:        dig_lookup_t *lookup;
                    170:        isc_boolean_t waiting_connect,
                    171:                pending_free,
                    172:                waiting_senddone,
                    173:                first_pass,
                    174:                first_soa_rcvd,
                    175:                second_rr_rcvd,
                    176:                first_repeat_rcvd,
                    177:                recv_made,
                    178:                warn_id,
                    179:                timedout;
                    180:        uint32_t first_rr_serial;
                    181:        uint32_t second_rr_serial;
                    182:        uint32_t msg_count;
                    183:        uint32_t rr_count;
                    184:        isc_boolean_t ixfr_axfr;
                    185:        char *servname;
                    186:        char *userarg;
                    187:        isc_bufferlist_t sendlist,
                    188:                recvlist,
                    189:                lengthlist;
                    190:        isc_buffer_t recvbuf,
                    191:                lengthbuf,
                    192:                slbuf;
                    193:        char *recvspace,
                    194:                lengthspace[4],
                    195:                slspace[4];
                    196:        isc_socket_t *sock;
                    197:        ISC_LINK(dig_query_t) link;
                    198:        ISC_LINK(dig_query_t) clink;
                    199:        isc_sockaddr_t sockaddr;
                    200:        isc_time_t time_sent;
                    201:        isc_time_t time_recv;
                    202:        uint64_t byte_count;
                    203:        isc_buffer_t sendbuf;
                    204:        isc_timer_t *timer;
                    205: };
                    206:
                    207: struct dig_server {
                    208:        char servername[MXNAME];
                    209:        char userarg[MXNAME];
                    210:        ISC_LINK(dig_server_t) link;
                    211: };
                    212:
                    213: struct dig_searchlist {
                    214:        char origin[MXNAME];
                    215:        ISC_LINK(dig_searchlist_t) link;
                    216: };
                    217:
                    218: typedef ISC_LIST(dig_searchlist_t) dig_searchlistlist_t;
                    219: typedef ISC_LIST(dig_lookup_t) dig_lookuplist_t;
                    220:
                    221: /*
                    222:  * Externals from dighost.c
                    223:  */
                    224:
                    225: extern dig_lookuplist_t lookup_list;
                    226: extern dig_serverlist_t server_list;
                    227: extern dig_searchlistlist_t search_list;
                    228: extern unsigned int extrabytes;
                    229:
                    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 int sendcount;
                    235: extern int ndots;
                    236: extern int lookup_counter;
                    237: extern int exitcode;
                    238: extern isc_sockaddr_t bind_address;
                    239: extern char keynametext[MXNAME];
                    240: extern char keyfile[MXNAME];
                    241: extern char keysecret[MXNAME];
                    242: extern dns_name_t *hmacname;
                    243: extern unsigned int digestbits;
                    244: extern dns_tsigkey_t *tsigkey;
                    245: extern isc_boolean_t validated;
                    246: extern isc_taskmgr_t *taskmgr;
                    247: extern isc_task_t *global_task;
                    248: extern isc_boolean_t free_now;
                    249: extern isc_boolean_t debugging, debugtiming;
                    250: extern isc_boolean_t keep_open;
                    251:
                    252: extern char *progname;
                    253: extern int tries;
                    254: extern int fatalexit;
                    255:
                    256: int host_main(int, char **);
                    257: int nslookup_main(int, char **);
                    258:
                    259: /*
                    260:  * Routines in dighost.c.
                    261:  */
                    262: isc_result_t
                    263: get_address(char *host, in_port_t port, isc_sockaddr_t *sockaddr);
                    264:
                    265: int
                    266: getaddresses(dig_lookup_t *lookup, const char *host, isc_result_t *resultp);
                    267:
                    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:
                    272: __dead void
                    273: fatal(const char *format, ...)
                    274: ISC_FORMAT_PRINTF(1, 2);
                    275:
                    276: void
                    277: debug(const char *format, ...) ISC_FORMAT_PRINTF(1, 2);
                    278:
                    279: void
                    280: check_result(isc_result_t result, const char *msg);
                    281:
                    282: isc_boolean_t
                    283: setup_lookup(dig_lookup_t *lookup);
                    284:
                    285: void
                    286: destroy_lookup(dig_lookup_t *lookup);
                    287:
                    288: void
                    289: do_lookup(dig_lookup_t *lookup);
                    290:
                    291: void
                    292: start_lookup(void);
                    293:
                    294: void
                    295: onrun_callback(isc_task_t *task, isc_event_t *event);
                    296:
                    297: int
                    298: dhmain(int argc, char **argv);
                    299:
                    300: void
                    301: setup_libs(void);
                    302:
                    303: void
                    304: setup_system(isc_boolean_t ipv4only, isc_boolean_t ipv6only);
                    305:
                    306: isc_result_t
                    307: parse_uint(uint32_t *uip, const char *value, uint32_t max,
                    308:           const char *desc);
                    309:
                    310: isc_result_t
                    311: parse_xint(uint32_t *uip, const char *value, uint32_t max,
                    312:           const char *desc);
                    313:
                    314: isc_result_t
                    315: parse_netprefix(isc_sockaddr_t **sap, const char *value);
                    316:
                    317: void
                    318: parse_hmac(const char *hmacstr);
                    319:
                    320: dig_lookup_t *
                    321: requeue_lookup(dig_lookup_t *lookold, isc_boolean_t servers);
                    322:
                    323: dig_lookup_t *
                    324: make_empty_lookup(void);
                    325:
                    326: dig_lookup_t *
                    327: clone_lookup(dig_lookup_t *lookold, isc_boolean_t servers);
                    328:
                    329: dig_server_t *
                    330: make_server(const char *servname, const char *userarg);
                    331:
                    332: void
                    333: flush_server_list(void);
                    334:
                    335: void
                    336: set_nameserver(char *opt);
                    337:
                    338: void
                    339: clone_server_list(dig_serverlist_t src,
                    340:                  dig_serverlist_t *dest);
                    341:
                    342: void
                    343: cancel_all(void);
                    344:
                    345: void
                    346: destroy_libs(void);
                    347:
                    348: void
                    349: set_search_domain(char *domain);
                    350:
                    351: char *
                    352: next_token(char **stringp, const char *delim);
                    353:
                    354: /*
                    355:  * Routines to be defined in dig.c, host.c, and nslookup.c. and
                    356:  * then assigned to the appropriate function pointer
                    357:  */
                    358:
                    359: extern isc_result_t
                    360: (*dighost_printmessage)(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers);
                    361: /*%<
                    362:  * Print the final result of the lookup.
                    363:  */
                    364:
                    365: extern void
                    366: (*dighost_received)(unsigned int bytes, isc_sockaddr_t *from, dig_query_t *query);
                    367: /*%<
                    368:  * Print a message about where and when the response
                    369:  * was received from, like the final comment in the
                    370:  * output of "dig".
                    371:  */
                    372:
                    373: extern void
                    374: (*dighost_trying)(char *frm, dig_lookup_t *lookup);
                    375:
                    376: extern void
                    377: (*dighost_shutdown)(void);
                    378:
                    379: void save_opt(dig_lookup_t *lookup, char *code, char *value);
                    380:
                    381: void setup_file_key(void);
                    382: void setup_text_key(void);
                    383:
                    384: /*
                    385:  * Routines exported from dig.c for use by dig for iOS
                    386:  */
                    387:
                    388: /*%<
                    389:  * Call once only to set up libraries, parse global
                    390:  * parameters and initial command line query parameters
                    391:  */
                    392: void
                    393: dig_setup(int argc, char **argv);
                    394:
                    395: /*%<
                    396:  * Call to supply new parameters for the next lookup
                    397:  */
                    398: void
                    399: dig_query_setup(isc_boolean_t, isc_boolean_t, int argc, char **argv);
                    400:
                    401: /*%<
                    402:  * set the main application event cycle running
                    403:  */
                    404: void
                    405: dig_startup(void);
                    406:
                    407: /*%<
                    408:  * Cleans up the application
                    409:  */
                    410: void
                    411: dig_shutdown(void);
                    412:
                    413: ISC_LANG_ENDDECLS
                    414:
                    415: #endif