From: Willy Tarreau Date: Wed, 7 Oct 2026 15:59:26 +0000 (+0200) Subject: CLEANUP: cfgparse-listen: move "disabled" and "enabled" to their own parser X-Git-Tag: v3.5-dev9~135 X-Git-Url: https://git.kaiwu.me/$%7BISSUES%7D/static/gitweb.js?a=commitdiff_plain;h=bf90b356d00453de9f7ea56a612802a5a24dcc18;p=haproxy.git CLEANUP: cfgparse-listen: move "disabled" and "enabled" to their own parser Both keywords only set or clear PR_FL_DISABLED, so they were moved together to a new proxy_parse_enabled() function registered in cfg_kws, making them discoverable via "-dKcfg". --- diff --git a/src/cfgparse-listen.c b/src/cfgparse-listen.c index efe1ef539..805f69881 100644 --- a/src/cfgparse-listen.c +++ b/src/cfgparse-listen.c @@ -42,7 +42,7 @@ static const char *common_kw_list[] = { "listen", "frontend", "backend", "defaults", "server", "default-server", "server-template", "bind", - "monitor-uri", "mode", "id", "description", "disabled", "enabled", + "monitor-uri", "mode", "id", "description", "acl", "dynamic-cookie-key", "cookie", "email-alert", "persist", "load-server-state-from-file", "server-state-file-name", "max-session-srv-conns", "capture", @@ -770,16 +770,6 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm) d += snprintf(d, curproxy->desc + len - d, " %s", args[i]); } - else if (strcmp(args[0], "disabled") == 0) { /* disables this proxy */ - if (alertif_too_many_args(0, file, linenum, args, &err_code)) - goto out; - curproxy->flags |= PR_FL_DISABLED; - } - else if (strcmp(args[0], "enabled") == 0) { /* enables this proxy (used to revert a disabled default) */ - if (alertif_too_many_args(0, file, linenum, args, &err_code)) - goto out; - curproxy->flags &= ~PR_FL_DISABLED; - } else if (strcmp(args[0], "acl") == 0) { /* add an ACL */ if ((curproxy->cap & PR_CAP_DEF) && strlen(curproxy->id) == 0) { ha_alert("parsing [%s:%d] : '%s' not allowed in anonymous 'defaults' section.\n", file, linenum, args[0]); @@ -3194,12 +3184,37 @@ static int proxy_parse_removed_kw(char **args, int section_type, struct proxy *c return -1; } +/* Parses the "disabled" and "enabled" keywords, which mark this proxy as + * disabled or not. "enabled" is mostly used to revert a "disabled" inherited + * from a defaults section. + */ +static int proxy_parse_enabled(char **args, int section_type, struct proxy *curpx, + const struct proxy *defpx, const char *file, int line, + char **err) +{ + if (too_many_args(0, args, err, NULL)) + return -1; + + if (strcmp(args[0], "disabled") == 0) + curpx->flags |= PR_FL_DISABLED; + else if (strcmp(args[0], "enabled") == 0) + curpx->flags &= ~PR_FL_DISABLED; + else { + BUG_ON(1, "unhandled keyword in proxy_parse_enabled()."); + return -1; + } + + return 0; +} + static struct cfg_kw_list cfg_kws = {ILH, { { CFG_LISTEN, "appsession", proxy_parse_removed_kw }, { CFG_LISTEN, "bind-process", proxy_parse_removed_kw }, { CFG_LISTEN, "block", proxy_parse_removed_kw }, { CFG_LISTEN, "cliexp", proxy_parse_removed_kw }, + { CFG_LISTEN, "disabled", proxy_parse_enabled }, { CFG_LISTEN, "dispatch", proxy_parse_removed_kw }, + { CFG_LISTEN, "enabled", proxy_parse_enabled }, { CFG_LISTEN, "grace", proxy_parse_removed_kw }, { CFG_LISTEN, "monitor-net", proxy_parse_removed_kw }, { CFG_LISTEN, "redisp", proxy_parse_removed_kw },