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; 5065b390aaSDag-Erling Smørgrav struct respip_set; 51bc892140SDag-Erling Smørgrav 52bc892140SDag-Erling Smørgrav 53bc892140SDag-Erling Smørgrav /** 54bc892140SDag-Erling Smørgrav * Views storage, shared. 55bc892140SDag-Erling Smørgrav */ 56bc892140SDag-Erling Smørgrav struct views { 57bc892140SDag-Erling Smørgrav /** lock on the view tree */ 583005e0a3SDag-Erling Smørgrav lock_rw_type lock; 59bc892140SDag-Erling Smørgrav /** rbtree of struct view */ 603005e0a3SDag-Erling Smørgrav rbtree_type vtree; 61bc892140SDag-Erling Smørgrav }; 62bc892140SDag-Erling Smørgrav 63bc892140SDag-Erling Smørgrav /** 64bc892140SDag-Erling Smørgrav * View. Named structure holding local authority zones. 65bc892140SDag-Erling Smørgrav */ 66bc892140SDag-Erling Smørgrav struct view { 67bc892140SDag-Erling Smørgrav /** rbtree node, key is name */ 683005e0a3SDag-Erling Smørgrav rbnode_type node; 69bc892140SDag-Erling Smørgrav /** view name. 708a384985SDag-Erling Smørgrav * Has to be right after rbnode_t due to pointer arithmetic in 71bc892140SDag-Erling Smørgrav * view_create's lock protect */ 72bc892140SDag-Erling Smørgrav char* name; 73bc892140SDag-Erling Smørgrav /** view specific local authority zones */ 74bc892140SDag-Erling Smørgrav struct local_zones* local_zones; 7565b390aaSDag-Erling Smørgrav /** response-ip configuration data for this view */ 7665b390aaSDag-Erling Smørgrav struct respip_set* respip_set; 77bc892140SDag-Erling Smørgrav /** Fallback to global local_zones when there is no match in the view 78bc892140SDag-Erling Smørgrav * specific tree. 1 for yes, 0 for no */ 79bc892140SDag-Erling Smørgrav int isfirst; 80bc892140SDag-Erling Smørgrav /** lock on the data in the structure 813005e0a3SDag-Erling Smørgrav * For the node and name you need to also hold the views_tree lock to 823005e0a3SDag-Erling Smørgrav * change them. */ 833005e0a3SDag-Erling Smørgrav lock_rw_type lock; 84bc892140SDag-Erling Smørgrav }; 85bc892140SDag-Erling Smørgrav 86bc892140SDag-Erling Smørgrav 87bc892140SDag-Erling Smørgrav /** 88bc892140SDag-Erling Smørgrav * Create views storage 89bc892140SDag-Erling Smørgrav * @return new struct or NULL on error. 90bc892140SDag-Erling Smørgrav */ 91bc892140SDag-Erling Smørgrav struct views* views_create(void); 92bc892140SDag-Erling Smørgrav 93bc892140SDag-Erling Smørgrav /** 94bc892140SDag-Erling Smørgrav * Delete views storage 95bc892140SDag-Erling Smørgrav * @param v: views to delete. 96bc892140SDag-Erling Smørgrav */ 97bc892140SDag-Erling Smørgrav void views_delete(struct views* v); 98bc892140SDag-Erling Smørgrav 99bc892140SDag-Erling Smørgrav /** 100bc892140SDag-Erling Smørgrav * Apply config settings; 101bc892140SDag-Erling Smørgrav * Takes care of locking. 102bc892140SDag-Erling Smørgrav * @param v: view is set up. 103bc892140SDag-Erling Smørgrav * @param cfg: config data. 104bc892140SDag-Erling Smørgrav * @return false on error. 105bc892140SDag-Erling Smørgrav */ 106bc892140SDag-Erling Smørgrav int views_apply_cfg(struct views* v, struct config_file* cfg); 107bc892140SDag-Erling Smørgrav 108bc892140SDag-Erling Smørgrav /** 109bc892140SDag-Erling Smørgrav * Compare two view entries in rbtree. Sort canonical. 110bc892140SDag-Erling Smørgrav * @param v1: view 1 111bc892140SDag-Erling Smørgrav * @param v2: view 2 112bc892140SDag-Erling Smørgrav * @return: negative, positive or 0 comparison value. 113bc892140SDag-Erling Smørgrav */ 114bc892140SDag-Erling Smørgrav int view_cmp(const void* v1, const void* v2); 115bc892140SDag-Erling Smørgrav 116bc892140SDag-Erling Smørgrav /** 117bc892140SDag-Erling Smørgrav * Delete one view 118bc892140SDag-Erling Smørgrav * @param v: view to delete. 119bc892140SDag-Erling Smørgrav */ 120bc892140SDag-Erling Smørgrav void view_delete(struct view* v); 121bc892140SDag-Erling Smørgrav 122bc892140SDag-Erling Smørgrav /** 123bc892140SDag-Erling Smørgrav * Debug helper. Print all views 124bc892140SDag-Erling Smørgrav * Takes care of locking. 125bc892140SDag-Erling Smørgrav * @param v: the views tree 126bc892140SDag-Erling Smørgrav */ 127bc892140SDag-Erling Smørgrav void views_print(struct views* v); 128bc892140SDag-Erling Smørgrav 129*335c7cdaSCy Schubert /** 130*335c7cdaSCy Schubert * Find a view by name. 131bc892140SDag-Erling Smørgrav * @param vs: views 132bc892140SDag-Erling Smørgrav * @param name: name of the view we are looking for 133bc892140SDag-Erling Smørgrav * @param write: 1 for obtaining write lock on found view, 0 for read lock 134bc892140SDag-Erling Smørgrav * @return: locked view or NULL. 135bc892140SDag-Erling Smørgrav */ 136bc892140SDag-Erling Smørgrav struct view* views_find_view(struct views* vs, const char* name, int write); 137bc892140SDag-Erling Smørgrav 138bc892140SDag-Erling Smørgrav #endif /* SERVICES_VIEW_H */ 139