From ea2fe8eea4f78dd32431b0866fd34334dacf50c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Mon, 26 Jun 2023 11:09:26 +0200 Subject: [PATCH] Refactor dns_zone_create() to return void After isc_stats_create() change, the dns_zone_create() cannot fail, so refactor the function to return void and fix all its uses. --- bin/check/check-tool.c | 2 +- bin/named/server.c | 8 ++++---- bin/tests/system/dyndb/driver/zone.c | 8 ++------ fuzz/dns_message_checksig.c | 7 +------ lib/dns/dlz.c | 5 +---- lib/dns/include/dns/zone.h | 7 +------ lib/dns/zone.c | 12 ++++-------- tests/libtest/dns.c | 5 +---- 8 files changed, 15 insertions(+), 39 deletions(-) diff --git a/bin/check/check-tool.c b/bin/check/check-tool.c index 77aecccc70..93cde40550 100644 --- a/bin/check/check-tool.c +++ b/bin/check/check-tool.c @@ -595,7 +595,7 @@ load_zone(isc_mem_t *mctx, const char *zonename, const char *filename, zonename, filename, classname); } - CHECK(dns_zone_create(&zone, mctx, 0)); + dns_zone_create(&zone, mctx, 0); dns_zone_settype(zone, dns_zone_primary); diff --git a/bin/named/server.c b/bin/named/server.c index 3c63b4d843..ca4a5b3260 100644 --- a/bin/named/server.c +++ b/bin/named/server.c @@ -1938,7 +1938,7 @@ dns64_reverse(dns_view_t *view, isc_mem_t *mctx, isc_netaddr_t *na, isc_buffer_constinit(&b, reverse, strlen(reverse)); isc_buffer_add(&b, strlen(reverse)); CHECK(dns_name_fromtext(name, &b, dns_rootname, 0, NULL)); - CHECK(dns_zone_create(&zone, mctx, 0)); + dns_zone_create(&zone, mctx, 0); CHECK(dns_zone_setorigin(zone, name)); dns_zone_setview(zone, view); CHECK(dns_zonemgr_managezone(named_g_server->zonemgr, zone)); @@ -3613,7 +3613,7 @@ create_ipv4only_zone(dns_zone_t *pzone, dns_view_t *view, /* * Create the actual zone. */ - CHECK(dns_zone_create(&zone, mctx, 0)); + dns_zone_create(&zone, mctx, 0); CHECK(dns_zone_setorigin(zone, name)); CHECK(dns_zonemgr_managezone(named_g_server->zonemgr, zone)); dns_zone_setclass(zone, view->rdclass); @@ -6793,8 +6793,8 @@ configure_zone(const cfg_obj_t *config, const cfg_obj_t *zconfig, if (inline_signing) { dns_zone_getraw(zone, &raw); if (raw == NULL) { - CHECK(dns_zone_create(&raw, dns_zone_getmem(zone), - dns_zone_gettid(zone))); + dns_zone_create(&raw, dns_zone_getmem(zone), + dns_zone_gettid(zone)); CHECK(dns_zone_setorigin(raw, origin)); dns_zone_setview(raw, view); dns_zone_setstats(raw, named_g_server->zonestats); diff --git a/bin/tests/system/dyndb/driver/zone.c b/bin/tests/system/dyndb/driver/zone.c index 595b01da6a..caa615b4df 100644 --- a/bin/tests/system/dyndb/driver/zone.c +++ b/bin/tests/system/dyndb/driver/zone.c @@ -66,12 +66,8 @@ create_zone(sample_instance_t *const inst, dns_name_t *const name, zone_argv[0] = inst->db_name; - result = dns_zone_create(&raw, inst->mctx, 0); /* FIXME */ - if (result != ISC_R_SUCCESS) { - log_write(ISC_LOG_ERROR, "create_zone: dns_zone_create -> %s\n", - isc_result_totext(result)); - goto cleanup; - } + dns_zone_create(&raw, inst->mctx, 0); /* FIXME: all zones are assigned + to loop 0 */ result = dns_zone_setorigin(raw, name); if (result != ISC_R_SUCCESS) { log_write(ISC_LOG_ERROR, diff --git a/fuzz/dns_message_checksig.c b/fuzz/dns_message_checksig.c index 15a61995e1..a6544b80dc 100644 --- a/fuzz/dns_message_checksig.c +++ b/fuzz/dns_message_checksig.c @@ -274,12 +274,7 @@ LLVMFuzzerInitialize(int *argc ISC_ATTR_UNUSED, char ***argv ISC_ATTR_UNUSED) { return (1); } - result = dns_zone_create(&zone, mctx, 0); - if (result != ISC_R_SUCCESS) { - fprintf(stderr, "dns_zone_create failed: %s\n", - isc_result_totext(result)); - return (1); - } + dns_zone_create(&zone, mctx, 0); result = dns_zone_setorigin(zone, name); if (result != ISC_R_SUCCESS) { diff --git a/lib/dns/dlz.c b/lib/dns/dlz.c index de22dd3a83..475d6849cd 100644 --- a/lib/dns/dlz.c +++ b/lib/dns/dlz.c @@ -450,10 +450,7 @@ dns_dlz_writeablezone(dns_view_t *view, dns_dlzdb_t *dlzdb, INSIST(dupzone == NULL); /* Create it */ - result = dns_zone_create(&zone, view->mctx, 0); - if (result != ISC_R_SUCCESS) { - goto cleanup; - } + dns_zone_create(&zone, view->mctx, 0); result = dns_zone_setorigin(zone, origin); if (result != ISC_R_SUCCESS) { goto cleanup; diff --git a/lib/dns/include/dns/zone.h b/lib/dns/include/dns/zone.h index 467dc4007a..b7084676db 100644 --- a/lib/dns/include/dns/zone.h +++ b/lib/dns/include/dns/zone.h @@ -149,7 +149,7 @@ ISC_LANG_BEGINDECLS *** Functions ***/ -isc_result_t +void dns_zone_create(dns_zone_t **zonep, isc_mem_t *mctx, unsigned int tid); /*%< * Creates a new empty zone and attach '*zonep' to it. @@ -160,11 +160,6 @@ dns_zone_create(dns_zone_t **zonep, isc_mem_t *mctx, unsigned int tid); * * Ensures: *\li '*zonep' refers to a valid zone. - * - * Returns: - *\li #ISC_R_SUCCESS - *\li #ISC_R_NOMEMORY - *\li #ISC_R_UNEXPECTED */ void diff --git a/lib/dns/zone.c b/lib/dns/zone.c index 8dd5d66118..8e2416a171 100644 --- a/lib/dns/zone.c +++ b/lib/dns/zone.c @@ -1080,7 +1080,7 @@ inc_stats(dns_zone_t *zone, isc_statscounter_t counter) { *** Public functions. ***/ -isc_result_t +void dns_zone_create(dns_zone_t **zonep, isc_mem_t *mctx, unsigned int tid) { isc_time_t now; dns_zone_t *zone = NULL; @@ -1165,7 +1165,6 @@ dns_zone_create(dns_zone_t **zonep, isc_mem_t *mctx, unsigned int tid) { dns_zone_setdbtype(zone, dbargc_default, dbargv_default); *zonep = zone; - return (ISC_R_SUCCESS); } static void @@ -18242,7 +18241,6 @@ dns_zonemgr_create(isc_mem_t *mctx, isc_loopmgr_t *loopmgr, isc_nm_t *netmgr, isc_result_t dns_zonemgr_createzone(dns_zonemgr_t *zmgr, dns_zone_t **zonep) { - isc_result_t result; isc_mem_t *mctx = NULL; dns_zone_t *zone = NULL; unsigned int tid; @@ -18261,13 +18259,11 @@ dns_zonemgr_createzone(dns_zonemgr_t *zmgr, dns_zone_t **zonep) { return (ISC_R_FAILURE); } - result = dns_zone_create(&zone, mctx, tid); + dns_zone_create(&zone, mctx, tid); - if (result == ISC_R_SUCCESS) { - *zonep = zone; - } + *zonep = zone; - return (result); + return (ISC_R_SUCCESS); } isc_result_t diff --git a/tests/libtest/dns.c b/tests/libtest/dns.c index d398c5c954..4c8880fea7 100644 --- a/tests/libtest/dns.c +++ b/tests/libtest/dns.c @@ -104,10 +104,7 @@ dns_test_makezone(const char *name, dns_zone_t **zonep, dns_view_t *view, /* * Create the zone structure. */ - result = dns_zone_create(&zone, mctx, 0); - if (result != ISC_R_SUCCESS) { - return (result); - } + dns_zone_create(&zone, mctx, 0); /* * Set zone type and origin.