]> git.ipfire.org Git - thirdparty/knot-dns.git/commitdiff
zone load: double changeset works only without the feature ignoring DNSSEC changes...
authorLibor Peltan <libor.peltan@nic.cz>
Thu, 11 Jul 2019 12:17:40 +0000 (14:17 +0200)
committerLibor Peltan <libor.peltan@nic.cz>
Thu, 15 Aug 2019 12:25:18 +0000 (14:25 +0200)
src/knot/events/handlers/load.c
src/knot/updates/zone-update.c
src/knot/updates/zone-update.h

index f1f71fe6d550c1c928063c8544f854a7fd40908c..cc71cab9398823d42caceb66a59cd1652b505ce8 100644 (file)
@@ -145,8 +145,8 @@ int event_load(conf_t *conf, zone_t *zone)
        val = conf_zone_get(conf, C_DNSSEC_SIGNING, zone->name);
        bool dnssec_enable = conf_bool(&val), zu_from_zf_conts = false;
        zone_update_t up = { 0 };
-       bool ignore_dnssec = ((zf_from == ZONEFILE_LOAD_DIFF || zf_from == ZONEFILE_LOAD_DIFSE)
-                             && dnssec_enable);
+       bool do_diff = (zf_from == ZONEFILE_LOAD_DIFF || zf_from == ZONEFILE_LOAD_DIFSE);
+       bool ignore_dnssec = (do_diff && dnssec_enable);
 
        // Create zone_update structure according to current state.
        if (old_contents_exist) {
@@ -163,8 +163,6 @@ int event_load(conf_t *conf, zone_t *zone)
                } else {
                        // compute ZF diff and if success, apply it
                        ret = zone_update_from_differences(&up, zone, zone->contents, zf_conts, UPDATE_INCREMENTAL, ignore_dnssec);
-                       zone_contents_deep_free(zf_conts);
-                       zf_conts = NULL;
                }
        } else {
                if (journal_conts != NULL && zf_from != ZONEFILE_LOAD_WHOLE) {
@@ -175,8 +173,6 @@ int event_load(conf_t *conf, zone_t *zone)
                                // load zone-in-journal, compute ZF diff and if success, apply it
                                ret = zone_update_from_differences(&up, zone, journal_conts, zf_conts,
                                                                   UPDATE_HYBRID, ignore_dnssec);
-                               zone_contents_deep_free(zf_conts);
-                               zf_conts = NULL;
                                if (ret == KNOT_ESEMCHECK || ret == KNOT_ERANGE) {
                                        log_zone_warning(zone->name,
                                                         "zone file changed with SOA serial %s, "
@@ -221,10 +217,8 @@ int event_load(conf_t *conf, zone_t *zone)
 
        uint32_t middle_serial = zone_contents_serial(up.new_cont);
 
-       if ((zf_from == ZONEFILE_LOAD_DIFF || zf_from == ZONEFILE_LOAD_DIFSE) &&
-           old_contents_exist && journal_conts == NULL) {
+       if (do_diff && old_contents_exist && journal_conts == NULL && dnssec_enable) {
                ret = zone_update_start_extra(&up);
-               printf("start extra %d %u\n", ret, up.flags);
                if (ret != KNOT_EOK) {
                        zone_update_clear(&up);
                        goto cleanup;
index 451f805e76f6dcaee19ebe5893cdc81abd983b70..867e8bc3d7d1cc7354b0a90d3631aeda998a8c92 100644 (file)
@@ -194,6 +194,7 @@ int zone_update_from_differences(zone_update_t *update, zone_t *zone, zone_conte
                log_zone_info(zone->name, "automatic SOA serial increment");
        }
 
+       update->init_cont = new_cont;
        return KNOT_EOK;
 }
 
@@ -255,19 +256,31 @@ int zone_update_start_extra(zone_update_t *update)
                return ret;
        }
 
-       update->extra_ch.soa_from = node_create_rrset(update->new_cont->apex, KNOT_RRTYPE_SOA);
-       if (update->extra_ch.soa_from == NULL) {
-               return KNOT_ENOMEM;
-       }
+       if (update->init_cont != NULL) {
+               ret = zone_update_increment_soa(update, conf());
+               if (ret != KNOT_EOK) {
+                       return ret;
+               }
 
-       ret = zone_update_increment_soa(update, conf());
-       if (ret != KNOT_EOK) {
-               return ret;
-       }
+               ret = zone_contents_diff(update->init_cont, update->new_cont, &update->extra_ch, false);
+               if (ret != KNOT_EOK) {
+                       return ret;
+               }
+       } else {
+               update->extra_ch.soa_from = node_create_rrset(update->new_cont->apex, KNOT_RRTYPE_SOA);
+               if (update->extra_ch.soa_from == NULL) {
+                       return KNOT_ENOMEM;
+               }
 
-       update->extra_ch.soa_to = node_create_rrset(update->new_cont->apex, KNOT_RRTYPE_SOA);
-       if (update->extra_ch.soa_to == NULL) {
-               return KNOT_ENOMEM;
+               ret = zone_update_increment_soa(update, conf());
+               if (ret != KNOT_EOK) {
+                       return ret;
+               }
+
+               update->extra_ch.soa_to = node_create_rrset(update->new_cont->apex, KNOT_RRTYPE_SOA);
+               if (update->extra_ch.soa_to == NULL) {
+                       return KNOT_ENOMEM;
+               }
        }
 
        update->flags |= UPDATE_EXTRA_CHSET;
@@ -357,6 +370,8 @@ void zone_update_clear(zone_update_t *update)
                changeset_clear(&update->extra_ch);
        }
 
+       zone_contents_deep_free(update->init_cont);
+
        if (update->flags & (UPDATE_FULL | UPDATE_HYBRID)) {
                update_cleanup(update->a_ctx);
                zone_contents_deep_free(update->new_cont);
index dd7d8cd9079cb1cd5e6f05601e9e4c90d1ef87fc..1ad2d64602a5f93f5a39cfd2cd830bf93822891a 100644 (file)
@@ -28,6 +28,7 @@ typedef struct zone_update {
        zone_t *zone;                /*!< Zone being updated. */
        zone_contents_t *new_cont;   /*!< New zone contents for full updates. */
        changeset_t change;          /*!< Changes we want to apply. */
+       zone_contents_t *init_cont;  /*!< Exact contents of the zonefile. */
        changeset_t extra_ch;        /*!< Extra changeset to store just diff btwn zonefile and result. */
        apply_ctx_t *a_ctx;          /*!< Context for applying changesets. */
        uint32_t flags;              /*!< Zone update flags. */