diff options
-rw-r--r-- | ctdb/include/ctdb.h | 6 | ||||
-rw-r--r-- | ctdb/include/ctdb_private.h | 1 | ||||
-rw-r--r-- | ctdb/server/ctdb_server.c | 17 | ||||
-rw-r--r-- | ctdb/server/ctdbd.c | 16 | ||||
-rw-r--r-- | ctdb/tcp/tcp_connect.c | 26 |
5 files changed, 56 insertions, 10 deletions
diff --git a/ctdb/include/ctdb.h b/ctdb/include/ctdb.h index b3a65a36ab2..a2245d220b8 100644 --- a/ctdb/include/ctdb.h +++ b/ctdb/include/ctdb.h @@ -160,6 +160,12 @@ int ctdb_set_socketname(struct ctdb_context *ctdb, const char *socketname); int ctdb_set_nlist(struct ctdb_context *ctdb, const char *nlist); /* + Check that a specific ip address exists in the node list and returns + the id for the node or -1 +*/ +int ctdb_ip_to_nodeid(struct ctdb_context *ctdb, const char *nodeip); + +/* start the ctdb protocol */ int ctdb_start(struct ctdb_context *ctdb); diff --git a/ctdb/include/ctdb_private.h b/ctdb/include/ctdb_private.h index cb76bb0074c..10abafa1d93 100644 --- a/ctdb/include/ctdb_private.h +++ b/ctdb/include/ctdb_private.h @@ -367,6 +367,7 @@ struct ctdb_context { const char *default_public_interface; pid_t recoverd_pid; bool done_startup; + const char *node_ip; }; struct ctdb_db_context { diff --git a/ctdb/server/ctdb_server.c b/ctdb/server/ctdb_server.c index dddf90753bd..2a80798dd93 100644 --- a/ctdb/server/ctdb_server.c +++ b/ctdb/server/ctdb_server.c @@ -35,6 +35,23 @@ int ctdb_set_transport(struct ctdb_context *ctdb, const char *transport) } /* + Check whether an ip is a valid node ip + Returns the node id for this ip address or -1 +*/ +int ctdb_ip_to_nodeid(struct ctdb_context *ctdb, const char *nodeip) +{ + int nodeid; + + for (nodeid=0;nodeid<ctdb->num_nodes;nodeid++) { + if (!strcmp(ctdb->nodes[nodeid]->address.address, nodeip)) { + return nodeid; + } + } + + return -1; +} + +/* choose the recovery lock file */ int ctdb_set_recovery_lock_file(struct ctdb_context *ctdb, const char *file) diff --git a/ctdb/server/ctdbd.c b/ctdb/server/ctdbd.c index eaf79a0ed7d..ba0eac42fb8 100644 --- a/ctdb/server/ctdbd.c +++ b/ctdb/server/ctdbd.c @@ -50,6 +50,7 @@ static struct { const char *db_dir_persistent; const char *public_interface; const char *single_public_ip; + const char *node_ip; int no_setsched; } options = { .nlist = ETCDIR "/ctdb/nodes", @@ -110,6 +111,7 @@ int main(int argc, const char *argv[]) { "event-script-dir", 0, POPT_ARG_STRING, &options.event_script_dir, 0, "event script directory", "dirname" }, { "logfile", 0, POPT_ARG_STRING, &options.logfile, 0, "log file location", "filename" }, { "nlist", 0, POPT_ARG_STRING, &options.nlist, 0, "node list file", "filename" }, + { "node-ip", 0, POPT_ARG_STRING, &options.node_ip, 0, "node ip", "ip-address"}, { "listen", 0, POPT_ARG_STRING, &options.myaddress, 0, "address to listen on", "address" }, { "transport", 0, POPT_ARG_STRING, &options.transport, 0, "protocol transport", NULL }, { "dbdir", 0, POPT_ARG_STRING, &options.db_dir, 0, "directory for the tdb files", NULL }, @@ -198,6 +200,20 @@ int main(int argc, const char *argv[]) exit(1); } + /* if a node-ip was specified, verify that it exists in the + nodes file + */ + if (options.node_ip != NULL) { + DEBUG(0,("IP for this node is %s\n", options.node_ip)); + ret = ctdb_ip_to_nodeid(ctdb, options.node_ip); + if (ret == -1) { + DEBUG(0,("The specified node-ip:%s is not a valid node address. Exiting.\n", options.node_ip)); + exit(1); + } + ctdb->node_ip = options.node_ip; + DEBUG(0,("This is node %d\n", ret)); + } + if (options.db_dir) { ret = ctdb_set_tdb_dir(ctdb, options.db_dir); if (ret == -1) { diff --git a/ctdb/tcp/tcp_connect.c b/ctdb/tcp/tcp_connect.c index 3548f82ed70..3c4e7bfb10d 100644 --- a/ctdb/tcp/tcp_connect.c +++ b/ctdb/tcp/tcp_connect.c @@ -214,13 +214,9 @@ static void ctdb_listen_event(struct event_context *ev, struct fd_event *fde, if (fd == -1) return; incoming_node = inet_ntoa(addr.sin_addr); - for (nodeid=0;nodeid<ctdb->num_nodes;nodeid++) { - if (!strcmp(incoming_node, ctdb->nodes[nodeid]->address.address)) { - DEBUG(0, ("Incoming connection from node:%d %s\n",nodeid,incoming_node)); - break; - } - } - if (nodeid>=ctdb->num_nodes) { + nodeid = ctdb_ip_to_nodeid(ctdb, incoming_node); + + if (nodeid == -1) { DEBUG(0, ("Refused connection from unknown node %s\n", incoming_node)); close(fd); return; @@ -275,17 +271,27 @@ static int ctdb_tcp_listen_automatic(struct ctdb_context *ctdb) } for (i=0;i<ctdb->num_nodes;i++) { + /* if node_ip is specified we will only try to bind to that + ip. + */ + if (ctdb->node_ip != NULL) { + if (strcmp(ctdb->node_ip, ctdb->nodes[i]->address.address)) { + continue; + } + } + ZERO_STRUCT(sock); #ifdef HAVE_SOCK_SIN_LEN sock.sin_len = sizeof(sock); #endif sock.sin_port = htons(ctdb->nodes[i]->address.port); sock.sin_family = PF_INET; - if (ctdb_tcp_get_address(ctdb, ctdb->nodes[i]->address.address, - &sock.sin_addr) != 0) { + if (ctdb_tcp_get_address(ctdb, + ctdb->nodes[i]->address.address, + &sock.sin_addr) != 0) { continue; } - + if (bind(ctcp->listen_fd, (struct sockaddr * )&sock, sizeof(sock)) == 0) { break; |