]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Extract the do-while loop in dns__zone_updatesigs() into a separate function
authorMichał Kępień <michal@isc.org>
Thu, 10 May 2018 07:43:38 +0000 (09:43 +0200)
committerMichał Kępień <michal@isc.org>
Thu, 10 May 2018 07:43:38 +0000 (09:43 +0200)
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.

lib/dns/zone.c

index 568e4727f7d4059972230011cb954d90216b787f..29537d04077397876c5a0638aab946199d8d437c 100644 (file)
@@ -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);
 }