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_ZT_H
13 #define DNS_ZT_H 1
14 
15 /*! \file dns/zt.h */
16 
17 #include <stdbool.h>
18 
19 #include <isc/lang.h>
20 
21 #include <dns/types.h>
22 
23 #define DNS_ZTFIND_NOEXACT 0x01
24 #define DNS_ZTFIND_MIRROR  0x02
25 
26 ISC_LANG_BEGINDECLS
27 
28 typedef isc_result_t (*dns_zt_allloaded_t)(void *arg);
29 /*%<
30  * Method prototype: when all pending zone loads are complete,
31  * the zone table can inform the caller via a callback function with
32  * this signature.
33  */
34 
35 typedef isc_result_t (*dns_zt_zoneloaded_t)(dns_zt_t *zt, dns_zone_t *zone,
36 					    isc_task_t *task);
37 /*%<
38  * Method prototype: when a zone finishes loading, the zt object
39  * can be informed via a callback function with this signature.
40  */
41 
42 isc_result_t
43 dns_zt_create(isc_mem_t *mctx, dns_rdataclass_t rdclass, dns_zt_t **zt);
44 /*%<
45  * Creates a new zone table.
46  *
47  * Requires:
48  * \li	'mctx' to be initialized.
49  *
50  * Returns:
51  * \li	#ISC_R_SUCCESS on success.
52  * \li	#ISC_R_NOMEMORY
53  */
54 
55 isc_result_t
56 dns_zt_mount(dns_zt_t *zt, dns_zone_t *zone);
57 /*%<
58  * Mounts the zone on the zone table.
59  *
60  * Requires:
61  * \li	'zt' to be valid
62  * \li	'zone' to be valid
63  *
64  * Returns:
65  * \li	#ISC_R_SUCCESS
66  * \li	#ISC_R_EXISTS
67  * \li	#ISC_R_NOSPACE
68  * \li	#ISC_R_NOMEMORY
69  */
70 
71 isc_result_t
72 dns_zt_unmount(dns_zt_t *zt, dns_zone_t *zone);
73 /*%<
74  * Unmount the given zone from the table.
75  *
76  * Requires:
77  * 	'zt' to be valid
78  * \li	'zone' to be valid
79  *
80  * Returns:
81  * \li	#ISC_R_SUCCESS
82  * \li	#ISC_R_NOTFOUND
83  * \li	#ISC_R_NOMEMORY
84  */
85 
86 isc_result_t
87 dns_zt_find(dns_zt_t *zt, const dns_name_t *name, unsigned int options,
88 	    dns_name_t *foundname, dns_zone_t **zone);
89 /*%<
90  * Find the best match for 'name' in 'zt'.  If foundname is non NULL
91  * then the name of the zone found is returned.
92  *
93  * Notes:
94  * \li	If the DNS_ZTFIND_NOEXACT is set, the best partial match (if any)
95  *	to 'name' will be returned.
96  *
97  * Requires:
98  * \li	'zt' to be valid
99  * \li	'name' to be valid
100  * \li	'foundname' to be initialized and associated with a fixedname or NULL
101  * \li	'zone' to be non NULL and '*zone' to be NULL
102  *
103  * Returns:
104  * \li	#ISC_R_SUCCESS
105  * \li	#DNS_R_PARTIALMATCH
106  * \li	#ISC_R_NOTFOUND
107  * \li	#ISC_R_NOSPACE
108  */
109 
110 void
111 dns_zt_detach(dns_zt_t **ztp);
112 /*%<
113  * Detach the given zonetable, if the reference count goes to zero the
114  * zonetable will be freed.  In either case 'ztp' is set to NULL.
115  *
116  * Requires:
117  * \li	'*ztp' to be valid
118  */
119 
120 void
121 dns_zt_flushanddetach(dns_zt_t **ztp);
122 /*%<
123  * Detach the given zonetable, if the reference count goes to zero the
124  * zonetable will be flushed and then freed.  In either case 'ztp' is
125  * set to NULL.
126  *
127  * Requires:
128  * \li	'*ztp' to be valid
129  */
130 
131 void
132 dns_zt_attach(dns_zt_t *zt, dns_zt_t **ztp);
133 /*%<
134  * Attach 'zt' to '*ztp'.
135  *
136  * Requires:
137  * \li	'zt' to be valid
138  * \li	'*ztp' to be NULL
139  */
140 
141 isc_result_t
142 dns_zt_load(dns_zt_t *zt, bool stop, bool newonly);
143 
144 isc_result_t
145 dns_zt_asyncload(dns_zt_t *zt, bool newonly, dns_zt_allloaded_t alldone,
146 		 void *arg);
147 /*%<
148  * Load all zones in the table.  If 'stop' is true,
149  * stop on the first error and return it.  If 'stop'
150  * is false, ignore errors.
151  *
152  * if newonly is set only zones that were never loaded are loaded.
153  * dns_zt_asyncload() loads zones asynchronously; when all
154  * zones in the zone table have finished loaded (or failed due
155  * to errors), the caller is informed by calling 'alldone'
156  * with an argument of 'arg'.
157  *
158  * Requires:
159  * \li	'zt' to be valid
160  */
161 
162 isc_result_t
163 dns_zt_freezezones(dns_zt_t *zt, bool freeze);
164 /*%<
165  * Freeze/thaw updates to master zones.
166  * Any pending updates will be flushed.
167  * Zones will be reloaded on thaw.
168  */
169 
170 isc_result_t
171 dns_zt_apply(dns_zt_t *zt, bool stop, isc_result_t *sub,
172 	     isc_result_t (*action)(dns_zone_t *, void *), void *uap);
173 /*%<
174  * Apply a given 'action' to all zone zones in the table.
175  * If 'stop' is 'true' then walking the zone tree will stop if
176  * 'action' does not return ISC_R_SUCCESS.
177  *
178  * Requires:
179  * \li	'zt' to be valid.
180  * \li	'action' to be non NULL.
181  *
182  * Returns:
183  * \li	ISC_R_SUCCESS if action was applied to all nodes.  If 'stop' is
184  *	false and 'sub' is non NULL then the first error (if any)
185  *	reported by 'action' is returned in '*sub';
186  *	any error code from 'action'.
187  */
188 
189 bool
190 dns_zt_loadspending(dns_zt_t *zt);
191 /*%<
192  * Returns true if and only if there are zones still waiting to
193  * be loaded in zone table 'zt'.
194  *
195  * Requires:
196  * \li	'zt' to be valid.
197  */
198 
199 void
200 dns_zt_setviewcommit(dns_zt_t *zt);
201 /*%<
202  * Commit dns_zone_setview() calls previously made for all zones in this
203  * zone table.
204  *
205  * Requires:
206  *\li	'view' to be valid.
207  */
208 
209 void
210 dns_zt_setviewrevert(dns_zt_t *zt);
211 /*%<
212  * Revert dns_zone_setview() calls previously made for all zones in this
213  * zone table.
214  *
215  * Requires:
216  *\li	'view' to be valid.
217  */
218 
219 ISC_LANG_ENDDECLS
220 
221 #endif /* DNS_ZT_H */
222