2 * Copyright (c) 1983, 1989, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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 * 4. 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.
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
31 * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
32 * Copyright (c) 1996-1999 by Internet Software Consortium.
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.
38 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
39 * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
40 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
41 * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
42 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
43 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
44 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
48 #ifndef _ARPA_NAMESER_H_
49 #define _ARPA_NAMESER_H_
51 #include <sys/param.h>
52 #include <sys/types.h>
56 * Define constants based on RFC 883, RFC 1034, RFC 1035
58 #define NS_PACKETSZ 512 /*%< default UDP packet size */
59 #define NS_MAXDNAME 1025 /*%< maximum domain name */
60 #define NS_MAXMSG 65535 /*%< maximum message size */
61 #define NS_MAXCDNAME 255 /*%< maximum compressed domain name */
62 #define NS_MAXLABEL 63 /*%< maximum length of domain label */
63 #define NS_HFIXEDSZ 12 /*%< #/bytes of fixed data in header */
64 #define NS_QFIXEDSZ 4 /*%< #/bytes of fixed data in query */
65 #define NS_RRFIXEDSZ 10 /*%< #/bytes of fixed data in r record */
66 #define NS_INT32SZ 4 /*%< #/bytes of data in a uint32_t */
67 #define NS_INT16SZ 2 /*%< #/bytes of data in a uint16_t */
68 #define NS_INT8SZ 1 /*%< #/bytes of data in a uint8_t */
69 #define NS_INADDRSZ 4 /*%< IPv4 T_A */
70 #define NS_IN6ADDRSZ 16 /*%< IPv6 T_AAAA */
71 #define NS_CMPRSFLGS 0xc0 /*%< Flag bits indicating name compression. */
72 #define NS_DEFAULTPORT 53 /*%< For both TCP and UDP. */
74 * These can be expanded with synonyms, just keep ns_parse.c:ns_parserecord()
77 typedef enum __ns_sect
{
78 ns_s_qd
= 0, /*%< Query: Question. */
79 ns_s_zn
= 0, /*%< Update: Zone. */
80 ns_s_an
= 1, /*%< Query: Answer. */
81 ns_s_pr
= 1, /*%< Update: Prerequisites. */
82 ns_s_ns
= 2, /*%< Query: Name servers. */
83 ns_s_ud
= 2, /*%< Update: Update. */
84 ns_s_ar
= 3, /*%< Query|Update: Additional records. */
89 * This is a message handle. It is caller allocated and has no dynamic data.
90 * This structure is intended to be opaque to all but ns_parse.c, thus the
91 * leading _'s on the member names. Use the accessor functions, not the _'s.
93 typedef struct __ns_msg
{
94 const unsigned char *_msg
, *_eom
;
95 uint16_t _id
, _flags
, _counts
[ns_s_max
];
96 const unsigned char *_sections
[ns_s_max
];
99 const unsigned char *_msg_ptr
;
102 /* Private data structure - do not use from outside library. */
103 struct _ns_flagdata
{ int mask
, shift
; };
104 extern const struct _ns_flagdata _ns_flagdata
[];
106 /* Accessor macros - this is part of the public interface. */
108 #define ns_msg_id(handle) ((handle)._id + 0)
109 #define ns_msg_base(handle) ((handle)._msg + 0)
110 #define ns_msg_end(handle) ((handle)._eom + 0)
111 #define ns_msg_size(handle) ((handle)._eom - (handle)._msg)
112 #define ns_msg_count(handle, section) ((handle)._counts[section] + 0)
115 * This is a parsed record. It is caller allocated and has no dynamic data.
117 typedef struct __ns_rr
{
118 char name
[NS_MAXDNAME
];
123 const unsigned char * rdata
;
126 /* Accessor macros - this is part of the public interface. */
127 #define ns_rr_name(rr) (((rr).name[0] != '\0') ? (rr).name : ".")
128 #define ns_rr_type(rr) ((ns_type)((rr).type + 0))
129 #define ns_rr_class(rr) ((ns_class)((rr).rr_class + 0))
130 #define ns_rr_ttl(rr) ((rr).ttl + 0)
131 #define ns_rr_rdlen(rr) ((rr).rdlength + 0)
132 #define ns_rr_rdata(rr) ((rr).rdata + 0)
135 * These don't have to be in the same order as in the packet flags word,
136 * and they can even overlap in some cases, but they will need to be kept
137 * in synch with ns_parse.c:ns_flagdata[].
139 typedef enum __ns_flag
{
140 ns_f_qr
, /*%< Question/Response. */
141 ns_f_opcode
, /*%< Operation code. */
142 ns_f_aa
, /*%< Authoritative Answer. */
143 ns_f_tc
, /*%< Truncation occurred. */
144 ns_f_rd
, /*%< Recursion Desired. */
145 ns_f_ra
, /*%< Recursion Available. */
147 ns_f_ad
, /*%< Authentic Data (DNSSEC). */
148 ns_f_cd
, /*%< Checking Disabled (DNSSEC). */
149 ns_f_rcode
, /*%< Response code. */
154 * Currently defined opcodes.
156 typedef enum __ns_opcode
{
157 ns_o_query
= 0, /*%< Standard query. */
158 ns_o_iquery
= 1, /*%< Inverse query (deprecated/unsupported). */
159 ns_o_status
= 2, /*%< Name server status query (unsupported). */
160 /* Opcode 3 is undefined/reserved. */
161 ns_o_notify
= 4, /*%< Zone change notification. */
162 ns_o_update
= 5, /*%< Zone update message. */
167 * Currently defined response codes.
169 typedef enum __ns_rcode
{
170 ns_r_noerror
= 0, /*%< No error occurred. */
171 ns_r_formerr
= 1, /*%< Format error. */
172 ns_r_servfail
= 2, /*%< Server failure. */
173 ns_r_nxdomain
= 3, /*%< Name error. */
174 ns_r_notimpl
= 4, /*%< Unimplemented. */
175 ns_r_refused
= 5, /*%< Operation refused. */
176 /* these are for BIND_UPDATE */
177 ns_r_yxdomain
= 6, /*%< Name exists */
178 ns_r_yxrrset
= 7, /*%< RRset exists */
179 ns_r_nxrrset
= 8, /*%< RRset does not exist */
180 ns_r_notauth
= 9, /*%< Not authoritative for zone */
181 ns_r_notzone
= 10, /*%< Zone of record different from zone section */
183 /* The following are EDNS extended rcodes */
185 /* The following are TSIG errors */
192 typedef enum __ns_update_operation
{
196 } ns_update_operation
;
199 * This structure is used for TSIG authenticated messages
202 char name
[NS_MAXDNAME
], alg
[NS_MAXDNAME
];
206 typedef struct ns_tsig_key ns_tsig_key
;
209 * This structure is used for TSIG authenticated TCP messages
211 struct ns_tcp_tsig_state
{
215 unsigned char sig
[NS_PACKETSZ
];
218 typedef struct ns_tcp_tsig_state ns_tcp_tsig_state
;
220 #define NS_TSIG_FUDGE 300
221 #define NS_TSIG_TCP_COUNT 100
222 #define NS_TSIG_ALG_HMAC_MD5 "HMAC-MD5.SIG-ALG.REG.INT"
224 #define NS_TSIG_ERROR_NO_TSIG -10
225 #define NS_TSIG_ERROR_NO_SPACE -11
226 #define NS_TSIG_ERROR_FORMERR -12
229 * Currently defined type values for resources and queries.
231 typedef enum __ns_type
{
232 ns_t_invalid
= 0, /*%< Cookie. */
233 ns_t_a
= 1, /*%< Host address. */
234 ns_t_ns
= 2, /*%< Authoritative server. */
235 ns_t_md
= 3, /*%< Mail destination. */
236 ns_t_mf
= 4, /*%< Mail forwarder. */
237 ns_t_cname
= 5, /*%< Canonical name. */
238 ns_t_soa
= 6, /*%< Start of authority zone. */
239 ns_t_mb
= 7, /*%< Mailbox domain name. */
240 ns_t_mg
= 8, /*%< Mail group member. */
241 ns_t_mr
= 9, /*%< Mail rename name. */
242 ns_t_null
= 10, /*%< Null resource record. */
243 ns_t_wks
= 11, /*%< Well known service. */
244 ns_t_ptr
= 12, /*%< Domain name pointer. */
245 ns_t_hinfo
= 13, /*%< Host information. */
246 ns_t_minfo
= 14, /*%< Mailbox information. */
247 ns_t_mx
= 15, /*%< Mail routing information. */
248 ns_t_txt
= 16, /*%< Text strings. */
249 ns_t_rp
= 17, /*%< Responsible person. */
250 ns_t_afsdb
= 18, /*%< AFS cell database. */
251 ns_t_x25
= 19, /*%< X_25 calling address. */
252 ns_t_isdn
= 20, /*%< ISDN calling address. */
253 ns_t_rt
= 21, /*%< Router. */
254 ns_t_nsap
= 22, /*%< NSAP address. */
255 ns_t_nsap_ptr
= 23, /*%< Reverse NSAP lookup (deprecated). */
256 ns_t_sig
= 24, /*%< Security signature. */
257 ns_t_key
= 25, /*%< Security key. */
258 ns_t_px
= 26, /*%< X.400 mail mapping. */
259 ns_t_gpos
= 27, /*%< Geographical position (withdrawn). */
260 ns_t_aaaa
= 28, /*%< Ip6 Address. */
261 ns_t_loc
= 29, /*%< Location Information. */
262 ns_t_nxt
= 30, /*%< Next domain (security). */
263 ns_t_eid
= 31, /*%< Endpoint identifier. */
264 ns_t_nimloc
= 32, /*%< Nimrod Locator. */
265 ns_t_srv
= 33, /*%< Server Selection. */
266 ns_t_atma
= 34, /*%< ATM Address */
267 ns_t_naptr
= 35, /*%< Naming Authority PoinTeR */
268 ns_t_kx
= 36, /*%< Key Exchange */
269 ns_t_cert
= 37, /*%< Certification record */
270 ns_t_a6
= 38, /*%< IPv6 address (deprecated, use ns_t_aaaa) */
271 ns_t_dname
= 39, /*%< Non-terminal DNAME (for IPv6) */
272 ns_t_sink
= 40, /*%< Kitchen sink (experimentatl) */
273 ns_t_opt
= 41, /*%< EDNS0 option (meta-RR) */
274 ns_t_apl
= 42, /*%< Address prefix list (RFC3123) */
275 ns_t_tkey
= 249, /*%< Transaction key */
276 ns_t_tsig
= 250, /*%< Transaction signature. */
277 ns_t_ixfr
= 251, /*%< Incremental zone transfer. */
278 ns_t_axfr
= 252, /*%< Transfer zone of authority. */
279 ns_t_mailb
= 253, /*%< Transfer mailbox records. */
280 ns_t_maila
= 254, /*%< Transfer mail agent records. */
281 ns_t_any
= 255, /*%< Wildcard match. */
282 ns_t_zxfr
= 256, /*%< BIND-specific, nonstandard. */
287 * Values for class field
289 typedef enum __ns_class
{
290 ns_c_invalid
= 0, /*%< Cookie. */
291 ns_c_in
= 1, /*%< Internet. */
292 ns_c_2
= 2, /*%< unallocated/unsupported. */
293 ns_c_chaos
= 3, /*%< MIT Chaos-net. */
294 ns_c_hs
= 4, /*%< MIT Hesiod. */
295 /* Query class values which do not appear in resource records */
296 ns_c_none
= 254, /*%< for prereq. sections in update requests */
297 ns_c_any
= 255, /*%< Wildcard match. */
301 /* Certificate type values in CERT resource records. */
302 typedef enum __ns_cert_types
{
303 cert_t_pkix
= 1, /*%< PKIX (X.509v3) */
304 cert_t_spki
= 2, /*%< SPKI */
305 cert_t_pgp
= 3, /*%< PGP */
306 cert_t_url
= 253, /*%< URL private type */
307 cert_t_oid
= 254 /*%< OID private type */
311 * EDNS0 extended flags and option codes, host order.
313 #define NS_OPT_DNSSEC_OK 0x8000U
314 #define NS_OPT_NSID 3
317 * Inline versions of get/put short/long. Pointer is advanced.
319 #define NS_GET16(s, cp) do { \
320 const unsigned char *t_cp = (const unsigned char *)(cp); \
321 (s) = ((uint16_t)t_cp[0] << 8) \
322 | ((uint16_t)t_cp[1]) \
324 (cp) += NS_INT16SZ; \
327 #define NS_GET32(l, cp) do { \
328 const unsigned char *t_cp = (const unsigned char *)(cp); \
329 (l) = ((uint32_t)t_cp[0] << 24) \
330 | ((uint32_t)t_cp[1] << 16) \
331 | ((uint32_t)t_cp[2] << 8) \
332 | ((uint32_t)t_cp[3]) \
334 (cp) += NS_INT32SZ; \
337 #define NS_PUT16(s, cp) do { \
338 uint16_t t_s = (uint16_t)(s); \
339 unsigned char *t_cp = (unsigned char *)(cp); \
340 *t_cp++ = t_s >> 8; \
342 (cp) += NS_INT16SZ; \
345 #define NS_PUT32(l, cp) do { \
346 uint32_t t_l = (uint32_t)(l); \
347 unsigned char *t_cp = (unsigned char *)(cp); \
348 *t_cp++ = t_l >> 24; \
349 *t_cp++ = t_l >> 16; \
350 *t_cp++ = t_l >> 8; \
352 (cp) += NS_INT32SZ; \
356 int ns_msg_getflag (ns_msg
, int) __THROW
;
357 unsigned int ns_get16 (const unsigned char *) __THROW
;
358 unsigned long ns_get32 (const unsigned char *) __THROW
;
359 void ns_put16 (unsigned int, unsigned char *) __THROW
;
360 void ns_put32 (unsigned long, unsigned char *) __THROW
;
361 int ns_initparse (const unsigned char *, int, ns_msg
*) __THROW
;
362 int ns_skiprr (const unsigned char *, const unsigned char *,
363 ns_sect
, int) __THROW
;
364 int ns_parserr (ns_msg
*, ns_sect
, int, ns_rr
*) __THROW
;
365 int ns_sprintrr (const ns_msg
*, const ns_rr
*,
366 const char *, const char *, char *, size_t)
368 int ns_sprintrrf (const unsigned char *, size_t, const char *,
369 ns_class
, ns_type
, unsigned long,
370 const unsigned char *, size_t, const char *,
371 const char *, char *, size_t) __THROW
;
372 int ns_format_ttl (unsigned long, char *, size_t) __THROW
;
373 int ns_parse_ttl (const char *, unsigned long *) __THROW
;
374 uint32_t ns_datetosecs (const char *, int *) __THROW
;
375 int ns_name_ntol (const unsigned char *, unsigned char *, size_t)
377 int ns_name_ntop (const unsigned char *, char *, size_t) __THROW
;
378 int ns_name_pton (const char *, unsigned char *, size_t) __THROW
;
379 int ns_name_unpack (const unsigned char *, const unsigned char *,
380 const unsigned char *, unsigned char *, size_t)
382 int ns_name_pack (const unsigned char *, unsigned char *, int,
383 const unsigned char **, const unsigned char **)
385 int ns_name_uncompress (const unsigned char *,
386 const unsigned char *,
387 const unsigned char *,
388 char *, size_t) __THROW
;
389 int ns_name_compress (const char *, unsigned char *, size_t,
390 const unsigned char **,
391 const unsigned char **) __THROW
;
392 int ns_name_skip (const unsigned char **, const unsigned char *)
394 void ns_name_rollback (const unsigned char *,
395 const unsigned char **,
396 const unsigned char **) __THROW
;
397 int ns_samedomain (const char *, const char *) __THROW
;
398 int ns_subdomain (const char *, const char *) __THROW
;
399 int ns_makecanon (const char *, char *, size_t) __THROW
;
400 int ns_samename (const char *, const char *) __THROW
;
403 #include <arpa/nameser_compat.h>
405 #endif /* !_ARPA_NAMESER_H_ */