]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: server: change server ip address from stats socket
authorBaptiste Assmann <bedis9@gmail.com>
Mon, 13 Apr 2015 20:54:33 +0000 (22:54 +0200)
committerWilly Tarreau <w@1wt.eu>
Sat, 13 Jun 2015 20:07:35 +0000 (22:07 +0200)
New command available on the stats socket to change a server addr using
the command "set server <backend>/<server> addr <ip4|ip6>"

doc/configuration.txt
include/proto/server.h
src/dumpstats.c
src/server.c

index 897e28500acd23cb4d6a788ee166fa9c40953212..9fbffbaafd89a85f14f0bf97e0f15dca8716ee02 100644 (file)
@@ -14930,6 +14930,9 @@ set rate-limit ssl-sessions global <value>
   is passed in number of sessions per second sent to the SSL stack. It applies
   before the handshake in order to protect the stack against handshake abuses.
 
+set server <backend>/<server> addr <ip4 or ip6 address>
+  Replace the current IP address of a server by the one provided.
+
 set server <backend>/<server> agent [ up | down ]
   Force a server's agent to a new state. This can be useful to immediately
   switch a server's state regardless of some slow agent checks for example.
index 7e329957320f1a895431fd4adf9a04ba2092768d..64f2327063579578d492950bb1b6cc2f666c2e9a 100644 (file)
@@ -94,6 +94,13 @@ static inline unsigned int server_throttle_rate(struct server *sv)
 const char *server_parse_weight_change_request(struct server *sv,
                                               const char *weight_str);
 
+/*
+ * Parses addr_str and configures sv accordingly.
+ * Returns NULL on success, error message string otherwise.
+ */
+const char *server_parse_addr_change_request(struct server *sv,
+                                             const char *addr_str);
+
 /*
  * Return true if the server has a zero user-weight, meaning it's in draining
  * mode (ie: not taking new non-persistent connections).
index 31bc0ba6ca2f54144cc481acb74d8d8ab02af4c4..cd19279558b9ac68bdc84d6676eae6dd25500e01 100644 (file)
@@ -186,7 +186,7 @@ static const char stats_sock_usage_msg[] =
        "  show table [id]: report table usage stats or dump this table's contents\n"
        "  get weight     : report a server's current weight\n"
        "  set weight     : change a server's weight\n"
-       "  set server     : change a server's state or weight\n"
+       "  set server     : change a server's state, weight or address\n"
        "  set table [id] : update or create a table entry's data\n"
        "  set timeout    : change a timeout setting\n"
        "  set maxconn    : change a maxconn setting\n"
@@ -1510,8 +1510,15 @@ static int stats_sock_parse_request(struct stream_interface *si, char *line)
                                        appctx->st0 = STAT_CLI_PRINT;
                                }
                        }
+                       else if (strcmp(args[3], "addr") == 0) {
+                               warning = server_parse_addr_change_request(sv, args[4]);
+                               if (warning) {
+                                       appctx->ctx.cli.msg = warning;
+                                       appctx->st0 = STAT_CLI_PRINT;
+                               }
+                       }
                        else {
-                               appctx->ctx.cli.msg = "'set server <srv>' only supports 'agent', 'health', 'state' and 'weight'.\n";
+                               appctx->ctx.cli.msg = "'set server <srv>' only supports 'agent', 'health', 'state', 'weight' and 'addr'.\n";
                                appctx->st0 = STAT_CLI_PRINT;
                        }
                        return 1;
index 369dd79ed62a0cccf3f9310b44c8571f98cda8cd..2bde246290e9e1cfc869ff5adc998d687a20e323 100644 (file)
@@ -802,6 +802,29 @@ const char *server_parse_weight_change_request(struct server *sv,
        return NULL;
 }
 
+/*
+ * Parses <addr_str> and configures <sv> accordingly.
+ * Returns:
+ *  - error string on error
+ *  - NULL on success
+ */
+const char *server_parse_addr_change_request(struct server *sv,
+                                             const char *addr_str)
+{
+       unsigned char ip[INET6_ADDRSTRLEN];
+
+       if (inet_pton(AF_INET6, addr_str, ip)) {
+               update_server_addr(sv, ip, AF_INET6, "stats command\n");
+               return NULL;
+       }
+       if (inet_pton(AF_INET, addr_str, ip)) {
+               update_server_addr(sv, ip, AF_INET, "stats command\n");
+               return NULL;
+       }
+
+       return "Could not understand IP address format.\n";
+}
+
 int parse_server(const char *file, int linenum, char **args, struct proxy *curproxy, struct proxy *defproxy)
 {
        struct server *newsrv = NULL;