zone-update.h 7.03 KB
Newer Older
Daniel Salzman's avatar
Daniel Salzman committed
1
/*  Copyright (C) 2015 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
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 <http://www.gnu.org/licenses/>.
 */
Daniel Salzman's avatar
Daniel Salzman committed
16 17 18 19 20 21 22 23
/*!
 * \file
 *
 * \brief API for quering zone that is being updated.
 *
 * \addtogroup ddns
 * @{
 */
24 25 26

#pragma once

27
#include "knot/updates/apply.h"
28
#include "knot/conf/conf.h"
29 30
#include "knot/updates/changesets.h"
#include "knot/zone/contents.h"
31
#include "knot/zone/zone.h"
32
#include "libknot/mm_ctx.h"
33

34
/*! \brief Structure for zone contents updating / querying. */
35
typedef struct {
36 37
	zone_t *zone;                /*!< Zone being updated. */
	zone_contents_t *new_cont;   /*!< New zone contents for full updates. */
38
	changeset_t change;          /*!< Changes we want to apply. */
39
	apply_ctx_t a_ctx;           /*!< Context for applying changesets. */
40
	uint32_t flags;              /*!< Zone update flags. */
41
	knot_mm_t mm;                /*!< Memory context used for intermediate nodes. */
42 43
} zone_update_t;

44 45
typedef struct {
	zone_update_t *update;          /*!< The update we're iterating over. */
46
	hattrie_iter_t *base_it;        /*!< Iterator for the original zone in the case of INCREMENTAL update or the new zone in case of FULL update. */
47
	hattrie_iter_t *add_it;         /*!< Iterator for the added nodes in the changeset. Available in the INCREMENTAL update only. */
48
	const zone_node_t *base_node;   /*!< The original node (INCREMENTAL update) or new node (FULL update). */
49
	const zone_node_t *add_node;    /*!< The additions to that node (INCREMENTAL update only). */
50
	const zone_node_t *next_node;   /*!< The smaller of t_node and ch_node (INCREMENTAL update) or next new node (FULL update). */
51 52 53
	bool nsec3;                     /*!< Set when we're using the NSEC3 node tree. */
} zone_update_iter_t;

54
typedef enum {
55 56 57 58
	UPDATE_FULL           = 1 << 0, /*!< Replace the old zone by a complete new one. */
	UPDATE_INCREMENTAL    = 1 << 1, /*!< Apply changes to the old zone. */
	UPDATE_SIGN           = 1 << 2, /*!< Sign the resulting zone. */
	UPDATE_DIFF           = 1 << 3, /*!< In the case of full update, create a diff for journal. */
59 60
} zone_update_flags_t;

61 62 63 64 65
/*!
 * \brief Inits given zone update structure, new memory context is created.
 *
 * \param update  Zone update structure to init.
 * \param zone    Init with this zone.
66
 * \param flags   Flags to control the behavior of the update.
67 68
 *
 * \return KNOT_E*
69
 */
70
int zone_update_init(zone_update_t *update, zone_t *zone, zone_update_flags_t flags);
71

72 73 74
/*!
 * \brief Returns node that would be in the zone after updating it.
 *
75
 * \note Returned node is either zone original or synthesized, do *not* free
76
 *       or modify. Returned node is allocated on local mempool.
77 78 79 80
 *
 * \param update  Zone update.
 * \param dname   Dname to search for.
 *
81
 * \return   Node after zone update.
82 83 84
 */
const zone_node_t *zone_update_get_node(zone_update_t *update,
                                        const knot_dname_t *dname);
85 86 87 88 89 90 91 92 93 94 95

/*!
 * \brief Returns updated zone apex.
 *
 * \note Returned node is either zone original or synthesized, do *not* free
 *       or modify.
 *
 * \param update  Zone update.
 *
 * \return   Returns apex after update.
 */
96
const zone_node_t *zone_update_get_apex(zone_update_t *update);
97 98 99 100 101 102 103 104

