Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optionally exclude ZONEMD RRs in ldns-compare-zone #220

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions examples/ldns-compare-zones.c
Original file line number Diff line number Diff line change
Expand Up @@ -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] "
"<zonefile1> <zonefile2>\n", prog);
printf(" -i - print inserted\n");
printf(" -d - print deleted\n");
Expand All @@ -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");
Expand All @@ -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]);
Expand All @@ -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;
Expand Down Expand Up @@ -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",
Expand All @@ -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);
Expand Down
15 changes: 15 additions & 0 deletions ldns/zone.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions zone.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand Down