From 9e73dc87ccfbb148af4cd83ae1415fcb7b6e2f23 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Mon, 26 Nov 2007 10:52:55 +1100 Subject: Add a --node-ip argument so that one can specify which ip address a specific instance of ctdbd should bind to. This helps when running a "virtual" cluster on a single machine where all instcances bind to different alias interfaces. If --node-ip is specified, then we will only try to bind to this ip address only. Othervise we fall back to the original method trying the ip addresses in /etc/ctdb/nodes one by one until we find one we can bind to. No variable in /etc/sysconfig/ctdb added since this parameter only makes sense in a virtual test/debug cluster. (This used to be ctdb commit d96cb02c2c24f9eabbc53d3d38e90dea49cff3e0) --- ctdb/tcp/tcp_connect.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'ctdb/tcp') 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;nodeidnum_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;inum_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; -- cgit v1.2.1