[Sheepdog] Small sheepdog howto

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Tue Jan 26 07:09:44 CET 2010


Hi,

On 2010/01/26 1:30, PCextreme B.V. - Wido den Hollander wrote:
> Hi,
> 
> root at wido-desktop:~# corosync-cfgtool -s
> Printing ring status.
> Local node ID 537307328
> RING ID 0
> 	id	= 192.168.6.32
> 	status	= ring 0 active with no faults
> root at wido-desktop:~# 

Your corosync seems to work right.
The problem is that the collie fails to get the local ip address.

Could you try the following patch?

==
From: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
Date: Tue, 26 Jan 2010 14:33:02 +0900
Subject: [PATCH] collie: avoid using an invalid address

Some distributions contain `127.0.1.1' in /etc/hosts.
We avoid using these kind of invalid addresses.

Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 collie/group.c |   46 +++++++++++++++++++++++++++++++++-------------
 1 files changed, 33 insertions(+), 13 deletions(-)

diff --git a/collie/group.c b/collie/group.c
index cbb4761..676706d 100644
--- a/collie/group.c
+++ b/collie/group.c
@@ -728,7 +728,7 @@ struct cluster_info *create_cluster(int port)
 	int fd, ret;
 	cpg_handle_t cpg_handle;
 	struct cluster_info *ci;
-	struct addrinfo hints, *res;
+	struct addrinfo hints, *res, *res0;
 	char name[INET6_ADDRSTRLEN];
 	struct cpg_name group = { 8, "sheepdog" };
 	cpg_callbacks_t cb = { &sd_deliver, &sd_confch };
@@ -782,23 +782,43 @@ join_retry:
 	memset(&hints, 0, sizeof(hints));

 	hints.ai_socktype = SOCK_STREAM;
-	ret = getaddrinfo(name, NULL, &hints, &res);
+	ret = getaddrinfo(name, NULL, &hints, &res0);
 	if (ret)
 		exit(1);

-	if (res->ai_family == AF_INET) {
-		struct sockaddr_in *addr = (struct sockaddr_in *)res->ai_addr;
-		memset(ci->this_node.addr, 0, sizeof(ci->this_node.addr));
-		memcpy(ci->this_node.addr + 12, &addr->sin_addr, 4);
-	} else if (res->ai_family == AF_INET6) {
-		struct sockaddr_in6 *addr = (struct sockaddr_in6 *)res->ai_addr;
-		memcpy(ci->this_node.addr, &addr->sin6_addr, 16);
-	} else {
-		eprintf("unknown address family\n");
-		exit(1);
+	for (res = res0; res; res = res->ai_next) {
+		if (res->ai_family == AF_INET) {
+			struct sockaddr_in *addr;
+			addr = (struct sockaddr_in *)res->ai_addr;
+
+			if (((char *) &addr->sin_addr)[0] == 127)
+				continue;
+
+			memset(ci->this_node.addr, 0, 12);
+			memcpy(ci->this_node.addr + 12, &addr->sin_addr, 4);
+			break;
+		} else if (res->ai_family == AF_INET6) {
+			struct sockaddr_in6 *addr;
+			uint8_t localhost[16] = { 0, 0, 0, 0, 0, 0, 0, 0,
+						  0, 0, 0, 0, 0, 0, 0, 1 };
+
+			addr = (struct sockaddr_in6 *)res->ai_addr;
+
+			if (memcmp(&addr->sin6_addr, localhost, 16) == 0)
+				continue;
+
+			memcpy(ci->this_node.addr, &addr->sin6_addr, 16);
+			break;
+		} else
+			dprintf("unknown address family\n");
+	}
+
+	if (res == NULL) {
+		eprintf("failed to get address info\n");
+		return NULL;
 	}

-	freeaddrinfo(res);
+	freeaddrinfo(res0);

 	ci->this_node.port = port;

-- 
1.6.5



More information about the sheepdog mailing list