2 * Copyright (C) 2004-2010 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 2000, 2001 Internet Software Consortium.
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.
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.
18 /* $Id: diff.h,v 1.15.120.2.24.2 2010/06/04 23:49:23 tbox Exp $ */
29 * A diff is a convenience type representing a list of changes to be
38 #include <isc/magic.h>
41 #include <dns/rdata.h>
42 #include <dns/types.h>
49 * A dns_difftuple_t represents a single RR being added or deleted.
50 * The RR type and class are in the 'rdata' member; the class is always
51 * the real one, not a DynDNS meta-class, so that the rdatas can be
52 * compared using dns_rdata_compare(). The TTL is significant
53 * even for deletions, because a deletion/addition pair cannot
54 * be canceled out if the TTL differs (it might be an explicit
57 * Tuples are also used to represent complete RRs with owner
58 * names for a couple of other purposes, such as the
59 * individual RRs of a "RRset exists (value dependent)"
60 * prerequisite set. In this case, op==DNS_DIFFOP_EXISTS,
61 * and the TTL is ignored.
63 * DNS_DIFFOP_*RESIGN will cause the 'resign' attribute of the resulting
64 * RRset to be recomputed to be 'resign' seconds before the earliest RRSIG
69 DNS_DIFFOP_ADD = 0, /*%< Add an RR. */
70 DNS_DIFFOP_DEL = 1, /*%< Delete an RR. */
71 DNS_DIFFOP_EXISTS = 2, /*%< Assert RR existence. */
72 DNS_DIFFOP_ADDRESIGN = 4, /*%< ADD + RESIGN. */
73 DNS_DIFFOP_DELRESIGN = 5 /*%< DEL + RESIGN. */
76 typedef struct dns_difftuple dns_difftuple_t;
78 #define DNS_DIFFTUPLE_MAGIC ISC_MAGIC('D','I','F','T')
79 #define DNS_DIFFTUPLE_VALID(t) ISC_MAGIC_VALID(t, DNS_DIFFTUPLE_MAGIC)
81 struct dns_difftuple {
88 ISC_LINK(dns_difftuple_t) link;
89 /* Variable-size name data and rdata follows. */
93 * A dns_diff_t represents a set of changes being applied to
94 * a zone. Diffs are also used to represent "RRset exists
95 * (value dependent)" prerequisites.
97 typedef struct dns_diff dns_diff_t;
99 #define DNS_DIFF_MAGIC ISC_MAGIC('D','I','F','F')
100 #define DNS_DIFF_VALID(t) ISC_MAGIC_VALID(t, DNS_DIFF_MAGIC)
106 * Set the 'resign' attribute to this many second before the
107 * earliest RRSIG timeexpire.
110 ISC_LIST(dns_difftuple_t) tuples;
113 /* Type of comparison function for sorting diffs. */
114 typedef int dns_diff_compare_func(const void *, const void *);
122 /**************************************************************************/
124 * Manipulation of diffs and tuples.
128 dns_difftuple_create(isc_mem_t *mctx,
129 dns_diffop_t op, dns_name_t *name, dns_ttl_t ttl,
130 dns_rdata_t *rdata, dns_difftuple_t **tp);
132 * Create a tuple. Deep copies are made of the name and rdata, so
133 * they need not remain valid after the call.
136 *\li *tp != NULL && *tp == NULL.
144 dns_difftuple_free(dns_difftuple_t **tp);
149 * \li **tp is a valid tuple.
153 * \li All memory used by the tuple is freed.
157 dns_difftuple_copy(dns_difftuple_t *orig, dns_difftuple_t **copyp);
162 * \li 'orig' points to a valid tuple
163 *\li copyp != NULL && *copyp == NULL
167 dns_diff_init(isc_mem_t *mctx, dns_diff_t *diff);
172 * \li 'diff' points to an uninitialized dns_diff_t
173 * \li allocated by the caller.
176 * \li '*diff' is a valid, empty diff.
180 dns_diff_clear(dns_diff_t *diff);
182 * Clear a diff, destroying all its tuples.
185 * \li 'diff' points to a valid dns_diff_t.
188 * \li Any tuples in the diff are destroyed.
189 * The diff now empty, but it is still valid
190 * and may be reused without calling dns_diff_init
191 * again. The only memory used is that of the
192 * dns_diff_t structure itself.
195 * \li Managing the memory of the dns_diff_t structure itself
196 * is the caller's responsibility.
200 dns_diff_append(dns_diff_t *diff, dns_difftuple_t **tuple);
202 * Append a single tuple to a diff.
204 *\li 'diff' is a valid diff.
205 * \li '*tuple' is a valid tuple.
209 *\li The tuple has been freed, or will be freed when the diff is cleared.
213 dns_diff_appendminimal(dns_diff_t *diff, dns_difftuple_t **tuple);
215 * Append 'tuple' to 'diff', removing any duplicate
216 * or conflicting updates as needed to create a minimal diff.
219 *\li 'diff' is a minimal diff.
222 *\li 'diff' is still a minimal diff.
223 * \li *tuple is NULL.
224 * \li The tuple has been freed, or will be freed when the diff is cleared.
229 dns_diff_sort(dns_diff_t *diff, dns_diff_compare_func *compare);
231 * Sort 'diff' in-place according to the comparison function 'compare'.
235 dns_diff_apply(dns_diff_t *diff, dns_db_t *db, dns_dbversion_t *ver);
237 dns_diff_applysilently(dns_diff_t *diff, dns_db_t *db, dns_dbversion_t *ver);
239 * Apply 'diff' to the database 'db'.
241 * dns_diff_apply() logs warnings about updates with no effect or
242 * with inconsistent TTLs; dns_diff_applysilently() does not.
244 * For efficiency, the diff should be sorted by owner name.
245 * If it is not sorted, operation will still be correct,
246 * but less efficient.
249 *\li *diff is a valid diff (possibly empty), containing
250 * tuples of type #DNS_DIFFOP_ADD and/or
251 * For #DNS_DIFFOP_DEL tuples, the TTL is ignored.
256 dns_diff_load(dns_diff_t *diff, dns_addrdatasetfunc_t addfunc,
259 * Like dns_diff_apply, but for use when loading a new database
260 * instead of modifying an existing one. This bypasses the
261 * database transaction mechanisms.
264 *\li 'addfunc' is a valid dns_addradatasetfunc_t obtained from
267 *\li 'add_private' points to a corresponding dns_dbload_t *
268 * (XXX why is it a void pointer, then?)
272 dns_diff_print(dns_diff_t *diff, FILE *file);
275 * Print the differences to 'file' or if 'file' is NULL via the
279 *\li 'diff' to be valid.
280 *\li 'file' to refer to a open file or NULL.
285 *\li #ISC_R_UNEXPECTED
286 *\li any error from dns_rdataset_totext()
291 #endif /* DNS_DIFF_H */