summaryrefslogtreecommitdiffstats
path: root/ctdb
diff options
context:
space:
mode:
authorMartin Schwenke <martin@meltin.net>2014-03-03 13:20:06 +1100
committerAmitay Isaacs <amitay@samba.org>2014-03-23 04:20:14 +0100
commit441e0998370bfd7b0de5dd9aed7e2abbcf64cf73 (patch)
treea977af24a78bded2c91e4f20da6d0388d99a5303 /ctdb
parentfad2b6b074495eb1dc036cce293456857985f8f5 (diff)
downloadsamba-441e0998370bfd7b0de5dd9aed7e2abbcf64cf73.tar.gz
samba-441e0998370bfd7b0de5dd9aed7e2abbcf64cf73.tar.xz
samba-441e0998370bfd7b0de5dd9aed7e2abbcf64cf73.zip
ctdb-tools-ctdb: Parse IP addresses when reading a list from a file
This way this logic is centralised. It also means that the IP address comparisons in the NAT gateway code are IPv6 safe. Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
Diffstat (limited to 'ctdb')
-rw-r--r--ctdb/tools/ctdb.c36
1 files changed, 15 insertions, 21 deletions
diff --git a/ctdb/tools/ctdb.c b/ctdb/tools/ctdb.c
index 58ac5e64d38..68d365bf789 100644
--- a/ctdb/tools/ctdb.c
+++ b/ctdb/tools/ctdb.c
@@ -813,7 +813,7 @@ static int control_pnn(struct ctdb_context *ctdb, int argc, const char **argv)
struct pnn_node {
struct pnn_node *next, *prev;
- const char *addr;
+ ctdb_sock_addr addr;
int pnn;
};
@@ -847,7 +847,14 @@ static struct pnn_node *read_pnn_node_file(TALLOC_CTX *mem_ctx,
}
pnn_node = talloc(mem_ctx, struct pnn_node);
pnn_node->pnn = pnn++;
- pnn_node->addr = talloc_strdup(pnn_node, node);
+
+ if (!parse_ip(node, NULL, 0, &pnn_node->addr)) {
+ DEBUG(DEBUG_ERR,
+ ("Invalid IP address '%s' in file %s\n",
+ node, file));
+ /* Caller will free mem_ctx */
+ return NULL;
+ }
DLIST_ADD_END(pnn_nodes, pnn_node, NULL);
}
@@ -894,15 +901,7 @@ static int control_xpnn(struct ctdb_context *ctdb, int argc, const char **argv)
}
for(pnn_node=pnn_nodes;pnn_node;pnn_node=pnn_node->next) {
- ctdb_sock_addr addr;
-
- if (parse_ip(pnn_node->addr, NULL, 63999, &addr) == 0) {
- DEBUG(DEBUG_ERR,("Wrongly formed ip address '%s' in nodes file\n", pnn_node->addr));
- talloc_free(mem_ctx);
- return -1;
- }
-
- if (ctdb_sys_have_ip(&addr)) {
+ if (ctdb_sys_have_ip(&pnn_node->addr)) {
printf("PNN:%d\n", pnn_node->pnn);
talloc_free(mem_ctx);
return 0;
@@ -1161,8 +1160,8 @@ filter_nodemap_by_addrs(struct ctdb_context *ctdb,
for (i = 0; i < nodemap->num; i++) {
for(n = nodes; n != NULL ; n = n->next) {
- if (!strcmp(n->addr,
- ctdb_addr_to_str(&nodemap->nodes[i].addr))) {
+ if (ctdb_same_ip(&n->addr,
+ &nodemap->nodes[i].addr)) {
break;
}
}
@@ -6127,16 +6126,11 @@ static int control_listnodes(struct ctdb_context *ctdb, int argc, const char **a
}
for(pnn_node=pnn_nodes;pnn_node;pnn_node=pnn_node->next) {
- ctdb_sock_addr addr;
- if (parse_ip(pnn_node->addr, NULL, 63999, &addr) == 0) {
- DEBUG(DEBUG_ERR,("Wrongly formed ip address '%s' in nodes file\n", pnn_node->addr));
- talloc_free(mem_ctx);
- return -1;
- }
+ const char *addr = ctdb_addr_to_str(&pnn_node->addr);
if (options.machinereadable){
- printf(":%d:%s:\n", pnn_node->pnn, pnn_node->addr);
+ printf(":%d:%s:\n", pnn_node->pnn, addr);
} else {
- printf("%s\n", pnn_node->addr);
+ printf("%s\n", addr);
}
}
talloc_free(mem_ctx);