From: Michał Kępień Date: Thu, 10 May 2018 07:43:38 +0000 (+0200) Subject: Extract the do-while loop in dns__zone_updatesigs() into a separate function X-Git-Tag: v9.13.0~26^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=31cdf770a491e94bd2a124b798eaa7117dfe2208;p=thirdparty%2Fbind9.git Extract the do-while loop in dns__zone_updatesigs() into a separate function The do-while loop in dns__zone_updatesigs() is hard to follow due to heavy nesting and the 'tuple' variable also being used in the outer for loop. Add a comment to explain the purpose of the do-while loop. Extract it into a separate function to decrease indentation and prevent using 'tuple' in two different loops. --- diff --git a/lib/dns/zone.c b/lib/dns/zone.c index 568e4727f7d..29537d04077 100644 --- a/lib/dns/zone.c +++ b/lib/dns/zone.c @@ -7288,6 +7288,25 @@ need_nsec_chain(dns_db_t *db, dns_dbversion_t *ver, return (result); } +/*% + * Remove all tuples with the same name and type as 'cur' from 'src' and append + * them to 'dst'. + */ +static void +move_matching_tuples(dns_difftuple_t *cur, dns_diff_t *src, dns_diff_t *dst) { + do { + dns_difftuple_t *next = ISC_LIST_NEXT(cur, link); + while (next != NULL && + (cur->rdata.type != next->rdata.type || + !dns_name_equal(&cur->name, &next->name))) + next = ISC_LIST_NEXT(next, link); + ISC_LIST_UNLINK(src->tuples, cur, link); + dns_diff_appendminimal(dst, &cur); + INSIST(cur == NULL); + cur = next; + } while (cur != NULL); +} + /*% * Add/remove DNSSEC signatures for the list of "raw" zone changes supplied in * 'diff'. Gradually remove tuples from 'diff' and append them to 'zonediff' @@ -7337,17 +7356,14 @@ dns__zone_updatesigs(dns_diff_t *diff, dns_db_t *db, dns_dbversion_t *version, return (result); } - do { - dns_difftuple_t *next = ISC_LIST_NEXT(tuple, link); - while (next != NULL && - (tuple->rdata.type != next->rdata.type || - !dns_name_equal(&tuple->name, &next->name))) - next = ISC_LIST_NEXT(next, link); - ISC_LIST_UNLINK(diff->tuples, tuple, link); - dns_diff_appendminimal(zonediff->diff, &tuple); - INSIST(tuple == NULL); - tuple = next; - } while (tuple != NULL); + /* + * Signature changes for all RRs with name tuple->name and type + * tuple->rdata.type were appended to zonediff->diff. Now we + * remove all the "raw" changes with the same name and type + * from diff (so that they are not processed by this loop + * again) and append them to zonediff so that they get applied. + */ + move_matching_tuples(tuple, diff, zonediff->diff); } return (ISC_R_SUCCESS); }