/contrib/bind9/lib/dns/include/dns/diff.h

https://bitbucket.org/freebsd/freebsd-head/ · C Header · 291 lines · 66 code · 34 blank · 191 comment · 0 complexity · 9ba717b02ad888393f9c37a3f9a17b0d MD5 · raw file

  1. /*
  2. * Copyright (C) 2004-2010 Internet Systems Consortium, Inc. ("ISC")
  3. * Copyright (C) 2000, 2001 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. /* $Id: diff.h,v 1.19 2010/06/04 23:51:14 tbox Exp $ */
  18. #ifndef DNS_DIFF_H
  19. #define DNS_DIFF_H 1
  20. /*****
  21. ***** Module Info
  22. *****/
  23. /*! \file dns/diff.h
  24. * \brief
  25. * A diff is a convenience type representing a list of changes to be
  26. * made to a database.
  27. */
  28. /***
  29. *** Imports
  30. ***/
  31. #include <isc/lang.h>
  32. #include <isc/magic.h>
  33. #include <dns/name.h>
  34. #include <dns/rdata.h>
  35. #include <dns/types.h>
  36. /***
  37. *** Types
  38. ***/
  39. /*%
  40. * A dns_difftuple_t represents a single RR being added or deleted.
  41. * The RR type and class are in the 'rdata' member; the class is always
  42. * the real one, not a DynDNS meta-class, so that the rdatas can be
  43. * compared using dns_rdata_compare(). The TTL is significant
  44. * even for deletions, because a deletion/addition pair cannot
  45. * be canceled out if the TTL differs (it might be an explicit
  46. * TTL update).
  47. *
  48. * Tuples are also used to represent complete RRs with owner
  49. * names for a couple of other purposes, such as the
  50. * individual RRs of a "RRset exists (value dependent)"
  51. * prerequisite set. In this case, op==DNS_DIFFOP_EXISTS,
  52. * and the TTL is ignored.
  53. *
  54. * DNS_DIFFOP_*RESIGN will cause the 'resign' attribute of the resulting
  55. * RRset to be recomputed to be 'resign' seconds before the earliest RRSIG
  56. * timeexpire.
  57. */
  58. typedef enum {
  59. DNS_DIFFOP_ADD = 0, /*%< Add an RR. */
  60. DNS_DIFFOP_DEL = 1, /*%< Delete an RR. */
  61. DNS_DIFFOP_EXISTS = 2, /*%< Assert RR existence. */
  62. DNS_DIFFOP_ADDRESIGN = 4, /*%< ADD + RESIGN. */
  63. DNS_DIFFOP_DELRESIGN = 5 /*%< DEL + RESIGN. */
  64. } dns_diffop_t;
  65. typedef struct dns_difftuple dns_difftuple_t;
  66. #define DNS_DIFFTUPLE_MAGIC ISC_MAGIC('D','I','F','T')
  67. #define DNS_DIFFTUPLE_VALID(t) ISC_MAGIC_VALID(t, DNS_DIFFTUPLE_MAGIC)
  68. struct dns_difftuple {
  69. unsigned int magic;
  70. isc_mem_t *mctx;
  71. dns_diffop_t op;
  72. dns_name_t name;
  73. dns_ttl_t ttl;
  74. dns_rdata_t rdata;
  75. ISC_LINK(dns_difftuple_t) link;
  76. /* Variable-size name data and rdata follows. */
  77. };
  78. /*%
  79. * A dns_diff_t represents a set of changes being applied to
  80. * a zone. Diffs are also used to represent "RRset exists
  81. * (value dependent)" prerequisites.
  82. */
  83. typedef struct dns_diff dns_diff_t;
  84. #define DNS_DIFF_MAGIC ISC_MAGIC('D','I','F','F')
  85. #define DNS_DIFF_VALID(t) ISC_MAGIC_VALID(t, DNS_DIFF_MAGIC)
  86. struct dns_diff {
  87. unsigned int magic;
  88. isc_mem_t * mctx;
  89. /*
  90. * Set the 'resign' attribute to this many second before the
  91. * earliest RRSIG timeexpire.
  92. */
  93. isc_uint32_t resign;
  94. ISC_LIST(dns_difftuple_t) tuples;
  95. };
  96. /* Type of comparison function for sorting diffs. */
  97. typedef int dns_diff_compare_func(const void *, const void *);
  98. /***
  99. *** Functions
  100. ***/
  101. ISC_LANG_BEGINDECLS
  102. /**************************************************************************/
  103. /*
  104. * Manipulation of diffs and tuples.
  105. */
  106. isc_result_t
  107. dns_difftuple_create(isc_mem_t *mctx,
  108. dns_diffop_t op, dns_name_t *name, dns_ttl_t ttl,
  109. dns_rdata_t *rdata, dns_difftuple_t **tp);
  110. /*%<
  111. * Create a tuple. Deep copies are made of the name and rdata, so
  112. * they need not remain valid after the call.
  113. *
  114. * Requires:
  115. *\li *tp != NULL && *tp == NULL.
  116. *
  117. * Returns:
  118. *\li ISC_R_SUCCESS
  119. * \li ISC_R_NOMEMORY
  120. */
  121. void
  122. dns_difftuple_free(dns_difftuple_t **tp);
  123. /*%<
  124. * Free a tuple.
  125. *
  126. * Requires:
  127. * \li **tp is a valid tuple.
  128. *
  129. * Ensures:
  130. * \li *tp == NULL
  131. * \li All memory used by the tuple is freed.
  132. */
  133. isc_result_t
  134. dns_difftuple_copy(dns_difftuple_t *orig, dns_difftuple_t **copyp);
  135. /*%<
  136. * Copy a tuple.
  137. *
  138. * Requires:
  139. * \li 'orig' points to a valid tuple
  140. *\li copyp != NULL && *copyp == NULL
  141. */
  142. void
  143. dns_diff_init(isc_mem_t *mctx, dns_diff_t *diff);
  144. /*%<
  145. * Initialize a diff.
  146. *
  147. * Requires:
  148. * \li 'diff' points to an uninitialized dns_diff_t
  149. * \li allocated by the caller.
  150. *
  151. * Ensures:
  152. * \li '*diff' is a valid, empty diff.
  153. */
  154. void
  155. dns_diff_clear(dns_diff_t *diff);
  156. /*%<
  157. * Clear a diff, destroying all its tuples.
  158. *
  159. * Requires:
  160. * \li 'diff' points to a valid dns_diff_t.
  161. *
  162. * Ensures:
  163. * \li Any tuples in the diff are destroyed.
  164. * The diff now empty, but it is still valid
  165. * and may be reused without calling dns_diff_init
  166. * again. The only memory used is that of the
  167. * dns_diff_t structure itself.
  168. *
  169. * Notes:
  170. * \li Managing the memory of the dns_diff_t structure itself
  171. * is the caller's responsibility.
  172. */
  173. void
  174. dns_diff_append(dns_diff_t *diff, dns_difftuple_t **tuple);
  175. /*%<
  176. * Append a single tuple to a diff.
  177. *
  178. *\li 'diff' is a valid diff.
  179. * \li '*tuple' is a valid tuple.
  180. *
  181. * Ensures:
  182. *\li *tuple is NULL.
  183. *\li The tuple has been freed, or will be freed when the diff is cleared.
  184. */
  185. void
  186. dns_diff_appendminimal(dns_diff_t *diff, dns_difftuple_t **tuple);
  187. /*%<
  188. * Append 'tuple' to 'diff', removing any duplicate
  189. * or conflicting updates as needed to create a minimal diff.
  190. *
  191. * Requires:
  192. *\li 'diff' is a minimal diff.
  193. *
  194. * Ensures:
  195. *\li 'diff' is still a minimal diff.
  196. * \li *tuple is NULL.
  197. * \li The tuple has been freed, or will be freed when the diff is cleared.
  198. *
  199. */
  200. isc_result_t
  201. dns_diff_sort(dns_diff_t *diff, dns_diff_compare_func *compare);
  202. /*%<
  203. * Sort 'diff' in-place according to the comparison function 'compare'.
  204. */
  205. isc_result_t
  206. dns_diff_apply(dns_diff_t *diff, dns_db_t *db, dns_dbversion_t *ver);
  207. isc_result_t
  208. dns_diff_applysilently(dns_diff_t *diff, dns_db_t *db, dns_dbversion_t *ver);
  209. /*%<
  210. * Apply 'diff' to the database 'db'.
  211. *
  212. * dns_diff_apply() logs warnings about updates with no effect or
  213. * with inconsistent TTLs; dns_diff_applysilently() does not.
  214. *
  215. * For efficiency, the diff should be sorted by owner name.
  216. * If it is not sorted, operation will still be correct,
  217. * but less efficient.
  218. *
  219. * Requires:
  220. *\li *diff is a valid diff (possibly empty), containing
  221. * tuples of type #DNS_DIFFOP_ADD and/or
  222. * For #DNS_DIFFOP_DEL tuples, the TTL is ignored.
  223. *
  224. */
  225. isc_result_t
  226. dns_diff_load(dns_diff_t *diff, dns_addrdatasetfunc_t addfunc,
  227. void *add_private);
  228. /*%<
  229. * Like dns_diff_apply, but for use when loading a new database
  230. * instead of modifying an existing one. This bypasses the
  231. * database transaction mechanisms.
  232. *
  233. * Requires:
  234. *\li 'addfunc' is a valid dns_addradatasetfunc_t obtained from
  235. * dns_db_beginload()
  236. *
  237. *\li 'add_private' points to a corresponding dns_dbload_t *
  238. * (XXX why is it a void pointer, then?)
  239. */
  240. isc_result_t
  241. dns_diff_print(dns_diff_t *diff, FILE *file);
  242. /*%<
  243. * Print the differences to 'file' or if 'file' is NULL via the
  244. * logging system.
  245. *
  246. * Require:
  247. *\li 'diff' to be valid.
  248. *\li 'file' to refer to a open file or NULL.
  249. *
  250. * Returns:
  251. *\li #ISC_R_SUCCESS
  252. *\li #ISC_R_NOMEMORY
  253. *\li #ISC_R_UNEXPECTED
  254. *\li any error from dns_rdataset_totext()
  255. */
  256. ISC_LANG_ENDDECLS
  257. #endif /* DNS_DIFF_H */