Source code pulled from OpenBSD for OpenNTPD. The place to contribute to this code is via the OpenBSD CVS tree.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

396 lines
15 KiB

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