2010-07-14 19:17:39 +02:00
|
|
|
/****************************************************************************
|
2014-05-30 21:05:19 +02:00
|
|
|
* net/igmp/igmp_input.c
|
2010-07-14 19:17:39 +02:00
|
|
|
*
|
2020-01-11 16:40:32 +01:00
|
|
|
* Copyright (C) 2010, 2014, 2020 Gregory Nutt. All rights reserved.
|
2012-09-13 20:32:24 +02:00
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
2010-07-14 19:17:39 +02:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2014-04-13 22:32:20 +02:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
2010-07-14 19:17:39 +02:00
|
|
|
*
|
2014-04-13 22:32:20 +02:00
|
|
|
* 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.
|
2020-08-06 19:41:45 +02:00
|
|
|
* 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.
|
2010-07-14 19:17:39 +02:00
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY CITEL TECHNOLOGIES AND CONTRIBUTORS ``AS IS''
|
2014-04-13 22:32:20 +02:00
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
2020-08-06 19:41:45 +02:00
|
|
|
* 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.
|
2010-07-14 19:17:39 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <debug.h>
|
2020-11-23 12:33:36 +01:00
|
|
|
#include <inttypes.h>
|
|
|
|
#include <stdint.h>
|
2010-07-14 19:17:39 +02:00
|
|
|
|
2014-08-21 19:16:55 +02:00
|
|
|
#include <nuttx/wdog.h>
|
2014-06-24 16:53:28 +02:00
|
|
|
#include <nuttx/net/netconfig.h>
|
2014-06-26 17:32:39 +02:00
|
|
|
#include <nuttx/net/netstats.h>
|
2014-07-05 03:13:08 +02:00
|
|
|
#include <nuttx/net/ip.h>
|
|
|
|
#include <nuttx/net/igmp.h>
|
2010-07-14 19:17:39 +02:00
|
|
|
|
2014-06-29 02:07:02 +02:00
|
|
|
#include "devif/devif.h"
|
2014-06-25 17:52:36 +02:00
|
|
|
#include "igmp/igmp.h"
|
2014-07-05 23:15:40 +02:00
|
|
|
#include "utils/utils.h"
|
2010-07-14 19:17:39 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_NET_IGMP
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2014-06-25 17:52:36 +02:00
|
|
|
* Name: igmp_input
|
2010-07-14 19:17:39 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* An IGMP packet has been received.
|
|
|
|
*
|
|
|
|
* ________________
|
|
|
|
* | |
|
|
|
|
* | |
|
|
|
|
* | |
|
|
|
|
* | |
|
|
|
|
* +--------->| Non-Member |<---------+
|
|
|
|
* | | | |
|
|
|
|
* | | | |
|
|
|
|
* | | | |
|
|
|
|
* | |________________| |
|
|
|
|
* | | |
|
|
|
|
* | leave group | join group | leave group
|
|
|
|
* | (stop timer, |(send report, | (send leave
|
|
|
|
* | send leave if | set flag, | if flag set)
|
|
|
|
* | flag set) | start timer) |
|
|
|
|
* ________|________ | ________|________
|
|
|
|
* | |<---------+ | |
|
|
|
|
* | | | |
|
|
|
|
* | |<-------------------| |
|
|
|
|
* | | query received | |
|
|
|
|
* | Delaying Member | (start timer) | Idle Member |
|
|
|
|
* +---->| |------------------->| |
|
|
|
|
* | | | report received | |
|
|
|
|
* | | | (stop timer, | |
|
|
|
|
* | | | clear flag) | |
|
|
|
|
* | |_________________|------------------->|_________________|
|
|
|
|
* | query received | timer expired
|
|
|
|
* | (reset timer if | (send report,
|
|
|
|
* | Max Resp Time | set flag)
|
|
|
|
* | < current timer) |
|
|
|
|
* +-------------------+
|
|
|
|
*
|
2017-09-02 18:27:03 +02:00
|
|
|
* NOTE: The network must be locked.
|
2010-07-14 19:17:39 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2014-06-28 00:48:12 +02:00
|
|
|
void igmp_input(struct net_driver_s *dev)
|
2010-07-14 19:17:39 +02:00
|
|
|
{
|
2022-10-26 06:35:08 +02:00
|
|
|
FAR struct igmp_iphdr_s *ipv4 = IPBUF(0);
|
2019-08-31 20:25:30 +02:00
|
|
|
FAR struct igmp_hdr_s *igmp;
|
2010-07-14 19:17:39 +02:00
|
|
|
FAR struct igmp_group_s *group;
|
2015-01-16 19:30:18 +01:00
|
|
|
in_addr_t destipaddr;
|
|
|
|
in_addr_t grpaddr;
|
2019-08-31 20:25:30 +02:00
|
|
|
uint16_t iphdrlen;
|
2010-07-14 19:17:39 +02:00
|
|
|
unsigned int ticks;
|
|
|
|
|
2020-08-06 19:41:45 +02:00
|
|
|
ninfo("IGMP message: %04x%04x\n",
|
|
|
|
ipv4->destipaddr[1], ipv4->destipaddr[0]);
|
2019-08-31 20:25:30 +02:00
|
|
|
|
|
|
|
/* Get the IP header length (accounting for possible options). */
|
|
|
|
|
|
|
|
iphdrlen = (ipv4->vhl & IPv4_HLMASK) << 2;
|
|
|
|
|
|
|
|
/* The IGMP header immediately follows the IP header */
|
|
|
|
|
2022-10-26 06:35:08 +02:00
|
|
|
igmp = IPBUF(iphdrlen);
|
2010-07-14 19:17:39 +02:00
|
|
|
|
|
|
|
/* Verify the message length */
|
|
|
|
|
2019-08-31 20:25:30 +02:00
|
|
|
if (dev->d_len < NET_LL_HDRLEN(dev) + (iphdrlen + IGMP_HDRLEN))
|
2010-07-14 19:17:39 +02:00
|
|
|
{
|
2014-06-26 17:32:39 +02:00
|
|
|
IGMP_STATINCR(g_netstats.igmp.length_errors);
|
2016-06-20 17:37:08 +02:00
|
|
|
nwarn("WARNING: Length error\n");
|
2021-04-14 14:56:38 +02:00
|
|
|
goto drop;
|
2010-07-14 19:17:39 +02:00
|
|
|
}
|
|
|
|
|
2024-04-24 05:06:52 +02:00
|
|
|
#ifdef CONFIG_NET_IGMP_CHECKSUMS
|
2010-07-14 19:17:39 +02:00
|
|
|
/* Calculate and check the IGMP checksum */
|
|
|
|
|
2019-08-31 20:25:30 +02:00
|
|
|
if (net_chksum((FAR uint16_t *)igmp, IGMP_HDRLEN) != 0)
|
2010-07-14 19:17:39 +02:00
|
|
|
{
|
2014-06-26 17:32:39 +02:00
|
|
|
IGMP_STATINCR(g_netstats.igmp.chksum_errors);
|
2016-06-20 17:37:08 +02:00
|
|
|
nwarn("WARNING: Checksum error\n");
|
2021-04-14 14:56:38 +02:00
|
|
|
goto drop;
|
2010-07-14 19:17:39 +02:00
|
|
|
}
|
2024-04-24 05:06:52 +02:00
|
|
|
#endif
|
2010-07-14 19:17:39 +02:00
|
|
|
|
2018-11-07 17:39:51 +01:00
|
|
|
/* Find the group (or create a new one) using the incoming IP address. */
|
2010-07-14 19:17:39 +02:00
|
|
|
|
2019-08-31 20:25:30 +02:00
|
|
|
destipaddr = net_ip4addr_conv32(ipv4->destipaddr);
|
2018-11-04 17:57:21 +01:00
|
|
|
|
2014-06-25 17:52:36 +02:00
|
|
|
group = igmp_grpallocfind(dev, &destipaddr);
|
2018-11-04 17:57:21 +01:00
|
|
|
if (group == NULL)
|
|
|
|
{
|
2020-11-23 12:33:36 +01:00
|
|
|
nerr("ERROR: Failed to find/allocate group: %08" PRIx32 "\n",
|
|
|
|
(uint32_t)destipaddr);
|
2021-04-14 14:56:38 +02:00
|
|
|
goto drop;
|
2018-11-04 17:57:21 +01:00
|
|
|
}
|
|
|
|
|
2010-07-14 19:17:39 +02:00
|
|
|
/* Now handle the message based on the IGMP message type */
|
|
|
|
|
2019-08-31 20:25:30 +02:00
|
|
|
switch (igmp->type)
|
2010-07-14 19:17:39 +02:00
|
|
|
{
|
|
|
|
case IGMP_MEMBERSHIP_QUERY:
|
|
|
|
/* RFC 2236, 2.2. ax Response Time
|
2020-08-06 19:41:45 +02:00
|
|
|
* "The Max Response Time field is meaningful only in Membership
|
|
|
|
* Query messages, and specifies the maximum allowed time before
|
|
|
|
* sending a responding report in units of 1/10 second. In all
|
|
|
|
* other messages, it is set to zero by the sender and ignored by
|
|
|
|
* receivers.
|
2010-07-14 19:17:39 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Check if the query was sent to all systems */
|
|
|
|
|
2015-01-16 20:01:08 +01:00
|
|
|
if (net_ipv4addr_cmp(destipaddr, g_ipv4_allsystems))
|
2010-07-14 19:17:39 +02:00
|
|
|
{
|
Sources and Docs: Fix typos and nxstyle issues
Documentation/contributing/coding_style.rst:
* Fix repeated words: ("this this").
* Remove trailing spaces.
boards/z80/z80/z80sim/README.txt:
* Fix repeated words: ("this this") and rewrap lines.
graphics/Kconfig,
libs/libc/math/Kconfig:
* Fix repeated words: ("this this").
arch/arm/src/armv7-a/arm_assert.c,
arch/arm/src/armv7-r/arm_assert.c,
arch/arm/src/imxrt/imxrt_enet.c,
arch/arm/src/kinetis/kinetis_enet.c,
arch/arm/src/kinetis/kinetis_flexcan.c,
arch/arm/src/s32k1xx/s32k1xx_enet.c,
arch/arm/src/s32k1xx/s32k1xx_flexcan.c,
arch/arm/src/stm32/stm32_pwm.c,
arch/arm/src/stm32h7/stm32_pwm.c,
arch/arm/src/stm32l4/stm32l4_pwm.c,
arch/renesas/src/rx65n/rx65n_usbdev.c,
binfmt/libnxflat/libnxflat_bind.c,
drivers/pipes/pipe_common.c,
net/igmp/igmp_input.c,
net/tcp/tcp_conn.c,
sched/sched/sched_roundrobin.c:
* Fix typo in comment ("this this").
arch/arm/src/cxd56xx/cxd56_usbdev.c,
arch/arm/src/lc823450/lc823450_usbdev.c:
* Fix typo in comment and rewrap lines.
arch/arm/src/imxrt/imxrt_usbdev.c,
arch/arm/src/stm32/stm32_dac.c,
arch/arm/src/stm32f0l0g0/stm32_pwm.c,
arch/arm/src/stm32f7/stm32_pwm.c,
arch/arm/src/tiva/lm/lm4f_gpio.h,
fs/nxffs/nxffs_write.c,
include/nuttx/analog/pga11x.h,
include/nuttx/usb/usbdev.h,
net/mld/mld_join.c:
* Fix typo in comment ("this this").
* Fix nxstyle issues.
2020-10-02 01:29:35 +02:00
|
|
|
/* Yes... Now check the if this is a general or a group
|
2010-07-14 19:17:39 +02:00
|
|
|
* specific query.
|
|
|
|
*
|
|
|
|
* RFC 2236, 2.1. Type
|
|
|
|
* There are two sub-types of Membership Query messages:
|
|
|
|
* - General Query, used to learn which groups have members on an
|
|
|
|
* attached network.
|
|
|
|
* - Group-Specific Query, used to learn if a particular group
|
|
|
|
* has any members on an attached network.
|
|
|
|
*
|
|
|
|
* RFC 2236, 2.4. Group Address
|
|
|
|
* "In a Membership Query message, the group address field is
|
|
|
|
* set to zero when sending a General Query, and set to the
|
|
|
|
* group address being queried when sending a Group-Specific
|
|
|
|
* Query."
|
|
|
|
*/
|
|
|
|
|
2022-10-10 15:54:37 +02:00
|
|
|
if (net_ipv4addr_cmp(igmp->grpaddr, INADDR_ANY) != 0)
|
2010-07-14 19:17:39 +02:00
|
|
|
{
|
|
|
|
FAR struct igmp_group_s *member;
|
|
|
|
|
|
|
|
/* This is the general query */
|
|
|
|
|
2016-06-20 19:59:15 +02:00
|
|
|
ninfo("General multicast query\n");
|
2019-08-31 20:25:30 +02:00
|
|
|
if (igmp->maxresp == 0)
|
2010-07-14 19:17:39 +02:00
|
|
|
{
|
2014-06-26 17:32:39 +02:00
|
|
|
IGMP_STATINCR(g_netstats.igmp.v1_received);
|
2019-08-31 20:25:30 +02:00
|
|
|
igmp->maxresp = 10;
|
2010-07-14 19:17:39 +02:00
|
|
|
|
2016-06-20 17:37:08 +02:00
|
|
|
nwarn("WARNING: V1 not implemented\n");
|
2010-07-14 19:17:39 +02:00
|
|
|
}
|
|
|
|
|
2014-06-26 17:32:39 +02:00
|
|
|
IGMP_STATINCR(g_netstats.igmp.query_received);
|
2018-11-04 17:57:21 +01:00
|
|
|
|
2020-08-06 19:41:45 +02:00
|
|
|
member = (FAR struct igmp_group_s *)dev->d_igmp_grplist.head;
|
|
|
|
for (; member; member = member->next)
|
2010-07-14 19:17:39 +02:00
|
|
|
{
|
|
|
|
/* Skip over the all systems group entry */
|
|
|
|
|
2020-08-06 19:41:45 +02:00
|
|
|
if (!net_ipv4addr_cmp(member->grpaddr,
|
|
|
|
g_ipv4_allsystems))
|
2010-07-14 19:17:39 +02:00
|
|
|
{
|
2019-08-31 20:25:30 +02:00
|
|
|
ticks = net_dsec2tick((int)igmp->maxresp);
|
2010-07-14 19:17:39 +02:00
|
|
|
if (IS_IDLEMEMBER(member->flags) ||
|
2014-06-25 17:52:36 +02:00
|
|
|
igmp_cmptimer(member, ticks))
|
2010-07-14 19:17:39 +02:00
|
|
|
{
|
2014-06-25 17:52:36 +02:00
|
|
|
igmp_startticks(member, ticks);
|
2010-07-14 19:17:39 +02:00
|
|
|
CLR_IDLEMEMBER(member->flags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-10-10 15:54:37 +02:00
|
|
|
else /* if (net_ipv4addr_cmp(igmp->grpaddr, INADDR_ANY) == 0) */
|
2010-07-14 19:17:39 +02:00
|
|
|
{
|
2018-11-01 14:52:32 +01:00
|
|
|
ninfo("Group-specific multicast query\n");
|
2010-07-14 19:17:39 +02:00
|
|
|
|
2020-08-06 19:41:45 +02:00
|
|
|
/* We first need to re-lookup the group since we used dest
|
|
|
|
* last time. Use the incoming IPaddress!
|
2010-07-14 19:17:39 +02:00
|
|
|
*/
|
|
|
|
|
2014-06-26 17:32:39 +02:00
|
|
|
IGMP_STATINCR(g_netstats.igmp.ucast_query);
|
2018-11-04 17:57:21 +01:00
|
|
|
|
2019-08-31 20:25:30 +02:00
|
|
|
grpaddr = net_ip4addr_conv32(igmp->grpaddr);
|
2018-11-07 17:39:51 +01:00
|
|
|
group = igmp_grpallocfind(dev, &grpaddr);
|
2018-11-04 17:57:21 +01:00
|
|
|
|
|
|
|
if (group != NULL)
|
2010-07-14 19:17:39 +02:00
|
|
|
{
|
2019-08-31 20:25:30 +02:00
|
|
|
ticks = net_dsec2tick((int)igmp->maxresp);
|
2018-11-04 17:57:21 +01:00
|
|
|
|
2020-01-11 16:40:32 +01:00
|
|
|
if (IS_IDLEMEMBER(group->flags) ||
|
|
|
|
igmp_cmptimer(group, ticks))
|
2018-11-04 17:57:21 +01:00
|
|
|
{
|
|
|
|
igmp_startticks(group, ticks);
|
|
|
|
CLR_IDLEMEMBER(group->flags);
|
|
|
|
}
|
2010-07-14 19:17:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Not sent to all systems -- Unicast query */
|
|
|
|
|
2022-10-10 15:54:37 +02:00
|
|
|
else if (net_ipv4addr_cmp(igmp->grpaddr, INADDR_ANY) == 0)
|
2010-07-14 19:17:39 +02:00
|
|
|
{
|
2016-06-20 19:59:15 +02:00
|
|
|
ninfo("Unicast query\n");
|
2014-06-26 17:32:39 +02:00
|
|
|
IGMP_STATINCR(g_netstats.igmp.ucast_query);
|
2010-07-14 19:17:39 +02:00
|
|
|
|
2020-01-11 16:40:32 +01:00
|
|
|
ninfo("Query to a specific group with the group address as "
|
|
|
|
"destination\n");
|
2010-07-14 19:17:39 +02:00
|
|
|
|
2019-08-31 20:25:30 +02:00
|
|
|
ticks = net_dsec2tick((int)igmp->maxresp);
|
2014-06-25 17:52:36 +02:00
|
|
|
if (IS_IDLEMEMBER(group->flags) || igmp_cmptimer(group, ticks))
|
2010-07-14 19:17:39 +02:00
|
|
|
{
|
2014-06-25 17:52:36 +02:00
|
|
|
igmp_startticks(group, ticks);
|
2010-07-14 19:17:39 +02:00
|
|
|
CLR_IDLEMEMBER(group->flags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IGMPv2_MEMBERSHIP_REPORT:
|
|
|
|
{
|
2016-06-20 19:59:15 +02:00
|
|
|
ninfo("Membership report\n");
|
2010-07-14 19:17:39 +02:00
|
|
|
|
2014-06-26 17:32:39 +02:00
|
|
|
IGMP_STATINCR(g_netstats.igmp.report_received);
|
2010-07-14 19:17:39 +02:00
|
|
|
if (!IS_IDLEMEMBER(group->flags))
|
|
|
|
{
|
|
|
|
/* This is on a specific group we have already looked up */
|
|
|
|
|
2020-08-04 12:31:31 +02:00
|
|
|
wd_cancel(&group->wdog);
|
2010-07-14 19:17:39 +02:00
|
|
|
SET_IDLEMEMBER(group->flags);
|
|
|
|
CLR_LASTREPORT(group->flags);
|
|
|
|
}
|
|
|
|
}
|
2018-11-07 17:39:51 +01:00
|
|
|
break;
|
2010-07-14 19:17:39 +02:00
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
2019-08-31 20:25:30 +02:00
|
|
|
nwarn("WARNING: Unexpected msg %02x\n", igmp->type);
|
2010-07-14 19:17:39 +02:00
|
|
|
}
|
2018-11-07 17:39:51 +01:00
|
|
|
break;
|
2010-07-14 19:17:39 +02:00
|
|
|
}
|
2018-11-04 17:57:21 +01:00
|
|
|
|
2021-04-14 14:56:38 +02:00
|
|
|
drop:
|
2018-11-04 17:57:21 +01:00
|
|
|
dev->d_len = 0;
|
2010-07-14 19:17:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_NET_IGMP */
|