contents.h 11.5 KB
 Ondřej Surý committed Nov 01, 2011 1 ``````/* Copyright (C) 2011 CZ.NIC, z.s.p.o. `````` Lubos Slovak committed Aug 03, 2011 2 3 4 5 6 7 8 9 10 11 12 13 14 15 `````` This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ `````` Jan Včelák committed Mar 26, 2014 16 17 18 19 20 21 22 23 24 25 ``````/*! * \file contents.h * * \author Lubos Slovak * * \brief Zone contents structure and API for manipulating it. * * \addtogroup libknot * @{ */ `````` Lubos Slovak committed Jul 19, 2011 26 `````` `````` Jan Včelák committed Mar 26, 2014 27 ``````#pragma once `````` Lubos Slovak committed Jul 19, 2011 28 `````` `````` Jan Kadlec committed Mar 31, 2014 29 ``````#include "common/lists.h" `````` Marek Vavruša committed Apr 09, 2014 30 ``````#include "libknot/rdata/nsec3param.h" `````` Jan Včelák committed Jan 28, 2014 31 32 ``````#include "knot/zone/node.h" #include "knot/zone/zone-tree.h" `````` Lubos Slovak committed Jul 19, 2011 33 `````` `````` Jan Včelák committed Feb 03, 2014 34 35 36 37 38 39 ``````struct zone_t; enum zone_contents_find_dname_result { ZONE_NAME_FOUND = 1, ZONE_NAME_NOT_FOUND = 0 }; `````` Lubos Slovak committed Jul 25, 2011 40 `````` `````` Lubos Slovak committed Jul 19, 2011 41 42 ``````/*----------------------------------------------------------------------------*/ `````` Jan Včelák committed Mar 26, 2014 43 ``````typedef struct zone_contents_t { `````` Jan Kadlec committed Apr 16, 2014 44 `````` zone_node_t *apex; /*!< Apex node of the zone (holding SOA) */ `````` Lubos Slovak committed Jul 19, 2011 45 `````` `````` Lubos Slovak committed Aug 02, 2011 46 47 `````` knot_zone_tree_t *nodes; knot_zone_tree_t *nsec3_nodes; `````` Lubos Slovak committed Jul 19, 2011 48 `````` `````` Lubos Slovak committed Aug 02, 2011 49 `````` knot_nsec3_params_t nsec3_params; `````` Jan Včelák committed Apr 26, 2013 50 `````` `````` Lubos Slovak committed Jul 04, 2012 51 `````` /*! `````` Daniel Salzman committed Feb 29, 2012 52 53 `````` * \todo Unify the use of this field - authoritative nodes vs. all. */ `````` Jan Kadlec committed Feb 01, 2013 54 `````` size_t node_count; `````` Lubos Slovak committed Jul 19, 2011 55 `````` `````` Lubos Slovak committed Apr 27, 2012 56 `````` /*! \brief Various flags `````` Jan Včelák committed Apr 26, 2013 57 `````` * `````` Lubos Slovak committed Apr 27, 2012 58 59 `````` * Two rightmost bits denote zone contents generation. * `````` Lubos Slovak committed Aug 27, 2011 60 `````` * Possible values: `````` Lubos Slovak committed Apr 27, 2012 61 62 63 `````` * - 00 - Original version of the zone. Old nodes should be used. * - 01 - New (updated) zone. New nodes should be used. * - 10 - New (updated) zone, but exactly the stored nodes should be `````` Lubos Slovak committed Aug 27, 2011 64 `````` * used, no matter their generation. `````` Lubos Slovak committed Apr 27, 2012 65 66 67 68 `````` * * The third bit denotes whether ANY queries are enabled or disabled: * - 1xx - ANY queries disabled * - 0xx - ANY queries enabled `````` Lubos Slovak committed Aug 27, 2011 69 `````` */ `````` Lubos Slovak committed Apr 27, 2012 70 `````` uint8_t flags; `````` Jan Včelák committed Mar 26, 2014 71 ``````} zone_contents_t; `````` Lubos Slovak committed Jul 19, 2011 72 `````` `````` 73 74 ``````/*!< \brief Helper linked list list for CNAME loop checking */ typedef struct cname_chain { `````` Jan Kadlec committed Apr 16, 2014 75 `````` const zone_node_t *node; `````` 76 77 78 `````` struct cname_chain *next; } cname_chain_t; `````` Jan Včelák committed Oct 16, 2013 79 80 81 ``````/*! * \brief Signature of callback for zone contents apply functions. */ `````` Marek Vavruša committed Apr 17, 2014 82 ``````typedef int (*zone_contents_apply_cb_t)(zone_node_t *node, void *data); `````` Jan Včelák committed Oct 16, 2013 83 `````` `````` Lubos Slovak committed Jul 19, 2011 84 85 ``````/*----------------------------------------------------------------------------*/ `````` Jan Včelák committed Mar 26, 2014 86 ``````zone_contents_t *zone_contents_new(const knot_dname_t *apex_name); `````` Lubos Slovak committed Jul 19, 2011 87 `````` `````` Jan Včelák committed Mar 26, 2014 88 89 ``````int zone_contents_gen_is_old(const zone_contents_t *contents); int zone_contents_gen_is_new(const zone_contents_t *contents); `````` Lubos Slovak committed Aug 27, 2011 90 `````` `````` Jan Včelák committed Mar 26, 2014 91 92 ``````void zone_contents_set_gen_old(zone_contents_t *contents); void zone_contents_set_gen_new(zone_contents_t *contents); `````` Lubos Slovak committed Jul 19, 2011 93 `````` `````` Jan Kadlec committed Apr 25, 2014 94 ``````int zone_contents_add_rr(zone_contents_t *z, const knot_rrset_t *rr, zone_node_t **n); `````` Lubos Slovak committed Jul 19, 2011 95 `````` `````` Marek Vavruša committed Apr 17, 2014 96 ``````int zone_contents_remove_node(zone_contents_t *contents, const knot_dname_t *owner); `````` Lubos Slovak committed Jul 23, 2011 97 `````` `````` Marek Vavruša committed Apr 17, 2014 98 ``````int zone_contents_remove_nsec3_node(zone_contents_t *contents, const knot_dname_t *owner); `````` Lubos Slovak committed Jul 23, 2011 99 `````` `````` Lubos Slovak committed Jul 19, 2011 100 101 102 ``````/*! * \brief Tries to find a node with the specified name in the zone. * `````` Jan Včelák committed Mar 26, 2014 103 `````` * \note This function is identical to zone_contents_get_node(), only it returns `````` Lubos Slovak committed Jul 19, 2011 104 105 106 107 108 109 110 `````` * constant reference. * * \param zone Zone where the name should be searched for. * \param name Name to find. * * \return Corresponding node if found, NULL otherwise. */ `````` Marek Vavruša committed Apr 17, 2014 111 112 ``````const zone_node_t *zone_contents_find_node(const zone_contents_t *contents, const knot_dname_t *name); `````` Lubos Slovak committed Jul 19, 2011 113 114 115 116 117 118 119 120 121 122 123 `````` /*! * \brief Tries to find domain name in the given zone using AVL tree. * * \param[in] zone Zone to search for the name. * \param[in] name Domain name to search for. * \param[out] node The found node (if it was found, otherwise it may contain * arbitrary node). * \param[out] closest_encloser Closest encloser of the given name in the zone. * \param[out] previous Previous domain name in canonical order. * `````` Jan Včelák committed Feb 03, 2014 124 125 `````` * \retval ZONE_NAME_FOUND if node with owner \a name was found. * \retval ZONE_NAME_NOT_FOUND if it was not found. `````` Marek Vavrusa committed Sep 12, 2012 126 `````` * \retval KNOT_EINVAL `````` Jan Kadlec committed Jul 23, 2013 127 `````` * \retval KNOT_EOUTOFZONE `````` Lubos Slovak committed Jul 19, 2011 128 `````` */ `````` Jan Včelák committed Mar 26, 2014 129 ``````int zone_contents_find_dname(const zone_contents_t *contents, `````` Marek Vavruša committed Apr 17, 2014 130 131 132 133 `````` const knot_dname_t *name, const zone_node_t **node, const zone_node_t **closest_encloser, const zone_node_t **previous); `````` Lubos Slovak committed Jul 19, 2011 134 135 136 137 138 139 `````` /*! * \brief Finds previous name in canonical order to the given name in the zone. * * \param zone Zone to search for the name. * \param name Domain name to find the previous domain name of. `````` Marek Vavrusa committed Aug 03, 2011 140 `````` * `````` Lubos Slovak committed Jul 19, 2011 141 142 `````` * \return Previous node in canonical order, or NULL if some parameter is wrong. */ `````` Marek Vavruša committed Apr 17, 2014 143 144 ``````const zone_node_t *zone_contents_find_previous(const zone_contents_t *contents, const knot_dname_t *name); `````` Lubos Slovak committed Jul 19, 2011 145 146 147 148 149 `````` /*! * \brief Tries to find a node with the specified name among the NSEC3 nodes * of the zone. * `````` Jan Včelák committed Mar 26, 2014 150 `````` * \note This function is identical to zone_contents_get_nsec3_node(), only it `````` Lubos Slovak committed Jul 19, 2011 151 152 153 154 155 156 157 `````` * returns constant reference. * * \param zone Zone where the name should be searched for. * \param name Name to find. * * \return Corresponding node if found, NULL otherwise. */ `````` Marek Vavruša committed Apr 17, 2014 158 159 ``````const zone_node_t *zone_contents_find_nsec3_node(const zone_contents_t *contents, const knot_dname_t *name); `````` Lubos Slovak committed Jul 19, 2011 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 `````` /*! * \brief Finds NSEC3 node and previous NSEC3 node in canonical order, * corresponding to the given domain name. * * This functions creates a NSEC3 hash of \a name and tries to find NSEC3 node * with the hashed domain name as owner. * * \param[in] zone Zone to search in. * \param[in] name Domain name to get the corresponding NSEC3 nodes for. * \param[out] nsec3_node NSEC3 node corresponding to \a name (if found, * otherwise this may be an arbitrary NSEC3 node). * \param[out] nsec3_previous The NSEC3 node immediately preceding hashed domain * name corresponding to \a name in canonical order. * `````` Jan Včelák committed Feb 03, 2014 175 176 `````` * \retval ZONE_NAME_FOUND if the corresponding NSEC3 node was found. * \retval ZONE_NAME_NOT_FOUND if it was not found. `````` Marek Vavrusa committed Sep 12, 2012 177 `````` * \retval KNOT_EINVAL `````` Lubos Slovak committed Aug 02, 2011 178 179 180 `````` * \retval KNOT_ENSEC3PAR * \retval KNOT_ECRYPTO * \retval KNOT_ERROR `````` Lubos Slovak committed Jul 19, 2011 181 `````` */ `````` Marek Vavruša committed Apr 17, 2014 182 183 184 185 ``````int zone_contents_find_nsec3_for_name(const zone_contents_t *contents, const knot_dname_t *name, const zone_node_t **nsec3_node, const zone_node_t **nsec3_previous); `````` Lubos Slovak committed Jul 19, 2011 186 `````` `````` Marek Vavruša committed Apr 17, 2014 187 188 ``````const zone_node_t *zone_contents_find_wildcard_child(const zone_contents_t *contents, const zone_node_t *parent); `````` Lubos Slovak committed Jul 19, 2011 189 190 `````` /*! `````` Jan Kadlec committed Dec 19, 2013 191 `````` * \brief Sets parent and previous pointers and node flags. (cheap operation) `````` Jan Kadlec committed Jan 21, 2014 192 `````` * For both normal and NSEC3 tree `````` Jan Kadlec committed Dec 19, 2013 193 `````` */ `````` Jan Včelák committed Mar 26, 2014 194 ``````int zone_contents_adjust_pointers(zone_contents_t *contents); `````` Jan Kadlec committed Dec 19, 2013 195 196 197 198 199 `````` /*! * \brief Sets parent and previous pointers, sets node flags and NSEC3 links. * This has to be called before the zone can be served. * `````` Jan Kadlec committed Feb 27, 2013 200 201 202 203 `````` * \param first_nsec3_node First node in NSEC3 tree - needed in sem. checks. * Will not be saved if set to NULL. * \param last_nsec3_node Last node in NSEC3 tree - needed in sem. checks. * Will not be saved if set to NULL. `````` Lubos Slovak committed Jul 19, 2011 204 205 `````` * \param zone Zone to adjust domain names in. */ `````` Jan Včelák committed Mar 26, 2014 206 ``````int zone_contents_adjust_full(zone_contents_t *contents, `````` Marek Vavruša committed Apr 17, 2014 207 208 `````` zone_node_t **first_nsec3_node, zone_node_t **last_nsec3_node); `````` Lubos Slovak committed Feb 06, 2012 209 `````` `````` Lubos Slovak committed Jul 19, 2011 210 211 212 213 214 215 ``````/*! * \brief Parses the NSEC3PARAM record stored in the zone. * * This function properly fills in the nsec3_params field of the zone structure * according to data stored in the NSEC3PARAM record. This is necessary to do * before any NSEC3 operations on the zone are requested, otherwise they will `````` Lubos Slovak committed Aug 02, 2011 216 `````` * fail (error KNOT_ENSEC3PAR). `````` Lubos Slovak committed Jul 19, 2011 217 218 219 220 221 222 `````` * * \note If there is no NSEC3PARAM record in the zone, this function clears * the nsec3_params field of the zone structure (fills it with zeros). * * \param zone Zone to get the NSEC3PARAM record from. */ `````` Jan Včelák committed Mar 26, 2014 223 ``````int zone_contents_load_nsec3param(zone_contents_t *contents); `````` Lubos Slovak committed Jul 19, 2011 224 225 226 227 228 `````` /*! * \brief Returns the parsed NSEC3PARAM record of the zone. * * \note You must parse the NSEC3PARAM record prior to calling this function `````` Jan Včelák committed Mar 26, 2014 229 `````` * (zone_contents_load_nsec3param()). `````` Lubos Slovak committed Jul 19, 2011 230 231 232 233 234 235 `````` * * \param zone Zone to get the NSEC3PARAM record from. * * \return Parsed NSEC3PARAM from the zone or NULL if the zone does not use * NSEC3 or the record was not parsed before. * `````` Jan Včelák committed Mar 26, 2014 236 `````` * \see zone_contents_load_nsec3param() `````` Lubos Slovak committed Jul 19, 2011 237 `````` */ `````` Marek Vavruša committed Apr 17, 2014 238 ``````const knot_nsec3_params_t *zone_contents_nsec3params(const zone_contents_t *contents); `````` Lubos Slovak committed Jul 19, 2011 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 `````` /*! * \brief Applies the given function to each regular node in the zone. * * This function uses in-order depth-first forward traversal, i.e. the function * is first recursively applied to left subtree, then to the root and then to * the right subtree. * * \note This implies that the zone is stored in a binary tree. Is there a way * to make this traversal independent on the underlying structure? * * \param zone Nodes of this zone will be used as parameters for the function. * \param function Function to be applied to each node of the zone. * \param data Arbitrary data to be passed to the function. */ `````` Jan Včelák committed Mar 26, 2014 254 ``````int zone_contents_tree_apply_inorder(zone_contents_t *zone, `````` Marek Vavruša committed Apr 17, 2014 255 `````` zone_contents_apply_cb_t function, void *data); `````` Lubos Slovak committed Jul 19, 2011 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 `````` /*! * \brief Applies the given function to each NSEC3 node in the zone. * * This function uses in-order depth-first forward traversal, i.e. the function * is first recursively applied to left subtree, then to the root and then to * the right subtree. * * \note This implies that the zone is stored in a binary tree. Is there a way * to make this traversal independent on the underlying structure? * * \param zone NSEC3 nodes of this zone will be used as parameters for the * function. * \param function Function to be applied to each node of the zone. * \param data Arbitrary data to be passed to the function. */ `````` Jan Včelák committed Mar 26, 2014 272 ``````int zone_contents_nsec3_apply_inorder(zone_contents_t *zone, `````` Marek Vavruša committed Apr 17, 2014 273 `````` zone_contents_apply_cb_t function, void *data); `````` Lubos Slovak committed Jul 19, 2011 274 275 276 277 278 279 280 281 282 283 284 285 286 `````` /*! * \brief Creates a shallow copy of the zone (no stored data are copied). * * This function creates a new zone structure in \a to, creates new trees for * regular nodes and for NSEC3 nodes, creates new hash table and a new domain * table. It also fills these structures with the exact same data as the * original zone is - no copying of stored data is done, just pointers are * copied. * * \param from Original zone. * \param to Copy of the zone. * `````` Lubos Slovak committed Aug 02, 2011 287 `````` * \retval KNOT_EOK `````` Marek Vavrusa committed Sep 12, 2012 288 `````` * \retval KNOT_EINVAL `````` Lubos Slovak committed Aug 02, 2011 289 `````` * \retval KNOT_ENOMEM `````` Lubos Slovak committed Jul 19, 2011 290 `````` */ `````` Marek Vavruša committed Apr 17, 2014 291 ``````int zone_contents_shallow_copy(const zone_contents_t *from, zone_contents_t **to); `````` Lubos Slovak committed Jan 20, 2012 292 `````` `````` Jan Včelák committed Mar 26, 2014 293 ``````void zone_contents_free(zone_contents_t **contents); `````` Lubos Slovak committed Jul 19, 2011 294 `````` `````` Jan Včelák committed Mar 26, 2014 295 ``````void zone_contents_deep_free(zone_contents_t **contents); `````` Lubos Slovak committed Jul 19, 2011 296 `````` `````` Marek Vavruša committed Apr 14, 2014 297 298 299 ``````/*! \brief Return zone SOA rdataset. */ const knot_rdataset_t *zone_contents_soa(const zone_contents_t *zone); `````` Marek Vavrusa committed Apr 15, 2013 300 301 ``````/*! * \brief Fetch zone serial. `````` Jan Včelák committed Apr 26, 2013 302 `````` * `````` Marek Vavrusa committed Apr 15, 2013 303 `````` * \param zone Zone. `````` Jan Včelák committed Apr 26, 2013 304 `````` * `````` Marek Vavrusa committed Apr 15, 2013 305 306 `````` * \return serial or 0 */ `````` Marek Vavruša committed Mar 26, 2014 307 ``````uint32_t zone_contents_serial(const zone_contents_t *zone); `````` Marek Vavrusa committed Dec 03, 2013 308 `````` `````` Marek Vavruša committed Apr 14, 2014 309 `````` `````` Marek Vavruša committed Apr 02, 2014 310 311 312 ``````/*! \brief Calculate next serial. */ uint32_t zone_contents_next_serial(const zone_contents_t *zone, int policy); `````` Marek Vavrusa committed Dec 03, 2013 313 314 315 ``````/*! * \brief Return true if zone is signed. */ `````` Jan Včelák committed Mar 26, 2014 316 ``````bool zone_contents_is_signed(const zone_contents_t *zone); `````` Lubos Slovak committed Jul 19, 2011 317 `````` `````` Marek Vavruša committed Apr 10, 2014 318 319 320 ``````/*! * \brief Return true if zone is empty. */ `````` Marek Vavruša committed Mar 26, 2014 321 322 ``````bool zone_contents_is_empty(const zone_contents_t *zone); `````` Marek Vavruša committed Apr 17, 2014 323 ``````zone_node_t *zone_contents_get_node_for_rr(zone_contents_t *zone, const knot_rrset_t *rrset); `````` Jan Kadlec committed Mar 31, 2014 324 `````` `````` Marek Vavruša committed Apr 17, 2014 325 ``````zone_node_t *zone_contents_find_node_for_rr(zone_contents_t *zone, const knot_rrset_t *rrset); `````` Jan Kadlec committed Mar 31, 2014 326 `````` `````` Lubos Slovak committed Jul 19, 2011 327 ``/*! @} */``