From: Willy Tarreau Date: Wed, 7 Oct 2026 15:25:15 +0000 (+0200) Subject: CLEANUP: cfgparse-global: move "anonkey" to its own parser X-Git-Tag: v3.5-dev9~140 X-Git-Url: https://git.kaiwu.me/?a=commitdiff_plain;h=3e409f45418bf76584dba17c5a7a6d025e6de122;p=haproxy.git CLEANUP: cfgparse-global: move "anonkey" to its own parser The keyword is now registered in cfg_kws and parsed by cfg_parse_global_anonkey(), making it discoverable via "-dKcfg". This was the last keyword parsed by strcmp() in cfg_parse_global(). --- diff --git a/src/cfgparse-global.c b/src/cfgparse-global.c index e7eb7ab26..1efc372ac 100644 --- a/src/cfgparse-global.c +++ b/src/cfgparse-global.c @@ -66,30 +66,6 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm) if (global.mode & MODE_DISCOVERY) goto discovery_kw; - else if (strcmp(args[0], "anonkey") == 0) { - long long tmp = 0; - - if (alertif_too_many_args(1, file, linenum, args, &err_code)) - goto out; - if (*args[1] == 0) { - ha_alert("parsing [%s:%d]: a key is expected after '%s'.\n", - file, linenum, args[0]); - err_code |= ERR_ALERT | ERR_FATAL; - goto out; - } - - if (HA_ATOMIC_LOAD(&global.anon_key) == 0) { - tmp = atoll(args[1]); - if (tmp < 0 || tmp > UINT_MAX) { - ha_alert("parsing [%s:%d]: '%s' value must be within range %u-%u (was '%s').\n", - file, linenum, args[0], 0, UINT_MAX, args[1]); - err_code |= ERR_ALERT | ERR_FATAL; - goto out; - } - - HA_ATOMIC_STORE(&global.anon_key, tmp); - } - } else { struct cfg_kw_list *kwl; const char *best; @@ -2033,7 +2009,41 @@ static int cfg_parse_global_cpu_map(char **args, int section_type, struct proxy #endif /* ! USE_CPU_AFFINITY */ } +/* Parses the "anonkey" keyword, which sets the key used to anonymize the + * configuration and the dumps. It is ignored if a key was already set, e.g. + * from the command line. + */ +static int cfg_parse_global_anonkey(char **args, int section_type, struct proxy *curpx, + const struct proxy *defpx, const char *file, int line, + char **err) +{ + long long key; + + if (too_many_args(1, args, err, NULL)) + return -1; + + if (*args[1] == 0) { + memprintf(err, "a key is expected after '%s'.", args[0]); + return -1; + } + + if (HA_ATOMIC_LOAD(&global.anon_key) != 0) + return 0; + + key = atoll(args[1]); + if (key < 0 || key > UINT_MAX) { + memprintf(err, "'%s' value must be within range %u-%u (was '%s').", + args[0], 0, UINT_MAX, args[1]); + return -1; + } + + HA_ATOMIC_STORE(&global.anon_key, key); + + return 0; +} + static struct cfg_kw_list cfg_kws = {ILH, { + { CFG_GLOBAL, "anonkey", cfg_parse_global_anonkey }, { CFG_GLOBAL, "busy-polling", cfg_parse_global_bool_opts }, { CFG_GLOBAL, "chroot", cfg_parse_global_chroot }, { CFG_GLOBAL, "cluster-secret", cfg_parse_global_cluster_secret },