nameser.h revision 1.15 1 /*
2 * ++Copyright++ 1983, 1989, 1993
3 * -
4 * Copyright (c) 1983, 1989, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 * -
31 * Portions Copyright (c) 1993 by Digital Equipment Corporation.
32 *
33 * Permission to use, copy, modify, and distribute this software for any
34 * purpose with or without fee is hereby granted, provided that the above
35 * copyright notice and this permission notice appear in all copies, and that
36 * the name of Digital Equipment Corporation not be used in advertising or
37 * publicity pertaining to distribution of the document or software without
38 * specific, written prior permission.
39 *
40 * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
41 * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
42 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
43 * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
44 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
45 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
46 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
47 * SOFTWARE.
48 * -
49 * Portions Copyright (c) 1995 by International Business Machines, Inc.
50 *
51 * International Business Machines, Inc. (hereinafter called IBM) grants
52 * permission under its copyrights to use, copy, modify, and distribute this
53 * Software with or without fee, provided that the above copyright notice and
54 * all paragraphs of this notice appear in all copies, and that the name of IBM
55 * not be used in connection with the marketing of any product incorporating
56 * the Software or modifications thereof, without specific, written prior
57 * permission.
58 *
59 * To the extent it has a right to do so, IBM grants an immunity from suit
60 * under its patents, if any, for the use, sale or manufacture of products to
61 * the extent that such products are used for performing Domain Name System
62 * dynamic updates in TCP/IP networks by means of the Software. No immunity is
63 * granted for any product per se or for any other function of any product.
64 *
65 * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES,
66 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
67 * PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL,
68 * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING
69 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN
70 * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.
71 * --Copyright--
72 */
73
74 /*
75 * @(#)nameser.h 8.1 (Berkeley) 6/2/93
76 * $NetBSD: nameser.h,v 1.15 2003/08/07 09:44:12 agc Exp $
77 */
78
79 #ifndef _ARPA_NAMESER_H_
80 #define _ARPA_NAMESER_H_
81
82 #include <sys/param.h>
83 #if (!defined(BSD)) || (BSD < 199306)
84 # include <sys/bitypes.h>
85 #else
86 # include <sys/types.h>
87 #endif
88 #include <sys/cdefs.h>
89
90 #ifdef _AUX_SOURCE
91 # include <sys/types.h>
92 #endif
93
94 /*
95 * revision information. this is the release date in YYYYMMDD format.
96 * it can change every day so the right thing to do with it is use it
97 * in preprocessor commands such as "#if (__BIND > 19931104)". do not
98 * compare for equality; rather, use it to determine whether your resolver
99 * is new enough to contain a certain feature.
100 */
101
102 #define __BIND 19960801 /* interface version stamp */
103
104 /*
105 * Define constants based on rfc883
106 */
107 #define PACKETSZ 512 /* maximum packet size */
108 #define MAXDNAME 1025 /* maximum presentation domain name */
109 #define MAXCDNAME 255 /* maximum compressed domain name */
110 #define MAXLABEL 63 /* maximum length of domain label */
111 #define HFIXEDSZ 12 /* #/bytes of fixed data in header */
112 #define QFIXEDSZ 4 /* #/bytes of fixed data in query */
113 #define RRFIXEDSZ 10 /* #/bytes of fixed data in r record */
114 #define INT32SZ 4 /* for systems without 32-bit ints */
115 #define INT16SZ 2 /* for systems without 16-bit ints */
116 #define INADDRSZ 4 /* IPv4 T_A */
117 #define IN6ADDRSZ 16 /* IPv6 T_AAAA */
118
119 /*
120 * Internet nameserver port number
121 */
122 #define NAMESERVER_PORT 53
123
124 /*
125 * Currently defined opcodes
126 */
127 #define QUERY 0x0 /* standard query */
128 #define IQUERY 0x1 /* inverse query */
129 #define STATUS 0x2 /* nameserver status query */
130 /*#define xxx 0x3*/ /* 0x3 reserved */
131 #define NS_NOTIFY_OP 0x4 /* notify secondary of SOA change */
132 /*
133 * Currently defined response codes
134 */
135 #define NOERROR 0 /* no error */
136 #define FORMERR 1 /* format error */
137 #define SERVFAIL 2 /* server failure */
138 #define NXDOMAIN 3 /* non existent domain */
139 #define NOTIMP 4 /* not implemented */
140 #define REFUSED 5 /* query refused */
141
142 /*
143 * Type values for resources and queries
144 */
145 #define T_A 1 /* host address */
146 #define T_NS 2 /* authoritative server */
147 #define T_MD 3 /* mail destination */
148 #define T_MF 4 /* mail forwarder */
149 #define T_CNAME 5 /* canonical name */
150 #define T_SOA 6 /* start of authority zone */
151 #define T_MB 7 /* mailbox domain name */
152 #define T_MG 8 /* mail group member */
153 #define T_MR 9 /* mail rename name */
154 #define T_NULL 10 /* null resource record */
155 #define T_WKS 11 /* well known service */
156 #define T_PTR 12 /* domain name pointer */
157 #define T_HINFO 13 /* host information */
158 #define T_MINFO 14 /* mailbox information */
159 #define T_MX 15 /* mail routing information */
160 #define T_TXT 16 /* text strings */
161 #define T_RP 17 /* responsible person */
162 #define T_AFSDB 18 /* AFS cell database */
163 #define T_X25 19 /* X_25 calling address */
164 #define T_ISDN 20 /* ISDN calling address */
165 #define T_RT 21 /* router */
166 #define T_NSAP 22 /* NSAP address */
167 #define T_NSAP_PTR 23 /* reverse NSAP lookup (deprecated) */
168 #define T_SIG 24 /* security signature */
169 #define T_KEY 25 /* security key */
170 #define T_PX 26 /* X.400 mail mapping */
171 #define T_GPOS 27 /* geographical position (withdrawn) */
172 #define T_AAAA 28 /* IP6 Address */
173 #define T_LOC 29 /* Location Information */
174 #define T_NXT 30 /* Next Valid Name in Zone */
175 #define T_EID 31 /* Endpoint identifier */
176 #define T_NIMLOC 32 /* Nimrod locator */
177 #define T_SRV 33 /* Server selection */
178 #define T_ATMA 34 /* ATM Address */
179 #define T_NAPTR 35 /* Naming Authority PoinTeR */
180 #define T_OPT 41 /* OPT pseudo-RR, RFC2761 */
181 /* non standard */
182 #define T_UINFO 100 /* user (finger) information */
183 #define T_UID 101 /* user ID */
184 #define T_GID 102 /* group ID */
185 #define T_UNSPEC 103 /* Unspecified format (binary data) */
186 /* Query type values which do not appear in resource records */
187 #define T_IXFR 251 /* incremental zone transfer */
188 #define T_AXFR 252 /* transfer zone of authority */
189 #define T_MAILB 253 /* transfer mailbox records */
190 #define T_MAILA 254 /* transfer mail agent records */
191 #define T_ANY 255 /* wildcard match */
192
193 /*
194 * Values for class field
195 */
196
197 #define C_IN 1 /* the arpa internet */
198 #define C_CHAOS 3 /* for chaos net (MIT) */
199 #define C_HS 4 /* for Hesiod name server (MIT) (XXX) */
200 /* Query class values which do not appear in resource records */
201 #define C_ANY 255 /* wildcard match */
202
203 /*
204 * Flags field of the KEY RR rdata
205 */
206 #define KEYFLAG_TYPEMASK 0xC000 /* Mask for "type" bits */
207 #define KEYFLAG_TYPE_AUTH_CONF 0x0000 /* Key usable for both */
208 #define KEYFLAG_TYPE_CONF_ONLY 0x8000 /* Key usable for confidentiality */
209 #define KEYFLAG_TYPE_AUTH_ONLY 0x4000 /* Key usable for authentication */
210 #define KEYFLAG_TYPE_NO_KEY 0xC000 /* No key usable for either; no key */
211 /* The type bits can also be interpreted independently, as single bits: */
212 #define KEYFLAG_NO_AUTH 0x8000 /* Key not usable for authentication */
213 #define KEYFLAG_NO_CONF 0x4000 /* Key not usable for confidentiality */
214
215 #define KEYFLAG_EXPERIMENTAL 0x2000 /* Security is *mandatory* if bit=0 */
216 #define KEYFLAG_RESERVED3 0x1000 /* reserved - must be zero */
217 #define KEYFLAG_RESERVED4 0x0800 /* reserved - must be zero */
218 #define KEYFLAG_USERACCOUNT 0x0400 /* key is assoc. with a user acct */
219 #define KEYFLAG_ENTITY 0x0200 /* key is assoc. with entity eg host */
220 #define KEYFLAG_ZONEKEY 0x0100 /* key is zone key for the zone named */
221 #define KEYFLAG_IPSEC 0x0080 /* key is for IPSEC use (host or user)*/
222 #define KEYFLAG_EMAIL 0x0040 /* key is for email (MIME security) */
223 #define KEYFLAG_RESERVED10 0x0020 /* reserved - must be zero */
224 #define KEYFLAG_RESERVED11 0x0010 /* reserved - must be zero */
225 #define KEYFLAG_SIGNATORYMASK 0x000F /* key can sign DNS RR's of same name */
226
227 #define KEYFLAG_RESERVED_BITMASK ( KEYFLAG_RESERVED3 | \
228 KEYFLAG_RESERVED4 | \
229 KEYFLAG_RESERVED10| KEYFLAG_RESERVED11)
230
231 /* The Algorithm field of the KEY and SIG RR's is an integer, {1..254} */
232 #define ALGORITHM_MD5RSA 1 /* MD5 with RSA */
233 #define ALGORITHM_EXPIRE_ONLY 253 /* No alg, no security */
234 #define ALGORITHM_PRIVATE_OID 254 /* Key begins with OID indicating alg */
235
236 /* Signatures */
237 /* Size of a mod or exp in bits */
238 #define MIN_MD5RSA_KEY_PART_BITS 512
239 #define MAX_MD5RSA_KEY_PART_BITS 2552
240 /* Total of binary mod and exp, bytes */
241 #define MAX_MD5RSA_KEY_BYTES ((MAX_MD5RSA_KEY_PART_BITS+7/8)*2+3)
242 /* Max length of text sig block */
243 #define MAX_KEY_BASE64 (((MAX_MD5RSA_KEY_BYTES+2)/3)*4)
244
245 /*
246 * Status return codes for T_UNSPEC conversion routines
247 */
248 #define CONV_SUCCESS 0
249 #define CONV_OVERFLOW (-1)
250 #define CONV_BADFMT (-2)
251 #define CONV_BADCKSUM (-3)
252 #define CONV_BADBUFLEN (-4)
253
254 #ifndef BYTE_ORDER
255 #if (BSD >= 199103)
256 # include <machine/endian.h>
257 #else
258 #ifdef linux
259 # include <endian.h>
260 #else
261 #define LITTLE_ENDIAN 1234 /* least-significant byte first (vax, pc) */
262 #define BIG_ENDIAN 4321 /* most-significant byte first (IBM, net) */
263 #define PDP_ENDIAN 3412 /* LSB first in word, MSW first in long (pdp)*/
264
265 #if defined(vax) || defined(ns32000) || defined(sun386) || defined(i386) || \
266 defined(MIPSEL) || defined(_MIPSEL) || defined(BIT_ZERO_ON_RIGHT) || \
267 defined(__alpha__) || defined(__alpha) || defined(__vax__)
268 #define BYTE_ORDER LITTLE_ENDIAN
269 #endif
270
271 #if defined(sel) || defined(pyr) || defined(mc68000) || defined(sparc) || \
272 defined(is68k) || defined(tahoe) || defined(ibm032) || defined(ibm370) || \
273 defined(MIPSEB) || defined(_MIPSEB) || defined(_IBMR2) || defined(DGUX) ||\
274 defined(apollo) || defined(__convex__) || defined(_CRAY) || \
275 defined(__hppa) || defined(__hp9000) || \
276 defined(__hp9000s300) || defined(__hp9000s700) || \
277 defined (BIT_ZERO_ON_LEFT) || defined(m68k)
278 #define BYTE_ORDER BIG_ENDIAN
279 #endif
280 #endif /* linux */
281 #endif /* BSD */
282 #endif /* BYTE_ORDER */
283
284 #if !defined(BYTE_ORDER) || \
285 (BYTE_ORDER != BIG_ENDIAN && BYTE_ORDER != LITTLE_ENDIAN && \
286 BYTE_ORDER != PDP_ENDIAN)
287 /* you must determine what the correct bit order is for
288 * your compiler - the next line is an intentional error
289 * which will force your compiles to bomb until you fix
290 * the above macros.
291 */
292 error "Undefined or invalid BYTE_ORDER";
293 #endif
294
295 /*
296 * Structure for query header. The order of the fields is machine- and
297 * compiler-dependent, depending on the byte/bit order and the layout
298 * of bit fields. We use bit fields only in int variables, as this
299 * is all ANSI requires. This requires a somewhat confusing rearrangement.
300 */
301
302 typedef struct {
303 unsigned id :16; /* query identification number */
304 #if BYTE_ORDER == BIG_ENDIAN
305 /* fields in third byte */
306 unsigned qr: 1; /* response flag */
307 unsigned opcode: 4; /* purpose of message */
308 unsigned aa: 1; /* authoritive answer */
309 unsigned tc: 1; /* truncated message */
310 unsigned rd: 1; /* recursion desired */
311 /* fields in fourth byte */
312 unsigned ra: 1; /* recursion available */
313 unsigned unused :1; /* unused bits (MBZ as of 4.9.3a3) */
314 unsigned ad: 1; /* authentic data from named */
315 unsigned cd: 1; /* checking disabled by resolver */
316 unsigned rcode :4; /* response code */
317 #endif
318 #if BYTE_ORDER == LITTLE_ENDIAN || BYTE_ORDER == PDP_ENDIAN
319 /* fields in third byte */
320 unsigned rd :1; /* recursion desired */
321 unsigned tc :1; /* truncated message */
322 unsigned aa :1; /* authoritive answer */
323 unsigned opcode :4; /* purpose of message */
324 unsigned qr :1; /* response flag */
325 /* fields in fourth byte */
326 unsigned rcode :4; /* response code */
327 unsigned cd: 1; /* checking disabled by resolver */
328 unsigned ad: 1; /* authentic data from named */
329 unsigned unused :1; /* unused bits (MBZ as of 4.9.3a3) */
330 unsigned ra :1; /* recursion available */
331 #endif
332 /* remaining bytes */
333 unsigned qdcount :16; /* number of question entries */
334 unsigned ancount :16; /* number of answer entries */
335 unsigned nscount :16; /* number of authority entries */
336 unsigned arcount :16; /* number of resource entries */
337 } HEADER;
338
339 /*
340 * Defines for handling compressed domain names
341 */
342 #define INDIR_MASK 0xc0
343
344 extern u_int16_t _getshort __P((const u_char *));
345 extern u_int32_t _getlong __P((const u_char *));
346
347 /*
348 * Inline versions of get/put short/long. Pointer is advanced.
349 *
350 * These macros demonstrate the property of C whereby it can be
351 * portable or it can be elegant but rarely both.
352 */
353 #define GETSHORT(s, cp) { \
354 register const u_char *t_cp = (const u_char *)(cp); \
355 (s) = ((const u_int16_t)t_cp[0] << 8) \
356 | ((const u_int16_t)t_cp[1]) \
357 ; \
358 (cp) += INT16SZ; \
359 }
360
361 #define GETLONG(l, cp) { \
362 register const u_char *t_cp = (const u_char *)(cp); \
363 (l) = ((const u_int32_t)t_cp[0] << 24) \
364 | ((const u_int32_t)t_cp[1] << 16) \
365 | ((const u_int32_t)t_cp[2] << 8) \
366 | ((const u_int32_t)t_cp[3]) \
367 ; \
368 (cp) += INT32SZ; \
369 }
370
371 #define PUTSHORT(s, cp) { \
372 register u_int16_t t_s = (u_int16_t)(s); \
373 register u_char *t_cp = (u_char *)(cp); \
374 *t_cp++ = (u_int32_t)t_s >> 8; \
375 *t_cp = t_s; \
376 (cp) += INT16SZ; \
377 }
378
379 #define PUTLONG(l, cp) { \
380 register u_int32_t t_l = (u_int32_t)(l); \
381 register u_char *t_cp = (u_char *)(cp); \
382 *t_cp++ = t_l >> 24; \
383 *t_cp++ = t_l >> 16; \
384 *t_cp++ = t_l >> 8; \
385 *t_cp = t_l; \
386 (cp) += INT32SZ; \
387 }
388
389 #endif /* _ARPA_NAMESER_H_ */
390