Explorar o código

Check for a properly configured multicast address.

git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@3057 fd59a12c-fef9-0310-b244-a6a79926bd2f
Angus Salkeld %!s(int64=15) %!d(string=hai) anos
pai
achega
10be299e7b
Modificáronse 3 ficheiros con 23 adicións e 0 borrados
  1. 4 0
      exec/totemconfig.c
  2. 18 0
      exec/totemip.c
  3. 1 0
      include/corosync/totem/totemip.h

+ 4 - 0
exec/totemconfig.c

@@ -453,6 +453,10 @@ int totem_config_validate (
 				error_reason =  "Not all bind address belong to the same IP family";
 				error_reason =  "Not all bind address belong to the same IP family";
 				goto parse_error;
 				goto parse_error;
 			}
 			}
+			if (totemip_is_mcast (&totem_config->interfaces[i].mcast_addr) != 0) {
+				error_reason = "mcastaddr is not a correct multicast address.";
+				goto parse_error;
+			}
 		}
 		}
 	}
 	}
 
 

+ 18 - 0
exec/totemip.c

@@ -123,6 +123,24 @@ void totemip_copy_endian_convert(struct totem_ip_address *addr1,
 	memcpy(addr1->addr, addr2->addr, TOTEMIP_ADDRLEN);
 	memcpy(addr1->addr, addr2->addr, TOTEMIP_ADDRLEN);
 }
 }
 
 
+/*
+ * Multicast address range is 224.0.0.0 to 239.255.255.255 this
+ * translates to the first 4 bits == 1110 (0xE).
+ * http://en.wikipedia.org/wiki/Multicast_address
+ */
+int32_t totemip_is_mcast(struct totem_ip_address *ip_addr)
+{
+	uint32_t addr = 0;
+
+	if (ip_addr->family == AF_INET) {
+		addr = ntohl(*(int32_t*)ip_addr->addr);
+		if ((addr >> 28) != 0xE) {
+			return -1;
+		}
+	}
+	return 0;
+}
+
 /* For sorting etc. params are void * for qsort's benefit */
 /* For sorting etc. params are void * for qsort's benefit */
 int totemip_compare(const void *a, const void *b)
 int totemip_compare(const void *a, const void *b)
 {
 {

+ 1 - 0
include/corosync/totem/totemip.h

@@ -68,6 +68,7 @@ struct totem_ip_address
 extern int totemip_equal(const struct totem_ip_address *addr1,
 extern int totemip_equal(const struct totem_ip_address *addr1,
 			 const struct totem_ip_address *addr2);
 			 const struct totem_ip_address *addr2);
 extern int totemip_compare(const void *a, const void *b);
 extern int totemip_compare(const void *a, const void *b);
+extern int totemip_is_mcast(struct totem_ip_address *addr);
 extern void totemip_copy(struct totem_ip_address *addr1,
 extern void totemip_copy(struct totem_ip_address *addr1,
 			 const struct totem_ip_address *addr2);
 			 const struct totem_ip_address *addr2);
 extern void totemip_copy_endian_convert(struct totem_ip_address *addr1,
 extern void totemip_copy_endian_convert(struct totem_ip_address *addr1,