]> CyberLeo.Net >> Repos - FreeBSD/stable/9.git/blob - contrib/bind9/lib/dns/diff.c
MFC r254651:
[FreeBSD/stable/9.git] / contrib / bind9 / lib / dns / diff.c
1 /*
2  * Copyright (C) 2004, 2005, 2007-2009, 2011, 2013  Internet Systems Consortium, Inc. ("ISC")
3  * Copyright (C) 2000-2003  Internet Software Consortium.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15  * PERFORMANCE OF THIS SOFTWARE.
16  */
17
18 /* $Id: diff.c,v 1.26 2011/03/25 23:53:02 each Exp $ */
19
20 /*! \file */
21
22 #include <config.h>
23
24 #include <stdlib.h>
25
26 #include <isc/buffer.h>
27 #include <isc/file.h>
28 #include <isc/mem.h>
29 #include <isc/string.h>
30 #include <isc/util.h>
31
32 #include <dns/db.h>
33 #include <dns/diff.h>
34 #include <dns/log.h>
35 #include <dns/rdataclass.h>
36 #include <dns/rdatalist.h>
37 #include <dns/rdataset.h>
38 #include <dns/rdatastruct.h>
39 #include <dns/rdatatype.h>
40 #include <dns/result.h>
41
42 #define CHECK(op) \
43         do { result = (op);                                     \
44                 if (result != ISC_R_SUCCESS) goto failure;      \
45         } while (0)
46
47 #define DIFF_COMMON_LOGARGS \
48         dns_lctx, DNS_LOGCATEGORY_GENERAL, DNS_LOGMODULE_DIFF
49
50 static dns_rdatatype_t
51 rdata_covers(dns_rdata_t *rdata) {
52         return (rdata->type == dns_rdatatype_rrsig ?
53                 dns_rdata_covers(rdata) : 0);
54 }
55
56 isc_result_t
57 dns_difftuple_create(isc_mem_t *mctx,
58                      dns_diffop_t op, dns_name_t *name, dns_ttl_t ttl,
59                      dns_rdata_t *rdata, dns_difftuple_t **tp)
60 {
61         dns_difftuple_t *t;
62         unsigned int size;
63         unsigned char *datap;
64
65         REQUIRE(tp != NULL && *tp == NULL);
66
67         /*
68          * Create a new tuple.  The variable-size wire-format name data and
69          * rdata immediately follow the dns_difftuple_t structure
70          * in memory.
71          */
72         size = sizeof(*t) + name->length + rdata->length;
73         t = isc_mem_allocate(mctx, size);
74         if (t == NULL)
75                 return (ISC_R_NOMEMORY);
76         t->mctx = NULL;
77         isc_mem_attach(mctx, &t->mctx);
78         t->op = op;
79
80         datap = (unsigned char *)(t + 1);
81
82         memcpy(datap, name->ndata, name->length);
83         dns_name_init(&t->name, NULL);
84         dns_name_clone(name, &t->name);
85         t->name.ndata = datap;
86         datap += name->length;
87
88         t->ttl = ttl;
89
90         memcpy(datap, rdata->data, rdata->length);
91         dns_rdata_init(&t->rdata);
92         dns_rdata_clone(rdata, &t->rdata);
93         t->rdata.data = datap;
94         datap += rdata->length;
95
96         ISC_LINK_INIT(&t->rdata, link);
97         ISC_LINK_INIT(t, link);
98         t->magic = DNS_DIFFTUPLE_MAGIC;
99
100         INSIST(datap == (unsigned char *)t + size);
101
102         *tp = t;
103         return (ISC_R_SUCCESS);
104 }
105
106 void
107 dns_difftuple_free(dns_difftuple_t **tp) {
108         dns_difftuple_t *t = *tp;
109         isc_mem_t *mctx;
110
111         REQUIRE(DNS_DIFFTUPLE_VALID(t));
112
113         dns_name_invalidate(&t->name);
114         t->magic = 0;
115         mctx = t->mctx;
116         isc_mem_free(mctx, t);
117         isc_mem_detach(&mctx);
118         *tp = NULL;
119 }
120
121 isc_result_t
122 dns_difftuple_copy(dns_difftuple_t *orig, dns_difftuple_t **copyp) {
123         return (dns_difftuple_create(orig->mctx, orig->op, &orig->name,
124                                      orig->ttl, &orig->rdata, copyp));
125 }
126
127 void
128 dns_diff_init(isc_mem_t *mctx, dns_diff_t *diff) {
129         diff->mctx = mctx;
130         diff->resign = 0;
131         ISC_LIST_INIT(diff->tuples);
132         diff->magic = DNS_DIFF_MAGIC;
133 }
134
135 void
136 dns_diff_clear(dns_diff_t *diff) {
137         dns_difftuple_t *t;
138         REQUIRE(DNS_DIFF_VALID(diff));
139         while ((t = ISC_LIST_HEAD(diff->tuples)) != NULL) {
140                 ISC_LIST_UNLINK(diff->tuples, t, link);
141                 dns_difftuple_free(&t);
142         }
143         ENSURE(ISC_LIST_EMPTY(diff->tuples));
144 }
145
146 void
147 dns_diff_append(dns_diff_t *diff, dns_difftuple_t **tuplep)
148 {
149         ISC_LIST_APPEND(diff->tuples, *tuplep, link);
150         *tuplep = NULL;
151 }
152
153 /* XXX this is O(N) */
154
155 void
156 dns_diff_appendminimal(dns_diff_t *diff, dns_difftuple_t **tuplep)
157 {
158         dns_difftuple_t *ot, *next_ot;
159
160         REQUIRE(DNS_DIFF_VALID(diff));
161         REQUIRE(DNS_DIFFTUPLE_VALID(*tuplep));
162
163         /*
164          * Look for an existing tuple with the same owner name,
165          * rdata, and TTL.   If we are doing an addition and find a
166          * deletion or vice versa, remove both the old and the
167          * new tuple since they cancel each other out (assuming
168          * that we never delete nonexistent data or add existing
169          * data).
170          *
171          * If we find an old update of the same kind as
172          * the one we are doing, there must be a programming
173          * error.  We report it but try to continue anyway.
174          */
175         for (ot = ISC_LIST_HEAD(diff->tuples); ot != NULL;
176              ot = next_ot)
177         {
178                 next_ot = ISC_LIST_NEXT(ot, link);
179                 if (dns_name_equal(&ot->name, &(*tuplep)->name) &&
180                     dns_rdata_compare(&ot->rdata, &(*tuplep)->rdata) == 0 &&
181                     ot->ttl == (*tuplep)->ttl)
182                 {
183                         ISC_LIST_UNLINK(diff->tuples, ot, link);
184                         if ((*tuplep)->op == ot->op) {
185                                 UNEXPECTED_ERROR(__FILE__, __LINE__,
186                                          "unexpected non-minimal diff");
187                         } else {
188                                 dns_difftuple_free(tuplep);
189                         }
190                         dns_difftuple_free(&ot);
191                         break;
192                 }
193         }
194
195         if (*tuplep != NULL) {
196                 ISC_LIST_APPEND(diff->tuples, *tuplep, link);
197                 *tuplep = NULL;
198         }
199
200         ENSURE(*tuplep == NULL);
201 }
202
203 static isc_stdtime_t
204 setresign(dns_rdataset_t *modified, isc_uint32_t delta) {
205         dns_rdata_t rdata = DNS_RDATA_INIT;
206         dns_rdata_rrsig_t sig;
207         isc_stdtime_t when;
208         isc_result_t result;
209
210         result = dns_rdataset_first(modified);
211         INSIST(result == ISC_R_SUCCESS);
212         dns_rdataset_current(modified, &rdata);
213         (void)dns_rdata_tostruct(&rdata, &sig, NULL);
214         if ((rdata.flags & DNS_RDATA_OFFLINE) != 0)
215                 when = 0;
216         else
217                 when = sig.timeexpire - delta;
218         dns_rdata_reset(&rdata);
219
220         result = dns_rdataset_next(modified);
221         while (result == ISC_R_SUCCESS) {
222                 dns_rdataset_current(modified, &rdata);
223                 (void)dns_rdata_tostruct(&rdata, &sig, NULL);
224                 if ((rdata.flags & DNS_RDATA_OFFLINE) != 0) {
225                         goto next_rr;
226                 }
227                 if (when == 0 || sig.timeexpire - delta < when)
228                         when = sig.timeexpire - delta;
229  next_rr:
230                 dns_rdata_reset(&rdata);
231                 result = dns_rdataset_next(modified);
232         }
233         INSIST(result == ISC_R_NOMORE);
234         return (when);
235 }
236
237 static isc_result_t
238 diff_apply(dns_diff_t *diff, dns_db_t *db, dns_dbversion_t *ver,
239            isc_boolean_t warn)
240 {
241         dns_difftuple_t *t;
242         dns_dbnode_t *node = NULL;
243         isc_result_t result;
244         char namebuf[DNS_NAME_FORMATSIZE];
245         char typebuf[DNS_RDATATYPE_FORMATSIZE];
246         char classbuf[DNS_RDATACLASS_FORMATSIZE];
247
248         REQUIRE(DNS_DIFF_VALID(diff));
249         REQUIRE(DNS_DB_VALID(db));
250
251         t = ISC_LIST_HEAD(diff->tuples);
252         while (t != NULL) {
253                 dns_name_t *name;
254
255                 INSIST(node == NULL);
256                 name = &t->name;
257                 /*
258                  * Find the node.
259                  * We create the node if it does not exist.
260                  * This will cause an empty node to be created if the diff
261                  * contains a deletion of an RR at a nonexistent name,
262                  * but such diffs should never be created in the first
263                  * place.
264                  */
265
266                 while (t != NULL && dns_name_equal(&t->name, name)) {
267                         dns_rdatatype_t type, covers;
268                         dns_diffop_t op;
269                         dns_rdatalist_t rdl;
270                         dns_rdataset_t rds;
271                         dns_rdataset_t ardataset;
272                         dns_rdataset_t *modified = NULL;
273
274                         op = t->op;
275                         type = t->rdata.type;
276                         covers = rdata_covers(&t->rdata);
277
278                         /*
279                          * Collect a contiguous set of updates with
280                          * the same operation (add/delete) and RR type
281                          * into a single rdatalist so that the
282                          * database rrset merging/subtraction code
283                          * can work more efficiently than if each
284                          * RR were merged into / subtracted from
285                          * the database separately.
286                          *
287                          * This is done by linking rdata structures from the
288                          * diff into "rdatalist".  This uses the rdata link
289                          * field, not the diff link field, so the structure
290                          * of the diff itself is not affected.
291                          */
292
293                         rdl.type = type;
294                         rdl.covers = covers;
295                         rdl.rdclass = t->rdata.rdclass;
296                         rdl.ttl = t->ttl;
297                         ISC_LIST_INIT(rdl.rdata);
298                         ISC_LINK_INIT(&rdl, link);
299
300                         node = NULL;
301                         if (type != dns_rdatatype_nsec3 &&
302                             covers != dns_rdatatype_nsec3)
303                                 CHECK(dns_db_findnode(db, name, ISC_TRUE,
304                                                       &node));
305                         else
306                                 CHECK(dns_db_findnsec3node(db, name, ISC_TRUE,
307                                                            &node));
308
309                         while (t != NULL &&
310                                dns_name_equal(&t->name, name) &&
311                                t->op == op &&
312                                t->rdata.type == type &&
313                                rdata_covers(&t->rdata) == covers)
314                         {
315                                 dns_name_format(name, namebuf, sizeof(namebuf));
316                                 dns_rdatatype_format(t->rdata.type, typebuf,
317                                                      sizeof(typebuf));
318                                 dns_rdataclass_format(t->rdata.rdclass,
319                                                       classbuf,
320                                                       sizeof(classbuf));
321                                 if (t->ttl != rdl.ttl && warn)
322                                         isc_log_write(DIFF_COMMON_LOGARGS,
323                                                 ISC_LOG_WARNING,
324                                                 "'%s/%s/%s': TTL differs in "
325                                                 "rdataset, adjusting "
326                                                 "%lu -> %lu",
327                                                 namebuf, typebuf, classbuf,
328                                                 (unsigned long) t->ttl,
329                                                 (unsigned long) rdl.ttl);
330                                 ISC_LIST_APPEND(rdl.rdata, &t->rdata, link);
331                                 t = ISC_LIST_NEXT(t, link);
332                         }
333
334                         /*
335                          * Convert the rdatalist into a rdataset.
336                          */
337                         dns_rdataset_init(&rds);
338                         CHECK(dns_rdatalist_tordataset(&rdl, &rds));
339                         if (rds.type == dns_rdatatype_rrsig)
340                                 switch (op) {
341                                 case DNS_DIFFOP_ADDRESIGN:
342                                 case DNS_DIFFOP_DELRESIGN:
343                                         modified = &ardataset;
344                                         dns_rdataset_init(modified);
345                                         break;
346                                 default:
347                                         break;
348                                 }
349                         rds.trust = dns_trust_ultimate;
350
351                         /*
352                          * Merge the rdataset into the database.
353                          */
354                         switch (op) {
355                         case DNS_DIFFOP_ADD:
356                         case DNS_DIFFOP_ADDRESIGN:
357                                 result = dns_db_addrdataset(db, node, ver,
358                                                             0, &rds,
359                                                             DNS_DBADD_MERGE|
360                                                             DNS_DBADD_EXACT|
361                                                             DNS_DBADD_EXACTTTL,
362                                                             modified);
363                                 break;
364                         case DNS_DIFFOP_DEL:
365                         case DNS_DIFFOP_DELRESIGN:
366                                 result = dns_db_subtractrdataset(db, node, ver,
367                                                                &rds,
368                                                                DNS_DBSUB_EXACT,
369                                                                modified);
370                                 break;
371                         default:
372                                 INSIST(0);
373                         }
374
375                         if (result == ISC_R_SUCCESS) {
376                                 if (modified != NULL) {
377                                         isc_stdtime_t resign;
378                                         resign = setresign(modified,
379                                                            diff->resign);
380                                         dns_db_setsigningtime(db, modified,
381                                                               resign);
382                                         if (diff->resign == 0 &&
383                                             (op == DNS_DIFFOP_ADDRESIGN ||
384                                              op == DNS_DIFFOP_DELRESIGN))
385                                                 isc_log_write(
386                                                         DIFF_COMMON_LOGARGS,
387                                                         ISC_LOG_WARNING,
388                                                         "resign requested "
389                                                         "with 0 resign "
390                                                         "interval");
391                                 }
392                         } else if (result == DNS_R_UNCHANGED) {
393                                 /*
394                                  * This will not happen when executing a
395                                  * dynamic update, because that code will
396                                  * generate strictly minimal diffs.
397                                  * It may happen when receiving an IXFR
398                                  * from a server that is not as careful.
399                                  * Issue a warning and continue.
400                                  */
401                                 if (warn) {
402                                         char classbuf[DNS_RDATATYPE_FORMATSIZE];
403                                         char namebuf[DNS_NAME_FORMATSIZE];
404
405                                         dns_name_format(dns_db_origin(db),
406                                                         namebuf,
407                                                         sizeof(namebuf));
408                                         dns_rdataclass_format(dns_db_class(db),
409                                                               classbuf,
410                                                               sizeof(classbuf));
411                                         isc_log_write(DIFF_COMMON_LOGARGS,
412                                                       ISC_LOG_WARNING,
413                                                       "%s/%s: dns_diff_apply: "
414                                                       "update with no effect",
415                                                       namebuf, classbuf);
416                                 }
417                         } else if (result == DNS_R_NXRRSET) {
418                                 /*
419                                  * OK.
420                                  */
421                         } else {
422                                 if (modified != NULL &&
423                                     dns_rdataset_isassociated(modified))
424                                         dns_rdataset_disassociate(modified);
425                                 CHECK(result);
426                         }
427                         dns_db_detachnode(db, &node);
428                         if (modified != NULL &&
429                             dns_rdataset_isassociated(modified))
430                                 dns_rdataset_disassociate(modified);
431                 }
432         }
433         return (ISC_R_SUCCESS);
434
435  failure:
436         if (node != NULL)
437                 dns_db_detachnode(db, &node);
438         return (result);
439 }
440
441 isc_result_t
442 dns_diff_apply(dns_diff_t *diff, dns_db_t *db, dns_dbversion_t *ver) {
443         return (diff_apply(diff, db, ver, ISC_TRUE));
444 }
445
446 isc_result_t
447 dns_diff_applysilently(dns_diff_t *diff, dns_db_t *db, dns_dbversion_t *ver) {
448         return (diff_apply(diff, db, ver, ISC_FALSE));
449 }
450
451 /* XXX this duplicates lots of code in diff_apply(). */
452
453 isc_result_t
454 dns_diff_load(dns_diff_t *diff, dns_addrdatasetfunc_t addfunc,
455               void *add_private)
456 {
457         dns_difftuple_t *t;
458         isc_result_t result;
459
460         REQUIRE(DNS_DIFF_VALID(diff));
461
462         t = ISC_LIST_HEAD(diff->tuples);
463         while (t != NULL) {
464                 dns_name_t *name;
465
466                 name = &t->name;
467                 while (t != NULL && dns_name_equal(&t->name, name)) {
468                         dns_rdatatype_t type, covers;
469                         dns_diffop_t op;
470                         dns_rdatalist_t rdl;
471                         dns_rdataset_t rds;
472
473                         op = t->op;
474                         type = t->rdata.type;
475                         covers = rdata_covers(&t->rdata);
476
477                         rdl.type = type;
478                         rdl.covers = covers;
479                         rdl.rdclass = t->rdata.rdclass;
480                         rdl.ttl = t->ttl;
481                         ISC_LIST_INIT(rdl.rdata);
482                         ISC_LINK_INIT(&rdl, link);
483
484                         while (t != NULL && dns_name_equal(&t->name, name) &&
485                                t->op == op && t->rdata.type == type &&
486                                rdata_covers(&t->rdata) == covers)
487                         {
488                                 ISC_LIST_APPEND(rdl.rdata, &t->rdata, link);
489                                 t = ISC_LIST_NEXT(t, link);
490                         }
491
492                         /*
493                          * Convert the rdatalist into a rdataset.
494                          */
495                         dns_rdataset_init(&rds);
496                         CHECK(dns_rdatalist_tordataset(&rdl, &rds));
497                         rds.trust = dns_trust_ultimate;
498
499                         INSIST(op == DNS_DIFFOP_ADD);
500                         result = (*addfunc)(add_private, name, &rds);
501                         if (result == DNS_R_UNCHANGED) {
502                                 isc_log_write(DIFF_COMMON_LOGARGS,
503                                               ISC_LOG_WARNING,
504                                               "dns_diff_load: "
505                                               "update with no effect");
506                         } else if (result == ISC_R_SUCCESS ||
507                                    result == DNS_R_NXRRSET) {
508                                 /*
509                                  * OK.
510                                  */
511                         } else {
512                                 CHECK(result);
513                         }
514                 }
515         }
516         result = ISC_R_SUCCESS;
517  failure:
518         return (result);
519 }
520
521 /*
522  * XXX uses qsort(); a merge sort would be more natural for lists,
523  * and perhaps safer wrt thread stack overflow.
524  */
525 isc_result_t
526 dns_diff_sort(dns_diff_t *diff, dns_diff_compare_func *compare) {
527         unsigned int length = 0;
528         unsigned int i;
529         dns_difftuple_t **v;
530         dns_difftuple_t *p;
531         REQUIRE(DNS_DIFF_VALID(diff));
532
533         for (p = ISC_LIST_HEAD(diff->tuples);
534              p != NULL;
535              p = ISC_LIST_NEXT(p, link))
536                 length++;
537         if (length == 0)
538                 return (ISC_R_SUCCESS);
539         v = isc_mem_get(diff->mctx, length * sizeof(dns_difftuple_t *));
540         if (v == NULL)
541                 return (ISC_R_NOMEMORY);
542         for (i = 0; i < length; i++) {
543                 p = ISC_LIST_HEAD(diff->tuples);
544                 v[i] = p;
545                 ISC_LIST_UNLINK(diff->tuples, p, link);
546         }
547         INSIST(ISC_LIST_HEAD(diff->tuples) == NULL);
548         qsort(v, length, sizeof(v[0]), compare);
549         for (i = 0; i < length; i++) {
550                 ISC_LIST_APPEND(diff->tuples, v[i], link);
551         }
552         isc_mem_put(diff->mctx, v, length * sizeof(dns_difftuple_t *));
553         return (ISC_R_SUCCESS);
554 }
555
556
557 /*
558  * Create an rdataset containing the single RR of the given
559  * tuple.  The caller must allocate the rdata, rdataset and
560  * an rdatalist structure for it to refer to.
561  */
562
563 static isc_result_t
564 diff_tuple_tordataset(dns_difftuple_t *t, dns_rdata_t *rdata,
565                       dns_rdatalist_t *rdl, dns_rdataset_t *rds)
566 {
567         REQUIRE(DNS_DIFFTUPLE_VALID(t));
568         REQUIRE(rdl != NULL);
569         REQUIRE(rds != NULL);
570
571         rdl->type = t->rdata.type;
572         rdl->rdclass = t->rdata.rdclass;
573         rdl->ttl = t->ttl;
574         ISC_LIST_INIT(rdl->rdata);
575         ISC_LINK_INIT(rdl, link);
576         dns_rdataset_init(rds);
577         ISC_LINK_INIT(rdata, link);
578         dns_rdata_clone(&t->rdata, rdata);
579         ISC_LIST_APPEND(rdl->rdata, rdata, link);
580         return (dns_rdatalist_tordataset(rdl, rds));
581 }
582
583 isc_result_t
584 dns_diff_print(dns_diff_t *diff, FILE *file) {
585         isc_result_t result;
586         dns_difftuple_t *t;
587         char *mem = NULL;
588         unsigned int size = 2048;
589         const char *op = NULL;
590
591         REQUIRE(DNS_DIFF_VALID(diff));
592
593         mem = isc_mem_get(diff->mctx, size);
594         if (mem == NULL)
595                 return (ISC_R_NOMEMORY);
596
597         for (t = ISC_LIST_HEAD(diff->tuples); t != NULL;
598              t = ISC_LIST_NEXT(t, link))
599         {
600                 isc_buffer_t buf;
601                 isc_region_t r;
602
603                 dns_rdatalist_t rdl;
604                 dns_rdataset_t rds;
605                 dns_rdata_t rd = DNS_RDATA_INIT;
606
607                 result = diff_tuple_tordataset(t, &rd, &rdl, &rds);
608                 if (result != ISC_R_SUCCESS) {
609                         UNEXPECTED_ERROR(__FILE__, __LINE__,
610                                          "diff_tuple_tordataset failed: %s",
611                                          dns_result_totext(result));
612                         result =  ISC_R_UNEXPECTED;
613                         goto cleanup;
614                 }
615  again:
616                 isc_buffer_init(&buf, mem, size);
617                 result = dns_rdataset_totext(&rds, &t->name,
618                                              ISC_FALSE, ISC_FALSE, &buf);
619
620                 if (result == ISC_R_NOSPACE) {
621                         isc_mem_put(diff->mctx, mem, size);
622                         size += 1024;
623                         mem = isc_mem_get(diff->mctx, size);
624                         if (mem == NULL) {
625                                 result = ISC_R_NOMEMORY;
626                                 goto cleanup;
627                         }
628                         goto again;
629                 }
630
631                 if (result != ISC_R_SUCCESS)
632                         goto cleanup;
633                 /*
634                  * Get rid of final newline.
635                  */
636                 INSIST(buf.used >= 1 &&
637                        ((char *) buf.base)[buf.used-1] == '\n');
638                 buf.used--;
639
640                 isc_buffer_usedregion(&buf, &r);
641                 switch (t->op) {
642                 case DNS_DIFFOP_EXISTS: op = "exists"; break;
643                 case DNS_DIFFOP_ADD: op = "add"; break;
644                 case DNS_DIFFOP_DEL: op = "del"; break;
645                 case DNS_DIFFOP_ADDRESIGN: op = "add re-sign"; break;
646                 case DNS_DIFFOP_DELRESIGN: op = "del re-sign"; break;
647                 }
648                 if (file != NULL)
649                         fprintf(file, "%s %.*s\n", op, (int) r.length,
650                                 (char *) r.base);
651                 else
652                         isc_log_write(DIFF_COMMON_LOGARGS, ISC_LOG_DEBUG(7),
653                                       "%s %.*s", op, (int) r.length,
654                                       (char *) r.base);
655         }
656         result = ISC_R_SUCCESS;
657  cleanup:
658         if (mem != NULL)
659                 isc_mem_put(diff->mctx, mem, size);
660         return (result);
661 }