xfr-in.h 5.11 KB
Newer Older
1
/*!
Lubos Slovak's avatar
Lubos Slovak committed
2
 * \file xfr-in.h
3 4 5
 *
 * \author Lubos Slovak <lubos.slovak@nic.cz>
 *
Lubos Slovak's avatar
Lubos Slovak committed
6
 * \brief XFR client API.
7
 *
Lubos Slovak's avatar
Lubos Slovak committed
8
 * \addtogroup xfr
9 10
 * @{
 */
11
/*  Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
Lubos Slovak's avatar
Lubos Slovak committed
12 13 14 15 16 17 18 19 20 21 22 23 24 25

    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/>.
 */
26

Lubos Slovak's avatar
Lubos Slovak committed
27 28
#ifndef _KNOT_XFR_IN_H_
#define _KNOT_XFR_IN_H_
29 30 31 32

#include <stdint.h>
#include <string.h>

33
#include "libknot/dname.h"
34
#include "knot/zone/zone.h"
35
#include "libknot/packet/pkt.h"
36
#include "knot/server/xfr-handler.h"
37
#include "knot/updates/changesets.h"
38

39
struct xfr_proc;
40
struct ixfrin_proc;
41

42 43
/*----------------------------------------------------------------------------*/

44 45
typedef enum xfrin_transfer_result {
	XFRIN_RES_COMPLETE = 1,
46 47
	XFRIN_RES_SOA_ONLY = 2,
	XFRIN_RES_FALLBACK = 3
48 49
} xfrin_transfer_result_t;

50 51
/*----------------------------------------------------------------------------*/

52 53 54 55 56 57 58 59 60 61 62
/*!
 * \brief Checks if a zone transfer is required by comparing the zone's SOA with
 *        the one received from master server.
 *
 * \param zone Zone to check.
 * \param soa_response Response to SOA query received from master server.
 *
 * \retval < 0 if an error occured.
 * \retval 1 if the transfer is needed.
 * \retval 0 if the transfer is not needed.
 */
63
int xfrin_transfer_needed(const zone_contents_t *zone,
64
                          knot_pkt_t *soa_response);
65

66 67 68 69 70 71 72 73 74 75
/*!
 * \brief Processes one incoming packet of AXFR transfer by updating the given
 *        zone.
 *
 * \param pkt Incoming packet in wire format.
 * \param size Size of the packet in bytes.
 * \param zone Zone being built. If there is no such zone (i.e. this is the
 *             first packet, \a *zone may be set to NULL, in which case a new
 *             zone structure is created).
 *
Lubos Slovak's avatar
Lubos Slovak committed
76
 * \retval KNOT_EOK
77
 *
78
 * \todo Refactor!!!
79
 */
80
int xfrin_process_axfr_packet(knot_pkt_t *pkt, struct xfr_proc *proc);
81

Lubos Slovak's avatar
Lubos Slovak committed
82 83 84 85 86 87 88 89
/*!
 * \brief Destroys the whole changesets structure.
 *
 * Frees all RRSets present in the changesets and all their data. Also frees
 * the changesets structure and sets the parameter to NULL.
 *
 * \param changesets Changesets to destroy.
 */
90
void xfrin_free_changesets(knot_changesets_t **changesets);
91

Lubos Slovak's avatar
Lubos Slovak committed
92 93 94 95 96 97 98
/*!
 * \brief Parses IXFR reply packet and fills in the changesets structure.
 *
 * \param pkt Packet containing the IXFR reply in wire format.
 * \param size Size of the packet in bytes.
 * \param changesets Changesets to be filled in.
 *
Lubos Slovak's avatar
Lubos Slovak committed
99 100 101 102
 * \retval KNOT_EOK
 * \retval KNOT_EINVAL
 * \retval KNOT_EMALF
 * \retval KNOT_ENOMEM
Lubos Slovak's avatar
Lubos Slovak committed
103
 */
104
int xfrin_process_ixfr_packet(knot_pkt_t *pkt, struct ixfrin_proc *proc);
105

106 107 108 109 110 111 112 113
/*!
 * \brief Applies changesets *with* zone shallow copy.
 *
 * \param zone          Zone to be updated.
 * \param chsets        Changes to be made.
 * \param new_contents  New zone will be returned using this arg.
 * \return KNOT_E*
 */
114
int xfrin_apply_changesets(zone_t *zone,
115
                           knot_changesets_t *chsets,
116
                           zone_contents_t **new_contents);
117

118 119 120 121 122 123 124 125 126
/*!
 * \brief Applies changesets directly to the zone, without copying it.
 *
 * \param contents Zone contents to apply the changesets to. Will be modified.
 * \param chsets   Changesets to be applied to the zone.
 *
 * \retval KNOT_EOK if successful.
 * \retval KNOT_EINVAL if given one of the arguments is NULL.
 * \return Other error code if the application went wrong.
127
 */
128
int xfrin_apply_changesets_directly(zone_contents_t *contents,
129
                                    knot_changesets_t *chsets);
130

131 132
int xfrin_prepare_zone_copy(zone_contents_t *old_contents,
                            zone_contents_t **new_contents);
133

134 135 136 137 138 139
/*!
 * \brief Sets pointers and NSEC3 nodes after signing/DDNS.
 * \param contents_copy    Contents to be updated.
 * \param set_nsec3_names  Set to true if NSEC3 hashes should be set.
 * \return KNOT_E*
 */
140
int xfrin_finalize_updated_zone(zone_contents_t *contents_copy,
141
                                bool set_nsec3_names);
142

143
zone_contents_t *xfrin_switch_zone(zone_t *zone, zone_contents_t *new_contents);
144

145
void xfrin_rollback_update(knot_changesets_t *chgs,
146
                           zone_contents_t **new_contents);
Lubos Slovak's avatar
Lubos Slovak committed
147

148
int xfrin_copy_rrset(zone_node_t *node, uint16_t type,
149
                     knot_rrset_t **rrset);
150

151
int xfrin_copy_old_rrset(knot_rrset_t *old, knot_rrset_t **copy);
152

153
int xfrin_replace_rrset_in_node(zone_node_t *node,
154
                                knot_rrset_t *rrset_new,
155
                                zone_contents_t *contents);
156

157
void xfrin_cleanup_successful_update(knot_changesets_t *chgs);
Jan Kadlec's avatar
Jan Kadlec committed
158

159
/* @note Exported because of update.c */
160
void xfrin_zone_contents_free(zone_contents_t **contents);
Jan Kadlec's avatar
Jan Kadlec committed
161

Lubos Slovak's avatar
Lubos Slovak committed
162
#endif /* _KNOTXFR_IN_H_ */
163 164

/*! @} */