From: Michał Kępień Date: Tue, 13 Mar 2018 13:06:06 +0000 (+0100) Subject: Add a helper function to facilitate preparing dns_diff_t structures X-Git-Tag: v9.9.13rc1~28^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f7a84380dd18c9bba01ea83952869ebbf668b02f;p=thirdparty%2Fbind9.git Add a helper function to facilitate preparing dns_diff_t structures 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) --- diff --git a/lib/dns/tests/dnstest.c b/lib/dns/tests/dnstest.c index 8a26c2f6ef6..67f213e46f4 100644 --- a/lib/dns/tests/dnstest.c +++ b/lib/dns/tests/dnstest.c @@ -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 *)®ion); + 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); +} diff --git a/lib/dns/tests/dnstest.h b/lib/dns/tests/dnstest.h index 5f6a54cb53a..8763fff118d 100644 --- a/lib/dns/tests/dnstest.h +++ b/lib/dns/tests/dnstest.h @@ -28,6 +28,7 @@ #include #include +#include #include #include @@ -38,6 +39,16 @@ 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);