From: Colin Vidal Date: Thu, 30 Oct 2025 22:18:54 +0000 (+0100) Subject: don't retain the default configuration X-Git-Tag: v9.21.15~16^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=51bc6e7dd854b62487e8d285af98ba39271dbfb3;p=thirdparty%2Fbind9.git don't retain the default configuration The built-in configuration is actually used in two cases: first, when the server is loaded (or reloaded), and second when 'rndc showconf -builtin' is called. Considering the parsing of the builtin configuration is quick and does not occur during exclusive mode, but the configuration tree takes considerable memory space, the built-in configuration is no longer kept in memory once it has been used; instead it is re-parsed on demand. --- diff --git a/bin/named/include/named/globals.h b/bin/named/include/named/globals.h index e5ed76d6e62..3df3ec038ac 100644 --- a/bin/named/include/named/globals.h +++ b/bin/named/include/named/globals.h @@ -85,8 +85,6 @@ EXTERN unsigned int named_g_debuglevel INIT(0); /* * Current configuration information. */ -EXTERN cfg_obj_t *named_g_defaultconfig INIT(NULL); -EXTERN const cfg_obj_t *named_g_defaultoptions INIT(NULL); EXTERN const char *named_g_conffile INIT(NAMED_SYSCONFDIR "/named.conf"); EXTERN const char *named_g_bindkeysfile INIT(NULL); EXTERN const char *named_g_keyfile INIT(NAMED_SYSCONFDIR "/rndc.key"); diff --git a/bin/named/server.c b/bin/named/server.c index 70ee898c213..52b79a21546 100644 --- a/bin/named/server.c +++ b/bin/named/server.c @@ -9092,7 +9092,8 @@ emit_text(void *arg, const char *buf, int len) { static isc_result_t load_configuration(named_server_t *server, bool first_time) { isc_result_t result; - cfg_obj_t *config = NULL, *bindkeys = NULL, *effective = NULL; + cfg_obj_t *config = NULL, *effective = NULL; + cfg_obj_t *bindkeys = NULL, *builtin = NULL; ns_dzarg_t dzarg = { .magic = DZARG_MAGIC, .result = ISC_R_SUCCESS, @@ -9102,6 +9103,7 @@ load_configuration(named_server_t *server, bool first_time) { isc_log_write(NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_SERVER, ISC_LOG_DEBUG(1), "load_configuration"); + CHECK(named_config_parsedefaults(&builtin)); CHECK(named_config_parsefile(&config)); if (named_g_bindkeysfile != NULL) { @@ -9135,7 +9137,7 @@ load_configuration(named_server_t *server, bool first_time) { } /* Merge and apply */ - effective = cfg_effective_config(config, named_g_defaultconfig); + effective = cfg_effective_config(config, builtin); /* * Save the user configuration for later reference. @@ -9157,6 +9159,9 @@ cleanup: if (config != NULL) { cfg_obj_detach(&config); } + if (builtin != NULL) { + cfg_obj_detach(&builtin); + } return result; } @@ -9331,13 +9336,6 @@ run_server(void *arg) { isc_timer_create(isc_loop_main(), pps_timer_tick, server, &server->pps_timer); - CHECKFATAL(named_config_parsedefaults(&named_g_defaultconfig), - "unable to parse defaults config"); - - CHECKFATAL(cfg_map_get(named_g_defaultconfig, "options", - &named_g_defaultoptions), - "missing 'options' in default config"); - CHECKFATAL(load_configuration(server, true), "loading configuration"); CHECKFATAL(load_zones(server, false), "loading zones"); @@ -9389,8 +9387,6 @@ shutdown_server(void *arg) { cfg_aclconfctx_detach(&server->aclctx); } - cfg_obj_detach(&named_g_defaultconfig); - (void)named_server_saventa(server); ISC_LIST_FOREACH(server->kasplist, kasp, link) { @@ -13891,7 +13887,7 @@ named_server_showconf(named_server_t *server, isc_lex_t *lex, isc_buffer_t **text) { isc_result_t result, tresult; const char *arg = NULL; - const cfg_obj_t *config = NULL; + cfg_obj_t *config = NULL; ns_dzarg_t dzarg = { .magic = DZARG_MAGIC, .result = ISC_R_SUCCESS, @@ -13913,9 +13909,9 @@ named_server_showconf(named_server_t *server, isc_lex_t *lex, result = ISC_R_SUCCESS; goto cleanup; } else if (strcasecmp(arg, "-builtin") == 0) { - config = named_g_defaultconfig; + named_config_parsedefaults(&config); } else if (strcasecmp(arg, "-effective") == 0) { - config = server->effectiveconfig; + cfg_obj_attach(server->effectiveconfig, &config); } else { CHECK(DNS_R_SYNTAX); } @@ -13934,6 +13930,10 @@ cleanup: (void)putnull(text); } + if (config != NULL) { + cfg_obj_detach(&config); + } + return result; }