1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-10 01:18:15 +03:00

ctdb-daemon: Move port filtering to server side when getting tickles

Why allocate all that memory and transfer all that data across the
socket?

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
This commit is contained in:
Martin Schwenke 2015-03-23 20:18:25 +11:00 committed by Amitay Isaacs
parent 84fdc2a562
commit 107f40abf9
2 changed files with 32 additions and 17 deletions

View File

@ -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;

View File

@ -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;i<list->num;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;i<list->num;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;
}