2 CTDB TCP connection killing utility
4 Copyright (C) Martin Schwenke <martin@meltin.net> 2016
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, see <http://www.gnu.org/licenses/>.
21 #include "system/network.h"
23 #include "lib/util/debug.h"
25 #include "protocol/protocol.h"
27 #include "common/system.h"
28 #include "common/logging.h"
30 #include "server/killtcp.h"
32 static const char *prog;
34 static int ctdb_killtcp_destructor(struct ctdb_kill_tcp *killtcp)
36 bool *done = killtcp->destructor_data;
42 static void usage(void)
44 printf("usage: %s <interface> [ <srcip:port> <dstip:port> ]\n", prog);
48 int main(int argc, char **argv)
50 struct ctdb_connection conn;
51 struct ctdb_kill_tcp *killtcp = NULL;
52 struct tevent_context *ev = NULL;
53 struct TALLOC_CONTEXT *mem_ctx = NULL;
54 struct ctdb_connection *conns = NULL;
61 if (argc != 2 && argc != 4) {
66 if (!parse_ip_port(argv[2], &conn.src)) {
67 DEBUG(DEBUG_ERR, ("Bad IP:port '%s'\n", argv[2]));
71 if (!parse_ip_port(argv[3], &conn.dst)) {
72 DEBUG(DEBUG_ERR, ("Bad IP:port '%s'\n", argv[3]));
79 ret = ctdb_parse_connections(stdin, mem_ctx, &num, &conns);
82 ("Unable to parse connections [%s]\n",
88 mem_ctx = talloc_new(NULL);
89 if (mem_ctx == NULL) {
90 DEBUG(DEBUG_ERR, (__location__ " out of memory\n"));
94 ev = tevent_context_init(mem_ctx);
96 DEBUG(DEBUG_ERR, ("Failed to initialise tevent\n"));
101 /* No connections, done! */
102 talloc_free(mem_ctx);
106 for (i = 0; i < num; i++) {
107 ret = ctdb_killtcp(ev, mem_ctx, argv[1],
108 &conns[i].src, &conns[i].dst,
111 DEBUG(DEBUG_ERR, ("Unable to killtcp\n"));
117 killtcp->destructor_data = &done;
118 talloc_set_destructor(killtcp, ctdb_killtcp_destructor);
121 tevent_loop_once(ev);
124 talloc_free(mem_ctx);
129 TALLOC_FREE(mem_ctx);