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