Home | History | Annotate | Line # | Download | only in dns
      1 /*	$NetBSD: zt.h,v 1.10 2025/01/26 16:25:29 christos Exp $	*/
      2 
      3 /*
      4  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
      5  *
      6  * SPDX-License-Identifier: MPL-2.0
      7  *
      8  * This Source Code Form is subject to the terms of the Mozilla Public
      9  * License, v. 2.0. If a copy of the MPL was not distributed with this
     10  * file, you can obtain one at https://mozilla.org/MPL/2.0/.
     11  *
     12  * See the COPYRIGHT file distributed with this work for additional
     13  * information regarding copyright ownership.
     14  */
     15 
     16 #pragma once
     17 
     18 /*! \file dns/zt.h */
     19 
     20 #include <stdbool.h>
     21 
     22 #include <isc/lang.h>
     23 #include <isc/rwlock.h>
     24 
     25 #include <dns/types.h>
     26 
     27 ISC_LANG_BEGINDECLS
     28 
     29 typedef enum dns_ztfind {
     30 	DNS_ZTFIND_EXACT = 1 << 0,
     31 	DNS_ZTFIND_NOEXACT = 1 << 1,
     32 	DNS_ZTFIND_MIRROR = 1 << 2,
     33 } dns_ztfind_t;
     34 
     35 typedef isc_result_t
     36 dns_zt_callback_t(void *arg);
     37 
     38 void
     39 dns_zt_create(isc_mem_t *mctx, dns_view_t *view, dns_zt_t **ztp);
     40 /*%<
     41  * Creates a new zone table for a view.
     42  *
     43  * Requires:
     44  * \li	'mctx' to be initialized.
     45  * \li	'view' is non-NULL
     46  * \li	'ztp' is non-NULL
     47  * \li	'*ztp' is NULL
     48  */
     49 
     50 void
     51 dns_zt_compact(dns_zt_t *zt);
     52 /*%<
     53  * Reclaim unused memory in the zone table
     54  *
     55  * Requires:
     56  * \li	'zt' to be valid
     57  */
     58 
     59 isc_result_t
     60 dns_zt_mount(dns_zt_t *zt, dns_zone_t *zone);
     61 /*%<
     62  * Mounts the zone on the zone table.
     63  *
     64  * Requires:
     65  * \li	'zt' to be valid
     66  * \li	'zone' to be valid
     67  *
     68  * Returns:
     69  * \li	#ISC_R_SUCCESS
     70  * \li	#ISC_R_EXISTS
     71  */
     72 
     73 isc_result_t
     74 dns_zt_unmount(dns_zt_t *zt, dns_zone_t *zone);
     75 /*%<
     76  * Unmount the given zone from the table.
     77  *
     78  * Requires:
     79  *	'zt' to be valid
     80  * \li	'zone' to be valid
     81  *
     82  * Returns:
     83  * \li	#ISC_R_SUCCESS
     84  * \li	#ISC_R_NOTFOUND
     85  */
     86 
     87 isc_result_t
     88 dns_zt_find(dns_zt_t *zt, const dns_name_t *name, dns_ztfind_t options,
     89 	    dns_zone_t **zone);
     90 /*%<
     91  * Find the best match for 'name' in 'zt'.
     92  *
     93  * Notes:
     94  * \li	If the DNS_ZTFIND_EXACT option is set, only an exact match is
     95  *	returned.
     96  *
     97  * \li	If the DNS_ZTFIND_NOEXACT option is set, the closest matching
     98  *      parent domain is returned, even when there is an exact match
     99  *      in the tree.
    100  *
    101  * Requires:
    102  * \li	'zt' to be valid
    103  * \li	'name' to be valid
    104  * \li	'zone' to be non NULL and '*zone' to be NULL
    105  * \li	DNS_ZTFIND_EXACT and DNS_ZTFIND_NOEXACT are not both set
    106  *
    107  * Returns:
    108  * \li	#ISC_R_SUCCESS
    109  * \li	#DNS_R_PARTIALMATCH (if DNS_ZTFIND_EXACT is not set)
    110  * \li	#ISC_R_NOTFOUND
    111  */
    112 
    113 void
    114 dns_zt_detach(dns_zt_t **ztp);
    115 /*%<
    116  * Detach the given zonetable, if the reference count goes to zero the
    117  * zonetable will be freed.  In either case 'ztp' is set to NULL.
    118  *
    119  * Requires:
    120  * \li	'*ztp' to be valid
    121  */
    122 
    123 void
    124 dns_zt_flush(dns_zt_t *ztp);
    125 /*%<
    126  * Schedule flushing of the given zonetable, when reference count goes
    127  * to zero.
    128  *
    129  * Requires:
    130  * \li	'ztp' to be valid
    131  */
    132 
    133 void
    134 dns_zt_attach(dns_zt_t *zt, dns_zt_t **ztp);
    135 /*%<
    136  * Attach 'zt' to '*ztp'.
    137  *
    138  * Requires:
    139  * \li	'zt' to be valid
    140  * \li	'*ztp' to be NULL
    141  */
    142 
    143 isc_result_t
    144 dns_zt_load(dns_zt_t *zt, bool stop, bool newonly);
    145 
    146 isc_result_t
    147 dns_zt_asyncload(dns_zt_t *zt, bool newonly, dns_zt_callback_t alldone,
    148 		 void *arg);
    149 /*%<
    150  * Load all zones in the table. If 'stop' is true, stop on the first
    151  * error and return it. If 'stop' is false, ignore errors.
    152  *
    153  * If newonly is set only zones that were never loaded are loaded.
    154  *
    155  * dns_zt_asyncload() loads zones asynchronously; when all
    156  * zones in the zone table have finished loaded (or failed due
    157  * to errors), the caller is informed by calling 'alldone'
    158  * with an argument of 'arg'.
    159  *
    160  * Requires:
    161  * \li	'zt' to be valid
    162  */
    163 
    164 isc_result_t
    165 dns_zt_freezezones(dns_zt_t *zt, dns_view_t *view, bool freeze);
    166 /*%<
    167  * Freeze/thaw updates to primary zones.
    168  * Any pending updates will be flushed.
    169  * Zones will be reloaded on thaw.
    170  */
    171 
    172 isc_result_t
    173 dns_zt_apply(dns_zt_t *zt, bool stop, isc_result_t *sub,
    174 	     isc_result_t (*action)(dns_zone_t *, void *), void *uap);
    175 /*%<
    176  * Apply a given 'action' to all zone zones in the table.
    177  * If 'stop' is 'true' then walking the zone tree will stop if
    178  * 'action' does not return ISC_R_SUCCESS.
    179  *
    180  * Requires:
    181  * \li	'zt' to be valid.
    182  * \li	'action' to be non NULL.
    183  *
    184  * Returns:
    185  * \li	ISC_R_SUCCESS if action was applied to all nodes.  If 'stop' is
    186  *	false and 'sub' is non NULL then the first error (if any)
    187  *	reported by 'action' is returned in '*sub'. If 'stop' is true,
    188  *	the first error code from 'action' is returned.
    189  */
    190 
    191 bool
    192 dns_zt_loadspending(dns_zt_t *zt);
    193 /*%<
    194  * Returns true if and only if there are zones still waiting to
    195  * be loaded in zone table 'zt'.
    196  *
    197  * Requires:
    198  * \li	'zt' to be valid.
    199  */
    200 
    201 void
    202 dns_zt_setviewcommit(dns_zt_t *zt);
    203 /*%<
    204  * Commit dns_zone_setview() calls previously made for all zones in this
    205  * zone table.
    206  *
    207  * Requires:
    208  *\li	'zt' to be valid.
    209  */
    210 
    211 void
    212 dns_zt_setviewrevert(dns_zt_t *zt);
    213 /*%<
    214  * Revert dns_zone_setview() calls previously made for all zones in this
    215  * zone table.
    216  *
    217  * Requires:
    218  *\li	'zt' to be valid.
    219  */
    220 
    221 ISC_LANG_ENDDECLS
    222