xref: /freebsd/contrib/unbound/services/view.h (revision 3005e0a300309ec169f8e42181b39865e910da6c)
1bc892140SDag-Erling Smørgrav /*
2bc892140SDag-Erling Smørgrav  * services/view.h - named views containing local zones authority service.
3bc892140SDag-Erling Smørgrav  *
4bc892140SDag-Erling Smørgrav  * Copyright (c) 2016, NLnet Labs. All rights reserved.
5bc892140SDag-Erling Smørgrav  *
6bc892140SDag-Erling Smørgrav  * This software is open source.
7bc892140SDag-Erling Smørgrav  *
8bc892140SDag-Erling Smørgrav  * Redistribution and use in source and binary forms, with or without
9bc892140SDag-Erling Smørgrav  * modification, are permitted provided that the following conditions
10bc892140SDag-Erling Smørgrav  * are met:
11bc892140SDag-Erling Smørgrav  *
12bc892140SDag-Erling Smørgrav  * Redistributions of source code must retain the above copyright notice,
13bc892140SDag-Erling Smørgrav  * this list of conditions and the following disclaimer.
14bc892140SDag-Erling Smørgrav  *
15bc892140SDag-Erling Smørgrav  * Redistributions in binary form must reproduce the above copyright notice,
16bc892140SDag-Erling Smørgrav  * this list of conditions and the following disclaimer in the documentation
17bc892140SDag-Erling Smørgrav  * and/or other materials provided with the distribution.
18bc892140SDag-Erling Smørgrav  *
19bc892140SDag-Erling Smørgrav  * Neither the name of the NLNET LABS nor the names of its contributors may
20bc892140SDag-Erling Smørgrav  * be used to endorse or promote products derived from this software without
21bc892140SDag-Erling Smørgrav  * specific prior written permission.
22bc892140SDag-Erling Smørgrav  *
23bc892140SDag-Erling Smørgrav  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24bc892140SDag-Erling Smørgrav  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25bc892140SDag-Erling Smørgrav  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26bc892140SDag-Erling Smørgrav  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27bc892140SDag-Erling Smørgrav  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28bc892140SDag-Erling Smørgrav  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
29bc892140SDag-Erling Smørgrav  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30bc892140SDag-Erling Smørgrav  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31bc892140SDag-Erling Smørgrav  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32bc892140SDag-Erling Smørgrav  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33bc892140SDag-Erling Smørgrav  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34bc892140SDag-Erling Smørgrav  */
35bc892140SDag-Erling Smørgrav 
36bc892140SDag-Erling Smørgrav /**
37bc892140SDag-Erling Smørgrav  * \file
38bc892140SDag-Erling Smørgrav  *
39bc892140SDag-Erling Smørgrav  * This file contains functions to enable named views that can hold local zone
40bc892140SDag-Erling Smørgrav  * authority service.
41bc892140SDag-Erling Smørgrav  */
42bc892140SDag-Erling Smørgrav 
43bc892140SDag-Erling Smørgrav #ifndef SERVICES_VIEW_H
44bc892140SDag-Erling Smørgrav #define SERVICES_VIEW_H
45bc892140SDag-Erling Smørgrav #include "util/rbtree.h"
46bc892140SDag-Erling Smørgrav #include "util/locks.h"
47bc892140SDag-Erling Smørgrav struct regional;
48bc892140SDag-Erling Smørgrav struct config_file;
49bc892140SDag-Erling Smørgrav struct config_view;
50bc892140SDag-Erling Smørgrav 
51bc892140SDag-Erling Smørgrav 
52bc892140SDag-Erling Smørgrav /**
53bc892140SDag-Erling Smørgrav  * Views storage, shared.
54bc892140SDag-Erling Smørgrav  */
55bc892140SDag-Erling Smørgrav struct views {
56bc892140SDag-Erling Smørgrav 	/** lock on the view tree */
57*3005e0a3SDag-Erling Smørgrav 	lock_rw_type lock;
58bc892140SDag-Erling Smørgrav 	/** rbtree of struct view */
59*3005e0a3SDag-Erling Smørgrav 	rbtree_type vtree;
60bc892140SDag-Erling Smørgrav };
61bc892140SDag-Erling Smørgrav 
62bc892140SDag-Erling Smørgrav /**
63bc892140SDag-Erling Smørgrav  * View. Named structure holding local authority zones.
64bc892140SDag-Erling Smørgrav  */
65bc892140SDag-Erling Smørgrav struct view {
66bc892140SDag-Erling Smørgrav 	/** rbtree node, key is name */
67*3005e0a3SDag-Erling Smørgrav 	rbnode_type node;
68bc892140SDag-Erling Smørgrav 	/** view name.
69bc892140SDag-Erling Smørgrav 	 * Has to be right after rbnode_t due to pointer arithmatic in
70bc892140SDag-Erling Smørgrav 	 * view_create's lock protect */
71bc892140SDag-Erling Smørgrav 	char* name;
72bc892140SDag-Erling Smørgrav 	/** view specific local authority zones */
73bc892140SDag-Erling Smørgrav 	struct local_zones* local_zones;
74bc892140SDag-Erling Smørgrav 	/** Fallback to global local_zones when there is no match in the view
75bc892140SDag-Erling Smørgrav 	 * specific tree. 1 for yes, 0 for no */
76bc892140SDag-Erling Smørgrav 	int isfirst;
77bc892140SDag-Erling Smørgrav 	/** lock on the data in the structure
78*3005e0a3SDag-Erling Smørgrav 	 * For the node and name you need to also hold the views_tree lock to
79*3005e0a3SDag-Erling Smørgrav 	 * change them. */
80*3005e0a3SDag-Erling Smørgrav 	lock_rw_type lock;
81bc892140SDag-Erling Smørgrav };
82bc892140SDag-Erling Smørgrav 
83bc892140SDag-Erling Smørgrav 
84bc892140SDag-Erling Smørgrav /**
85bc892140SDag-Erling Smørgrav  * Create views storage
86bc892140SDag-Erling Smørgrav  * @return new struct or NULL on error.
87bc892140SDag-Erling Smørgrav  */
88bc892140SDag-Erling Smørgrav struct views* views_create(void);
89bc892140SDag-Erling Smørgrav 
90bc892140SDag-Erling Smørgrav /**
91bc892140SDag-Erling Smørgrav  * Delete views storage
92bc892140SDag-Erling Smørgrav  * @param v: views to delete.
93bc892140SDag-Erling Smørgrav  */
94bc892140SDag-Erling Smørgrav void views_delete(struct views* v);
95bc892140SDag-Erling Smørgrav 
96bc892140SDag-Erling Smørgrav /**
97bc892140SDag-Erling Smørgrav  * Apply config settings;
98bc892140SDag-Erling Smørgrav  * Takes care of locking.
99bc892140SDag-Erling Smørgrav  * @param v: view is set up.
100bc892140SDag-Erling Smørgrav  * @param cfg: config data.
101bc892140SDag-Erling Smørgrav  * @return false on error.
102bc892140SDag-Erling Smørgrav  */
103bc892140SDag-Erling Smørgrav int views_apply_cfg(struct views* v, struct config_file* cfg);
104bc892140SDag-Erling Smørgrav 
105bc892140SDag-Erling Smørgrav /**
106bc892140SDag-Erling Smørgrav  * Compare two view entries in rbtree. Sort canonical.
107bc892140SDag-Erling Smørgrav  * @param v1: view 1
108bc892140SDag-Erling Smørgrav  * @param v2: view 2
109bc892140SDag-Erling Smørgrav  * @return: negative, positive or 0 comparison value.
110bc892140SDag-Erling Smørgrav  */
111bc892140SDag-Erling Smørgrav int view_cmp(const void* v1, const void* v2);
112bc892140SDag-Erling Smørgrav 
113bc892140SDag-Erling Smørgrav /**
114bc892140SDag-Erling Smørgrav  * Delete one view
115bc892140SDag-Erling Smørgrav  * @param v: view to delete.
116bc892140SDag-Erling Smørgrav  */
117bc892140SDag-Erling Smørgrav void view_delete(struct view* v);
118bc892140SDag-Erling Smørgrav 
119bc892140SDag-Erling Smørgrav /**
120bc892140SDag-Erling Smørgrav  * Debug helper. Print all views
121bc892140SDag-Erling Smørgrav  * Takes care of locking.
122bc892140SDag-Erling Smørgrav  * @param v: the views tree
123bc892140SDag-Erling Smørgrav  */
124bc892140SDag-Erling Smørgrav void views_print(struct views* v);
125bc892140SDag-Erling Smørgrav 
126bc892140SDag-Erling Smørgrav /* Find a view by name.
127bc892140SDag-Erling Smørgrav  * @param vs: views
128bc892140SDag-Erling Smørgrav  * @param name: name of the view we are looking for
129bc892140SDag-Erling Smørgrav  * @param write: 1 for obtaining write lock on found view, 0 for read lock
130bc892140SDag-Erling Smørgrav  * @return: locked view or NULL.
131bc892140SDag-Erling Smørgrav  */
132bc892140SDag-Erling Smørgrav struct view* views_find_view(struct views* vs, const char* name, int write);
133bc892140SDag-Erling Smørgrav 
134bc892140SDag-Erling Smørgrav #endif /* SERVICES_VIEW_H */
135