]> git.kaiwu.me - haproxy.git/commitdiff
CLENAUP: cfgparse-listen: move the "server" keywords to their own parser
authorWilly Tarreau <w@1wt.eu>
Thu, 8 Oct 2026 15:49:55 +0000 (17:49 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 9 Oct 2026 08:30:59 +0000 (10:30 +0200)
"server", "default-server" and "server-template" only differ by the
flags they pass to parse_server(), so they were moved together to a new
proxy_parse_server() function registered in cfg_kws, making them
discoverable via "-dKcfg". parse_server() emits its own messages, so the
new parser only has to turn a fatal error into a negative return value.

src/cfgparse-listen.c

index 8c210d539378eb020480afb9ad602dac680656ca..0eec587f0b7ba8c1733a45a063740a4efffff7db 100644 (file)
@@ -40,8 +40,7 @@
  * registered anywhere. They are used as suggestions for mistyped words.
  */
 static const char *common_kw_list[] = {
-       "listen", "frontend", "backend", "defaults", "server",
-       "default-server", "server-template", "bind",
+       "listen", "frontend", "backend", "defaults", "bind",
        "option",
        NULL /* must be last */
 };
@@ -540,31 +539,7 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
        curproxy->conf.args.line = linenum;
 
        /* Now let's parse the proxy-specific keywords */
-       if ((strcmp(args[0], "server") == 0)) {
-               err_code |= parse_server(file, linenum, args,
-                                        curproxy, curr_defproxy,
-                                        SRV_PARSE_PARSE_ADDR);
-
-               if (err_code & ERR_FATAL)
-                       goto out;
-       }
-       else if (strcmp(args[0], "default-server") == 0) {
-               err_code |= parse_server(file, linenum, args,
-                                        curproxy, curr_defproxy,
-                                        SRV_PARSE_DEFAULT_SERVER);
-
-               if (err_code & ERR_FATAL)
-                       goto out;
-       }
-       else if (strcmp(args[0], "server-template") == 0) {
-               err_code |= parse_server(file, linenum, args,
-                                        curproxy, curr_defproxy,
-                                        SRV_PARSE_TEMPLATE|SRV_PARSE_PARSE_ADDR);
-
-               if (err_code & ERR_FATAL)
-                       goto out;
-       }
-       else if (strcmp(args[0], "bind") == 0) {  /* new listen addresses */
+       if (strcmp(args[0], "bind") == 0) {  /* new listen addresses */
                struct listener *l;
                int cur_arg;
 
@@ -3130,6 +3105,31 @@ static int proxy_parse_stats(char **args, int section_type, struct proxy *curpx,
        return -1;
 }
 
+/* Parses the "server", "default-server" and "server-template" keywords */
+static int proxy_parse_server(char **args, int section_type, struct proxy *curpx,
+                              const struct proxy *defpx, const char *file, int line,
+                              char **err)
+{
+       int flags;
+       int ret;
+
+       if (strcmp(args[0], "server") == 0)
+               flags = SRV_PARSE_PARSE_ADDR;
+       else if (strcmp(args[0], "default-server") == 0)
+               flags = SRV_PARSE_DEFAULT_SERVER;
+       else if (strcmp(args[0], "server-template") == 0)
+               flags = SRV_PARSE_TEMPLATE | SRV_PARSE_PARSE_ADDR;
+       else {
+               BUG_ON(1, "unhandled keyword in proxy_parse_server().");
+               return -1;
+       }
+
+       /* the messages are emitted by parse_server() itself */
+       ret = parse_server(file, line, args, curpx, (struct proxy *)defpx, flags);
+
+       return (ret & ERR_FATAL) ? -1 : 0;
+}
+
 static struct cfg_kw_list cfg_kws = {ILH, {
        { CFG_LISTEN, "acl", proxy_parse_acl },
        { CFG_LISTEN, "appsession", proxy_parse_removed_kw },
@@ -3140,6 +3140,7 @@ static struct cfg_kw_list cfg_kws = {ILH, {
        { CFG_LISTEN, "capture", proxy_parse_capture },
        { CFG_LISTEN, "cliexp", proxy_parse_removed_kw },
        { CFG_LISTEN, "cookie", proxy_parse_cookie },
+       { CFG_LISTEN, "default-server", proxy_parse_server },
        { CFG_LISTEN, "default_backend", proxy_parse_use_backend },
        { CFG_LISTEN, "description", proxy_parse_id_desc },
        { CFG_LISTEN, "disabled", proxy_parse_enabled },
@@ -3196,7 +3197,9 @@ static struct cfg_kw_list cfg_kws = {ILH, {
        { CFG_LISTEN, "rspideny", proxy_parse_removed_kw },
        { CFG_LISTEN, "rspirep", proxy_parse_removed_kw },
        { CFG_LISTEN, "rsprep", proxy_parse_removed_kw },
+       { CFG_LISTEN, "server", proxy_parse_server },
        { CFG_LISTEN, "server-state-file-name", proxy_parse_be_opts },
+       { CFG_LISTEN, "server-template", proxy_parse_server },
        { CFG_LISTEN, "source", proxy_parse_source },
        { CFG_LISTEN, "srvexp", proxy_parse_removed_kw },
        { CFG_LISTEN, "stats", proxy_parse_stats },