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