update lib/replace from samba4
[vlendec/samba-autobuild/.git] / ctdb / tools / ctdb.c
index b283789103566faef215115f76ac3026d10e6ebc..2308261d00535eb0079063ed30bf2a1ac7ee5587 100644 (file)
@@ -5,7 +5,7 @@
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
@@ -14,8 +14,7 @@
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program; if not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "includes.h"
@@ -308,22 +307,26 @@ static int control_status(struct ctdb_context *ctdb, int argc, const char **argv
  */
 static int kill_tcp(struct ctdb_context *ctdb, int argc, const char **argv)
 {
-       int i, ret;
+       int i, ret, numrst;
        struct sockaddr_in src, dst;
 
-       if (argc < 4) {
+       if (argc < 3) {
                usage();
        }
 
-       src.sin_family=AF_INET;
-       src.sin_port=htons(atoi(argv[1]));
-       inet_aton(argv[0], &src.sin_addr);
+       if (!parse_ip_port(argv[0], &src)) {
+               printf("Bad IP:port '%s'\n", argv[0]);
+               return -1;
+       }
 
-       dst.sin_family=AF_INET;
-       dst.sin_port=htons(atoi(argv[3]));
-       inet_aton(argv[2], &dst.sin_addr);
+       if (!parse_ip_port(argv[1], &dst)) {
+               printf("Bad IP:port '%s'\n", argv[1]);
+               return -1;
+       }
+
+       numrst = strtoul(argv[2], NULL, 0);
 
-       for (i=0;i<5;i++) {
+       for (i=0;i<numrst;i++) {
                ret = ctdb_sys_kill_tcp(ctdb->ev, &src, &dst);
 
                printf("ret:%d\n", ret);
@@ -335,6 +338,37 @@ static int kill_tcp(struct ctdb_context *ctdb, int argc, const char **argv)
        return -1;
 }
 
+/*
+  send a tcp tickle ack
+ */
+static int tickle_tcp(struct ctdb_context *ctdb, int argc, const char **argv)
+{
+       int ret;
+       struct sockaddr_in src, dst;
+
+       if (argc < 2) {
+               usage();
+       }
+
+       if (!parse_ip_port(argv[0], &src)) {
+               printf("Bad IP:port '%s'\n", argv[0]);
+               return -1;
+       }
+
+       if (!parse_ip_port(argv[1], &dst)) {
+               printf("Bad IP:port '%s'\n", argv[1]);
+               return -1;
+       }
+
+       ret = ctdb_sys_send_tcp(&src, &dst, 0, 0, 0);
+       if (ret==0) {
+               return 0;
+       }
+       printf("Error while sending tickle ack\n");
+
+       return -1;
+}
+
 /*
   display public ip status
  */
@@ -856,7 +890,8 @@ static const struct {
        { "recover",         control_recover,           true,  "force recovery" },
        { "freeze",          control_freeze,            true,  "freeze all databases" },
        { "thaw",            control_thaw,              true,  "thaw all databases" },
-       { "killtcp",         kill_tcp,                  false, "kill a tcp connection", "<srcip> <srcport> <dstip> <dstport>" },
+       { "killtcp",         kill_tcp,                  false, "kill a tcp connection. Try <num> times.", "<srcip:port> <dstip:port> <num>" },
+       { "tickle",          tickle_tcp,                false, "send a tcp tickle ack", "<srcip:port> <dstip:port>" },
 };
 
 /*
@@ -873,7 +908,7 @@ static void usage(void)
 "   -t <timelimit>     set timelimit for control in seconds (default %u)\n", options.timelimit);
        printf("Controls:\n");
        for (i=0;i<ARRAY_SIZE(ctdb_commands);i++) {
-               printf("  %-15s %-20s  %s\n", 
+               printf("  %-15s %-27s  %s\n", 
                       ctdb_commands[i].name, 
                       ctdb_commands[i].args?ctdb_commands[i].args:"",
                       ctdb_commands[i].msg);