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

    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
14
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
Lubos Slovak's avatar
Lubos Slovak committed
15
 */
16

17
#pragma once
18

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

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

28
struct apply_ctx {
29
	zone_contents_t *contents;
Libor Peltan's avatar
Libor Peltan committed
30 31
	zone_tree_t *node_ptrs;   /*!< Just pointers to the affected nodes in contents. */
	zone_tree_t *nsec3_ptrs;  /*!< The same for NSEC3 nodes. */
32
	uint32_t flags;
33
	knot_sem_t *cow_mutex;
34 35 36 37 38 39 40
};

typedef struct apply_ctx apply_ctx_t;

/*!
 * \brief Initialize a new context structure.
 *
41 42 43
 * \param ctx       Context to be initialized.
 * \param contents  Zone contents to apply changes onto.
 * \param flags     Flags to control the application process.
Libor Peltan's avatar
Libor Peltan committed
44 45
 *
 * \return KNOT_E*
46
 */
Libor Peltan's avatar
Libor Peltan committed
47
int apply_init_ctx(apply_ctx_t *ctx, zone_contents_t *contents, uint32_t flags);
48

49 50 51 52 53 54 55 56 57 58
/*!
 * \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);
59

60 61 62 63 64 65 66 67 68
/*!
 * \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);
69

70 71 72 73 74 75 76 77 78
/*!
 * \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);
79

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

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

/*!
 * \brief Applies changeset directly to the zone, without copying it.
 *
105 106
 * \param ctx  Apply context.
 * \param ch   Changeset to be applied to the zone.
107 108 109
 *
 * \return KNOT_E*
 */
110
int apply_changeset_directly(apply_ctx_t *ctx, const changeset_t *ch);
111 112 113 114

/*!
 * \brief Cleanups successful zone update.
 *
115
 * \param ctx  Context used to create the update.
116
 */
117
void update_cleanup(apply_ctx_t *ctx);
118

119 120 121
/*!
 * \brief Rollbacks failed zone update.
 *
122
 * \param ctx  Context used to create the update.
123
 */
124
void update_rollback(apply_ctx_t *ctx);
Jan Kadlec's avatar
Jan Kadlec committed
125

126
/*!
127 128 129
 * \brief Shallow frees zone contents - either shallow copy after failed update
 *        or original zone contents after successful update.
 *
130 131
 * \param contents  Contents to free.
 */
132
void update_free_zone(zone_contents_t *contents);