]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: server: support keyword proto in 'add server' cli
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Fri, 12 Mar 2021 17:03:27 +0000 (18:03 +0100)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 18 Mar 2021 15:22:10 +0000 (16:22 +0100)
Allow to specify the mux proto for a dynamic server. It must be
compatible with the backend mode to be accepted. The reg-tests has been
extended for this error case.

doc/management.txt
reg-tests/server/cli_add_server.vtc
src/server.c

index 6301ffaca76379e0fead2ae2cb9195e06923ce89..261c74d5581f967fbd079bc19fbde8269bdc9997 100644 (file)
@@ -1447,6 +1447,7 @@ add server <backend>/<server> [args]*
   - pool-low-conn
   - pool-max-conn
   - pool-purge-delay
+  - proto
   - proxy-v2-options
   - send-proxy
   - send-proxy-v2
index be2d38ccf2b13854e86529b9661d2fb906f3abd3..67e7252344e04bcc7360234b68765b7c7a632f4e 100644 (file)
@@ -26,6 +26,10 @@ haproxy h1 -conf {
 
        backend other
                balance static-rr
+
+       backend other2
+               balance random
+               mode tcp
 } -start
 
 client c1 -connect ${h1_feS_sock} {
@@ -51,6 +55,10 @@ haproxy h1 -cli {
        send "experimental-mode on; add server other/s1 ${s1_addr}:${s1_port}"
        expect ~ "Backend must use a consistent hashing method for load balancing to support dynamic servers."
 
+       # invalid mux proto
+       send "experimental-mode on; add server other2/s1 ${s1_addr}:${s1_port} proto h2"
+       expect ~ "MUX protocol is not usable for server."
+
        # valid command
        send "experimental-mode on; add server test/s1 ${s1_addr}:${s1_port}"
        expect ~ "New server registered."
@@ -58,6 +66,11 @@ haproxy h1 -cli {
        # duplicate server
        send "experimental-mode on; add server test/s1 ${s1_addr}:${s1_port}"
        expect ~ "Already exists a server with the same name in backend."
+
+       # valid command
+       # specify the proto, it should be accepted for this backend
+       send "experimental-mode on; add server test/s2 ${s1_addr}:${s1_port} proto h2"
+       expect ~ "New server registered."
 }
 
 # dynamic servers are created on MAINT mode and should not be available at first
index 376c797c1fac2e5bc02ad47e00bf3a6aa14c393d..702c307fc48857227989eb8e3872fda5bbb6c0fb 100644 (file)
@@ -1651,7 +1651,7 @@ static struct srv_kw_list srv_kws = { "ALL", { }, {
        { "pool-low-conn",       srv_parse_pool_low_conn,       1,  1,  1 }, /* Set the min number of orphan idle connecbefore being allowed to pick from other threads */
        { "pool-max-conn",       srv_parse_pool_max_conn,       1,  1,  1 }, /* Set the max number of orphan idle connections, -1 means unlimited */
        { "pool-purge-delay",    srv_parse_pool_purge_delay,    1,  1,  1 }, /* Set the time before we destroy orphan idle connections, defaults to 1s */
-       { "proto",               srv_parse_proto,               1,  1,  0 }, /* Set the proto to use for all outgoing connections */
+       { "proto",               srv_parse_proto,               1,  1,  1 }, /* Set the proto to use for all outgoing connections */
        { "proxy-v2-options",    srv_parse_proxy_v2_options,    1,  1,  1 }, /* options for send-proxy-v2 */
        { "redir",               srv_parse_redir,               1,  1,  0 }, /* Enable redirection mode */
        { "resolve-net",         srv_parse_resolve_net,         1,  1,  0 }, /* Set the prefered network range for name resolution */
@@ -4377,6 +4377,13 @@ static int cli_parse_add_server(char **args, char *payload, struct appctx *appct
                goto out;
        }
 
+       if (srv->mux_proto) {
+               if (!conn_get_best_mux_entry(srv->mux_proto->token, PROTO_SIDE_BE, be->mode)) {
+                       cli_err(appctx, "MUX protocol is not usable for server.");
+                       goto out;
+               }
+       }
+
        srv->per_thr = calloc(global.nbthread, sizeof(*srv->per_thr));
        if (!srv->per_thr) {
                cli_err(appctx, "failed to allocate per-thread lists for server.");