xref: /titanic_44/usr/src/head/arpa/nameser.h (revision 4a6ec905b96eb96a398c346f59e034a90ce8ad37)
1 /*
2  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 /*
7  * Copyright (c) 1983, 1989, 1993
8  *    The Regents of the University of California.  All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  * 	This product includes software developed by the University of
21  * 	California, Berkeley and its contributors.
22  * 4. Neither the name of the University nor the names of its contributors
23  *    may be used to endorse or promote products derived from this software
24  *    without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36  * SUCH DAMAGE.
37  */
38 
39 /*
40  * Copyright (c) 1996-1999 by Internet Software Consortium.
41  *
42  * Permission to use, copy, modify, and distribute this software for any
43  * purpose with or without fee is hereby granted, provided that the above
44  * copyright notice and this permission notice appear in all copies.
45  *
46  * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
47  * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
48  * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
49  * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
50  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
51  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
52  * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
53  * SOFTWARE.
54  */
55 
56 /*
57  *	$Id: nameser.h,v 8.50 2003/05/27 23:36:52 marka Exp $
58  */
59 
60 #ifndef _ARPA_NAMESER_H
61 #define	_ARPA_NAMESER_H
62 
63 #pragma ident	"%Z%%M%	%I%	%E% SMI"
64 
65 #include <sys/isa_defs.h>
66 
67 
68 #ifdef	__cplusplus
69 extern "C" {
70 #endif
71 
72 #define	BIND_4_COMPAT
73 
74 /*
75  * Revision information.  This is the release date in YYYYMMDD format.
76  * It can change every day so the right thing to do with it is use it
77  * in preprocessor commands such as "#if (__NAMESER > 19931104)".  Do not
78  * compare for equality; rather, use it to determine whether your libresolv
79  * contains a new enough lib/nameser/ to support the feature you need.
80  */
81 
82 #define	__NAMESER	19991006	/* New interface version stamp. */
83 
84 /*
85  * Define constants based on RFC 883, RFC 1034, RFC 1035
86  */
87 #define	NS_PACKETSZ	512	/* default UDP packet size */
88 #define	NS_MAXDNAME	1025	/* maximum domain name */
89 #define	NS_MAXMSG	65535	/* maximum message size */
90 #define	NS_MAXCDNAME	255	/* maximum compressed domain name */
91 #define	NS_MAXLABEL	63	/* maximum length of domain label */
92 #define	NS_HFIXEDSZ	12	/* #/bytes of fixed data in header */
93 #define	NS_QFIXEDSZ	4	/* #/bytes of fixed data in query */
94 #define	NS_RRFIXEDSZ	10	/* #/bytes of fixed data in r record */
95 #define	NS_INT32SZ	4	/* #/bytes of data in a u_int32_t */
96 #define	NS_INT16SZ	2	/* #/bytes of data in a u_int16_t */
97 #define	NS_INT8SZ	1	/* #/bytes of data in a u_int8_t */
98 #define	NS_INADDRSZ	4	/* IPv4 T_A */
99 #define	NS_IN6ADDRSZ	16	/* IPv6 T_AAAA */
100 #define	NS_CMPRSFLGS	0xc0	/* Flag bits indicating name compression. */
101 #define	NS_DEFAULTPORT	53	/* For both TCP and UDP. */
102 
103 /*
104  * These can be expanded with synonyms, just keep ns_parse.c:ns_parserecord()
105  * in synch with it.
106  */
107 typedef enum __ns_sect {
108 	ns_s_qd = 0,		/* Query: Question. */
109 	ns_s_zn = 0,		/* Update: Zone. */
110 	ns_s_an = 1,		/* Query: Answer. */
111 	ns_s_pr = 1,		/* Update: Prerequisites. */
112 	ns_s_ns = 2,		/* Query: Name servers. */
113 	ns_s_ud = 2,		/* Update: Update. */
114 	ns_s_ar = 3,		/* Query|Update: Additional records. */
115 	ns_s_max = 4
116 } ns_sect;
117 
118 /*
119  * This is a message handle.  It is caller allocated and has no dynamic data.
120  * This structure is intended to be opaque to all but ns_parse.c, thus the
121  * leading _'s on the member names.  Use the accessor functions, not the _'s.
122  */
123 typedef struct __ns_msg {
124 	const uchar_t	*_msg, *_eom;
125 	uint16_t	_id, _flags, _counts[ns_s_max];
126 	const uchar_t	*_sections[ns_s_max];
127 	ns_sect		_sect;
128 	int		_rrnum;
129 	const uchar_t	*_msg_ptr;
130 } ns_msg;
131 
132 /* Private data structure - do not use from outside library. */
133 struct _ns_flagdata {  int mask, shift;  };
134 extern struct _ns_flagdata _ns_flagdata[];
135 
136 /* Accessor macros - this is part of the public interface. */
137 #define	ns_msg_id(handle) ((handle)._id + 0)
138 #define	ns_msg_base(handle) ((handle)._msg + 0)
139 #define	ns_msg_end(handle) ((handle)._eom + 0)
140 #define	ns_msg_size(handle) ((handle)._eom - (handle)._msg)
141 #define	ns_msg_count(handle, section) ((handle)._counts[section] + 0)
142 
143 /*
144  * This is a parsed record.  It is caller allocated and has no dynamic data.
145  */
146 typedef	struct __ns_rr {
147 	char		name[NS_MAXDNAME];
148 	uint16_t	type;
149 	uint16_t	rr_class;
150 	uint32_t	ttl;
151 	uint16_t	rdlength;
152 	const uchar_t	*rdata;
153 } ns_rr;
154 
155 /* Accessor macros - this is part of the public interface. */
156 #define	ns_rr_name(rr)	(((rr).name[0] != '\0') ? (rr).name : ".")
157 #define	ns_rr_type(rr)	((ns_type)((rr).type + 0))
158 #define	ns_rr_class(rr)	((ns_class)((rr).rr_class + 0))
159 #define	ns_rr_ttl(rr)	((rr).ttl + 0)
160 #define	ns_rr_rdlen(rr)	((rr).rdlength + 0)
161 #define	ns_rr_rdata(rr)	((rr).rdata + 0)
162 
163 /*
164  * These don't have to be in the same order as in the packet flags word,
165  * and they can even overlap in some cases, but they will need to be kept
166  * in synch with ns_parse.c:ns_flagdata[].
167  */
168 typedef enum __ns_flag {
169 	ns_f_qr,		/* Question/Response. */
170 	ns_f_opcode,		/* Operation code. */
171 	ns_f_aa,		/* Authoritative Answer. */
172 	ns_f_tc,		/* Truncation occurred. */
173 	ns_f_rd,		/* Recursion Desired. */
174 	ns_f_ra,		/* Recursion Available. */
175 	ns_f_z,			/* MBZ. */
176 	ns_f_ad,		/* Authentic Data (DNSSEC). */
177 	ns_f_cd,		/* Checking Disabled (DNSSEC). */
178 	ns_f_rcode,		/* Response code. */
179 	ns_f_max
180 } ns_flag;
181 
182 /*
183  * Currently defined opcodes.
184  */
185 typedef enum __ns_opcode {
186 	ns_o_query = 0,		/* Standard query. */
187 	ns_o_iquery = 1,	/* Inverse query (deprecated/unsupported). */
188 	ns_o_status = 2,	/* Name server status query (unsupported). */
189 				/* Opcode 3 is undefined/reserved. */
190 	ns_o_notify = 4,	/* Zone change notification. */
191 	ns_o_update = 5,	/* Zone update message. */
192 	ns_o_max = 6
193 } ns_opcode;
194 
195 /*
196  * Currently defined response codes.
197  */
198 typedef	enum __ns_rcode {
199 	ns_r_noerror = 0,	/* No error occurred. */
200 	ns_r_formerr = 1,	/* Format error. */
201 	ns_r_servfail = 2,	/* Server failure. */
202 	ns_r_nxdomain = 3,	/* Name error. */
203 	ns_r_notimpl = 4,	/* Unimplemented. */
204 	ns_r_refused = 5,	/* Operation refused. */
205 	/* these are for BIND_UPDATE */
206 	ns_r_yxdomain = 6,	/* Name exists */
207 	ns_r_yxrrset = 7,	/* RRset exists */
208 	ns_r_nxrrset = 8,	/* RRset does not exist */
209 	ns_r_notauth = 9,	/* Not authoritative for zone */
210 	ns_r_notzone = 10,	/* Zone of record different from zone section */
211 	ns_r_max = 11,
212 	/* The following are EDNS extended rcodes */
213 	ns_r_badvers = 16,
214 	/* The following are TSIG errors */
215 	ns_r_badsig = 16,
216 	ns_r_badkey = 17,
217 	ns_r_badtime = 18
218 } ns_rcode;
219 
220 /* BIND_UPDATE */
221 typedef enum __ns_update_operation {
222 	ns_uop_delete = 0,
223 	ns_uop_add = 1,
224 	ns_uop_max = 2
225 } ns_update_operation;
226 
227 /*
228  * This RR-like structure is particular to UPDATE.
229  */
230 struct ns_updrec {
231 	struct ns_updrec *r_prev;	/* prev record */
232 	struct ns_updrec *r_next;	/* next record */
233 	uint8_t	r_section;	/* ZONE/PREREQUISITE/UPDATE */
234 	char		*r_dname;	/* owner of the RR */
235 	uint16_t	r_class;	/* class number */
236 	uint16_t	r_type;		/* type number */
237 	uint32_t	r_ttl;		/* time to live */
238 	uchar_t		*r_data;	/* rdata fields as text string */
239 	uint16_t	r_size;		/* size of r_data field */
240 	int		r_opcode;	/* type of operation */
241 	/* following fields for private use by the resolver/server routines */
242 	struct ns_updrec *r_grpnext;	/* next record when grouped */
243 	struct databuf *r_dp;		/* databuf to process */
244 	struct databuf *r_deldp;	/* databuf's deleted/overwritten */
245 	uint16_t	r_zone;		/* zone number on server */
246 };
247 typedef struct ns_updrec ns_updrec;
248 
249 /*
250  * This structure is used for TSIG authenticated messages
251  */
252 struct ns_tsig_key {
253 		char name[NS_MAXDNAME], alg[NS_MAXDNAME];
254 		unsigned char *data;
255 		int len;
256 };
257 typedef struct ns_tsig_key ns_tsig_key;
258 
259 /*
260  * This structure is used for TSIG authenticated TCP messages
261  */
262 struct ns_tcp_tsig_state {
263 	int counter;
264 	struct dst_key *key;
265 	void *ctx;
266 	unsigned char sig[NS_PACKETSZ];
267 	int siglen;
268 };
269 typedef struct ns_tcp_tsig_state ns_tcp_tsig_state;
270 
271 #define	NS_TSIG_FUDGE 300
272 #define	NS_TSIG_TCP_COUNT 100
273 #define	NS_TSIG_ALG_HMAC_MD5 "HMAC-MD5.SIG-ALG.REG.INT"
274 
275 #define	NS_TSIG_ERROR_NO_TSIG -10
276 #define	NS_TSIG_ERROR_NO_SPACE -11
277 #define	NS_TSIG_ERROR_FORMERR -12
278 
279 /*
280  * Currently defined type values for resources and queries.
281  */
282 typedef enum __ns_type {
283 	ns_t_invalid = 0,	/* Cookie. */
284 	ns_t_a = 1,		/* Host address. */
285 	ns_t_ns = 2,		/* Authoritative server. */
286 	ns_t_md = 3,		/* Mail destination. */
287 	ns_t_mf = 4,		/* Mail forwarder. */
288 	ns_t_cname = 5,		/* Canonical name. */
289 	ns_t_soa = 6,		/* Start of authority zone. */
290 	ns_t_mb = 7,		/* Mailbox domain name. */
291 	ns_t_mg = 8,		/* Mail group member. */
292 	ns_t_mr = 9,		/* Mail rename name. */
293 	ns_t_null = 10,		/* Null resource record. */
294 	ns_t_wks = 11,		/* Well known service. */
295 	ns_t_ptr = 12,		/* Domain name pointer. */
296 	ns_t_hinfo = 13,	/* Host information. */
297 	ns_t_minfo = 14,	/* Mailbox information. */
298 	ns_t_mx = 15,		/* Mail routing information. */
299 	ns_t_txt = 16,		/* Text strings. */
300 	ns_t_rp = 17,		/* Responsible person. */
301 	ns_t_afsdb = 18,	/* AFS cell database. */
302 	ns_t_x25 = 19,		/* X_25 calling address. */
303 	ns_t_isdn = 20,		/* ISDN calling address. */
304 	ns_t_rt = 21,		/* Router. */
305 	ns_t_nsap = 22,		/* NSAP address. */
306 	ns_t_nsap_ptr = 23,	/* Reverse NSAP lookup (deprecated). */
307 	ns_t_sig = 24,		/* Security signature. */
308 	ns_t_key = 25,		/* Security key. */
309 	ns_t_px = 26,		/* X.400 mail mapping. */
310 	ns_t_gpos = 27,		/* Geographical position (withdrawn). */
311 	ns_t_aaaa = 28,		/* IPv6 Address. */
312 	ns_t_loc = 29,		/* Location Information. */
313 	ns_t_nxt = 30,		/* Next domain (security). */
314 	ns_t_eid = 31,		/* Endpoint identifier. */
315 	ns_t_nimloc = 32,	/* Nimrod Locator. */
316 	ns_t_srv = 33,		/* Server Selection. */
317 	ns_t_atma = 34,		/* ATM Address */
318 	ns_t_naptr = 35,	/* Naming Authority PoinTeR */
319 	ns_t_kx = 36,		/* Key Exchange */
320 	ns_t_cert = 37,		/* Certification record */
321 	ns_t_a6 = 38,		/* IPv6 address (deprecated) */
322 	ns_t_dname = 39,	/* Non-terminal DNAME (for IPv6) */
323 	ns_t_sink = 40,		/* Kitchen sink (experimentatl) */
324 	ns_t_opt = 41,		/* EDNS0 option (meta-RR) */
325 	ns_t_apl = 42,		/* Address prefix list (RFC 3123) */
326 	ns_t_tkey = 249,	/* Transaction key */
327 	ns_t_tsig = 250,	/* Transaction signature. */
328 	ns_t_ixfr = 251,	/* Incremental zone transfer. */
329 	ns_t_axfr = 252,	/* Transfer zone of authority. */
330 	ns_t_mailb = 253,	/* Transfer mailbox records. */
331 	ns_t_maila = 254,	/* Transfer mail agent records. */
332 	ns_t_any = 255,		/* Wildcard match. */
333 	ns_t_zxfr = 256,	/* BIND-specific, nonstandard. */
334 	ns_t_max = 65536
335 } ns_type;
336 
337 /* Exclusively a QTYPE? (not also an RTYPE) */
338 #define	ns_t_qt_p(t) (ns_t_xfr_p(t) || (t) == ns_t_any || \
339 		(t) == ns_t_mailb || (t) == ns_t_maila)
340 /* Some kind of meta-RR? (not a QTYPE, but also not an RTYPE) */
341 #define	ns_t_mrr_p(t) ((t) == ns_t_tsig || (t) == ns_t_opt)
342 /* Exclusively an RTYPE? (not also a QTYPE or a meta-RR) */
343 #define	ns_t_rr_p(t) (!ns_t_qt_p(t) && !ns_t_mrr_p(t))
344 #define	ns_t_udp_p(t) ((t) != ns_t_axfr && (t) != ns_t_zxfr)
345 #define	ns_t_xfr_p(t) ((t) == ns_t_axfr || (t) == ns_t_ixfr || \
346 		(t) == ns_t_zxfr)
347 
348 /*
349  * Values for class field
350  */
351 typedef enum __ns_class {
352 	ns_c_invalid = 0,	/* Cookie. */
353 	ns_c_in = 1,		/* Internet. */
354 	ns_c_2 = 2,		/* unallocated/unsupported. */
355 	ns_c_chaos = 3,		/* MIT Chaos-net. */
356 	ns_c_hs = 4,		/* MIT Hesiod. */
357 	/* Query class values which do not appear in resource records */
358 	ns_c_none = 254,	/* for prereq. sections in update requests */
359 	ns_c_any = 255,		/* Wildcard match. */
360 	ns_c_max = 65536
361 } ns_class;
362 
363 /* DNSSEC constants. */
364 
365 typedef enum __ns_key_types {
366 	ns_kt_rsa = 1,		/* key type RSA/MD5 */
367 	ns_kt_dh  = 2,		/* Diffie Hellman */
368 	ns_kt_dsa = 3,		/* Digital Signature Standard (MANDATORY) */
369 	ns_kt_private = 254	/* Private key type starts with OID */
370 } ns_key_types;
371 
372 typedef enum __ns_cert_types {
373 	cert_t_pkix = 1,	/* PKIX (X.509v3) */
374 	cert_t_spki = 2,	/* SPKI */
375 	cert_t_pgp  = 3,	/* PGP */
376 	cert_t_url  = 253,	/* URL private type */
377 	cert_t_oid  = 254	/* OID private type */
378 } ns_cert_types;
379 
380 /* Flags field of the KEY RR rdata. */
381 #define	NS_KEY_TYPEMASK		0xC000	/* Mask for "type" bits */
382 #define	NS_KEY_TYPE_AUTH_CONF	0x0000	/* Key usable for both */
383 #define	NS_KEY_TYPE_CONF_ONLY	0x8000	/* Key usable for confidentiality */
384 #define	NS_KEY_TYPE_AUTH_ONLY	0x4000	/* Key usable for authentication */
385 #define	NS_KEY_TYPE_NO_KEY	0xC000	/* No key usable for either; no key */
386 /* The type bits can also be interpreted independently, as single bits: */
387 #define	NS_KEY_NO_AUTH		0x8000	/* Key unusable for authentication */
388 #define	NS_KEY_NO_CONF		0x4000	/* Key unusable for confidentiality */
389 #define	NS_KEY_RESERVED2	0x2000	/* Security is *mandatory* if bit=0 */
390 #define	NS_KEY_EXTENDED_FLAGS	0x1000	/* reserved - must be zero */
391 #define	NS_KEY_RESERVED4	0x0800  /* reserved - must be zero */
392 #define	NS_KEY_RESERVED5	0x0400  /* reserved - must be zero */
393 #define	NS_KEY_NAME_TYPE	0x0300	/* these bits determine the type */
394 #define	NS_KEY_NAME_USER	0x0000	/* key is assoc. with user */
395 #define	NS_KEY_NAME_ENTITY	0x0200	/* key is assoc. with entity eg host */
396 #define	NS_KEY_NAME_ZONE	0x0100	/* key is zone key */
397 #define	NS_KEY_NAME_RESERVED	0x0300	/* reserved meaning */
398 #define	NS_KEY_RESERVED8	0x0080  /* reserved - must be zero */
399 #define	NS_KEY_RESERVED9	0x0040  /* reserved - must be zero */
400 #define	NS_KEY_RESERVED10	0x0020  /* reserved - must be zero */
401 #define	NS_KEY_RESERVED11	0x0010  /* reserved - must be zero */
402 #define	NS_KEY_SIGNATORYMASK	0x000F	/* key can sign RR's of same name */
403 #define	NS_KEY_RESERVED_BITMASK (NS_KEY_RESERVED2 | \
404     NS_KEY_RESERVED4 | \
405     NS_KEY_RESERVED5 | \
406     NS_KEY_RESERVED8 | \
407     NS_KEY_RESERVED9 | \
408     NS_KEY_RESERVED10 | \
409     NS_KEY_RESERVED11)
410 #define	NS_KEY_RESERVED_BITMASK2	0xFFFF /* no bits defined here */
411 
412 /* The Algorithm field of the KEY and SIG RR's is an integer, {1..254} */
413 #define	NS_ALG_MD5RSA		1	/* MD5 with RSA */
414 #define	NS_ALG_DH		2	/* Diffie Hellman KEY */
415 #define	NS_ALG_DSA		3	/* DSA KEY */
416 #define	NS_ALG_DSS		NS_ALG_DSA
417 #define	NS_ALG_EXPIRE_ONLY	253	/* No alg, no security */
418 #define	NS_ALG_PRIVATE_OID	254	/* Key begins with OID giving alg */
419 
420 /* Protocol values  */
421 /* value 0 is reserved */
422 #define	NS_KEY_PROT_TLS		1
423 #define	NS_KEY_PROT_EMAIL	2
424 #define	NS_KEY_PROT_DNSSEC	3
425 #define	NS_KEY_PROT_IPSEC	4
426 #define	NS_KEY_PROT_ANY		255
427 
428 /* Signatures */
429 #define	NS_MD5RSA_MIN_BITS	 512	/* Size of a mod or exp in bits */
430 #define	NS_MD5RSA_MAX_BITS	4096
431 	/* Total of binary mod and exp */
432 #define	NS_MD5RSA_MAX_BYTES	((NS_MD5RSA_MAX_BITS+7/8)*2+3)
433 	/* Max length of text sig block */
434 #define	NS_MD5RSA_MAX_BASE64	(((NS_MD5RSA_MAX_BYTES+2)/3)*4)
435 #define	NS_MD5RSA_MIN_SIZE	((NS_MD5RSA_MIN_BITS+7)/8)
436 #define	NS_MD5RSA_MAX_SIZE	((NS_MD5RSA_MAX_BITS+7)/8)
437 
438 #define	NS_DSA_SIG_SIZE		41
439 #define	NS_DSA_MIN_SIZE		213
440 #define	NS_DSA_MAX_BYTES	405
441 
442 /* Offsets into SIG record rdata to find various values */
443 #define	NS_SIG_TYPE	0	/* Type flags */
444 #define	NS_SIG_ALG	2	/* Algorithm */
445 #define	NS_SIG_LABELS	3	/* How many labels in name */
446 #define	NS_SIG_OTTL	4	/* Original TTL */
447 #define	NS_SIG_EXPIR	8	/* Expiration time */
448 #define	NS_SIG_SIGNED	12	/* Signature time */
449 #define	NS_SIG_FOOT	16	/* Key footprint */
450 #define	NS_SIG_SIGNER	18	/* Domain name of who signed it */
451 
452 /* How RR types are represented as bit-flags in NXT records */
453 #define	NS_NXT_BITS 8
454 #define	NS_NXT_BIT_SET(n, p) \
455 	(p[(n)/NS_NXT_BITS] |=  (0x80>>((n)%NS_NXT_BITS)))
456 #define	NS_NXT_BIT_CLEAR(n, p) \
457 	(p[(n)/NS_NXT_BITS] &= ~(0x80>>((n)%NS_NXT_BITS)))
458 #define	NS_NXT_BIT_ISSET(n, p) \
459 	(p[(n)/NS_NXT_BITS] &   (0x80>>((n)%NS_NXT_BITS)))
460 #define	NS_NXT_MAX	127
461 
462 /*
463  * EDNS0 extended flags, host order.
464  */
465 #define	NS_OPT_DNSSEC_OK	0x8000U
466 
467 /*
468  * Inline versions of get/put short/long.  Pointer is advanced.
469  */
470 #define	NS_GET16(s, cp) do { \
471 	register const uchar_t *t_cp = (const uchar_t *)(cp); \
472 	(s) = ((uint16_t)t_cp[0] << 8) \
473 	    | ((uint16_t)t_cp[1]) \
474 	; \
475 	(cp) += NS_INT16SZ; \
476 } while (0)
477 
478 #define	NS_GET32(l, cp) do { \
479 	register const uchar_t *t_cp = (const uchar_t *)(cp); \
480 	(l) = ((uint32_t)t_cp[0] << 24) \
481 	    | ((uint32_t)t_cp[1] << 16) \
482 	    | ((uint32_t)t_cp[2] << 8) \
483 	    | ((uint32_t)t_cp[3]) \
484 	; \
485 	(cp) += NS_INT32SZ; \
486 } while (0)
487 
488 #define	NS_PUT16(s, cp) do { \
489 	register uint16_t t_s = (uint16_t)(s); \
490 	register uchar_t *t_cp = (uchar_t *)(cp); \
491 	*t_cp++ = t_s >> 8; \
492 	*t_cp   = t_s; \
493 	(cp) += NS_INT16SZ; \
494 } while (0)
495 
496 #define	NS_PUT32(l, cp) do { \
497 	register uint32_t t_l = (uint32_t)(l); \
498 	register uchar_t *t_cp = (uchar_t *)(cp); \
499 	*t_cp++ = t_l >> 24; \
500 	*t_cp++ = t_l >> 16; \
501 	*t_cp++ = t_l >> 8; \
502 	*t_cp   = t_l; \
503 	(cp) += NS_INT32SZ; \
504 } while (0)
505 
506 /*
507  * ANSI C identifier hiding.
508  */
509 #define	ns_msg_getflag		__ns_msg_getflag
510 #define	ns_get16		__ns_get16
511 #define	ns_get32		__ns_get32
512 #define	ns_put16		__ns_put16
513 #define	ns_put32		__ns_put32
514 #define	ns_initparse		__ns_initparse
515 #define	ns_skiprr		__ns_skiprr
516 #define	ns_parserr		__ns_parserr
517 #define	ns_sprintrr		__ns_sprintrr
518 #define	ns_sprintrrf		__ns_sprintrrf
519 #define	ns_format_ttl		__ns_format_ttl
520 #define	ns_parse_ttl		__ns_parse_ttl
521 #define	ns_datetosecs		__ns_datetosecs
522 #define	ns_name_ntol		__ns_name_ntol
523 #define	ns_name_ntop		__ns_name_ntop
524 #define	ns_name_pton		__ns_name_pton
525 #define	ns_name_unpack		__ns_name_unpack
526 #define	ns_name_pack		__ns_name_pack
527 #define	ns_name_compress	__ns_name_compress
528 #define	ns_name_uncompress	__ns_name_uncompress
529 #define	ns_name_skip		__ns_name_skip
530 #define	ns_name_rollback	__ns_name_rollback
531 #define	ns_sign			__ns_sign
532 #define	ns_sign2		__ns_sign2
533 #define	ns_sign_tcp		__ns_sign_tcp
534 #define	ns_sign_tcp2		__ns_sign_tcp2
535 #define	ns_sign_tcp_init	__ns_sign_tcp_init
536 #define	ns_find_tsig		__ns_find_tsig
537 #define	ns_verify		__ns_verify
538 #define	ns_verify_tcp		__ns_verify_tcp
539 #define	ns_verify_tcp_init	__ns_verify_tcp_init
540 #define	ns_samedomain		__ns_samedomain
541 #define	ns_subdomain		__ns_subdomain
542 #define	ns_makecanon		__ns_makecanon
543 #define	ns_samename		__ns_samename
544 
545 int		ns_msg_getflag(ns_msg, int);
546 uint_t		ns_get16(const uchar_t *);
547 ulong_t		ns_get32(const uchar_t *);
548 void		ns_put16(uint_t, uchar_t *);
549 void		ns_put32(ulong_t, uchar_t *);
550 int		ns_initparse(const uchar_t *, int, ns_msg *);
551 int		ns_skiprr(const uchar_t *, const uchar_t *, ns_sect, int);
552 int		ns_parserr(ns_msg *, ns_sect, int, ns_rr *);
553 int		ns_sprintrr(const ns_msg *, const ns_rr *,
554     const char *, const char *, char *, size_t);
555 int		ns_sprintrrf(const uchar_t *, size_t, const char *,
556     ns_class, ns_type, ulong_t, const uchar_t *,
557     size_t, const char *, const char *,
558     char *, size_t);
559 int		ns_format_ttl(ulong_t, char *, size_t);
560 int		ns_parse_ttl(const char *, ulong_t *);
561 uint32_t	ns_datetosecs(const char *cp, int *errp);
562 int		ns_name_ntol(const uchar_t *, uchar_t *, size_t);
563 int		ns_name_ntop(const uchar_t *, char *, size_t);
564 int		ns_name_pton(const char *, uchar_t *, size_t);
565 int		ns_name_unpack(const uchar_t *, const uchar_t *,
566 				    const uchar_t *, uchar_t *, size_t);
567 int		ns_name_pack(const uchar_t *, uchar_t *, int,
568     const uchar_t **, const uchar_t **);
569 int		ns_name_uncompress(const uchar_t *, const uchar_t *,
570 					const uchar_t *, char *, size_t);
571 int		ns_name_compress(const char *, uchar_t *, size_t,
572 			const uchar_t **, const uchar_t **);
573 int		ns_name_skip(const uchar_t **, const uchar_t *);
574 void	ns_name_rollback(const uchar_t *, const uchar_t **,
575 			const uchar_t **);
576 int		ns_sign(uchar_t *, int *, int, int, void *,
577 			const uchar_t *, int, uchar_t *, int *, time_t);
578 int		ns_sign2(uchar_t *, int *, int, int, void *,
579 			const uchar_t *, int, uchar_t *, int *, time_t,
580 			uchar_t **, uchar_t **);
581 int		ns_sign_tcp(uchar_t *, int *, int, int,
582 			ns_tcp_tsig_state *, int);
583 int		ns_sign_tcp2(uchar_t *, int *, int, int,
584 			ns_tcp_tsig_state *, int,
585 			uchar_t **, uchar_t **);
586 int		ns_sign_tcp_init(void *, const uchar_t *, int,
587 					ns_tcp_tsig_state *);
588 uchar_t		*ns_find_tsig(uchar_t *, uchar_t *);
589 int		ns_verify(uchar_t *, int *, void *,
590 			const uchar_t *, int, uchar_t *, int *,
591 			time_t *, int);
592 int		ns_verify_tcp(uchar_t *, int *, ns_tcp_tsig_state *, int);
593 int		ns_verify_tcp_init(void *, const uchar_t *, int,
594 					ns_tcp_tsig_state *);
595 int		ns_samedomain(const char *, const char *);
596 int		ns_subdomain(const char *, const char *);
597 int		ns_makecanon(const char *, char *, size_t);
598 int		ns_samename(const char *, const char *);
599 
600 #ifdef BIND_4_COMPAT
601 #include <arpa/nameser_compat.h>
602 #endif
603 
604 #ifdef	__cplusplus
605 }
606 #endif
607 
608 #endif	/* !_ARPA_NAMESER_H */
609