/** * 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; LWIP_DEBUGF(IGMP_DEBUG, ("igmp_start: starting IGMP processing on if %p\n", (void*)netif)); group = igmp_lookup_group(netif, &allsystems); if (group != NULL) { group->group_state = IGMP_GROUP_IDLE_MEMBER; group->use++; /* Allow the igmp messages at the MAC level */ if (netif->igmp_mac_filter != NULL) { LWIP_DEBUGF(IGMP_DEBUG, ("igmp_start: igmp_mac_filter(ADD ")); ip4_addr_debug_print_val(IGMP_DEBUG, allsystems); LWIP_DEBUGF(IGMP_DEBUG, (") on if %p\n", (void*)netif)); netif->igmp_mac_filter(netif, &allsystems, IGMP_ADD_MAC_FILTER); } return ERR_OK; } return ERR_MEM; }
/** * 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 = netif_igmp_data(netif); netif_set_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_IGMP, NULL); while (group != NULL) { struct igmp_group *next = group->next; /* avoid use-after-free below */ /* disable the group at the MAC level */ if (netif->igmp_mac_filter != NULL) { LWIP_DEBUGF(IGMP_DEBUG, ("igmp_stop: igmp_mac_filter(DEL ")); ip4_addr_debug_print_val(IGMP_DEBUG, group->group_address); LWIP_DEBUGF(IGMP_DEBUG, (") on if %p\n", (void *)netif)); netif->igmp_mac_filter(netif, &(group->group_address), NETIF_DEL_MAC_FILTER); } /* free group */ memp_free(MEMP_IGMP_GROUP, group); /* move to "next" */ group = next; } return ERR_OK; }
/** * Called from ip_input() if a new IGMP packet is received. * * @param p received igmp packet, p->payload pointing to the igmp header * @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, const ip4_addr_t *dest) { struct igmp_msg *igmp; struct igmp_group *group; struct igmp_group *groupref; IGMP_STATS_INC(igmp.recv); /* Note that the length CAN be greater than 8 but only 8 are used - All are included in the checksum */ if (p->len < IGMP_MINLEN) { pbuf_free(p); IGMP_STATS_INC(igmp.lenerr); LWIP_DEBUGF(IGMP_DEBUG, ("igmp_input: length error\n")); return; } LWIP_DEBUGF(IGMP_DEBUG, ("igmp_input: message from ")); ip4_addr_debug_print_val(IGMP_DEBUG, ip4_current_header()->src); LWIP_DEBUGF(IGMP_DEBUG, (" to address ")); ip4_addr_debug_print_val(IGMP_DEBUG, ip4_current_header()->dest); LWIP_DEBUGF(IGMP_DEBUG, (" on if %p\n", (void *)inp)); /* Now calculate and check the checksum */ igmp = (struct igmp_msg *)p->payload; if (inet_chksum(igmp, p->len)) { pbuf_free(p); IGMP_STATS_INC(igmp.chkerr); LWIP_DEBUGF(IGMP_DEBUG, ("igmp_input: checksum error\n")); return; } /* Packet is ok so find an existing group */ group = igmp_lookfor_group(inp, dest); /* use the destination IP address of incoming packet */ /* If group can be found or create... */ if (!group) { pbuf_free(p); IGMP_STATS_INC(igmp.drop); LWIP_DEBUGF(IGMP_DEBUG, ("igmp_input: IGMP frame not for us\n")); return; } /* NOW ACT ON THE INCOMING MESSAGE TYPE... */ switch (igmp->igmp_msgtype) { case IGMP_MEMB_QUERY: /* IGMP_MEMB_QUERY to the "all systems" address ? */ if ((ip4_addr_cmp(dest, &allsystems)) && ip4_addr_isany(&igmp->igmp_group_address)) { /* 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.rx_v1); 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; } else { IGMP_STATS_INC(igmp.rx_general); } groupref = netif_igmp_data(inp); /* Do not send messages on the all systems group address! */ /* Skip the first group in the list, it is always the allsystems group added in igmp_start() */ if (groupref != NULL) { groupref = groupref->next; } while (groupref) { igmp_delaying_member(groupref, igmp->igmp_maxresp); groupref = groupref->next; } } else { /* IGMP_MEMB_QUERY to a specific group ? */ if (!ip4_addr_isany(&igmp->igmp_group_address)) { LWIP_DEBUGF(IGMP_DEBUG, ("igmp_input: IGMP_MEMB_QUERY to a specific group ")); ip4_addr_debug_print_val(IGMP_DEBUG, igmp->igmp_group_address); if (ip4_addr_cmp(dest, &allsystems)) { ip4_addr_t groupaddr; 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-look for the group since we used dest last time */ ip4_addr_copy(groupaddr, igmp->igmp_group_address); group = igmp_lookfor_group(inp, &groupaddr); } 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.rx_group); igmp_delaying_member(group, igmp->igmp_maxresp); } else { IGMP_STATS_INC(igmp.drop); } } else { IGMP_STATS_INC(igmp.proterr); } } break; case IGMP_V2_MEMB_REPORT: LWIP_DEBUGF(IGMP_DEBUG, ("igmp_input: IGMP_V2_MEMB_REPORT\n")); IGMP_STATS_INC(igmp.rx_report); if (group->group_state == IGMP_GROUP_DELAYING_MEMBER) { /* This is on a specific group we have already looked up */ group->timer = 0; /* stopped */ group->group_state = IGMP_GROUP_IDLE_MEMBER; group->last_reporter_flag = 0; } break; default: LWIP_DEBUGF(IGMP_DEBUG, ("igmp_input: unexpected msg %d in state %d on group %p on if %p\n", igmp->igmp_msgtype, group->group_state, (void *)&group, (void *)inp)); IGMP_STATS_INC(igmp.proterr); break; } pbuf_free(p); return; }