From 10be299e7be05f2a19d82a0c80ef3af3ee0072fb Mon Sep 17 00:00:00 2001 From: Angus Salkeld Date: Mon, 27 Sep 2010 22:41:26 +0000 Subject: [PATCH] Check for a properly configured multicast address. git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@3057 fd59a12c-fef9-0310-b244-a6a79926bd2f --- exec/totemconfig.c | 4 ++++ exec/totemip.c | 18 ++++++++++++++++++ include/corosync/totem/totemip.h | 1 + 3 files changed, 23 insertions(+) diff --git a/exec/totemconfig.c b/exec/totemconfig.c index 381cf4fb..ad1b1166 100644 --- a/exec/totemconfig.c +++ b/exec/totemconfig.c @@ -453,6 +453,10 @@ int totem_config_validate ( error_reason = "Not all bind address belong to the same IP family"; 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; + } } } diff --git a/exec/totemip.c b/exec/totemip.c index f6613e89..d6bb34a9 100644 --- a/exec/totemip.c +++ b/exec/totemip.c @@ -123,6 +123,24 @@ void totemip_copy_endian_convert(struct totem_ip_address *addr1, 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 */ int totemip_compare(const void *a, const void *b) { diff --git a/include/corosync/totem/totemip.h b/include/corosync/totem/totemip.h index 9f45b5f9..e7f1d18d 100644 --- a/include/corosync/totem/totemip.h +++ b/include/corosync/totem/totemip.h @@ -68,6 +68,7 @@ struct totem_ip_address extern int totemip_equal(const struct totem_ip_address *addr1, const struct totem_ip_address *addr2); 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, const struct totem_ip_address *addr2); extern void totemip_copy_endian_convert(struct totem_ip_address *addr1,