add SSHFP, clean up the the dns_header
[metze/heimdal/wip.git] / lib / roken / resolve.h
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 /* We use these, but they are not always present in <arpa/nameser.h> */
40
41 #ifndef C_IN
42 #define C_IN            1
43 #endif
44
45 #ifndef T_A
46 #define T_A             1
47 #endif
48 #ifndef T_NS
49 #define T_NS            2
50 #endif
51 #ifndef T_CNAME
52 #define T_CNAME         5
53 #endif
54 #ifndef T_SOA
55 #define T_SOA           5
56 #endif
57 #ifndef T_PTR
58 #define T_PTR           12
59 #endif
60 #ifndef T_MX
61 #define T_MX            15
62 #endif
63 #ifndef T_TXT
64 #define T_TXT           16
65 #endif
66 #ifndef T_AFSDB
67 #define T_AFSDB         18
68 #endif
69 #ifndef T_SIG
70 #define T_SIG           24
71 #endif
72 #ifndef T_KEY
73 #define T_KEY           25
74 #endif
75 #ifndef T_AAAA
76 #define T_AAAA          28
77 #endif
78 #ifndef T_SRV
79 #define T_SRV           33
80 #endif
81 #ifndef T_NAPTR
82 #define T_NAPTR         35
83 #endif
84 #ifndef T_CERT
85 #define T_CERT          37
86 #endif
87 #ifndef T_SSHFP
88 #define T_SSHFP         44
89 #endif
90
91 #ifndef MAXDNAME
92 #define MAXDNAME        1025
93 #endif
94
95 #define dns_query               rk_dns_query
96 #define mx_record               rk_mx_record
97 #define srv_record              rk_srv_record
98 #define key_record              rk_key_record
99 #define sig_record              rk_sig_record
100 #define cert_record             rk_cert_record
101 #define resource_record         rk_resource_record
102 #define dns_reply               rk_dns_reply
103
104 #define dns_lookup              rk_dns_lookup
105 #define dns_free_data           rk_dns_free_data
106 #define dns_string_to_type      rk_dns_string_to_type
107 #define dns_type_to_string      rk_dns_type_to_string
108 #define dns_srv_order           rk_dns_srv_order
109
110 struct dns_query{
111     char *domain;
112     unsigned type;
113     unsigned class;
114 };
115
116 struct mx_record{
117     unsigned  preference;
118     char domain[1];
119 };
120
121 struct srv_record{
122     unsigned priority;
123     unsigned weight;
124     unsigned port;
125     char target[1];
126 };
127
128 struct key_record {
129     unsigned flags;
130     unsigned protocol;
131     unsigned algorithm;
132     size_t   key_len;
133     u_char   key_data[1];
134 };
135
136 struct sig_record {
137     unsigned type;
138     unsigned algorithm;
139     unsigned labels;
140     unsigned orig_ttl;
141     unsigned sig_expiration;
142     unsigned sig_inception;
143     unsigned key_tag;
144     char     *signer;
145     unsigned sig_len;
146     char     sig_data[1];       /* also includes signer */
147 };
148
149 struct cert_record {
150     unsigned type;
151     unsigned tag;
152     unsigned algorithm;
153     size_t   cert_len;
154     u_char   cert_data[1];
155 };
156
157 struct sshfp_record {
158     unsigned algorithm;
159     unsigned type;
160     size_t   sshfp_len;
161     u_char   sshfp_data[1];
162 };
163
164
165 struct resource_record{
166     char *domain;
167     unsigned type;
168     unsigned class;
169     unsigned ttl;
170     unsigned size;
171     union {
172         void *data;
173         struct mx_record *mx;
174         struct mx_record *afsdb; /* mx and afsdb are identical */
175         struct srv_record *srv;
176         struct in_addr *a;
177         char *txt;
178         struct key_record *key;
179         struct cert_record *cert;
180         struct sig_record *sig;
181         struct sshfp_record *sshfp;
182     }u;
183     struct resource_record *next;
184 };
185
186 struct dns_header {
187     unsigned id;
188     unsigned flags;
189 #define rk_DNS_HEADER_RESPONSE_FLAG             1
190 #define rk_DNS_HEADER_AUTHORITIVE_ANSWER        2
191 #define rk_DNS_HEADER_TRUNCATED_MESSAGE         4
192 #define rk_DNS_HEADER_RECURSION_DESIRED         8
193 #define rk_DNS_HEADER_RECURSION_AVAILABLE       16
194 #define rk_DNS_HEADER_AUTHENTIC_DATA            32
195 #define rk_DNS_HEADER_CHECKING_DISABLED         64
196     unsigned opcode;
197     unsigned response_code;
198     unsigned qdcount;
199     unsigned ancount;
200     unsigned nscount;
201     unsigned arcount;
202 };
203
204 struct dns_reply{
205     struct dns_header h;
206     struct dns_query q;
207     struct resource_record *head;
208 };
209
210
211 struct dns_reply* dns_lookup(const char *, const char *);
212 void dns_free_data(struct dns_reply *);
213 int dns_string_to_type(const char *name);
214 const char *dns_type_to_string(int type);
215 void dns_srv_order(struct dns_reply*);
216
217 #endif /* __RESOLVE_H__ */