Check for a properly configured multicast address.

git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@3057 fd59a12c-fef9-0310-b244-a6a79926bd2f
This commit is contained in:
Angus Salkeld 2010-09-27 22:41:26 +00:00
parent a166db335b
commit 10be299e7b
3 changed files with 23 additions and 0 deletions

View File

@ -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;
}
}
}

View File

@ -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)
{

View File

@ -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,