diff --git a/ctdb/server/ctdb_takeover.c b/ctdb/server/ctdb_takeover.c index 88656f97444..0caf55bff33 100644 --- a/ctdb/server/ctdb_takeover.c +++ b/ctdb/server/ctdb_takeover.c @@ -2633,22 +2633,34 @@ int32_t ctdb_control_get_tcp_tickle_list(struct ctdb_context *ctdb, TDB_DATA ind ctdb_sock_addr *addr = (ctdb_sock_addr *)indata.dptr; struct ctdb_tickle_list_old *list; struct ctdb_tcp_array *tcparray; - int num; + int num, i; struct ctdb_vnn *vnn; + unsigned port; vnn = find_public_ip_vnn(ctdb, addr); if (vnn == NULL) { - DEBUG(DEBUG_ERR,(__location__ " Could not get tcp tickle list, '%s' is not a public address\n", + DEBUG(DEBUG_ERR,(__location__ " Could not get tcp tickle list, '%s' is not a public address\n", ctdb_addr_to_str(addr))); return 1; } + port = ctdb_addr_to_port(addr); + tcparray = vnn->tcp_array; - if (tcparray) { - num = tcparray->num; - } else { - num = 0; + num = 0; + if (tcparray != NULL) { + if (port == 0) { + /* All connections */ + num = tcparray->num; + } else { + /* Count connections for port */ + for (i = 0; i < tcparray->num; i++) { + if (port == ctdb_addr_to_port(&tcparray->connections[i].dst)) { + num++; + } + } + } } outdata->dsize = offsetof(struct ctdb_tickle_list_old, connections) @@ -2660,9 +2672,18 @@ int32_t ctdb_control_get_tcp_tickle_list(struct ctdb_context *ctdb, TDB_DATA ind list->addr = *addr; list->num = num; - if (num) { - memcpy(&list->connections[0], tcparray->connections, - sizeof(struct ctdb_connection) * num); + + if (num == 0) { + return 0; + } + + num = 0; + for (i = 0; i < tcparray->num; i++) { + if (port == 0 || \ + port == ctdb_addr_to_port(&tcparray->connections[i].dst)) { + list->connections[num] = tcparray->connections[i]; + num++; + } } return 0; diff --git a/ctdb/tools/ctdb.c b/ctdb/tools/ctdb.c index 2d4610f1223..350e2dfe5c8 100644 --- a/ctdb/tools/ctdb.c +++ b/ctdb/tools/ctdb.c @@ -1479,7 +1479,7 @@ static int control_get_tickles(struct ctdb_context *ctdb, int argc, const char * port = atoi(argv[1]); } - if (parse_ip(argv[0], NULL, 0, &addr) == 0) { + if (parse_ip(argv[0], NULL, port, &addr) == 0) { DEBUG(DEBUG_ERR,("Wrongly formed ip address '%s'\n", argv[0])); return -1; } @@ -1493,9 +1493,6 @@ static int control_get_tickles(struct ctdb_context *ctdb, int argc, const char * if (options.machinereadable){ printm(":source ip:port:destination ip:port:\n"); for (i=0;inum;i++) { - if (port && port != ntohs(list->connections[i].dst.ip.sin_port)) { - continue; - } printm(":%s:%u", ctdb_addr_to_str(&list->connections[i].src), ntohs(list->connections[i].src.ip.sin_port)); printm(":%s:%u:\n", ctdb_addr_to_str(&list->connections[i].dst), ntohs(list->connections[i].dst.ip.sin_port)); } @@ -1503,16 +1500,13 @@ static int control_get_tickles(struct ctdb_context *ctdb, int argc, const char * printf("Tickles for ip:%s\n", ctdb_addr_to_str(&list->addr)); printf("Num tickles:%u\n", list->num); for (i=0;inum;i++) { - if (port && port != ntohs(list->connections[i].dst.ip.sin_port)) { - continue; - } printf("SRC: %s:%u ", ctdb_addr_to_str(&list->connections[i].src), ntohs(list->connections[i].src.ip.sin_port)); printf("DST: %s:%u\n", ctdb_addr_to_str(&list->connections[i].dst), ntohs(list->connections[i].dst.ip.sin_port)); } } talloc_free(list); - + return 0; }