nameser.h 15 KB

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