mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2024-10-05 22:29:49 +00:00
Let lookup_group() call lookfor_group() to reduce code size, done some work on task #1549 (function documentation) and minor changes to meet coding standard
This commit is contained in:
parent
b7603f8600
commit
a185e19bc1
@ -87,17 +87,22 @@ Steve Reynolds
|
|||||||
* Globales
|
* Globales
|
||||||
*----------------------------------------------------------------------------*/
|
*----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
struct igmp_group* GroupList;
|
struct igmp_group* group_list;
|
||||||
struct igmp_stats igmpstats;
|
struct igmp_stats igmpstats;
|
||||||
|
|
||||||
struct ip_addr allsystems;
|
struct ip_addr allsystems;
|
||||||
struct ip_addr allrouters;
|
struct ip_addr allrouters;
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/**
|
||||||
* igmp_init
|
* Initialize this module
|
||||||
*----------------------------------------------------------------------------*/
|
*
|
||||||
void igmp_init(void)
|
* Only network interfaces registered when this function is called
|
||||||
{ struct igmp_group* group;
|
* are igmp-enabled.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
igmp_init(void)
|
||||||
|
{
|
||||||
|
struct igmp_group* group;
|
||||||
struct netif* netif;
|
struct netif* netif;
|
||||||
|
|
||||||
LWIP_DEBUGF(IGMP_DEBUG, ("IGMP Initialising\n"));
|
LWIP_DEBUGF(IGMP_DEBUG, ("IGMP Initialising\n"));
|
||||||
@ -105,79 +110,101 @@ void igmp_init(void)
|
|||||||
IP4_ADDR(&allsystems, 224, 0, 0, 1);
|
IP4_ADDR(&allsystems, 224, 0, 0, 1);
|
||||||
IP4_ADDR(&allrouters, 224, 0, 0, 2);
|
IP4_ADDR(&allrouters, 224, 0, 0, 2);
|
||||||
|
|
||||||
GroupList = NULL;
|
group_list = NULL;
|
||||||
memset(&igmpstats, 0, sizeof(igmpstats));
|
memset(&igmpstats, 0, sizeof(igmpstats));
|
||||||
|
|
||||||
for( netif = netif_list; netif != NULL; netif = netif->next)
|
for (netif = netif_list; netif != NULL; netif = netif->next) {
|
||||||
{ group = lookup_group (netif, &allsystems);
|
group = lookup_group(netif, &allsystems);
|
||||||
|
|
||||||
if (group)
|
if (group) {
|
||||||
{ group->group_state = IDLE_MEMBER;
|
group->group_state = IDLE_MEMBER;
|
||||||
|
|
||||||
/* Allow the igmp messages at the MAC level */
|
/* Allow the igmp messages at the MAC level */
|
||||||
if (netif->igmp_mac_filter!=NULL)
|
if (netif->igmp_mac_filter != NULL) {
|
||||||
{ netif->igmp_mac_filter( netif, &allsystems, IGMP_ADD_MAC_FILTER);
|
netif->igmp_mac_filter(netif, &allsystems, IGMP_ADD_MAC_FILTER);
|
||||||
netif->igmp_mac_filter(netif, &allrouters, IGMP_ADD_MAC_FILTER);
|
netif->igmp_mac_filter(netif, &allrouters, IGMP_ADD_MAC_FILTER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/**
|
||||||
* lookfor_group
|
* Search for a group in the global group_list
|
||||||
*----------------------------------------------------------------------------*/
|
*
|
||||||
struct igmp_group * lookfor_group( struct netif *ifp, struct ip_addr *addr)
|
* @param ifp the network interfacefor which to look
|
||||||
{ struct igmp_group *group = GroupList;
|
* @param addr the group ip address to search
|
||||||
|
* @return a struct igmp_group* if the group has been found,
|
||||||
|
* NULL if the group wasn't found.
|
||||||
|
*/
|
||||||
|
struct igmp_group *
|
||||||
|
lookfor_group(struct netif *ifp, struct ip_addr *addr)
|
||||||
|
{
|
||||||
|
struct igmp_group *group = group_list;
|
||||||
|
|
||||||
while (group)
|
while (group) {
|
||||||
{ if ((group->interface == ifp) && (ip_addr_cmp (&(group->group_address), addr)))
|
if ((group->interface == ifp) && (ip_addr_cmp(&(group->group_address), addr))) {
|
||||||
{ return group;
|
return group;
|
||||||
}
|
}
|
||||||
group = group->next;
|
group = group->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* to be clearer, we return NULL here instead of
|
||||||
|
* 'group' (which is also NULL at this point).
|
||||||
|
*/
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Search for a specific igmp group and create a new one if not found-
|
||||||
|
*
|
||||||
|
* @param ifp the network interfacefor which to look
|
||||||
|
* @param addr the group ip address to search
|
||||||
|
* @return a struct igmp_group*,
|
||||||
|
* NULL on memory error.
|
||||||
|
*/
|
||||||
|
struct igmp_group *
|
||||||
|
lookup_group(struct netif *ifp, struct ip_addr *addr)
|
||||||
|
{
|
||||||
|
struct igmp_group *group = group_list;
|
||||||
|
|
||||||
|
/* Search if the group already exists */
|
||||||
|
group = lookfor_group(ifp, addr);
|
||||||
|
if (group != NULL) {
|
||||||
|
/* Group already exists. */
|
||||||
return group;
|
return group;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/* Group doesn't exist yet, create a new one. */
|
||||||
* lookup_group
|
|
||||||
*----------------------------------------------------------------------------*/
|
|
||||||
struct igmp_group * lookup_group( struct netif *ifp, struct ip_addr *addr)
|
|
||||||
{ struct igmp_group *group = GroupList;
|
|
||||||
|
|
||||||
while (group)
|
|
||||||
{ if ((group->interface == ifp) && (ip_addr_cmp (&(group->group_address), addr)))
|
|
||||||
{ return group;
|
|
||||||
}
|
|
||||||
group = group->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
group = mem_malloc(sizeof(struct igmp_group));
|
group = mem_malloc(sizeof(struct igmp_group));
|
||||||
|
if (group) {
|
||||||
if (group)
|
group->interface = ifp;
|
||||||
{ group->interface = ifp;
|
|
||||||
ip_addr_set(&(group->group_address), addr);
|
ip_addr_set(&(group->group_address), addr);
|
||||||
group->timer = 0; /* Not running */
|
group->timer = 0; /* Not running */
|
||||||
group->group_state = NON_MEMBER;
|
group->group_state = NON_MEMBER;
|
||||||
group->last_reporter_flag = 0;
|
group->last_reporter_flag = 0;
|
||||||
group->next = GroupList;
|
group->next = group_list;
|
||||||
|
|
||||||
GroupList = group;
|
group_list = group;
|
||||||
|
|
||||||
LWIP_DEBUGF(IGMP_DEBUG, ("igmp.c,Line %d allocated a new group with address %x on if %x \n", __LINE__, (int) addr, (int) ifp));
|
LWIP_DEBUGF(IGMP_DEBUG, ("igmp.c,Line %d allocated a new group with address %x on if %x \n", __LINE__, (int) addr, (int) ifp));
|
||||||
}
|
} else {
|
||||||
else
|
LWIP_DEBUGF(IGMP_DEBUG, ("igmp.c,Line %d impossible to allocated a new group with address %x on if %x \n", __LINE__, (int) addr, (int) ifp));
|
||||||
{ LWIP_DEBUGF(IGMP_DEBUG, ("igmp.c,Line %d impossible to allocated a new group with address %x on if %x \n", __LINE__, (int) addr, (int) ifp));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return group;
|
return group;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/**
|
||||||
* igmp_input
|
* Called from ip_input() if a new IGMP packet is received.
|
||||||
*----------------------------------------------------------------------------*/
|
*
|
||||||
void igmp_input( struct pbuf *p, struct netif *inp, struct ip_addr *dest)
|
* @param p received igmp packet, p->payload pointing to the ip header
|
||||||
{ struct ip_hdr * iphdr;
|
* @param inp network interface on which the packet was received
|
||||||
|
* @param dest destination ip address of the igmp packet
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
igmp_input(struct pbuf *p, struct netif *inp, struct ip_addr *dest)
|
||||||
|
{
|
||||||
|
struct ip_hdr * iphdr;
|
||||||
struct igmpmsg* igmp;
|
struct igmpmsg* igmp;
|
||||||
struct igmp_group* group;
|
struct igmp_group* group;
|
||||||
struct igmp_group* groupref;
|
struct igmp_group* groupref;
|
||||||
@ -187,8 +214,8 @@ void igmp_input( struct pbuf *p, struct netif *inp, struct ip_addr *dest)
|
|||||||
|
|
||||||
LWIP_DEBUGF(IGMP_DEBUG, ("igmp message to address %l \n", (long)dest->addr));
|
LWIP_DEBUGF(IGMP_DEBUG, ("igmp message to address %l \n", (long)dest->addr));
|
||||||
|
|
||||||
if (p->len < IGMP_MINLEN)
|
if (p->len < IGMP_MINLEN) {
|
||||||
{ /* Note that the length CAN be greater than 8 but only 8 are used - All are included in the checksum */
|
/* Note that the length CAN be greater than 8 but only 8 are used - All are included in the checksum */
|
||||||
pbuf_free(p);
|
pbuf_free(p);
|
||||||
igmpstats.igmp_length_err++;
|
igmpstats.igmp_length_err++;
|
||||||
LWIP_DEBUGF(IGMP_DEBUG, ("igmp.c,Line %x igmp length error\n", __LINE__));
|
LWIP_DEBUGF(IGMP_DEBUG, ("igmp.c,Line %x igmp length error\n", __LINE__));
|
||||||
@ -196,8 +223,8 @@ void igmp_input( struct pbuf *p, struct netif *inp, struct ip_addr *dest)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Now calculate and check the checksum */
|
/* Now calculate and check the checksum */
|
||||||
if (inet_chksum (igmp, IGMP_MINLEN /*p->len*/))
|
if (inet_chksum(igmp, IGMP_MINLEN /*p->len*/)) {
|
||||||
{ pbuf_free (p);
|
pbuf_free(p);
|
||||||
igmpstats.igmp_checksum_err++;
|
igmpstats.igmp_checksum_err++;
|
||||||
LWIP_DEBUGF(IGMP_DEBUG, ("igmp.c,Line %d igmp checksum error\n", __LINE__));
|
LWIP_DEBUGF(IGMP_DEBUG, ("igmp.c,Line %d igmp checksum error\n", __LINE__));
|
||||||
return;
|
return;
|
||||||
@ -207,8 +234,8 @@ void igmp_input( struct pbuf *p, struct netif *inp, struct ip_addr *dest)
|
|||||||
group = lookup_group(inp, dest); /* use the incoming IP address! */
|
group = lookup_group(inp, dest); /* use the incoming IP address! */
|
||||||
|
|
||||||
/* If group can be found or create... */
|
/* If group can be found or create... */
|
||||||
if (!group)
|
if (!group) {
|
||||||
{ pbuf_free (p);
|
pbuf_free(p);
|
||||||
LWIP_DEBUGF(IGMP_DEBUG, ("igmp.c,Line %d igmp allocation error\n", __LINE__));
|
LWIP_DEBUGF(IGMP_DEBUG, ("igmp.c,Line %d igmp allocation error\n", __LINE__));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -217,84 +244,96 @@ void igmp_input( struct pbuf *p, struct netif *inp, struct ip_addr *dest)
|
|||||||
|
|
||||||
/* The membership query message goes to the all groups address */
|
/* The membership query message goes to the all groups address */
|
||||||
/* and it control block does not have state */
|
/* and it control block does not have state */
|
||||||
if ((IGMP_MEMB_QUERY == igmp->igmp_msgtype) && (ip_addr_cmp (dest, &allsystems)) && (igmp->igmp_group_address.addr == 0))
|
if ((IGMP_MEMB_QUERY == igmp->igmp_msgtype) && (ip_addr_cmp(dest, &allsystems)) &&
|
||||||
{ /* THIS IS THE GENERAL QUERY */
|
(igmp->igmp_group_address.addr == 0)) {
|
||||||
|
/* THIS IS THE GENERAL QUERY */
|
||||||
LWIP_DEBUGF(IGMP_DEBUG, ("General IGMP_MEMB_QUERY on ALL SYSTEMS ADDRESS 224.0.0.1\n"));
|
LWIP_DEBUGF(IGMP_DEBUG, ("General IGMP_MEMB_QUERY on ALL SYSTEMS ADDRESS 224.0.0.1\n"));
|
||||||
|
|
||||||
if (0 ==igmp->igmp_maxresp )
|
if (0 ==igmp->igmp_maxresp) {
|
||||||
{ igmpstats.igmp_v1_rxed++;
|
igmpstats.igmp_v1_rxed++;
|
||||||
igmp->igmp_maxresp = 10;
|
igmp->igmp_maxresp = 10;
|
||||||
LWIP_DEBUGF(IGMP_DEBUG, ("igmp.c,Line %d got an all hosts query with time== 0 - this is V1 and not implemented - treat as v2\n", __LINE__));
|
LWIP_DEBUGF(IGMP_DEBUG, ("igmp.c,Line %d got an all hosts query with time== 0 - this is V1 and not implemented - treat as v2\n", __LINE__));
|
||||||
}
|
}
|
||||||
|
|
||||||
igmpstats.igmp_group_query_rxed++;
|
igmpstats.igmp_group_query_rxed++;
|
||||||
groupref = GroupList;
|
groupref = group_list;
|
||||||
while (groupref)
|
while (groupref) {
|
||||||
{ if ((groupref->interface == inp) && (!(ip_addr_cmp (&(groupref->group_address), &allsystems))))
|
if ((groupref->interface == inp) &&
|
||||||
{ /* Do not send messages on the all systems group address! */
|
(!(ip_addr_cmp(&(groupref->group_address), &allsystems)))) {
|
||||||
if ((groupref->group_state == IDLE_MEMBER) || ((groupref->group_state == DELAYING_MEMBER) && (igmp->igmp_maxresp > groupref->timer)))
|
/* Do not send messages on the all systems group address! */
|
||||||
{ igmp_start_timer (groupref, (igmp->igmp_maxresp)/2);
|
if ((groupref->group_state == IDLE_MEMBER) ||
|
||||||
|
((groupref->group_state == DELAYING_MEMBER) &&
|
||||||
|
(igmp->igmp_maxresp > groupref->timer))) {
|
||||||
|
igmp_start_timer(groupref, (igmp->igmp_maxresp)/2);
|
||||||
groupref->group_state = DELAYING_MEMBER;
|
groupref->group_state = DELAYING_MEMBER;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
groupref = groupref->next;
|
groupref = groupref->next;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
if ((IGMP_MEMB_QUERY == igmp->igmp_msgtype) && ip_addr_cmp (dest, &allsystems) &&
|
||||||
if ((IGMP_MEMB_QUERY == igmp->igmp_msgtype) && ip_addr_cmp (dest, &allsystems) && (group->group_address.addr != 0))
|
(group->group_address.addr != 0)) {
|
||||||
{ LWIP_DEBUGF(IGMP_DEBUG, ("igmp.c,Line %x got a query to a specific group using the allsystems address \n", __LINE__));
|
LWIP_DEBUGF(IGMP_DEBUG, ("igmp.c,Line %x got a query to a specific group using the allsystems address \n", __LINE__));
|
||||||
|
|
||||||
/* we first need to re-lookup the group since we used dest last time */
|
/* we first need to re-lookup the group since we used dest last time */
|
||||||
group = lookup_group(inp, &igmp->igmp_group_address); /* use the incoming IP address! */
|
group = lookup_group(inp, &igmp->igmp_group_address); /* use the incoming IP address! */
|
||||||
igmpstats.igmp_unicast_query++;
|
igmpstats.igmp_unicast_query++;
|
||||||
|
|
||||||
if ((IDLE_MEMBER == group->group_state ) || ((DELAYING_MEMBER == group->group_state ) && (igmp->igmp_maxresp > group->timer)))
|
if ((IDLE_MEMBER == group->group_state ) || ((DELAYING_MEMBER == group->group_state) &&
|
||||||
{ igmp_start_timer (group, (igmp->igmp_maxresp)/2);
|
(igmp->igmp_maxresp > group->timer))) {
|
||||||
|
igmp_start_timer(group, (igmp->igmp_maxresp)/2);
|
||||||
group->group_state = DELAYING_MEMBER;
|
group->group_state = DELAYING_MEMBER;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
if ((IGMP_MEMB_QUERY == igmp->igmp_msgtype) && !(ip_addr_cmp (dest, &allsystems)) &&
|
||||||
if ((IGMP_MEMB_QUERY == igmp->igmp_msgtype) && !(ip_addr_cmp (dest, &allsystems)) && (group->group_address.addr != 0))
|
(group->group_address.addr != 0)) {
|
||||||
{ LWIP_DEBUGF(IGMP_DEBUG, ("igmp.c,Line %x got a query to a specific group with the group address as destination \n", __LINE__));
|
LWIP_DEBUGF(IGMP_DEBUG, ("igmp.c,Line %x got a query to a specific group with the group address as destination \n", __LINE__));
|
||||||
|
|
||||||
igmpstats.igmp_unicast_query++; /* This is the unicast query */
|
igmpstats.igmp_unicast_query++; /* This is the unicast query */
|
||||||
if ((IDLE_MEMBER == group->group_state ) || ((DELAYING_MEMBER == group->group_state ) && (igmp->igmp_maxresp > group->timer)))
|
if ((IDLE_MEMBER == group->group_state) || ((DELAYING_MEMBER == group->group_state) &&
|
||||||
{ igmp_start_timer (group, (igmp->igmp_maxresp)/2);
|
(igmp->igmp_maxresp > group->timer))) {
|
||||||
|
igmp_start_timer(group, (igmp->igmp_maxresp)/2);
|
||||||
group->group_state = DELAYING_MEMBER;
|
group->group_state = DELAYING_MEMBER;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
if (IGMP_V2_MEMB_REPORT == igmp->igmp_msgtype) {
|
||||||
if (IGMP_V2_MEMB_REPORT == igmp->igmp_msgtype )
|
LWIP_DEBUGF(IGMP_DEBUG, ("igmp.c,Line %x got an IGMP_V2_MEMB_REPORT \n", __LINE__));
|
||||||
{ LWIP_DEBUGF(IGMP_DEBUG, ("igmp.c,Line %x got an IGMP_V2_MEMB_REPORT \n", __LINE__));
|
|
||||||
|
|
||||||
igmpstats.report_rxed++;
|
igmpstats.report_rxed++;
|
||||||
if (DELAYING_MEMBER == group->group_state )
|
if (DELAYING_MEMBER == group->group_state) {
|
||||||
{ /* This is on a specific group we have already looked up */
|
/* This is on a specific group we have already looked up */
|
||||||
group->timer = 0; /* stopped */
|
group->timer = 0; /* stopped */
|
||||||
group->group_state = IDLE_MEMBER;
|
group->group_state = IDLE_MEMBER;
|
||||||
group->last_reporter_flag = 0;
|
group->last_reporter_flag = 0;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
LWIP_DEBUGF(IGMP_DEBUG, ("igmp_input, Line %x unexpected msg %x in state %x on group %x at interface %x\n", __LINE__, (int) igmp->igmp_msgtype, (int) group->group_state, (int) &group, (int) group->interface));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{ LWIP_DEBUGF(IGMP_DEBUG, ("igmp_input, Line %x unexpected msg %x in state %x on group %x at interface %x\n", __LINE__, (int) igmp->igmp_msgtype, (int) group->group_state, (int) &group, (int) group->interface));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pbuf_free(p);
|
pbuf_free(p);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/**
|
||||||
* igmp_joingroup
|
* Join a group on one network interface.
|
||||||
*----------------------------------------------------------------------------*/
|
*
|
||||||
err_t igmp_joingroup( struct netif *ifp, struct ip_addr *groupaddr)
|
* @param ifp the network interface which should join a new group
|
||||||
{ struct igmp_group *group;
|
* @param groupaddr the ip address of the group which to join
|
||||||
|
* @return ERR_OK if group was joined, an err_t otherwise
|
||||||
|
*/
|
||||||
|
err_t
|
||||||
|
igmp_joingroup(struct netif *ifp, struct ip_addr *groupaddr)
|
||||||
|
{
|
||||||
|
struct igmp_group *group;
|
||||||
|
|
||||||
group = lookup_group(ifp, groupaddr);
|
group = lookup_group(ifp, groupaddr);
|
||||||
|
|
||||||
if (group)
|
if (group) {
|
||||||
{ /* This should create a new group, check the state to make sure */
|
/* This should create a new group, check the state to make sure */
|
||||||
if (group->group_state != NON_MEMBER)
|
if (group->group_state != NON_MEMBER) {
|
||||||
{ LWIP_DEBUGF(IGMP_DEBUG, ("igmp.c Line %x join to group not in state NON_MEMBER\n", __LINE__));
|
LWIP_DEBUGF(IGMP_DEBUG, ("igmp.c Line %x join to group not in state NON_MEMBER\n", __LINE__));
|
||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -303,8 +342,8 @@ err_t igmp_joingroup( struct netif *ifp, struct ip_addr *groupaddr)
|
|||||||
|
|
||||||
LWIP_DEBUGF(IGMP_DEBUG, ("igmp join to new group\n"));
|
LWIP_DEBUGF(IGMP_DEBUG, ("igmp join to new group\n"));
|
||||||
|
|
||||||
if (ifp->igmp_mac_filter!=NULL)
|
if (ifp->igmp_mac_filter != NULL) {
|
||||||
{ ifp->igmp_mac_filter( ifp, groupaddr, IGMP_ADD_MAC_FILTER);
|
ifp->igmp_mac_filter(ifp, groupaddr, IGMP_ADD_MAC_FILTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
igmp_send(group, IGMP_V2_MEMB_REPORT);
|
igmp_send(group, IGMP_V2_MEMB_REPORT);
|
||||||
@ -320,18 +359,24 @@ err_t igmp_joingroup( struct netif *ifp, struct ip_addr *groupaddr)
|
|||||||
return ERR_MEM;
|
return ERR_MEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/**
|
||||||
* igmp_leavegroup
|
* Leave a group on one network interface.
|
||||||
*----------------------------------------------------------------------------*/
|
*
|
||||||
err_t igmp_leavegroup( struct netif *ifp, struct ip_addr *groupaddr)
|
* @param ifp the network interface which should leave a group
|
||||||
{ struct igmp_group *group;
|
* @param groupaddr the ip address of the group which to leave
|
||||||
|
* @return ERR_OK if group was left, an err_t otherwise
|
||||||
|
*/
|
||||||
|
err_t
|
||||||
|
igmp_leavegroup(struct netif *ifp, struct ip_addr *groupaddr)
|
||||||
|
{
|
||||||
|
struct igmp_group *group;
|
||||||
|
|
||||||
group = lookup_group(ifp, groupaddr);
|
group = lookup_group(ifp, groupaddr);
|
||||||
|
|
||||||
if (group)
|
if (group) {
|
||||||
{ /* Only send a leave if the flag is set according to the state diagram */
|
/* Only send a leave if the flag is set according to the state diagram */
|
||||||
if (group->last_reporter_flag)
|
if (group->last_reporter_flag) {
|
||||||
{ LWIP_DEBUGF(IGMP_DEBUG, ("igmp.c Line %x Leaving group\n", __LINE__));
|
LWIP_DEBUGF(IGMP_DEBUG, ("igmp.c Line %x Leaving group\n", __LINE__));
|
||||||
igmpstats.igmp_leave_sent++;
|
igmpstats.igmp_leave_sent++;
|
||||||
igmp_send(group, IGMP_LEAVE_GROUP);
|
igmp_send(group, IGMP_LEAVE_GROUP);
|
||||||
}
|
}
|
||||||
@ -341,8 +386,8 @@ err_t igmp_leavegroup( struct netif *ifp, struct ip_addr *groupaddr)
|
|||||||
group->group_state = NON_MEMBER;
|
group->group_state = NON_MEMBER;
|
||||||
group->timer = 0;
|
group->timer = 0;
|
||||||
|
|
||||||
if (ifp->igmp_mac_filter!=NULL)
|
if (ifp->igmp_mac_filter != NULL) {
|
||||||
{ ifp->igmp_mac_filter( ifp, groupaddr, IGMP_DEL_MAC_FILTER);
|
ifp->igmp_mac_filter(ifp, groupaddr, IGMP_DEL_MAC_FILTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
@ -351,65 +396,99 @@ err_t igmp_leavegroup( struct netif *ifp, struct ip_addr *groupaddr)
|
|||||||
return ERR_MEM;
|
return ERR_MEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/**
|
||||||
* igmp_tmr
|
* The igmp timer function (both for NO_SYS=1 and =0)
|
||||||
*----------------------------------------------------------------------------*/
|
* Should be called every IGMP_TMR_INTERVAL milliseconds (100 ms is default).
|
||||||
void igmp_tmr()
|
*/
|
||||||
{ struct igmp_group *group = GroupList;
|
void
|
||||||
|
igmp_tmr()
|
||||||
|
{
|
||||||
|
struct igmp_group *group = group_list;
|
||||||
|
|
||||||
while (group)
|
while (group) {
|
||||||
{ if (group->timer != 0)
|
if (group->timer != 0) {
|
||||||
{ group->timer -=1;
|
group->timer -= 1;
|
||||||
if (group->timer == 0)
|
if (group->timer == 0) {
|
||||||
{ igmp_timeout (group);
|
igmp_timeout(group);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
group = group->next;
|
group = group->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/**
|
||||||
* igmp_timeout
|
* Called if a timeout for one group is reached.
|
||||||
*----------------------------------------------------------------------------*/
|
* Sends a report for this group.
|
||||||
void igmp_timeout( struct igmp_group *group)
|
*
|
||||||
{ /* If the state is DELAYING_MEMBER then we send a report for this group */
|
* @param group an igmp_group for which a timeout is reached
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
igmp_timeout(struct igmp_group *group)
|
||||||
|
{
|
||||||
|
/* If the state is DELAYING_MEMBER then we send a report for this group */
|
||||||
LWIP_DEBUGF(IGMP_DEBUG, ("igmp.c, got a timeout\n"));
|
LWIP_DEBUGF(IGMP_DEBUG, ("igmp.c, got a timeout\n"));
|
||||||
|
|
||||||
if (DELAYING_MEMBER == group->group_state)
|
if (DELAYING_MEMBER == group->group_state) {
|
||||||
{ igmp_send( group, IGMP_V2_MEMB_REPORT);
|
igmp_send(group, IGMP_V2_MEMB_REPORT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/**
|
||||||
* igmp_start_timer
|
* Start a timer for an igmp group
|
||||||
*----------------------------------------------------------------------------*/
|
*
|
||||||
void igmp_start_timer( struct igmp_group *group, u8_t max_time)
|
* @param group the igmp_group for which to start a timer
|
||||||
{ /* Important !! this should be random 0 -> max_time */
|
* @param max_time the time in multiples of IGMP_TMR_INTERVAL (decrease with
|
||||||
/* find out how to do this */
|
* every call to igmp_tmr())
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
igmp_start_timer(struct igmp_group *group, u8_t max_time)
|
||||||
|
{
|
||||||
|
/* Important !! this should be random 0 -> max_time
|
||||||
|
* find out how to do this
|
||||||
|
*/
|
||||||
group->timer = max_time;
|
group->timer = max_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/**
|
||||||
* igmp_stop_timer
|
* Stop a timer for an igmp_group
|
||||||
*----------------------------------------------------------------------------*/
|
*
|
||||||
void igmp_stop_timer( struct igmp_group *group)
|
* @param group the igmp_group for which to stop the timer
|
||||||
{ group->timer = 0;
|
*/
|
||||||
|
void
|
||||||
|
igmp_stop_timer(struct igmp_group *group)
|
||||||
|
{
|
||||||
|
group->timer = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/**
|
||||||
* igmp_ip_output_if
|
|
||||||
* Sends an IP packet on a network interface. This function constructs the IP header
|
* 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,
|
* 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.
|
* the IP address of the outgoing network interface is filled in as source address.
|
||||||
*----------------------------------------------------------------------------*/
|
*
|
||||||
err_t igmp_ip_output_if( struct pbuf *p, struct ip_addr *src, struct ip_addr *dest, u8_t ttl, u8_t proto, struct netif *netif)
|
* @param p the packet to send (p->payload points to the data, e.g. next
|
||||||
{ static struct ip_hdr * iphdr = NULL;
|
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
|
||||||
|
igmp_ip_output_if(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
|
||||||
|
u8_t ttl, u8_t proto, struct netif *netif)
|
||||||
|
{
|
||||||
|
static struct ip_hdr * iphdr = NULL;
|
||||||
static u16_t ip_id = 0;
|
static u16_t ip_id = 0;
|
||||||
u16_t * ra = NULL;
|
u16_t * ra = NULL;
|
||||||
|
|
||||||
/* First write in the "router alert" */
|
/* First write in the "router alert" */
|
||||||
if (pbuf_header (p, ROUTER_ALERTLEN))
|
if (pbuf_header(p, ROUTER_ALERTLEN)) {
|
||||||
{ LWIP_DEBUGF(IGMP_DEBUG, ("igmp_ip_output_if: not enough room for IP header in pbuf\n"));
|
LWIP_DEBUGF(IGMP_DEBUG, ("igmp_ip_output_if: not enough room for IP header in pbuf\n"));
|
||||||
return ERR_BUF;
|
return ERR_BUF;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -419,14 +498,14 @@ err_t igmp_ip_output_if( struct pbuf *p, struct ip_addr *src, struct ip_addr *de
|
|||||||
ra[1] = 0x0000;
|
ra[1] = 0x0000;
|
||||||
|
|
||||||
/* now the normal ip header */
|
/* now the normal ip header */
|
||||||
if (pbuf_header (p, IP_HLEN))
|
if (pbuf_header(p, IP_HLEN)) {
|
||||||
{ LWIP_DEBUGF(IGMP_DEBUG, ("igmp_ip_output_if: not enough room for IP header in pbuf\n"));
|
LWIP_DEBUGF(IGMP_DEBUG, ("igmp_ip_output_if: not enough room for IP header in pbuf\n"));
|
||||||
return ERR_BUF;
|
return ERR_BUF;
|
||||||
}
|
}
|
||||||
|
|
||||||
iphdr = p->payload;
|
iphdr = p->payload;
|
||||||
if (dest != IP_HDRINCL)
|
if (dest != IP_HDRINCL) {
|
||||||
{ iphdr->_ttl_proto = (proto<<8);
|
iphdr->_ttl_proto = (proto<<8);
|
||||||
iphdr->_ttl_proto |= ttl;
|
iphdr->_ttl_proto |= ttl;
|
||||||
|
|
||||||
/* iphdr->dest = dest->addr; */
|
/* iphdr->dest = dest->addr; */
|
||||||
@ -443,18 +522,16 @@ err_t igmp_ip_output_if( struct pbuf *p, struct ip_addr *src, struct ip_addr *de
|
|||||||
iphdr->_offset = htons(0);
|
iphdr->_offset = htons(0);
|
||||||
iphdr->_id = htons(ip_id++);
|
iphdr->_id = htons(ip_id++);
|
||||||
|
|
||||||
if (ip_addr_isany (src))
|
if (ip_addr_isany(src)) {
|
||||||
{ ip_addr_set (&(iphdr->src), &(netif->ip_addr));
|
ip_addr_set(&(iphdr->src), &(netif->ip_addr));
|
||||||
}
|
} else {
|
||||||
else
|
ip_addr_set(&(iphdr->src), src);
|
||||||
{ ip_addr_set (&(iphdr->src), src);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
iphdr->_chksum = 0;
|
iphdr->_chksum = 0;
|
||||||
iphdr->_chksum = inet_chksum(iphdr, IP_HLEN + ROUTER_ALERTLEN);
|
iphdr->_chksum = inet_chksum(iphdr, IP_HLEN + ROUTER_ALERTLEN);
|
||||||
}
|
} else {
|
||||||
else
|
dest = &(iphdr->dest);
|
||||||
{ dest = &(iphdr->dest);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if IP_DEBUG
|
#if IP_DEBUG
|
||||||
@ -466,11 +543,16 @@ err_t igmp_ip_output_if( struct pbuf *p, struct ip_addr *src, struct ip_addr *de
|
|||||||
return netif->output(netif, p, dest);
|
return netif->output(netif, p, dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/**
|
||||||
* igmp_send
|
* Send an igmp packet to a specific group.
|
||||||
*----------------------------------------------------------------------------*/
|
*
|
||||||
void igmp_send( struct igmp_group *group, u8_t type)
|
* @param the group to which to send the packet
|
||||||
{ struct pbuf* p = NULL;
|
* @param type the type of igmp packet to send
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
igmp_send(struct igmp_group *group, u8_t type)
|
||||||
|
{
|
||||||
|
struct pbuf* p = NULL;
|
||||||
struct igmpmsg* igmp = NULL;
|
struct igmpmsg* igmp = NULL;
|
||||||
struct ip_addr src = {0};
|
struct ip_addr src = {0};
|
||||||
struct ip_addr* dest = NULL;
|
struct ip_addr* dest = NULL;
|
||||||
@ -478,24 +560,24 @@ void igmp_send( struct igmp_group *group, u8_t type)
|
|||||||
/* IP header + IGMP header */
|
/* IP header + IGMP header */
|
||||||
p = pbuf_alloc(PBUF_TRANSPORT, IGMP_MINLEN, PBUF_RAM);
|
p = pbuf_alloc(PBUF_TRANSPORT, IGMP_MINLEN, PBUF_RAM);
|
||||||
|
|
||||||
if (p)
|
if (p) {
|
||||||
{ igmp = p->payload;
|
igmp = p->payload;
|
||||||
ip_addr_set(&src, &((group->interface)->ip_addr));
|
ip_addr_set(&src, &((group->interface)->ip_addr));
|
||||||
|
|
||||||
if (IGMP_V2_MEMB_REPORT == type)
|
if (IGMP_V2_MEMB_REPORT == type) {
|
||||||
{ dest = &(group->group_address);
|
dest = &(group->group_address);
|
||||||
igmpstats.report_sent++;
|
igmpstats.report_sent++;
|
||||||
ip_addr_set(&(igmp->igmp_group_address), &(group->group_address));
|
ip_addr_set(&(igmp->igmp_group_address), &(group->group_address));
|
||||||
group->last_reporter_flag = 1; /* Remember we were the last to report */
|
group->last_reporter_flag = 1; /* Remember we were the last to report */
|
||||||
}
|
} else {
|
||||||
else
|
if (IGMP_LEAVE_GROUP == type) {
|
||||||
if (IGMP_LEAVE_GROUP == type)
|
dest = &allrouters;
|
||||||
{ dest = &allrouters;
|
|
||||||
ip_addr_set(&(igmp->igmp_group_address), &(group->group_address));
|
ip_addr_set(&(igmp->igmp_group_address), &(group->group_address));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ((IGMP_V2_MEMB_REPORT == type) || (IGMP_LEAVE_GROUP == type))
|
if ((IGMP_V2_MEMB_REPORT == type) || (IGMP_LEAVE_GROUP == type)) {
|
||||||
{ igmp->igmp_msgtype = type;
|
igmp->igmp_msgtype = type;
|
||||||
igmp->igmp_maxresp = 0;
|
igmp->igmp_maxresp = 0;
|
||||||
igmp->igmp_checksum = 0;
|
igmp->igmp_checksum = 0;
|
||||||
igmp->igmp_checksum = inet_chksum( igmp, IGMP_MINLEN);
|
igmp->igmp_checksum = inet_chksum( igmp, IGMP_MINLEN);
|
||||||
@ -504,9 +586,8 @@ void igmp_send( struct igmp_group *group, u8_t type)
|
|||||||
}
|
}
|
||||||
|
|
||||||
pbuf_free (p);
|
pbuf_free (p);
|
||||||
}
|
} else {
|
||||||
else
|
LWIP_DEBUGF(IGMP_DEBUG, ("IGMP, not enough memory for igmp_send\n"));
|
||||||
{ LWIP_DEBUGF(IGMP_DEBUG, ("IGMP, not enough memory for igmp_send\n"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user