From 6594f7acb2c48819f49e70871df588b7a82ae0a8 Mon Sep 17 00:00:00 2001 From: Matthijs Mekking Date: Fri, 8 Feb 2019 16:20:47 +0100 Subject: [PATCH] Remove rpz->db_registered As pointed out in !813 db_registered is sort of redundant. It is set to `true` only in `dns_zone_rpz_enable_db()` right before the `dns_rpz_dbupdate_callback()` callback is registered. It is only required in that callback and it is the only place that the callback is registered. Therefore there is no path that that `REQUIRE` can fail. The `db_registered` variable is only set to `false` in `dns_rpz_new_zone`, so it is not like the variable is unset again later. The only other place where `db_registered` is checked is in `rpz_detach()`. If `true`, it will call `dns_db_updatenotify_unregister()`. However if that happens, the `db_registered` is not set back to `false` thus this implies that this may happen multiple times. If called a second time, most likely the unregister function will return `ISC_R_NOTFOUND`, but the return value is not checked anyway. So it can do without the `db_registered` check. --- lib/dns/include/dns/rpz.h | 5 ++--- lib/dns/rpz.c | 8 ++------ lib/dns/zone.c | 1 - 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/lib/dns/include/dns/rpz.h b/lib/dns/include/dns/rpz.h index 0c12da6e9d..e8f5170ca7 100644 --- a/lib/dns/include/dns/rpz.h +++ b/lib/dns/include/dns/rpz.h @@ -144,15 +144,14 @@ struct dns_rpz_zone { isc_ht_t *nodes; /* entries in zone */ dns_rpz_zones_t *rpzs; /* owner */ isc_time_t lastupdated; /* last time the zone was processed */ - bool updatepending; /* there is an update pending/waiting */ - bool updaterunning; /* there is an update running */ + bool updatepending; /* there is an update pending/waiting */ + bool updaterunning; /* there is an update running */ dns_db_t *db; /* zones database */ dns_dbversion_t *dbversion; /* version we will be updating to */ dns_db_t *updb; /* zones database we're working on */ dns_dbversion_t *updbversion; /* version we're currently working on */ dns_dbiterator_t *updbit; /* iterator to use when updating */ isc_ht_t *newnodes; /* entries in zone being updated */ - bool db_registered; /* is the notify event registered? */ isc_timer_t *updatetimer; isc_event_t updateevent; }; diff --git a/lib/dns/rpz.c b/lib/dns/rpz.c index d7112b01ed..83f8f7d6c5 100644 --- a/lib/dns/rpz.c +++ b/lib/dns/rpz.c @@ -1549,7 +1549,6 @@ dns_rpz_new_zone(dns_rpz_zones_t *rpzs, dns_rpz_zone_t **rpzp) { zone->updbversion = NULL; zone->updbit = NULL; zone->rpzs = rpzs; - zone->db_registered = false; ISC_EVENT_INIT(&zone->updateevent, sizeof(zone->updateevent), 0, NULL, 0, NULL, NULL, NULL, NULL, NULL); @@ -1584,7 +1583,6 @@ dns_rpz_dbupdate_callback(dns_db_t *db, void *fn_arg) { REQUIRE(zone != NULL); LOCK(&zone->rpzs->maint_lock); - REQUIRE(zone->db_registered); /* New zone came as AXFR */ if (zone->db != NULL && zone->db != db) { @@ -2100,10 +2098,8 @@ rpz_detach(dns_rpz_zone_t **rpzp, dns_rpz_zones_t *rpzs) { dns_db_closeversion(rpz->db, &rpz->dbversion, false); } if (rpz->db != NULL) { - if (rpz->db_registered) { - dns_db_updatenotify_unregister( - rpz->db, dns_rpz_dbupdate_callback, rpz); - } + dns_db_updatenotify_unregister( + rpz->db, dns_rpz_dbupdate_callback, rpz); dns_db_detach(&rpz->db); } if (rpz->updaterunning) { diff --git a/lib/dns/zone.c b/lib/dns/zone.c index 457e47b927..28f353a2ea 100644 --- a/lib/dns/zone.c +++ b/lib/dns/zone.c @@ -1786,7 +1786,6 @@ dns_zone_rpz_enable_db(dns_zone_t *zone, dns_db_t *db) { if (zone->rpz_num == DNS_RPZ_INVALID_NUM) return; REQUIRE(zone->rpzs != NULL); - zone->rpzs->zones[zone->rpz_num]->db_registered = true; result = dns_db_updatenotify_register(db, dns_rpz_dbupdate_callback, zone->rpzs->zones[zone->rpz_num]);