]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Add a helper function to facilitate preparing dns_diff_t structures
authorMichał Kępień <michal@isc.org>
Tue, 13 Mar 2018 13:06:06 +0000 (14:06 +0100)
committerEvan Hunt <each@isc.org>
Thu, 10 May 2018 16:42:13 +0000 (09:42 -0700)
Implement dns_test_difffromchanges(), a function which enables preparing
a dns_diff_t structure from a mostly-textual representation of zone
database changes to be applied.  This will improve readability of test
case definitions by allowing contents of a dns_diff_t structure, passed
e.g. to update_sigs(), to be represented in a human-friendly manner.

(cherry picked from commit 3c22af0d35ada9f83557845d481ef1c9257ae383)
(cherry picked from commit d4c603eb8ac7c663d3fb5063259067d9f4600968)
(cherry picked from commit 1f454b8d91bff9ecb70307557d1a30e24cd6dc44)
(cherry picked from commit 7193496b6e72d2258fc71fa775f574a606b73ca9)

lib/dns/tests/dnstest.c
lib/dns/tests/dnstest.h

index 8a26c2f6ef6a6da0be3439898ef3eae3fe9295b8..67f213e46f41808252c17b14e3f594b3f2aa855a 100644 (file)
@@ -459,3 +459,72 @@ dns_test_namefromstring(const char *namestr, dns_fixedname_t *fname) {
 
        isc_buffer_free(&b);
 }
+
+isc_result_t
+dns_test_difffromchanges(dns_diff_t *diff, const zonechange_t *changes) {
+       isc_result_t result = ISC_R_SUCCESS;
+       unsigned char rdata_buf[1024];
+       dns_difftuple_t *tuple = NULL;
+       isc_consttextregion_t region;
+       dns_rdatatype_t rdatatype;
+       dns_fixedname_t fixedname;
+       dns_rdata_t rdata;
+       dns_name_t *name;
+       size_t i;
+
+       REQUIRE(diff != NULL);
+       REQUIRE(changes != NULL);
+
+       dns_diff_init(mctx, diff);
+
+       for (i = 0; changes[i].owner != NULL; i++) {
+               /*
+                * Parse owner name.
+                */
+               name = dns_fixedname_initname(&fixedname);
+               result = dns_name_fromstring(name, changes[i].owner, 0, mctx);
+               if (result != ISC_R_SUCCESS) {
+                       break;
+               }
+
+               /*
+                * Parse RDATA type.
+                */
+               region.base = changes[i].type;
+               region.length = strlen(changes[i].type);
+               result = dns_rdatatype_fromtext(&rdatatype,
+                                               (isc_textregion_t *)&region);
+               if (result != ISC_R_SUCCESS) {
+                       break;
+               }
+
+               /*
+                * Parse RDATA.
+                */
+               dns_rdata_init(&rdata);
+               result = dns_test_rdatafromstring(&rdata, dns_rdataclass_in,
+                                                 rdatatype, rdata_buf,
+                                                 sizeof(rdata_buf),
+                                                 changes[i].rdata);
+               if (result != ISC_R_SUCCESS) {
+                       break;
+               }
+
+               /*
+                * Create a diff tuple for the parsed change and append it to
+                * the diff.
+                */
+               result = dns_difftuple_create(mctx, changes[i].op, name,
+                                             changes[i].ttl, &rdata, &tuple);
+               if (result != ISC_R_SUCCESS) {
+                       break;
+               }
+               dns_diff_append(diff, &tuple);
+       }
+
+       if (result != ISC_R_SUCCESS) {
+               dns_diff_clear(diff);
+       }
+
+       return (result);
+}
index 5f6a54cb53afd7fab8109b2dc883e82f62da66e6..8763fff118d1a9ae983a7036c383f4f39c393043 100644 (file)
@@ -28,6 +28,7 @@
 #include <isc/timer.h>
 #include <isc/util.h>
 
+#include <dns/diff.h>
 #include <dns/result.h>
 #include <dns/zone.h>
 
                        goto cleanup; \
        } while (0)
 
+typedef struct {
+       dns_diffop_t op;
+       const char *owner;
+       dns_ttl_t ttl;
+       const char *type;
+       const char *rdata;
+} zonechange_t;
+
+#define ZONECHANGE_SENTINEL { 0, NULL, 0, NULL, NULL }
+
 extern isc_mem_t *mctx;
 extern isc_entropy_t *ectx;
 extern isc_log_t *lctx;
@@ -113,3 +124,10 @@ dns_test_rdatafromstring(dns_rdata_t *rdata, dns_rdataclass_t rdclass,
 
 void
 dns_test_namefromstring(const char *namestr, dns_fixedname_t *fname);
+
+/*%
+ * Given a pointer to an uninitialized dns_diff_t structure in 'diff', make it
+ * contain diff tuples representing zone database changes listed in 'changes'.
+ */
+isc_result_t
+dns_test_difffromchanges(dns_diff_t *diff, const zonechange_t *changes);