]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
don't retain the default configuration
authorColin Vidal <colin@isc.org>
Thu, 30 Oct 2025 22:18:54 +0000 (23:18 +0100)
committerColin Vidal <colin@isc.org>
Fri, 31 Oct 2025 07:02:17 +0000 (08:02 +0100)
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.

bin/named/include/named/globals.h
bin/named/server.c

index e5ed76d6e6282d95581ac10305c29980d33de154..3df3ec038acdc55dfc1c9ebf4087fd13ab5f711e 100644 (file)
@@ -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");
index 70ee898c2132b2b9edf4d4eb9252ac096e4007b3..52b79a2154677543a66f4a7a70c0b71b885679db 100644 (file)
@@ -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;
 }