OpenDNSSEC-signer 2.1.13
ixfr.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009 NLNet Labs. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
19 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
21 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
22 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
23 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 *
25 */
26
32#include "config.h"
33#include "util.h"
34#include "signer/ixfr.h"
35#include "signer/rrset.h"
36#include "signer/zone.h"
37
38static const char* ixfr_str = "journal";
39
40
45static part_type*
46part_create()
47{
48 part_type* part = NULL;
49
50 CHECKALLOC(part = (part_type*) malloc(sizeof(part_type)));
51 part->soaplus = NULL;
52 part->soamin = NULL;
53 part->plus = ldns_rr_list_new();
54 if (!part->plus) {
55 ods_log_error("[%s] unable to create ixfr part: "
56 "ldns_rr_list_new() failed", ixfr_str);
57 free(part);
58 return NULL;
59 }
60 part->min = ldns_rr_list_new();
61 if (!part->min) {
62 ods_log_error("[%s] unable to create ixfr part: "
63 "ldns_rr_list_new() failed", ixfr_str);
64 ldns_rr_list_free(part->plus);
65 free(part);
66 return NULL;
67 }
68 return part;
69}
70
71
76static void
77part_free(part_type* part)
78{
79 if (!part) return;
80 ldns_rr_list_deep_free(part->min);
81 ldns_rr_list_deep_free(part->plus);
82 free(part);
83}
84
85
92{
93 ixfr_type* xfr;
94
95 CHECKALLOC(xfr = (ixfr_type*) calloc(1, sizeof(ixfr_type)));
96 pthread_mutex_init(&xfr->ixfr_lock, NULL);
97 return xfr;
98}
99
100
105void
107{
108 ldns_rr* rr_copy = ldns_rr_clone(rr);
109
110 ods_log_assert(ixfr)
111 ods_log_assert(rr);
112 ods_log_assert(ixfr->part[0]);
113 ods_log_assert(ixfr->part[0]->plus);
114
115 if (!ldns_rr_list_push_rr(ixfr->part[0]->plus, rr_copy)) {
116 ldns_rr_free(rr_copy);
117 ods_fatal_exit("[%s] fatal unable to +RR: ldns_rr_list_push_rr() failed",
118 ixfr_str);
119 }
120 if (ldns_rr_get_type(rr_copy) == LDNS_RR_TYPE_SOA) {
121 ixfr->part[0]->soaplus = rr_copy;
122 }
123}
124
125
130void
132{
133 ldns_rr* rr_copy = ldns_rr_clone(rr);
134
135 ods_log_assert(ixfr)
136 ods_log_assert(rr);
137 ods_log_assert(ixfr->part[0]);
138 ods_log_assert(ixfr->part[0]->min);
139
140 if (!ldns_rr_list_push_rr(ixfr->part[0]->min, rr_copy)) {
141 ldns_rr_free(rr_copy);
142 ods_fatal_exit("[%s] fatal unable to -RR: ldns_rr_list_push_rr() failed",
143 ixfr_str);
144 }
145 if (ldns_rr_get_type(rr_copy) == LDNS_RR_TYPE_SOA) {
146 ixfr->part[0]->soamin = rr_copy;
147 }
148}
149
150
155static int
156part_rr_list_print_nonsoa(FILE* fd, ldns_rr_list* list)
157{
158 size_t i = 0;
159 int error = 0;
160 if (!list || !fd) {
161 return 1;
162 }
163 for (i = 0; i < ldns_rr_list_rr_count(list); i++) {
164 if (ldns_rr_get_type(ldns_rr_list_rr(list, i)) != LDNS_RR_TYPE_SOA) {
165 if (util_rr_print(fd, ldns_rr_list_rr(list, i)) != ODS_STATUS_OK) {
166 error = 1;
167 }
168 }
169 }
170 return error;
171}
172
173
178static int
179part_print(FILE* fd, ixfr_type* ixfr, size_t i)
180{
181 part_type* part = NULL;
182
183 ods_log_assert(ixfr);
184 ods_log_assert(fd);
185
186 part = ixfr->part[i];
187 if (!part || !part->soamin || !part->soaplus) {
188 return 0; /* due to code buggyness this is not considered an
189 error condition*/
190 }
191 ods_log_assert(part->min);
192 ods_log_assert(part->plus);
193 ods_log_assert(part->soamin);
194 ods_log_assert(part->soaplus);
195
196 if (util_rr_print(fd, part->soamin) != ODS_STATUS_OK) {
197 return 1;
198 } else if (part_rr_list_print_nonsoa(fd, part->min)) {
199 return 1;
200 } else if (util_rr_print(fd, part->soaplus) != ODS_STATUS_OK) {
201 return 1;
202 } else if (part_rr_list_print_nonsoa(fd, part->plus)) {
203 return 1;
204 }
205 return 0;
206}
207
208
213int
215{
216 int i = 0;
217
218 ods_log_assert(fd);
219 ods_log_assert(ixfr);
220
221 ods_log_debug("[%s] print ixfr", ixfr_str);
222 for (i = IXFR_MAX_PARTS - 1; i >= 0; i--) {
223 ods_log_deeebug("[%s] print ixfr part #%d", ixfr_str, i);
224 if (part_print(fd, ixfr, i)) {
225 return 1;
226 }
227 }
228 return 0;
229}
230
231
236void
237ixfr_purge(ixfr_type* ixfr, char const *zonename)
238{
239 int i = 0;
240
241 ods_log_assert(ixfr);
242 ods_log_assert(zonename);
243
244 if (ixfr->part[0] &&
245 (!ixfr->part[0]->soamin || !ixfr->part[0]->soaplus))
246 {
247 /* Somehow the signer does a double purge without having used
248 * this part. There is no need to create a new one. In fact,
249 * we should not. It would cause an assertion later on when
250 * printing to file */
251 return;
252 }
253
254 ods_log_debug("[%s] purge ixfr for zone %s", ixfr_str, zonename);
255 for (i = IXFR_MAX_PARTS - 1; i >= 0; i--) {
256 if (i == (IXFR_MAX_PARTS - 1)) {
257 part_free(ixfr->part[i]);
258 ixfr->part[i] = NULL;
259 } else {
260 ixfr->part[i+1] = ixfr->part[i];
261 ixfr->part[i] = NULL;
262 }
263 }
264 ixfr->part[0] = part_create();
265 if (!ixfr->part[0]) {
266 ods_fatal_exit("[%s] fatal unable to purge ixfr for zone %s: "
267 "part_create() failed", ixfr_str, zonename);
268 }
269}
270
271
276void
278{
279 int i = 0;
280 if (!ixfr) {
281 return;
282 }
283 for (i = IXFR_MAX_PARTS - 1; i >= 0; i--) {
284 part_free(ixfr->part[i]);
285 }
286 pthread_mutex_destroy(&ixfr->ixfr_lock);
287 free(ixfr);
288}
query_state ixfr(query_type *q, engine_type *engine)
Definition axfr.c:389
void ixfr_purge(ixfr_type *ixfr, char const *zonename)
Definition ixfr.c:237
int ixfr_print(FILE *fd, ixfr_type *ixfr)
Definition ixfr.c:214
void ixfr_del_rr(ixfr_type *ixfr, ldns_rr *rr)
Definition ixfr.c:131
void ixfr_cleanup(ixfr_type *ixfr)
Definition ixfr.c:277
ixfr_type * ixfr_create()
Definition ixfr.c:91
void ixfr_add_rr(ixfr_type *ixfr, ldns_rr *rr)
Definition ixfr.c:106
#define IXFR_MAX_PARTS
Definition ixfr.h:44
pthread_mutex_t ixfr_lock
Definition ixfr.h:64
ldns_rr_list * plus
Definition ixfr.h:55
ldns_rr * soamin
Definition ixfr.h:52
ldns_rr_list * min
Definition ixfr.h:53
ldns_rr * soaplus
Definition ixfr.h:54