2007-08-09 16:53:47 +00:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* IGMP - Internet Group Management Protocol
|
2007-08-09 22:21:44 +00:00
|
|
|
*
|
2007-08-09 16:53:47 +00:00
|
|
|
*/
|
|
|
|
|
2007-03-11 19:45:32 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* This file is a contribution to the lwIP TCP/IP stack.
|
|
|
|
* The Swedish Institute of Computer Science and Adam Dunkels
|
|
|
|
* are specifically granted permission to redistribute this
|
|
|
|
* source code.
|
|
|
|
*/
|
|
|
|
|
2007-08-30 09:14:28 +00:00
|
|
|
/*-------------------------------------------------------------
|
|
|
|
Note 1)
|
2007-03-11 19:45:32 +00:00
|
|
|
Although the rfc requires V1 AND V2 capability
|
2007-08-30 09:14:28 +00:00
|
|
|
we will only support v2 since now V1 is very old (August 1989)
|
2007-03-11 19:45:32 +00:00
|
|
|
V1 can be added if required
|
|
|
|
|
|
|
|
a debug print and statistic have been implemented to
|
|
|
|
show this up.
|
|
|
|
-------------------------------------------------------------
|
|
|
|
-------------------------------------------------------------
|
2007-08-30 09:14:28 +00:00
|
|
|
Note 2)
|
2007-03-11 19:45:32 +00:00
|
|
|
A query for a specific group address (as opposed to ALLHOSTS)
|
|
|
|
has now been implemented as I am unsure if it is required
|
|
|
|
|
|
|
|
a debug print and statistic have been implemented to
|
|
|
|
show this up.
|
|
|
|
-------------------------------------------------------------
|
|
|
|
-------------------------------------------------------------
|
2007-08-30 09:14:28 +00:00
|
|
|
Note 3)
|
2007-03-11 19:45:32 +00:00
|
|
|
The router alert rfc 2113 is implemented in outgoing packets
|
|
|
|
but not checked rigorously incoming
|
|
|
|
-------------------------------------------------------------
|
|
|
|
Steve Reynolds
|
|
|
|
------------------------------------------------------------*/
|
|
|
|
|
2007-08-09 16:53:47 +00:00
|
|
|
/*-----------------------------------------------------------------------------
|
|
|
|
* RFC 988 - Host extensions for IP multicasting - V0
|
|
|
|
* RFC 1054 - Host extensions for IP multicasting -
|
|
|
|
* RFC 1112 - Host extensions for IP multicasting - V1
|
|
|
|
* RFC 2236 - Internet Group Management Protocol, Version 2 - V2 <- this code is based on this RFC (it's the "de facto" standard)
|
|
|
|
* RFC 3376 - Internet Group Management Protocol, Version 3 - V3
|
|
|
|
* RFC 4604 - Using Internet Group Management Protocol Version 3... - V3+
|
|
|
|
* RFC 2113 - IP Router Alert Option -
|
|
|
|
*----------------------------------------------------------------------------*/
|
|
|
|
|
2007-03-11 19:45:32 +00:00
|
|
|
/*-----------------------------------------------------------------------------
|
|
|
|
* Includes
|
|
|
|
*----------------------------------------------------------------------------*/
|
|
|
|
|
2007-09-07 23:01:59 +00:00
|
|
|
#include "lwip/opt.h"
|
|
|
|
|
|
|
|
#if LWIP_IGMP /* don't build if not configured for use in lwipopts.h */
|
|
|
|
|
2007-11-16 19:31:10 +00:00
|
|
|
#include "lwip/igmp.h"
|
2007-03-11 19:45:32 +00:00
|
|
|
#include "lwip/debug.h"
|
|
|
|
#include "lwip/def.h"
|
|
|
|
#include "lwip/mem.h"
|
|
|
|
#include "lwip/ip.h"
|
2007-11-16 19:31:10 +00:00
|
|
|
#include "lwip/inet_chksum.h"
|
2007-03-11 19:45:32 +00:00
|
|
|
#include "lwip/netif.h"
|
|
|
|
#include "lwip/icmp.h"
|
|
|
|
#include "lwip/udp.h"
|
|
|
|
#include "lwip/tcp.h"
|
|
|
|
#include "lwip/stats.h"
|
|
|
|
|
|
|
|
#include "string.h"
|
|
|
|
|
|
|
|
/*-----------------------------------------------------------------------------
|
|
|
|
* Globales
|
|
|
|
*----------------------------------------------------------------------------*/
|
|
|
|
|
2007-06-11 07:27:12 +00:00
|
|
|
static struct igmp_group* igmp_group_list;
|
2010-02-04 18:47:44 +00:00
|
|
|
static ip_addr_t allsystems;
|
|
|
|
static ip_addr_t allrouters;
|
2007-03-11 19:45:32 +00:00
|
|
|
|
2007-06-08 12:54:40 +00:00
|
|
|
/**
|
2007-08-29 21:12:32 +00:00
|
|
|
* Initialize the IGMP module
|
2007-06-08 12:54:40 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
igmp_init(void)
|
|
|
|
{
|
2007-08-09 16:53:47 +00:00
|
|
|
LWIP_DEBUGF(IGMP_DEBUG, ("igmp_init: initializing\n"));
|
2007-03-11 19:45:32 +00:00
|
|
|
|
2007-06-08 12:54:40 +00:00
|
|
|
IP4_ADDR(&allsystems, 224, 0, 0, 1);
|
|
|
|
IP4_ADDR(&allrouters, 224, 0, 0, 2);
|
2007-08-29 21:12:32 +00:00
|
|
|
}
|
|
|
|
|
2007-09-09 20:46:33 +00:00
|
|
|
#ifdef LWIP_DEBUG
|
|
|
|
/**
|
|
|
|
* Dump global IGMP groups list
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
igmp_dump_group_list()
|
|
|
|
{
|
|
|
|
struct igmp_group *group = igmp_group_list;
|
|
|
|
|
|
|
|
while (group != NULL) {
|
|
|
|
LWIP_DEBUGF(IGMP_DEBUG, ("igmp_dump_group_list: [%"U32_F"] ", (u32_t)(group->group_state)));
|
|
|
|
ip_addr_debug_print(IGMP_DEBUG, &group->group_address);
|
2010-01-28 18:27:26 +00:00
|
|
|
LWIP_DEBUGF(IGMP_DEBUG, (" on if %p\n", group->netif));
|
2007-09-09 20:46:33 +00:00
|
|
|
group = group->next;
|
|
|
|
}
|
|
|
|
LWIP_DEBUGF(IGMP_DEBUG, ("\n"));
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define igmp_dump_group_list()
|
|
|
|
#endif /* LWIP_DEBUG */
|
|
|
|
|
2007-08-29 21:12:32 +00:00
|
|
|
/**
|
|
|
|
* Start IGMP processing on interface
|
|
|
|
*
|
|
|
|
* @param netif network interface on which start IGMP processing
|
|
|
|
*/
|
|
|
|
err_t
|
|
|
|
igmp_start(struct netif *netif)
|
|
|
|
{
|
|
|
|
struct igmp_group* group;
|
2007-08-09 16:53:47 +00:00
|
|
|
|
2009-02-18 20:37:09 +00:00
|
|
|
LWIP_DEBUGF(IGMP_DEBUG, ("igmp_start: starting IGMP processing on if %p\n", netif));
|
2007-06-08 12:54:40 +00:00
|
|
|
|
2007-08-29 21:12:32 +00:00
|
|
|
group = igmp_lookup_group(netif, &allsystems);
|
|
|
|
|
|
|
|
if (group != NULL) {
|
2007-09-04 15:15:20 +00:00
|
|
|
group->group_state = IGMP_GROUP_IDLE_MEMBER;
|
|
|
|
group->use++;
|
2007-08-29 21:12:32 +00:00
|
|
|
|
|
|
|
/* Allow the igmp messages at the MAC level */
|
|
|
|
if (netif->igmp_mac_filter != NULL) {
|
2007-09-04 15:15:20 +00:00
|
|
|
LWIP_DEBUGF(IGMP_DEBUG, ("igmp_start: igmp_mac_filter(ADD "));
|
|
|
|
ip_addr_debug_print(IGMP_DEBUG, &allsystems);
|
2009-02-18 20:37:09 +00:00
|
|
|
LWIP_DEBUGF(IGMP_DEBUG, (") on if %p\n", netif));
|
2007-08-29 21:12:32 +00:00
|
|
|
netif->igmp_mac_filter( netif, &allsystems, IGMP_ADD_MAC_FILTER);
|
2007-06-08 12:54:40 +00:00
|
|
|
}
|
2007-08-29 21:12:32 +00:00
|
|
|
|
|
|
|
return ERR_OK;
|
2007-06-08 12:54:40 +00:00
|
|
|
}
|
2007-08-29 21:12:32 +00:00
|
|
|
|
|
|
|
return ERR_MEM;
|
2007-03-11 19:45:32 +00:00
|
|
|
}
|
|
|
|
|
2007-09-09 20:46:33 +00:00
|
|
|
/**
|
|
|
|
* Stop IGMP processing on interface
|
|
|
|
*
|
|
|
|
* @param netif network interface on which stop IGMP processing
|
|
|
|
*/
|
|
|
|
err_t
|
|
|
|
igmp_stop(struct netif *netif)
|
|
|
|
{
|
|
|
|
struct igmp_group *group = igmp_group_list;
|
|
|
|
struct igmp_group *prev = NULL;
|
|
|
|
struct igmp_group *next;
|
|
|
|
|
|
|
|
/* look for groups joined on this interface further down the list */
|
|
|
|
while (group != NULL) {
|
|
|
|
next = group->next;
|
|
|
|
/* is it a group joined on this interface? */
|
2010-01-28 18:27:26 +00:00
|
|
|
if (group->netif == netif) {
|
2007-09-09 20:46:33 +00:00
|
|
|
/* is it the first group of the list? */
|
|
|
|
if (group == igmp_group_list) {
|
|
|
|
igmp_group_list = next;
|
|
|
|
}
|
|
|
|
/* is there a "previous" group defined? */
|
|
|
|
if (prev != NULL) {
|
|
|
|
prev->next = next;
|
|
|
|
}
|
|
|
|
/* disable the group at the MAC level */
|
|
|
|
if (netif->igmp_mac_filter != NULL) {
|
|
|
|
LWIP_DEBUGF(IGMP_DEBUG, ("igmp_stop: igmp_mac_filter(DEL "));
|
|
|
|
ip_addr_debug_print(IGMP_DEBUG, &group->group_address);
|
2009-02-18 20:37:09 +00:00
|
|
|
LWIP_DEBUGF(IGMP_DEBUG, (") on if %p\n", netif));
|
2007-09-09 20:46:33 +00:00
|
|
|
netif->igmp_mac_filter(netif, &(group->group_address), IGMP_DEL_MAC_FILTER);
|
|
|
|
}
|
|
|
|
/* free group */
|
|
|
|
memp_free(MEMP_IGMP_GROUP, group);
|
|
|
|
} else {
|
|
|
|
/* change the "previous" */
|
|
|
|
prev = group;
|
|
|
|
}
|
|
|
|
/* move to "next" */
|
|
|
|
group = next;
|
|
|
|
}
|
|
|
|
return ERR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Report IGMP memberships for this interface
|
|
|
|
*
|
|
|
|
* @param netif network interface on which report IGMP memberships
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
igmp_report_groups( struct netif *netif)
|
|
|
|
{
|
|
|
|
struct igmp_group *group = igmp_group_list;
|
|
|
|
|
2009-02-18 20:37:09 +00:00
|
|
|
LWIP_DEBUGF(IGMP_DEBUG, ("igmp_report_groups: sending IGMP reports on if %p\n", netif));
|
2007-09-09 20:46:33 +00:00
|
|
|
|
|
|
|
while (group != NULL) {
|
2010-01-28 18:27:26 +00:00
|
|
|
if (group->netif == netif) {
|
2007-09-09 20:46:33 +00:00
|
|
|
igmp_delaying_member( group, IGMP_JOIN_DELAYING_MEMBER_TMR);
|
|
|
|
}
|
|
|
|
group = group->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-08 12:54:40 +00:00
|
|
|
/**
|
2007-06-11 07:27:12 +00:00
|
|
|
* Search for a group in the global igmp_group_list
|
2007-06-08 12:54:40 +00:00
|
|
|
*
|
2007-08-09 16:53:47 +00:00
|
|
|
* @param ifp the network interface for which to look
|
|
|
|
* @param addr the group ip address to search for
|
2007-06-08 12:54:40 +00:00
|
|
|
* @return a struct igmp_group* if the group has been found,
|
|
|
|
* NULL if the group wasn't found.
|
|
|
|
*/
|
|
|
|
struct igmp_group *
|
2010-02-04 18:47:44 +00:00
|
|
|
igmp_lookfor_group(struct netif *ifp, ip_addr_t *addr)
|
2007-06-08 12:54:40 +00:00
|
|
|
{
|
2007-06-11 07:27:12 +00:00
|
|
|
struct igmp_group *group = igmp_group_list;
|
2007-06-08 12:54:40 +00:00
|
|
|
|
2007-09-09 20:46:33 +00:00
|
|
|
while (group != NULL) {
|
2010-01-28 18:27:26 +00:00
|
|
|
if ((group->netif == ifp) && (ip_addr_cmp(&(group->group_address), addr))) {
|
2007-06-08 12:54:40 +00:00
|
|
|
return group;
|
|
|
|
}
|
|
|
|
group = group->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* to be clearer, we return NULL here instead of
|
|
|
|
* 'group' (which is also NULL at this point).
|
|
|
|
*/
|
|
|
|
return NULL;
|
2007-03-11 19:45:32 +00:00
|
|
|
}
|
|
|
|
|
2007-06-08 12:54:40 +00:00
|
|
|
/**
|
|
|
|
* Search for a specific igmp group and create a new one if not found-
|
|
|
|
*
|
2007-08-30 09:14:28 +00:00
|
|
|
* @param ifp the network interface for which to look
|
2007-06-08 12:54:40 +00:00
|
|
|
* @param addr the group ip address to search
|
|
|
|
* @return a struct igmp_group*,
|
|
|
|
* NULL on memory error.
|
|
|
|
*/
|
|
|
|
struct igmp_group *
|
2010-02-04 18:47:44 +00:00
|
|
|
igmp_lookup_group(struct netif *ifp, ip_addr_t *addr)
|
2007-06-08 12:54:40 +00:00
|
|
|
{
|
2007-06-11 07:27:12 +00:00
|
|
|
struct igmp_group *group = igmp_group_list;
|
2007-03-11 19:45:32 +00:00
|
|
|
|
2007-06-08 12:54:40 +00:00
|
|
|
/* Search if the group already exists */
|
2007-08-09 16:53:47 +00:00
|
|
|
group = igmp_lookfor_group(ifp, addr);
|
2007-06-08 12:54:40 +00:00
|
|
|
if (group != NULL) {
|
|
|
|
/* Group already exists. */
|
|
|
|
return group;
|
|
|
|
}
|
|
|
|
|
2007-09-04 15:15:20 +00:00
|
|
|
/* Group doesn't exist yet, create a new one */
|
|
|
|
group = memp_malloc(MEMP_IGMP_GROUP);
|
2007-08-09 16:53:47 +00:00
|
|
|
if (group != NULL) {
|
2010-01-28 18:27:26 +00:00
|
|
|
group->netif = ifp;
|
2007-06-08 12:54:40 +00:00
|
|
|
ip_addr_set(&(group->group_address), addr);
|
|
|
|
group->timer = 0; /* Not running */
|
2007-09-04 15:15:20 +00:00
|
|
|
group->group_state = IGMP_GROUP_NON_MEMBER;
|
2007-06-08 12:54:40 +00:00
|
|
|
group->last_reporter_flag = 0;
|
2007-09-04 15:15:20 +00:00
|
|
|
group->use = 0;
|
2007-06-11 07:27:12 +00:00
|
|
|
group->next = igmp_group_list;
|
2007-09-04 15:15:20 +00:00
|
|
|
|
2007-06-11 07:27:12 +00:00
|
|
|
igmp_group_list = group;
|
2007-06-08 12:54:40 +00:00
|
|
|
}
|
|
|
|
|
2007-08-30 14:20:54 +00:00
|
|
|
LWIP_DEBUGF(IGMP_DEBUG, ("igmp_lookup_group: %sallocated a new group with address ", (group?"":"impossible to ")));
|
|
|
|
ip_addr_debug_print(IGMP_DEBUG, addr);
|
2009-02-18 20:37:09 +00:00
|
|
|
LWIP_DEBUGF(IGMP_DEBUG, (" on if %p\n", ifp));
|
2007-08-30 14:20:54 +00:00
|
|
|
|
2007-03-11 19:45:32 +00:00
|
|
|
return group;
|
|
|
|
}
|
|
|
|
|
2007-09-04 15:15:20 +00:00
|
|
|
/**
|
|
|
|
* Remove a group in the global igmp_group_list
|
|
|
|
*
|
|
|
|
* @param group the group to remove from the global igmp_group_list
|
|
|
|
* @return ERR_OK if group was removed from the list, an err_t otherwise
|
|
|
|
*/
|
|
|
|
err_t
|
|
|
|
igmp_remove_group(struct igmp_group *group)
|
2007-09-09 20:46:33 +00:00
|
|
|
{
|
2007-09-04 15:15:20 +00:00
|
|
|
err_t err = ERR_OK;
|
|
|
|
|
|
|
|
/* Is it the first group? */
|
|
|
|
if (igmp_group_list == group) {
|
|
|
|
igmp_group_list = group->next;
|
|
|
|
} else {
|
2007-09-09 20:46:33 +00:00
|
|
|
/* look for group further down the list */
|
2007-09-04 15:15:20 +00:00
|
|
|
struct igmp_group *tmpGroup;
|
|
|
|
for (tmpGroup = igmp_group_list; tmpGroup != NULL; tmpGroup = tmpGroup->next) {
|
|
|
|
if (tmpGroup->next == group) {
|
|
|
|
tmpGroup->next = group->next;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Group not found in the global igmp_group_list */
|
|
|
|
if (tmpGroup == NULL)
|
|
|
|
err = ERR_ARG;
|
|
|
|
}
|
|
|
|
/* free group */
|
|
|
|
memp_free(MEMP_IGMP_GROUP, group);
|
2007-09-09 20:46:33 +00:00
|
|
|
|
2007-09-04 15:15:20 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2007-06-08 12:54:40 +00:00
|
|
|
/**
|
|
|
|
* Called from ip_input() if a new IGMP packet is received.
|
|
|
|
*
|
|
|
|
* @param p received igmp packet, p->payload pointing to the ip header
|
|
|
|
* @param inp network interface on which the packet was received
|
|
|
|
* @param dest destination ip address of the igmp packet
|
|
|
|
*/
|
|
|
|
void
|
2010-02-04 18:47:44 +00:00
|
|
|
igmp_input(struct pbuf *p, struct netif *inp, ip_addr_t *dest)
|
2007-06-08 12:54:40 +00:00
|
|
|
{
|
|
|
|
struct ip_hdr * iphdr;
|
2007-08-09 20:21:59 +00:00
|
|
|
struct igmp_msg* igmp;
|
2007-03-11 19:45:32 +00:00
|
|
|
struct igmp_group* group;
|
|
|
|
struct igmp_group* groupref;
|
2007-06-08 12:54:40 +00:00
|
|
|
|
2007-07-26 17:10:56 +00:00
|
|
|
/* Note that the length CAN be greater than 8 but only 8 are used - All are included in the checksum */
|
|
|
|
iphdr = p->payload;
|
2008-03-17 13:40:00 +00:00
|
|
|
if (pbuf_header(p, -(s16_t)(IPH_HL(iphdr) * 4)) || (p->len < IGMP_MINLEN)) {
|
2007-06-08 12:54:40 +00:00
|
|
|
pbuf_free(p);
|
2007-08-09 20:09:22 +00:00
|
|
|
IGMP_STATS_INC(igmp.lenerr);
|
2007-08-09 16:53:47 +00:00
|
|
|
LWIP_DEBUGF(IGMP_DEBUG, ("igmp_input: length error\n"));
|
2007-06-08 12:54:40 +00:00
|
|
|
return;
|
|
|
|
}
|
2007-03-11 19:45:32 +00:00
|
|
|
|
2007-08-30 14:20:54 +00:00
|
|
|
LWIP_DEBUGF(IGMP_DEBUG, ("igmp_input: message from "));
|
|
|
|
ip_addr_debug_print(IGMP_DEBUG, &(iphdr->src));
|
|
|
|
LWIP_DEBUGF(IGMP_DEBUG, (" to address "));
|
|
|
|
ip_addr_debug_print(IGMP_DEBUG, &(iphdr->dest));
|
2009-02-18 20:37:09 +00:00
|
|
|
LWIP_DEBUGF(IGMP_DEBUG, (" on if %p\n", inp));
|
2007-07-26 17:10:56 +00:00
|
|
|
|
2007-03-21 14:47:52 +00:00
|
|
|
/* Now calculate and check the checksum */
|
2007-08-09 20:21:59 +00:00
|
|
|
igmp = (struct igmp_msg *)p->payload;
|
2007-07-26 17:10:56 +00:00
|
|
|
if (inet_chksum(igmp, p->len)) {
|
2007-06-08 12:54:40 +00:00
|
|
|
pbuf_free(p);
|
2007-08-09 20:09:22 +00:00
|
|
|
IGMP_STATS_INC(igmp.chkerr);
|
2007-08-09 16:53:47 +00:00
|
|
|
LWIP_DEBUGF(IGMP_DEBUG, ("igmp_input: checksum error\n"));
|
2007-06-08 12:54:40 +00:00
|
|
|
return;
|
|
|
|
}
|
2007-03-11 19:45:32 +00:00
|
|
|
|
2007-08-09 16:53:47 +00:00
|
|
|
/* Packet is ok so find an existing group */
|
|
|
|
group = igmp_lookfor_group(inp, dest); /* use the incoming IP address! */
|
2007-03-11 19:45:32 +00:00
|
|
|
|
2007-03-21 14:47:52 +00:00
|
|
|
/* If group can be found or create... */
|
2007-06-08 12:54:40 +00:00
|
|
|
if (!group) {
|
|
|
|
pbuf_free(p);
|
2007-08-09 16:53:47 +00:00
|
|
|
LWIP_DEBUGF(IGMP_DEBUG, ("igmp_input: IGMP frame not for us\n"));
|
2007-06-08 12:54:40 +00:00
|
|
|
return;
|
|
|
|
}
|
2007-03-11 19:45:32 +00:00
|
|
|
|
2007-03-21 14:47:52 +00:00
|
|
|
/* NOW ACT ON THE INCOMING MESSAGE TYPE... */
|
2007-08-30 14:20:54 +00:00
|
|
|
switch (igmp->igmp_msgtype) {
|
|
|
|
case IGMP_MEMB_QUERY: {
|
|
|
|
/* IGMP_MEMB_QUERY to the "all systems" address ? */
|
2010-02-04 17:21:32 +00:00
|
|
|
if ((ip_addr_cmp(dest, &allsystems)) && ip_addr_isany(&igmp->igmp_group_address)) {
|
2007-08-30 14:20:54 +00:00
|
|
|
/* THIS IS THE GENERAL QUERY */
|
|
|
|
LWIP_DEBUGF(IGMP_DEBUG, ("igmp_input: General IGMP_MEMB_QUERY on \"ALL SYSTEMS\" address (224.0.0.1) [igmp_maxresp=%i]\n", (int)(igmp->igmp_maxresp)));
|
|
|
|
|
|
|
|
if (igmp->igmp_maxresp == 0) {
|
|
|
|
IGMP_STATS_INC(igmp.v1_rxed);
|
|
|
|
LWIP_DEBUGF(IGMP_DEBUG, ("igmp_input: got an all hosts query with time== 0 - this is V1 and not implemented - treat as v2\n"));
|
|
|
|
igmp->igmp_maxresp = IGMP_V1_DELAYING_MEMBER_TMR;
|
|
|
|
}
|
|
|
|
|
|
|
|
IGMP_STATS_INC(igmp.group_query_rxed);
|
|
|
|
groupref = igmp_group_list;
|
|
|
|
while (groupref) {
|
|
|
|
/* Do not send messages on the all systems group address! */
|
2010-01-28 18:27:26 +00:00
|
|
|
if ((groupref->netif == inp) && (!(ip_addr_cmp(&(groupref->group_address), &allsystems)))) {
|
2007-08-30 14:20:54 +00:00
|
|
|
igmp_delaying_member( groupref, igmp->igmp_maxresp);
|
|
|
|
}
|
|
|
|
groupref = groupref->next;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* IGMP_MEMB_QUERY to a specific group ? */
|
2010-02-04 17:21:32 +00:00
|
|
|
if (!ip_addr_isany(&group->group_address) != 0) {
|
2007-08-30 14:20:54 +00:00
|
|
|
LWIP_DEBUGF(IGMP_DEBUG, ("igmp_input: IGMP_MEMB_QUERY to a specific group "));
|
|
|
|
ip_addr_debug_print(IGMP_DEBUG, &group->group_address);
|
|
|
|
if (ip_addr_cmp (dest, &allsystems)) {
|
|
|
|
LWIP_DEBUGF(IGMP_DEBUG, (" using \"ALL SYSTEMS\" address (224.0.0.1) [igmp_maxresp=%i]\n", (int)(igmp->igmp_maxresp)));
|
|
|
|
/* we first need to re-lookfor the group since we used dest last time */
|
|
|
|
group = igmp_lookfor_group(inp, &igmp->igmp_group_address);
|
|
|
|
} else {
|
|
|
|
LWIP_DEBUGF(IGMP_DEBUG, (" with the group address as destination [igmp_maxresp=%i]\n", (int)(igmp->igmp_maxresp)));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (group != NULL) {
|
|
|
|
IGMP_STATS_INC(igmp.unicast_query);
|
|
|
|
igmp_delaying_member( group, igmp->igmp_maxresp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case IGMP_V2_MEMB_REPORT: {
|
|
|
|
LWIP_DEBUGF(IGMP_DEBUG, ("igmp_input: IGMP_V2_MEMB_REPORT\n"));
|
|
|
|
|
|
|
|
IGMP_STATS_INC(igmp.report_rxed);
|
2007-09-04 15:15:20 +00:00
|
|
|
if (group->group_state == IGMP_GROUP_DELAYING_MEMBER) {
|
2007-08-30 14:20:54 +00:00
|
|
|
/* This is on a specific group we have already looked up */
|
|
|
|
group->timer = 0; /* stopped */
|
2007-09-04 15:15:20 +00:00
|
|
|
group->group_state = IGMP_GROUP_IDLE_MEMBER;
|
2007-08-30 14:20:54 +00:00
|
|
|
group->last_reporter_flag = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
2009-02-18 20:37:09 +00:00
|
|
|
LWIP_DEBUGF(IGMP_DEBUG, ("igmp_input: unexpected msg %d in state %d on group %p on if %p\n",
|
2010-01-28 18:27:26 +00:00
|
|
|
igmp->igmp_msgtype, group->group_state, &group, group->netif));
|
2007-08-30 14:20:54 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-06-08 12:54:40 +00:00
|
|
|
}
|
2007-08-30 14:20:54 +00:00
|
|
|
|
2007-06-08 12:54:40 +00:00
|
|
|
pbuf_free(p);
|
2007-03-11 19:45:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-06-08 12:54:40 +00:00
|
|
|
/**
|
|
|
|
* Join a group on one network interface.
|
|
|
|
*
|
2007-09-03 14:53:18 +00:00
|
|
|
* @param ifaddr ip address of the network interface which should join a new group
|
2007-06-08 12:54:40 +00:00
|
|
|
* @param groupaddr the ip address of the group which to join
|
2007-09-03 14:53:18 +00:00
|
|
|
* @return ERR_OK if group was joined on the netif(s), an err_t otherwise
|
2007-06-08 12:54:40 +00:00
|
|
|
*/
|
|
|
|
err_t
|
2010-02-04 18:47:44 +00:00
|
|
|
igmp_joingroup(ip_addr_t *ifaddr, ip_addr_t *groupaddr)
|
2007-06-08 12:54:40 +00:00
|
|
|
{
|
2007-09-03 14:53:18 +00:00
|
|
|
err_t err = ERR_VAL; /* no matching interface */
|
2007-06-08 12:54:40 +00:00
|
|
|
struct igmp_group *group;
|
2007-09-03 14:53:18 +00:00
|
|
|
struct netif *netif;
|
2007-09-03 09:56:38 +00:00
|
|
|
|
2007-08-09 16:53:47 +00:00
|
|
|
/* make sure it is multicast address */
|
2007-08-30 15:48:14 +00:00
|
|
|
LWIP_ERROR("igmp_joingroup: attempt to join non-multicast address", ip_addr_ismulticast(groupaddr), return ERR_VAL;);
|
2007-09-04 15:15:20 +00:00
|
|
|
LWIP_ERROR("igmp_joingroup: attempt to join allsystems address", (!ip_addr_cmp(groupaddr, &allsystems)), return ERR_VAL;);
|
2007-08-09 16:53:47 +00:00
|
|
|
|
2007-09-03 14:53:18 +00:00
|
|
|
/* loop through netif's */
|
|
|
|
netif = netif_list;
|
|
|
|
while (netif != NULL) {
|
|
|
|
/* Should we join this interface ? */
|
2007-09-09 20:46:33 +00:00
|
|
|
if ((netif->flags & NETIF_FLAG_IGMP) && ((ip_addr_isany(ifaddr) || ip_addr_cmp(&(netif->ip_addr), ifaddr)))) {
|
2007-09-03 14:53:18 +00:00
|
|
|
/* find group or create a new one if not found */
|
|
|
|
group = igmp_lookup_group(netif, groupaddr);
|
|
|
|
|
|
|
|
if (group != NULL) {
|
|
|
|
/* This should create a new group, check the state to make sure */
|
2007-09-04 15:15:20 +00:00
|
|
|
if (group->group_state != IGMP_GROUP_NON_MEMBER) {
|
|
|
|
LWIP_DEBUGF(IGMP_DEBUG, ("igmp_joingroup: join to group not in state IGMP_GROUP_NON_MEMBER\n"));
|
2007-09-03 14:53:18 +00:00
|
|
|
} else {
|
|
|
|
/* OK - it was new group */
|
|
|
|
LWIP_DEBUGF(IGMP_DEBUG, ("igmp_joingroup: join to new group: "));
|
|
|
|
ip_addr_debug_print(IGMP_DEBUG, groupaddr);
|
|
|
|
LWIP_DEBUGF(IGMP_DEBUG, ("\n"));
|
|
|
|
|
2007-09-04 15:15:20 +00:00
|
|
|
/* If first use of the group, allow the group at the MAC level */
|
|
|
|
if ((group->use==0) && (netif->igmp_mac_filter != NULL)) {
|
|
|
|
LWIP_DEBUGF(IGMP_DEBUG, ("igmp_joingroup: igmp_mac_filter(ADD "));
|
|
|
|
ip_addr_debug_print(IGMP_DEBUG, groupaddr);
|
2009-02-18 20:37:09 +00:00
|
|
|
LWIP_DEBUGF(IGMP_DEBUG, (") on if %p\n", netif));
|
2007-09-03 14:53:18 +00:00
|
|
|
netif->igmp_mac_filter(netif, groupaddr, IGMP_ADD_MAC_FILTER);
|
|
|
|
}
|
|
|
|
|
|
|
|
IGMP_STATS_INC(igmp.join_sent);
|
|
|
|
igmp_send(group, IGMP_V2_MEMB_REPORT);
|
|
|
|
|
|
|
|
igmp_start_timer(group, IGMP_JOIN_DELAYING_MEMBER_TMR);
|
|
|
|
|
|
|
|
/* Need to work out where this timer comes from */
|
2007-09-04 15:15:20 +00:00
|
|
|
group->group_state = IGMP_GROUP_DELAYING_MEMBER;
|
2007-09-03 14:53:18 +00:00
|
|
|
}
|
2007-09-04 15:15:20 +00:00
|
|
|
/* Increment group use */
|
|
|
|
group->use++;
|
2007-09-03 14:53:18 +00:00
|
|
|
/* Join on this interface */
|
|
|
|
err = ERR_OK;
|
|
|
|
} else {
|
|
|
|
/* Return an error even if some network interfaces are joined */
|
|
|
|
/** @todo undo any other netif already joined */
|
|
|
|
LWIP_DEBUGF(IGMP_DEBUG, ("igmp_joingroup: Not enought memory to join to group\n"));
|
|
|
|
return ERR_MEM;
|
|
|
|
}
|
2007-06-08 12:54:40 +00:00
|
|
|
}
|
2007-09-03 14:53:18 +00:00
|
|
|
/* proceed to next network interface */
|
|
|
|
netif = netif->next;
|
2007-06-08 12:54:40 +00:00
|
|
|
}
|
2007-03-11 19:45:32 +00:00
|
|
|
|
2007-09-03 14:53:18 +00:00
|
|
|
return err;
|
2007-03-11 19:45:32 +00:00
|
|
|
}
|
|
|
|
|
2007-06-08 12:54:40 +00:00
|
|
|
/**
|
|
|
|
* Leave a group on one network interface.
|
|
|
|
*
|
2007-09-03 14:53:18 +00:00
|
|
|
* @param ifaddr ip address of the network interface which should leave a group
|
2007-06-08 12:54:40 +00:00
|
|
|
* @param groupaddr the ip address of the group which to leave
|
2007-09-03 14:53:18 +00:00
|
|
|
* @return ERR_OK if group was left on the netif(s), an err_t otherwise
|
2007-06-08 12:54:40 +00:00
|
|
|
*/
|
|
|
|
err_t
|
2010-02-04 18:47:44 +00:00
|
|
|
igmp_leavegroup(ip_addr_t *ifaddr, ip_addr_t *groupaddr)
|
2007-06-08 12:54:40 +00:00
|
|
|
{
|
2007-09-03 14:53:18 +00:00
|
|
|
err_t err = ERR_VAL; /* no matching interface */
|
2007-06-08 12:54:40 +00:00
|
|
|
struct igmp_group *group;
|
2007-09-03 14:53:18 +00:00
|
|
|
struct netif *netif;
|
2007-09-03 09:56:38 +00:00
|
|
|
|
2007-08-30 15:48:14 +00:00
|
|
|
/* make sure it is multicast address */
|
|
|
|
LWIP_ERROR("igmp_leavegroup: attempt to leave non-multicast address", ip_addr_ismulticast(groupaddr), return ERR_VAL;);
|
2007-09-04 15:15:20 +00:00
|
|
|
LWIP_ERROR("igmp_leavegroup: attempt to leave allsystems address", (!ip_addr_cmp(groupaddr, &allsystems)), return ERR_VAL;);
|
2007-08-30 15:48:14 +00:00
|
|
|
|
2007-09-03 14:53:18 +00:00
|
|
|
/* loop through netif's */
|
|
|
|
netif = netif_list;
|
|
|
|
while (netif != NULL) {
|
|
|
|
/* Should we leave this interface ? */
|
2007-09-09 20:46:33 +00:00
|
|
|
if ((netif->flags & NETIF_FLAG_IGMP) && ((ip_addr_isany(ifaddr) || ip_addr_cmp(&(netif->ip_addr), ifaddr)))) {
|
2007-09-03 14:53:18 +00:00
|
|
|
/* find group */
|
|
|
|
group = igmp_lookfor_group(netif, groupaddr);
|
|
|
|
|
|
|
|
if (group != NULL) {
|
|
|
|
/* Only send a leave if the flag is set according to the state diagram */
|
|
|
|
LWIP_DEBUGF(IGMP_DEBUG, ("igmp_leavegroup: Leaving group: "));
|
|
|
|
ip_addr_debug_print(IGMP_DEBUG, groupaddr);
|
|
|
|
LWIP_DEBUGF(IGMP_DEBUG, ("\n"));
|
|
|
|
|
2007-09-04 15:15:20 +00:00
|
|
|
/* If there is no other use of the group */
|
|
|
|
if (group->use <= 1) {
|
|
|
|
/* If we are the last reporter for this group */
|
|
|
|
if (group->last_reporter_flag) {
|
|
|
|
LWIP_DEBUGF(IGMP_DEBUG, ("igmp_leavegroup: sending leaving group\n"));
|
|
|
|
IGMP_STATS_INC(igmp.leave_sent);
|
|
|
|
igmp_send(group, IGMP_LEAVE_GROUP);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Disable the group at the MAC level */
|
|
|
|
if (netif->igmp_mac_filter != NULL) {
|
|
|
|
LWIP_DEBUGF(IGMP_DEBUG, ("igmp_leavegroup: igmp_mac_filter(DEL "));
|
|
|
|
ip_addr_debug_print(IGMP_DEBUG, groupaddr);
|
2009-02-18 20:37:09 +00:00
|
|
|
LWIP_DEBUGF(IGMP_DEBUG, (") on if %p\n", netif));
|
2007-09-04 15:15:20 +00:00
|
|
|
netif->igmp_mac_filter(netif, groupaddr, IGMP_DEL_MAC_FILTER);
|
|
|
|
}
|
|
|
|
|
|
|
|
LWIP_DEBUGF(IGMP_DEBUG, ("igmp_leavegroup: remove group: "));
|
|
|
|
ip_addr_debug_print(IGMP_DEBUG, groupaddr);
|
|
|
|
LWIP_DEBUGF(IGMP_DEBUG, ("\n"));
|
|
|
|
|
|
|
|
/* Free the group */
|
|
|
|
igmp_remove_group(group);
|
|
|
|
} else {
|
|
|
|
/* Decrement group use */
|
|
|
|
group->use--;
|
2007-09-03 14:53:18 +00:00
|
|
|
}
|
|
|
|
/* Leave on this interface */
|
|
|
|
err = ERR_OK;
|
|
|
|
} else {
|
|
|
|
/* It's not a fatal error on "leavegroup" */
|
|
|
|
LWIP_DEBUGF(IGMP_DEBUG, ("igmp_leavegroup: not member of group\n"));
|
|
|
|
}
|
2007-06-08 12:54:40 +00:00
|
|
|
}
|
2007-09-03 14:53:18 +00:00
|
|
|
/* proceed to next network interface */
|
|
|
|
netif = netif->next;
|
2007-06-08 12:54:40 +00:00
|
|
|
}
|
2007-03-11 19:45:32 +00:00
|
|
|
|
2007-09-03 14:53:18 +00:00
|
|
|
return err;
|
2007-03-11 19:45:32 +00:00
|
|
|
}
|
|
|
|
|
2007-06-08 12:54:40 +00:00
|
|
|
/**
|
|
|
|
* The igmp timer function (both for NO_SYS=1 and =0)
|
|
|
|
* Should be called every IGMP_TMR_INTERVAL milliseconds (100 ms is default).
|
|
|
|
*/
|
|
|
|
void
|
2007-08-09 16:53:47 +00:00
|
|
|
igmp_tmr(void)
|
2007-06-08 12:54:40 +00:00
|
|
|
{
|
2007-06-11 07:27:12 +00:00
|
|
|
struct igmp_group *group = igmp_group_list;
|
2007-06-08 12:54:40 +00:00
|
|
|
|
2007-08-09 16:53:47 +00:00
|
|
|
while (group != NULL) {
|
2007-06-08 12:54:40 +00:00
|
|
|
if (group->timer != 0) {
|
|
|
|
group->timer -= 1;
|
|
|
|
if (group->timer == 0) {
|
|
|
|
igmp_timeout(group);
|
2007-03-11 19:45:32 +00:00
|
|
|
}
|
2007-06-08 12:54:40 +00:00
|
|
|
}
|
|
|
|
group = group->next;
|
|
|
|
}
|
2007-03-11 19:45:32 +00:00
|
|
|
}
|
|
|
|
|
2007-06-08 12:54:40 +00:00
|
|
|
/**
|
|
|
|
* Called if a timeout for one group is reached.
|
|
|
|
* Sends a report for this group.
|
|
|
|
*
|
|
|
|
* @param group an igmp_group for which a timeout is reached
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
igmp_timeout(struct igmp_group *group)
|
|
|
|
{
|
2007-09-04 15:15:20 +00:00
|
|
|
/* If the state is IGMP_GROUP_DELAYING_MEMBER then we send a report for this group */
|
|
|
|
if (group->group_state == IGMP_GROUP_DELAYING_MEMBER) {
|
2007-08-30 14:20:54 +00:00
|
|
|
LWIP_DEBUGF(IGMP_DEBUG, ("igmp_timeout: report membership for group with address "));
|
|
|
|
ip_addr_debug_print(IGMP_DEBUG, &(group->group_address));
|
2010-01-28 18:27:26 +00:00
|
|
|
LWIP_DEBUGF(IGMP_DEBUG, (" on if %p\n", group->netif));
|
2007-08-30 14:20:54 +00:00
|
|
|
|
2007-06-08 12:54:40 +00:00
|
|
|
igmp_send(group, IGMP_V2_MEMB_REPORT);
|
|
|
|
}
|
2007-03-11 19:45:32 +00:00
|
|
|
}
|
|
|
|
|
2007-06-08 12:54:40 +00:00
|
|
|
/**
|
|
|
|
* Start a timer for an igmp group
|
|
|
|
*
|
|
|
|
* @param group the igmp_group for which to start a timer
|
|
|
|
* @param max_time the time in multiples of IGMP_TMR_INTERVAL (decrease with
|
|
|
|
* every call to igmp_tmr())
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
igmp_start_timer(struct igmp_group *group, u8_t max_time)
|
|
|
|
{
|
2010-01-10 10:47:27 +00:00
|
|
|
group->timer = LWIP_RAND() % max_time;
|
2007-03-11 19:45:32 +00:00
|
|
|
}
|
|
|
|
|
2007-06-08 12:54:40 +00:00
|
|
|
/**
|
|
|
|
* Stop a timer for an igmp_group
|
|
|
|
*
|
|
|
|
* @param group the igmp_group for which to stop the timer
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
igmp_stop_timer(struct igmp_group *group)
|
|
|
|
{
|
|
|
|
group->timer = 0;
|
2007-03-11 19:45:32 +00:00
|
|
|
}
|
|
|
|
|
2007-08-30 14:20:54 +00:00
|
|
|
/**
|
|
|
|
* Delaying membership report for a group if necessary
|
|
|
|
*
|
|
|
|
* @param group the igmp_group for which "delaying" membership report
|
|
|
|
* @param maxresp query delay
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
igmp_delaying_member( struct igmp_group *group, u8_t maxresp)
|
|
|
|
{
|
2009-05-12 18:00:47 +00:00
|
|
|
if ((group->group_state == IGMP_GROUP_IDLE_MEMBER) ||
|
2009-07-09 10:21:16 +00:00
|
|
|
((group->group_state == IGMP_GROUP_DELAYING_MEMBER) && (maxresp > group->timer))) {
|
2007-08-30 14:20:54 +00:00
|
|
|
igmp_start_timer(group, (maxresp)/2);
|
2007-09-04 15:15:20 +00:00
|
|
|
group->group_state = IGMP_GROUP_DELAYING_MEMBER;
|
2007-08-30 14:20:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-06-08 12:54:40 +00:00
|
|
|
/**
|
2007-03-11 19:45:32 +00:00
|
|
|
* Sends an IP packet on a network interface. This function constructs the IP header
|
|
|
|
* and calculates the IP header checksum. If the source IP address is NULL,
|
|
|
|
* the IP address of the outgoing network interface is filled in as source address.
|
2007-06-08 12:54:40 +00:00
|
|
|
*
|
|
|
|
* @param p the packet to send (p->payload points to the data, e.g. next
|
|
|
|
protocol header; if dest == IP_HDRINCL, p already includes an IP
|
|
|
|
header and p->payload points to that IP header)
|
|
|
|
* @param src the source IP address to send from (if src == IP_ADDR_ANY, the
|
|
|
|
* IP address of the netif used to send is used as source address)
|
|
|
|
* @param dest the destination IP address to send the packet to
|
|
|
|
* @param ttl the TTL value to be set in the IP header
|
|
|
|
* @param proto the PROTOCOL to be set in the IP header
|
|
|
|
* @param netif the netif on which to send this packet
|
|
|
|
* @return ERR_OK if the packet was sent OK
|
|
|
|
* ERR_BUF if p doesn't have enough space for IP/LINK headers
|
|
|
|
* returns errors returned by netif->output
|
|
|
|
*/
|
|
|
|
err_t
|
2010-02-04 18:47:44 +00:00
|
|
|
igmp_ip_output_if(struct pbuf *p, ip_addr_t *src, ip_addr_t *dest,
|
2007-06-08 12:54:40 +00:00
|
|
|
u8_t ttl, u8_t proto, struct netif *netif)
|
|
|
|
{
|
2007-03-21 14:47:52 +00:00
|
|
|
/* This is the "router alert" option */
|
2009-05-12 18:00:47 +00:00
|
|
|
u16_t ra[2];
|
2008-03-17 13:40:00 +00:00
|
|
|
ra[0] = htons (ROUTER_ALERT);
|
|
|
|
ra[1] = 0x0000; /* Router shall examine packet */
|
2009-05-12 18:00:47 +00:00
|
|
|
return ip_output_if_opt(p, src, dest, ttl, 0, proto, netif, ra, ROUTER_ALERTLEN);
|
2007-03-11 19:45:32 +00:00
|
|
|
}
|
|
|
|
|
2007-06-08 12:54:40 +00:00
|
|
|
/**
|
|
|
|
* Send an igmp packet to a specific group.
|
|
|
|
*
|
2007-08-09 22:21:44 +00:00
|
|
|
* @param group the group to which to send the packet
|
2007-06-08 12:54:40 +00:00
|
|
|
* @param type the type of igmp packet to send
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
igmp_send(struct igmp_group *group, u8_t type)
|
|
|
|
{
|
2007-08-09 20:21:59 +00:00
|
|
|
struct pbuf* p = NULL;
|
|
|
|
struct igmp_msg* igmp = NULL;
|
2010-02-04 18:47:44 +00:00
|
|
|
ip_addr_t src = {0};
|
|
|
|
ip_addr_t* dest = NULL;
|
2007-03-11 19:45:32 +00:00
|
|
|
|
2008-03-17 13:40:00 +00:00
|
|
|
/* IP header + "router alert" option + IGMP header */
|
2007-06-08 12:54:40 +00:00
|
|
|
p = pbuf_alloc(PBUF_TRANSPORT, IGMP_MINLEN, PBUF_RAM);
|
2007-03-11 19:45:32 +00:00
|
|
|
|
2007-06-08 12:54:40 +00:00
|
|
|
if (p) {
|
|
|
|
igmp = p->payload;
|
2007-08-09 20:21:59 +00:00
|
|
|
LWIP_ASSERT("igmp_send: check that first pbuf can hold struct igmp_msg",
|
|
|
|
(p->len >= sizeof(struct igmp_msg)));
|
2010-01-28 18:27:26 +00:00
|
|
|
ip_addr_set(&src, &((group->netif)->ip_addr));
|
2007-03-11 19:45:32 +00:00
|
|
|
|
2007-08-09 16:53:47 +00:00
|
|
|
if (type == IGMP_V2_MEMB_REPORT) {
|
2007-06-08 12:54:40 +00:00
|
|
|
dest = &(group->group_address);
|
2007-08-09 20:09:22 +00:00
|
|
|
IGMP_STATS_INC(igmp.report_sent);
|
2007-06-08 12:54:40 +00:00
|
|
|
ip_addr_set(&(igmp->igmp_group_address), &(group->group_address));
|
|
|
|
group->last_reporter_flag = 1; /* Remember we were the last to report */
|
|
|
|
} else {
|
2007-08-09 16:53:47 +00:00
|
|
|
if (type == IGMP_LEAVE_GROUP) {
|
2007-06-08 12:54:40 +00:00
|
|
|
dest = &allrouters;
|
|
|
|
ip_addr_set(&(igmp->igmp_group_address), &(group->group_address));
|
2007-03-11 19:45:32 +00:00
|
|
|
}
|
2007-06-08 12:54:40 +00:00
|
|
|
}
|
2007-03-11 19:45:32 +00:00
|
|
|
|
2007-08-30 14:20:54 +00:00
|
|
|
if ((type == IGMP_V2_MEMB_REPORT) || (type == IGMP_LEAVE_GROUP)) {
|
|
|
|
igmp->igmp_msgtype = type;
|
|
|
|
igmp->igmp_maxresp = 0;
|
|
|
|
igmp->igmp_checksum = 0;
|
|
|
|
igmp->igmp_checksum = inet_chksum( igmp, IGMP_MINLEN);
|
2007-06-08 12:54:40 +00:00
|
|
|
|
2010-01-28 18:27:26 +00:00
|
|
|
igmp_ip_output_if(p, &src, dest, IGMP_TTL, IP_PROTO_IGMP, group->netif);
|
2007-08-30 14:20:54 +00:00
|
|
|
}
|
|
|
|
|
2009-05-12 18:00:47 +00:00
|
|
|
pbuf_free(p);
|
2007-06-08 12:54:40 +00:00
|
|
|
} else {
|
2007-08-09 16:53:47 +00:00
|
|
|
LWIP_DEBUGF(IGMP_DEBUG, ("igmp_send: not enough memory for igmp_send\n"));
|
2007-06-08 12:54:40 +00:00
|
|
|
}
|
2007-03-11 19:45:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* LWIP_IGMP */
|