"Fossies" - the Fresh Open Source Software Archive

Member "knot-2.9.2/src/knot/updates/changesets.h" (12 Dec 2019, 8052 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 "changesets.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 <stdio.h>
   20 
   21 #include "libknot/rrset.h"
   22 #include "knot/zone/contents.h"
   23 #include "contrib/ucw/lists.h"
   24 
   25 /*! \brief Changeset addition/removal flags */
   26 typedef enum {
   27     CHANGESET_NONE = 0,
   28     CHANGESET_CHECK = 1 << 0, /*! Perform redundancy check on additions/removals */
   29 } changeset_flag_t;
   30 
   31 /*! \brief One zone change, from 'soa_from' to 'soa_to'. */
   32 typedef struct {
   33     node_t n;                 /*!< List node. */
   34     knot_rrset_t *soa_from;   /*!< Start SOA. */
   35     knot_rrset_t *soa_to;     /*!< Destination SOA. */
   36     zone_contents_t *add;     /*!< Change additions. */
   37     zone_contents_t *remove;  /*!< Change removals. */
   38     size_t size;              /*!< Size of serialized changeset. \todo Remove after old_journal removal! */
   39     uint8_t *data;            /*!< Serialized changeset. */
   40 } changeset_t;
   41 
   42 /*! \brief Changeset iteration structure. */
   43 typedef struct {
   44     list_t iters;             /*!< List of pending zone iterators. */
   45     zone_tree_t *trees[4];    /*!< Poiters to zone trees to iterate over. */
   46     size_t n_trees;           /*!< Their count. */
   47     zone_tree_it_t it;        /*!< Zone tree iterator. */
   48     const zone_node_t *node;  /*!< Current zone node. */
   49     uint16_t node_pos;        /*!< Position in node. */
   50 } changeset_iter_t;
   51 
   52 /*!
   53  * \brief Inits changeset structure.
   54  *
   55  * \param ch    Changeset to init.
   56  * \param apex  Zone apex DNAME.
   57  *
   58  * \return KNOT_E*
   59  */
   60 int changeset_init(changeset_t *ch, const knot_dname_t *apex);
   61 
   62 /*!
   63  * \brief Creates new changeset structure and inits it.
   64  *
   65  * \param apex  Zone apex DNAME.
   66  *
   67  * \return Changeset structure on success, NULL on errors.
   68  */
   69 changeset_t *changeset_new(const knot_dname_t *apex);
   70 
   71 /*!
   72  * \brief Checks whether changeset is empty, i.e. no change will happen after its application.
   73  *
   74  * \param ch  Changeset to be checked.
   75  *
   76  * \retval true if changeset is empty.
   77  * \retval false if changeset is not empty.
   78  */
   79 bool changeset_empty(const changeset_t *ch);
   80 
   81 /*!
   82  * \brief Get number of changes (additions and removals) in the changeset.
   83  *
   84  * \param ch  Changeset to be checked.
   85  *
   86  * \return Number of changes in the changeset.
   87  */
   88 size_t changeset_size(const changeset_t *ch);
   89 
   90 /*!
   91  * \brief Add RRSet to 'add' part of changeset.
   92  *
   93  * \param ch     Changeset to add RRSet into.
   94  * \param rrset  RRSet to be added.
   95  * \param flags  Changeset flags.
   96  *
   97  * \return KNOT_E*
   98  */
   99 int changeset_add_addition(changeset_t *ch, const knot_rrset_t *rrset, changeset_flag_t flags);
  100 
  101 /*!
  102  * \brief Add RRSet to 'remove' part of changeset.
  103  *
  104  * \param ch     Changeset to add RRSet into.
  105  * \param rrset  RRSet to be added.
  106  * \param flags  Changeset flags.
  107  *
  108  * \return KNOT_E*
  109  */
  110 int changeset_add_removal(changeset_t *ch, const knot_rrset_t *rrset, changeset_flag_t flags);
  111 
  112 
  113 /*!
  114  * \brief Remove an RRSet from the 'add' part of changeset.
  115  *
  116  * \param ch                Changeset to add RRSet into.
  117  * \param rrset             RRSet to be added.
  118  *
  119  * \return KNOT_E*
  120  */
  121 int changeset_remove_addition(changeset_t *ch, const knot_rrset_t *rrset);
  122 
  123 /*!
  124  * \brief Remove an RRSet from the 'remove' part of changeset.
  125  *
  126  * \param ch                Changeset to add RRSet into.
  127  * \param rrset             RRSet to be added.
  128  *
  129  * \return KNOT_E*
  130  */
  131 int changeset_remove_removal(changeset_t *ch, const knot_rrset_t *rrset);
  132 
  133 /*!
  134  * \brief Merges two changesets together.
  135  *
  136  * \param ch1  Merge into this changeset.
  137  * \param ch2  Merge this changeset.
  138  * \param flags  Flags how to handle rendundancies.
  139  *
  140  * \return KNOT_E*
  141  */
  142 int changeset_merge(changeset_t *ch1, const changeset_t *ch2, int flags);
  143 
  144 /*!
  145  * \brief Get serial "from" of the changeset.
  146  *
  147  * \param ch   Changeset in question.
  148  *
  149  * \return Its serial "from", or 0 if none.
  150  */
  151 uint32_t changeset_from(const changeset_t *ch);
  152 
  153 /*!
  154  * \brief Get serial "to" of the changeset.
  155  *
  156  * \param ch   Changeset in question.
  157  *
  158  * \return Its serial "to", or 0 if none.
  159  */
  160 uint32_t changeset_to(const changeset_t *ch);
  161 
  162 /*!
  163  * \brief Check the changes and SOA, ignoring possibly updated SOA serial.
  164  *
  165  * \note Also tolerates changed RRSIG of SOA.
  166  *
  167  * \param ch  Changeset in question.
  168  *
  169  * \retval false  If the changeset changes other records than SOA, or some SOA field
  170  *                other than serial changed.
  171  * \retval true   Otherwise.
  172  */
  173 bool changeset_differs_just_serial(const changeset_t *ch);
  174 
  175 /*!
  176  * \brief Clears changesets in list. Changesets are not free'd. Legacy.
  177  *
  178  * \param chgs  Changeset list to clear.
  179  */
  180 void changesets_clear(list_t *chgs);
  181 
  182 /*!
  183  * \brief Free changesets in list. Legacy.
  184  *
  185  * \param chgs  Changeset list to free.
  186  */
  187 void changesets_free(list_t *chgs);
  188 
  189 /*!
  190  * \brief Clear single changeset.
  191  *
  192  * \param ch  Changeset to clear.
  193  */
  194 void changeset_clear(changeset_t *ch);
  195 
  196 /*!
  197  * \brief Copy changeset to newly allocated space, all rrsigs are copied.
  198  *
  199  * \param ch  Changeset to be copied.
  200  *
  201  * \return a copy, or NULL if error.
  202  */
  203 changeset_t *changeset_clone(const changeset_t *ch);
  204 
  205 /*!
  206  * \brief Frees single changeset.
  207  *
  208  * \param ch  Changeset to free.
  209  */
  210 void changeset_free(changeset_t *ch);
  211 
  212 /*!
  213  * \brief Inits changeset iteration structure with changeset additions.
  214  *
  215  * \param itt  Iterator to init.
  216  * \param ch   Changeset to use.
  217  *
  218  * \return KNOT_E*
  219  */
  220 int changeset_iter_add(changeset_iter_t *itt, const changeset_t *ch);
  221 
  222 /*!
  223  * \brief Inits changeset iteration structure with changeset removals.
  224  *
  225  * \param itt  Iterator to init.
  226  * \param ch   Changeset to use.
  227  *
  228  * \return KNOT_E*
  229  */
  230 int changeset_iter_rem(changeset_iter_t *itt, const changeset_t *ch);
  231 
  232 /*!
  233  * \brief Inits changeset iteration structure with changeset additions and removals.
  234  *
  235  * \param itt  Iterator to init.
  236  * \param ch   Changeset to use.
  237  *
  238  * \return KNOT_E*
  239  */
  240 int changeset_iter_all(changeset_iter_t *itt, const changeset_t *ch);
  241 
  242 /*!
  243  * \brief Gets next RRSet from changeset iterator.
  244  *
  245  * \param it  Changeset iterator.
  246  *
  247  * \return Next RRSet in iterator, empty RRSet if iteration done.
  248  */
  249 knot_rrset_t changeset_iter_next(changeset_iter_t *it);
  250 
  251 /*!
  252  * \brief Free resources allocated by changeset iterator.
  253  *
  254  * \param it  Iterator to clear.
  255  */
  256 void changeset_iter_clear(changeset_iter_t *it);
  257 
  258 /*!
  259  * \brief A pointer type for callback for changeset_walk() function.
  260  *
  261  * \param rrset    An actual removal/addition inside the changeset.
  262  * \param addition Indicates addition against removal.
  263  * \param ctx      A context passed to the changeset_walk() function.
  264  *
  265  * \retval KNOT_EOK if all ok, iteration will continue
  266  * \return KNOT_E*  if error, iteration will stop immediately and changeset_walk() returns this error.
  267  */
  268 typedef int (*changeset_walk_callback)(const knot_rrset_t *rrset, bool addition, void *ctx);
  269 
  270 /*!
  271  * \brief Calls a callback for each removal/addition in the changeset.
  272  *
  273  * \param changeset Changeset.
  274  * \param callback  Callback.
  275  * \param ctx       Arbitrary context passed to the callback.
  276  *
  277  * \return KNOT_E*
  278  */
  279 int changeset_walk(const changeset_t *changeset, changeset_walk_callback callback, void *ctx);
  280 
  281 /*!
  282  *
  283  * \brief Dumps the changeset into text file.
  284  *
  285  * \param changeset Changeset.
  286  * \param outfile   File to write into.
  287  * \param color     Use unix tty color metacharacters.
  288  */
  289 void changeset_print(const changeset_t *changeset, FILE *outfile, bool color);