apply.h 4.68 KB
Newer Older
Daniel Salzman's avatar
Daniel Salzman committed
1
/*  Copyright (C) 2016 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
Lubos Slovak's avatar
Lubos Slovak committed
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 Changesets application and update helpers.
 *
 * \addtogroup ddns
 * @{
 */
24

25
#pragma once
26

27
#include "knot/zone/zone.h"
28
#include "knot/updates/changesets.h"
Daniel Salzman's avatar
Daniel Salzman committed
29
#include "contrib/ucw/lists.h"
30

31 32 33 34
enum {
	APPLY_STRICT = 1 << 0,    /* Apply strictly, don't ignore removing non-existent RRs. */
};

35
struct apply_ctx {
36
	zone_contents_t *contents;
37 38
	list_t old_data;          /*!< Old data, to be freed after successful update. */
	list_t new_data;          /*!< New data, to be freed after failed update. */
39
	uint32_t flags;
40 41 42 43 44 45 46
};

typedef struct apply_ctx apply_ctx_t;

/*!
 * \brief Initialize a new context structure.
 *
47 48 49
 * \param ctx       Context to be initialized.
 * \param contents  Zone contents to apply changes onto.
 * \param flags     Flags to control the application process.
50
 */
51
void apply_init_ctx(apply_ctx_t *ctx, zone_contents_t *contents, uint32_t flags);
52

53 54 55 56 57 58 59 60 61 62
/*!
 * \brief Creates a shallow zone contents copy.
 *
 * \param old_contents  Source.
 * \param new_contents  Target.
 *
 * \return KNOT_E*
 */
int apply_prepare_zone_copy(zone_contents_t *old_contents,
                            zone_contents_t **new_contents);
63

64 65 66 67 68 69 70 71 72
/*!
 * \brief Adds a single RR into zone contents.
 *
 * \param ctx  Apply context.
 * \param rr   RRSet to add.
 *
 * \return KNOT_E*
 */
int apply_add_rr(apply_ctx_t *ctx, const knot_rrset_t *rr);
73

74 75 76 77 78 79 80 81 82
/*!
 * \brief Removes single RR from zone contents.
 *
 * \param ctx  Apply context.
 * \param rr   RRSet to remove.
 *
 * \return KNOT_E*
 */
int apply_remove_rr(apply_ctx_t *ctx, const knot_rrset_t *rr);
83

84 85 86 87
/*!
 * \brief Adds a single RR into zone contents.
 *
 * \param ctx  Apply context.
Daniel Salzman's avatar
Daniel Salzman committed
88
 * \param ch   Changeset to be applied to the zone.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
 *
 * \return KNOT_E*
 */
int apply_replace_soa(apply_ctx_t *ctx, changeset_t *ch);

/*!
 * \brief Prepares the new zone contents for signing.
 *
 * Adjusted pointers are required for DNSSEC.
 *
 * \param ctx  Apply context.
 *
 * \return KNOT_E*
 */
int apply_prepare_to_sign(apply_ctx_t *ctx);
104

105
/*!
106
 * \brief Applies changesets to a shallow zone-copy.
107 108
 *
 * \param zone          Zone to be updated.
109 110
 * \param chsets        List of changesets to be applied.
 * \param new_contents  Storage for the new zone contents pointer.
111
 *
112 113
 * \return KNOT_E*
 */
114
int apply_changesets(apply_ctx_t *ctx, zone_t *zone, list_t *chsets,
115
                     zone_contents_t **new_contents);
116

117
/*!
118
 * \brief Applies changeset to a shallow zone-copy.
119 120
 *
 * \param zone          Zone to be updated.
121 122
 * \param ch            Changeset to be applied.
 * \param new_contents  Storage for the new zone contents pointer.
123 124 125
 *
 * \return KNOT_E*
 */
126
int apply_changeset(apply_ctx_t *ctx, zone_t *zone, changeset_t *ch,
127 128
                    zone_contents_t **new_contents);

129 130 131
/*!
 * \brief Applies changesets directly to the zone, without copying it.
 *
132 133
 * \warning Modified zone is in inconsitent state after error and should be freed.
 *
134 135
 * \param ctx     Apply context.
 * \param chsets  List of changesets to be applied to the zone.
136
 *
Marek Vavruša's avatar
Marek Vavruša committed
137
 * \return KNOT_E*
138
 */
139
int apply_changesets_directly(apply_ctx_t *ctx, list_t *chsets);
140 141 142 143

/*!
 * \brief Applies changeset directly to the zone, without copying it.
 *
144 145
 * \param ctx  Apply context.
 * \param ch   Changeset to be applied to the zone.
146 147 148
 *
 * \return KNOT_E*
 */
149 150
int apply_changeset_directly(apply_ctx_t *ctx, changeset_t *ch);

151
/*!
152 153 154 155 156 157 158 159 160
 * \brief Finalizes the zone contents for publishing.
 *
 * Fully adjusts the zone.
 *
 * \param ctx  Apply context.
 *
 * \return KNOT_E*
 */
int apply_finalize(apply_ctx_t *ctx);
161

162 163 164
/*!
 * \brief Cleanups successful zone update.
 *
165 166
 * \param chgs  Changeset used to create the update.
 */
167
void update_cleanup(apply_ctx_t *ctx);
168

169 170 171 172 173
/*!
 * \brief Rollbacks failed zone update.
 *
 * \param chgs   Changeset. used to create the update.
 */
174
void update_rollback(apply_ctx_t *ctx);
Jan Kadlec's avatar
Jan Kadlec committed
175

176
/*!
177 178 179
 * \brief Shallow frees zone contents - either shallow copy after failed update
 *        or original zone contents after successful update.
 *
180 181
 * \param contents  Contents to free.
 */
182
void update_free_zone(zone_contents_t **contents);
183 184

/*! @} */