From: Willy Tarreau Date: Wed, 23 Nov 2016 15:22:04 +0000 (+0100) Subject: REORG: cli: move "set maxconn frontend" to proxy.c X-Git-Tag: v1.7.0~39 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c429a1fc2d4fa59fc23a82d1eebe4a9c383cf376;p=thirdparty%2Fhaproxy.git REORG: cli: move "set maxconn frontend" to proxy.c And get rid of the last specific "set maxconn" case. --- diff --git a/src/cli.c b/src/cli.c index 177a955a7c..3e560c3e3f 100644 --- a/src/cli.c +++ b/src/cli.c @@ -73,7 +73,6 @@ static const char stats_sock_usage_msg[] = " help : this message\n" " prompt : toggle interactive mode with prompt\n" " quit : disconnect\n" - " set maxconn : change a maxconn setting\n" " set rate-limit : change a rate limiting value\n" " disable : put a server or frontend in maintenance mode\n" " enable : re-enable a server or frontend which is in maintenance mode\n" @@ -542,51 +541,7 @@ static int stats_sock_parse_request(struct stream_interface *si, char *line) } } else if (strcmp(args[0], "set") == 0) { - if (strcmp(args[1], "maxconn") == 0) { - if (strcmp(args[2], "frontend") == 0) { - struct proxy *px; - struct listener *l; - int v; - - px = expect_frontend_admin(s, si, args[3]); - if (!px) - return 1; - - if (!*args[4]) { - appctx->ctx.cli.msg = "Integer value expected.\n"; - appctx->st0 = STAT_CLI_PRINT; - return 1; - } - - v = atoi(args[4]); - if (v < 0) { - appctx->ctx.cli.msg = "Value out of range.\n"; - appctx->st0 = STAT_CLI_PRINT; - return 1; - } - - /* OK, the value is fine, so we assign it to the proxy and to all of - * its listeners. The blocked ones will be dequeued. - */ - px->maxconn = v; - list_for_each_entry(l, &px->conf.listeners, by_fe) { - l->maxconn = v; - if (l->state == LI_FULL) - resume_listener(l); - } - - if (px->maxconn > px->feconn && !LIST_ISEMPTY(&px->listener_queue)) - dequeue_all_listeners(&px->listener_queue); - - return 1; - } - else { - appctx->ctx.cli.msg = "'set maxconn' only supports 'frontend', 'server', and 'global'.\n"; - appctx->st0 = STAT_CLI_PRINT; - return 1; - } - } - else if (strcmp(args[1], "rate-limit") == 0) { + if (strcmp(args[1], "rate-limit") == 0) { if (strcmp(args[2], "connections") == 0) { if (strcmp(args[3], "global") == 0) { int v; diff --git a/src/proxy.c b/src/proxy.c index 45a3db09ea..7d33442d4e 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -1419,8 +1419,52 @@ static int cli_io_handler_show_backend(struct appctx *appctx) return 1; } +/* Parses the "set maxconn frontend" directive, it always returns 1 */ +static int cli_parse_set_maxconn_frontend(char **args, struct appctx *appctx, void *private) +{ + struct proxy *px; + struct listener *l; + int v; + + if (!cli_has_level(appctx, ACCESS_LVL_ADMIN)) + return 1; + + px = cli_find_frontend(appctx, args[3]); + if (!px) + return 1; + + if (!*args[4]) { + appctx->ctx.cli.msg = "Integer value expected.\n"; + appctx->st0 = STAT_CLI_PRINT; + return 1; + } + + v = atoi(args[4]); + if (v < 0) { + appctx->ctx.cli.msg = "Value out of range.\n"; + appctx->st0 = STAT_CLI_PRINT; + return 1; + } + + /* OK, the value is fine, so we assign it to the proxy and to all of + * its listeners. The blocked ones will be dequeued. + */ + px->maxconn = v; + list_for_each_entry(l, &px->conf.listeners, by_fe) { + l->maxconn = v; + if (l->state == LI_FULL) + resume_listener(l); + } + + if (px->maxconn > px->feconn && !LIST_ISEMPTY(&px->listener_queue)) + dequeue_all_listeners(&px->listener_queue); + + return 1; +} + /* register cli keywords */ static struct cli_kw_list cli_kws = {{ },{ + { { "set", "maxconn", "frontend", NULL }, "set maxconn frontend : change a frontend's maxconn setting", cli_parse_set_maxconn_frontend, NULL }, { { "show","servers", "state", NULL }, "show servers state [id]: dump volatile server information (for backend )", cli_parse_show_servers, cli_io_handler_servers_state }, { { "show", "backend", NULL }, "show backend : list backends in the current running config", cli_parse_show_backend, cli_io_handler_show_backend }, {{},}