"Fossies" - the Fresh Open Source Software Archive

Member "knot-2.9.2/src/knot/updates/zone-update.h" (12 Dec 2019, 8891 Bytes) of package /linux/misc/dns/knot-2.9.2.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "zone-update.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 2.9.1_vs_2.9.2.

    1 /*  Copyright (C) 2019 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
    2 
    3     This program is free software: you can redistribute it and/or modify
    4     it under the terms of the GNU General Public License as published by
    5     the Free Software Foundation, either version 3 of the License, or
    6     (at your option) any later version.
    7 
    8     This program is distributed in the hope that it will be useful,
    9     but WITHOUT ANY WARRANTY; without even the implied warranty of
   10     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   11     GNU General Public License for more details.
   12 
   13     You should have received a copy of the GNU General Public License
   14     along with this program.  If not, see <https://www.gnu.org/licenses/>.
   15  */
   16 
   17 #pragma once
   18 
   19 #include "knot/updates/apply.h"
   20 #include "knot/conf/conf.h"
   21 #include "knot/updates/changesets.h"
   22 #include "knot/zone/contents.h"
   23 #include "knot/zone/zone.h"
   24 
   25 /*! \brief Structure for zone contents updating / querying. */
   26 typedef struct zone_update {
   27     zone_t *zone;                /*!< Zone being updated. */
   28     zone_contents_t *new_cont;   /*!< New zone contents for full updates. */
   29     changeset_t change;          /*!< Changes we want to apply. */
   30     zone_contents_t *init_cont;  /*!< Exact contents of the zonefile. */
   31     changeset_t extra_ch;        /*!< Extra changeset to store just diff btwn zonefile and result. */
   32     apply_ctx_t *a_ctx;          /*!< Context for applying changesets. */
   33     uint32_t flags;              /*!< Zone update flags. */
   34 } zone_update_t;
   35 
   36 typedef struct {
   37     zone_update_t *update;          /*!< The update we're iterating over. */
   38     zone_tree_it_t tree_it;         /*!< Iterator for the new zone. */
   39     const zone_node_t *cur_node;    /*!< Current node in the new zone. */
   40     bool nsec3;                     /*!< Set when we're using the NSEC3 node tree. */
   41 } zone_update_iter_t;
   42 
   43 typedef enum {
   44     // Mutually exclusive flags
   45     UPDATE_FULL           = 1 << 0, /*!< Replace the old zone by a complete new one. */
   46     UPDATE_HYBRID         = 1 << 1, /*!< Changeset like for incremental, adjusting like full. */
   47     UPDATE_INCREMENTAL    = 1 << 2, /*!< Apply changes to the old zone. */
   48     // Additional flags
   49     UPDATE_SIGN           = 1 << 3, /*!< Sign the resulting zone. */
   50     UPDATE_STRICT         = 1 << 4, /*!< Apply changes strictly, i.e. fail when removing nonexistent RR. */
   51     UPDATE_EXTRA_CHSET    = 1 << 6, /*!< Extra changeset in use, to store diff btwn zonefile and final contents. */
   52 } zone_update_flags_t;
   53 
   54 /*!
   55  * \brief Inits given zone update structure, new memory context is created.
   56  *
   57  * \param update  Zone update structure to init.
   58  * \param zone    Init with this zone.
   59  * \param flags   Flags to control the behavior of the update.
   60  *
   61  * \return KNOT_E*
   62  */
   63 int zone_update_init(zone_update_t *update, zone_t *zone, zone_update_flags_t flags);
   64 
   65 /*!
   66  * \brief Inits update structure, the update is built like IXFR from differences.
   67  *
   68  * The existing zone with its own contents is taken as a base,
   69  * the new candidate zone contents are taken as new contents,
   70  * the diff is calculated, so that this update is INCREMENTAL.
   71  *
   72  * \param update   Zone update structure to init.
   73  * \param zone     Init with this zone.
   74  * \param old_cont The current zone contents the diff will be against. Probably zone->contents.
   75  * \param new_cont New zone contents. Will be taken over (and later freed) by zone update.
   76  * \param flags    Flags for update. Must be UPDATE_INCREMENTAL.
   77  *
   78  * \return KNOT_E*
   79  */
   80 int zone_update_from_differences(zone_update_t *update, zone_t *zone, zone_contents_t *old_cont,
   81                                  zone_contents_t *new_cont, zone_update_flags_t flags, bool ignore_dnssec);
   82 
   83 /*!
   84  * \brief Inits a zone update based on new zone contents.
   85  *
   86  * \param update                 Zone update structure to init.
   87  * \param zone_without_contents  Init with this zone. Its contents may be NULL.
   88  * \param new_cont               New zone contents. Will be taken over (and later freed) by zone update.
   89  * \param flags                  Flags for update.
   90  *
   91  * \return KNOT_E*
   92  */
   93 int zone_update_from_contents(zone_update_t *update, zone_t *zone_without_contents,
   94                               zone_contents_t *new_cont, zone_update_flags_t flags);
   95 
   96 /*!
   97  * \brief Inits using extra changeset, increments SOA serial.
   98  *
   99  * This shall be used after from_differences, to start tracking changes that are against the loaded zonefile.
  100  *
  101  * \param update   Zone update.
  102  *
  103  * \return KNOT_E*
  104  */
  105 int zone_update_start_extra(zone_update_t *update);
  106 
  107 /*!
  108  * \brief Returns node that would be in the zone after updating it.
  109  *
  110  * \note Returned node is either zone original or synthesized, do *not* free
  111  *       or modify. Returned node is allocated on local mempool.
  112  *
  113  * \param update  Zone update.
  114  * \param dname   Dname to search for.
  115  *
  116  * \return   Node after zone update.
  117  */
  118 const zone_node_t *zone_update_get_node(zone_update_t *update,
  119                                         const knot_dname_t *dname);
  120 
  121 /*!
  122  * \brief Returns the serial from the current apex.
  123  *
  124  * \param update  Zone update.
  125  *
  126  * \return   0 if no apex was found, its serial otherwise.
  127  */
  128 uint32_t zone_update_current_serial(zone_update_t *update);
  129 
  130 /*! \brief Return true if NSEC3PARAM has been changed in this update. */
  131 bool zone_update_changed_nsec3param(const zone_update_t *update);
  132 
  133 /*!
  134  * \brief Returns the SOA rdataset we're updating from.
  135  *
  136  * \param update  Zone update.
  137  *
  138  * \return   The original SOA rdataset.
  139  */
  140 const knot_rdataset_t *zone_update_from(zone_update_t *update);
  141 
  142 /*!
  143  * \brief Returns the SOA rdataset we're updating to.
  144  *
  145  * \param update  Zone update.
  146  *
  147  * \return   NULL if no new SOA has been added, new SOA otherwise.
  148  */
  149 const knot_rdataset_t *zone_update_to(zone_update_t *update);
  150 
  151 /*!
  152  * \brief Clear data allocated by given zone update structure.
  153  *
  154  * \param  update Zone update to clear.
  155  */
  156 void zone_update_clear(zone_update_t *update);
  157 
  158 /*!
  159  * \brief Adds an RRSet to the zone.
  160  *
  161  * \warning Do not edit the zone_update when any iterator is active. Any
  162  *          zone_update modifications will invalidate the trie iterators
  163  *          in the zone_update iterator(s).
  164  *
  165  * \param update  Zone update.
  166  * \param rrset   RRSet to add.
  167  *
  168  * \return KNOT_E*
  169  */
  170 int zone_update_add(zone_update_t *update, const knot_rrset_t *rrset);
  171 
  172 /*!
  173  * \brief Removes an RRSet from the zone.
  174  *
  175  * \warning Do not edit the zone_update when any iterator is active. Any
  176  *          zone_update modifications will invalidate the trie iterators
  177  *          in the zone_update iterator(s).
  178  *
  179  * \param update  Zone update.
  180  * \param rrset   RRSet to remove.
  181  *
  182  * \return KNOT_E*
  183  */
  184 int zone_update_remove(zone_update_t *update, const knot_rrset_t *rrset);
  185 
  186 /*!
  187  * \brief Removes a whole RRSet of specified type from the zone.
  188  *
  189  * \warning Do not edit the zone_update when any iterator is active. Any
  190  *          zone_update modifications will invalidate the trie iterators
  191  *          in the zone_update iterator(s).
  192  *
  193  * \param update  Zone update.
  194  * \param owner   Node name to remove.
  195  * \param type    RRSet type to remove.
  196  *
  197  * \return KNOT_E*
  198  */
  199 int zone_update_remove_rrset(zone_update_t *update, knot_dname_t *owner, uint16_t type);
  200 
  201 /*!
  202  * \brief Removes a whole node from the zone.
  203  *
  204  * \warning Do not edit the zone_update when any iterator is active. Any
  205  *          zone_update modifications will invalidate the trie iterators
  206  *          in the zone_update iterator(s).
  207  *
  208  * \param update  Zone update.
  209  * \param owner   Node name to remove.
  210  *
  211  * \return KNOT_E*
  212  */
  213 int zone_update_remove_node(zone_update_t *update, const knot_dname_t *owner);
  214 
  215 /*!
  216  * \brief Adds and removes RRsets to/from the zone according to the changeset.
  217  *
  218  * \param update  Zone update.
  219  * \param changes Changes to be made in zone.
  220  *
  221  * \return KNOT_E*
  222  */
  223 int zone_update_apply_changeset(zone_update_t *update, const changeset_t *changes);
  224 
  225 /*!
  226  * \brief Applies the changeset in reverse, rsets from REM section are added and from ADD section removed.
  227  *
  228  * \param update   Zone update.
  229  * \param changes  Changes to be un-done.
  230  *
  231  * \return KNOT_E*
  232  */
  233 int zone_update_apply_changeset_reverse(zone_update_t *update, const changeset_t *changes);
  234 
  235 /*!
  236  * \brief Increment SOA serial (according to cofigured policy) in the update.
  237  *
  238  * \param update  Update to be modified.
  239  * \param conf    Configuration.
  240  *
  241  * \return KNOT_E*
  242  */
  243 int zone_update_increment_soa(zone_update_t *update, conf_t *conf);
  244 
  245 /*!
  246  * \brief Commits all changes to the zone, signs it, saves changes to journal.
  247  *
  248  * \param conf          Configuration.
  249  * \param update        Zone update.
  250  *
  251  * \return KNOT_E*
  252  */
  253 int zone_update_commit(conf_t *conf, zone_update_t *update);
  254 
  255 /*!
  256  * \brief Returns bool whether there are any changes at all.
  257  *
  258  * \param update  Zone update.
  259  */
  260 bool zone_update_no_change(zone_update_t *update);