[SCM] CTDB repository - branch ipv6-test updated - 2f8b33948e395228cbac3450c0c684e49069abf0

Ronnie Sahlberg sahlberg at samba.org
Wed Aug 20 02:28:36 GMT 2008


The branch, ipv6-test has been updated
       via  2f8b33948e395228cbac3450c0c684e49069abf0 (commit)
       via  1157d61a0bc557d8ffc453c518dfc48473492bfd (commit)
       via  b0fe4c45fc5ba1ecf62ebb921092c8a34e28a2bd (commit)
      from  6da7b36b7ccc4ee9b809867ea32036f09a801bb3 (commit)

http://gitweb.samba.org/?p=sahlberg/ctdb.git;a=shortlog;h=ipv6-test


- Log -----------------------------------------------------------------
commit 2f8b33948e395228cbac3450c0c684e49069abf0
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Wed Aug 20 12:02:54 2008 +1000

    we must canonicalize the sockaddr structures in killtcp so that we do the necessary downgrade if required

commit 1157d61a0bc557d8ffc453c518dfc48473492bfd
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Wed Aug 20 11:58:27 2008 +1000

    make the function to canonicalize a sockaddr structure public

commit b0fe4c45fc5ba1ecf62ebb921092c8a34e28a2bd
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Wed Aug 20 11:52:36 2008 +1000

    when we compare ip addresses in ctdb_same_ip we must first canonicalize the addresses  so that we realize that 127.0.0.1:22 is really the same thing as ::ffff:127.0.0.1:22
    
    Downgrade all AF_INET6 ::ffff:xxxx:xxxx sockaddresses into AF_INET ones

-----------------------------------------------------------------------

Summary of changes:
 common/ctdb_util.c     |   40 +++++++++++++++++++++++++++++++++-------
 include/ctdb.h         |    1 -
 include/ctdb_private.h |    2 ++
 server/ctdb_takeover.c |   18 +++++++++++-------
 4 files changed, 46 insertions(+), 15 deletions(-)


Changeset truncated at 500 lines:

diff --git a/common/ctdb_util.c b/common/ctdb_util.c
index 2023836..792ff3c 100644
--- a/common/ctdb_util.c
+++ b/common/ctdb_util.c
@@ -502,21 +502,47 @@ bool parse_ip_mask(const char *str, ctdb_sock_addr *addr, unsigned *mask)
 	return ret;
 }
 
