Steven Dake wrote:
> Instead of specifying mcastaddr, broadcast: yes can be set in
> openais.conf to allow openais to use the broadcast address instead of a
> multicast address.
> 


This patch ports almost effortlessly to corosync. And it works too :-)


Chrissie
Index: include/corosync/totem/totem.h
===================================================================
--- include/corosync/totem/totem.h	(revision 2199)
+++ include/corosync/totem/totem.h	(working copy)
@@ -155,6 +155,8 @@
 
 	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;
 
Index: exec/totemnet.c
===================================================================
--- exec/totemnet.c	(revision 2199)
+++ exec/totemnet.c	(working copy)
@@ -1545,30 +1545,45 @@
 	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);
+	if (instance->totem_config->broadcast_use == 1) {
+		unsigned int broadcast = 1;
+
+		if ((setsockopt(sockets->mcast_recv, SOL_SOCKET,
+			SO_BROADCAST, &broadcast, sizeof (broadcast))) == -1) {
+			perror("setting broadcast option");
+			exit(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 ((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);
+			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;
 	}
 
 	/*
Index: exec/totemconfig.c
===================================================================
--- exec/totemconfig.c	(revision 2199)
+++ exec/totemconfig.c	(working copy)
@@ -351,7 +351,18 @@
 		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 @@
 			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;
+			}
 		}
 	}
 
Index: man/corosync.conf.5
===================================================================
--- man/corosync.conf.5	(revision 2199)
+++ man/corosync.conf.5	(working copy)
@@ -91,6 +91,12 @@
 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
 should work for most networks, but the network administrator should be queried
_______________________________________________
Openais mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/openais

Reply via email to