journal.c revision 875e88e734b310976b178dc26a74d86fbebc935c
499b34cea04a46823d003d4c0520c8b03e8513cbBrian Wellington * Copyright (C) 1999 Internet Software Consortium.
7e4d75a5daeaaf8a7f559f9bd7fbf540184e235cMark Andrews * Permission to use, copy, modify, and distribute this software for any
7e4d75a5daeaaf8a7f559f9bd7fbf540184e235cMark Andrews * purpose with or without fee is hereby granted, provided that the above
7e4d75a5daeaaf8a7f559f9bd7fbf540184e235cMark Andrews * copyright notice and this permission notice appear in all copies.
15a44745412679c30a6d022733925af70a38b715David Lawrence * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
15a44745412679c30a6d022733925af70a38b715David Lawrence * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
15a44745412679c30a6d022733925af70a38b715David Lawrence * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
15a44745412679c30a6d022733925af70a38b715David Lawrence * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
15a44745412679c30a6d022733925af70a38b715David Lawrence * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15a44745412679c30a6d022733925af70a38b715David Lawrence * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
15a44745412679c30a6d022733925af70a38b715David Lawrence * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * When true, accept IXFR difference sequences where the
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * SOA serial number does not change (BIND 8 sends such
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * sequences).
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsstatic isc_boolean_t bind8_compat = ISC_TRUE; /* XXX config */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews/**************************************************************************/
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * Miscellaneous utilities.
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews dns_lctx, DNS_LOGCATEGORY_GENERAL, DNS_LOGMODULE_JOURNAL
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence#define FAIL(code) do { result = (code); goto failure; } while (0)
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence/* XXX should be macros */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsdecode_uint32(unsigned char *p) {
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews return ((p[0] << 24) +
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews (p[3] << 0));
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsencode_uint32(isc_uint32_t val, unsigned char *p) {
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews * Locate the serial number within the SOA RDATA based
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * on its position relative to the end of the data.
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * (it starts 20 bytes from the end). This is a bit of
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence * a kludge, but the alternative approach of using
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence * dns_rdata_tostruct() and dns_rdata_fromstruct()
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence * would involve a lot of unnecessary work (like
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * building domain names and allocating temporary memory)
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * when all we really want to do is to change 32 bits of
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * fixed-sized data. Besides, fromstruct_soa() is not
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * implemented yet.
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews return (decode_uint32(rdata->data + rdata->length - 20));
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrencedns_soa_setserial(isc_uint32_t val, dns_rdata_t *rdata)
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews encode_uint32(val, rdata->data + rdata->length - 20);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsdns_db_getsoaserial(dns_db_t *db, dns_dbversion_t *ver, isc_uint32_t *serialp)
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence result = dns_db_findnode(db, dns_db_origin(db), ISC_FALSE, &node);
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence result = dns_db_findrdataset(db, node, ver, dns_rdatatype_soa, 0,
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsdns_db_createsoatuple(dns_db_t *db, dns_dbversion_t *ver, isc_mem_t *mctx,
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews result = dns_db_findnode(db, zonename, ISC_FALSE, &node);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews result = dns_db_findrdataset(db, node, ver, dns_rdatatype_soa, 0,
171d0db7f93bf796f870713d6208b21893401cfcBrian Wellington result = dns_difftuple_create(mctx, op, zonename, rdataset.ttl,
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews/**************************************************************************/
af9cfbc64363b61aa5903dd916e9fbc152084d4cMark Andrews * Diffs, aka Pending Journal Entries.
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews dns_diffop_t op, dns_name_t *name, dns_ttl_t ttl,
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews unsigned int size;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews unsigned char *datap;
347ccc2716b45b8c72a1021d7a74faab49d3eefaBrian Wellington * Create a new tuple. The variable-size wire-format name data and
ed71ea51c6ecb5d7d659b6e6a20f6b3f5c2678c6David Lawrence * rdata immediately follow the dns_difftuple_t structure
ed71ea51c6ecb5d7d659b6e6a20f6b3f5c2678c6David Lawrence size = sizeof(*t) + name->length + rdata->length;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsdns_difftuple_copy(dns_difftuple_t *orig, dns_difftuple_t **copyp)
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews return (dns_difftuple_create(orig->mctx, orig->op, &orig->name,
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellingtondns_diff_init(isc_mem_t *mctx, dns_diff_t *diff)
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews while ((t = ISC_LIST_HEAD(diff->tuples)) != NULL) {
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsdns_diff_append(dns_diff_t *diff, dns_difftuple_t **tuplep)
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence ISC_LIST_APPEND(diff->tuples, *tuplep, link);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews/* XXX this is O(N) */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsdns_diff_appendminimal(dns_diff_t *diff, dns_difftuple_t **tuplep)
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * Look for an existing tuple with the same owner name,
ed71ea51c6ecb5d7d659b6e6a20f6b3f5c2678c6David Lawrence * rdata, and TTL. If we are doing an addition and find a
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * deletion or vice versa, remove both the old and the
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * new tuple since they cancel each other out (assuming
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * that we never delete nonexistent data or add existing
03084608809afbaf570093a14d2dc4ad507336a0Brian Wellington * If we find an old update of the same kind as
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington * the one we are doing, there must be a programming
347ccc2716b45b8c72a1021d7a74faab49d3eefaBrian Wellington * error. We report it but try to continue anyway.
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews for (ot = ISC_LIST_HEAD(diff->tuples); ot != NULL;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews if (dns_name_equal(&ot->name, &(*tuplep)->name) &&
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews dns_rdata_compare(&ot->rdata, &(*tuplep)->rdata) == 0 &&
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews "unexpected non-minimal diff");
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsdns_diff_apply(dns_diff_t *diff, dns_db_t *db, dns_dbversion_t *ver)
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews while (t != NULL) {
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * Find the node.
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * We create the node if it does not exist.
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * This will cause an empty node to be created if the diff
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * contains a deletion of an RR at a nonexistent name,
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * but such diffs should never be created in the first
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews CHECK(dns_db_findnode(db, name, ISC_TRUE, &node));
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews while (t != NULL && dns_name_equal(&t->name, name)) {
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * Collect a contiguous set of updates with
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * the same operation (add/delete) and RR type
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence * into a single rdatalist so that the
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence * database rrset merging/subtraction code
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence * can work more efficiently than if each
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * RR were merged into / subtracted from
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * the database separately.
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence * This is done by linking rdata structures from the
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence * diff into "rdatalist". This uses the rdata link
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * field, not the diff link field, so the structure
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * of the diff itself is not affected.
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews while (t != NULL &&
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews "TTL differs in rdataset, "
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews "adjusting %lu -> %lu",
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews (unsigned long) t->ttl,
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews /* Convert the rdatalist into a rdataset. */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews /* Merge the rdataset into the database. */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews result = dns_db_subtractrdataset(db, node, ver,
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence * This will not happen when executing a
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * dynamic update, because that code will
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * generate strictly minimal diffs.
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * It may happen when receiving an IXFR
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * from a server that is not as careful.
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * Issue a warning and continue.
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews "update with no effect");
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews/* XXX this duplicates lots of code in dns_diff_apply(). */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsdns_diff_load(dns_diff_t *diff, dns_addrdatasetfunc_t addfunc,
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews while (t != NULL) {
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews while (t != NULL && dns_name_equal(&t->name, name)) {
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews while (t != NULL && dns_name_equal(&t->name, name) &&
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews /* Convert the rdatalist into a rdataset. */
ed019cabc1cc75d4412010c331876e4ae5080a4dDavid Lawrence "update with no effect");
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * XXX uses qsort(); a merge sort would be more natural for lists,
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * and perhaps safer wrt thread stack overflow.
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsdns_diff_sort(dns_diff_t *diff, dns_diff_compare_func *compare) {
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews unsigned int length = 0;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews unsigned int i;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews v = isc_mem_get(diff->mctx, length * sizeof(dns_difftuple_t *));
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews for (i = 0; i < length; i++) {
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews for (i = 0; i < length; i++) {
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews isc_mem_put(diff->mctx, v, length * sizeof(dns_difftuple_t *));
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * Create an rdataset containing the single RR of the given
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence * tuple. The caller must allocate both the rdataset and
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence * an rdatalist structure for it to refer to.
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsdiff_tuple_tordataset(dns_difftuple_t *t, dns_rdatalist_t *rdl,
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence for (t = ISC_LIST_HEAD(diff->tuples); t != NULL;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews "diff_tuple_tordataset failed: %s",
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews isc_buffer_init(&buf, mem, size, ISC_BUFFERTYPE_TEXT);
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence /* Get rid of final newline. */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews INSIST(buf.used >= 1 && ((char *) buf.base)[buf.used-1] == '\n');
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews (char *) r.base);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews/**************************************************************************/
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews * Journalling.
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews * A journal file consists of
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * - A fixed-size header of type journal_rawheader_t.
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * - The index. This is an unordered array of index entries
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * of type journal_rawpos_t giving the locations
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * of some arbitrary subset of the journal's addressable
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * transactions. The index entries are used as hints to
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * speed up the process of locating a transaction with a given
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * serial number. Unused index entries have an "offset"
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * field of zero. The size of the index can vary between
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews * journal files, but does not change during the lifetime
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * of a file. The size can be zero.
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * - The journal data. This consists of one or more transactions.
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * Each transaction begins with a transaction header of type
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * journal_rawxhdr_t. The transaction header is followed by a
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * sequence of RRs, similar in structure to an IXFR difference
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * sequence (RFC1995). That is, the pre-transaction SOA,
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * zero or more other deleted RRs, the post-transaction SOA,
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence * and zero or more other added RRs. Unlike in IXFR, each RR
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence * is prefixed with a 32-bit length.
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * The journal data part grows as new transactions are
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * appended to the file. Only those transactions
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * whose serial number is current-(2^31-1) to current
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews * are considered "addressable" and may be pointed
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * to from the header or index. They may be preceded
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * by old transactions that are no longer addressable,
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews * and they may be followed by transactions that were
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * appended to the journal but never committed by updating
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * the "end" position in the header. The latter will
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * be overwritten when new transactions are added.
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence * On-disk representation of a "pointer" to a journal entry.
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence * These are used in the journal header to locate the beginning
88ed7381f16a72409061875ddeda598f477e5ef6Michael Graff * and end of the journal, and in the journal index to locate
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * other transactions.
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewstypedef struct {
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence unsigned char serial[4]; /* SOA serial before update. */
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence * XXXRTH Should offset be 8 bytes?
347ccc2716b45b8c72a1021d7a74faab49d3eefaBrian Wellington unsigned char offset[4]; /* Offset from beginning of file. */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * The on-disk representation of the journal header.
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * All numbers are stored in big-endian order.
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence * The header is of a fixed size, with some spare room for future
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence * extensions.
c4cc75482fd6846163cafa79e98abb11bcfaf3d3Mark Andrewstypedef union {
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews /* File format version ID. */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews /* Position of the first addressable transaction */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews /* Position of the next (yet nonexistent) transaction. */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews /* Number of index entries following the header. */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews /* Pad the header to a fixed size. */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * The on-disk representation of the transaction header.
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * There is one of these at the beginning of each transaction.
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewstypedef struct {
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews unsigned char size[4]; /* In bytes, excluding header. */
347ccc2716b45b8c72a1021d7a74faab49d3eefaBrian Wellington unsigned char serial0[4]; /* SOA serial before update. */
347ccc2716b45b8c72a1021d7a74faab49d3eefaBrian Wellington unsigned char serial1[4]; /* SOA serial after update. */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * The on-disk representation of the RR header.
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence * There is one of these at the beginning of each RR.
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewstypedef struct {
d736db6dc53e615e3f2d66d1ddbe28473694d107Michael Graff unsigned char size[4]; /* In bytes, excluding header. */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews/* The in-core representation of the journal header. */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewstypedef struct {
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence * XXXRTH Should offset be 8 bytes?
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews#define POS_INVALIDATE(pos) ((pos).offset = 0, (pos).serial = 0)
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrewstypedef struct {
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence/* The in-core representation of the transaction header. */
88ed7381f16a72409061875ddeda598f477e5ef6Michael Grafftypedef struct {
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence/* The in-core representation of the RR header. */
f1b68725503ff3e46001eee5a1751e29a43a09d1Andreas Gustafssontypedef struct {
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * Initial contents to store in the header of a newly created
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence * journal file.
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence * The header starts with the magic string ";BIND LOG V9\n"
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * to identify the file as a BIND 9 journal file. An ASCII
d736db6dc53e615e3f2d66d1ddbe28473694d107Michael Graff * identification string is used rather than a binary magic
d736db6dc53e615e3f2d66d1ddbe28473694d107Michael Graff * number to be consistent with BIND 8 (BIND 8 journal files
d736db6dc53e615e3f2d66d1ddbe28473694d107Michael Graff * are ASCII text files).
d736db6dc53e615e3f2d66d1ddbe28473694d107Michael Graffinitial_journal_header = { ";BIND LOG V9\n", { 0, 0 }, { 0, 0 }, 0 };
d736db6dc53e615e3f2d66d1ddbe28473694d107Michael Graff#define JOURNAL_EMPTY(h) ((h)->begin.offset == (h)->end.offset)
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewstypedef enum {
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * XXXRTH We use 'off_t' in the following structure. If we continue to
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * use stdio instead of creating an ISC file module, we'll convert
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * 'off_t' to 'long'.
347ccc2716b45b8c72a1021d7a74faab49d3eefaBrian Wellington const char *filename; /* Journal file name */
} it;
* write_open() in BIND 8's ns_config.c). We also need a portable
static dns_result_t
int seek_result;
if (seek_result != 0) {
return (DNS_R_UNEXPECTED);
return (DNS_R_SUCCESS);
static dns_result_t
return (DNS_R_NOMORE);
return (DNS_R_UNEXPECTED);
return (DNS_R_SUCCESS);
static dns_result_t
return (DNS_R_UNEXPECTED);
return (DNS_R_SUCCESS);
static dns_result_t
j->filename,
return (DNS_R_UNEXPECTED);
j->filename,
return (DNS_R_UNEXPECTED);
return (DNS_R_SUCCESS);
static dns_result_t
return (result);
return (DNS_R_SUCCESS);
static dns_result_t
static dns_result_t
return (result);
return (DNS_R_SUCCESS);
static dns_result_t
int size;
if (fp == 0) {
return (DNS_R_UNEXPECTED);
return (DNS_R_NOMEMORY);
return (DNS_R_UNEXPECTED);
return (DNS_R_UNEXPECTED);
return (DNS_R_SUCCESS);
dns_journal_t *j;
if (j == NULL)
return (ISC_R_NOMEMORY);
j->fp = 0;
if (write) {
j->filename);
if (fp == 0) {
j->filename);
sizeof(journal_rawpos_t));
sizeof(journal_rawpos_t)));
j->state =
*journalp = j;
return (DNS_R_SUCCESS);
j->magic = 0;
sizeof(journal_rawpos_t));
return (result);
static dns_result_t
return (result);
return (result);
j->filename,
return (DNS_R_UNEXPECTED);
j->filename);
return (DNS_R_UNEXPECTED);
return (DNS_R_SUCCESS);
static dns_result_t
return (DNS_R_RANGE);
return (DNS_R_RANGE);
return (DNS_R_SUCCESS);
return (DNS_R_NOTFOUND);
return (result);
return (DNS_R_SUCCESS);
j->x.n_soa = 0;
return (result);
dns_difftuple_t *t;
unsigned int size;
size = 0;
j->x.n_soa++;
return (DNS_R_NOMEMORY);
return (result);
j->x.n_soa);
return (ISC_R_UNEXPECTED);
(bind8_compat &&
return (ISC_R_UNEXPECTED);
j->filename,
return (DNS_R_UNEXPECTED);
#ifdef notyet
force_dump(...);
sizeof(journal_rawxhdr_t),
sizeof(journal_rawpos_t)));
return (result);
return (result);
sizeof(journal_rawpos_t));
j->magic = 0;
static dns_result_t
unsigned int n_soa = 0;
unsigned int n_put = 0;
n_soa++;
if (n_soa == 0) {
n_put = 0;
if (n_put != 0) {
return (result);
dns_journal_t *j;
j = NULL;
return (DNS_R_SUCCESS);
return (result);
dns_journal_destroy(&j);
return (result);
dns_journal_t *j;
unsigned int n_soa = 0;
unsigned int n_put = 0;
j = NULL;
return (DNS_R_NOTFOUND);
return (result);
n_soa++;
if (n_soa == 0) {
n_put = 0;
if (n_put != 0) {
goto cleanup;
dns_journal_destroy(&j);
return (result);
static dns_result_t
return (DNS_R_NOMEMORY);
isc_buffer_clear(b);
return (DNS_R_SUCCESS);
return (read_one_rr(j));
return (result);
static dns_result_t
unsigned int rdlen;
isc_region_t r;
return (DNS_R_NOMORE);
j->filename,
return (result);
static dns_result_t
return (result);
goto cleanup_node;
&tuple);
goto cleanup_iterator;
goto cleanup_iterator;
goto cleanup_iterator;
return (result);
static dns_result_t
if (p[!i] == NULL) {
goto next;
goto next;
goto next;
INSIST(t == 0);
dns_difftuple_free(&p[i]);
next: ;
return (result);
const char *journal_filename)
&diff[i]));
if (! have[!i]) {
goto next;
INSIST(t == 0);
next: ;
return (result);