/*!
 * \brief Returns the serial from the current apex.
 *
 * \param update  Zone update.
 *
 * \return   0 if no apex was found, its serial otherwise.
 */
105 106
uint32_t zone_update_current_serial(zone_update_t *update);

107 108 109 110 111 112 113
/*!
 * \brief Returns the SOA rdataset we're updating from.
 *
 * \param update  Zone update.
 *
 * \return   The original SOA rdataset.
 */
114
const knot_rdataset_t *zone_update_from(zone_update_t *update);
115 116 117 118 119 120 121 122

/*!
 * \brief Returns the SOA rdataset we're updating to.
 *
 * \param update  Zone update.
 *
 * \return   NULL if no new SOA has been added, new SOA otherwise.
 */
123
const knot_rdataset_t *zone_update_to(zone_update_t *update);
124

125 126 127 128 129
/*!
 * \brief Clear data allocated by given zone update structure.
 *
 * \param  update Zone update to clear.
 */
130 131
void zone_update_clear(zone_update_t *update);

132 133 134
/*!
 * \brief Adds an RRSet to the zone.
 *
135 136 137 138
 * \warning Do not edit the zone_update when any iterator is active. Any
 *          zone_update modifications will invalidate the trie iterators
 *          in the zone_update iterator(s).
 *
139 140 141 142
 * \param update  Zone update.
 *
 * \return KNOT_E*
 */
143
int zone_update_add(zone_update_t *update, const knot_rrset_t *rrset);
144 145 146 147

/*!
 * \brief Removes an RRSet from the zone.
 *
148 149 150 151
 * \warning Do not edit the zone_update when any iterator is active. Any
 *          zone_update modifications will invalidate the trie iterators
 *          in the zone_update iterator(s).
 *
152 153 154 155
 * \param update  Zone update.
 *
 * \return KNOT_E*
 */
156
int zone_update_remove(zone_update_t *update, const knot_rrset_t *rrset);
157 158 159 160

/*!
 * \brief Commits all changes to the zone, signs it, saves changes to journal.
 *
161
 * \param conf          Configuration.
162
 * \param update        Zone update.
163 164 165
 *
 * \return KNOT_E*
 */
166
int zone_update_commit(conf_t *conf, zone_update_t *update);
167

168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
/*!
 * \brief Setup a zone_update iterator for both FULL and INCREMENTAL updates.
 *
 * \warning Do not init or use iterators when the zone is edited. Any
 *          zone_update modifications will invalidate the trie iterators
 *          in the zone_update iterator.
 *
 * \param it       Iterator.
 * \param update   Zone update.
 *
 * \return KNOT_E*
 */
int zone_update_iter(zone_update_iter_t *it, zone_update_t *update);

/*!
 * \brief Setup a zone_update iterator for both FULL and INCREMENTAL updates.
 *        Version for iterating over nsec3 nodes.
 *
 * \warning Do not init or use iterators when the zone is edited. Any
 *          zone_update modifications will invalidate the trie iterators
 *          in the zone_update iterator.
 *
 *
 * \param it       Iterator.
 * \param update   Zone update.
 *
 * \return KNOT_E*
 */
int zone_update_iter_nsec3(zone_update_iter_t *it, zone_update_t *update);

/*!
 * \brief Move the iterator to the next item.
 *
 * \param it  Iterator.
 *
 * \return KNOT_E*
 */
int zone_update_iter_next(zone_update_iter_t *it);

/*!
 * \brief Get the value of the iterator.
 *
 * \param it  Iterator.
 *
 * \return A (synthesized or added) node with all its current data.
 */
const zone_node_t *zone_update_iter_val(zone_update_iter_t *it);

/*!
 * \brief Finish the iterator and clean it up.
 *
 * \param it  Iterator.
 *
 * \return KNOT_E*
 */
int zone_update_iter_finish(zone_update_iter_t *it);

225 226 227 228 229
/*!
 * \brief Returns bool whether there are any changes at all.
 *
 * \param update  Zone update.
 */
230 231
bool zone_update_no_change(zone_update_t *up);

232
/*! @} */