]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
REORG: cli: move "set maxconn frontend" to proxy.c
authorWilly Tarreau <w@1wt.eu>
Wed, 23 Nov 2016 15:22:04 +0000 (16:22 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 24 Nov 2016 15:59:28 +0000 (16:59 +0100)
And get rid of the last specific "set maxconn" case.

src/cli.c
src/proxy.c

index 177a955a7c90d3fe0e3744323a0be308a8600047..3e560c3e3fe57bf631d282251394066d334d8cae 100644 (file)
--- 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;
index 45a3db09ea7eb4e2ce3bd9db528ed8e36ad48c29..7d33442d4e9311b6f00907d4eacfb05c460459ae 100644 (file)
@@ -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 <id>)", 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 },
        {{},}