1313158Sdes/*
2313158Sdes * services/view.h - named views containing local zones authority service.
3313158Sdes *
4313158Sdes * Copyright (c) 2016, NLnet Labs. All rights reserved.
5313158Sdes *
6313158Sdes * This software is open source.
7313158Sdes *
8313158Sdes * Redistribution and use in source and binary forms, with or without
9313158Sdes * modification, are permitted provided that the following conditions
10313158Sdes * are met:
11313158Sdes *
12313158Sdes * Redistributions of source code must retain the above copyright notice,
13313158Sdes * this list of conditions and the following disclaimer.
14313158Sdes *
15313158Sdes * Redistributions in binary form must reproduce the above copyright notice,
16313158Sdes * this list of conditions and the following disclaimer in the documentation
17313158Sdes * and/or other materials provided with the distribution.
18313158Sdes *
19313158Sdes * Neither the name of the NLNET LABS nor the names of its contributors may
20313158Sdes * be used to endorse or promote products derived from this software without
21313158Sdes * specific prior written permission.
22313158Sdes *
23313158Sdes * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24313158Sdes * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25313158Sdes * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26313158Sdes * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27313158Sdes * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28313158Sdes * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
29313158Sdes * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30313158Sdes * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31313158Sdes * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32313158Sdes * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33313158Sdes * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34313158Sdes */
35313158Sdes
36313158Sdes/**
37313158Sdes * \file
38313158Sdes *
39313158Sdes * This file contains functions to enable named views that can hold local zone
40313158Sdes * authority service.
41313158Sdes */
42313158Sdes
43313158Sdes#ifndef SERVICES_VIEW_H
44313158Sdes#define SERVICES_VIEW_H
45313158Sdes#include "util/rbtree.h"
46313158Sdes#include "util/locks.h"
47313158Sdesstruct regional;
48313158Sdesstruct config_file;
49313158Sdesstruct config_view;
50356345Scystruct respip_set;
51313158Sdes
52313158Sdes
53313158Sdes/**
54313158Sdes * Views storage, shared.
55313158Sdes */
56313158Sdesstruct views {
57313158Sdes	/** lock on the view tree */
58356345Scy	lock_rw_type lock;
59313158Sdes	/** rbtree of struct view */
60356345Scy	rbtree_type vtree;
61313158Sdes};
62313158Sdes
63313158Sdes/**
64313158Sdes * View. Named structure holding local authority zones.
65313158Sdes */
66313158Sdesstruct view {
67313158Sdes	/** rbtree node, key is name */
68356345Scy	rbnode_type node;
69313158Sdes	/** view name.
70356345Scy	 * Has to be right after rbnode_t due to pointer arithmetic in
71313158Sdes	 * view_create's lock protect */
72313158Sdes	char* name;
73313158Sdes	/** view specific local authority zones */
74313158Sdes	struct local_zones* local_zones;
75356345Scy	/** response-ip configuration data for this view */
76356345Scy	struct respip_set* respip_set;
77313158Sdes	/** Fallback to global local_zones when there is no match in the view
78313158Sdes	 * specific tree. 1 for yes, 0 for no */
79313158Sdes	int isfirst;
80313158Sdes	/** lock on the data in the structure
81356345Scy	 * For the node and name you need to also hold the views_tree lock to
82356345Scy	 * change them. */
83356345Scy	lock_rw_type lock;
84313158Sdes};
85313158Sdes
86313158Sdes
87313158Sdes/**
88313158Sdes * Create views storage
89313158Sdes * @return new struct or NULL on error.
90313158Sdes */
91313158Sdesstruct views* views_create(void);
92313158Sdes
93313158Sdes/**
94313158Sdes * Delete views storage
95313158Sdes * @param v: views to delete.
96313158Sdes */
97313158Sdesvoid views_delete(struct views* v);
98313158Sdes
99313158Sdes/**
100313158Sdes * Apply config settings;
101313158Sdes * Takes care of locking.
102313158Sdes * @param v: view is set up.
103313158Sdes * @param cfg: config data.
104313158Sdes * @return false on error.
105313158Sdes */
106313158Sdesint views_apply_cfg(struct views* v, struct config_file* cfg);
107313158Sdes
108313158Sdes/**
109313158Sdes * Compare two view entries in rbtree. Sort canonical.
110313158Sdes * @param v1: view 1
111313158Sdes * @param v2: view 2
112313158Sdes * @return: negative, positive or 0 comparison value.
113313158Sdes */
114313158Sdesint view_cmp(const void* v1, const void* v2);
115313158Sdes
116313158Sdes/**
117313158Sdes * Delete one view
118313158Sdes * @param v: view to delete.
119313158Sdes */
120313158Sdesvoid view_delete(struct view* v);
121313158Sdes
122313158Sdes/**
123313158Sdes * Debug helper. Print all views
124313158Sdes * Takes care of locking.
125313158Sdes * @param v: the views tree
126313158Sdes */
127313158Sdesvoid views_print(struct views* v);
128313158Sdes
129313158Sdes/* Find a view by name.
130313158Sdes * @param vs: views
131313158Sdes * @param name: name of the view we are looking for
132313158Sdes * @param write: 1 for obtaining write lock on found view, 0 for read lock
133313158Sdes * @return: locked view or NULL.
134313158Sdes */
135313158Sdesstruct view* views_find_view(struct views* vs, const char* name, int write);
136313158Sdes
137313158Sdes#endif /* SERVICES_VIEW_H */
138