xref: /illumos-gate/usr/src/head/arpa/nameser.h (revision 8119dad84d6416f13557b0ba8e2aaf9064cbcfd3)
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_tlsa = 52,		/* TLSA (RFC 6698) */
377 	ns_t_smimea = 53,	/* S/MIME cert association (RFC 8162) */
378 	ns_t_hip = 55,		/* Host Identity Protocol */
379 	ns_t_cds = 59,		/* Child DS (RFC 7344) */
380 	ns_t_cdnskey = 60,	/* DNSKEY(s) the Child wants reflected in DS */
381 	ns_t_openpgpkey = 61,	/* OpenPGP Key (RFC 7929) */
382 	ns_t_csync = 62,	/* Child-To-Parent Synchronization (RFC 7477) */
383 	ns_t_spf = 99,		/* Sender Policy Framework */
384 	ns_t_tkey = 249,	/* Transaction key */
385 	ns_t_tsig = 250,	/* Transaction signature. */
386 	ns_t_ixfr = 251,	/* Incremental zone transfer. */
387 	ns_t_axfr = 252,	/* Transfer zone of authority. */
388 	ns_t_mailb = 253,	/* Transfer mailbox records. */
389 	ns_t_maila = 254,	/* Transfer mail agent records. */
390 	ns_t_any = 255,		/* Wildcard match. */
391 	ns_t_zxfr = 256,	/* BIND-specific, nonstandard. */
392 	ns_t_caa = 257,		/* Certification Authority Restriction */
393 	ns_t_dlv = 32769,	/* DNSSEC look-aside validatation. */
394 	ns_t_max = 65536
395 } ns_type;
396 
397 /* Exclusively a QTYPE? (not also an RTYPE) */
398 #define	ns_t_qt_p(t) (ns_t_xfr_p(t) || (t) == ns_t_any || \
399 		(t) == ns_t_mailb || (t) == ns_t_maila)
400 /* Some kind of meta-RR? (not a QTYPE, but also not an RTYPE) */
401 #define	ns_t_mrr_p(t) ((t) == ns_t_tsig || (t) == ns_t_opt)
402 /* Exclusively an RTYPE? (not also a QTYPE or a meta-RR) */
403 #define	ns_t_rr_p(t) (!ns_t_qt_p(t) && !ns_t_mrr_p(t))
404 #define	ns_t_udp_p(t) ((t) != ns_t_axfr && (t) != ns_t_zxfr)
405 #define	ns_t_xfr_p(t) ((t) == ns_t_axfr || (t) == ns_t_ixfr || \
406 		(t) == ns_t_zxfr)
407 
408 /*
409  * Values for class field
410  */
411 typedef enum __ns_class {
412 	ns_c_invalid = 0,	/* Cookie. */
413 	ns_c_in = 1,		/* Internet. */
414 	ns_c_2 = 2,		/* unallocated/unsupported. */
415 	ns_c_chaos = 3,		/* MIT Chaos-net. */
416 	ns_c_hs = 4,		/* MIT Hesiod. */
417 	/* Query class values which do not appear in resource records */
418 	ns_c_none = 254,	/* for prereq. sections in update requests */
419 	ns_c_any = 255,		/* Wildcard match. */
420 	ns_c_max = 65536
421 } ns_class;
422 
423 /* DNSSEC constants. */
424 
425 typedef enum __ns_key_types {
426 	ns_kt_rsa = 1,		/* key type RSA/MD5 */
427 	ns_kt_dh  = 2,		/* Diffie Hellman */
428 	ns_kt_dsa = 3,		/* Digital Signature Standard (MANDATORY) */
429 	ns_kt_private = 254	/* Private key type starts with OID */
430 } ns_key_types;
431 
432 typedef enum __ns_cert_types {
433 	cert_t_pkix = 1,	/* PKIX (X.509v3) */
434 	cert_t_spki = 2,	/* SPKI */
435 	cert_t_pgp  = 3,	/* PGP */
436 	cert_t_url  = 253,	/* URL private type */
437 	cert_t_oid  = 254	/* OID private type */
438 } ns_cert_types;
439 
440 /* Flags field of the KEY RR rdata. */
441 #define	NS_KEY_TYPEMASK		0xC000	/* Mask for "type" bits */
442 #define	NS_KEY_TYPE_AUTH_CONF	0x0000	/* Key usable for both */
443 #define	NS_KEY_TYPE_CONF_ONLY	0x8000	/* Key usable for confidentiality */
444 #define	NS_KEY_TYPE_AUTH_ONLY	0x4000	/* Key usable for authentication */
445 #define	NS_KEY_TYPE_NO_KEY	0xC000	/* No key usable for either; no key */
446 /* The type bits can also be interpreted independently, as single bits: */
447 #define	NS_KEY_NO_AUTH		0x8000	/* Key unusable for authentication */
448 #define	NS_KEY_NO_CONF		0x4000	/* Key unusable for confidentiality */
449 #define	NS_KEY_RESERVED2	0x2000	/* Security is *mandatory* if bit=0 */
450 #define	NS_KEY_EXTENDED_FLAGS	0x1000	/* reserved - must be zero */
451 #define	NS_KEY_RESERVED4	0x0800  /* reserved - must be zero */
452 #define	NS_KEY_RESERVED5	0x0400  /* reserved - must be zero */
453 #define	NS_KEY_NAME_TYPE	0x0300	/* these bits determine the type */
454 #define	NS_KEY_NAME_USER	0x0000	/* key is assoc. with user */
455 #define	NS_KEY_NAME_ENTITY	0x0200	/* key is assoc. with entity eg host */
456 #define	NS_KEY_NAME_ZONE	0x0100	/* key is zone key */
457 #define	NS_KEY_NAME_RESERVED	0x0300	/* reserved meaning */
458 #define	NS_KEY_RESERVED8	0x0080  /* reserved - must be zero */
459 #define	NS_KEY_RESERVED9	0x0040  /* reserved - must be zero */
460 #define	NS_KEY_RESERVED10	0x0020  /* reserved - must be zero */
461 #define	NS_KEY_RESERVED11	0x0010  /* reserved - must be zero */
462 #define	NS_KEY_SIGNATORYMASK	0x000F	/* key can sign RR's of same name */
463 #define	NS_KEY_RESERVED_BITMASK (NS_KEY_RESERVED2 | \
464     NS_KEY_RESERVED4 | \
465     NS_KEY_RESERVED5 | \
466     NS_KEY_RESERVED8 | \
467     NS_KEY_RESERVED9 | \
468     NS_KEY_RESERVED10 | \
469     NS_KEY_RESERVED11)
470 #define	NS_KEY_RESERVED_BITMASK2	0xFFFF /* no bits defined here */
471 
472 /* The Algorithm field of the KEY and SIG RR's is an integer, {1..254} */
473 #define	NS_ALG_MD5RSA		1	/* MD5 with RSA */
474 #define	NS_ALG_DH		2	/* Diffie Hellman KEY */
475 #define	NS_ALG_DSA		3	/* DSA KEY */
476 #define	NS_ALG_DSS		NS_ALG_DSA
477 #define	NS_ALG_EXPIRE_ONLY	253	/* No alg, no security */
478 #define	NS_ALG_PRIVATE_OID	254	/* Key begins with OID giving alg */
479 
480 /* Protocol values  */
481 /* value 0 is reserved */
482 #define	NS_KEY_PROT_TLS		1
483 #define	NS_KEY_PROT_EMAIL	2
484 #define	NS_KEY_PROT_DNSSEC	3
485 #define	NS_KEY_PROT_IPSEC	4
486 #define	NS_KEY_PROT_ANY		255
487 
488 /* Signatures */
489 #define	NS_MD5RSA_MIN_BITS	 512	/* Size of a mod or exp in bits */
490 #define	NS_MD5RSA_MAX_BITS	4096
491 	/* Total of binary mod and exp */
492 #define	NS_MD5RSA_MAX_BYTES	((NS_MD5RSA_MAX_BITS+7/8)*2+3)
493 	/* Max length of text sig block */
494 #define	NS_MD5RSA_MAX_BASE64	(((NS_MD5RSA_MAX_BYTES+2)/3)*4)
495 #define	NS_MD5RSA_MIN_SIZE	((NS_MD5RSA_MIN_BITS+7)/8)
496 #define	NS_MD5RSA_MAX_SIZE	((NS_MD5RSA_MAX_BITS+7)/8)
497 
498 #define	NS_DSA_SIG_SIZE		41
499 #define	NS_DSA_MIN_SIZE		213
500 #define	NS_DSA_MAX_BYTES	405
501 
502 /* Offsets into SIG record rdata to find various values */
503 #define	NS_SIG_TYPE	0	/* Type flags */
504 #define	NS_SIG_ALG	2	/* Algorithm */
505 #define	NS_SIG_LABELS	3	/* How many labels in name */
506 #define	NS_SIG_OTTL	4	/* Original TTL */
507 #define	NS_SIG_EXPIR	8	/* Expiration time */
508 #define	NS_SIG_SIGNED	12	/* Signature time */
509 #define	NS_SIG_FOOT	16	/* Key footprint */
510 #define	NS_SIG_SIGNER	18	/* Domain name of who signed it */
511 
512 /* How RR types are represented as bit-flags in NXT records */
513 #define	NS_NXT_BITS 8
514 #define	NS_NXT_BIT_SET(n, p) \
515 	(p[(n)/NS_NXT_BITS] |=  (0x80>>((n)%NS_NXT_BITS)))
516 #define	NS_NXT_BIT_CLEAR(n, p) \
517 	(p[(n)/NS_NXT_BITS] &= ~(0x80>>((n)%NS_NXT_BITS)))
518 #define	NS_NXT_BIT_ISSET(n, p) \
519 	(p[(n)/NS_NXT_BITS] &   (0x80>>((n)%NS_NXT_BITS)))
520 #define	NS_NXT_MAX	127
521 
522 /*
523  * EDNS0 extended flags, host order.
524  */
525 #define	NS_OPT_DNSSEC_OK	0x8000U
526 #define	NS_OPT_NSID		3
527 
528 /*
529  * Inline versions of get/put short/long.  Pointer is advanced.
530  */
531 #define	NS_GET16(s, cp) do { \
532 	register const uchar_t *t_cp = (const uchar_t *)(cp); \
533 	(s) = ((uint16_t)t_cp[0] << 8) \
534 	    | ((uint16_t)t_cp[1]) \
535 	; \
536 	(cp) += NS_INT16SZ; \
537 } while (0)
538 
539 #define	NS_GET32(l, cp) do { \
540 	register const uchar_t *t_cp = (const uchar_t *)(cp); \
541 	(l) = ((uint32_t)t_cp[0] << 24) \
542 	    | ((uint32_t)t_cp[1] << 16) \
543 	    | ((uint32_t)t_cp[2] << 8) \
544 	    | ((uint32_t)t_cp[3]) \
545 	; \
546 	(cp) += NS_INT32SZ; \
547 } while (0)
548 
549 #define	NS_PUT16(s, cp) do { \
550 	register uint16_t t_s = (uint16_t)(s); \
551 	register uchar_t *t_cp = (uchar_t *)(cp); \
552 	*t_cp++ = t_s >> 8; \
553 	*t_cp   = t_s; \
554 	(cp) += NS_INT16SZ; \
555 } while (0)
556 
557 #define	NS_PUT32(l, cp) do { \
558 	register uint32_t t_l = (uint32_t)(l); \
559 	register uchar_t *t_cp = (uchar_t *)(cp); \
560 	*t_cp++ = t_l >> 24; \
561 	*t_cp++ = t_l >> 16; \
562 	*t_cp++ = t_l >> 8; \
563 	*t_cp   = t_l; \
564 	(cp) += NS_INT32SZ; \
565 } while (0)
566 
567 /*
568  * ANSI C identifier hiding.
569  */
570 #define	ns_msg_getflag		__ns_msg_getflag
571 #define	ns_get16		__ns_get16
572 #define	ns_get32		__ns_get32
573 #define	ns_put16		__ns_put16
574 #define	ns_put32		__ns_put32
575 #define	ns_initparse		__ns_initparse
576 #define	ns_skiprr		__ns_skiprr
577 #define	ns_parserr		__ns_parserr
578 #define	ns_parserr2		__ns_parserr2
579 #define	ns_sprintrr		__ns_sprintrr
580 #define	ns_sprintrrf		__ns_sprintrrf
581 #define	ns_format_ttl		__ns_format_ttl
582 #define	ns_parse_ttl		__ns_parse_ttl
583 #define	ns_datetosecs		__ns_datetosecs
584 #define	ns_name_ntol		__ns_name_ntol
585 #define	ns_name_ntop		__ns_name_ntop
586 #define	ns_name_pton		__ns_name_pton
587 #define	ns_name_pton2		__ns_name_pton2
588 #define	ns_name_unpack		__ns_name_unpack
589 #define	ns_name_pack		__ns_name_pack
590 #define	ns_name_compress	__ns_name_compress
591 #define	ns_name_uncompress	__ns_name_uncompress
592 #define	ns_name_skip		__ns_name_skip
593 #define	ns_name_rollback	__ns_name_rollback
594 #define	ns_name_length		__ns_name_length
595 #define	ns_name_eq		__ns_name_eq
596 #define	ns_name_owned		__ns_name_owned
597 #define	ns_name_map		__ns_name_map
598 #define	ns_name_labels		__ns_name_labels
599 #define	ns_sign			__ns_sign
600 #define	ns_sign2		__ns_sign2
601 #define	ns_sign_tcp		__ns_sign_tcp
602 #define	ns_sign_tcp2		__ns_sign_tcp2
603 #define	ns_sign_tcp_init	__ns_sign_tcp_init
604 #define	ns_find_tsig		__ns_find_tsig
605 #define	ns_verify		__ns_verify
606 #define	ns_verify_tcp		__ns_verify_tcp
607 #define	ns_verify_tcp_init	__ns_verify_tcp_init
608 #define	ns_samedomain		__ns_samedomain
609 #define	ns_subdomain		__ns_subdomain
610 #define	ns_makecanon		__ns_makecanon
611 #define	ns_samename		__ns_samename
612 #define	ns_newmsg_init		__ns_newmsg_init
613 #define	ns_newmsg_copy		__ns_newmsg_copy
614 #define	ns_newmsg_id		__ns_newmsg_id
615 #define	ns_newmsg_flag		__ns_newmsg_flag
616 #define	ns_newmsg_q		__ns_newmsg_q
617 #define	ns_newmsg_rr		__ns_newmsg_rr
618 #define	ns_newmsg_done		__ns_newmsg_done
619 #define	ns_rdata_unpack		__ns_rdata_unpack
620 #define	ns_rdata_equal		__ns_rdata_equal
621 #define	ns_rdata_refers		__ns_rdata_refers
622 
623 int		ns_msg_getflag(ns_msg, int);
624 uint_t		ns_get16(const uchar_t *);
625 ulong_t		ns_get32(const uchar_t *);
626 void		ns_put16(uint_t, uchar_t *);
627 void		ns_put32(ulong_t, uchar_t *);
628 int		ns_initparse(const uchar_t *, int, ns_msg *);
629 int		ns_skiprr(const uchar_t *, const uchar_t *, ns_sect, int);
630 int		ns_parserr(ns_msg *, ns_sect, int, ns_rr *);
631 int		ns_parserr2(ns_msg *, ns_sect, int, ns_rr2 *);
632 int		ns_sprintrr(const ns_msg *, const ns_rr *,
633     const char *, const char *, char *, size_t);
634 int		ns_sprintrrf(const uchar_t *, size_t, const char *,
635     ns_class, ns_type, ulong_t, const uchar_t *,
636     size_t, const char *, const char *,
637     char *, size_t);
638 int		ns_format_ttl(ulong_t, char *, size_t);
639 int		ns_parse_ttl(const char *, ulong_t *);
640 uint32_t	ns_datetosecs(const char *cp, int *errp);
641 int		ns_name_ntol(const uchar_t *, uchar_t *, size_t);
642 int		ns_name_ntop(const uchar_t *, char *, size_t);
643 int		ns_name_pton(const char *, uchar_t *, size_t);
644 int		ns_name_pton2(const char *, uchar_t *, size_t, size_t *);
645 int		ns_name_unpack(const uchar_t *, const uchar_t *,
646 				    const uchar_t *, uchar_t *, size_t);
647 int		ns_name_pack(const uchar_t *, uchar_t *, int,
648     const uchar_t **, const uchar_t **);
649 int		ns_name_uncompress(const uchar_t *, const uchar_t *,
650 					const uchar_t *, char *, size_t);
651 int		ns_name_compress(const char *, uchar_t *, size_t,
652 			const uchar_t **, const uchar_t **);
653 int		ns_name_skip(const uchar_t **, const uchar_t *);
654 void	ns_name_rollback(const uchar_t *, const uchar_t **,
655 			const uchar_t **);
656 ssize_t		ns_name_length(ns_nname_ct, size_t);
657 int		ns_name_eq(ns_nname_ct, size_t, ns_nname_ct, size_t);
658 int		ns_name_owned(ns_namemap_ct, int, ns_namemap_ct, int);
659 int		ns_name_map(ns_nname_ct, size_t, ns_namemap_t, int);
660 int		ns_name_labels(ns_nname_ct, size_t);
661 int		ns_sign(uchar_t *, int *, int, int, void *,
662 			const uchar_t *, int, uchar_t *, int *, time_t);
663 int		ns_sign2(uchar_t *, int *, int, int, void *,
664 			const uchar_t *, int, uchar_t *, int *, time_t,
665 			uchar_t **, uchar_t **);
666 int		ns_sign_tcp(uchar_t *, int *, int, int,
667 			ns_tcp_tsig_state *, int);
668 int		ns_sign_tcp2(uchar_t *, int *, int, int,
669 			ns_tcp_tsig_state *, int,
670 			uchar_t **, uchar_t **);
671 int		ns_sign_tcp_init(void *, const uchar_t *, int,
672 					ns_tcp_tsig_state *);
673 uchar_t		*ns_find_tsig(uchar_t *, uchar_t *);
674 int		ns_verify(uchar_t *, int *, void *,
675 			const uchar_t *, int, uchar_t *, int *,
676 			time_t *, int);
677 int		ns_verify_tcp(uchar_t *, int *, ns_tcp_tsig_state *, int);
678 int		ns_verify_tcp_init(void *, const uchar_t *, int,
679 					ns_tcp_tsig_state *);
680 int		ns_samedomain(const char *, const char *);
681 int		ns_subdomain(const char *, const char *);
682 int		ns_makecanon(const char *, char *, size_t);
683 int		ns_samename(const char *, const char *);
684 int		ns_newmsg_init(uchar_t *buffer, size_t bufsiz, ns_newmsg *);
685 int		ns_newmsg_copy(ns_newmsg *, ns_msg *);
686 void		ns_newmsg_id(ns_newmsg *handle, uint16_t id);
687 void		ns_newmsg_flag(ns_newmsg *handle, ns_flag flag, uint_t value);
688 int		ns_newmsg_q(ns_newmsg *handle, ns_nname_ct qname,
689 			    ns_type qtype, ns_class qclass);
690 int		ns_newmsg_rr(ns_newmsg *handle, ns_sect sect,
691 			    ns_nname_ct name, ns_type type,
692 			    ns_class rr_class, uint32_t ttl,
693 			    uint16_t rdlen, const uchar_t *rdata);
694 size_t		ns_newmsg_done(ns_newmsg *handle);
695 ssize_t		ns_rdata_unpack(const uchar_t *, const uchar_t *, ns_type,
696 				const uchar_t *, size_t, uchar_t *, size_t);
697 int		ns_rdata_equal(ns_type, const uchar_t *, size_t,
698 				const uchar_t *, size_t);
699 int		ns_rdata_refers(ns_type,
700 				const uchar_t *, size_t,
701 				const uchar_t *);
702 
703 #ifdef BIND_4_COMPAT
704 #include <arpa/nameser_compat.h>
705 #endif
706 
707 #ifdef	__cplusplus
708 }
709 #endif
710 
711 #endif	/* !_ARPA_NAMESER_H */
712