]> git.kaiwu.me - haproxy.git/commitdiff
MINOR: cfgparse-listen: introduce proxy_parse_removed_kw() and use it
authorWilly Tarreau <w@1wt.eu>
Wed, 7 Oct 2026 15:46:51 +0000 (17:46 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 9 Oct 2026 07:31:07 +0000 (09:31 +0200)
A significant number of cfgparse_listen()'s keywords are handled
specifically because they're obsolete and continue to deliver a detailed
indication about what to use instead. The most complicated ones are
"dispatch" and "monitor-net" which even suggest the exact line to use
in order to replace them.

Let's introduce proxy_parse_removed_kw() to handle such keywords and
their excentricities. The function is just a regular keyword parser,
so that the keywords it handles are now in the standard array and point
to it.

For now we only implement "monitor-net" and "dispatch". The output
messages remain exactly the same.

src/cfgparse-listen.c

index 00aeda783f8db34f6174b3516bfd3260caf6a4e6..9d4c9b365eabe9f8deccaa03137a6a5035b110d2 100644 (file)
@@ -41,7 +41,7 @@
  */
 static const char *common_kw_list[] = {
        "listen", "frontend", "backend", "defaults", "server",
-       "default-server", "server-template", "bind", "monitor-net",
+       "default-server", "server-template", "bind",
        "monitor-uri", "mode", "id", "description", "disabled", "enabled",
        "acl", "dynamic-cookie-key", "cookie", "email-alert",
        "persist", "appsession", "load-server-state-from-file",
@@ -51,7 +51,7 @@ static const char *common_kw_list[] = {
        "use-server", "force-persist", "ignore-persist",
        "stick-table", "stick", "stats", "option", "default_backend",
        "http-reuse", "monitor", "transparent", "maxconn", "backlog",
-       "fullconn", "dispatch", "balance", "hash-type",
+       "fullconn", "balance", "hash-type",
        "hash-balance-factor", "unique-id-format", "unique-id-header",
        "log-format", "log-format-sd", "log-tag", "log", "source", "usesrc",
        "error-log-format",
@@ -630,11 +630,6 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
                err_code |= bind_parse_args_list(bind_conf, args, cur_arg, cursection, file, linenum);
                goto out;
        }
-       else if (strcmp(args[0], "monitor-net") == 0) {  /* set the range of IPs to ignore */
-               ha_alert("parsing [%s:%d] : 'monitor-net' doesn't exist anymore. Please use 'http-request return status 200 if { src %s }' instead.\n", file, linenum, args[1]);
-               err_code |= ERR_ALERT | ERR_FATAL;
-               goto out;
-       }
        else if (strcmp(args[0], "monitor-uri") == 0) {  /* set the URI to intercept */
                if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
                        err_code |= ERR_WARN;
@@ -2681,15 +2676,6 @@ stats_error_parsing:
                err_code |= ERR_ALERT | ERR_FATAL;
                goto out;
        }
-       else if (strcmp(args[0], "dispatch") == 0) {  /* dispatch address */
-               ha_alert("parsing [%s:%d]: support for '%s' was removed in version 3.5. "
-                        "The modern way to do the same is to create a server with the same address, and "
-                        "possibly to assign any extra server a weight of zero if any:\n"
-                        "    server dispatch %s\n",
-                        file, linenum, args[0], args[1]);
-               err_code |= ERR_ALERT | ERR_FATAL;
-               goto out;
-       }
        else if (strcmp(args[0], "balance") == 0) {  /* set balancing with optional algorithm */
                if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
                        err_code |= ERR_WARN;
@@ -3271,3 +3257,42 @@ stats_error_parsing:
        err_code |= ERR_ALERT | ERR_ABORT;
        goto out;
 }
+
+/* Parses the proxy keywords which are not supported anymore, and only reports
+ * what to use instead.
+ */
+static int proxy_parse_removed_kw(char **args, int section_type, struct proxy *curpx,
+                                  const struct proxy *defpx, const char *file, int line,
+                                  char **err)
+{
+       int i;
+
+       /* these two report the argument they were passed, so they can't be
+        * described by a static message.
+        */
+       if (strcmp(args[0], "monitor-net") == 0) {
+               memprintf(err, "the '%s' keyword is not supported anymore. "
+                         "Please use 'http-request return status 200 if { src %s }' instead.",
+                         args[0], args[1]);
+               return -1;
+       }
+
+       if (strcmp(args[0], "dispatch") == 0) {
+               memprintf(err, "the '%s' keyword is not supported anymore since HAProxy 3.5. "
+                         "The modern way to do the same is to create a server with the same address, "
+                         "and possibly to assign any extra server a weight of zero if any:\n"
+                         "    server dispatch %s", args[0], args[1]);
+               return -1;
+       }
+
+       BUG_ON(1, "unhandled keyword in proxy_parse_removed_kw().");
+       return -1;
+}
+
+static struct cfg_kw_list cfg_kws = {ILH, {
+       { CFG_LISTEN, "dispatch", proxy_parse_removed_kw },
+       { CFG_LISTEN, "monitor-net", proxy_parse_removed_kw },
+       { 0, NULL, NULL },
+}};
+
+INITCALL1(STG_REGISTER, cfg_register_keywords, &cfg_kws);