[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.12

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