1: /*
2: * Copyright (c) 1985 Regents of the University of California.
3: * All rights reserved.
4: *
5: * Redistribution and use in source and binary forms are permitted
6: * provided that this notice is preserved and that due credit is given
7: * to the University of California at Berkeley. The name of the University
8: * may not be used to endorse or promote products derived from this
9: * software without specific prior written permission. This software
10: * is provided ``as is'' without express or implied warranty.
11: *
12: * @(#)ns.h 4.21.1 (2.11BSD GTE) 1/1/94
13: */
14:
15: /*
16: * Global definitions and variables for the name server.
17: */
18:
19: #include <strings.h>
20: #include <arpa/inet.h>
21:
22: /*
23: * Timeout time should be around 1 minute or so. Using the
24: * the current simplistic backoff strategy, the sequence
25: * retrys after 4, 8, and 16 seconds. With 3 servers, this
26: * dies out in a little more than a minute.
27: * (sequence RETRYBASE, 2*RETRYBASE, 4*RETRYBASE... for MAXRETRY)
28: */
29: #define MAXZONES 128 /* max number of zones supported */
30: #define MINROOTS 2 /* min number of root hints */
31: #define NSMAX 10 /* max number of NS's to try */
32: #define RETRYBASE 4 /* base time between retries */
33: #define MAXRETRY 3 /* max number of retries per addr */
34: #define MAXCNAMES 8 /* max # of CNAMES tried per addr */
35: #define MAXQUERIES 20 /* max # of queries to be made */
36: /* (prevent "recursive" loops) */
37: #define INIT_REFRESH 600 /* retry time for initial secondary */
38: /* contact (10 minutes) */
39:
40: #define ALPHA 0.7 /* How much to preserver of old response time */
41: #define BETA 1.2 /* How much to penalize response time on failure */
42: #define GAMMA 0.98 /* How much to decay unused response times */
43:
44: struct zoneinfo {
45: int z_type; /* type of zone */
46: int z_auth; /* zone is authoritative */
47: char *z_origin; /* root domain name of zone */
48: time_t z_time; /* time for next refresh */
49: time_t z_lastupdate; /* time of last refresh */
50: u_long z_refresh; /* refresh interval */
51: u_long z_retry; /* refresh retry interval */
52: u_long z_expire; /* expiration time for cached info */
53: u_long z_minimum; /* minimum TTL value */
54: u_long z_serial; /* changes if zone modified */
55: char *z_source; /* source location of data */
56: time_t z_ftime; /* modification time of source file */
57: int z_addrcnt; /* address count */
58: struct in_addr z_addr[NSMAX]; /* list of master servers for zone */
59: int z_sysloged; /* has fail to transfer been sysloged */
60: #ifdef ALLOW_UPDATES
61: int hasChanged; /* non-zero if zone has been updated
62: * since last checkpoint
63: */
64: #endif ALLOW_UPDATES
65: };
66:
67: /* zone types (z_type) */
68: #define Z_PRIMARY 1
69: #define Z_SECONDARY 2
70: #define Z_CACHE 3
71:
72: /*
73: * Structure for recording info on forwarded queries.
74: */
75: struct qinfo {
76: u_short q_id; /* id of query */
77: u_short q_nsid; /* id of forwarded query */
78: int q_dfd; /* UDP file descriptor */
79: struct sockaddr_in q_from; /* requestor's address */
80: char *q_msg; /* the message */
81: int q_msglen; /* len of message */
82: int q_naddr; /* number of addr's in q_addr */
83: int q_curaddr; /* last addr sent to */
84: struct fwdinfo *q_fwd; /* last forwarder used */
85: time_t q_time; /* time to retry */
86: struct qinfo *q_next; /* rexmit list (sorted by time) */
87: struct qinfo *q_link; /* storage list (random order) */
88: struct qserv {
89: struct sockaddr_in ns_addr; /* addresses of NS's */
90: struct databuf *ns; /* databuf for NS record */
91: struct databuf *nsdata; /* databuf for server address */
92: struct timeval stime; /* time first query started */
93: int nretry; /* # of times addr retried */
94: } q_addr[NSMAX]; /* addresses of NS's */
95: struct databuf *q_usedns[NSMAX]; /* databuf for NS that we've tried */
96: int q_nusedns;
97: int q_cname; /* # of cnames found */
98: int q_nqueries; /* # of queries required */
99: char *q_cmsg; /* the cname message */
100: int q_cmsglen; /* len of cname message */
101: struct qstream *q_stream; /* TCP stream, null if UDP */
102: int q_system; /* boolean, system query */
103: };
104:
105: #define Q_NEXTADDR(qp,n) \
106: (((qp)->q_fwd == (struct fwdinfo *)0) ? \
107: &(qp)->q_addr[n].ns_addr : &(qp)->q_fwd->fwdaddr)
108:
109: #define PRIMING_CACHE 42
110: #define QINFO_NULL ((struct qinfo *)0)
111: extern struct qinfo *qfindid();
112: extern struct qinfo *qnew();
113: extern struct qinfo *retryqp; /* next query to retry */
114: /*
115: * Return codes from ns_forw:
116: */
117: #define FW_OK 0
118: #define FW_DUP 1
119: #define FW_NOSERVER 2
120: #define FW_SERVFAIL 3
121:
122: struct qstream {
123: int s_rfd; /* stream file descriptor */
124: int s_size; /* expected amount of data to recive */
125: int s_bufsize; /* amount of data recived in s_buf */
126: char *s_buf; /* buffer of recived data */
127: char *s_bufp; /* pointer into s_buf of recived data */
128: struct qstream *s_next; /* next stream */
129: struct sockaddr_in s_from; /* address query came from */
130: u_long s_time; /* time stamp of last transaction */
131: int s_refcnt; /* number of outstanding queries */
132: u_short s_tempsize; /* temporary for size from net */
133: };
134:
135: #define QSTREAM_NULL ((struct qstream *)0)
136: extern struct qstream *streamq; /* stream queue */
137:
138: struct qdatagram {
139: int dq_dfd; /* datagram file descriptor */
140: struct qdatagram *dq_next; /* next datagram */
141: struct in_addr dq_addr; /* address of interface */
142: };
143:
144: #define QDATAGRAM_NULL ((struct qdatagram *)0)
145: extern struct qdatagram *datagramq; /* datagram queue */
146:
147: struct netinfo {
148: struct netinfo *next;
149: u_long net;
150: u_long mask;
151: struct in_addr my_addr;
152: };
153:
154: struct fwdinfo {
155: struct fwdinfo *next;
156: struct sockaddr_in fwdaddr;
157: };
158:
159: struct nets {
160: char *name;
161: long net;
162: struct nets *next;
163: };
164:
165: /*
166: * Statistics Defines
167: */
168: struct stats {
169: u_long cnt;
170: char *description;
171: };
172:
173: /* gross count of UDP packets in and out */
174: #define S_INPKTS 0
175: #define S_OUTPKTS 1
176: /* gross count of queries and inverse queries received */
177: #define S_QUERIES 2
178: #define S_IQUERIES 3
179: #define S_DUPQUERIES 4
180: #define S_RESPONSES 5
181: #define S_DUPRESP 6
182: #define S_RESPOK 7
183: #define S_RESPFAIL 8
184: #define S_RESPFORMERR 9
185: #define S_SYSQUERIES 10
186: #define S_PRIMECACHE 11
187: #define S_CHECKNS 12
188: #define S_BADRESPONSES 13
189: #define S_MARTIANS 14
190: #define S_NSTATS 15 /* Careful! */
191: #ifdef STATS
192: extern struct stats stats[S_NSTATS];
193: extern u_long typestats[T_ANY+1];
194: #endif
195:
196: #ifdef DEBUG
197: extern int debug; /* debug flag */
198: extern FILE *ddt; /* debug file discriptor */
199: #endif
200: extern int ds; /* datagram socket */
201: extern struct qdatagram *dqp;
202: extern struct timeval tt; /* place to store time */
203:
204: extern struct itimerval ival; /* maintenance interval */
205: extern struct zoneinfo zones[MAXZONES]; /* zone information */
206: extern int nzones; /* number of zones in use */
207:
208: #ifdef vax
209: extern u_short htons(), ntohs();
210: extern u_long htonl(), ntohl();
211: #endif
Defined struct's
nets
defined in line
159; used 2 times
qinfo
defined in line
75; used 78 times
- in line 86-87(4),
111-113(6)
- in /usr/src/usr.sbin/named/named/ns_forw.c line
27-28(4),
53-55(4),
154(2),
278-281(4),
308-310(4),
335(2),
449(2),
477(2),
487-491(4),
508-513(8),
531-533(4)
- in /usr/src/usr.sbin/named/named/ns_main.c line
163(2)
- in /usr/src/usr.sbin/named/named/ns_req.c line
47(2),
73-74(4)
- in /usr/src/usr.sbin/named/named/ns_resp.c line
38(2),
44(2),
1016-1020(6),
1067(2),
1086(2),
1106-1113(6)
qserv
defined in line
88; used 10 times
qstream
defined in line
122; used 35 times
- in line 101,
128(2),
136(2)
- in /usr/src/usr.sbin/named/named/ns_forw.c line
51(2)
- in /usr/src/usr.sbin/named/named/ns_main.c line
106(2),
140(2),
152(2),
162(2),
1067-1072(8),
1092-1095(4),
1122(2)
- in /usr/src/usr.sbin/named/named/ns_req.c line
56(2),
1043(2),
1257(2)
Defined macros
ALPHA
defined in line
40; used 3 times
BETA
defined in line
41; used 2 times
GAMMA
defined in line
42; used 1 times
NSMAX
defined in line
31; used 13 times
QSTREAM_NULL
defined in line
135; used 14 times
- in /usr/src/usr.sbin/named/named/ns_main.c line
106,
152,
687,
700-701(2),
715,
727,
755,
1079,
1124
- in /usr/src/usr.sbin/named/named/ns_req.c line
163,
558
- in /usr/src/usr.sbin/named/named/ns_resp.c line
1029,
1045
Usage of this include