mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-31 06:25:31 +00:00
Use clang-format to reformat the source files
This commit is contained in:
209
lib/dns/diff.c
209
lib/dns/diff.c
@@ -9,7 +9,6 @@
|
||||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
|
||||
/*! \file */
|
||||
|
||||
#include <inttypes.h>
|
||||
@@ -34,28 +33,30 @@
|
||||
#include <dns/result.h>
|
||||
#include <dns/time.h>
|
||||
|
||||
#define CHECK(op) \
|
||||
do { result = (op); \
|
||||
if (result != ISC_R_SUCCESS) goto failure; \
|
||||
#define CHECK(op) \
|
||||
do { \
|
||||
result = (op); \
|
||||
if (result != ISC_R_SUCCESS) \
|
||||
goto failure; \
|
||||
} while (0)
|
||||
|
||||
#define DIFF_COMMON_LOGARGS \
|
||||
dns_lctx, DNS_LOGCATEGORY_GENERAL, DNS_LOGMODULE_DIFF
|
||||
|
||||
static dns_rdatatype_t
|
||||
rdata_covers(dns_rdata_t *rdata) {
|
||||
return (rdata->type == dns_rdatatype_rrsig ?
|
||||
dns_rdata_covers(rdata) : 0);
|
||||
rdata_covers(dns_rdata_t *rdata)
|
||||
{
|
||||
return (rdata->type == dns_rdatatype_rrsig ? dns_rdata_covers(rdata)
|
||||
: 0);
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
dns_difftuple_create(isc_mem_t *mctx,
|
||||
dns_diffop_t op, const dns_name_t *name, dns_ttl_t ttl,
|
||||
dns_rdata_t *rdata, dns_difftuple_t **tp)
|
||||
dns_difftuple_create(isc_mem_t *mctx, dns_diffop_t op, const dns_name_t *name,
|
||||
dns_ttl_t ttl, dns_rdata_t *rdata, dns_difftuple_t **tp)
|
||||
{
|
||||
dns_difftuple_t *t;
|
||||
unsigned int size;
|
||||
unsigned char *datap;
|
||||
unsigned int size;
|
||||
unsigned char * datap;
|
||||
|
||||
REQUIRE(tp != NULL && *tp == NULL);
|
||||
|
||||
@@ -102,7 +103,8 @@ dns_difftuple_create(isc_mem_t *mctx,
|
||||
}
|
||||
|
||||
void
|
||||
dns_difftuple_free(dns_difftuple_t **tp) {
|
||||
dns_difftuple_free(dns_difftuple_t **tp)
|
||||
{
|
||||
dns_difftuple_t *t = *tp;
|
||||
*tp = NULL;
|
||||
isc_mem_t *mctx;
|
||||
@@ -117,20 +119,23 @@ dns_difftuple_free(dns_difftuple_t **tp) {
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
dns_difftuple_copy(dns_difftuple_t *orig, dns_difftuple_t **copyp) {
|
||||
dns_difftuple_copy(dns_difftuple_t *orig, dns_difftuple_t **copyp)
|
||||
{
|
||||
return (dns_difftuple_create(orig->mctx, orig->op, &orig->name,
|
||||
orig->ttl, &orig->rdata, copyp));
|
||||
}
|
||||
|
||||
void
|
||||
dns_diff_init(isc_mem_t *mctx, dns_diff_t *diff) {
|
||||
dns_diff_init(isc_mem_t *mctx, dns_diff_t *diff)
|
||||
{
|
||||
diff->mctx = mctx;
|
||||
ISC_LIST_INIT(diff->tuples);
|
||||
diff->magic = DNS_DIFF_MAGIC;
|
||||
}
|
||||
|
||||
void
|
||||
dns_diff_clear(dns_diff_t *diff) {
|
||||
dns_diff_clear(dns_diff_t *diff)
|
||||
{
|
||||
dns_difftuple_t *t;
|
||||
REQUIRE(DNS_DIFF_VALID(diff));
|
||||
while ((t = ISC_LIST_HEAD(diff->tuples)) != NULL) {
|
||||
@@ -169,18 +174,15 @@ dns_diff_appendminimal(dns_diff_t *diff, dns_difftuple_t **tuplep)
|
||||
* the one we are doing, there must be a programming
|
||||
* error. We report it but try to continue anyway.
|
||||
*/
|
||||
for (ot = ISC_LIST_HEAD(diff->tuples); ot != NULL;
|
||||
ot = next_ot)
|
||||
{
|
||||
for (ot = ISC_LIST_HEAD(diff->tuples); ot != NULL; ot = next_ot) {
|
||||
next_ot = ISC_LIST_NEXT(ot, link);
|
||||
if (dns_name_caseequal(&ot->name, &(*tuplep)->name) &&
|
||||
dns_rdata_compare(&ot->rdata, &(*tuplep)->rdata) == 0 &&
|
||||
ot->ttl == (*tuplep)->ttl)
|
||||
{
|
||||
ot->ttl == (*tuplep)->ttl) {
|
||||
ISC_LIST_UNLINK(diff->tuples, ot, link);
|
||||
if ((*tuplep)->op == ot->op) {
|
||||
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
||||
"unexpected non-minimal diff");
|
||||
"unexpected non-minimal diff");
|
||||
} else {
|
||||
dns_difftuple_free(tuplep);
|
||||
}
|
||||
@@ -196,11 +198,12 @@ dns_diff_appendminimal(dns_diff_t *diff, dns_difftuple_t **tuplep)
|
||||
}
|
||||
|
||||
static isc_stdtime_t
|
||||
setresign(dns_rdataset_t *modified) {
|
||||
dns_rdata_t rdata = DNS_RDATA_INIT;
|
||||
setresign(dns_rdataset_t *modified)
|
||||
{
|
||||
dns_rdata_t rdata = DNS_RDATA_INIT;
|
||||
dns_rdata_rrsig_t sig;
|
||||
int64_t when;
|
||||
isc_result_t result;
|
||||
int64_t when;
|
||||
isc_result_t result;
|
||||
|
||||
result = dns_rdataset_first(modified);
|
||||
INSIST(result == ISC_R_SUCCESS);
|
||||
@@ -221,7 +224,7 @@ setresign(dns_rdataset_t *modified) {
|
||||
}
|
||||
if (when == 0 || dns_time64_from32(sig.timeexpire) < when)
|
||||
when = dns_time64_from32(sig.timeexpire);
|
||||
next_rr:
|
||||
next_rr:
|
||||
dns_rdata_reset(&rdata);
|
||||
result = dns_rdataset_next(modified);
|
||||
}
|
||||
@@ -230,27 +233,28 @@ setresign(dns_rdataset_t *modified) {
|
||||
}
|
||||
|
||||
static void
|
||||
getownercase(dns_rdataset_t *rdataset, dns_name_t *name) {
|
||||
getownercase(dns_rdataset_t *rdataset, dns_name_t *name)
|
||||
{
|
||||
if (dns_rdataset_isassociated(rdataset))
|
||||
dns_rdataset_getownercase(rdataset, name);
|
||||
}
|
||||
|
||||
static void
|
||||
setownercase(dns_rdataset_t *rdataset, const dns_name_t *name) {
|
||||
setownercase(dns_rdataset_t *rdataset, const dns_name_t *name)
|
||||
{
|
||||
if (dns_rdataset_isassociated(rdataset))
|
||||
dns_rdataset_setownercase(rdataset, name);
|
||||
}
|
||||
|
||||
static isc_result_t
|
||||
diff_apply(dns_diff_t *diff, dns_db_t *db, dns_dbversion_t *ver,
|
||||
bool warn)
|
||||
diff_apply(dns_diff_t *diff, dns_db_t *db, dns_dbversion_t *ver, bool warn)
|
||||
{
|
||||
dns_difftuple_t *t;
|
||||
dns_dbnode_t *node = NULL;
|
||||
isc_result_t result;
|
||||
char namebuf[DNS_NAME_FORMATSIZE];
|
||||
char typebuf[DNS_RDATATYPE_FORMATSIZE];
|
||||
char classbuf[DNS_RDATACLASS_FORMATSIZE];
|
||||
dns_dbnode_t * node = NULL;
|
||||
isc_result_t result;
|
||||
char namebuf[DNS_NAME_FORMATSIZE];
|
||||
char typebuf[DNS_RDATATYPE_FORMATSIZE];
|
||||
char classbuf[DNS_RDATACLASS_FORMATSIZE];
|
||||
|
||||
REQUIRE(DNS_DIFF_VALID(diff));
|
||||
REQUIRE(DNS_DB_VALID(db));
|
||||
@@ -272,11 +276,11 @@ diff_apply(dns_diff_t *diff, dns_db_t *db, dns_dbversion_t *ver,
|
||||
|
||||
while (t != NULL && dns_name_equal(&t->name, name)) {
|
||||
dns_rdatatype_t type, covers;
|
||||
dns_diffop_t op;
|
||||
dns_diffop_t op;
|
||||
dns_rdatalist_t rdl;
|
||||
dns_rdataset_t rds;
|
||||
dns_rdataset_t ardataset;
|
||||
unsigned int options;
|
||||
dns_rdataset_t rds;
|
||||
dns_rdataset_t ardataset;
|
||||
unsigned int options;
|
||||
|
||||
op = t->op;
|
||||
type = t->rdata.type;
|
||||
@@ -306,18 +310,14 @@ diff_apply(dns_diff_t *diff, dns_db_t *db, dns_dbversion_t *ver,
|
||||
node = NULL;
|
||||
if (type != dns_rdatatype_nsec3 &&
|
||||
covers != dns_rdatatype_nsec3)
|
||||
CHECK(dns_db_findnode(db, name, true,
|
||||
&node));
|
||||
CHECK(dns_db_findnode(db, name, true, &node));
|
||||
else
|
||||
CHECK(dns_db_findnsec3node(db, name, true,
|
||||
&node));
|
||||
|
||||
while (t != NULL &&
|
||||
dns_name_equal(&t->name, name) &&
|
||||
t->op == op &&
|
||||
t->rdata.type == type &&
|
||||
rdata_covers(&t->rdata) == covers)
|
||||
{
|
||||
while (t != NULL && dns_name_equal(&t->name, name) &&
|
||||
t->op == op && t->rdata.type == type &&
|
||||
rdata_covers(&t->rdata) == covers) {
|
||||
/*
|
||||
* Remember the add name for
|
||||
* dns_rdataset_setownercase.
|
||||
@@ -333,13 +333,15 @@ diff_apply(dns_diff_t *diff, dns_db_t *db, dns_dbversion_t *ver,
|
||||
classbuf,
|
||||
sizeof(classbuf));
|
||||
isc_log_write(DIFF_COMMON_LOGARGS,
|
||||
ISC_LOG_WARNING,
|
||||
"'%s/%s/%s': TTL differs in "
|
||||
"rdataset, adjusting "
|
||||
"%lu -> %lu",
|
||||
namebuf, typebuf, classbuf,
|
||||
(unsigned long) t->ttl,
|
||||
(unsigned long) rdl.ttl);
|
||||
ISC_LOG_WARNING,
|
||||
"'%s/%s/%s': TTL differs "
|
||||
"in "
|
||||
"rdataset, adjusting "
|
||||
"%lu -> %lu",
|
||||
namebuf, typebuf,
|
||||
classbuf,
|
||||
(unsigned long)t->ttl,
|
||||
(unsigned long)rdl.ttl);
|
||||
}
|
||||
ISC_LIST_APPEND(rdl.rdata, &t->rdata, link);
|
||||
t = ISC_LIST_NEXT(t, link);
|
||||
@@ -361,8 +363,8 @@ diff_apply(dns_diff_t *diff, dns_db_t *db, dns_dbversion_t *ver,
|
||||
case DNS_DIFFOP_ADDRESIGN:
|
||||
options = DNS_DBADD_MERGE | DNS_DBADD_EXACT |
|
||||
DNS_DBADD_EXACTTTL;
|
||||
result = dns_db_addrdataset(db, node, ver,
|
||||
0, &rds, options,
|
||||
result = dns_db_addrdataset(db, node, ver, 0,
|
||||
&rds, options,
|
||||
&ardataset);
|
||||
break;
|
||||
case DNS_DIFFOP_DEL:
|
||||
@@ -441,19 +443,21 @@ diff_apply(dns_diff_t *diff, dns_db_t *db, dns_dbversion_t *ver,
|
||||
}
|
||||
return (ISC_R_SUCCESS);
|
||||
|
||||
failure:
|
||||
failure:
|
||||
if (node != NULL)
|
||||
dns_db_detachnode(db, &node);
|
||||
return (result);
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
dns_diff_apply(dns_diff_t *diff, dns_db_t *db, dns_dbversion_t *ver) {
|
||||
dns_diff_apply(dns_diff_t *diff, dns_db_t *db, dns_dbversion_t *ver)
|
||||
{
|
||||
return (diff_apply(diff, db, ver, true));
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
dns_diff_applysilently(dns_diff_t *diff, dns_db_t *db, dns_dbversion_t *ver) {
|
||||
dns_diff_applysilently(dns_diff_t *diff, dns_db_t *db, dns_dbversion_t *ver)
|
||||
{
|
||||
return (diff_apply(diff, db, ver, false));
|
||||
}
|
||||
|
||||
@@ -464,7 +468,7 @@ dns_diff_load(dns_diff_t *diff, dns_addrdatasetfunc_t addfunc,
|
||||
void *add_private)
|
||||
{
|
||||
dns_difftuple_t *t;
|
||||
isc_result_t result;
|
||||
isc_result_t result;
|
||||
|
||||
REQUIRE(DNS_DIFF_VALID(diff));
|
||||
|
||||
@@ -475,9 +479,9 @@ dns_diff_load(dns_diff_t *diff, dns_addrdatasetfunc_t addfunc,
|
||||
name = &t->name;
|
||||
while (t != NULL && dns_name_caseequal(&t->name, name)) {
|
||||
dns_rdatatype_t type, covers;
|
||||
dns_diffop_t op;
|
||||
dns_diffop_t op;
|
||||
dns_rdatalist_t rdl;
|
||||
dns_rdataset_t rds;
|
||||
dns_rdataset_t rds;
|
||||
|
||||
op = t->op;
|
||||
type = t->rdata.type;
|
||||
@@ -489,10 +493,10 @@ dns_diff_load(dns_diff_t *diff, dns_addrdatasetfunc_t addfunc,
|
||||
rdl.rdclass = t->rdata.rdclass;
|
||||
rdl.ttl = t->ttl;
|
||||
|
||||
while (t != NULL && dns_name_caseequal(&t->name, name) &&
|
||||
while (t != NULL &&
|
||||
dns_name_caseequal(&t->name, name) &&
|
||||
t->op == op && t->rdata.type == type &&
|
||||
rdata_covers(&t->rdata) == covers)
|
||||
{
|
||||
rdata_covers(&t->rdata) == covers) {
|
||||
ISC_LIST_APPEND(rdl.rdata, &t->rdata, link);
|
||||
t = ISC_LIST_NEXT(t, link);
|
||||
}
|
||||
@@ -522,7 +526,7 @@ dns_diff_load(dns_diff_t *diff, dns_addrdatasetfunc_t addfunc,
|
||||
}
|
||||
}
|
||||
result = ISC_R_SUCCESS;
|
||||
failure:
|
||||
failure:
|
||||
return (result);
|
||||
}
|
||||
|
||||
@@ -531,15 +535,15 @@ dns_diff_load(dns_diff_t *diff, dns_addrdatasetfunc_t addfunc,
|
||||
* and perhaps safer wrt thread stack overflow.
|
||||
*/
|
||||
isc_result_t
|
||||
dns_diff_sort(dns_diff_t *diff, dns_diff_compare_func *compare) {
|
||||
unsigned int length = 0;
|
||||
unsigned int i;
|
||||
dns_diff_sort(dns_diff_t *diff, dns_diff_compare_func *compare)
|
||||
{
|
||||
unsigned int length = 0;
|
||||
unsigned int i;
|
||||
dns_difftuple_t **v;
|
||||
dns_difftuple_t *p;
|
||||
dns_difftuple_t * p;
|
||||
REQUIRE(DNS_DIFF_VALID(diff));
|
||||
|
||||
for (p = ISC_LIST_HEAD(diff->tuples);
|
||||
p != NULL;
|
||||
for (p = ISC_LIST_HEAD(diff->tuples); p != NULL;
|
||||
p = ISC_LIST_NEXT(p, link))
|
||||
length++;
|
||||
if (length == 0)
|
||||
@@ -559,7 +563,6 @@ dns_diff_sort(dns_diff_t *diff, dns_diff_compare_func *compare) {
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Create an rdataset containing the single RR of the given
|
||||
* tuple. The caller must allocate the rdata, rdataset and
|
||||
@@ -586,39 +589,39 @@ diff_tuple_tordataset(dns_difftuple_t *t, dns_rdata_t *rdata,
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
dns_diff_print(dns_diff_t *diff, FILE *file) {
|
||||
isc_result_t result;
|
||||
dns_diff_print(dns_diff_t *diff, FILE *file)
|
||||
{
|
||||
isc_result_t result;
|
||||
dns_difftuple_t *t;
|
||||
char *mem = NULL;
|
||||
unsigned int size = 2048;
|
||||
const char *op = NULL;
|
||||
char * mem = NULL;
|
||||
unsigned int size = 2048;
|
||||
const char * op = NULL;
|
||||
|
||||
REQUIRE(DNS_DIFF_VALID(diff));
|
||||
|
||||
mem = isc_mem_get(diff->mctx, size);
|
||||
|
||||
for (t = ISC_LIST_HEAD(diff->tuples); t != NULL;
|
||||
t = ISC_LIST_NEXT(t, link))
|
||||
{
|
||||
t = ISC_LIST_NEXT(t, link)) {
|
||||
isc_buffer_t buf;
|
||||
isc_region_t r;
|
||||
|
||||
dns_rdatalist_t rdl;
|
||||
dns_rdataset_t rds;
|
||||
dns_rdata_t rd = DNS_RDATA_INIT;
|
||||
dns_rdataset_t rds;
|
||||
dns_rdata_t rd = DNS_RDATA_INIT;
|
||||
|
||||
result = diff_tuple_tordataset(t, &rd, &rdl, &rds);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
||||
"diff_tuple_tordataset failed: %s",
|
||||
dns_result_totext(result));
|
||||
result = ISC_R_UNEXPECTED;
|
||||
result = ISC_R_UNEXPECTED;
|
||||
goto cleanup;
|
||||
}
|
||||
again:
|
||||
again:
|
||||
isc_buffer_init(&buf, mem, size);
|
||||
result = dns_rdataset_totext(&rds, &t->name,
|
||||
false, false, &buf);
|
||||
result =
|
||||
dns_rdataset_totext(&rds, &t->name, false, false, &buf);
|
||||
|
||||
if (result == ISC_R_NOSPACE) {
|
||||
isc_mem_put(diff->mctx, mem, size);
|
||||
@@ -633,27 +636,37 @@ dns_diff_print(dns_diff_t *diff, FILE *file) {
|
||||
* Get rid of final newline.
|
||||
*/
|
||||
INSIST(buf.used >= 1 &&
|
||||
((char *) buf.base)[buf.used-1] == '\n');
|
||||
((char *)buf.base)[buf.used - 1] == '\n');
|
||||
buf.used--;
|
||||
|
||||
isc_buffer_usedregion(&buf, &r);
|
||||
switch (t->op) {
|
||||
case DNS_DIFFOP_EXISTS: op = "exists"; break;
|
||||
case DNS_DIFFOP_ADD: op = "add"; break;
|
||||
case DNS_DIFFOP_DEL: op = "del"; break;
|
||||
case DNS_DIFFOP_ADDRESIGN: op = "add re-sign"; break;
|
||||
case DNS_DIFFOP_DELRESIGN: op = "del re-sign"; break;
|
||||
case DNS_DIFFOP_EXISTS:
|
||||
op = "exists";
|
||||
break;
|
||||
case DNS_DIFFOP_ADD:
|
||||
op = "add";
|
||||
break;
|
||||
case DNS_DIFFOP_DEL:
|
||||
op = "del";
|
||||
break;
|
||||
case DNS_DIFFOP_ADDRESIGN:
|
||||
op = "add re-sign";
|
||||
break;
|
||||
case DNS_DIFFOP_DELRESIGN:
|
||||
op = "del re-sign";
|
||||
break;
|
||||
}
|
||||
if (file != NULL)
|
||||
fprintf(file, "%s %.*s\n", op, (int) r.length,
|
||||
(char *) r.base);
|
||||
fprintf(file, "%s %.*s\n", op, (int)r.length,
|
||||
(char *)r.base);
|
||||
else
|
||||
isc_log_write(DIFF_COMMON_LOGARGS, ISC_LOG_DEBUG(7),
|
||||
"%s %.*s", op, (int) r.length,
|
||||
(char *) r.base);
|
||||
"%s %.*s", op, (int)r.length,
|
||||
(char *)r.base);
|
||||
}
|
||||
result = ISC_R_SUCCESS;
|
||||
cleanup:
|
||||
cleanup:
|
||||
if (mem != NULL)
|
||||
isc_mem_put(diff->mctx, mem, size);
|
||||
return (result);
|
||||
|
Reference in New Issue
Block a user