xref: /titanic_41/usr/src/head/resolv.h (revision b59b3655028aeb11832ad679eb5c2577c2b75235)
1 /*
2  * Copyright 2014 Garrett D'Amore <garrett@damore.org>
3  *
4  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
5  * Use is subject to license terms.
6  *
7  * Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T
8  * All Rights Reserved
9  *
10  * Portions of this source code were derived from Berkeley
11  * 4.3 BSD under license from the regents of the University of
12  * California.
13  */
14 
15 /*
16  * BIND 4.9.4:
17  */
18 
19 /*
20  * Portions Copyright (c) 1993 by Digital Equipment Corporation.
21  *
22  * Permission to use, copy, modify, and distribute this software for any
23  * purpose with or without fee is hereby granted, provided that the above
24  * copyright notice and this permission notice appear in all copies, and that
25  * the name of Digital Equipment Corporation not be used in advertising or
26  * publicity pertaining to distribution of the document or software without
27  * specific, written prior permission.
28  *
29  * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
30  * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
31  * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
32  * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
33  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
34  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
35  * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
36  * SOFTWARE.
37  * --Copyright--
38  *
39  * End BIND 4.9.4
40  */
41 
42 /*
43  * Copyright (c) 1983, 1987, 1989
44  *    The Regents of the University of California.  All rights reserved.
45  *
46  * Redistribution and use in source and binary forms, with or without
47  * modification, are permitted provided that the following conditions
48  * are met:
49  * 1. Redistributions of source code must retain the above copyright
50  *    notice, this list of conditions and the following disclaimer.
51  * 2. Redistributions in binary form must reproduce the above copyright
52  *    notice, this list of conditions and the following disclaimer in the
53  *    documentation and/or other materials provided with the distribution.
54  * 3. All advertising materials mentioning features or use of this software
55  *    must display the following acknowledgement:
56  * 	This product includes software developed by the University of
57  * 	California, Berkeley and its contributors.
58  * 4. Neither the name of the University nor the names of its contributors
59  *    may be used to endorse or promote products derived from this software
60  *    without specific prior written permission.
61  *
62  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
63  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
64  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
65  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
66  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
67  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
68  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
69  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
70  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
71  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
72  * SUCH DAMAGE.
73  */
74 
75 /*
76  * Portions Copyright (c) 1996-1999 by Internet Software Consortium.
77  *
78  * Permission to use, copy, modify, and distribute this software for any
79  * purpose with or without fee is hereby granted, provided that the above
80  * copyright notice and this permission notice appear in all copies.
81  *
82  * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
83  * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
84  * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
85  * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
86  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
87  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
88  * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
89  * SOFTWARE.
90  */
91 
92 /*
93  *	@(#)resolv.h	8.1 (Berkeley) 6/2/93
94  *	$Id: resolv.h,v 8.52 2003/04/29 02:27:03 marka Exp $
95  */
96 
97 #ifndef _RESOLV_H_
98 #define	_RESOLV_H_
99 
100 #include <sys/param.h>
101 
102 #include <stdio.h>
103 #include <arpa/nameser.h>
104 #include <sys/socket.h>
105 
106 #ifdef	__cplusplus
107 extern "C" {
108 #endif
109 
110 /*
111  * Revision information.  This is the release date in YYYYMMDD format.
112  * It can change every day so the right thing to do with it is use it
113  * in preprocessor commands such as "#if (__RES > 19931104)".  Do not
114  * compare for equality; rather, use it to determine whether your resolver
115  * is new enough to contain a certain feature.
116  */
117 
118 #define	__RES	20090302
119 
120 #define	RES_SET_H_ERRNO(r, x)	__h_errno_set(r, x)
121 struct __res_state;					/* forward */
122 
123 void __h_errno_set(struct __res_state *res, int err);
124 
125 /*
126  * Resolver configuration file.
127  * Normally not present, but may contain the address of the
128  * initial name server(s) to query and the domain search list.
129  */
130 
131 #ifndef _PATH_RESCONF
132 #define	_PATH_RESCONF		"/etc/resolv.conf"
133 #endif
134 
135 #ifndef __P
136 #define	__P(x)	x
137 #endif
138 
139 typedef enum { res_goahead, res_nextns, res_modified, res_done, res_error }
140 	res_sendhookact;
141 
142 typedef res_sendhookact (*res_send_qhook)__P((struct sockaddr * const *ns,
143 						const uchar_t **query,
144 						int *querylen,
145 						uchar_t *ans,
146 						int anssiz,
147 						int *resplen));
148 
149 typedef res_sendhookact (*res_send_rhook)__P((const struct sockaddr *ns,
150 						const uchar_t *query,
151 						int querylen,
152 						uchar_t *ans,
153 						int anssiz,
154 						int *resplen));
155 
156 struct res_sym {
157 	int		number;	   /* Identifying number, like T_MX */
158 	const char 	*name;	   /* Its symbolic name, like "MX" */
159 	const char 	*humanname; /* Its fun name, like "mail exchanger" */
160 };
161 
162 /*
163  * Global defines and variables for resolver stub.
164  */
165 /* ADDRSORT and MAXADDR retained for compatibility; not used */
166 #define	ADDRSORT	1	/* enable the address-sorting option */
167 #define	MAXADDR		10	/* max # addresses to sort by */
168 
169 #define	MAXNS			3	/* max # name servers we'll track */
170 #define	MAXDFLSRCH		3	/* # default domain levels to try */
171 #define	MAXDNSRCH		6	/* max # domains in search path */
172 #define	LOCALDOMAINPARTS	2	/* min levels in name that is "local" */
173 
174 #define	RES_TIMEOUT		5	/* min. seconds between retries */
175 #define	MAXRESOLVSORT		10	/* number of net to sort on */
176 #define	RES_MAXNDOTS		15	/* should reflect bit field size */
177 #define	RES_MAXRETRANS		30	/* only for resolv.conf/RES_OPTIONS */
178 #define	RES_MAXRETRY		5	/* only for resolv.conf/RES_OPTIONS */
179 #define	RES_DFLRETRY		2	/* Default #/tries. */
180 #define	RES_MAXTIME		65535	/* Infinity, in milliseconds. */
181 
182 struct __res_state_ext;
183 
184 struct __res_state {
185 	int	retrans;		/* retransmission time interval */
186 	int	retry;			/* number of times to retransmit */
187 #ifdef __sun
188 	uint_t	options;		/* option flags - see below. */
189 #else
190 	ulong_t	options;		/* option flags - see below. */
191 #endif
192 	int	nscount;		/* number of name servers */
193 	struct sockaddr_in
194 		nsaddr_list[MAXNS];	/* address of name server */
195 #define	nsaddr	nsaddr_list[0]		/* for backward compatibility */
196 	ushort_t id;			/* current packet id */
197 	char	*dnsrch[MAXDNSRCH+1];	/* components of domain to search */
198 	char	defdname[256];		/* default domain (deprecated) */
199 #ifdef __sun
200 	uint_t	pfcode;			/* RES_PRF_ flags - see below. */
201 #else
202 	ulong_t	pfcode;			/* RES_PRF_ flags - see below. */
203 #endif
204 	unsigned ndots:4;		/* threshold for initial abs. query */
205 	unsigned nsort:4;		/* number of elements in sort_list[] */
206 	char	unused[3];
207 	struct {
208 		struct in_addr	addr;
209 		unsigned int	mask;
210 	} sort_list[MAXRESOLVSORT];
211 	res_send_qhook qhook;		/* query hook */
212 	res_send_rhook rhook;		/* response hook */
213 	int		res_h_errno;	/* last one set for this context */
214 	int		_vcsock;	/* PRIVATE: for res_send VC i/o */
215 	uint_t	_flags;		/* PRIVATE: see below */
216 	uint_t	_pad;			/* make _u 64 bit aligned */
217 	union {
218 		/* On an 32-bit arch this means 512b total. */
219 		char	pad[72 - 4*sizeof (int) - 2*sizeof (void *)];
220 		struct {
221 			uint16_t		nscount;
222 			uint16_t		nstimes[MAXNS];	/* ms. */
223 			int			nssocks[MAXNS];
224 			struct __res_state_ext *ext;	/* extention for IPv6 */
225 			uchar_t	_rnd[16];	/* PRIVATE: random state */
226 		} _ext;
227 	} _u;
228 };
229 
230 typedef	struct __res_state	*res_state;
231 
232 union res_sockaddr_union {
233 	struct sockaddr_in	sin;
234 #ifdef IN6ADDR_ANY_INIT
235 	struct sockaddr_in6	sin6;
236 #endif
237 #ifdef ISC_ALIGN64
238 	int64_t			__align64;	/* 64bit alignment */
239 #else
240 	int32_t			__align32;	/* 32bit alignment */
241 #endif
242 	char			__space[128];   /* max size */
243 };
244 
245 /*
246  * Resolver flags (used to be discrete per-module statics ints).
247  */
248 #define	RES_F_VC	0x00000001	/* socket is TCP */
249 #define	RES_F_CONN	0x00000002	/* socket is connected */
250 #define	RES_F_EDNS0ERR	0x00000004	/* EDNS0 caused errors */
251 #define	RES_F__UNUSED	0x00000008	/* (unused) */
252 #define	RES_F_LASTMASK	0x000000F0	/* ordinal server of last res_nsend */
253 #define	RES_F_LASTSHIFT	4		/* bit position of LASTMASK "flag" */
254 #define	RES_GETLAST(res) (((res)._flags & RES_F_LASTMASK) >> RES_F_LASTSHIFT)
255 
256 /* res_findzonecut2() options */
257 #define	RES_EXHAUSTIVE	0x00000001	/* always do all queries */
258 #define	RES_IPV4ONLY	0x00000002	/* IPv4 only */
259 #define	RES_IPV6ONLY	0x00000004	/* IPv6 only */
260 
261 /*
262  * Resolver options (keep these in synch with res_debug.c, please)
263  */
264 #define	RES_INIT	0x00000001	/* address initialized */
265 #define	RES_DEBUG	0x00000002	/* print debug messages */
266 #define	RES_AAONLY	0x00000004	/* authoritative answers only (!IMPL) */
267 #define	RES_USEVC	0x00000008	/* use virtual circuit */
268 #define	RES_PRIMARY	0x00000010	/* query primary server only (!IMPL) */
269 #define	RES_IGNTC	0x00000020	/* ignore trucation errors */
270 #define	RES_RECURSE	0x00000040	/* recursion desired */
271 #define	RES_DEFNAMES	0x00000080	/* use default domain name */
272 #define	RES_STAYOPEN	0x00000100	/* Keep TCP socket open */
273 #define	RES_DNSRCH	0x00000200	/* search up local domain tree */
274 #define	RES_INSECURE1	0x00000400	/* type 1 security disabled */
275 #define	RES_INSECURE2	0x00000800	/* type 2 security disabled */
276 #define	RES_NOALIASES	0x00001000	/* shuts off HOSTALIASES feature */
277 #define	RES_USE_INET6	0x00002000	/* use/map IPv6 in gethostbyname() */
278 #define	RES_ROTATE	0x00004000	/* rotate ns list after each query */
279 #define	RES_NOCHECKNAME	0x00008000	/* do not check names for sanity. */
280 #define	RES_KEEPTSIG	0x00010000	/* do not strip TSIG records */
281 #define	RES_BLAST	0x00020000	/* blast all recursive servers */
282 #define	RES_NO_NIBBLE	0x00040000	/* disable IPv6 nibble mode reverse */
283 #define	RES_NO_BITSTRING 0x00080000	/* disable IPv6 bitstring mode revrse */
284 #define	RES_NOTLDQUERY	0x00100000	/* don't unqualified name as a tld */
285 #define	RES_USE_DNSSEC	0x00200000	/* use DNSSEC using OK bit in OPT */
286 /* KAME extensions: use higher bit to avoid conflict with ISC use */
287 #define	RES_USE_DNAME	0x10000000	/* use DNAME */
288 #define	RES_USE_EDNS0	0x40000000	/* use EDNS0 if configured */
289 #define	RES_NO_NIBBLE2	0x80000000	/* disable alternate nibble lookup */
290 
291 #define	RES_DEFAULT	(RES_RECURSE | RES_DEFNAMES | RES_DNSRCH)
292 
293 /*
294  * Resolver "pfcode" values.  Used by dig.
295  */
296 #define	RES_PRF_STATS	0x00000001
297 #define	RES_PRF_UPDATE	0x00000002
298 #define	RES_PRF_CLASS   0x00000004
299 #define	RES_PRF_CMD		0x00000008
300 #define	RES_PRF_QUES	0x00000010
301 #define	RES_PRF_ANS		0x00000020
302 #define	RES_PRF_AUTH	0x00000040
303 #define	RES_PRF_ADD		0x00000080
304 #define	RES_PRF_HEAD1	0x00000100
305 #define	RES_PRF_HEAD2	0x00000200
306 #define	RES_PRF_TTLID	0x00000400
307 #define	RES_PRF_HEADX	0x00000800
308 #define	RES_PRF_QUERY	0x00001000
309 #define	RES_PRF_REPLY	0x00002000
310 #define	RES_PRF_INIT	0x00004000
311 #define	RES_PRF_TRUNC	0x00008000
312 /*			0x00010000	*/
313 
314 /* Things involving an internal (static) resolver context. */
315 #ifdef _REENTRANT
316 extern struct __res_state *__res_state(void);
317 #define	_res (*__res_state())
318 #else
319 #ifndef __BIND_NOSTATIC
320 extern struct __res_state _res;
321 #endif
322 #endif
323 
324 #ifndef __BIND_NOSTATIC
325 void		fp_nquery __P((const uchar_t *, int, FILE *));
326 void		fp_query __P((const uchar_t *, FILE *));
327 const char *hostalias __P((const char *));
328 void		p_query __P((const uchar_t *));
329 void		res_close __P((void));
330 int		res_init __P((void));
331 int		res_isourserver __P((const struct sockaddr_in *));
332 int		res_mkquery __P((int, const char *, int, int, const uchar_t *,
333 				int, const uchar_t *, uchar_t *, int));
334 int		res_query	__P((const char *, int, int, uchar_t *, int));
335 int		res_querydomain __P((const char *, const char *, int, int,
336 				uchar_t *, int));
337 int		res_search __P((const char *, int, int, uchar_t *, int));
338 int		res_send __P((const uchar_t *, int, uchar_t *, int));
339 int		res_sendsigned __P((const uchar_t *, int, ns_tsig_key *,
340 				    uchar_t *, int));
341 #endif	/* __BIND_NOSTATIC */
342 
343 extern const struct res_sym __p_key_syms[];
344 extern const struct res_sym __p_cert_syms[];
345 extern const struct res_sym __p_class_syms[];
346 extern const struct res_sym __p_type_syms[];
347 extern const struct res_sym __p_rcode_syms[];
348 
349 int		res_hnok __P((const char *));
350 int		res_ownok __P((const char *));
351 int		res_mailok __P((const char *));
352 int		res_dnok __P((const char *));
353 int		sym_ston __P((const struct res_sym *, const char *, int *));
354 const char	*sym_ntos __P((const struct res_sym *, int, int *));
355 const char	*sym_ntop __P((const struct res_sym *, int, int *));
356 int		b64_ntop __P((uchar_t const *, size_t, char *, size_t));
357 int		b64_pton __P((char const *, uchar_t *, size_t));
358 int		loc_aton __P((const char *ascii, uchar_t *binary));
359 const char	*loc_ntoa __P((const uchar_t *binary, char *ascii));
360 int		dn_skipname __P((const uchar_t *, const uchar_t *));
361 void		putlong __P((unsigned int, uchar_t *));
362 void		putshort __P((unsigned short, uchar_t *));
363 const char	*p_class __P((int));
364 const char	*p_time __P((unsigned int));
365 const char	*p_type __P((int));
366 const char	*p_rcode __P((int));
367 const char	*p_sockun __P((union res_sockaddr_union, char *, size_t));
368 const uchar_t	*p_cdnname __P((const uchar_t *, const uchar_t *, int,
369 			FILE *));
370 const uchar_t	*p_cdname __P((const uchar_t *, const uchar_t *, FILE *));
371 const uchar_t	*p_fqnname __P((const uchar_t *cp, const uchar_t *msg,
372 			int, char *, int));
373 const uchar_t	*p_fqname __P((const uchar_t *, const uchar_t *, FILE *));
374 const char	*p_option __P((uint_t option));
375 char		*p_secstodate __P((uint_t));
376 int		dn_count_labels __P((const char *));
377 int		dn_comp __P((const char *, uchar_t *, int,
378 				uchar_t **, uchar_t **));
379 int		dn_expand __P((const uchar_t *, const uchar_t *,
380 			const uchar_t *, char *, int));
381 void		res_rndinit __P((res_state));
382 uint_t		res_randomid __P((void));
383 uint_t		res_nrandomid __P((res_state));
384 int		res_nameinquery __P((const char *, int, int,
385 				const uchar_t *, const uchar_t *));
386 int		res_queriesmatch __P((const uchar_t *, const uchar_t *,
387 				const uchar_t *, const uchar_t *));
388 const char	*p_section __P((int section, int opcode));
389 
390 
391 /* Things involving a resolver context. */
392 int		res_ninit __P((res_state));
393 int		res_nisourserver __P((const res_state,
394 				const struct sockaddr_in *));
395 void	fp_resstat __P((const res_state, FILE *));
396 void	res_pquery	__P((const res_state, const uchar_t *, int, FILE *));
397 const char	*res_hostalias __P((const res_state, const char *,
398 				char *, size_t));
399 int		res_nquery __P((res_state,
400 				const char *, int, int, uchar_t *, int));
401 int		res_nsearch __P((res_state, const char *, int,
402 				int, uchar_t *, int));
403 int		res_nquerydomain __P((res_state,
404 				const char *, const char *, int, int,
405 				uchar_t *, int));
406 int		res_nmkquery __P((res_state,
407 				int, const char *, int, int, const uchar_t *,
408 				int, const uchar_t *, uchar_t *, int));
409 int		res_nsend __P((res_state, const uchar_t *, int, uchar_t *,
410 				int));
411 int		res_nsendsigned __P((res_state, const uchar_t *, int,
412 				ns_tsig_key *, uchar_t *, int));
413 int		res_findzonecut __P((res_state, const char *, ns_class, int,
414 				char *, size_t, struct in_addr *, int));
415 int		res_findzonecut2 __P((res_state, const char *, ns_class, int,
416 				char *, size_t, union res_sockaddr_union *,
417 				int));
418 void		res_nclose __P((res_state));
419 int		res_nopt __P((res_state, int, uchar_t *, int, int));
420 int		res_nopt_rdata __P((res_state, int, uchar_t *, int, uchar_t *,
421 				    ushort_t, ushort_t, uchar_t *));
422 void		res_send_setqhook __P((res_send_qhook hook));
423 void		res_send_setrhook __P((res_send_rhook hook));
424 int		__res_vinit __P((res_state, int));
425 void		res_destroyservicelist __P((void));
426 const char 	*res_servicename __P((uint16_t port, const char *proto));
427 const char 	*res_protocolname __P((int num));
428 void		res_destroyprotolist __P((void));
429 void		res_buildprotolist __P((void));
430 const char 	*res_get_nibblesuffix __P((res_state));
431 const char 	*res_get_nibblesuffix2 __P((res_state));
432 void		res_ndestroy __P((res_state));
433 uint16_t	res_nametoclass __P((const char *buf, int *success));
434 uint16_t	res_nametotype __P((const char *buf, int *success));
435 void		res_setservers __P((res_state,
436 				    const union res_sockaddr_union *, int));
437 int		res_getservers __P((res_state,
438 				    union res_sockaddr_union *, int));
439 
440 
441 #ifdef	__cplusplus
442 }
443 #endif
444 
445 #endif /* !_RESOLV_H_ */
446