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