diff.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004-2010, 2013  Internet Systems Consortium, Inc. ("ISC")
00003  * Copyright (C) 2000, 2001  Internet Software Consortium.
00004  *
00005  * Permission to use, copy, modify, and/or distribute this software for any
00006  * purpose with or without fee is hereby granted, provided that the above
00007  * copyright notice and this permission notice appear in all copies.
00008  *
00009  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
00010  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
00011  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
00012  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
00013  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
00014  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
00015  * PERFORMANCE OF THIS SOFTWARE.
00016  */
00017 
00018 /* $Id: diff.h,v 1.19 2010/06/04 23:51:14 tbox Exp $ */
00019 
00020 #ifndef DNS_DIFF_H
00021 #define DNS_DIFF_H 1
00022 
00023 /*****
00024  ***** Module Info
00025  *****/
00026 
00027 /*! \file dns/diff.h
00028  * \brief
00029  * A diff is a convenience type representing a list of changes to be
00030  * made to a database.
00031  */
00032 
00033 /***
00034  *** Imports
00035  ***/
00036 
00037 #include <isc/lang.h>
00038 #include <isc/magic.h>
00039 
00040 #include <dns/name.h>
00041 #include <dns/rdata.h>
00042 #include <dns/types.h>
00043 
00044 /***
00045  *** Types
00046  ***/
00047 
00048 /*%
00049  * A dns_difftuple_t represents a single RR being added or deleted.
00050  * The RR type and class are in the 'rdata' member; the class is always
00051  * the real one, not a DynDNS meta-class, so that the rdatas can be
00052  * compared using dns_rdata_compare().  The TTL is significant
00053  * even for deletions, because a deletion/addition pair cannot
00054  * be canceled out if the TTL differs (it might be an explicit
00055  * TTL update).
00056  *
00057  * Tuples are also used to represent complete RRs with owner
00058  * names for a couple of other purposes, such as the
00059  * individual RRs of a "RRset exists (value dependent)"
00060  * prerequisite set.  In this case, op==DNS_DIFFOP_EXISTS,
00061  * and the TTL is ignored.
00062  *
00063  * DNS_DIFFOP_*RESIGN will cause the 'resign' attribute of the resulting
00064  * RRset to be recomputed to be 'resign' seconds before the earliest RRSIG
00065  * timeexpire.
00066  */
00067 
00068 typedef enum {
00069         DNS_DIFFOP_ADD = 0,             /*%< Add an RR. */
00070         DNS_DIFFOP_DEL = 1,             /*%< Delete an RR. */
00071         DNS_DIFFOP_EXISTS = 2,          /*%< Assert RR existence. */
00072         DNS_DIFFOP_ADDRESIGN = 4,       /*%< ADD + RESIGN. */
00073         DNS_DIFFOP_DELRESIGN = 5        /*%< DEL + RESIGN. */
00074 } dns_diffop_t;
00075 
00076 typedef struct dns_difftuple dns_difftuple_t;
00077 
00078 #define DNS_DIFFTUPLE_MAGIC     ISC_MAGIC('D','I','F','T')
00079 #define DNS_DIFFTUPLE_VALID(t)  ISC_MAGIC_VALID(t, DNS_DIFFTUPLE_MAGIC)
00080 
00081 struct dns_difftuple {
00082         unsigned int                    magic;
00083         isc_mem_t                       *mctx;
00084         dns_diffop_t                    op;
00085         dns_name_t                      name;
00086         dns_ttl_t                       ttl;
00087         dns_rdata_t                     rdata;
00088         ISC_LINK(dns_difftuple_t)       link;
00089         /* Variable-size name data and rdata follows. */
00090 };
00091 
00092 /*%
00093  * A dns_diff_t represents a set of changes being applied to
00094  * a zone.  Diffs are also used to represent "RRset exists
00095  * (value dependent)" prerequisites.
00096  */
00097 typedef struct dns_diff dns_diff_t;
00098 
00099 #define DNS_DIFF_MAGIC          ISC_MAGIC('D','I','F','F')
00100 #define DNS_DIFF_VALID(t)       ISC_MAGIC_VALID(t, DNS_DIFF_MAGIC)
00101 
00102 struct dns_diff {
00103         unsigned int                    magic;
00104         isc_mem_t *                     mctx;
00105         ISC_LIST(dns_difftuple_t)       tuples;
00106 };
00107 
00108 /* Type of comparison function for sorting diffs. */
00109 typedef int dns_diff_compare_func(const void *, const void *);
00110 
00111 /***
00112  *** Functions
00113  ***/
00114 
00115 ISC_LANG_BEGINDECLS
00116 
00117 /**************************************************************************/
00118 /*
00119  * Manipulation of diffs and tuples.
00120  */
00121 
00122 isc_result_t
00123 dns_difftuple_create(isc_mem_t *mctx,
00124                      dns_diffop_t op, dns_name_t *name, dns_ttl_t ttl,
00125                      dns_rdata_t *rdata, dns_difftuple_t **tp);
00126 /*%<
00127  * Create a tuple.  Deep copies are made of the name and rdata, so
00128  * they need not remain valid after the call.
00129  *
00130  * Requires:
00131  *\li   *tp != NULL && *tp == NULL.
00132  *
00133  * Returns:
00134  *\li   ISC_R_SUCCESS
00135  *  \li    ISC_R_NOMEMORY
00136  */
00137 
00138 void
00139 dns_difftuple_free(dns_difftuple_t **tp);
00140 /*%<
00141  * Free a tuple.
00142  *
00143  * Requires:
00144  *    \li   **tp is a valid tuple.
00145  *
00146  * Ensures:
00147  *     \li  *tp == NULL
00148  *      \li All memory used by the tuple is freed.
00149  */
00150 
00151 isc_result_t
00152 dns_difftuple_copy(dns_difftuple_t *orig, dns_difftuple_t **copyp);
00153 /*%<
00154  * Copy a tuple.
00155  *
00156  * Requires:
00157  * \li  'orig' points to a valid tuple
00158  *\li   copyp != NULL && *copyp == NULL
00159  */
00160 
00161 void
00162 dns_diff_init(isc_mem_t *mctx, dns_diff_t *diff);
00163 /*%<
00164  * Initialize a diff.
00165  *
00166  * Requires:
00167  * \li   'diff' points to an uninitialized dns_diff_t
00168  *  \li  allocated by the caller.
00169  *
00170  * Ensures:
00171  * \li   '*diff' is a valid, empty diff.
00172  */
00173 
00174 void
00175 dns_diff_clear(dns_diff_t *diff);
00176 /*%<
00177  * Clear a diff, destroying all its tuples.
00178  *
00179  * Requires:
00180  * \li   'diff' points to a valid dns_diff_t.
00181  *
00182  * Ensures:
00183  * \li    Any tuples in the diff are destroyed.
00184  *     The diff now empty, but it is still valid
00185  *     and may be reused without calling dns_diff_init
00186  *     again.  The only memory used is that of the
00187  *     dns_diff_t structure itself.
00188  *
00189  * Notes:
00190  * \li    Managing the memory of the dns_diff_t structure itself
00191  *     is the caller's responsibility.
00192  */
00193 
00194 void
00195 dns_diff_append(dns_diff_t *diff, dns_difftuple_t **tuple);
00196 /*%<
00197  * Append a single tuple to a diff.
00198  *
00199  *\li   'diff' is a valid diff.
00200  * \li  '*tuple' is a valid tuple.
00201  *
00202  * Ensures:
00203  *\li   *tuple is NULL.
00204  *\li   The tuple has been freed, or will be freed when the diff is cleared.
00205  */
00206 
00207 void
00208 dns_diff_appendminimal(dns_diff_t *diff, dns_difftuple_t **tuple);
00209 /*%<
00210  * Append 'tuple' to 'diff', removing any duplicate
00211  * or conflicting updates as needed to create a minimal diff.
00212  *
00213  * Requires:
00214  *\li   'diff' is a minimal diff.
00215  *
00216  * Ensures:
00217  *\li   'diff' is still a minimal diff.
00218  *  \li         *tuple is NULL.
00219  *   \li        The tuple has been freed, or will be freed when the diff is cleared.
00220  *
00221  */
00222 
00223 isc_result_t
00224 dns_diff_sort(dns_diff_t *diff, dns_diff_compare_func *compare);
00225 /*%<
00226  * Sort 'diff' in-place according to the comparison function 'compare'.
00227  */
00228 
00229 isc_result_t
00230 dns_diff_apply(dns_diff_t *diff, dns_db_t *db, dns_dbversion_t *ver);
00231 isc_result_t
00232 dns_diff_applysilently(dns_diff_t *diff, dns_db_t *db, dns_dbversion_t *ver);
00233 /*%<
00234  * Apply 'diff' to the database 'db'.
00235  *
00236  * dns_diff_apply() logs warnings about updates with no effect or
00237  * with inconsistent TTLs; dns_diff_applysilently() does not.
00238  *
00239  * For efficiency, the diff should be sorted by owner name.
00240  * If it is not sorted, operation will still be correct,
00241  * but less efficient.
00242  *
00243  * Requires:
00244  *\li   *diff is a valid diff (possibly empty), containing
00245  *      tuples of type #DNS_DIFFOP_ADD and/or
00246  *      For #DNS_DIFFOP_DEL tuples, the TTL is ignored.
00247  *
00248  */
00249 
00250 isc_result_t
00251 dns_diff_load(dns_diff_t *diff, dns_addrdatasetfunc_t addfunc,
00252               void *add_private);
00253 /*%<
00254  * Like dns_diff_apply, but for use when loading a new database
00255  * instead of modifying an existing one.  This bypasses the
00256  * database transaction mechanisms.
00257  *
00258  * Requires:
00259  *\li   'addfunc' is a valid dns_addradatasetfunc_t obtained from
00260  *      dns_db_beginload()
00261  *
00262  *\li   'add_private' points to a corresponding dns_dbload_t *
00263  *      (XXX why is it a void pointer, then?)
00264  */
00265 
00266 isc_result_t
00267 dns_diff_print(dns_diff_t *diff, FILE *file);
00268 
00269 /*%<
00270  * Print the differences to 'file' or if 'file' is NULL via the
00271  * logging system.
00272  *
00273  * Require:
00274  *\li   'diff' to be valid.
00275  *\li   'file' to refer to a open file or NULL.
00276  *
00277  * Returns:
00278  *\li   #ISC_R_SUCCESS
00279  *\li   #ISC_R_NOMEMORY
00280  *\li   #ISC_R_UNEXPECTED
00281  *\li   any error from dns_rdataset_totext()
00282  */
00283 
00284 ISC_LANG_ENDDECLS
00285 
00286 #endif /* DNS_DIFF_H */

Generated on Tue Apr 28 17:40:57 2015 by Doxygen 1.5.4 for BIND9 Internals 9.11.0pre-alpha