Parcourir la source

Add broadcast option to corosync

This is a forward port of the openais, whitetank, code.



git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@2202 fd59a12c-fef9-0310-b244-a6a79926bd2f
Christine Caulfield il y a 16 ans
Parent
commit
5d8178f485
4 fichiers modifiés avec 65 ajouts et 29 suppressions
  1. 20 7
      exec/totemconfig.c
  2. 37 22
      exec/totemnet.c
  3. 2 0
      include/corosync/totem/totem.h
  4. 6 0
      man/corosync.conf.5

+ 20 - 7
exec/totemconfig.c

@@ -351,6 +351,17 @@ printf ("couldn't find totem handle\n");
 		if (!objdb_get_string (objdb, object_interface_handle, "mcastaddr", &str)) {
 			res = totemip_parse (&totem_config->interfaces[ringnumber].mcast_addr, str, 0);
 		}
+		totem_config->broadcast_use = 0;
+		if (!objdb_get_string (objdb, object_interface_handle, "broadcast", &str)) {
+			if (strcmp (str, "yes") == 0) {
+				totem_config->broadcast_use = 1;
+				totemip_parse (
+					&totem_config->interfaces[ringnumber].mcast_addr,
+					"255.255.255.255", 0);
+			}
+			
+
+		}
 
 		/*
 		 * Get mcast port
@@ -413,14 +424,16 @@ int totem_config_validate (
 			goto parse_error;
 		}
 
-		if (totem_config->interfaces[i].mcast_addr.family != totem_config->interfaces[i].bindnet.family) {
-			error_reason = "Multicast address family does not match bind address family";
-			goto parse_error;
-		}
+		if (totem_config->broadcast_use == 0) {
+			if (totem_config->interfaces[i].mcast_addr.family != totem_config->interfaces[i].bindnet.family) {
+				error_reason = "Multicast address family does not match bind address family";
+				goto parse_error;
+			}
 
-		if (totem_config->interfaces[i].mcast_addr.family != totem_config->interfaces[i].bindnet.family) {
-			error_reason =  "Not all bind address belong to the same IP family";
-			goto parse_error;
+			if (totem_config->interfaces[i].mcast_addr.family != totem_config->interfaces[i].bindnet.family) {
+				error_reason =  "Not all bind address belong to the same IP family";
+				goto parse_error;
+			}
 		}
 	}
 

+ 37 - 22
exec/totemnet.c

@@ -1545,30 +1545,45 @@ static int totemnet_build_sockets_ip (
 	totemip_totemip_to_sockaddr_convert(mcast_address, instance->totem_interface->ip_port, &mcast_ss, &addrlen);
 	totemip_totemip_to_sockaddr_convert(bound_to, instance->totem_interface->ip_port, &boundto_ss, &addrlen);
 
-	switch ( bindnet_address->family ) {
-		case AF_INET:
-		memset(&mreq, 0, sizeof(mreq));
-		mreq.imr_multiaddr.s_addr = mcast_sin->sin_addr.s_addr;
-		mreq.imr_interface.s_addr = boundto_sin->sin_addr.s_addr;
-		res = setsockopt (sockets->mcast_recv, IPPROTO_IP, IP_ADD_MEMBERSHIP,
-			&mreq, sizeof (mreq));
-		if (res == -1) {
-			perror ("join ipv4 multicast group failed");
-			return (-1);
-		}
-		break;
-		case AF_INET6:
-		memset(&mreq6, 0, sizeof(mreq6));
-		memcpy(&mreq6.ipv6mr_multiaddr, &mcast_sin6->sin6_addr, sizeof(struct in6_addr));
-		mreq6.ipv6mr_interface = interface_num;
+	if (instance->totem_config->broadcast_use == 1) {
+		unsigned int broadcast = 1;
 
-		res = setsockopt (sockets->mcast_recv, IPPROTO_IPV6, IPV6_JOIN_GROUP,
-			&mreq6, sizeof (mreq6));
-		if (res == -1) {
-			perror ("join ipv6 multicast group failed");
-			return (-1);
+		if ((setsockopt(sockets->mcast_recv, SOL_SOCKET,
+			SO_BROADCAST, &broadcast, sizeof (broadcast))) == -1) {
+			perror("setting broadcast option");
+			exit(1);
+		}
+		if ((setsockopt(sockets->mcast_send, SOL_SOCKET,
+			SO_BROADCAST, &broadcast, sizeof (broadcast))) == -1) {
+			perror("setting broadcast option");
+			exit(1);
+		}
+	} else {
+		switch (bindnet_address->family) {
+			case AF_INET:
+			memset(&mreq, 0, sizeof(mreq));
+			mreq.imr_multiaddr.s_addr = mcast_sin->sin_addr.s_addr;
+			mreq.imr_interface.s_addr = boundto_sin->sin_addr.s_addr;
+			res = setsockopt (sockets->mcast_recv, IPPROTO_IP, IP_ADD_MEMBERSHIP,
+				&mreq, sizeof (mreq));
+			if (res == -1) {
+				perror ("join ipv4 multicast group failed");
+				return (-1);
+			}
+			break;
+			case AF_INET6:
+			memset(&mreq6, 0, sizeof(mreq6));
+			memcpy(&mreq6.ipv6mr_multiaddr, &mcast_sin6->sin6_addr, sizeof(struct in6_addr));
+			mreq6.ipv6mr_interface = interface_num;
+
+			res = setsockopt (sockets->mcast_recv, IPPROTO_IPV6, IPV6_JOIN_GROUP,
+				&mreq6, sizeof (mreq6));
+			if (res == -1) {
+				perror ("join ipv6 multicast group failed");
+				return (-1);
+			}
+			break;
 		}
-		break;
 	}
 
 	/*

+ 2 - 0
include/corosync/totem/totem.h

@@ -155,6 +155,8 @@ struct totem_config {
 
 	const char *vsf_type;
 
+	unsigned int broadcast_use;
+
 	enum { TOTEM_CRYPTO_SOBER=0, TOTEM_CRYPTO_NSS } crypto_type;
 	enum { TOTEM_CRYPTO_ACCEPT_OLD=0, TOTEM_CRYPTO_ACCEPT_NEW } crypto_accept;
 

+ 6 - 0
man/corosync.conf.5

@@ -90,6 +90,12 @@ selection of the network interface within a specific subnet as with IPv4.
 
 If IPv6 networking is used, the nodeid field must be specified.
 
+.TP
+broadcast
+This is optional and can be set to yes.  If it is set to yes, the broadcast
+address will be used for communication.  If this option is set, mcastaddr
+should not be set.
+
 .TP
 mcastaddr
 This is the multicast address used by corosync executive.  The default