mirror of
https://github.com/samba-team/samba.git
synced 2024-12-22 13:34:15 +03:00
ctdb-tools: Use ctdb_connection and ctdb_connection_list structs
Also use new connection and sock addr utilities. Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
This commit is contained in:
parent
6d9fef467c
commit
c355fd979a
@ -52,8 +52,7 @@ static const char *prog;
|
||||
|
||||
/* TCP connection to be killed */
|
||||
struct ctdb_killtcp_con {
|
||||
ctdb_sock_addr src_addr;
|
||||
ctdb_sock_addr dst_addr;
|
||||
struct ctdb_connection conn;
|
||||
struct ctdb_kill_tcp *killtcp;
|
||||
};
|
||||
|
||||
@ -115,14 +114,15 @@ static void capture_tcp_handler(struct tevent_context *ev,
|
||||
{
|
||||
struct ctdb_kill_tcp *killtcp = talloc_get_type(private_data, struct ctdb_kill_tcp);
|
||||
struct ctdb_killtcp_con *con;
|
||||
ctdb_sock_addr src, dst;
|
||||
/* 0 the parts that don't get set by ctdb_sys_read_tcp_packet */
|
||||
struct ctdb_connection conn;
|
||||
uint32_t ack_seq, seq;
|
||||
int rst;
|
||||
uint16_t window;
|
||||
|
||||
if (ctdb_sys_read_tcp_packet(killtcp->capture_fd,
|
||||
killtcp->private_data,
|
||||
&src, &dst,
|
||||
&conn.server, &conn.client,
|
||||
&ack_seq, &seq, &rst, &window) != 0) {
|
||||
/* probably a non-tcp ACK packet */
|
||||
return;
|
||||
@ -130,12 +130,11 @@ static void capture_tcp_handler(struct tevent_context *ev,
|
||||
|
||||
if (window == htons(1234) && (rst || seq == 0)) {
|
||||
/* Ignore packets that we sent! */
|
||||
DEBUG(DEBUG_DEBUG,
|
||||
("Ignoring packet with dst=%s, src=%s, seq=%"PRIu32", "
|
||||
"ack_seq=%"PRIu32", rst=%d, window=%"PRIu16"\n",
|
||||
ctdb_sock_addr_to_string(killtcp, &dst, true),
|
||||
ctdb_sock_addr_to_string(killtcp, &src, true),
|
||||
seq, ack_seq, rst, ntohs(window)));
|
||||
D_DEBUG("Ignoring packet: %s, "
|
||||
"seq=%"PRIu32", ack_seq=%"PRIu32", "
|
||||
"rst=%d, window=%"PRIu16"\n",
|
||||
ctdb_connection_to_string(killtcp, &conn, false),
|
||||
seq, ack_seq, rst, ntohs(window));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -143,7 +142,8 @@ static void capture_tcp_handler(struct tevent_context *ev,
|
||||
to kill
|
||||
*/
|
||||
con = trbt_lookuparray32(killtcp->connections,
|
||||
KILLTCP_KEYLEN, killtcp_key(&src, &dst));
|
||||
KILLTCP_KEYLEN,
|
||||
killtcp_key(&conn.server, &conn.client));
|
||||
if (con == NULL) {
|
||||
/* no this was some other packet we can just ignore */
|
||||
return;
|
||||
@ -151,12 +151,11 @@ static void capture_tcp_handler(struct tevent_context *ev,
|
||||
|
||||
/* This connection has been tickled! RST it and remove it
|
||||
* from the list. */
|
||||
DEBUG(DEBUG_INFO,
|
||||
("Sending a TCP RST to kill connection (%s) -> %s\n",
|
||||
ctdb_sock_addr_to_string(con, &con->src_addr, true),
|
||||
ctdb_sock_addr_to_string(con, &con->dst_addr, true)));
|
||||
D_INFO("Sending a TCP RST to kill connection %s\n",
|
||||
ctdb_connection_to_string(killtcp, &con->conn, true));
|
||||
|
||||
ctdb_sys_send_tcp(&con->dst_addr, &con->src_addr, ack_seq, seq, 1);
|
||||
ctdb_sys_send_tcp(&con->conn.server, &con->conn.client,
|
||||
ack_seq, seq, 1);
|
||||
talloc_free(con);
|
||||
}
|
||||
|
||||
@ -176,7 +175,7 @@ static int tickle_connection_traverse(void *param, void *data)
|
||||
return -1;
|
||||
}
|
||||
|
||||
ctdb_sys_send_tcp(&con->dst_addr, &con->src_addr, 0, 0, 0);
|
||||
ctdb_sys_send_tcp(&con->conn.server, &con->conn.client, 0, 0, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -238,8 +237,7 @@ static void *add_killtcp_callback(void *parm, void *data)
|
||||
static int ctdb_killtcp(struct tevent_context *ev,
|
||||
TALLOC_CTX *mem_ctx,
|
||||
const char *iface,
|
||||
const ctdb_sock_addr *src,
|
||||
const ctdb_sock_addr *dst,
|
||||
struct ctdb_connection *conn,
|
||||
struct ctdb_kill_tcp **killtcp_arg)
|
||||
{
|
||||
struct ctdb_kill_tcp *killtcp;
|
||||
@ -284,15 +282,15 @@ static int ctdb_killtcp(struct tevent_context *ev,
|
||||
DEBUG(DEBUG_ERR, (__location__ " out of memory\n"));
|
||||
return -1;
|
||||
}
|
||||
con->src_addr = *src;
|
||||
con->dst_addr = *dst;
|
||||
con->conn.client = conn->client;
|
||||
con->conn.server = conn->server;
|
||||
con->killtcp = killtcp;
|
||||
|
||||
|
||||
trbt_insertarray32_callback(killtcp->connections,
|
||||
KILLTCP_KEYLEN,
|
||||
killtcp_key(&con->dst_addr,
|
||||
&con->src_addr),
|
||||
killtcp_key(&con->conn.server,
|
||||
&con->conn.client),
|
||||
add_killtcp_callback, con);
|
||||
|
||||
/*
|
||||
@ -342,11 +340,10 @@ int main(int argc, char **argv)
|
||||
struct ctdb_kill_tcp *killtcp = NULL;
|
||||
struct tevent_context *ev = NULL;
|
||||
struct TALLOC_CONTEXT *mem_ctx = NULL;
|
||||
struct ctdb_connection *conns = NULL;
|
||||
struct ctdb_connection_list *conn_list = NULL;
|
||||
const char *t;
|
||||
int debug_level;
|
||||
bool done;
|
||||
int num = 0;
|
||||
int i, ret;
|
||||
|
||||
/* Set the debug level */
|
||||
@ -366,24 +363,35 @@ int main(int argc, char **argv)
|
||||
}
|
||||
|
||||
if (argc == 4) {
|
||||
if (!parse_ip_port(argv[2], &conn.src)) {
|
||||
DEBUG(DEBUG_ERR, ("Bad IP:port '%s'\n", argv[2]));
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (!parse_ip_port(argv[3], &conn.dst)) {
|
||||
DEBUG(DEBUG_ERR, ("Bad IP:port '%s'\n", argv[3]));
|
||||
goto fail;
|
||||
}
|
||||
|
||||
conns = &conn;
|
||||
num = 1;
|
||||
} else {
|
||||
ret = ctdb_parse_connections(stdin, mem_ctx, &num, &conns);
|
||||
ret = ctdb_sock_addr_from_string(argv[2], &conn.client, true);
|
||||
if (ret != 0) {
|
||||
DEBUG(DEBUG_ERR,
|
||||
("Unable to parse connections [%s]\n",
|
||||
strerror(ret)));
|
||||
D_ERR("Bad IP:port '%s'\n", argv[2]);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = ctdb_sock_addr_from_string(argv[3], &conn.server, true);
|
||||
if (ret != 0) {
|
||||
D_ERR("Bad IP:port '%s'\n", argv[3]);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
|
||||
conn_list = talloc_zero(mem_ctx, struct ctdb_connection_list);
|
||||
if (conn_list == NULL) {
|
||||
ret = ENOMEM;
|
||||
DBG_ERR("Internal error (%s)\n", strerror(ret));
|
||||
goto fail;
|
||||
}
|
||||
ret = ctdb_connection_list_add(conn_list, &conn);
|
||||
if (ret != 0) {
|
||||
DBG_ERR("Internal error (%s)\n", strerror(ret));
|
||||
goto fail;
|
||||
}
|
||||
} else {
|
||||
ret = ctdb_connection_list_read(mem_ctx, true, &conn_list);
|
||||
if (ret != 0) {
|
||||
D_ERR("Unable to parse connections (%s)\n",
|
||||
strerror(ret));
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
@ -400,16 +408,15 @@ int main(int argc, char **argv)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (num == 0) {
|
||||
if (conn_list->num == 0) {
|
||||
/* No connections, done! */
|
||||
talloc_free(mem_ctx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < num; i++) {
|
||||
for (i = 0; i < conn_list->num; i++) {
|
||||
ret = ctdb_killtcp(ev, mem_ctx, argv[1],
|
||||
&conns[i].src, &conns[i].dst,
|
||||
&killtcp);
|
||||
&conn_list->conn[i], &killtcp);
|
||||
if (ret != 0) {
|
||||
DEBUG(DEBUG_ERR, ("Unable to killtcp\n"));
|
||||
goto fail;
|
||||
|
Loading…
Reference in New Issue
Block a user