]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: server: implement from be:
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 30 Jul 2026 13:25:52 +0000 (15:25 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Mon, 3 Aug 2026 14:52:09 +0000 (16:52 +0200)
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 <from>
output parameter.

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

index a52179c3a3ccd7515dbe81e40093057693c38b9d..36b565d18191c89a7cfefa33deb6835d749ff23f 100644 (file)
@@ -18227,6 +18227,14 @@ from <origin>
       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:[<bename>]
+      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,
index ce07f2617183fc3f36082c09c3644e7f79156a95..bd03ad72839b5244a5c12bd7bba58c4e7d945919 100644 (file)
@@ -1809,8 +1809,11 @@ add server <backend>/<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
index 155507ebec1a2f00daab8608e71606c9302be31b..78402f4c139cd10afa93a8194dfce6d6f882f37c 100644 (file)
@@ -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\\)"
 }
index d9140556fe5477d60c1e29aece1d81c84e3432b4..573f65256522f920e1675b74c7496c64f843b773 100644 (file)
@@ -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;