cfg_parse_ API doesn't need memory context

Because the parser now uses global memory context, the cfg_parse_* API
doesn't take a memory context anymore.
This commit is contained in:
Colin Vidal 2025-11-04 10:46:05 +01:00
parent bc82db7b82
commit f7b64e2e87
20 changed files with 81 additions and 92 deletions

View file

@ -531,11 +531,11 @@ parse_builtin(cfg_obj_t **defaultconfig) {
sizeof(common_named_defaultconf) - 1);
isc_buffer_add(&b, sizeof(common_named_defaultconf) - 1);
return cfg_parse_buffer(
isc_g_mctx, &b, __FILE__, 0, &cfg_type_namedconf,
CFG_PCTX_NODEPRECATED | CFG_PCTX_NOOBSOLETE |
CFG_PCTX_NOEXPERIMENTAL | CFG_PCTX_BUILTIN,
defaultconfig);
return cfg_parse_buffer(&b, __FILE__, 0, &cfg_type_namedconf,
CFG_PCTX_NODEPRECATED | CFG_PCTX_NOOBSOLETE |
CFG_PCTX_NOEXPERIMENTAL |
CFG_PCTX_BUILTIN,
defaultconfig);
}
static void
@ -714,8 +714,8 @@ main(int argc, char **argv) {
}
CHECK(setup_logging(stdout));
CHECK(cfg_parse_file(isc_g_mctx, conffile, &cfg_type_namedconf,
parserflags, &config));
CHECK(cfg_parse_file(conffile, &cfg_type_namedconf, parserflags,
&config));
CHECK(isccfg_check_namedconf(config, checkflags, isc_g_mctx));
if (load_zones || list_zones) {
CHECK(load_zones_fromconfig(config, list_zones));

View file

@ -829,8 +829,8 @@ setup_dnsseckeys(dns_client_t *client, dns_view_t *toview) {
fatal("Unable to read key file '%s'", anchorfile);
}
result = cfg_parse_file(isc_g_mctx, anchorfile,
&cfg_type_bindkeys, 0, &bindkeys);
result = cfg_parse_file(anchorfile, &cfg_type_bindkeys, 0,
&bindkeys);
if (result != ISC_R_SUCCESS) {
fatal("Unable to load keys from '%s'", anchorfile);
}
@ -842,8 +842,8 @@ setup_dnsseckeys(dns_client_t *client, dns_view_t *toview) {
isc_buffer_init(&b, anchortext, sizeof(anchortext) - 1);
isc_buffer_add(&b, sizeof(anchortext) - 1);
result = cfg_parse_buffer(isc_g_mctx, &b, NULL, 0, &delv_type,
0, &bindkeys);
result = cfg_parse_buffer(&b, NULL, 0, &delv_type, 0,
&bindkeys);
if (result != ISC_R_SUCCESS) {
fatal("Unable to parse built-in keys");
}

View file

@ -1062,8 +1062,7 @@ read_confkey(void) {
return ISC_R_FILENOTFOUND;
}
CHECK(cfg_parse_file(isc_g_mctx, keyfile, &cfg_type_sessionkey, 0,
&file));
CHECK(cfg_parse_file(keyfile, &cfg_type_sessionkey, 0, &file));
CHECK(cfg_map_get(file, "key", &keyobj));

View file

@ -1150,9 +1150,8 @@ main(int argc, char **argv) {
cfg_obj_t *config = NULL;
dns_kasp_t *kasp = NULL;
if (cfg_parse_file(isc_g_mctx, ctx.configfile,
&cfg_type_namedconf, 0,
&config) != ISC_R_SUCCESS)
if (cfg_parse_file(ctx.configfile, &cfg_type_namedconf,
0, &config) != ISC_R_SUCCESS)
{
fatal("unable to load dnssec-policy '%s' from "
"'%s'",

View file

@ -157,8 +157,8 @@ static void
getkasp(ksr_ctx_t *ksr, dns_kasp_t **kasp) {
cfg_obj_t *config = NULL;
if (cfg_parse_file(isc_g_mctx, ksr->configfile, &cfg_type_namedconf, 0,
&config) != ISC_R_SUCCESS)
if (cfg_parse_file(ksr->configfile, &cfg_type_namedconf, 0, &config) !=
ISC_R_SUCCESS)
{
fatal("unable to load dnssec-policy '%s' from '%s'",
ksr->policy, ksr->configfile);

View file

@ -55,11 +55,11 @@ named_config_parsedefaults(cfg_obj_t **conf) {
isc_buffer_constinit(&b, common_named_defaultconf,
sizeof(common_named_defaultconf) - 1);
isc_buffer_add(&b, sizeof(common_named_defaultconf) - 1);
return cfg_parse_buffer(
isc_g_mctx, &b, __FILE__, 0, &cfg_type_namedconf,
CFG_PCTX_NODEPRECATED | CFG_PCTX_NOOBSOLETE |
CFG_PCTX_NOEXPERIMENTAL | CFG_PCTX_BUILTIN,
conf);
return cfg_parse_buffer(&b, __FILE__, 0, &cfg_type_namedconf,
CFG_PCTX_NODEPRECATED | CFG_PCTX_NOOBSOLETE |
CFG_PCTX_NOEXPERIMENTAL |
CFG_PCTX_BUILTIN,
conf);
}
isc_result_t
@ -72,8 +72,7 @@ named_config_parsefile(cfg_obj_t **conf) {
ISC_LOG_INFO, "parsing user configuration from '%s'",
named_g_conffile);
CHECK(cfg_parse_file(isc_g_mctx, named_g_conffile, &cfg_type_namedconf,
0, conf));
CHECK(cfg_parse_file(named_g_conffile, &cfg_type_namedconf, 0, conf));
/*
* Check the validity of the configuration.

View file

@ -787,8 +787,7 @@ get_rndckey(isc_mem_t *mctx, controlkeylist_t *keyids) {
return ISC_R_FILENOTFOUND;
}
CHECK(cfg_parse_file(mctx, named_g_keyfile, &cfg_type_rndckey, 0,
&config));
CHECK(cfg_parse_file(named_g_keyfile, &cfg_type_rndckey, 0, &config));
CHECK(cfg_map_get(config, "key", &key));
keyid = isc_mem_get(mctx, sizeof(*keyid));

View file

@ -2350,7 +2350,7 @@ catz_addmodzone_cb(void *arg) {
confbuf = NULL;
result = dns_catz_generate_zonecfg(cz->origin, cz->entry, &confbuf);
if (result == ISC_R_SUCCESS) {
result = cfg_parse_buffer(isc_g_mctx, confbuf, "catz", 0,
result = cfg_parse_buffer(confbuf, "catz", 0,
&cfg_type_addzoneconf, 0, &zoneconf);
isc_buffer_free(&confbuf);
}
@ -2618,7 +2618,7 @@ catz_reconfigure(dns_catz_entry_t *entry, void *arg1, void *arg2) {
result = dns_catz_generate_zonecfg(data->catz, entry, &confbuf);
if (result == ISC_R_SUCCESS) {
result = cfg_parse_buffer(isc_g_mctx, confbuf, "catz", 0,
result = cfg_parse_buffer(confbuf, "catz", 0,
&cfg_type_addzoneconf, 0, &zoneconf);
isc_buffer_free(&confbuf);
}
@ -7294,8 +7294,8 @@ data_to_cfg(dns_view_t *view, MDB_val *key, MDB_val *data, isc_buffer_t *text,
snprintf(bufname, sizeof(bufname), "%.*s", (int)zone_name_len,
zone_name);
result = cfg_parse_buffer(isc_g_mctx, text, bufname, 0,
&cfg_type_addzoneconf, 0, &zoneconf);
result = cfg_parse_buffer(text, bufname, 0, &cfg_type_addzoneconf, 0,
&zoneconf);
if (result != ISC_R_SUCCESS) {
isc_log_write(NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_SERVER,
ISC_LOG_ERROR,
@ -8920,9 +8920,9 @@ load_configuration(named_server_t *server, bool first_time) {
"keys instead",
named_g_bindkeysfile);
} else {
result = cfg_parse_file(
isc_g_mctx, named_g_bindkeysfile,
&cfg_type_bindkeys, 0, &bindkeys);
result = cfg_parse_file(named_g_bindkeysfile,
&cfg_type_bindkeys, 0,
&bindkeys);
if (result != ISC_R_SUCCESS) {
isc_log_write(NAMED_LOGCATEGORY_GENERAL,
NAMED_LOGMODULE_SERVER,
@ -12129,8 +12129,7 @@ load_nzf(dns_view_t *view) {
/*
* Parse the configuration in the NZF file.
*/
result = cfg_parse_file(view->mctx, view->newzone.file,
&cfg_type_addzoneconf, 0,
result = cfg_parse_file(view->newzone.file, &cfg_type_addzoneconf, 0,
&view->newzone.nzconfig);
if (result != ISC_R_SUCCESS) {
isc_log_write(NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_SERVER,
@ -12496,8 +12495,8 @@ load_nzf(dns_view_t *view) {
* config type, giving us a guarantee that valid configuration
* will be written to DB.
*/
result = cfg_parse_file(isc_g_mctx, view->newzone.file,
&cfg_type_addzoneconf, 0, &nzf_config);
result = cfg_parse_file(view->newzone.file, &cfg_type_addzoneconf, 0,
&nzf_config);
if (result != ISC_R_SUCCESS) {
isc_log_write(NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_SERVER,
ISC_LOG_ERROR, "Error parsing NZF file '%s': %s",
@ -12647,8 +12646,8 @@ newzone_parse(named_server_t *server, char *command, dns_view_t **viewp,
*/
isc_buffer_forward(&argbuf, 3);
CHECK(cfg_parse_buffer(server->mctx, &argbuf, bn, 0,
&cfg_type_addzoneconf, 0, &zoneconf));
CHECK(cfg_parse_buffer(&argbuf, bn, 0, &cfg_type_addzoneconf, 0,
&zoneconf));
CHECK(cfg_map_get(zoneconf, "zone", &zlist));
if (!cfg_obj_islist(zlist)) {

View file

@ -569,8 +569,7 @@ read_sessionkey(isc_mem_t *mctx) {
return ISC_R_FILENOTFOUND;
}
CHECK(cfg_parse_file(mctx, keyfile, &cfg_type_sessionkey, 0,
&sessionkey));
CHECK(cfg_parse_file(keyfile, &cfg_type_sessionkey, 0, &sessionkey));
CHECK(cfg_map_get(sessionkey, "key", &key));

View file

@ -272,8 +272,8 @@ parse_parameters(filter_instance_t *inst, const char *parameters,
isc_buffer_constinit(&b, parameters, strlen(parameters));
isc_buffer_add(&b, strlen(parameters));
CHECK(cfg_parse_buffer(mctx, &b, cfg_file, cfg_line,
&cfg_type_parameters, 0, &param_obj));
CHECK(cfg_parse_buffer(&b, cfg_file, cfg_line, &cfg_type_parameters, 0,
&param_obj));
CHECK(parse_filter_a_on(param_obj, "filter-a-on-v6", &inst->v6_a));
CHECK(parse_filter_a_on(param_obj, "filter-a-on-v4", &inst->v4_a));
@ -359,8 +359,8 @@ plugin_check(const char *parameters, const void *cfg, const char *cfg_file,
isc_buffer_constinit(&b, parameters, strlen(parameters));
isc_buffer_add(&b, strlen(parameters));
CHECK(cfg_parse_buffer(mctx, &b, cfg_file, cfg_line,
&cfg_type_parameters, 0, &param_obj));
CHECK(cfg_parse_buffer(&b, cfg_file, cfg_line, &cfg_type_parameters, 0,
&param_obj));
CHECK(check_syntax(param_obj, cfg, mctx, aclctx));

View file

@ -273,8 +273,8 @@ parse_parameters(filter_instance_t *inst, const char *parameters,
isc_buffer_constinit(&b, parameters, strlen(parameters));
isc_buffer_add(&b, strlen(parameters));
CHECK(cfg_parse_buffer(mctx, &b, cfg_file, cfg_line,
&cfg_type_parameters, 0, &param_obj));
CHECK(cfg_parse_buffer(&b, cfg_file, cfg_line, &cfg_type_parameters, 0,
&param_obj));
CHECK(parse_filter_aaaa_on(param_obj, "filter-aaaa-on-v4",
&inst->v4_aaaa));
@ -363,8 +363,8 @@ plugin_check(const char *parameters, const void *cfg, const char *cfg_file,
isc_buffer_constinit(&b, parameters, strlen(parameters));
isc_buffer_add(&b, strlen(parameters));
CHECK(cfg_parse_buffer(mctx, &b, cfg_file, cfg_line,
&cfg_type_parameters, 0, &param_obj));
CHECK(cfg_parse_buffer(&b, cfg_file, cfg_line, &cfg_type_parameters, 0,
&param_obj));
CHECK(check_syntax(param_obj, cfg, mctx, aclctx));

View file

@ -554,15 +554,14 @@ synthrecord_parseconfig(synthrecord_t *inst, const char *parameters,
unsigned long cfgline, cfg_aclconfctx_t *aclctx,
const dns_name_t *zname) {
isc_result_t result;
isc_mem_t *mctx = inst->mctx;
cfg_obj_t *synthrecordcfg = NULL;
isc_buffer_t b;
isc_buffer_constinit(&b, parameters, strlen(parameters));
isc_buffer_add(&b, strlen(parameters));
CHECK(cfg_parse_buffer(mctx, &b, cfgfile, cfgline,
&synthrecord_cfgparams, 0, &synthrecordcfg));
CHECK(cfg_parse_buffer(&b, cfgfile, cfgline, &synthrecord_cfgparams, 0,
&synthrecordcfg));
synthrecord_setconfigmode(inst, zname);
CHECK(synthrecord_initorigin(inst, synthrecordcfg, zname));

View file

@ -537,7 +537,7 @@ rndc_start(void *arg) {
}
static void
parse_config(isc_mem_t *mctx, const char *keyname, cfg_obj_t **configp) {
parse_config(const char *keyname, cfg_obj_t **configp) {
isc_result_t result;
const char *conffile = admin_conffile;
const cfg_obj_t *addresses = NULL;
@ -581,7 +581,7 @@ parse_config(isc_mem_t *mctx, const char *keyname, cfg_obj_t **configp) {
/*
* The parser will output its own errors, so DO() is not used.
*/
result = cfg_parse_file(mctx, conffile, conftype, 0, &config);
result = cfg_parse_file(conffile, conftype, 0, &config);
if (result != ISC_R_SUCCESS) {
fatal("could not load rndc configuration");
}
@ -961,7 +961,7 @@ main(int argc, char **argv) {
ISC_LOG_PRINTTAG | ISC_LOG_PRINTLEVEL, ISC_LOGCATEGORY_DEFAULT,
ISC_LOGMODULE_DEFAULT);
parse_config(isc_g_mctx, keyname, &config);
parse_config(keyname, &config);
isc_buffer_allocate(isc_g_mctx, &databuf, 2048);

View file

@ -126,8 +126,8 @@ plugin_register(const char *parameters, const void *cfg, const char *cfgfile,
isc_buffer_constinit(&b, parameters, strlen(parameters));
isc_buffer_add(&b, strlen(parameters));
CHECK(cfg_parse_buffer(mctx, &b, cfgfile, cfgline,
&syncplugin__cfgparams, 0, &syncplugincfg));
CHECK(cfg_parse_buffer(&b, cfgfile, cfgline, &syncplugin__cfgparams, 0,
&syncplugincfg));
CHECK(syncplugin__parse_rcode(syncplugincfg, &inst->rcode));

View file

@ -133,7 +133,7 @@ main(int argc, char **argv) {
if (type == NULL || filename == NULL) {
usage();
}
result = cfg_parse_file(mctx, filename, type, 0, &cfg);
result = cfg_parse_file(filename, type, 0, &cfg);
fprintf(stderr, "read config: %s\n", isc_result_totext(result));
@ -147,6 +147,10 @@ main(int argc, char **argv) {
}
if (memstats) {
/*
* TODO: this is memstat of config that we are interested in
* here, right?
*/
isc_mem_stats(mctx, stderr);
}
isc_mem_detach(&mctx);

View file

@ -91,13 +91,12 @@ typedef isc_result_t (*cfg_parsecallback_t)(const char *clausename,
***/
isc_result_t
cfg_parse_file(isc_mem_t *mctx, const char *file, const cfg_type_t *type,
unsigned int flags, cfg_obj_t **ret);
cfg_parse_file(const char *file, const cfg_type_t *type, unsigned int flags,
cfg_obj_t **ret);
isc_result_t
cfg_parse_buffer(isc_mem_t *mctx, isc_buffer_t *buffer, const char *file,
unsigned int line, const cfg_type_t *type, unsigned int flags,
cfg_obj_t **ret);
cfg_parse_buffer(isc_buffer_t *buffer, const char *file, unsigned int line,
const cfg_type_t *type, unsigned int flags, cfg_obj_t **ret);
/*%<
* Read a configuration containing data of type 'type'
* and make '*ret' point to its parse tree.

View file

@ -680,17 +680,16 @@ static cfg_type_t cfg_type_filelist = { "filelist", NULL,
&cfg_rep_list, &cfg_type_qstring };
static void
parser_create(isc_mem_t *mctx, cfg_parser_t **ret) {
parser_create(cfg_parser_t **ret) {
cfg_parser_t *pctx;
isc_lexspecials_t specials;
REQUIRE(mctx != NULL);
REQUIRE(ret != NULL && *ret == NULL);
pctx = isc_mem_get(mctx, sizeof(*pctx));
pctx = isc_mem_get(isc_g_mctx, sizeof(*pctx));
pctx->mctx = NULL;
isc_mem_attach(mctx, &pctx->mctx);
isc_mem_attach(isc_g_mctx, &pctx->mctx);
pctx->lexer = NULL;
pctx->seen_eof = false;
@ -712,14 +711,14 @@ parser_create(isc_mem_t *mctx, cfg_parser_t **ret) {
specials['"'] = 1;
specials['!'] = 1;
isc_lex_create(pctx->mctx, 1024, &pctx->lexer);
isc_lex_create(isc_g_mctx, 1024, &pctx->lexer);
isc_lex_setspecials(pctx->lexer, specials);
isc_lex_setcomments(pctx->lexer, ISC_LEXCOMMENT_C |
ISC_LEXCOMMENT_CPLUSPLUS |
ISC_LEXCOMMENT_SHELL);
create_list(pctx->mctx, cfg_parser_currentfile(pctx), pctx->line,
create_list(isc_g_mctx, cfg_parser_currentfile(pctx), pctx->line,
&cfg_type_filelist, &pctx->open_files);
create_list(pctx->mctx, cfg_parser_currentfile(pctx), pctx->line,
&cfg_type_filelist, &pctx->closed_files);
@ -811,19 +810,18 @@ cleanup:
CFG_PCTX_NOEXPERIMENTAL | CFG_PCTX_BUILTIN)) == 0)
isc_result_t
cfg_parse_file(isc_mem_t *mctx, const char *filename, const cfg_type_t *type,
unsigned int flags, cfg_obj_t **ret) {
cfg_parse_file(const char *filename, const cfg_type_t *type, unsigned int flags,
cfg_obj_t **ret) {
isc_result_t result;
cfg_listelt_t *elt;
cfg_parser_t *pctx = NULL;
REQUIRE(mctx != NULL);
REQUIRE(filename != NULL);
REQUIRE(type != NULL);
REQUIRE(ret != NULL && *ret == NULL);
REQUIRE_PCTX_FLAGS(flags);
parser_create(mctx, &pctx);
parser_create(&pctx);
pctx->flags = flags;
CHECK(parser_openfile(pctx, filename));
@ -843,19 +841,17 @@ cleanup:
}
isc_result_t
cfg_parse_buffer(isc_mem_t *mctx, isc_buffer_t *buffer, const char *file,
unsigned int line, const cfg_type_t *type, unsigned int flags,
cfg_obj_t **ret) {
cfg_parse_buffer(isc_buffer_t *buffer, const char *file, unsigned int line,
const cfg_type_t *type, unsigned int flags, cfg_obj_t **ret) {
isc_result_t result;
cfg_parser_t *pctx = NULL;
REQUIRE(mctx != NULL);
REQUIRE(type != NULL);
REQUIRE(buffer != NULL);
REQUIRE(ret != NULL && *ret == NULL);
REQUIRE_PCTX_FLAGS(flags);
parser_create(mctx, &pctx);
parser_create(&pctx);
CHECK(isc_lex_openbuffer(pctx->lexer, buffer));
pctx->buf_name = file;

View file

@ -143,7 +143,7 @@ ISC_RUN_TEST_IMPL(duration) {
isc_buffer_add(&buf1, strlen(conf) - 1);
/* Parse with default line numbering */
result = cfg_parse_buffer(isc_g_mctx, &buf1, "text1", 0,
result = cfg_parse_buffer(&buf1, "text1", 0,
&cfg_type_namedconf, 0, &c1);
if (must_fail) {
assert_int_equal(result, DNS_R_BADTTL);

View file

@ -115,8 +115,8 @@ test__query_source_print(const char *config, const char *expected) {
isc_buffer_constinit(&buffer, config, strlen(config));
isc_buffer_add(&buffer, strlen(config));
result = cfg_parse_buffer(isc_g_mctx, &buffer, "text1", 0,
&cfg_type_namedconf, 0, &output_conf);
result = cfg_parse_buffer(&buffer, "text1", 0, &cfg_type_namedconf, 0,
&output_conf);
assert_int_equal(result, ISC_R_SUCCESS);
assert_non_null(output_conf);

View file

@ -79,8 +79,8 @@ ISC_RUN_TEST_IMPL(addzoneconf) {
isc_buffer_constinit(&b, tests[i], strlen(tests[i]));
isc_buffer_add(&b, strlen(tests[i]));
result = cfg_parse_buffer(isc_g_mctx, &b, "text1", 0,
&cfg_type_namedconf, 0, &conf);
result = cfg_parse_buffer(&b, "text1", 0, &cfg_type_namedconf,
0, &conf);
assert_int_equal(result, ISC_R_SUCCESS);
/*
@ -130,22 +130,20 @@ ISC_RUN_TEST_IMPL(parse_buffer) {
/* Parse with default line numbering. */
isc_buffer_init(&buf, &text[0], sizeof(text) - 1);
isc_buffer_add(&buf, sizeof(text) - 1);
result = cfg_parse_buffer(isc_g_mctx, &buf, "text1", 0,
&cfg_type_namedconf, 0, &c);
result = cfg_parse_buffer(&buf, "text1", 0, &cfg_type_namedconf, 0, &c);
assert_int_equal(result, ISC_R_FAILURE);
assert_null(c);
/* Parse with changed line number. */
isc_buffer_first(&buf);
result = cfg_parse_buffer(isc_g_mctx, &buf, "text2", 100,
&cfg_type_namedconf, 0, &c);
result = cfg_parse_buffer(&buf, "text2", 100, &cfg_type_namedconf, 0,
&c);
assert_int_equal(result, ISC_R_FAILURE);
assert_null(c);
/* Parse with changed line number and no name. */
isc_buffer_first(&buf);
result = cfg_parse_buffer(isc_g_mctx, &buf, NULL, 100,
&cfg_type_namedconf, 0, &c);
result = cfg_parse_buffer(&buf, NULL, 100, &cfg_type_namedconf, 0, &c);
assert_int_equal(result, ISC_R_FAILURE);
assert_null(c);
@ -262,8 +260,7 @@ view \"_bind\" chaos {\n\
isc_buffer_init(&buf, conf, sizeof(conf));
isc_buffer_add(&buf, sizeof(conf) - 1);
result = cfg_parse_buffer(isc_g_mctx, &buf, "", 0, &cfg_type_namedconf,
0, &orig);
result = cfg_parse_buffer(&buf, "", 0, &cfg_type_namedconf, 0, &orig);
assert_int_equal(result, ISC_R_SUCCESS);
isc_buffer_init(&dumpb1, dumpbdata1, sizeof(dumpbdata1));