MINOR: server: support keyword proto in 'add server' cli
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.
diff --git a/doc/management.txt b/doc/management.txt
index 6301ffa..261c74d 100644
--- a/doc/management.txt
+++ b/doc/management.txt
@@ -1447,6 +1447,7 @@
- pool-low-conn
- pool-max-conn
- pool-purge-delay
+ - proto
- proxy-v2-options
- send-proxy
- send-proxy-v2
diff --git a/reg-tests/server/cli_add_server.vtc b/reg-tests/server/cli_add_server.vtc
index be2d38c..67e7252 100644
--- a/reg-tests/server/cli_add_server.vtc
+++ b/reg-tests/server/cli_add_server.vtc
@@ -26,6 +26,10 @@
backend other
balance static-rr
+
+ backend other2
+ balance random
+ mode tcp
} -start
client c1 -connect ${h1_feS_sock} {
@@ -51,6 +55,10 @@
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 @@
# 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
diff --git a/src/server.c b/src/server.c
index 376c797..702c307 100644
--- a/src/server.c
+++ b/src/server.c
@@ -1651,7 +1651,7 @@
{ "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 @@
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.");