1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
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
|
/*!
* \file xfr-in.h
*
* \author Lubos Slovak <lubos.slovak@nic.cz>
*
* \brief XFR client API.
*
* \addtogroup xfr
* @{
*/
/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
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/>.
*/
#ifndef _KNOT_XFR_IN_H_
#define _KNOT_XFR_IN_H_
#include <stdint.h>
#include <string.h>
#include "dname.h"
#include "zone/zone.h"
#include "packet/packet.h"
#include "nameserver/name-server.h"
#include "updates/changesets.h"
/*----------------------------------------------------------------------------*/
typedef struct xfrin_orphan_rrsig {
knot_rrset_t *rrsig;
struct xfrin_orphan_rrsig *next;
} xfrin_orphan_rrsig_t;
typedef struct xfrin_constructed_zone {
knot_zone_contents_t *contents;
xfrin_orphan_rrsig_t *rrsigs;
} xfrin_constructed_zone_t;
typedef enum xfrin_transfer_result {
XFRIN_RES_COMPLETE = 1,
XFRIN_RES_SOA_ONLY = 2,
XFRIN_RES_FALLBACK = 3
} xfrin_transfer_result_t;
/*----------------------------------------------------------------------------*/
/*!
* \brief Creates normal query for the given zone name and the SOA type.
*
* \param owner Zone owner.
* \param buffer Buffer to fill the message in.
* \param size In: available space in the buffer. Out: actual size of the
* message in bytes.
*
* \retval KNOT_EOK
* \retval KNOT_ESPACE
* \retval KNOT_ERROR
*/
int xfrin_create_soa_query(knot_dname_t *owner, knot_ns_xfr_t *xfr,
size_t *size);
/*!
* \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.
*/
int xfrin_transfer_needed(const knot_zone_contents_t *zone,
knot_packet_t *soa_response);
/*!
* \brief Creates normal query for the given zone name and the AXFR type.
*
* \param owner Zone owner.
* \param xfr Data structure holding important data for the query, namely
* pointer to the buffer for wireformat and TSIG data.
* \param size In: available space in the buffer. Out: actual size of the
* message in bytes.
* \param use_tsig If TSIG should be used.
*
* \todo Parameter use_tsig probably not needed.
*
* \retval KNOT_EOK
* \retval KNOT_ESPACE
* \retval KNOT_ERROR
*/
int xfrin_create_axfr_query(knot_dname_t *owner, knot_ns_xfr_t *xfr,
size_t *size, int use_tsig);
/*!
* \brief Creates normal query for the given zone name and the IXFR type.
*
* \param zone Zone contents.
* \param buffer Buffer to fill the message in.
* \param size In: available space in the buffer. Out: actual size of the
* message in bytes.
* \param use_tsig If TSIG should be used.
*
* \todo Parameter use_tsig probably not needed.
*
* \retval KNOT_EOK
* \retval KNOT_ESPACE
* \retval KNOT_ERROR
*/
int xfrin_create_ixfr_query(const knot_zone_contents_t *zone,
knot_ns_xfr_t *xfr, size_t *size, int use_tsig);
/*!
* \brief Processes the newly created transferred zone.
*
* \param nameserver Name server to update.
* \param zone Zone build from transfer.
*
* \retval KNOT_ENOTSUP
*/
int xfrin_zone_transferred(knot_nameserver_t *nameserver,
knot_zone_contents_t *zone);
/*!
* \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).
*
* \retval KNOT_EOK
*
* \todo Refactor!!!
*/
int xfrin_process_axfr_packet(/*const uint8_t *pkt, size_t size,
xfrin_constructed_zone_t **zone*/
knot_ns_xfr_t *xfr);
void xfrin_free_orphan_rrsigs(xfrin_orphan_rrsig_t **rrsigs);
/*!
* \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.
*/
void xfrin_free_changesets(knot_changesets_t **changesets);
/*!
* \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.
*
* \retval KNOT_EOK
* \retval KNOT_EINVAL
* \retval KNOT_EMALF
* \retval KNOT_ENOMEM
*/
int xfrin_process_ixfr_packet(knot_ns_xfr_t *xfr/*const uint8_t *pkt, size_t size,
knot_changesets_t **changesets*/);
int xfrin_apply_changesets_to_zone(knot_zone_t *zone,
knot_changesets_t *chsets);
int xfrin_apply_changesets(knot_zone_t *zone,
knot_changesets_t *chsets,
knot_zone_contents_t **new_contents);
int xfrin_switch_zone(knot_zone_t *zone,
knot_zone_contents_t *new_contents,
int deep_free);
void xfrin_cleanup_successful_update(knot_changes_t **changes);
void xfrin_rollback_update(knot_zone_contents_t *old_contents,
knot_zone_contents_t **new_contents,
knot_changes_t **changes);
#endif /* _KNOTXFR_IN_H_ */
/*! @} */
|