LogoopenSUSE Build Service > Projects
Sign Up | Log In

View File cman_preconfig_allow_cman_to_configure_multicast_ttl.patch of Package cluster (Project home:sschapiro:openstack:upstream)

commit 14ff5606a01ff5b87d1fdbd785c969b523477a0f
Author: Fabio M. Di Nitto <fdinitto@redhat.com>
Date:   Tue Mar 15 08:22:02 2011 +0100

    cman-preconfig: allow cman to configure corosync multicast ttl
    
    syntax:
    
    <cman...>
     <multicast ttl=".."/>
    </cman>
    
    Resolves: rhbz#684020
    
    Acked-by: Christine Caulfield <ccaulfie@redhat.com>
    Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>

diff --git a/cman/daemon/cman-preconfig.c b/cman/daemon/cman-preconfig.c
index 4f98176..5a73fb3 100644
--- a/cman/daemon/cman-preconfig.c
+++ b/cman/daemon/cman-preconfig.c
@@ -289,7 +289,7 @@ static int add_udpu_members(struct objdb_iface_ver0 *objdb, hdb_handle_t interfa
 	return 0;
 }
 
-static int add_ifaddr(struct objdb_iface_ver0 *objdb, char *mcast, char *ifaddr, int port, enum tx_mech transport)
+static int add_ifaddr(struct objdb_iface_ver0 *objdb, char *mcast, char *ifaddr, int port, int ttl, enum tx_mech transport)
 {
 	hdb_handle_t totem_object_handle;
 	hdb_handle_t find_handle;
@@ -366,6 +366,19 @@ static int add_ifaddr(struct objdb_iface_ver0 *objdb, char *mcast, char *ifaddr,
 		objdb->object_key_create_typed(interface_object_handle, "mcastport",
 					       tmp, strlen(tmp)+1, OBJDB_VALUETYPE_STRING);
 
+		/* paranoia check. corosync already does it */
+		if ((ttl < 0) || (ttl > 255)) {
+			sprintf(error_reason, "TTL value (%u) out of range (0 - 255)", ttl);
+			return -1;
+		}
+
+		/* add the key to the objdb only if value is not default */
+		if (ttl != 1) {
+			sprintf(tmp, "%d", ttl);
+			objdb->object_key_create_typed(interface_object_handle, "ttl",
+						       tmp, strlen(tmp)+1, OBJDB_VALUETYPE_STRING);
+		}
+
 		num_interfaces++;
 	}
 	return ret;
@@ -608,6 +621,7 @@ static int get_nodename(struct objdb_iface_ver0 *objdb)
 	enum tx_mech transport = TX_MECH_UDP;
 	char *str;
 	int error;
+	unsigned int ttl = 1;
 
 	if (!getenv("CMAN_NOCONFIG")) {
 		/* our nodename */
@@ -677,6 +691,7 @@ static int get_nodename(struct objdb_iface_ver0 *objdb)
 			if (objdb->object_find_next(find_handle2, &mcast_handle) == 0) {
 
 				objdb_get_string(objdb, mcast_handle, "addr", &mcast_name);
+				objdb_get_int(objdb, mcast_handle, "ttl", &ttl, 0);
 			}
 			objdb->object_find_destroy(find_handle2);
 		}
@@ -743,7 +758,7 @@ static int get_nodename(struct objdb_iface_ver0 *objdb)
 		}
 	}
 
-	if (add_ifaddr(objdb, mcast_name, nodename, portnum, transport)) {
+	if (add_ifaddr(objdb, mcast_name, nodename, portnum, ttl, transport)) {
 		write_cman_pipe(error_reason);
 		return -1;
 	}
@@ -753,6 +768,7 @@ static int get_nodename(struct objdb_iface_ver0 *objdb)
 	objdb->object_find_create(node_object_handle,"altname", strlen("altname"), &find_handle);
 	while (objdb->object_find_next(find_handle, &alt_object) == 0) {
 		unsigned int port;
+		unsigned int altttl = 1;
 		char *node;
 		char *mcast;
 
@@ -762,11 +778,13 @@ static int get_nodename(struct objdb_iface_ver0 *objdb)
 
 		objdb_get_int(objdb, alt_object, "port", &port, portnum);
 
+		objdb_get_int(objdb, alt_object, "ttl", &altttl, ttl);
+
 		if (objdb_get_string(objdb, alt_object, "mcast", &mcast)) {
 			mcast = mcast_name;
 		}
 
-		if (add_ifaddr(objdb, mcast, node, portnum, transport)) {
+		if (add_ifaddr(objdb, mcast, node, portnum, altttl, transport)) {
 			write_cman_pipe(error_reason);
 			return -1;
 		}
diff --git a/config/tools/xml/cluster.rng.in b/config/tools/xml/cluster.rng.in
index 75bbd28..821fb82 100644
--- a/config/tools/xml/cluster.rng.in
+++ b/config/tools/xml/cluster.rng.in
@@ -147,14 +147,22 @@ To validate your cluster.conf against this schema, run:
          instead of using the multicast address generated by cman. If
          a user does not specify a multicast address, cman creates one. It
          forms the upper 16 bits of the multicast address with 239.192 and
-         forms the lower 16 bits based on the cluster ID."> <attribute
-         name="addr" rha:description="A multicast address specified
+         forms the lower 16 bits based on the cluster ID.">
+      <optional>
+       <attribute name="addr" rha:description="A multicast address specified
          by a user. If you do specify a multicast address, you should
          use the 239.192.x.x series that cman uses. Otherwise, using a
          multicast address outside that range may cause unpredictable
          results. For example, using 224.0.0.x (All hosts on the network)
          may not be routed correctly, or even routed at all by some
          hardware." rha:sample="239.192.0.1"/>
+      </optional>
+      <optional>
+       <attribute name="ttl" rha:description="Define the TTL (time to live) of
+         a multicast packets. Useful only if nodes are on different subnets and
+         a multicast router is available in between." rha:default="1"
+         rha:sample="24"/>
+      </optional>
      </element>
     </optional>
    </element>
@@ -734,6 +742,11 @@ To validate your cluster.conf against this schema, run:
       <attribute name="mcast" rha:description="The multicast address
           to use on the second interface. cman(5)"/>
      </optional>
+
+     <optional>
+      <attribute name="ttl" rha:description="The multicast TTL 
+          to use on the second interface. cman(5)"/>
+     </optional>
     </element>
    </optional>