Skip to content

Commit

Permalink
net/: There are many different checks for IPv6 multicast addresses. M…
Browse files Browse the repository at this point in the history
…ost of the checks are different. RFC 3513 clearly specifies how to detect an IPv6 multilcast address: they should begin with 0xffxx. I did not change some of the checks in ipv6_input.c, however. In that file, the comments indicate that the code should only pick of certain mulicast address that begin withi 0xff02.
  • Loading branch information
gregory-nutt committed Jun 23, 2018
1 parent 5db2f99 commit 5bb216f
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 18 deletions.
14 changes: 13 additions & 1 deletion include/nuttx/net/ip.h
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,19 @@ bool net_ipv6addr_maskcmp(const net_ipv6addr_t addr1,
* Name: net_is_addr_mcast
*
* Description:
* Is address a multicast address? see RFC 3513.
* Is address a multicast address? See RFC 3513:
*
* An IPv6 multicast address is an identifier for a group of interfaces
* (typically on different nodes). An interface may belong to any number
* of multicast groups. Multicast addresses have the following format:
*
* | 8 | 4 | 4 | 112 bits |
* +------ -+----+----+---------------------------------------------+
* |11111111|flgs|scop| group ID |
* +--------+----+----+---------------------------------------------+
*
* binary 11111111 at the start of the address identifies the address as
* being a multicast address.
*
****************************************************************************/

Expand Down
3 changes: 2 additions & 1 deletion net/icmpv6/icmpv6_solicit.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@
/****************************************************************************
* Private Data
****************************************************************************/
/* First 6 swords of the multi-cast address in network byte order */

/* First 6 hwords of the multi-cast address in network byte order */

static const uint16_t g_icmpv_mcastaddr[6] =
{
Expand Down
8 changes: 2 additions & 6 deletions net/netdev/netdev_findbyaddr.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,13 +300,9 @@ FAR struct net_driver_s *netdev_findby_ipv6addr(const net_ipv6addr_t lipaddr,
int ret;
#endif

/* First, check if this is the multicast IP address We should actually
* pick off certain multicast address (all hosts multicast address, and
* the solicited-node multicast address). We will cheat here and accept
* all multicast packets that are destined for the ff02::/16 addresses.
*/
/* First, check if this is the multicast IP address */

if (ripaddr[0] == HTONS(0xff02))
if (net_is_addr_mcast(ripaddr))
{
/* Yes.. Check the local, bound address. Is it INADDR_ANY? */

Expand Down
7 changes: 5 additions & 2 deletions net/sixlowpan/sixlowpan_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ int sixlowpan_nexthopaddr(FAR struct radio_driver_s *radio,
*
* 128 112 96 80 64 48 32 16
* ---- ---- ---- ---- ---- ---- ---- ----
* ff02 xxxx xxxx xxxx xxxx xxxx xxxx xxxx Multicast
* ffxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx Multicast address (RFC 3513)
* ff02 0000 0000 0000 0000 0000 0000 0001 All nodes multicast group
* xxxx 0000 0000 0000 0000 00ff fe00 xx00 1-byte short address IEEE 48-bit MAC
* xxxx 0000 0000 0000 0000 00ff fe00 xxxx 2-byte short address IEEE 48-bit MAC
Expand Down Expand Up @@ -274,7 +274,7 @@ int sixlowpan_destaddrfromip(FAR struct radio_driver_s *radio,

/* Check for a multicast address */

if (ipaddr[0] == HTONS(0xff02))
if (net_is_addr_mcast(ipaddr[0]))
{
DEBUGASSERT(radio->r_properties != NULL);
ret = radio->r_properties(radio, &properties);
Expand All @@ -299,6 +299,9 @@ int sixlowpan_destaddrfromip(FAR struct radio_driver_s *radio,
memcpy(destaddr, &properties.sp_bcast,
sizeof(struct netdev_varaddr_s));
}

/* Some other RFC 3513 multicast address */

else
{
memcpy(destaddr, &properties.sp_mcast,
Expand Down
9 changes: 1 addition & 8 deletions net/udp/udp_finddev.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,16 +193,9 @@ FAR struct net_driver_s *udp_find_raddr_device(FAR struct udp_conn_s *conn)
/* Check if the remote, destination address is a multicast
* address. If this is the case, select the device
* using the locally bound address (assuming that there is one).
*
* The general form of all well-known, reserved IPv6 multicast
* addresses is: ff0x::xx/16 (which includes most, but not all
* possible multicast addresses).
*/

if ((conn->u.ipv6.raddr[0] & HTONS(0xfff0)) == HTONS(0xff00) &&
conn->u.ipv6.raddr[1] == 0 && conn->u.ipv6.raddr[2] == 0 &&
conn->u.ipv6.raddr[3] == 0 && conn->u.ipv6.raddr[4] == 0 &&
conn->u.ipv6.raddr[5] == 0 && conn->u.ipv6.raddr[6] == 0)
if (net_is_addr_mcast(conn->u.ipv6.raddr))
{
/* Make sure that the socket is bound to some non-zero, local
* address. Zero is used as an indication that the laddr is
Expand Down

0 comments on commit 5bb216f

Please sign in to comment.