From: Amaury Denoyelle Date: Thu, 30 Jul 2026 13:25:52 +0000 (+0200) Subject: MEDIUM: server: implement from be: X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=077fd330d4d715d07159b66678c8725e2043bf34;p=thirdparty%2Fhaproxy.git MEDIUM: server: implement from be: Implement "from be:" syntax. This instructs that the server should reuse parameters from the default-server already defined in the same proxy instance. This behavior is already the current one in the configuration parser, thus there is no visible change here. The main usage is on "add server" command, which previously always ignored a default-server instance. This is implemented by extending _srv_parse_from() to parse "be:" argument value. If found, the designated server is returned via output parameter. --- diff --git a/doc/configuration.txt b/doc/configuration.txt index a52179c3a..36b565d18 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -18227,6 +18227,14 @@ from servers. This value is also directly useful on a default-server line, to reset its set of options to their documented values, before eventually configuring new settings. + - be:[] + instructs to reuse the settings from the final state of the designated + backend's default-server resulting from the processing of all its unnamed + default-server directives. If no backend is specified, the parent proxy + of the currently configured server is selected : this is the default + behavior for servers defined in the configuration file. This empty value + is mostly useful for dynamic servers created on the CLI which by default + ignore any default-server, which is equivalent to the "none" value. The currently supported server settings are the following ones. Note that all these settings are supported both by "server" and "default-server" keywords, diff --git a/doc/management.txt b/doc/management.txt index ce07f2617..bd03ad728 100644 --- a/doc/management.txt +++ b/doc/management.txt @@ -1809,8 +1809,11 @@ add server / [args]* restriction is put on the backend which must used a dynamic load-balancing algorithm. A subset of keywords from the server config file statement can be used to configure the server behavior (see "add server help" to list them). - Also note that no settings will be reused from an hypothetical - 'default-server' statement in the same backend. + + By default, 'default-server' is ignored by a dynamically created server. + However, it is possible to use the 'from' server positional keyword to + explicitely preset the settings of the newly created server from a + default-server instance. Currently a dynamic server is statically initialized with the "none" init-addr method. This means that no resolution will be undertaken if a FQDN diff --git a/reg-tests/server/from_keyword.vtc b/reg-tests/server/from_keyword.vtc index 155507ebe..78402f4c1 100644 --- a/reg-tests/server/from_keyword.vtc +++ b/reg-tests/server/from_keyword.vtc @@ -61,4 +61,10 @@ haproxy h1 -cli { expect ~ "New server registered." send "get weight be/srvdyn1" expect ~ "1 \\(initial 1\\)" + + # reuse default-server for a dynamic server insertion + send "add server be/srvdyn2 ${s1_addr}:${s1_port} from be:" + expect ~ "New server registered." + send "get weight be/srvdyn2" + expect ~ "10 \\(initial 10\\)" } diff --git a/src/server.c b/src/server.c index d9140556f..573f65256 100644 --- a/src/server.c +++ b/src/server.c @@ -3948,6 +3948,22 @@ static int _srv_parse_from(struct server *srv, char **args, int *cur_arg, else if (strcmp(args[*cur_arg + 1], "none") == 0) { *from = NULL; } + else if (strncmp(args[*cur_arg + 1], "be:", 3) == 0) { + struct ist be_name = istadv(ist(args[*cur_arg + 1]), 3); + struct proxy *px = curproxy; + + if (istlen(be_name)) { + px = proxy_be_by_name(istptr(be_name)); + if (!px) { + ha_alert("from: unknown backend instance '%s'.\n", + istptr(be_name)); + err_code = ERR_ALERT | ERR_FATAL; + goto out; + } + } + + *from = px->defsrv; + } else { ha_alert("invalid '%s' value for 'from' keyword.\n", args[*cur_arg + 1]); err_code |= ERR_FATAL | ERR_ALERT;