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