home *** CD-ROM | disk | FTP | other *** search
/ PC-Online 1996 May / PCOnline_05_1996.bin / linux / source / n / bind / bind-4.001 / bind-4~ / bind-4.9.3-BETA9 / named / ns_defs.h < prev    next >
C/C++ Source or Header  |  1994-07-23  |  13KB  |  369 lines

  1. /*
  2.  *    from ns.h    4.33 (Berkeley) 8/23/90
  3.  *    $Id: ns_defs.h,v 1.12 1994/07/23 23:23:56 vixie Exp $
  4.  */
  5.  
  6. /*
  7.  * ++Copyright++ 1986
  8.  * -
  9.  * Copyright (c) 1986
  10.  *    The Regents of the University of California.  All rights reserved.
  11.  * 
  12.  * Redistribution and use in source and binary forms, with or without
  13.  * modification, are permitted provided that the following conditions
  14.  * are met:
  15.  * 1. Redistributions of source code must retain the above copyright
  16.  *    notice, this list of conditions and the following disclaimer.
  17.  * 2. Redistributions in binary form must reproduce the above copyright
  18.  *    notice, this list of conditions and the following disclaimer in the
  19.  *    documentation and/or other materials provided with the distribution.
  20.  * 3. All advertising materials mentioning features or use of this software
  21.  *    must display the following acknowledgement:
  22.  *     This product includes software developed by the University of
  23.  *     California, Berkeley and its contributors.
  24.  * 4. Neither the name of the University nor the names of its contributors
  25.  *    may be used to endorse or promote products derived from this software
  26.  *    without specific prior written permission.
  27.  * 
  28.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  29.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  30.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  31.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  32.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  33.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  34.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  37.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  38.  * SUCH DAMAGE.
  39.  * -
  40.  * Portions Copyright (c) 1993 by Digital Equipment Corporation.
  41.  * 
  42.  * Permission to use, copy, modify, and distribute this software for any
  43.  * purpose with or without fee is hereby granted, provided that the above
  44.  * copyright notice and this permission notice appear in all copies, and that
  45.  * the name of Digital Equipment Corporation not be used in advertising or
  46.  * publicity pertaining to distribution of the document or software without
  47.  * specific, written prior permission.
  48.  * 
  49.  * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
  50.  * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
  51.  * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
  52.  * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  53.  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  54.  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
  55.  * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  56.  * SOFTWARE.
  57.  * -
  58.  * --Copyright--
  59.  */
  60.  
  61. /*
  62.  * Global definitions for the name server.
  63.  */
  64.  
  65. /*
  66.  * Effort has been expended here to make all structure members 32 bits or
  67.  * larger land on 32-bit boundaries; smaller structure members have been
  68.  * deliberately shuffled and smaller integer sizes chosen where possible
  69.  * to make sure this happens.  This is all meant to avoid structure member
  70.  * padding which can cost a _lot_ of memory when you have hundreds of 
  71.  * thousands of entries in your cache.
  72.  */
  73.  
  74. /*
  75.  * Timeout time should be around 1 minute or so.  Using the
  76.  * the current simplistic backoff strategy, the sequence
  77.  * retrys after 4, 8, and 16 seconds.  With 3 servers, this
  78.  * dies out in a little more than a minute.
  79.  * (sequence RETRYBASE, 2*RETRYBASE, 4*RETRYBASE... for MAXRETRY)
  80.  */
  81. #define MINROOTS    2    /* min number of root hints */
  82. #define NSMAX        16    /* max number of NS addrs to try ([0..255]) */
  83. #define RETRYBASE    4     /* base time between retries */
  84. #define    MAXCLASS    255    /* XXX - may belong elsewhere */
  85. #define MAXRETRY    3    /* max number of retries per addr */
  86. #define MAXCNAMES    8    /* max # of CNAMES tried per addr */
  87. #define MAXQUERIES    20    /* max # of queries to be made */
  88. #define    MAXQSERIAL    4    /* max # of outstanding QSERIAL's */
  89.                 /* (prevent "recursive" loops) */
  90. #define    INIT_REFRESH    600    /* retry time for initial secondary */
  91.                 /* contact (10 minutes) */
  92. #define NADDRECS    20    /* max addt'l rr's per resp */
  93.  
  94. #define XFER_TIMER    120    /* named-xfer's connect timeout */
  95. #define MAX_XFER_TIME    60*60*2    /* max seconds for an xfer */
  96. #define XFER_TIME_FUDGE    10    /* MAX_XFER_TIME fudge */
  97. #define MAX_XFERS_RUNNING 10    /* default max value of xfers_running */
  98. #define    MAX_XFERS_PERNS    2    /* max # of xfers per peer nameserver */
  99.  
  100. #define ALPHA    0.7    /* How much to preserve of old response time */
  101. #define    BETA     1.2    /* How much to penalize response time on failure */
  102. #define    GAMMA     0.98    /* How much to decay unused response times */
  103.  
  104.     /* sequence-space arithmetic */
  105. #define SEQ_GT(a,b)    ((int32_t)((a)-(b)) > 0)
  106.  
  107. /* these fields are ordered to maintain word-alignment;
  108.  * be careful about changing them.
  109.  */
  110. struct zoneinfo {
  111.     char        *z_origin;    /* root domain name of zone */
  112.     time_t        z_time;        /* time for next refresh */
  113.     time_t        z_lastupdate;    /* time of last refresh */
  114.     u_int32_t    z_refresh;    /* refresh interval */
  115.     u_int32_t    z_retry;    /* refresh retry interval */
  116.     u_int32_t    z_expire;    /* expiration time for cached info */
  117.     u_int32_t    z_minimum;    /* minimum TTL value */
  118.     u_int32_t    z_serial;    /* changes if zone modified */
  119.     char        *z_source;    /* source location of data */
  120.     time_t        z_ftime;    /* modification time of source file */
  121.     struct in_addr    z_xaddr;    /* override server for next xfer */
  122.     struct in_addr    z_addr[NSMAX];    /* list of master servers for zone */
  123.     u_char        z_addrcnt;    /* number of entries in z_addr[] */
  124.     u_char        z_type;        /* type of zone; see below */
  125.     u_int16_t    z_flags;    /* state bits; see below */
  126.     pid_t        z_xferpid;    /* xfer child pid */
  127.     int        z_class;    /* class of zone */
  128. #ifdef SECURE_ZONES
  129.     struct netinfo *secure_nets;    /* list of secure networks for zone */
  130. #endif    
  131. };
  132.  
  133.     /* zone types (z_type) */
  134. #define    Z_NIL        0        /* zone slot not in use */
  135. #define Z_PRIMARY    1
  136. #define Z_SECONDARY    2
  137. #define Z_CACHE        3
  138. #define Z_STUB        4
  139.  
  140.     /* zone state bits (16 bits) */
  141. #define    Z_AUTH        0x0001        /* zone is authoritative */
  142. #define    Z_NEED_XFER    0x0002        /* waiting to do xfer */
  143. #define    Z_XFER_RUNNING    0x0004        /* asynch. xfer is running */
  144. #define    Z_NEED_RELOAD    0x0008        /* waiting to do reload */
  145. #define    Z_SYSLOGGED    0x0010        /* have logged timeout */
  146. #define    Z_QSERIAL    0x0020        /* sysquery()'ing for serial number */
  147. #define    Z_FOUND        0x0040        /* found in boot file when reloading */
  148. #define    Z_INCLUDE    0x0080        /* set if include used in file */
  149. #define    Z_DB_BAD    0x0100        /* errors when loading file */
  150. #define    Z_TMP_FILE    0x0200        /* backup file for xfer is temporary */
  151. #ifdef ALLOW_UPDATES
  152. #define    Z_DYNAMIC    0x0400        /* allow dynamic updates */
  153. #define    Z_DYNADDONLY    0x0800        /* dynamic mode: add new data only */
  154. #define    Z_CHANGED    0x1000        /* zone has changed */
  155. #endif /* ALLOW_UPDATES */
  156.  
  157.     /* named_xfer exit codes */
  158. #define    XFER_UPTODATE    0        /* zone is up-to-date */
  159. #define    XFER_SUCCESS    1        /* performed transfer successfully */
  160. #define    XFER_TIMEOUT    2        /* no server reachable/xfer timeout */
  161. #define    XFER_FAIL    3        /* other failure, has been logged */
  162.  
  163. #include <sys/time.h>
  164.  
  165. /* XXX - "struct qserv" is deprecated in favor of "struct nameser" */
  166. struct qserv {
  167.     struct sockaddr_in
  168.             ns_addr;    /* address of NS */
  169.     struct databuf    *ns;        /* databuf for NS record */
  170.     struct databuf    *nsdata;    /* databuf for server address */
  171.     struct timeval    stime;        /* time first query started */
  172.     int        nretry;        /* # of times addr retried */
  173. };
  174.  
  175. /*
  176.  * Structure for recording info on forwarded or generated queries.
  177.  */
  178. struct qinfo {
  179.     u_int16_t    q_id;        /* id of query */
  180.     u_int16_t    q_nsid;        /* id of forwarded query */
  181.     struct sockaddr_in
  182.             q_from;        /* requestor's address */
  183.     u_char        *q_msg,        /* the message */
  184.             *q_cmsg;    /* the cname message */
  185.     int16_t        q_msglen,    /* len of message */
  186.             q_cmsglen;    /* len of cname message */
  187.     int16_t        q_dfd;        /* UDP file descriptor */
  188.     struct fwdinfo    *q_fwd;        /* last    forwarder used */
  189.     time_t        q_time;        /* time to retry */
  190.     time_t        q_expire;    /* time to expire */
  191.     struct qinfo    *q_next;    /* rexmit list (sorted by time) */
  192.     struct qinfo    *q_link;    /* storage list (random order) */
  193.     struct databuf    *q_usedns[NSMAX]; /* databuf for NS that we've tried */
  194.     struct qserv    q_addr[NSMAX];    /* addresses of NS's */
  195. #ifdef notyet
  196.     struct nameser    *q_ns[NSMAX];    /* name servers */
  197. #endif
  198.     u_char        q_naddr;    /* number of addr's in q_addr */
  199.     u_char        q_curaddr;    /* last addr sent to */
  200.     u_char        q_nusedns;    /* number of elements in q_usedns[] */
  201.     u_int8_t    q_flags;    /* see below */
  202.     int16_t        q_cname;    /* # of cnames found */
  203.     int16_t        q_nqueries;    /* # of queries required */
  204.     struct qstream    *q_stream;    /* TCP stream, null if UDP */
  205.     struct zoneinfo    *q_zquery;    /* Zone query is about (Q_ZSERIAL) */
  206. #ifdef LAME_DELEGATION
  207.     char    q_domain[MAXDNAME];    /* domain for servers we are querying */
  208. #endif /* LAME_DELEGATION */
  209. };
  210.  
  211.     /* q_flags bits (8 bits) */
  212. #define    Q_SYSTEM    0x01        /* is a system query */
  213. #define    Q_PRIMING    0x02        /* generated during priming phase */
  214. #define    Q_ZSERIAL    0x04        /* getting zone serial for xfer test */
  215.  
  216. #define    Q_NEXTADDR(qp,n)    \
  217.     (((qp)->q_fwd == (struct fwdinfo *)0) ? \
  218.      &(qp)->q_addr[n].ns_addr : &(qp)->q_fwd->fwdaddr)
  219.  
  220. #define    RETRY_TIMEOUT    45
  221. #define QINFO_NULL    ((struct qinfo *)0)
  222.  
  223. /*
  224.  * Return codes from ns_forw:
  225.  */
  226. #define    FW_OK        0
  227. #define    FW_DUP        1
  228. #define    FW_NOSERVER    2
  229. #define    FW_SERVFAIL    3
  230.  
  231. struct qstream {
  232.     int        s_rfd;        /* stream file descriptor */
  233.     int        s_size;        /* expected amount of data to recive */
  234.     int        s_bufsize;    /* amount of data recived in s_buf */
  235.     u_char        *s_buf;        /* buffer of received data */
  236.     u_char        *s_bufp;    /* pointer into s_buf of recived data*/
  237.     struct qstream    *s_next;    /* next stream */
  238.     struct sockaddr_in
  239.             s_from;        /* address query came from */
  240.     u_int32_t    s_time;        /* time stamp of last transaction */
  241.     int        s_refcnt;    /* number of outstanding queries */
  242.     u_int16_t    s_tempsize;    /* temporary for size from net */
  243. };
  244. #define QSTREAM_NULL    ((struct qstream *)0)
  245.  
  246. struct qdatagram {
  247.     int        dq_dfd;        /* datagram file descriptor */
  248.     time_t        dq_gen;        /* generation number */
  249.     struct qdatagram
  250.             *dq_next;    /* next datagram */
  251.     struct in_addr    dq_addr;    /* interface address */
  252. };
  253. #define QDATAGRAM_NULL    ((struct qdatagram *)0)
  254.  
  255. struct netinfo {
  256.     struct netinfo    *next;
  257.     u_int32_t    addr;
  258.     u_int32_t    mask;
  259.     struct in_addr    my_addr;
  260. };
  261.  
  262. #define ALLOW_NETS    0x0001
  263. #define    ALLOW_HOSTS    0x0002
  264. #define    ALLOW_ALL    (ALLOW_NETS | ALLOW_HOSTS)
  265.  
  266. struct fwdinfo {
  267.     struct fwdinfo    *next;
  268.     struct sockaddr_in
  269.             fwdaddr;
  270. };
  271.  
  272. enum nameserStats {    nssRcvdQ,    /* sent us a query */
  273.             nssRcvdR,    /* sent us an answer */
  274.             nssRcvdIQ,    /* sent us an inverse query */
  275.             nssRcvdNXD,    /* sent us a negative response */
  276.             nssRcvdFwdQ,    /* sent us a query we had to fwd */
  277.             nssRcvdFwdR,    /* sent us a response we had to fwd */
  278.             nssRcvdDupQ,    /* sent us a retry */
  279.             nssRcvdDupR,    /* sent us an extra answer */
  280.             nssRcvdFail,    /* sent us a SERVFAIL */
  281.             nssRcvdFErr,    /* sent us a FORMERR */
  282.             nssRcvdErr,    /* sent us some other error */
  283.             nssRcvdTCP,    /* sent us a query using TCP */
  284.             nssRcvdAXFR,    /* sent us an AXFR */
  285.             nssRcvdLDel,    /* sent us a lame delegation */
  286.             nssRcvdOpts,    /* sent us some IP options */
  287.             nssSentSysQ,    /* sent them a sysquery */
  288.             nssSentAns,    /* sent them an answer */
  289.             nssSentFwdQ,    /* fwdd a query to them */
  290.             nssSentFwdR,    /* fwdd a response to them */
  291.             nssSentDupQ,    /* sent them a retry */
  292.             nssSentFail,    /* sent them a SERVFAIL */
  293.             nssSentFErr,    /* sent them a FORMERR */
  294.             nssSendtoErr,    /* error in sendto(2) */
  295.             nssLast };
  296.  
  297. struct nameser {
  298.     struct in_addr    addr;        /* key */
  299.     u_long        stats[nssLast];    /* statistics */
  300. #ifdef notyet
  301.     u_int32_t    rtt;        /* round trip time */
  302.     /* XXX - need to add more stuff from "struct qserv", and use our rtt */
  303.     u_int16_t    flags;        /* see below */
  304. #endif
  305.     u_int8_t    xfers;        /* #/xfers running right now */
  306. };
  307.         
  308.  
  309. #ifdef NCACHE
  310. #define NOERROR_NODATA   6 /* only used internally by the server, used for
  311.                             * -ve $ing non-existence of records. 6 is not 
  312.                             * a code used as yet anyway. anant@isi.edu
  313.                             */
  314. #define NTTL        600 /* ttl for negative data: 10 minutes? */
  315. #endif /*NCACHE*/
  316.  
  317. #define VQEXPIRY    900 /* a VQ entry expires in 15*60 = 900 seconds */
  318.  
  319. #ifdef VALIDATE
  320.  
  321. #define INVALID        0
  322. #define VALID_NO_CACHE    1
  323. #define VALID_CACHE    2
  324. #define MAXNAMECACHE    100
  325. #define MAXVQ        100 /* Max number of elements in TO_Validate queue */
  326.  
  327. struct _nameaddr {
  328.     struct in_addr    ns_addr;
  329.     char        *nsname;
  330. };
  331. typedef struct _nameaddr NAMEADDR;
  332.  
  333. struct _to_validate {
  334.     int16_t        class;        /* Name Class */
  335.     int16_t        type;        /* RR type */
  336.     char        *data;        /* RR data */
  337.     char        *dname;        /* Name */
  338.     time_t        time;        /* time at which inserted in queue */
  339.     struct _to_validate
  340.             *next,
  341.             *prev;
  342. };
  343. typedef struct _to_validate TO_Validate;
  344.  
  345. #endif /*VALIDATE*/
  346.  
  347.  
  348. #ifdef DEBUG
  349. # define dprintf(lev, args) ((debug >= lev) && fprintf args)
  350. #else
  351. # define dprintf(lev, args)
  352. #endif
  353.  
  354.  
  355. #ifdef INIT
  356.     error "INIT already defined, check system include files"
  357. #endif
  358. #ifdef DECL
  359.     error "DECL already defined, check system include files"
  360. #endif
  361.  
  362. #ifdef MAIN_PROGRAM
  363. #define INIT(x) = x
  364. #define    DECL
  365. #else
  366. #define INIT(x)
  367. #define DECL extern
  368. #endif
  369.