Home | History | Annotate | Line # | Download | only in dist
nameser.h revision 1.2.14.1
      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. Neither the name of the University nor the names of its contributors
     14  *    may be used to endorse or promote products derived from this software
     15  *    without specific prior written permission.
     16  *
     17  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     27  * SUCH DAMAGE.
     28  *
     29  *      @(#)nameser.h	8.2 (Berkeley) 2/16/94
     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  * --Copyright--
     50  */
     51 
     52 #ifndef _NAMESER_H_
     53 #define	_NAMESER_H_
     54 
     55 #include <sys/types.h>
     56 
     57 /*
     58  * Define constants based on rfc883
     59  */
     60 #define PACKETSZ	512		/* maximum packet size */
     61 #define MAXDNAME	256		/* maximum domain name */
     62 #define MAXCDNAME	255		/* maximum compressed domain name */
     63 #define MAXLABEL	63		/* maximum length of domain label */
     64 	/* Number of bytes of fixed size data in query structure */
     65 #define QFIXEDSZ	4
     66 	/* number of bytes of fixed size data in resource record */
     67 #define RRFIXEDSZ	10
     68 
     69 /*
     70  * Currently defined opcodes
     71  */
     72 #define QUERY		0x0		/* standard query */
     73 #define IQUERY		0x1		/* inverse query */
     74 #define STATUS		0x2		/* nameserver status query */
     75 #if 0
     76 #define xxx		0x3		/* 0x3 reserved */
     77 #endif
     78 	/* non standard - supports ALLOW_UPDATES stuff from Mike Schwartz */
     79 #define UPDATEA		0x9		/* add resource record */
     80 #define UPDATED		0xa		/* delete a specific resource record */
     81 #define UPDATEDA	0xb		/* delete all named resource record */
     82 #define UPDATEM		0xc		/* modify a specific resource record */
     83 #define UPDATEMA	0xd		/* modify all named resource record */
     84 
     85 #define ZONEINIT	0xe		/* initial zone transfer */
     86 #define ZONEREF		0xf		/* incremental zone referesh */
     87 
     88 /*
     89  * Undefine various #defines from various System V-flavored OSes (Solaris,
     90  * SINIX, HP-UX) so the compiler doesn't whine that we redefine them.
     91  */
     92 #ifdef T_NULL
     93 #undef T_NULL
     94 #endif
     95 #ifdef T_OPT
     96 #undef T_OPT
     97 #endif
     98 #ifdef T_UNSPEC
     99 #undef T_UNSPEC
    100 #endif
    101 #ifdef NOERROR
    102 #undef NOERROR
    103 #endif
    104 
    105 /*
    106  * Currently defined response codes
    107  */
    108 #define NOERROR		0		/* no error */
    109 #define FORMERR		1		/* format error */
    110 #define SERVFAIL	2		/* server failure */
    111 #define NXDOMAIN	3		/* non existent domain */
    112 #define NOTIMP		4		/* not implemented */
    113 #define REFUSED		5		/* query refused */
    114 	/* non standard */
    115 #define NOCHANGE	0xf		/* update failed to change db */
    116 
    117 /*
    118  * Type values for resources and queries
    119  */
    120 #define T_A		1		/* host address */
    121 #define T_NS		2		/* authoritative server */
    122 #define T_MD		3		/* mail destination */
    123 #define T_MF		4		/* mail forwarder */
    124 #define T_CNAME		5		/* connonical name */
    125 #define T_SOA		6		/* start of authority zone */
    126 #define T_MB		7		/* mailbox domain name */
    127 #define T_MG		8		/* mail group member */
    128 #define T_MR		9		/* mail rename name */
    129 #define T_NULL		10		/* null resource record */
    130 #define T_WKS		11		/* well known service */
    131 #define T_PTR		12		/* domain name pointer */
    132 #define T_HINFO		13		/* host information */
    133 #define T_MINFO		14		/* mailbox information */
    134 #define T_MX		15		/* mail routing information */
    135 #define T_TXT		16		/* text strings */
    136 #define	T_RP		17		/* responsible person */
    137 #define	T_AFSDB		18		/* AFS cell database */
    138 #define T_X25		19		/* X_25 calling address */
    139 #define T_ISDN		20		/* ISDN calling address */
    140 #define T_RT		21		/* router */
    141 #define	T_NSAP		22		/* NSAP address */
    142 #define	T_NSAP_PTR	23		/* reverse lookup for NSAP */
    143 #define T_SIG		24		/* security signature */
    144 #define T_KEY		25		/* security key */
    145 #define T_PX		26		/* X.400 mail mapping */
    146 #define T_GPOS		27		/* geographical position (withdrawn) */
    147 #define T_AAAA		28		/* IP6 Address */
    148 #define T_LOC		29		/* Location Information */
    149 #define T_NXT		30		/* Next Valid Name in Zone */
    150 #define T_EID		31		/* Endpoint identifier */
    151 #define T_NIMLOC	32		/* Nimrod locator */
    152 #define T_SRV		33		/* Server selection */
    153 #define T_ATMA		34		/* ATM Address */
    154 #define T_NAPTR		35		/* Naming Authority PoinTeR */
    155 #define T_KX		36		/* Key Exchanger */
    156 #define T_CERT		37		/* Certificates in the DNS */
    157 #define T_A6		38		/* IP6 address */
    158 #define T_DNAME		39		/* non-terminal redirection */
    159 #define T_SINK		40		/* unknown */
    160 #define T_OPT		41		/* EDNS0 option (meta-RR) */
    161 #define T_APL		42		/* lists of address prefixes */
    162 #define T_DS		43		/* Delegation Signer */
    163 #define T_SSHFP		44		/* SSH Fingerprint */
    164 #define T_IPSECKEY	45		/* IPsec keying material */
    165 #define T_RRSIG		46		/* new security signature */
    166 #define T_NSEC		47		/* provable insecure information */
    167 #define T_DNSKEY	48		/* new security key */
    168 	/* non standard */
    169 #define T_SPF		99		/* sender policy framework */
    170 #define T_UINFO		100		/* user (finger) information */
    171 #define T_UID		101		/* user ID */
    172 #define T_GID		102		/* group ID */
    173 #define T_UNSPEC	103		/* Unspecified format (binary data) */
    174 #define T_UNSPECA	104		/* "unspecified ascii". Ugly MIT hack */
    175 	/* Query type values which do not appear in resource records */
    176 #define T_TKEY		249		/* Transaction Key [RFC2930] */
    177 #define T_TSIG		250		/* Transaction Signature [RFC2845] */
    178 #define T_IXFR		251		/* incremental transfer [RFC1995] */
    179 #define T_AXFR		252		/* transfer zone of authority */
    180 #define T_MAILB		253		/* transfer mailbox records */
    181 #define T_MAILA		254		/* transfer mail agent records */
    182 #define T_ANY		255		/* wildcard match */
    183 
    184 /*
    185  * Values for class field
    186  */
    187 
    188 #define C_IN		1		/* the arpa internet */
    189 #define C_CHAOS		3		/* for chaos net (MIT) */
    190 #define C_HS		4		/* for Hesiod name server (MIT) (XXX) */
    191 	/* Query class values which do not appear in resource records */
    192 #define C_ANY		255		/* wildcard match */
    193 #define C_QU		0x8000		/* mDNS QU flag in queries */
    194 #define C_CACHE_FLUSH	0x8000		/* mDNS cache flush flag in replies */
    195 
    196 /*
    197  * Status return codes for T_UNSPEC conversion routines
    198  */
    199 #define CONV_SUCCESS 0
    200 #define CONV_OVERFLOW -1
    201 #define CONV_BADFMT -2
    202 #define CONV_BADCKSUM -3
    203 #define CONV_BADBUFLEN -4
    204 
    205 /*
    206  * Structure for query header.
    207  */
    208 typedef struct {
    209 	uint16_t id;		/* query identification number */
    210 	uint8_t  flags1;	/* first byte of flags */
    211 	uint8_t  flags2;	/* second byte of flags */
    212 	uint16_t qdcount;	/* number of question entries */
    213 	uint16_t ancount;	/* number of answer entries */
    214 	uint16_t nscount;	/* number of authority entries */
    215 	uint16_t arcount;	/* number of resource entries */
    216 } HEADER;
    217 
    218 /*
    219  * Macros for subfields of flag fields.
    220  */
    221 #define DNS_QR(np)	((np)->flags1 & 0x80)		/* response flag */
    222 #define DNS_OPCODE(np)	((((np)->flags1) >> 3) & 0xF)	/* purpose of message */
    223 #define DNS_AA(np)	((np)->flags1 & 0x04)		/* authoritative answer */
    224 #define DNS_TC(np)	((np)->flags1 & 0x02)		/* truncated message */
    225 #define DNS_RD(np)	((np)->flags1 & 0x01)		/* recursion desired */
    226 
    227 #define DNS_RA(np)	((np)->flags2 & 0x80)	/* recursion available */
    228 #define DNS_AD(np)	((np)->flags2 & 0x20)	/* authentic data from named */
    229 #define DNS_CD(np)	((np)->flags2 & 0x10)	/* checking disabled by resolver */
    230 #define DNS_RCODE(np)	((np)->flags2 & 0xF)	/* response code */
    231 
    232 /*
    233  * Defines for handling compressed domain names, EDNS0 labels, etc.
    234  */
    235 #define INDIR_MASK	0xc0	/* 11.... */
    236 #define EDNS0_MASK	0x40	/* 01.... */
    237 #  define EDNS0_ELT_BITLABEL 0x01
    238 
    239 /*
    240  * Structure for passing resource records around.
    241  */
    242 struct rrec {
    243 	int16_t	r_zone;			/* zone number */
    244 	int16_t	r_class;		/* class number */
    245 	int16_t	r_type;			/* type number */
    246 	uint32_t	r_ttl;			/* time to live */
    247 	int	r_size;			/* size of data area */
    248 	char	*r_data;		/* pointer to data */
    249 };
    250 
    251 /*
    252  * Inline versions of get/put short/long.  Pointer is advanced.
    253  * We also assume that a "uint16_t" holds 2 "chars"
    254  * and that a "uint32_t" holds 4 "chars".
    255  *
    256  * These macros demonstrate the property of C whereby it can be
    257  * portable or it can be elegant but never both.
    258  */
    259 #define GETSHORT(s, cp) { \
    260 	register u_char *t_cp = (u_char *)(cp); \
    261 	(s) = ((uint16_t)t_cp[0] << 8) | (uint16_t)t_cp[1]; \
    262 	(cp) += 2; \
    263 }
    264 
    265 #define GETLONG(l, cp) { \
    266 	register u_char *t_cp = (u_char *)(cp); \
    267 	(l) = (((uint32_t)t_cp[0]) << 24) \
    268 	    | (((uint32_t)t_cp[1]) << 16) \
    269 	    | (((uint32_t)t_cp[2]) << 8) \
    270 	    | (((uint32_t)t_cp[3])); \
    271 	(cp) += 4; \
    272 }
    273 
    274 #define PUTSHORT(s, cp) { \
    275 	register uint16_t t_s = (uint16_t)(s); \
    276 	register u_char *t_cp = (u_char *)(cp); \
    277 	*t_cp++ = t_s >> 8; \
    278 	*t_cp   = t_s; \
    279 	(cp) += 2; \
    280 }
    281 
    282 /*
    283  * Warning: PUTLONG --no-longer-- destroys its first argument.  if you
    284  * were depending on this "feature", you will lose.
    285  */
    286 #define PUTLONG(l, cp) { \
    287 	register uint32_t t_l = (uint32_t)(l); \
    288 	register u_char *t_cp = (u_char *)(cp); \
    289 	*t_cp++ = t_l >> 24; \
    290 	*t_cp++ = t_l >> 16; \
    291 	*t_cp++ = t_l >> 8; \
    292 	*t_cp   = t_l; \
    293 	(cp) += 4; \
    294 }
    295 
    296 #endif /* !_NAMESER_H_ */
    297