nameser.h revision 158787
117955Speter/*
217955Speter * Copyright (c) 1983, 1989, 1993
317917Speter *    The Regents of the University of California.  All rights reserved.
417955Speter *
517955Speter * Redistribution and use in source and binary forms, with or without
617955Speter * modification, are permitted provided that the following conditions
717955Speter * are met:
817955Speter * 1. Redistributions of source code must retain the above copyright
917955Speter *    notice, this list of conditions and the following disclaimer.
1017955Speter * 2. Redistributions in binary form must reproduce the above copyright
1117955Speter *    notice, this list of conditions and the following disclaimer in the
1217955Speter *    documentation and/or other materials provided with the distribution.
1317955Speter * 3. All advertising materials mentioning features or use of this software
1417955Speter *    must display the following acknowledgement:
1517917Speter * 	This product includes software developed by the University of
1617955Speter * 	California, Berkeley and its contributors.
1717955Speter * 4. Neither the name of the University nor the names of its contributors
1817955Speter *    may be used to endorse or promote products derived from this software
1917955Speter *    without specific prior written permission.
2017955Speter *
2117955Speter * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2217955Speter * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2317955Speter * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2417955Speter * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2517955Speter * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2617955Speter * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2717917Speter * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2826721Scharnier * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2950476Speter * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3017955Speter * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31324515Scy * SUCH DAMAGE.
3217955Speter */
3379531Sru
3417955Speter/*
3517955Speter * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
3619302Speter * Copyright (c) 1996-1999 by Internet Software Consortium.
3717955Speter *
3817955Speter * Permission to use, copy, modify, and distribute this software for any
3917955Speter * purpose with or without fee is hereby granted, provided that the above
4017955Speter * copyright notice and this permission notice appear in all copies.
4119302Speter *
4219302Speter * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
4317955Speter * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
4459460Sphantom * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR
4559460Sphantom * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
4617955Speter * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
4784306Sru * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
48163982Slawrance * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
4917955Speter */
5018824Sjdp
5117955Speter/*
5219302Speter *	$Id: nameser.h,v 1.2.2.4.4.1 2004/03/09 08:33:30 marka Exp $
5319302Speter * $FreeBSD: head/include/arpa/nameser.h 158787 2006-05-21 11:19:36Z ume $
54254484Spjd */
5517955Speter
5617955Speter#ifndef _ARPA_NAMESER_H_
5724006Sbde#define _ARPA_NAMESER_H_
5817955Speter
5924006Sbde#define BIND_4_COMPAT
6017955Speter
6124006Sbde#include <sys/param.h>
6218824Sjdp#include <sys/types.h>
6319302Speter#include <sys/cdefs.h>
6419302Speter
6517955Speter/*
6681283Sru * Revision information.  This is the release date in YYYYMMDD format.
6717955Speter * It can change every day so the right thing to do with it is use it
6881283Sru * in preprocessor commands such as "#if (__NAMESER > 19931104)".  Do not
6981283Sru * compare for equality; rather, use it to determine whether your libbind.a
7081283Sru * contains a new enough lib/nameser/ to support the feature you need.
7181283Sru */
7219302Speter
7381283Sru#define __NAMESER	19991006	/* New interface version stamp. */
7481283Sru
7581283Sru/*
7681283Sru * Define constants based on RFC 883, RFC 1034, RFC 1035
7781283Sru */
7881283Sru#define NS_PACKETSZ	512	/* default UDP packet size */
7981283Sru#define NS_MAXDNAME	1025	/* maximum domain name */
8081283Sru#define NS_MAXMSG	65535	/* maximum message size */
8119302Speter#define NS_MAXCDNAME	255	/* maximum compressed domain name */
8217917Speter#define NS_MAXLABEL	63	/* maximum length of domain label */
8317955Speter#define NS_HFIXEDSZ	12	/* #/bytes of fixed data in header */
8417955Speter#define NS_QFIXEDSZ	4	/* #/bytes of fixed data in query */
8517917Speter#define NS_RRFIXEDSZ	10	/* #/bytes of fixed data in r record */
8617917Speter#define NS_INT32SZ	4	/* #/bytes of data in a u_int32_t */
8717917Speter#define NS_INT16SZ	2	/* #/bytes of data in a u_int16_t */
8872251Snik#define NS_INT8SZ	1	/* #/bytes of data in a u_int8_t */
8972251Snik#define NS_INADDRSZ	4	/* IPv4 T_A */
9072251Snik#define NS_IN6ADDRSZ	16	/* IPv6 T_AAAA */
91108087Sru#define NS_CMPRSFLGS	0xc0	/* Flag bits indicating name compression. */
9272251Snik#define NS_DEFAULTPORT	53	/* For both TCP and UDP. */
9372251Snik
9472251Snik/*
9572314Sru * These can be expanded with synonyms, just keep ns_parse.c:ns_parserecord()
9672314Sru * in synch with it.
9772314Sru */
9872251Sniktypedef enum __ns_sect {
9972251Snik	ns_s_qd = 0,		/* Query: Question. */
100108087Sru	ns_s_zn = 0,		/* Update: Zone. */
10172251Snik	ns_s_an = 1,		/* Query: Answer. */
10272251Snik	ns_s_pr = 1,		/* Update: Prerequisites. */
10372251Snik	ns_s_ns = 2,		/* Query: Name servers. */
10472251Snik	ns_s_ud = 2,		/* Update: Update. */
10572251Snik	ns_s_ar = 3,		/* Query|Update: Additional records. */
106131504Sru	ns_s_max = 4
10772314Sru} ns_sect;
10872314Sru
10972251Snik/*
110254484Spjd * This is a message handle.  It is caller allocated and has no dynamic data.
111108087Sru * This structure is intended to be opaque to all but ns_parse.c, thus the
11272314Sru * leading _'s on the member names.  Use the accessor functions, not the _'s.
11372314Sru */
11472314Srutypedef struct __ns_msg {
11572251Snik	const u_char	*_msg, *_eom;
11672251Snik	u_int16_t	_id, _flags, _counts[ns_s_max];
11772251Snik	const u_char	*_sections[ns_s_max];
11817955Speter	ns_sect		_sect;
11965532Snectar	int		_rrnum;
12065532Snectar	const u_char	*_msg_ptr;
12165532Snectar} ns_msg;
12289362Sru
12365532Snectar/* Private data structure - do not use from outside library. */
12465532Snectarstruct _ns_flagdata {  int mask, shift;  };
12565532Snectarextern struct _ns_flagdata _ns_flagdata[];
12665532Snectar
12765532Snectar/* Accessor macros - this is part of the public interface. */
12817955Speter
12917917Speter#define ns_msg_id(handle) ((handle)._id + 0)
13017917Speter#define ns_msg_base(handle) ((handle)._msg + 0)
13117917Speter#define ns_msg_end(handle) ((handle)._eom + 0)
13217917Speter#define ns_msg_size(handle) ((handle)._eom - (handle)._msg)
13317917Speter#define ns_msg_count(handle, section) ((handle)._counts[section] + 0)
13417917Speter
13517917Speter/*
13617917Speter * This is a parsed record.  It is caller allocated and has no dynamic data.
13717955Speter */
13817955Spetertypedef	struct __ns_rr {
13917917Speter	char		name[NS_MAXDNAME];
14017955Speter	u_int16_t	type;
14172314Sru	u_int16_t	rr_class;
14217917Speter	u_int32_t	ttl;
14372314Sru	u_int16_t	rdlength;
14472314Sru	const u_char *	rdata;
14572314Sru} ns_rr;
14672314Sru
14772314Sru/* Accessor macros - this is part of the public interface. */
14819302Speter#define ns_rr_name(rr)	(((rr).name[0] != '\0') ? (rr).name : ".")
14917955Speter#define ns_rr_type(rr)	((ns_type)((rr).type + 0))
15072314Sru#define ns_rr_class(rr)	((ns_class)((rr).rr_class + 0))
15117917Speter#define ns_rr_ttl(rr)	((rr).ttl + 0)
15272314Sru#define ns_rr_rdlen(rr)	((rr).rdlength + 0)
15372314Sru#define ns_rr_rdata(rr)	((rr).rdata + 0)
15472314Sru
15572314Sru/*
15617917Speter * These don't have to be in the same order as in the packet flags word,
15772314Sru * and they can even overlap in some cases, but they will need to be kept
15817955Speter * in synch with ns_parse.c:ns_flagdata[].
15972314Sru */
16017955Spetertypedef enum __ns_flag {
16119302Speter	ns_f_qr,		/* Question/Response. */
16217955Speter	ns_f_opcode,		/* Operation code. */
16317917Speter	ns_f_aa,		/* Authoritative Answer. */
16417955Speter	ns_f_tc,		/* Truncation occurred. */
16519302Speter	ns_f_rd,		/* Recursion Desired. */
16651419Sphantom	ns_f_ra,		/* Recursion Available. */
16717917Speter	ns_f_z,			/* MBZ. */
16817917Speter	ns_f_ad,		/* Authentic Data (DNSSEC). */
16917955Speter	ns_f_cd,		/* Checking Disabled (DNSSEC). */
17017955Speter	ns_f_rcode,		/* Response code. */
17117917Speter	ns_f_max
17217917Speter} ns_flag;
17317917Speter
17417955Speter/*
17517917Speter * Currently defined opcodes.
17617955Speter */
17717955Spetertypedef enum __ns_opcode {
17819302Speter	ns_o_query = 0,		/* Standard query. */
17919302Speter	ns_o_iquery = 1,	/* Inverse query (deprecated/unsupported). */
18019302Speter	ns_o_status = 2,	/* Name server status query (unsupported). */
18119302Speter				/* Opcode 3 is undefined/reserved. */
18219302Speter	ns_o_notify = 4,	/* Zone change notification. */
18319302Speter	ns_o_update = 5,	/* Zone update message. */
18419302Speter	ns_o_max = 6
18519302Speter} ns_opcode;
18619302Speter
18717955Speter/*
18817955Speter * Currently defined response codes.
18917955Speter */
19017955Spetertypedef	enum __ns_rcode {
19117955Speter	ns_r_noerror = 0,	/* No error occurred. */
192324515Scy	ns_r_formerr = 1,	/* Format error. */
193324515Scy	ns_r_servfail = 2,	/* Server failure. */
194324515Scy	ns_r_nxdomain = 3,	/* Name error. */
19517917Speter	ns_r_notimpl = 4,	/* Unimplemented. */
19617955Speter	ns_r_refused = 5,	/* Operation refused. */
197324515Scy	/* these are for BIND_UPDATE */
19817955Speter	ns_r_yxdomain = 6,	/* Name exists */
199324515Scy	ns_r_yxrrset = 7,	/* RRset exists */
200324515Scy	ns_r_nxrrset = 8,	/* RRset does not exist */
20119302Speter	ns_r_notauth = 9,	/* Not authoritative for zone */
20219302Speter	ns_r_notzone = 10,	/* Zone of record different from zone section */
20317917Speter	ns_r_max = 11,
204324515Scy	/* The following are EDNS extended rcodes */
205324515Scy	ns_r_badvers = 16,
20617955Speter	/* The following are TSIG errors */
20717955Speter	ns_r_badsig = 16,
20817955Speter	ns_r_badkey = 17,
20917955Speter	ns_r_badtime = 18
21017955Speter} ns_rcode;
21117955Speter
21217955Speter/* BIND_UPDATE */
21319302Spetertypedef enum __ns_update_operation {
21419302Speter	ns_uop_delete = 0,
21519302Speter	ns_uop_add = 1,
21619302Speter	ns_uop_max = 2
217108087Sru} ns_update_operation;
218108087Sru
21972314Sru/*
22072314Sru * This structure is used for TSIG authenticated messages
22172314Sru */
22219302Speterstruct ns_tsig_key {
22319302Speter        char name[NS_MAXDNAME], alg[NS_MAXDNAME];
22419302Speter        unsigned char *data;
22519302Speter        int len;
22619302Speter};
22719302Spetertypedef struct ns_tsig_key ns_tsig_key;
22819302Speter
229108087Sru/*
23017955Speter * This structure is used for TSIG authenticated TCP messages
23165532Snectar */
23217955Speterstruct ns_tcp_tsig_state {
23365532Snectar	int counter;
23419302Speter	struct dst_key *key;
23517955Speter	void *ctx;
23672251Snik	unsigned char sig[NS_PACKETSZ];
23772251Snik	int siglen;
23872314Sru};
23972314Srutypedef struct ns_tcp_tsig_state ns_tcp_tsig_state;
24072314Sru
24172314Sru#define NS_TSIG_FUDGE 300
24272251Snik#define NS_TSIG_TCP_COUNT 100
24372314Sru#define NS_TSIG_ALG_HMAC_MD5 "HMAC-MD5.SIG-ALG.REG.INT"
24472314Sru
24572251Snik#define NS_TSIG_ERROR_NO_TSIG -10
246158477Sume#define NS_TSIG_ERROR_NO_SPACE -11
24772314Sru#define NS_TSIG_ERROR_FORMERR -12
24872314Sru
24972251Snik/*
25072314Sru * Currently defined type values for resources and queries.
25172314Sru */
25217955Spetertypedef enum __ns_type {
25379754Sdd	ns_t_invalid = 0,	/* Cookie. */
25419302Speter	ns_t_a = 1,		/* Host address. */
25519302Speter	ns_t_ns = 2,		/* Authoritative server. */
25617917Speter	ns_t_md = 3,		/* Mail destination. */
25717955Speter	ns_t_mf = 4,		/* Mail forwarder. */
25872314Sru	ns_t_cname = 5,		/* Canonical name. */
25972314Sru	ns_t_soa = 6,		/* Start of authority zone. */
26072314Sru	ns_t_mb = 7,		/* Mailbox domain name. */
261163982Slawrance	ns_t_mg = 8,		/* Mail group member. */
26217955Speter	ns_t_mr = 9,		/* Mail rename name. */
26317917Speter	ns_t_null = 10,		/* Null resource record. */
26417917Speter	ns_t_wks = 11,		/* Well known service. */
26517917Speter	ns_t_ptr = 12,		/* Domain name pointer. */
26617955Speter	ns_t_hinfo = 13,	/* Host information. */
26717917Speter	ns_t_minfo = 14,	/* Mailbox information. */
26817917Speter	ns_t_mx = 15,		/* Mail routing information. */
26917955Speter	ns_t_txt = 16,		/* Text strings. */
27017955Speter	ns_t_rp = 17,		/* Responsible person. */
27172314Sru	ns_t_afsdb = 18,	/* AFS cell database. */
27217955Speter	ns_t_x25 = 19,		/* X_25 calling address. */
27317917Speter	ns_t_isdn = 20,		/* ISDN calling address. */
27417955Speter	ns_t_rt = 21,		/* Router. */
27517955Speter	ns_t_nsap = 22,		/* NSAP address. */
27617955Speter	ns_t_nsap_ptr = 23,	/* Reverse NSAP lookup (deprecated). */
27717917Speter	ns_t_sig = 24,		/* Security signature. */
27817955Speter	ns_t_key = 25,		/* Security key. */
27917955Speter	ns_t_px = 26,		/* X.400 mail mapping. */
28017917Speter	ns_t_gpos = 27,		/* Geographical position (withdrawn). */
28117955Speter	ns_t_aaaa = 28,		/* Ip6 Address. */
28217917Speter	ns_t_loc = 29,		/* Location Information. */
28317917Speter	ns_t_nxt = 30,		/* Next domain (security). */
28417917Speter	ns_t_eid = 31,		/* Endpoint identifier. */
28517917Speter	ns_t_nimloc = 32,	/* Nimrod Locator. */
28617955Speter	ns_t_srv = 33,		/* Server Selection. */
28717917Speter	ns_t_atma = 34,		/* ATM Address */
28817917Speter	ns_t_naptr = 35,	/* Naming Authority PoinTeR */
28917955Speter	ns_t_kx = 36,		/* Key Exchange */
29079754Sdd	ns_t_cert = 37,		/* Certification record */
29179754Sdd	ns_t_a6 = 38,		/* IPv6 address (deprecates AAAA) */
29217917Speter	ns_t_dname = 39,	/* Non-terminal DNAME (for IPv6) */
29317917Speter	ns_t_sink = 40,		/* Kitchen sink (experimentatl) */
29417917Speter	ns_t_opt = 41,		/* EDNS0 option (meta-RR) */
29517917Speter	ns_t_apl = 42,		/* Address prefix list (RFC 3123) */
29617917Speter	ns_t_tkey = 249,	/* Transaction key */
29717955Speter	ns_t_tsig = 250,	/* Transaction signature. */
29817955Speter	ns_t_ixfr = 251,	/* Incremental zone transfer. */
29976620Sru	ns_t_axfr = 252,	/* Transfer zone of authority. */
30081283Sru	ns_t_mailb = 253,	/* Transfer mailbox records. */
30172251Snik	ns_t_maila = 254,	/* Transfer mail agent records. */
30217955Speter	ns_t_any = 255,		/* Wildcard match. */
30317955Speter	ns_t_zxfr = 256,	/* BIND-specific, nonstandard. */
30417955Speter	ns_t_max = 65536
30517955Speter} ns_type;
30617955Speter
30717955Speter/* Exclusively a QTYPE? (not also an RTYPE) */
30817955Speter#define	ns_t_qt_p(t) (ns_t_xfr_p(t) || (t) == ns_t_any || \
30917955Speter		      (t) == ns_t_mailb || (t) == ns_t_maila)
31017917Speter/* Some kind of meta-RR? (not a QTYPE, but also not an RTYPE) */
31117955Speter#define	ns_t_mrr_p(t) ((t) == ns_t_tsig || (t) == ns_t_opt)
31217917Speter/* Exclusively an RTYPE? (not also a QTYPE or a meta-RR) */
31317955Speter#define ns_t_rr_p(t) (!ns_t_qt_p(t) && !ns_t_mrr_p(t))
31417917Speter#define ns_t_udp_p(t) ((t) != ns_t_axfr && (t) != ns_t_zxfr)
31517917Speter#define ns_t_xfr_p(t) ((t) == ns_t_axfr || (t) == ns_t_ixfr || \
316116022Scharnier		       (t) == ns_t_zxfr)
31717917Speter
31817955Speter/*
31917917Speter * Values for class field
32017955Speter */
32117955Spetertypedef enum __ns_class {
32217955Speter	ns_c_invalid = 0,	/* Cookie. */
32317955Speter	ns_c_in = 1,		/* Internet. */
32417917Speter	ns_c_2 = 2,		/* unallocated/unsupported. */
32517955Speter	ns_c_chaos = 3,		/* MIT Chaos-net. */
32617917Speter	ns_c_hs = 4,		/* MIT Hesiod. */
32717955Speter	/* Query class values which do not appear in resource records */
32817955Speter	ns_c_none = 254,	/* for prereq. sections in update requests */
32917955Speter	ns_c_any = 255,		/* Wildcard match. */
33017955Speter	ns_c_max = 65536
33117955Speter} ns_class;
33217955Speter
33317955Speter/* DNSSEC constants. */
33417955Speter
33517917Spetertypedef enum __ns_key_types {
33617955Speter	ns_kt_rsa = 1,		/* key type RSA/MD5 */
33719302Speter	ns_kt_dh  = 2,		/* Diffie Hellman */
33819302Speter	ns_kt_dsa = 3,		/* Digital Signature Standard (MANDATORY) */
33917917Speter	ns_kt_private = 254	/* Private key type starts with OID */
34017955Speter} ns_key_types;
34117955Speter
34217955Spetertypedef enum __ns_cert_types {
34317955Speter	cert_t_pkix = 1,	/* PKIX (X.509v3) */
34417955Speter	cert_t_spki = 2,	/* SPKI */
34517955Speter	cert_t_pgp  = 3,	/* PGP */
34617955Speter	cert_t_url  = 253,	/* URL private type */
34717955Speter	cert_t_oid  = 254	/* OID private type */
34817955Speter} ns_cert_types;
34979754Sdd
35017955Speter/* Flags field of the KEY RR rdata. */
35117955Speter#define	NS_KEY_TYPEMASK		0xC000	/* Mask for "type" bits */
35217955Speter#define	NS_KEY_TYPE_AUTH_CONF	0x0000	/* Key usable for both */
35317955Speter#define	NS_KEY_TYPE_CONF_ONLY	0x8000	/* Key usable for confidentiality */
35417955Speter#define	NS_KEY_TYPE_AUTH_ONLY	0x4000	/* Key usable for authentication */
35517955Speter#define	NS_KEY_TYPE_NO_KEY	0xC000	/* No key usable for either; no key */
35617955Speter/* The type bits can also be interpreted independently, as single bits: */
35717955Speter#define	NS_KEY_NO_AUTH		0x8000	/* Key unusable for authentication */
35817955Speter#define	NS_KEY_NO_CONF		0x4000	/* Key unusable for confidentiality */
35917955Speter#define	NS_KEY_RESERVED2	0x2000	/* Security is *mandatory* if bit=0 */
36019302Speter#define	NS_KEY_EXTENDED_FLAGS	0x1000	/* reserved - must be zero */
36119302Speter#define	NS_KEY_RESERVED4	0x0800  /* reserved - must be zero */
36272314Sru#define	NS_KEY_RESERVED5	0x0400  /* reserved - must be zero */
36372314Sru#define	NS_KEY_NAME_TYPE	0x0300	/* these bits determine the type */
36472314Sru#define	NS_KEY_NAME_USER	0x0000	/* key is assoc. with user */
36517955Speter#define	NS_KEY_NAME_ENTITY	0x0200	/* key is assoc. with entity eg host */
366145633Sume#define	NS_KEY_NAME_ZONE	0x0100	/* key is zone key */
36717955Speter#define	NS_KEY_NAME_RESERVED	0x0300	/* reserved meaning */
36817955Speter#define	NS_KEY_RESERVED8	0x0080  /* reserved - must be zero */
369145633Sume#define	NS_KEY_RESERVED9	0x0040  /* reserved - must be zero */
370145633Sume#define	NS_KEY_RESERVED10	0x0020  /* reserved - must be zero */
371145633Sume#define	NS_KEY_RESERVED11	0x0010  /* reserved - must be zero */
372126243Sgreen#define	NS_KEY_SIGNATORYMASK	0x000F	/* key can sign RR's of same name */
373145633Sume#define	NS_KEY_RESERVED_BITMASK ( NS_KEY_RESERVED2 | \
374145633Sume				  NS_KEY_RESERVED4 | \
37517955Speter				  NS_KEY_RESERVED5 | \
37617917Speter				  NS_KEY_RESERVED8 | \
377				  NS_KEY_RESERVED9 | \
378				  NS_KEY_RESERVED10 | \
379				  NS_KEY_RESERVED11 )
380#define NS_KEY_RESERVED_BITMASK2 0xFFFF /* no bits defined here */
381
382/* The Algorithm field of the KEY and SIG RR's is an integer, {1..254} */
383#define	NS_ALG_MD5RSA		1	/* MD5 with RSA */
384#define	NS_ALG_DH               2	/* Diffie Hellman KEY */
385#define	NS_ALG_DSA              3	/* DSA KEY */
386#define	NS_ALG_DSS              NS_ALG_DSA
387#define	NS_ALG_EXPIRE_ONLY	253	/* No alg, no security */
388#define	NS_ALG_PRIVATE_OID	254	/* Key begins with OID giving alg */
389
390/* Protocol values  */
391/* value 0 is reserved */
392#define NS_KEY_PROT_TLS         1
393#define NS_KEY_PROT_EMAIL       2
394#define NS_KEY_PROT_DNSSEC      3
395#define NS_KEY_PROT_IPSEC       4
396#define NS_KEY_PROT_ANY		255
397
398/* Signatures */
399#define	NS_MD5RSA_MIN_BITS	 512	/* Size of a mod or exp in bits */
400#define	NS_MD5RSA_MAX_BITS	4096
401	/* Total of binary mod and exp */
402#define	NS_MD5RSA_MAX_BYTES	((NS_MD5RSA_MAX_BITS+7/8)*2+3)
403	/* Max length of text sig block */
404#define	NS_MD5RSA_MAX_BASE64	(((NS_MD5RSA_MAX_BYTES+2)/3)*4)
405#define NS_MD5RSA_MIN_SIZE	((NS_MD5RSA_MIN_BITS+7)/8)
406#define NS_MD5RSA_MAX_SIZE	((NS_MD5RSA_MAX_BITS+7)/8)
407
408#define NS_DSA_SIG_SIZE         41
409#define NS_DSA_MIN_SIZE         213
410#define NS_DSA_MAX_BYTES        405
411
412/* Offsets into SIG record rdata to find various values */
413#define	NS_SIG_TYPE	0	/* Type flags */
414#define	NS_SIG_ALG	2	/* Algorithm */
415#define	NS_SIG_LABELS	3	/* How many labels in name */
416#define	NS_SIG_OTTL	4	/* Original TTL */
417#define	NS_SIG_EXPIR	8	/* Expiration time */
418#define	NS_SIG_SIGNED	12	/* Signature time */
419#define	NS_SIG_FOOT	16	/* Key footprint */
420#define	NS_SIG_SIGNER	18	/* Domain name of who signed it */
421
422/* How RR types are represented as bit-flags in NXT records */
423#define	NS_NXT_BITS 8
424#define	NS_NXT_BIT_SET(  n,p) (p[(n)/NS_NXT_BITS] |=  (0x80>>((n)%NS_NXT_BITS)))
425#define	NS_NXT_BIT_CLEAR(n,p) (p[(n)/NS_NXT_BITS] &= ~(0x80>>((n)%NS_NXT_BITS)))
426#define	NS_NXT_BIT_ISSET(n,p) (p[(n)/NS_NXT_BITS] &   (0x80>>((n)%NS_NXT_BITS)))
427#define NS_NXT_MAX 127
428
429/*
430 * EDNS0 extended flags, host order.
431 */
432#define NS_OPT_DNSSEC_OK	0x8000U
433
434/*
435 * Inline versions of get/put short/long.  Pointer is advanced.
436 */
437#define NS_GET16(s, cp) do { \
438	register const u_char *t_cp = (const u_char *)(cp); \
439	(s) = ((u_int16_t)t_cp[0] << 8) \
440	    | ((u_int16_t)t_cp[1]) \
441	    ; \
442	(cp) += NS_INT16SZ; \
443} while (0)
444
445#define NS_GET32(l, cp) do { \
446	register const u_char *t_cp = (const u_char *)(cp); \
447	(l) = ((u_int32_t)t_cp[0] << 24) \
448	    | ((u_int32_t)t_cp[1] << 16) \
449	    | ((u_int32_t)t_cp[2] << 8) \
450	    | ((u_int32_t)t_cp[3]) \
451	    ; \
452	(cp) += NS_INT32SZ; \
453} while (0)
454
455#define NS_PUT16(s, cp) do { \
456	register u_int16_t t_s = (u_int16_t)(s); \
457	register u_char *t_cp = (u_char *)(cp); \
458	*t_cp++ = t_s >> 8; \
459	*t_cp   = t_s; \
460	(cp) += NS_INT16SZ; \
461} while (0)
462
463#define NS_PUT32(l, cp) do { \
464	register u_int32_t t_l = (u_int32_t)(l); \
465	register u_char *t_cp = (u_char *)(cp); \
466	*t_cp++ = t_l >> 24; \
467	*t_cp++ = t_l >> 16; \
468	*t_cp++ = t_l >> 8; \
469	*t_cp   = t_l; \
470	(cp) += NS_INT32SZ; \
471} while (0)
472
473/*
474 * ANSI C identifier hiding for bind's lib/nameser.
475 */
476#define	ns_msg_getflag		__ns_msg_getflag
477#define ns_get16		__ns_get16
478#define ns_get32		__ns_get32
479#define ns_put16		__ns_put16
480#define ns_put32		__ns_put32
481#define ns_initparse		__ns_initparse
482#define ns_skiprr		__ns_skiprr
483#define ns_parserr		__ns_parserr
484#define	ns_sprintrr		__ns_sprintrr
485#define	ns_sprintrrf		__ns_sprintrrf
486#define	ns_format_ttl		__ns_format_ttl
487#define	ns_parse_ttl		__ns_parse_ttl
488#if 0
489#define ns_datetosecs		__ns_datetosecs
490#endif
491#define	ns_name_ntol		__ns_name_ntol
492#define	ns_name_ntop		__ns_name_ntop
493#define	ns_name_pton		__ns_name_pton
494#define	ns_name_unpack		__ns_name_unpack
495#define	ns_name_pack		__ns_name_pack
496#define	ns_name_compress	__ns_name_compress
497#define	ns_name_uncompress	__ns_name_uncompress
498#define	ns_name_skip		__ns_name_skip
499#define	ns_name_rollback	__ns_name_rollback
500#if 0
501#define	ns_sign			__ns_sign
502#define	ns_sign2		__ns_sign2
503#define	ns_sign_tcp		__ns_sign_tcp
504#define	ns_sign_tcp2		__ns_sign_tcp2
505#define	ns_sign_tcp_init	__ns_sign_tcp_init
506#define ns_find_tsig		__ns_find_tsig
507#define	ns_verify		__ns_verify
508#define	ns_verify_tcp		__ns_verify_tcp
509#define	ns_verify_tcp_init	__ns_verify_tcp_init
510#endif
511#define	ns_samedomain		__ns_samedomain
512#if 0
513#define	ns_subdomain		__ns_subdomain
514#endif
515#define	ns_makecanon		__ns_makecanon
516#define	ns_samename		__ns_samename
517
518__BEGIN_DECLS
519int		ns_msg_getflag(ns_msg, int);
520u_int		ns_get16(const u_char *);
521u_long		ns_get32(const u_char *);
522void		ns_put16(u_int, u_char *);
523void		ns_put32(u_long, u_char *);
524int		ns_initparse(const u_char *, int, ns_msg *);
525int		ns_skiprr(const u_char *, const u_char *, ns_sect, int);
526int		ns_parserr(ns_msg *, ns_sect, int, ns_rr *);
527int		ns_sprintrr(const ns_msg *, const ns_rr *,
528			    const char *, const char *, char *, size_t);
529int		ns_sprintrrf(const u_char *, size_t, const char *,
530			     ns_class, ns_type, u_long, const u_char *,
531			     size_t, const char *, const char *,
532			     char *, size_t);
533int		ns_format_ttl(u_long, char *, size_t);
534int		ns_parse_ttl(const char *, u_long *);
535#if 0
536u_int32_t	ns_datetosecs(const char *cp, int *errp);
537#endif
538int		ns_name_ntol(const u_char *, u_char *, size_t);
539int		ns_name_ntop(const u_char *, char *, size_t);
540int		ns_name_pton(const char *, u_char *, size_t);
541int		ns_name_unpack(const u_char *, const u_char *,
542			       const u_char *, u_char *, size_t);
543int		ns_name_pack(const u_char *, u_char *, int,
544			     const u_char **, const u_char **);
545int		ns_name_uncompress(const u_char *, const u_char *,
546				   const u_char *, char *, size_t);
547int		ns_name_compress(const char *, u_char *, size_t,
548				 const u_char **, const u_char **);
549int		ns_name_skip(const u_char **, const u_char *);
550void		ns_name_rollback(const u_char *, const u_char **,
551				 const u_char **);
552#if 0
553int		ns_sign(u_char *, int *, int, int, void *,
554			const u_char *, int, u_char *, int *, time_t);
555int		ns_sign2(u_char *, int *, int, int, void *,
556			 const u_char *, int, u_char *, int *, time_t,
557			 u_char **, u_char **);
558int		ns_sign_tcp(u_char *, int *, int, int,
559			    ns_tcp_tsig_state *, int);
560int		ns_sign_tcp2(u_char *, int *, int, int,
561			     ns_tcp_tsig_state *, int,
562			     u_char **, u_char **);
563int		ns_sign_tcp_init(void *, const u_char *, int,
564				 ns_tcp_tsig_state *);
565u_char		*ns_find_tsig(u_char *, u_char *);
566int		ns_verify(u_char *, int *, void *,
567			  const u_char *, int, u_char *, int *,
568			  time_t *, int);
569int		ns_verify_tcp(u_char *, int *, ns_tcp_tsig_state *, int);
570int		ns_verify_tcp_init(void *, const u_char *, int,
571				   ns_tcp_tsig_state *);
572#endif
573int		ns_samedomain(const char *, const char *);
574#if 0
575int		ns_subdomain(const char *, const char *);
576#endif
577int		ns_makecanon(const char *, char *, size_t);
578int		ns_samename(const char *, const char *);
579__END_DECLS
580
581#ifdef BIND_4_COMPAT
582#include <arpa/nameser_compat.h>
583#endif
584
585#endif /* !_ARPA_NAMESER_H_ */
586