-bool ctdb_same_ip(const ctdb_sock_addr *ip1, const ctdb_sock_addr *ip2)
+/*
+   This is used to canonicalize a ctdb_sock_addr structure.
+*/
+void ctdb_canonicalize_ip(const ctdb_sock_addr *ip, ctdb_sock_addr *cip)
 {
-	if (ip1->sa.sa_family != ip2->sa.sa_family) {
+	char prefix[12] = { 0,0,0,0,0,0,0,0,0,0,0xff,0xff };
+
+	memcpy(cip, ip, sizeof (*cip));
+
+	if ( (ip->sa.sa_family == AF_INET6)
+	&& !memcmp(&ip->ip6.sin6_addr, prefix, 12)) {
+		memset(cip, 0, sizeof(*cip));
+#ifdef HAVE_SOCK_SIN_LEN
+		cip->ip.sin_len = sizeof(*cip);
+#endif
+		cip->ip.sin_family = AF_INET;
+		cip->ip.sin_port   = ip->ip6.sin6_port;
+		memcpy(&cip->ip.sin_addr, &ip->ip6.sin6_addr.s6_addr32[3], 4);
+	}
+}
+
+bool ctdb_same_ip(const ctdb_sock_addr *tip1, const ctdb_sock_addr *tip2)
+{
+	ctdb_sock_addr ip1, ip2;
+
+	ctdb_canonicalize_ip(tip1, &ip1);
+	ctdb_canonicalize_ip(tip2, &ip2);
+	
+	if (ip1.sa.sa_family != ip2.sa.sa_family) {
 		return false;
 	}
 
-	switch (ip1->sa.sa_family) {
+	switch (ip1.sa.sa_family) {
 	case AF_INET:
-		return ip1->ip.sin_addr.s_addr == ip2->ip.sin_addr.s_addr;
+		return ip1.ip.sin_addr.s_addr == ip2.ip.sin_addr.s_addr;
 	case AF_INET6:
-		return !memcmp(&ip1->ip6.sin6_addr.s6_addr[0],
-				&ip2->ip6.sin6_addr.s6_addr[0],
+		return !memcmp(&ip1.ip6.sin6_addr.s6_addr[0],
+				&ip2.ip6.sin6_addr.s6_addr[0],
 				16);
 	default:
-		DEBUG(DEBUG_ERR, (__location__ " CRITICAL Can not compare sockaddr structures of type %u\n", ip1->sa.sa_family));
+		DEBUG(DEBUG_ERR, (__location__ " CRITICAL Can not compare sockaddr structures of type %u\n", ip1.sa.sa_family));
 		return false;
 	}
 
diff --git a/include/ctdb.h b/include/ctdb.h
index c6f2574..d43ab50 100644
--- a/include/ctdb.h
+++ b/include/ctdb.h
@@ -566,5 +566,4 @@ int ctdb_transaction_store(struct ctdb_transaction_handle *h,
 			   TDB_DATA key, TDB_DATA data);
 int ctdb_transaction_commit(struct ctdb_transaction_handle *h);
 
-
 #endif
diff --git a/include/ctdb_private.h b/include/ctdb_private.h
index f73f9ef..8834ec4 100644
--- a/include/ctdb_private.h
+++ b/include/ctdb_private.h
@@ -1376,5 +1376,7 @@ int32_t ctdb_control_trans2_error(struct ctdb_context *ctdb,
 				  struct ctdb_req_control *c);
 
 char *ctdb_addr_to_str(ctdb_sock_addr *addr);
+void ctdb_canonicalize_ip(const ctdb_sock_addr *ip, ctdb_sock_addr *cip);
+
 
 #endif
diff --git a/server/ctdb_takeover.c b/server/ctdb_takeover.c
index 5458190..b33471d 100644
--- a/server/ctdb_takeover.c
+++ b/server/ctdb_takeover.c
@@ -1453,21 +1453,25 @@ static void *add_killtcp_callback(void *parm, void *data)
   add a tcp socket to the list of connections we want to RST
  */
 static int ctdb_killtcp_add_connection(struct ctdb_context *ctdb, 
-				       ctdb_sock_addr *src,
-				       ctdb_sock_addr *dst)
+				       ctdb_sock_addr *s,
+				       ctdb_sock_addr *d)
 {
+	ctdb_sock_addr src, dst;
 	struct ctdb_kill_tcp *killtcp;
 	struct ctdb_killtcp_con *con;
 	struct ctdb_vnn *vnn;
 
-	vnn = find_public_ip_vnn(ctdb, dst);
+	ctdb_canonicalize_ip(s, &src);
+	ctdb_canonicalize_ip(d, &dst);
+
+	vnn = find_public_ip_vnn(ctdb, &dst);
 	if (vnn == NULL) {
-		vnn = find_public_ip_vnn(ctdb, src);
+		vnn = find_public_ip_vnn(ctdb, &src);
 	}
 	if (vnn == NULL) {
 		/* if it is not a public ip   it could be our 'single ip' */
 		if (ctdb->single_ip_vnn) {
-			if (ctdb_same_ip(&ctdb->single_ip_vnn->public_address, dst)) {
+			if (ctdb_same_ip(&ctdb->single_ip_vnn->public_address, &dst)) {
 				vnn = ctdb->single_ip_vnn;
 			}
 		}
@@ -1502,8 +1506,8 @@ static int ctdb_killtcp_add_connection(struct ctdb_context *ctdb,
 	*/
 	con = talloc(killtcp, struct ctdb_killtcp_con);
 	CTDB_NO_MEMORY(ctdb, con);
-	con->src_addr = *src;
-	con->dst_addr = *dst;
+	con->src_addr = src;
+	con->dst_addr = dst;
 	con->count    = 0;
 	con->killtcp  = killtcp;
 


-- 
CTDB repository


More information about the samba-cvs mailing list