From 304672320ea6125875d7ba124abefe705eceabe1 Mon Sep 17 00:00:00 2001 From: Amaury Denoyelle Date: Fri, 12 Mar 2021 18:03:27 +0100 Subject: [PATCH] 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. --- doc/management.txt | 1 + reg-tests/server/cli_add_server.vtc | 13 +++++++++++++ src/server.c | 9 ++++++++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/doc/management.txt b/doc/management.txt index 6301ffaca7..261c74d558 100644 --- a/doc/management.txt +++ b/doc/management.txt @@ -1447,6 +1447,7 @@ add server / [args]* - 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 be2d38ccf2..67e7252344 100644 --- a/reg-tests/server/cli_add_server.vtc +++ b/reg-tests/server/cli_add_server.vtc @@ -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 diff --git a/src/server.c b/src/server.c index 376c797c1f..702c307fc4 100644 --- a/src/server.c +++ b/src/server.c @@ -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."); -- 2.39.5