]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: cfgparse-global: parse only KWF_DISCOVERY keywords in MODE_DISCOVERY
authorValentine Krasnobaeva <vkrasnobaeva@haproxy.com>
Tue, 1 Oct 2024 14:07:49 +0000 (16:07 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 16 Oct 2024 20:02:39 +0000 (22:02 +0200)
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.

src/cfgparse-global.c

index 87adf1b8928bfdfe4cf900d6a612df1de81b7626..a17bf001a58e32f815654b720f4d747e1a0a5114 100644 (file)
@@ -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);