apply.h 3.85 KB
Newer Older
1
/*  Copyright (C) 2017 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/>.
 */
16

17
#pragma once
18

19
#include "knot/zone/contents.h"
20
#include "knot/updates/changesets.h"
Daniel Salzman's avatar
Daniel Salzman committed
21
#include "contrib/ucw/lists.h"
22

23 24 25 26
enum {
	APPLY_STRICT = 1 << 0,    /* Apply strictly, don't ignore removing non-existent RRs. */
};

27
struct apply_ctx {
28
	zone_contents_t *contents;
29 30
	list_t old_data;          /*!< Old data, to be freed after successful update. */
	list_t new_data;          /*!< New data, to be freed after failed update. */
31
	uint32_t flags;
32 33 34 35 36 37 38
};

typedef struct apply_ctx apply_ctx_t;

/*!
 * \brief Initialize a new context structure.
 *
39 40 41
 * \param ctx       Context to be initialized.
 * \param contents  Zone contents to apply changes onto.
 * \param flags     Flags to control the application process.
42
 */
43
void apply_init_ctx(apply_ctx_t *ctx, zone_contents_t *contents, uint32_t flags);
44

45 46 47 48 49 50 51 52 53 54
/*!
 * \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);
55

56 57 58 59 60 61 62 63 64
/*!
 * \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);
65

66 67 68 69 70 71 72 73 74
/*!
 * \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);
75

76 77 78 79
/*!
 * \brief Adds a single RR into zone contents.
 *
 * \param ctx  Apply context.
Daniel Salzman's avatar
Daniel Salzman committed
80
 * \param ch   Changeset to be applied to the zone.
81 82 83
 *
 * \return KNOT_E*
 */
84
int apply_replace_soa(apply_ctx_t *ctx, const changeset_t *ch);
85 86 87 88 89 90 91 92 93 94 95

/*!
 * \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);
96

97 98 99
/*!
 * \brief Applies changesets directly to the zone, without copying it.
 *
100
 * \warning Modified zone is in inconsistent state after error and should be freed.
101
 *
102 103
 * \param ctx     Apply context.
 * \param chsets  List of changesets to be applied to the zone.
104
 *
Marek Vavruša's avatar
Marek Vavruša committed
105
 * \return KNOT_E*
106
 */
107
int apply_changesets_directly(apply_ctx_t *ctx, list_t *chsets);
108 109 110 111

/*!
 * \brief Applies changeset directly to the zone, without copying it.
 *
112 113
 * \param ctx  Apply context.
 * \param ch   Changeset to be applied to the zone.
114 115 116
 *
 * \return KNOT_E*
 */
117
int apply_changeset_directly(apply_ctx_t *ctx, const changeset_t *ch);
118

119
/*!
120 121 122 123 124 125 126 127 128
 * \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);
129

130 131 132
/*!
 * \brief Cleanups successful zone update.
 *
133
 * \param ctx  Context used to create the update.
134
 */
135
void update_cleanup(apply_ctx_t *ctx);
136

137 138 139
/*!
 * \brief Rollbacks failed zone update.
 *
140
 * \param ctx  Context used to create the update.
141
 */
142
void update_rollback(apply_ctx_t *ctx);
Jan Kadlec's avatar
Jan Kadlec committed
143

144
/*!
145 146 147
 * \brief Shallow frees zone contents - either shallow copy after failed update
 *        or original zone contents after successful update.
 *
148 149
 * \param contents  Contents to free.
 */
150
void update_free_zone(zone_contents_t *contents);