Rev 70: merge from ronnie in http://samba.org/~tridge/ctdb

tridge at samba.org tridge at samba.org
Thu Apr 5 23:46:45 GMT 2007


------------------------------------------------------------
revno: 70
revision-id: tridge at samba.org-20070405234645-d4e331dc0077c3ed
parent: tridge at samba.org-20070405031906-a9920c6dd34b2138
parent: ronniesahlberg at gmail.com-20070405230841-qvbelakbhbpl1za4
committer: Andrew Tridgell <tridge at samba.org>
branch nick: tridge
timestamp: Fri 2007-04-06 09:46:45 +1000
message:
  merge from ronnie
modified:
  tcp/tcp_connect.c              tcp_connect.c-20061128004937-x70q1cu5xzg5g2tm-1
    ------------------------------------------------------------
    merged: ronniesahlberg at gmail.com-20070405230841-qvbelakbhbpl1za4
    parent: ronniesahlberg at gmail.com-20070404111556-vc1hky229by8leu1
    committer: Ronnie sahlberg <ronniesahlberg at gmail.com>
    branch nick: ctdb
    timestamp: Fri 2007-04-06 09:08:41 +1000
    message:
      When we create a tcp connection to a remote ctdb node  do an explicit bind() to set our source side to the same ip address as we use to listen to ctdb traffic.
      
      We need this since there is no guarantee that INADDR_ANY (which would be defaulted to if we dont bind) would be routable from the remote host.
      This is entirely possible to happen since CTDB traffic is likely to be isolated to a private non-routable network.
=== modified file 'tcp/tcp_connect.c'
--- a/tcp/tcp_connect.c	2007-02-20 03:57:13 +0000
+++ b/tcp/tcp_connect.c	2007-04-05 23:08:41 +0000
@@ -98,6 +98,7 @@
 	struct ctdb_tcp_node *tnode = talloc_get_type(node->private, 
 						      struct ctdb_tcp_node);
 	struct ctdb_context *ctdb = node->ctdb;
+        struct sockaddr_in sock_in;
         struct sockaddr_in sock_out;
 
 	tnode->fd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
@@ -109,7 +110,21 @@
 	}
 	sock_out.sin_port = htons(node->address.port);
 	sock_out.sin_family = PF_INET;
-	
+
+
+	/* Bind our side of the socketpair to the same address we use to listen
+	 * on incoming CTDB traffic.
+	 * We must specify this address to make sure that the address we expose to
+	 * the remote side is actually routable in case CTDB traffic will run on
+	 * a dedicated non-routeable network.
+	 */
+	if (ctdb_tcp_get_address(ctdb, ctdb->address.address, &sock_in.sin_addr) != 0) {
+		return;
+	}
+	sock_in.sin_port = htons(0); /* INPORT_ANY is not always available */
+	sock_in.sin_family = PF_INET;
+	bind(tnode->fd, (struct sockaddr *)&sock_in, sizeof(sock_in));
+
 	if (connect(tnode->fd, (struct sockaddr *)&sock_out, sizeof(sock_out)) != 0 &&
 	    errno != EINPROGRESS) {
 		/* try again once a second */



More information about the samba-cvs mailing list