xref: /freebsd/crypto/heimdal/lib/roken/resolve.h (revision 8ddb146abcdf061be9f2c0db7e391697dafad85c)
1 /*
2  * Copyright (c) 1995 - 2002 Kungliga Tekniska Högskolan
3  * (Royal Institute of Technology, Stockholm, Sweden).
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * 3. Neither the name of the Institute nor the names of its contributors
18  *    may be used to endorse or promote products derived from this software
19  *    without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  */
33 
34 /* $Id$ */
35 
36 #ifndef __RESOLVE_H__
37 #define __RESOLVE_H__
38 
39 #ifndef ROKEN_LIB_FUNCTION
40 #ifdef _WIN32
41 #define ROKEN_LIB_FUNCTION
42 #define ROKEN_LIB_CALL     __cdecl
43 #else
44 #define ROKEN_LIB_FUNCTION
45 #define ROKEN_LIB_CALL
46 #endif
47 #endif
48 
49 enum {
50     rk_ns_c_in = 1
51 };
52 
53 enum {
54 	rk_ns_t_invalid = 0,	/* Cookie. */
55 	rk_ns_t_a = 1,		/* Host address. */
56 	rk_ns_t_ns = 2,		/* Authoritative server. */
57 	rk_ns_t_md = 3,		/* Mail destination. */
58 	rk_ns_t_mf = 4,		/* Mail forwarder. */
59 	rk_ns_t_cname = 5,	/* Canonical name. */
60 	rk_ns_t_soa = 6,	/* Start of authority zone. */
61 	rk_ns_t_mb = 7,		/* Mailbox domain name. */
62 	rk_ns_t_mg = 8,		/* Mail group member. */
63 	rk_ns_t_mr = 9,		/* Mail rename name. */
64 	rk_ns_t_null = 10,	/* Null resource record. */
65 	rk_ns_t_wks = 11,	/* Well known service. */
66 	rk_ns_t_ptr = 12,	/* Domain name pointer. */
67 	rk_ns_t_hinfo = 13,	/* Host information. */
68 	rk_ns_t_minfo = 14,	/* Mailbox information. */
69 	rk_ns_t_mx = 15,	/* Mail routing information. */
70 	rk_ns_t_txt = 16,	/* Text strings. */
71 	rk_ns_t_rp = 17,	/* Responsible person. */
72 	rk_ns_t_afsdb = 18,	/* AFS cell database. */
73 	rk_ns_t_x25 = 19,	/* X_25 calling address. */
74 	rk_ns_t_isdn = 20,	/* ISDN calling address. */
75 	rk_ns_t_rt = 21,	/* Router. */
76 	rk_ns_t_nsap = 22,	/* NSAP address. */
77 	rk_ns_t_nsap_ptr = 23,	/* Reverse NSAP lookup (deprecated). */
78 	rk_ns_t_sig = 24,	/* Security signature. */
79 	rk_ns_t_key = 25,	/* Security key. */
80 	rk_ns_t_px = 26,	/* X.400 mail mapping. */
81 	rk_ns_t_gpos = 27,	/* Geographical position (withdrawn). */
82 	rk_ns_t_aaaa = 28,	/* Ip6 Address. */
83 	rk_ns_t_loc = 29,	/* Location Information. */
84 	rk_ns_t_nxt = 30,	/* Next domain (security). */
85 	rk_ns_t_eid = 31,	/* Endpoint identifier. */
86 	rk_ns_t_nimloc = 32,	/* Nimrod Locator. */
87 	rk_ns_t_srv = 33,	/* Server Selection. */
88 	rk_ns_t_atma = 34,	/* ATM Address */
89 	rk_ns_t_naptr = 35,	/* Naming Authority PoinTeR */
90 	rk_ns_t_kx = 36,	/* Key Exchange */
91 	rk_ns_t_cert = 37,	/* Certification record */
92 	rk_ns_t_a6 = 38,	/* IPv6 address (deprecates AAAA) */
93 	rk_ns_t_dname = 39,	/* Non-terminal DNAME (for IPv6) */
94 	rk_ns_t_sink = 40,	/* Kitchen sink (experimentatl) */
95 	rk_ns_t_opt = 41,	/* EDNS0 option (meta-RR) */
96 	rk_ns_t_apl = 42,	/* Address prefix list (RFC 3123) */
97 	rk_ns_t_ds = 43,	/* Delegation Signer (RFC 3658) */
98 	rk_ns_t_sshfp = 44,	/* SSH fingerprint */
99 	rk_ns_t_tkey = 249,	/* Transaction key */
100 	rk_ns_t_tsig = 250,	/* Transaction signature. */
101 	rk_ns_t_ixfr = 251,	/* Incremental zone transfer. */
102 	rk_ns_t_axfr = 252,	/* Transfer zone of authority. */
103 	rk_ns_t_mailb = 253,	/* Transfer mailbox records. */
104 	rk_ns_t_maila = 254,	/* Transfer mail agent records. */
105 	rk_ns_t_any = 255,	/* Wildcard match. */
106 	rk_ns_t_zxfr = 256,	/* BIND-specific, nonstandard. */
107 	rk_ns_t_max = 65536
108 };
109 
110 #ifndef MAXDNAME
111 #define MAXDNAME	1025
112 #endif
113 
114 #define mx_record		rk_mx_record
115 #define srv_record		rk_srv_record
116 #define key_record		rk_key_record
117 #define sig_record		rk_sig_record
118 #define cert_record		rk_cert_record
119 #define sshfp_record		rk_sshfp_record
120 
121 struct rk_dns_query{
122     char *domain;
123     unsigned type;
124     unsigned class;
125 };
126 
127 struct rk_mx_record{
128     unsigned  preference;
129     char domain[1];
130 };
131 
132 struct rk_srv_record{
133     unsigned priority;
134     unsigned weight;
135     unsigned port;
136     char target[1];
137 };
138 
139 struct rk_key_record {
140     unsigned flags;
141     unsigned protocol;
142     unsigned algorithm;
143     size_t   key_len;
144     u_char   key_data[1];
145 };
146 
147 struct rk_sig_record {
148     unsigned type;
149     unsigned algorithm;
150     unsigned labels;
151     unsigned orig_ttl;
152     unsigned sig_expiration;
153     unsigned sig_inception;
154     unsigned key_tag;
155     char     *signer;
156     size_t   sig_len;
157     char     sig_data[1];	/* also includes signer */
158 };
159 
160 struct rk_cert_record {
161     unsigned type;
162     unsigned tag;
163     unsigned algorithm;
164     size_t   cert_len;
165     u_char   cert_data[1];
166 };
167 
168 struct rk_sshfp_record {
169     unsigned algorithm;
170     unsigned type;
171     size_t   sshfp_len;
172     u_char   sshfp_data[1];
173 };
174 
175 struct rk_ds_record {
176     unsigned key_tag;
177     unsigned algorithm;
178     unsigned digest_type;
179     size_t digest_len;
180     u_char digest_data[1];
181 };
182 
183 struct rk_resource_record{
184     char *domain;
185     unsigned type;
186     unsigned class;
187     unsigned ttl;
188     unsigned size;
189     union {
190 	void *data;
191 	struct rk_mx_record *mx;
192 	struct rk_mx_record *afsdb; /* mx and afsdb are identical */
193 	struct rk_srv_record *srv;
194 	struct in_addr *a;
195 	char *txt;
196 	struct rk_key_record *key;
197 	struct rk_cert_record *cert;
198 	struct rk_sig_record *sig;
199 	struct rk_sshfp_record *sshfp;
200 	struct rk_ds_record *ds;
201     }u;
202     struct rk_resource_record *next;
203 };
204 
205 #define rk_DNS_MAX_PACKET_SIZE		0xffff
206 
207 struct rk_dns_header {
208     unsigned id;
209     unsigned flags;
210 #define rk_DNS_HEADER_RESPONSE_FLAG		1
211 #define rk_DNS_HEADER_AUTHORITIVE_ANSWER	2
212 #define rk_DNS_HEADER_TRUNCATED_MESSAGE		4
213 #define rk_DNS_HEADER_RECURSION_DESIRED		8
214 #define rk_DNS_HEADER_RECURSION_AVAILABLE	16
215 #define rk_DNS_HEADER_AUTHENTIC_DATA		32
216 #define rk_DNS_HEADER_CHECKING_DISABLED		64
217     unsigned opcode;
218     unsigned response_code;
219     unsigned qdcount;
220     unsigned ancount;
221     unsigned nscount;
222     unsigned arcount;
223 };
224 
225 struct rk_dns_reply{
226     struct rk_dns_header h;
227     struct rk_dns_query q;
228     struct rk_resource_record *head;
229 };
230 
231 
232 #ifdef __cplusplus
233 extern "C" {
234 #endif
235 
236 ROKEN_LIB_FUNCTION struct rk_dns_reply* ROKEN_LIB_CALL
237 	rk_dns_lookup(const char *, const char *);
238 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
239 	rk_dns_free_data(struct rk_dns_reply *);
240 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
241 	rk_dns_string_to_type(const char *name);
242 ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL
243 	rk_dns_type_to_string(int type);
244 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
245 	rk_dns_srv_order(struct rk_dns_reply*);
246 
247 #ifdef __cplusplus
248 }
249 #endif
250 
251 #endif /* __RESOLVE_H__ */
252