From: Valentine Krasnobaeva Date: Tue, 1 Oct 2024 14:07:49 +0000 (+0200) Subject: MEDIUM: cfgparse-global: parse only KWF_DISCOVERY keywords in MODE_DISCOVERY X-Git-Tag: v3.1-dev10~40 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=699be6a55df2d56e30686f717a1ea1795d29cb2d;p=thirdparty%2Fhaproxy.git MEDIUM: cfgparse-global: parse only KWF_DISCOVERY keywords in MODE_DISCOVERY This commit is a part of the series to add a support of discovery mode in the configuration parser and in initialization sequence. Global section parser parses the majority of keywords in its function, so those keywords don't have any dedicated parsers yet. Only after this parsing block cfg_parse_global() starts to call dedicated parsers for any other discovered keywords, which were not found in the block. As all keywords, which should be parsed in MODE_DISCOVERY have its own parser funtions, we can skip this block with goto discovery_kw and start directly from the part, where we call parsers from the keywords list. KWF_DISCOVERY flag helps to call in MODE_DISCOVERY only the parsers, which we are needed at this mode. All unknown keywords and garbage will be ignored at this stage. --- diff --git a/src/cfgparse-global.c b/src/cfgparse-global.c index 87adf1b892..a17bf001a5 100644 --- a/src/cfgparse-global.c +++ b/src/cfgparse-global.c @@ -67,6 +67,10 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm) alertif_too_many_args(0, file, linenum, args, &err_code); goto out; } + + if (global.mode & MODE_DISCOVERY) + goto discovery_kw; + else if (strcmp(args[0], "limited-quic") == 0) { if (alertif_too_many_args(0, file, linenum, args, &err_code)) goto out; @@ -872,12 +876,17 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm) const char *best; int index; int rc; - +discovery_kw: list_for_each_entry(kwl, &cfg_keywords.list, list) { for (index = 0; kwl->kw[index].kw != NULL; index++) { if (kwl->kw[index].section != CFG_GLOBAL) continue; if (strcmp(kwl->kw[index].kw, args[0]) == 0) { + + /* in MODE_DISCOVERY we read only the keywords, which contains the appropiate flag */ + if ((global.mode & MODE_DISCOVERY) && ((kwl->kw[index].flags & KWF_DISCOVERY) == 0 )) + goto out; + if (check_kw_experimental(&kwl->kw[index], file, linenum, &errmsg)) { ha_alert("%s\n", errmsg); err_code |= ERR_ALERT | ERR_FATAL; @@ -898,6 +907,9 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm) } } + if (global.mode & MODE_DISCOVERY) + goto out; + best = cfg_find_best_match(args[0], &cfg_keywords.list, CFG_GLOBAL, common_kw_list); if (best) ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section; did you mean '%s' maybe ?\n", file, linenum, args[0], cursection, best);