1 /*
2  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7  *
8  * See the COPYRIGHT file distributed with this work for additional
9  * information regarding copyright ownership.
10  */
11 
12 #ifndef DNS_FORWARD_H
13 #define DNS_FORWARD_H 1
14 
15 /*! \file dns/forward.h */
16 
17 #include <isc/lang.h>
18 #include <isc/result.h>
19 #include <isc/sockaddr.h>
20 
21 #include <dns/types.h>
22 
23 ISC_LANG_BEGINDECLS
24 
25 struct dns_forwarder {
26 	isc_sockaddr_t addr;
27 	isc_dscp_t     dscp;
28 	ISC_LINK(dns_forwarder_t) link;
29 };
30 
31 typedef ISC_LIST(struct dns_forwarder) dns_forwarderlist_t;
32 
33 struct dns_forwarders {
34 	dns_forwarderlist_t fwdrs;
35 	dns_fwdpolicy_t	    fwdpolicy;
36 };
37 
38 isc_result_t
39 dns_fwdtable_create(isc_mem_t *mctx, dns_fwdtable_t **fwdtablep);
40 /*%<
41  * Creates a new forwarding table.
42  *
43  * Requires:
44  * \li 	mctx is a valid memory context.
45  * \li	fwdtablep != NULL && *fwdtablep == NULL
46  *
47  * Returns:
48  * \li	#ISC_R_SUCCESS
49  * \li	#ISC_R_NOMEMORY
50  */
51 
52 isc_result_t
53 dns_fwdtable_addfwd(dns_fwdtable_t *fwdtable, const dns_name_t *name,
54 		    dns_forwarderlist_t *fwdrs, dns_fwdpolicy_t policy);
55 isc_result_t
56 dns_fwdtable_add(dns_fwdtable_t *fwdtable, const dns_name_t *name,
57 		 isc_sockaddrlist_t *addrs, dns_fwdpolicy_t policy);
58 /*%<
59  * Adds an entry to the forwarding table.  The entry associates
60  * a domain with a list of forwarders and a forwarding policy.  The
61  * addrs/fwdrs list is copied if not empty, so the caller should free
62  * its copy.
63  *
64  * Requires:
65  * \li	fwdtable is a valid forwarding table.
66  * \li	name is a valid name
67  * \li	addrs/fwdrs is a valid list of isc_sockaddr/dns_forwarder
68  *      structures, which may be empty.
69  *
70  * Returns:
71  * \li	#ISC_R_SUCCESS
72  * \li	#ISC_R_NOMEMORY
73  */
74 
75 isc_result_t
76 dns_fwdtable_delete(dns_fwdtable_t *fwdtable, const dns_name_t *name);
77 /*%<
78  * Removes an entry for 'name' from the forwarding table.  If an entry
79  * that exactly matches 'name' does not exist, ISC_R_NOTFOUND will be returned.
80  *
81  * Requires:
82  * \li	fwdtable is a valid forwarding table.
83  * \li	name is a valid name
84  *
85  * Returns:
86  * \li	#ISC_R_SUCCESS
87  * \li	#ISC_R_NOTFOUND
88  */
89 
90 isc_result_t
91 dns_fwdtable_find(dns_fwdtable_t *fwdtable, const dns_name_t *name,
92 		  dns_name_t *foundname, dns_forwarders_t **forwardersp);
93 /*%<
94  * Finds a domain in the forwarding table.  The closest matching parent
95  * domain is returned.
96  *
97  * Requires:
98  * \li	fwdtable is a valid forwarding table.
99  * \li	name is a valid name
100  * \li	forwardersp != NULL && *forwardersp == NULL
101  * \li	foundname to be NULL or a valid name with buffer.
102  *
103  * Returns:
104  * \li	#ISC_R_SUCCESS
105  * \li	#ISC_R_NOTFOUND
106  */
107 
108 void
109 dns_fwdtable_destroy(dns_fwdtable_t **fwdtablep);
110 /*%<
111  * Destroys a forwarding table.
112  *
113  * Requires:
114  * \li	fwtablep != NULL && *fwtablep != NULL
115  *
116  * Ensures:
117  * \li	all memory associated with the forwarding table is freed.
118  */
119 
120 ISC_LANG_ENDDECLS
121 
122 #endif /* DNS_FORWARD_H */
123