1 /*	$NetBSD: forward.h,v 1.5 2014/12/10 04:37:58 christos Exp $	*/
2 
3 /*
4  * Copyright (C) 2004-2007, 2009, 2013  Internet Systems Consortium, Inc. ("ISC")
5  * Copyright (C) 2000, 2001  Internet Software Consortium.
6  *
7  * Permission to use, copy, modify, and/or distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17  * PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 /* Id: forward.h,v 1.13 2009/09/02 23:48:02 tbox Exp  */
21 
22 #ifndef DNS_FORWARD_H
23 #define DNS_FORWARD_H 1
24 
25 /*! \file dns/forward.h */
26 
27 #include <isc/lang.h>
28 #include <isc/result.h>
29 
30 #include <dns/types.h>
31 
32 ISC_LANG_BEGINDECLS
33 
34 struct dns_forwarder {
35 	isc_sockaddr_t			addr;
36 	isc_dscp_t			dscp;
37 	ISC_LINK(dns_forwarder_t)	link;
38 };
39 
40 typedef ISC_LIST(struct dns_forwarder)	dns_forwarderlist_t;
41 
42 struct dns_forwarders {
43 	dns_forwarderlist_t	fwdrs;
44 	dns_fwdpolicy_t		fwdpolicy;
45 };
46 
47 isc_result_t
48 dns_fwdtable_create(isc_mem_t *mctx, dns_fwdtable_t **fwdtablep);
49 /*%<
50  * Creates a new forwarding table.
51  *
52  * Requires:
53  * \li 	mctx is a valid memory context.
54  * \li	fwdtablep != NULL && *fwdtablep == NULL
55  *
56  * Returns:
57  * \li	#ISC_R_SUCCESS
58  * \li	#ISC_R_NOMEMORY
59  */
60 
61 isc_result_t
62 dns_fwdtable_addfwd(dns_fwdtable_t *fwdtable, dns_name_t *name,
63 		    dns_forwarderlist_t *fwdrs, dns_fwdpolicy_t policy);
64 isc_result_t
65 dns_fwdtable_add(dns_fwdtable_t *fwdtable, dns_name_t *name,
66 		 isc_sockaddrlist_t *addrs, dns_fwdpolicy_t policy);
67 /*%<
68  * Adds an entry to the forwarding table.  The entry associates
69  * a domain with a list of forwarders and a forwarding policy.  The
70  * addrs/fwdrs list is copied if not empty, so the caller should free
71  * its copy.
72  *
73  * Requires:
74  * \li	fwdtable is a valid forwarding table.
75  * \li	name is a valid name
76  * \li	addrs/fwdrs is a valid list of isc_sockaddr/dns_forwarder
77  *      structures, which may be empty.
78  *
79  * Returns:
80  * \li	#ISC_R_SUCCESS
81  * \li	#ISC_R_NOMEMORY
82  */
83 
84 isc_result_t
85 dns_fwdtable_delete(dns_fwdtable_t *fwdtable, dns_name_t *name);
86 /*%<
87  * Removes an entry for 'name' from the forwarding table.  If an entry
88  * that exactly matches 'name' does not exist, ISC_R_NOTFOUND will be returned.
89  *
90  * Requires:
91  * \li	fwdtable is a valid forwarding table.
92  * \li	name is a valid name
93  *
94  * Returns:
95  * \li	#ISC_R_SUCCESS
96  * \li	#ISC_R_NOTFOUND
97  */
98 
99 isc_result_t
100 dns_fwdtable_find(dns_fwdtable_t *fwdtable, dns_name_t *name,
101 		  dns_forwarders_t **forwardersp);
102 /*%<
103  * Finds a domain in the forwarding table.  The closest matching parent
104  * domain is returned.
105  *
106  * Requires:
107  * \li	fwdtable is a valid forwarding table.
108  * \li	name is a valid name
109  * \li	forwardersp != NULL && *forwardersp == NULL
110  *
111  * Returns:
112  * \li	#ISC_R_SUCCESS
113  * \li	#ISC_R_NOTFOUND
114  */
115 
116 isc_result_t
117 dns_fwdtable_find2(dns_fwdtable_t *fwdtable, dns_name_t *name,
118 		   dns_name_t *foundname, dns_forwarders_t **forwardersp);
119 /*%<
120  * Finds a domain in the forwarding table.  The closest matching parent
121  * domain is returned.
122  *
123  * Requires:
124  * \li	fwdtable is a valid forwarding table.
125  * \li	name is a valid name
126  * \li	forwardersp != NULL && *forwardersp == NULL
127  * \li	foundname to be NULL or a valid name with buffer.
128  *
129  * Returns:
130  * \li	#ISC_R_SUCCESS
131  * \li	#ISC_R_NOTFOUND
132  */
133 
134 void
135 dns_fwdtable_destroy(dns_fwdtable_t **fwdtablep);
136 /*%<
137  * Destroys a forwarding table.
138  *
139  * Requires:
140  * \li	fwtablep != NULL && *fwtablep != NULL
141  *
142  * Ensures:
143  * \li	all memory associated with the forwarding table is freed.
144  */
145 
146 ISC_LANG_ENDDECLS
147 
148 #endif /* DNS_FORWARD_H */
149