mirror of
https://github.com/apache/nuttx.git
synced 2026-06-07 01:05:54 +08:00
Add support for multicast MAC addresses
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@2784 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
+1
-1
@@ -82,7 +82,7 @@ endif
|
||||
|
||||
ifeq ($(CONFIG_NET_IGMP),y)
|
||||
UIP_CSRCS += uip_igmpinit.c uip_igmpgroup.c uip_igmpinput.c uip_igmpjoin.c \
|
||||
uip_igmpleave.c uip_igmpmsg.c uip_igmptimer.c
|
||||
uip_igmpleave.c uip_igmpmsg.c uip_igmptimer.c uip_mcastmac.c
|
||||
endif
|
||||
|
||||
endif
|
||||
|
||||
+2
-2
@@ -140,7 +140,7 @@ static const uint16_t g_broadcast_ipaddr[2] = {0xffff, 0xffff};
|
||||
* The following is the first three octects of the IGMP address:
|
||||
*/
|
||||
|
||||
#if defined(CONFIG_NET_MULTICAST) && !defined(CONFIG_NET_IPv6)
|
||||
#if defined(CONFIG_NET_IGMP) && !defined(CONFIG_NET_IPv6)
|
||||
static const uint8_t g_multicast_ethaddr[3] = {0x01, 0x00, 0x5e};
|
||||
#endif
|
||||
|
||||
@@ -306,7 +306,7 @@ void uip_arp_out(struct uip_driver_s *dev)
|
||||
{
|
||||
memcpy(peth->dest, g_broadcast_ethaddr.ether_addr_octet, ETHER_ADDR_LEN);
|
||||
}
|
||||
#if defined(CONFIG_NET_MULTICAST) && !defined(CONFIG_NET_IPv6)
|
||||
#if defined(CONFIG_NET_IGMP) && !defined(CONFIG_NET_IPv6)
|
||||
/* Check if the destination address is a multicast address
|
||||
*
|
||||
* - IPv4: multicast addresses lie in the class D group -- The address range
|
||||
|
||||
@@ -119,8 +119,8 @@ void uip_igmpdevinit(struct uip_driver_s *dev)
|
||||
|
||||
/* Allow the IGMP messages at the MAC level */
|
||||
|
||||
uip_igmpmac(dev, &g_allrouters, true);
|
||||
uip_igmpmac(dev, &g_allsystems, true);
|
||||
uip_addmcastmac(dev, &g_allrouters);
|
||||
uip_addmcastmac(dev, &g_allsystems);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NET_IGMP */
|
||||
|
||||
@@ -146,7 +146,7 @@ void igmp_joingroup(struct uip_driver_s *dev, uip_ipaddr_t *grpaddr)
|
||||
|
||||
/* Add the group (MAC) address to the ether drivers MAC filter list */
|
||||
|
||||
uip_igmpmac(dev, grpaddr, true);
|
||||
uip_addmcastmac(dev, grpaddr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -166,7 +166,7 @@ void igmp_leavegroup(struct uip_driver_s *dev, uip_ipaddr_t *grpaddr)
|
||||
|
||||
/* And remove the group address from the ethernet drivers MAC filter set */
|
||||
|
||||
uip_igmpmac(dev, grpaddr, false);
|
||||
uip_removemcastmac(dev, grpaddr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -434,7 +434,7 @@ void uip_input(struct uip_driver_s *dev)
|
||||
}
|
||||
}
|
||||
|
||||
/* Check if the pack is destined for out IP address */
|
||||
/* Check if the packet is destined for out IP address */
|
||||
else
|
||||
#endif
|
||||
{
|
||||
|
||||
@@ -250,9 +250,10 @@ EXTERN void uip_igmpstartticks(FAR struct igmp_group_s *group, int ticks);
|
||||
EXTERN void uip_igmpstarttimer(FAR struct igmp_group_s *group, uint8_t decisecs);
|
||||
EXTERN bool uip_igmpcmptimer(FAR struct igmp_group_s *group, int maxticks);
|
||||
|
||||
/* Defined in TBD ************************************************************/
|
||||
/* Defined in uip_mcastmac ***************************************************/
|
||||
|
||||
EXTERN void uip_igmpmac(struct uip_driver_s *dev, uip_ipaddr_t *ip, bool on);
|
||||
EXTERN void uip_addmcastmac(FAR struct uip_driver_s *dev, FAR uip_ipaddr_t *ip);
|
||||
EXTERN void uip_removemcastmac(FAR struct uip_driver_s *dev, FAR uip_ipaddr_t *ip);
|
||||
|
||||
#endif /* CONFIG_NET_IGMP */
|
||||
|
||||
|
||||
Executable
+132
@@ -0,0 +1,132 @@
|
||||
/****************************************************************************
|
||||
* net/uip/uip_mcastmac.c
|
||||
*
|
||||
* Copyright (C) 2010 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* The NuttX implementation of IGMP was inspired by the IGMP add-on for the
|
||||
* lwIP TCP/IP stack by Steve Reynolds:
|
||||
*
|
||||
* Copyright (c) 2002 CITEL Technologies Ltd.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of CITEL Technologies Ltd nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY CITEL TECHNOLOGIES AND CONTRIBUTORS ``AS IS''
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL CITEL TECHNOLOGIES OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <net/uip/uipopt.h>
|
||||
#include <net/uip/uip.h>
|
||||
|
||||
#include "uip_internal.h"
|
||||
|
||||
#ifdef CONFIG_NET_IGMP
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: uip_mcastmac
|
||||
*
|
||||
* Description:
|
||||
* Given an IP address (in network order), create a IGMP multicast MAC
|
||||
* address.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void uip_mcastmac(uip_ipaddr_t *ip, FAR uint8_t *mac)
|
||||
{
|
||||
/* This mapping is from the IETF IN RFC 1700 */
|
||||
|
||||
mac[0] = 0x01;
|
||||
mac[1] = 0x00;
|
||||
mac[2] = 0x5e;
|
||||
mac[3] = ip4_addr2(*ip) & 0x7f;
|
||||
mac[4] = ip4_addr3(*ip);
|
||||
mac[5] = ip4_addr4(*ip);
|
||||
|
||||
nvdbg("IP: %04x -> MAC: %02%02%02%02%02%02\n",
|
||||
*ip, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: uip_addmcastmac
|
||||
*
|
||||
* Description:
|
||||
* Add an IGMP MAC address to the device's MAC filter table.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void uip_addmcastmac(FAR struct uip_driver_s *dev, FAR uip_ipaddr_t *ip)
|
||||
{
|
||||
uint8_t mcastmac[6];
|
||||
|
||||
nvdbg("Adding: IP %04x\n");
|
||||
if (dev->d_addmac)
|
||||
{
|
||||
uip_mcastmac(ip, mcastmac);
|
||||
dev->d_addmac(dev, mcastmac);
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: uip_removemcastmac
|
||||
*
|
||||
* Description:
|
||||
* Remove an IGMP MAC address from the device's MAC filter table.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void uip_removemcastmac(FAR struct uip_driver_s *dev, FAR uip_ipaddr_t *ip)
|
||||
{
|
||||
uint8_t mcastmac[6];
|
||||
|
||||
nvdbg("Removing: IP %04x\n");
|
||||
if (dev->d_rmmac)
|
||||
{
|
||||
uip_mcastmac(ip, mcastmac);
|
||||
dev->d_rmmac(dev, mcastmac);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NET_IGMP */
|
||||
Reference in New Issue
Block a user