From: Amaury Denoyelle Date: Thu, 22 May 2025 15:12:53 +0000 (+0200) Subject: MINOR: server: implement "add server help" X-Git-Tag: v3.2.0~33 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4de5090976e1d188c039eec5373ccbf448f8bc9f;p=thirdparty%2Fhaproxy.git MINOR: server: implement "add server help" Implement "help" as a sub-command for "add server" CLI. The objective is to list all the keywords that are supported for dynamic servers. CLI IO handler and add_srv_ctx are used to support reentrancy on full output buffer. Now that this command is implemented, the outdated keyword list on "add server" from management documentation can be removed. --- diff --git a/doc/management.txt b/doc/management.txt index e7ecb0bbc..984d5645c 100644 --- a/doc/management.txt +++ b/doc/management.txt @@ -1724,8 +1724,9 @@ add server / [args]* The name must not be already used in the backend. A special restriction is put on the backend which must used a dynamic load-balancing algorithm. A subset of keywords from the server config file statement can be - used to configure the server behavior. Also note that no settings will be - reused from an hypothetical 'default-server' statement in the same backend. + used to configure the server behavior (see "add server help" to list them). + Also note that no settings will be reused from an hypothetical + 'default-server' statement in the same backend. Currently a dynamic server is statically initialized with the "none" init-addr method. This means that no resolution will be undertaken if a FQDN @@ -1755,78 +1756,10 @@ add server / [args]* servers. Please refer to the "u-limit" global keyword documentation in this case. - Here is the list of the currently supported keywords : - - - agent-addr - - agent-check - - agent-inter - - agent-port - - agent-send - - allow-0rtt - - alpn - - addr - - backup - - ca-file - - check - - check-alpn - - check-proto - - check-send-proxy - - check-sni - - check-ssl - - check-via-socks4 - - ciphers - - ciphersuites - - cookie - - crl-file - - crt - - disabled - - downinter - - error-limit - - fall - - fastinter - - force-sslv3/tlsv10/tlsv11/tlsv12/tlsv13 - - id - - init-state - - inter - - maxconn - - maxqueue - - minconn - - no-ssl-reuse - - no-sslv3/tlsv10/tlsv11/tlsv12/tlsv13 - - no-tls-tickets - - npn - - observe - - on-error - - on-marked-down - - on-marked-up - - pool-low-conn - - pool-max-conn - - pool-purge-delay - - port - - proto - - proxy-v2-options - - rise - - send-proxy - - send-proxy-v2 - - send-proxy-v2-ssl - - send-proxy-v2-ssl-cn - - slowstart - - sni - - source - - ssl - - ssl-max-ver - - ssl-min-ver - - tfo - - tls-tickets - - track - - usesrc - - verify - - verifyhost - - weight - - ws - - Their syntax is similar to the server line from the configuration file, - please refer to their individual documentation for details. +add server help + List the keywords supported for dynamic servers by the current haproxy + version. Keyword syntax is similar to the server line from the configuration + file, please refer to their individual documentation for details. add ssl ca-file Add a new certificate to a ca-file. This command is useful when you reached diff --git a/src/server.c b/src/server.c index 27c5b44bf..afe228043 100644 --- a/src/server.c +++ b/src/server.c @@ -5816,6 +5816,7 @@ int srv_init_per_thr(struct server *srv) /* Distinguish between "add server" default usage or one of its sub-commands. */ enum add_srv_mode { ADD_SRV_MODE_DEF, /* default mode, IO handler should be skipped by parser. */ + ADD_SRV_MODE_HELP, /* help mode to list supported keywords */ }; /* Context for "add server" CLI. */ @@ -5825,12 +5826,45 @@ struct add_srv_ctx { void *obj2; }; -/* Handler for "add server" command. Should be reserved to extra sub-commands. */ +/* Handler for "add server" command. Should be reserved to extra sub-commands + * such as "help". + */ int cli_io_handler_add_server(struct appctx *appctx) { struct add_srv_ctx *ctx = appctx->svcctx; + struct srv_kw_list *kwl = ctx->obj1; + struct srv_kw *kw; switch (ctx->mode) { + case ADD_SRV_MODE_HELP: + if (!kwl) { + /* first invocation */ + if (applet_putstr(appctx, "List of keywords supported for dynamic server:\n") < 0) + return cli_err(appctx, "output error"); + + kwl = LIST_NEXT(&srv_keywords.list, struct srv_kw_list *, list); + ctx->obj1 = kwl; + ctx->obj2 = kwl->kw; + } + + while (kwl != &srv_keywords) { + for (kw = ctx->obj2; kw->kw; ++kw) { + if (!kw->dynamic_ok) + continue; + + ctx->obj2 = kw; + chunk_reset(&trash); + chunk_printf(&trash, "%s\n", kw->kw); + if (applet_putchk(appctx, &trash) == -1) + goto full; + } + + kwl = LIST_NEXT(&kwl->list, struct srv_kw_list *, list); + ctx->obj1 = kwl; + ctx->obj2 = kwl->kw; + } + break; + case ADD_SRV_MODE_DEF: /* Add srv parser must return 1 to prevent I/O handler execution in default mode. */ ABORT_NOW(); @@ -5838,6 +5872,9 @@ int cli_io_handler_add_server(struct appctx *appctx) } return 1; + + full: + return 0; } /* Parse a "add server" command. @@ -5861,6 +5898,12 @@ static int cli_parse_add_server(char **args, char *payload, struct appctx *appct ++args; + if (strcmp(args[1], "help") == 0) { + ctx->mode = ADD_SRV_MODE_HELP; + ctx->obj2 = ctx->obj1 = NULL; + return 0; + } + ctx->mode = ADD_SRV_MODE_DEF; sv_name = be_name = args[1]; /* split backend/server arg */