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