diff --git a/examples/ldns-compare-zones.c b/examples/ldns-compare-zones.c index 750a8455..7cb25a37 100644 --- a/examples/ldns-compare-zones.c +++ b/examples/ldns-compare-zones.c @@ -26,7 +26,7 @@ static void usage(char *prog) { - printf("Usage: %s [-v] [-i] [-d] [-c] [-u] [-s] [-e] " + printf("Usage: %s [-v] [-i] [-d] [-c] [-u] [-s] [-Z] [-e] " " \n", prog); printf(" -i - print inserted\n"); printf(" -d - print deleted\n"); @@ -35,6 +35,7 @@ usage(char *prog) printf(" -U - print unchanged records in changed names\n"); printf(" -a - print all differences (-i -d -c)\n"); printf(" -s - do not exclude SOA record from comparison\n"); + printf(" -Z - exclude ZONEMD records from comparison\n"); printf(" -z - do not sort zones\n"); printf(" -e - exit with status 2 on changed zones\n"); printf(" -h - show usage and exit\n"); @@ -61,10 +62,11 @@ main(int argc, char **argv) bool opt_deleted = false, opt_inserted = false; bool opt_changed = false, opt_unchanged = false, opt_Unchanged = false; bool sort = true, inc_soa = false; + ldns_rr_type exc_rr_type = 0; bool opt_exit_status = false; char op = 0; - while ((c = getopt(argc, argv, "ahvdicuUesz")) != -1) { + while ((c = getopt(argc, argv, "ahvdicuUesZz")) != -1) { switch (c) { case 'h': usage(argv[0]); @@ -83,6 +85,9 @@ main(int argc, char **argv) case 's': inc_soa = true; break; + case 'Z': + exc_rr_type = LDNS_RR_TYPE_ZONEMD; + break; case 'z': sort = false; break; @@ -129,8 +134,8 @@ main(int argc, char **argv) exit(EXIT_FAILURE); } /* Read first zone */ - s = ldns_zone_new_frm_fp_l(&z1, fp1, NULL, 0, - LDNS_RR_CLASS_IN, &line_nr1); + s = ldns_zone_new_frm_fp_l_e(&z1, fp1, NULL, 0, + LDNS_RR_CLASS_IN, &line_nr1, exc_rr_type); if (s != LDNS_STATUS_OK) { fclose(fp1); fprintf(stderr, "%s: %s at line %d\n", @@ -148,8 +153,8 @@ main(int argc, char **argv) exit(EXIT_FAILURE); } /* Read second zone */ - s = ldns_zone_new_frm_fp_l(&z2, fp2, NULL, 0, - LDNS_RR_CLASS_IN, &line_nr2); + s = ldns_zone_new_frm_fp_l_e(&z2, fp2, NULL, 0, + LDNS_RR_CLASS_IN, &line_nr2, exc_rr_type); if (s != LDNS_STATUS_OK) { ldns_zone_deep_free(z1); fclose(fp2); diff --git a/ldns/zone.h b/ldns/zone.h index 805661f8..5eb64a09 100644 --- a/ldns/zone.h +++ b/ldns/zone.h @@ -150,6 +150,21 @@ ldns_status ldns_zone_new_frm_fp(ldns_zone **z, FILE *fp, const ldns_rdf *origin */ ldns_status ldns_zone_new_frm_fp_l(ldns_zone **z, FILE *fp, const ldns_rdf *origin, uint32_t ttl, ldns_rr_class c, int *line_nr); +/** + * Create a new zone from a file, keep track of the line numbering, + * filtering out the specified RR type + * \param[out] z the new zone + * \param[in] *fp the filepointer to use + * \param[in] *origin the zones' origin + * \param[in] ttl default ttl to use + * \param[in] c default class to use (IN) + * \param[out] line_nr used for error msg, to get to the line number + * \param[in] exc excluded RR type + * + * \return ldns_status mesg with an error or LDNS_STATUS_OK + */ +ldns_status ldns_zone_new_frm_fp_l_e(ldns_zone **z, FILE *fp, const ldns_rdf *origin, uint32_t ttl, ldns_rr_class c, int *line_nr, ldns_rr_type exc); + /** * Frees the allocated memory for the zone, and the rr_list structure in it * \param[in] zone the zone to free diff --git a/zone.c b/zone.c index 9a5d4c4e..b5612be8 100644 --- a/zone.c +++ b/zone.c @@ -197,6 +197,13 @@ ldns_status _ldns_rr_new_frm_fp_l_internal(ldns_rr **newrr, FILE *fp, ldns_status ldns_zone_new_frm_fp_l(ldns_zone **z, FILE *fp, const ldns_rdf *origin, uint32_t default_ttl, ldns_rr_class ATTR_UNUSED(c), int *line_nr) +{ + return ldns_zone_new_frm_fp_l_e(z, fp, origin, default_ttl, c, line_nr, 0); +} + +ldns_status +ldns_zone_new_frm_fp_l_e(ldns_zone **z, FILE *fp, const ldns_rdf *origin, + uint32_t default_ttl, ldns_rr_class ATTR_UNUSED(c), int *line_nr, ldns_rr_type exc) { ldns_zone *newzone; ldns_rr *rr, *prev_rr = NULL; @@ -301,6 +308,11 @@ ldns_zone_new_frm_fp_l(ldns_zone **z, FILE *fp, const ldns_rdf *origin, } continue; } + /* skip excluded RR type */ + else if (ldns_rr_get_type(rr) == exc) { + ldns_rr_free(rr); + continue; + } /* a normal RR - as sofar the DNS is normal */ if (!ldns_zone_push_rr(newzone, rr)) {