]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MINOR] Allow showing and clearing by key of integer stick tables
authorSimon Horman <horms@verge.net.au>
Wed, 15 Jun 2011 06:18:51 +0000 (15:18 +0900)
committerWilly Tarreau <w@1wt.eu>
Fri, 17 Jun 2011 09:39:30 +0000 (11:39 +0200)
doc/configuration.txt
src/dumpstats.c

index a946e75d5df9162f0190ceb3ed4155fb2f838673..f70a9522f5f127ddac011af40ffc416aae9a4257 100644 (file)
@@ -9336,7 +9336,7 @@ clear table <table> [ data.<type> <operator> <value> ] | [ key <key> ]
     - gt : match entries whose data is greater than this value
 
   When the key form is used the entry <key> is removed.  The key must be of the
-  same type as the table, which currently is limited to IPv4 and IPv6.
+  same type as the table, which currently is limited to IPv4, IPv6 and integer.
 
   Example :
         $ echo "show table http_proxy" | socat stdio /tmp/sock1
@@ -9562,7 +9562,7 @@ show table <name> [ data.<type> <operator> <value> ] | [ key <key> ]
 
 
   When the key form is used the entry <key> is shown.  The key must be of the
-  same type as the table, which currently is limited to IPv4 and IPv6.
+  same type as the table, which currently is limited to IPv4, IPv6 and integer.
 
   Example :
         $ echo "show table http_proxy" | socat stdio /tmp/sock1
index 0d5396c0e78e4e50402e5f24a5792b547d3fa2df..45424dfa3cfbcf89b8a7ef23cccedad9aa865d08 100644 (file)
@@ -15,6 +15,7 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <stdbool.h>
+#include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -510,7 +511,7 @@ static void stats_sock_table_key_request(struct stream_interface *si, char **arg
        struct session *s = si->applet.private;
        struct proxy *px = si->applet.ctx.table.target;
        struct stksess *ts;
-       unsigned int ip_key;
+       uint32_t uint32_key;
        unsigned char ip6_key[sizeof(struct in6_addr)];
 
        si->applet.st0 = STAT_CLI_OUTPUT;
@@ -523,18 +524,36 @@ static void stats_sock_table_key_request(struct stream_interface *si, char **arg
 
        switch (px->table.type) {
        case STKTABLE_TYPE_IP:
-               ip_key = htonl(inetaddr_host(args[4]));
-               static_table_key.key = (void *)&ip_key;
+               uint32_key = htonl(inetaddr_host(args[4]));
+               static_table_key.key = &uint32_key;
                break;
        case STKTABLE_TYPE_IPV6:
                inet_pton(AF_INET6, args[4], ip6_key);
                static_table_key.key = &ip6_key;
                break;
+       case STKTABLE_TYPE_INTEGER:
+               {
+                       char *endptr;
+                       unsigned long val;
+                       errno = 0;
+                       val = strtoul(args[4], &endptr, 10);
+                       if ((errno == ERANGE && val == ULONG_MAX) ||
+                           (errno != 0 && val == 0) || endptr == args[4] ||
+                           val > 0xffffffff) {
+                               si->applet.ctx.cli.msg = "Invalid key\n";
+                               si->applet.st0 = STAT_CLI_PRINT;
+                               return;
+                       }
+                       uint32_key = (uint32_t) val;
+                       static_table_key.key = &uint32_key;
+                       break;
+               }
+               break;
        default:
                if (show)
-                       si->applet.ctx.cli.msg = "Showing keys from tables of type other than ip and ipv6 is not supported\n";
+                       si->applet.ctx.cli.msg = "Showing keys from tables of type other than ip, ipv6 and integer is not supported\n";
                else
-                       si->applet.ctx.cli.msg = "Removing keys from ip tables of type other than ip and ipv6 is not supported\n";
+                       si->applet.ctx.cli.msg = "Removing keys from ip tables of type other than ip, ipv6 and integer is not supported\n";
                si->applet.st0 = STAT_CLI_PRINT;
                return;
        }