From: Wouter Wijngaards Date: Mon, 1 Mar 2010 09:49:11 +0000 (+0000) Subject: -s option. X-Git-Tag: release-1.6.5~75 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d1ec8aa6a4bf8bbf315d8665a110fef7778dae55;p=thirdparty%2Fldns.git -s option. --- diff --git a/Changelog b/Changelog index 404817ec..6235192f 100644 --- a/Changelog +++ b/Changelog @@ -6,6 +6,7 @@ * Fix parse of \# syntax with space for type LOC. * Fix ldns_dname_absolute for escape sequences, fixes some parse errs. * bugfix #297: linking ssl, bug due to patch submitted as #296. + * ldns-compare-zones -s to not exclude SOA record from comparison. 1.6.4 2010-01-20 * Imported pyldns contribution by Zdenek Vasicek and Karel Slany. diff --git a/examples/ldns-compare-zones.1 b/examples/ldns-compare-zones.1 index ae4d152a..facccd87 100644 --- a/examples/ldns-compare-zones.1 +++ b/examples/ldns-compare-zones.1 @@ -7,55 +7,50 @@ ldns-compare-zones \- read and compare two zonefiles and print differences .IR [-i] .IR [-d] .IR [-z] +.IR [-s] .IR ZONEFILE1 .IR ZONEFILE2 - .SH DESCRIPTION - \fBldns-compare-zones\fR reads two DNS zone files and prints number of differences. +.nf Output is formated to: +NUM_INS -NUM_DEL ~NUM_CHG +.fi The major comparison is based on the owner name. If an owner name is present in zonefile 1, but not in zonefile 2, the resource records with this owner name are considered deleted, and counted as NUM_DEL. If an owner name is present in zonefile 2, but not in zonefile 1, the resource records with this owner name are considered inserted, and counted as NUM_INS. If an owner name is present in both, but there is a difference in the amount or content of the records, these are considered changed, and counted as NUM_CHG. - .SH OPTIONS .TP \fB-c\fR Print resource records whose owner names are in both zone files, but with different resource records. (a.k.a. changed) - .TP \fB-i\fR Print resource records whose owner names are present only in ZONEFILE2 (a.k.a. inserted) - .TP \fB-d\fR Print resource records whose owner names are present only in ZONEFILE1 (a.k.a. deleted) - .TP \fB-a\fR Print all changes. Specifying this option is the same as specifying -c -i amd -d. - .TP \fB-z\fR Suppress zone sorting; this option is not recommended; it can cause records to be incorrectly marked as changed, depending of the nature of the changes. - +.TP +\fB-s\fR +Do not exclude the SOA record from the comparison. The SOA record may +then show up as changed due to a new serial number. Off by default since +you may be interested to know if (other zone apex elements) have changed. .TP \fB-h\fR Show usage and exit - .TP \fB-v\fR Show the version and exit - - .SH AUTHOR Written by Ondřej Surý for CZ.NIC, z.s.p.o. (czech domain registry) - .SH REPORTING BUGS Report bugs to . - .SH COPYRIGHT Copyright (C) 2005 CZ.NIC, z.s.p.o.. This is free software. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR diff --git a/examples/ldns-compare-zones.c b/examples/ldns-compare-zones.c index bb0ffc94..56d36a28 100644 --- a/examples/ldns-compare-zones.c +++ b/examples/ldns-compare-zones.c @@ -25,12 +25,13 @@ static void usage(int argc, char **argv) { - printf("Usage: %s [-v] [-i] [-d] [-c] \n", + printf("Usage: %s [-v] [-i] [-d] [-c] [-s] \n", argv[0]); printf(" -i - print inserted\n"); printf(" -d - print deleted\n"); printf(" -c - print changed\n"); printf(" -a - print all differences (-i -d -c)\n"); + printf(" -s - do not exclude SOA record from comparison\n"); printf(" -z - do not sort zones\n"); } @@ -50,10 +51,10 @@ main(int argc, char **argv) size_t num_ins = 0, num_del = 0, num_chg = 0; int c; bool opt_deleted = false, opt_inserted = false, opt_changed = false; - bool sort = true; + bool sort = true, inc_soa = false; char op = 0; - while ((c = getopt(argc, argv, "ahvdicz")) != -1) { + while ((c = getopt(argc, argv, "ahvdicsz")) != -1) { switch (c) { case 'h': usage(argc, argv); @@ -66,6 +67,9 @@ main(int argc, char **argv) ldns_version()); exit(EXIT_SUCCESS); break; + case 's': + inc_soa = true; + break; case 'z': sort = false; break; @@ -157,6 +161,23 @@ main(int argc, char **argv) ldns_zone_sort(z2); } + if(inc_soa) { + ldns_rr_list* wsoa = ldns_rr_list_new(); + ldns_rr_list_push_rr(wsoa, ldns_zone_soa(z1)); + ldns_rr_list_cat(wsoa, rrl1); + rrl1 = wsoa; + rrc1 = ldns_rr_list_rr_count(rrl1); + wsoa = ldns_rr_list_new(); + ldns_rr_list_push_rr(wsoa, ldns_zone_soa(z2)); + ldns_rr_list_cat(wsoa, rrl2); + rrl2 = wsoa; + rrc2 = ldns_rr_list_rr_count(rrl2); + if(sort) { + ldns_rr_list_sort(rrl1); + ldns_rr_list_sort(rrl2); + } + } + /* * Walk through both zones. The previously seen resource record is * kept (in the variable rrx) so that we can recognize when we are @@ -251,6 +272,10 @@ main(int argc, char **argv) (unsigned int) num_chg); /* Free resources */ + if(inc_soa) { + ldns_rr_list_free(rrl1); + ldns_rr_list_free(rrl2); + } ldns_zone_deep_free(z2); ldns_zone_deep_free(z1);