![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Embedded C project:18/12/2014
Dependencies: DS1307 TextLCD mbed
NetServices/lwip/core/ipv4/igmp.c@0:8d87bc453349, 2014-12-18 (annotated)
- Committer:
- ninoderkinderen
- Date:
- Thu Dec 18 09:35:49 2014 +0000
- Revision:
- 0:8d87bc453349
Programma embedded C
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ninoderkinderen | 0:8d87bc453349 | 1 | #pragma diag_remark 177 |
ninoderkinderen | 0:8d87bc453349 | 2 | /** |
ninoderkinderen | 0:8d87bc453349 | 3 | * @file |
ninoderkinderen | 0:8d87bc453349 | 4 | * IGMP - Internet Group Management Protocol |
ninoderkinderen | 0:8d87bc453349 | 5 | * |
ninoderkinderen | 0:8d87bc453349 | 6 | */ |
ninoderkinderen | 0:8d87bc453349 | 7 | |
ninoderkinderen | 0:8d87bc453349 | 8 | /* |
ninoderkinderen | 0:8d87bc453349 | 9 | * Copyright (c) 2002 CITEL Technologies Ltd. |
ninoderkinderen | 0:8d87bc453349 | 10 | * All rights reserved. |
ninoderkinderen | 0:8d87bc453349 | 11 | * |
ninoderkinderen | 0:8d87bc453349 | 12 | * Redistribution and use in source and binary forms, with or without |
ninoderkinderen | 0:8d87bc453349 | 13 | * modification, are permitted provided that the following conditions |
ninoderkinderen | 0:8d87bc453349 | 14 | * are met: |
ninoderkinderen | 0:8d87bc453349 | 15 | * 1. Redistributions of source code must retain the above copyright |
ninoderkinderen | 0:8d87bc453349 | 16 | * notice, this list of conditions and the following disclaimer. |
ninoderkinderen | 0:8d87bc453349 | 17 | * 2. Redistributions in binary form must reproduce the above copyright |
ninoderkinderen | 0:8d87bc453349 | 18 | * notice, this list of conditions and the following disclaimer in the |
ninoderkinderen | 0:8d87bc453349 | 19 | * documentation and/or other materials provided with the distribution. |
ninoderkinderen | 0:8d87bc453349 | 20 | * 3. Neither the name of CITEL Technologies Ltd nor the names of its contributors |
ninoderkinderen | 0:8d87bc453349 | 21 | * may be used to endorse or promote products derived from this software |
ninoderkinderen | 0:8d87bc453349 | 22 | * without specific prior written permission. |
ninoderkinderen | 0:8d87bc453349 | 23 | * |
ninoderkinderen | 0:8d87bc453349 | 24 | * THIS SOFTWARE IS PROVIDED BY CITEL TECHNOLOGIES AND CONTRIBUTORS ``AS IS'' |
ninoderkinderen | 0:8d87bc453349 | 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
ninoderkinderen | 0:8d87bc453349 | 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
ninoderkinderen | 0:8d87bc453349 | 27 | * ARE DISCLAIMED. IN NO EVENT SHALL CITEL TECHNOLOGIES OR CONTRIBUTORS BE LIABLE |
ninoderkinderen | 0:8d87bc453349 | 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
ninoderkinderen | 0:8d87bc453349 | 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
ninoderkinderen | 0:8d87bc453349 | 30 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
ninoderkinderen | 0:8d87bc453349 | 31 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
ninoderkinderen | 0:8d87bc453349 | 32 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
ninoderkinderen | 0:8d87bc453349 | 33 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
ninoderkinderen | 0:8d87bc453349 | 34 | * SUCH DAMAGE. |
ninoderkinderen | 0:8d87bc453349 | 35 | * |
ninoderkinderen | 0:8d87bc453349 | 36 | * This file is a contribution to the lwIP TCP/IP stack. |
ninoderkinderen | 0:8d87bc453349 | 37 | * The Swedish Institute of Computer Science and Adam Dunkels |
ninoderkinderen | 0:8d87bc453349 | 38 | * are specifically granted permission to redistribute this |
ninoderkinderen | 0:8d87bc453349 | 39 | * source code. |
ninoderkinderen | 0:8d87bc453349 | 40 | */ |
ninoderkinderen | 0:8d87bc453349 | 41 | |
ninoderkinderen | 0:8d87bc453349 | 42 | /*------------------------------------------------------------- |
ninoderkinderen | 0:8d87bc453349 | 43 | Note 1) |
ninoderkinderen | 0:8d87bc453349 | 44 | Although the rfc requires V1 AND V2 capability |
ninoderkinderen | 0:8d87bc453349 | 45 | we will only support v2 since now V1 is very old (August 1989) |
ninoderkinderen | 0:8d87bc453349 | 46 | V1 can be added if required |
ninoderkinderen | 0:8d87bc453349 | 47 | |
ninoderkinderen | 0:8d87bc453349 | 48 | a debug print and statistic have been implemented to |
ninoderkinderen | 0:8d87bc453349 | 49 | show this up. |
ninoderkinderen | 0:8d87bc453349 | 50 | ------------------------------------------------------------- |
ninoderkinderen | 0:8d87bc453349 | 51 | ------------------------------------------------------------- |
ninoderkinderen | 0:8d87bc453349 | 52 | Note 2) |
ninoderkinderen | 0:8d87bc453349 | 53 | A query for a specific group address (as opposed to ALLHOSTS) |
ninoderkinderen | 0:8d87bc453349 | 54 | has now been implemented as I am unsure if it is required |
ninoderkinderen | 0:8d87bc453349 | 55 | |
ninoderkinderen | 0:8d87bc453349 | 56 | a debug print and statistic have been implemented to |
ninoderkinderen | 0:8d87bc453349 | 57 | show this up. |
ninoderkinderen | 0:8d87bc453349 | 58 | ------------------------------------------------------------- |
ninoderkinderen | 0:8d87bc453349 | 59 | ------------------------------------------------------------- |
ninoderkinderen | 0:8d87bc453349 | 60 | Note 3) |
ninoderkinderen | 0:8d87bc453349 | 61 | The router alert rfc 2113 is implemented in outgoing packets |
ninoderkinderen | 0:8d87bc453349 | 62 | but not checked rigorously incoming |
ninoderkinderen | 0:8d87bc453349 | 63 | ------------------------------------------------------------- |
ninoderkinderen | 0:8d87bc453349 | 64 | Steve Reynolds |
ninoderkinderen | 0:8d87bc453349 | 65 | ------------------------------------------------------------*/ |
ninoderkinderen | 0:8d87bc453349 | 66 | |
ninoderkinderen | 0:8d87bc453349 | 67 | /*----------------------------------------------------------------------------- |
ninoderkinderen | 0:8d87bc453349 | 68 | * RFC 988 - Host extensions for IP multicasting - V0 |
ninoderkinderen | 0:8d87bc453349 | 69 | * RFC 1054 - Host extensions for IP multicasting - |
ninoderkinderen | 0:8d87bc453349 | 70 | * RFC 1112 - Host extensions for IP multicasting - V1 |
ninoderkinderen | 0:8d87bc453349 | 71 | * RFC 2236 - Internet Group Management Protocol, Version 2 - V2 <- this code is based on this RFC (it's the "de facto" standard) |
ninoderkinderen | 0:8d87bc453349 | 72 | * RFC 3376 - Internet Group Management Protocol, Version 3 - V3 |
ninoderkinderen | 0:8d87bc453349 | 73 | * RFC 4604 - Using Internet Group Management Protocol Version 3... - V3+ |
ninoderkinderen | 0:8d87bc453349 | 74 | * RFC 2113 - IP Router Alert Option - |
ninoderkinderen | 0:8d87bc453349 | 75 | *----------------------------------------------------------------------------*/ |
ninoderkinderen | 0:8d87bc453349 | 76 | |
ninoderkinderen | 0:8d87bc453349 | 77 | /*----------------------------------------------------------------------------- |
ninoderkinderen | 0:8d87bc453349 | 78 | * Includes |
ninoderkinderen | 0:8d87bc453349 | 79 | *----------------------------------------------------------------------------*/ |
ninoderkinderen | 0:8d87bc453349 | 80 | |
ninoderkinderen | 0:8d87bc453349 | 81 | #include "lwip/opt.h" |
ninoderkinderen | 0:8d87bc453349 | 82 | |
ninoderkinderen | 0:8d87bc453349 | 83 | #if LWIP_IGMP /* don't build if not configured for use in lwipopts.h */ |
ninoderkinderen | 0:8d87bc453349 | 84 | |
ninoderkinderen | 0:8d87bc453349 | 85 | #include "lwip/igmp.h" |
ninoderkinderen | 0:8d87bc453349 | 86 | #include "lwip/debug.h" |
ninoderkinderen | 0:8d87bc453349 | 87 | #include "lwip/def.h" |
ninoderkinderen | 0:8d87bc453349 | 88 | #include "lwip/mem.h" |
ninoderkinderen | 0:8d87bc453349 | 89 | #include "lwip/ip.h" |
ninoderkinderen | 0:8d87bc453349 | 90 | #include "lwip/inet_chksum.h" |
ninoderkinderen | 0:8d87bc453349 | 91 | #include "lwip/netif.h" |
ninoderkinderen | 0:8d87bc453349 | 92 | #include "lwip/icmp.h" |
ninoderkinderen | 0:8d87bc453349 | 93 | #include "lwip/udp.h" |
ninoderkinderen | 0:8d87bc453349 | 94 | #include "lwip/tcp.h" |
ninoderkinderen | 0:8d87bc453349 | 95 | #include "lwip/stats.h" |
ninoderkinderen | 0:8d87bc453349 | 96 | |
ninoderkinderen | 0:8d87bc453349 | 97 | #include "string.h" |
ninoderkinderen | 0:8d87bc453349 | 98 | |
ninoderkinderen | 0:8d87bc453349 | 99 | /* |
ninoderkinderen | 0:8d87bc453349 | 100 | * IGMP constants |
ninoderkinderen | 0:8d87bc453349 | 101 | */ |
ninoderkinderen | 0:8d87bc453349 | 102 | #define IGMP_TTL 1 |
ninoderkinderen | 0:8d87bc453349 | 103 | #define IGMP_MINLEN 8 |
ninoderkinderen | 0:8d87bc453349 | 104 | #define ROUTER_ALERT 0x9404 |
ninoderkinderen | 0:8d87bc453349 | 105 | #define ROUTER_ALERTLEN 4 |
ninoderkinderen | 0:8d87bc453349 | 106 | |
ninoderkinderen | 0:8d87bc453349 | 107 | /* |
ninoderkinderen | 0:8d87bc453349 | 108 | * IGMP message types, including version number. |
ninoderkinderen | 0:8d87bc453349 | 109 | */ |
ninoderkinderen | 0:8d87bc453349 | 110 | #define IGMP_MEMB_QUERY 0x11 /* Membership query */ |
ninoderkinderen | 0:8d87bc453349 | 111 | #define IGMP_V1_MEMB_REPORT 0x12 /* Ver. 1 membership report */ |
ninoderkinderen | 0:8d87bc453349 | 112 | #define IGMP_V2_MEMB_REPORT 0x16 /* Ver. 2 membership report */ |
ninoderkinderen | 0:8d87bc453349 | 113 | #define IGMP_LEAVE_GROUP 0x17 /* Leave-group message */ |
ninoderkinderen | 0:8d87bc453349 | 114 | |
ninoderkinderen | 0:8d87bc453349 | 115 | /* Group membership states */ |
ninoderkinderen | 0:8d87bc453349 | 116 | #define IGMP_GROUP_NON_MEMBER 0 |
ninoderkinderen | 0:8d87bc453349 | 117 | #define IGMP_GROUP_DELAYING_MEMBER 1 |
ninoderkinderen | 0:8d87bc453349 | 118 | #define IGMP_GROUP_IDLE_MEMBER 2 |
ninoderkinderen | 0:8d87bc453349 | 119 | |
ninoderkinderen | 0:8d87bc453349 | 120 | /** |
ninoderkinderen | 0:8d87bc453349 | 121 | * IGMP packet format. |
ninoderkinderen | 0:8d87bc453349 | 122 | */ |
ninoderkinderen | 0:8d87bc453349 | 123 | #ifdef PACK_STRUCT_USE_INCLUDES |
ninoderkinderen | 0:8d87bc453349 | 124 | # include "arch/bpstruct.h" |
ninoderkinderen | 0:8d87bc453349 | 125 | #endif |
ninoderkinderen | 0:8d87bc453349 | 126 | PACK_STRUCT_BEGIN |
ninoderkinderen | 0:8d87bc453349 | 127 | struct igmp_msg { |
ninoderkinderen | 0:8d87bc453349 | 128 | PACK_STRUCT_FIELD(u8_t igmp_msgtype); |
ninoderkinderen | 0:8d87bc453349 | 129 | PACK_STRUCT_FIELD(u8_t igmp_maxresp); |
ninoderkinderen | 0:8d87bc453349 | 130 | PACK_STRUCT_FIELD(u16_t igmp_checksum); |
ninoderkinderen | 0:8d87bc453349 | 131 | PACK_STRUCT_FIELD(ip_addr_p_t igmp_group_address); |
ninoderkinderen | 0:8d87bc453349 | 132 | } PACK_STRUCT_STRUCT; |
ninoderkinderen | 0:8d87bc453349 | 133 | PACK_STRUCT_END |
ninoderkinderen | 0:8d87bc453349 | 134 | #ifdef PACK_STRUCT_USE_INCLUDES |
ninoderkinderen | 0:8d87bc453349 | 135 | # include "arch/epstruct.h" |
ninoderkinderen | 0:8d87bc453349 | 136 | #endif |
ninoderkinderen | 0:8d87bc453349 | 137 | |
ninoderkinderen | 0:8d87bc453349 | 138 | |
ninoderkinderen | 0:8d87bc453349 | 139 | static struct igmp_group *igmp_lookup_group(struct netif *ifp, ip_addr_t *addr); |
ninoderkinderen | 0:8d87bc453349 | 140 | static err_t igmp_remove_group(struct igmp_group *group); |
ninoderkinderen | 0:8d87bc453349 | 141 | static void igmp_timeout( struct igmp_group *group); |
ninoderkinderen | 0:8d87bc453349 | 142 | static void igmp_start_timer(struct igmp_group *group, u8_t max_time); |
ninoderkinderen | 0:8d87bc453349 | 143 | static void igmp_stop_timer(struct igmp_group *group); |
ninoderkinderen | 0:8d87bc453349 | 144 | static void igmp_delaying_member(struct igmp_group *group, u8_t maxresp); |
ninoderkinderen | 0:8d87bc453349 | 145 | static err_t igmp_ip_output_if(struct pbuf *p, ip_addr_t *src, ip_addr_t *dest, struct netif *netif); |
ninoderkinderen | 0:8d87bc453349 | 146 | static void igmp_send(struct igmp_group *group, u8_t type); |
ninoderkinderen | 0:8d87bc453349 | 147 | |
ninoderkinderen | 0:8d87bc453349 | 148 | |
ninoderkinderen | 0:8d87bc453349 | 149 | static struct igmp_group* igmp_group_list; |
ninoderkinderen | 0:8d87bc453349 | 150 | static ip_addr_t allsystems; |
ninoderkinderen | 0:8d87bc453349 | 151 | static ip_addr_t allrouters; |
ninoderkinderen | 0:8d87bc453349 | 152 | |
ninoderkinderen | 0:8d87bc453349 | 153 | |
ninoderkinderen | 0:8d87bc453349 | 154 | /** |
ninoderkinderen | 0:8d87bc453349 | 155 | * Initialize the IGMP module |
ninoderkinderen | 0:8d87bc453349 | 156 | */ |
ninoderkinderen | 0:8d87bc453349 | 157 | void |
ninoderkinderen | 0:8d87bc453349 | 158 | igmp_init(void) |
ninoderkinderen | 0:8d87bc453349 | 159 | { |
ninoderkinderen | 0:8d87bc453349 | 160 | LWIP_DEBUGF(IGMP_DEBUG, ("igmp_init: initializing\n")); |
ninoderkinderen | 0:8d87bc453349 | 161 | |
ninoderkinderen | 0:8d87bc453349 | 162 | IP4_ADDR(&allsystems, 224, 0, 0, 1); |
ninoderkinderen | 0:8d87bc453349 | 163 | IP4_ADDR(&allrouters, 224, 0, 0, 2); |
ninoderkinderen | 0:8d87bc453349 | 164 | } |
ninoderkinderen | 0:8d87bc453349 | 165 | |
ninoderkinderen | 0:8d87bc453349 | 166 | #ifdef LWIP_DEBUG |
ninoderkinderen | 0:8d87bc453349 | 167 | /** |
ninoderkinderen | 0:8d87bc453349 | 168 | * Dump global IGMP groups list |
ninoderkinderen | 0:8d87bc453349 | 169 | */ |
ninoderkinderen | 0:8d87bc453349 | 170 | void |
ninoderkinderen | 0:8d87bc453349 | 171 | igmp_dump_group_list() |
ninoderkinderen | 0:8d87bc453349 | 172 | { |
ninoderkinderen | 0:8d87bc453349 | 173 | struct igmp_group *group = igmp_group_list; |
ninoderkinderen | 0:8d87bc453349 | 174 | |
ninoderkinderen | 0:8d87bc453349 | 175 | while (group != NULL) { |
ninoderkinderen | 0:8d87bc453349 | 176 | LWIP_DEBUGF(IGMP_DEBUG, ("igmp_dump_group_list: [%"U32_F"] ", (u32_t)(group->group_state))); |
ninoderkinderen | 0:8d87bc453349 | 177 | ip_addr_debug_print(IGMP_DEBUG, &group->group_address); |
ninoderkinderen | 0:8d87bc453349 | 178 | LWIP_DEBUGF(IGMP_DEBUG, (" on if %p\n", group->netif)); |
ninoderkinderen | 0:8d87bc453349 | 179 | group = group->next; |
ninoderkinderen | 0:8d87bc453349 | 180 | } |
ninoderkinderen | 0:8d87bc453349 | 181 | LWIP_DEBUGF(IGMP_DEBUG, ("\n")); |
ninoderkinderen | 0:8d87bc453349 | 182 | } |
ninoderkinderen | 0:8d87bc453349 | 183 | #else |
ninoderkinderen | 0:8d87bc453349 | 184 | #define igmp_dump_group_list() |
ninoderkinderen | 0:8d87bc453349 | 185 | #endif /* LWIP_DEBUG */ |
ninoderkinderen | 0:8d87bc453349 | 186 | |
ninoderkinderen | 0:8d87bc453349 | 187 | /** |
ninoderkinderen | 0:8d87bc453349 | 188 | * Start IGMP processing on interface |
ninoderkinderen | 0:8d87bc453349 | 189 | * |
ninoderkinderen | 0:8d87bc453349 | 190 | * @param netif network interface on which start IGMP processing |
ninoderkinderen | 0:8d87bc453349 | 191 | */ |
ninoderkinderen | 0:8d87bc453349 | 192 | err_t |
ninoderkinderen | 0:8d87bc453349 | 193 | igmp_start(struct netif *netif) |
ninoderkinderen | 0:8d87bc453349 | 194 | { |
ninoderkinderen | 0:8d87bc453349 | 195 | struct igmp_group* group; |
ninoderkinderen | 0:8d87bc453349 | 196 | |
ninoderkinderen | 0:8d87bc453349 | 197 | LWIP_DEBUGF(IGMP_DEBUG, ("igmp_start: starting IGMP processing on if %p\n", netif)); |
ninoderkinderen | 0:8d87bc453349 | 198 | |
ninoderkinderen | 0:8d87bc453349 | 199 | group = igmp_lookup_group(netif, &allsystems); |
ninoderkinderen | 0:8d87bc453349 | 200 | |
ninoderkinderen | 0:8d87bc453349 | 201 | if (group != NULL) { |
ninoderkinderen | 0:8d87bc453349 | 202 | group->group_state = IGMP_GROUP_IDLE_MEMBER; |
ninoderkinderen | 0:8d87bc453349 | 203 | group->use++; |
ninoderkinderen | 0:8d87bc453349 | 204 | |
ninoderkinderen | 0:8d87bc453349 | 205 | /* Allow the igmp messages at the MAC level */ |
ninoderkinderen | 0:8d87bc453349 | 206 | if (netif->igmp_mac_filter != NULL) { |
ninoderkinderen | 0:8d87bc453349 | 207 | LWIP_DEBUGF(IGMP_DEBUG, ("igmp_start: igmp_mac_filter(ADD ")); |
ninoderkinderen | 0:8d87bc453349 | 208 | ip_addr_debug_print(IGMP_DEBUG, &allsystems); |
ninoderkinderen | 0:8d87bc453349 | 209 | LWIP_DEBUGF(IGMP_DEBUG, (") on if %p\n", netif)); |
ninoderkinderen | 0:8d87bc453349 | 210 | netif->igmp_mac_filter(netif, &allsystems, IGMP_ADD_MAC_FILTER); |
ninoderkinderen | 0:8d87bc453349 | 211 | } |
ninoderkinderen | 0:8d87bc453349 | 212 | |
ninoderkinderen | 0:8d87bc453349 | 213 | return ERR_OK; |
ninoderkinderen | 0:8d87bc453349 | 214 | } |
ninoderkinderen | 0:8d87bc453349 | 215 | |
ninoderkinderen | 0:8d87bc453349 | 216 | return ERR_MEM; |
ninoderkinderen | 0:8d87bc453349 | 217 | } |
ninoderkinderen | 0:8d87bc453349 | 218 | |
ninoderkinderen | 0:8d87bc453349 | 219 | /** |
ninoderkinderen | 0:8d87bc453349 | 220 | * Stop IGMP processing on interface |
ninoderkinderen | 0:8d87bc453349 | 221 | * |
ninoderkinderen | 0:8d87bc453349 | 222 | * @param netif network interface on which stop IGMP processing |
ninoderkinderen | 0:8d87bc453349 | 223 | */ |
ninoderkinderen | 0:8d87bc453349 | 224 | err_t |
ninoderkinderen | 0:8d87bc453349 | 225 | igmp_stop(struct netif *netif) |
ninoderkinderen | 0:8d87bc453349 | 226 | { |
ninoderkinderen | 0:8d87bc453349 | 227 | struct igmp_group *group = igmp_group_list; |
ninoderkinderen | 0:8d87bc453349 | 228 | struct igmp_group *prev = NULL; |
ninoderkinderen | 0:8d87bc453349 | 229 | struct igmp_group *next; |
ninoderkinderen | 0:8d87bc453349 | 230 | |
ninoderkinderen | 0:8d87bc453349 | 231 | /* look for groups joined on this interface further down the list */ |
ninoderkinderen | 0:8d87bc453349 | 232 | while (group != NULL) { |
ninoderkinderen | 0:8d87bc453349 | 233 | next = group->next; |
ninoderkinderen | 0:8d87bc453349 | 234 | /* is it a group joined on this interface? */ |
ninoderkinderen | 0:8d87bc453349 | 235 | if (group->netif == netif) { |
ninoderkinderen | 0:8d87bc453349 | 236 | /* is it the first group of the list? */ |
ninoderkinderen | 0:8d87bc453349 | 237 | if (group == igmp_group_list) { |
ninoderkinderen | 0:8d87bc453349 | 238 | igmp_group_list = next; |
ninoderkinderen | 0:8d87bc453349 | 239 | } |
ninoderkinderen | 0:8d87bc453349 | 240 | /* is there a "previous" group defined? */ |
ninoderkinderen | 0:8d87bc453349 | 241 | if (prev != NULL) { |
ninoderkinderen | 0:8d87bc453349 | 242 | prev->next = next; |
ninoderkinderen | 0:8d87bc453349 | 243 | } |
ninoderkinderen | 0:8d87bc453349 | 244 | /* disable the group at the MAC level */ |
ninoderkinderen | 0:8d87bc453349 | 245 | if (netif->igmp_mac_filter != NULL) { |
ninoderkinderen | 0:8d87bc453349 | 246 | LWIP_DEBUGF(IGMP_DEBUG, ("igmp_stop: igmp_mac_filter(DEL ")); |
ninoderkinderen | 0:8d87bc453349 | 247 | ip_addr_debug_print(IGMP_DEBUG, &group->group_address); |
ninoderkinderen | 0:8d87bc453349 | 248 | LWIP_DEBUGF(IGMP_DEBUG, (") on if %p\n", netif)); |
ninoderkinderen | 0:8d87bc453349 | 249 | netif->igmp_mac_filter(netif, &(group->group_address), IGMP_DEL_MAC_FILTER); |
ninoderkinderen | 0:8d87bc453349 | 250 | } |
ninoderkinderen | 0:8d87bc453349 | 251 | /* free group */ |
ninoderkinderen | 0:8d87bc453349 | 252 | memp_free(MEMP_IGMP_GROUP, group); |
ninoderkinderen | 0:8d87bc453349 | 253 | } else { |
ninoderkinderen | 0:8d87bc453349 | 254 | /* change the "previous" */ |
ninoderkinderen | 0:8d87bc453349 | 255 | prev = group; |
ninoderkinderen | 0:8d87bc453349 | 256 | } |
ninoderkinderen | 0:8d87bc453349 | 257 | /* move to "next" */ |
ninoderkinderen | 0:8d87bc453349 | 258 | group = next; |
ninoderkinderen | 0:8d87bc453349 | 259 | } |
ninoderkinderen | 0:8d87bc453349 | 260 | return ERR_OK; |
ninoderkinderen | 0:8d87bc453349 | 261 | } |
ninoderkinderen | 0:8d87bc453349 | 262 | |
ninoderkinderen | 0:8d87bc453349 | 263 | /** |
ninoderkinderen | 0:8d87bc453349 | 264 | * Report IGMP memberships for this interface |
ninoderkinderen | 0:8d87bc453349 | 265 | * |
ninoderkinderen | 0:8d87bc453349 | 266 | * @param netif network interface on which report IGMP memberships |
ninoderkinderen | 0:8d87bc453349 | 267 | */ |
ninoderkinderen | 0:8d87bc453349 | 268 | void |
ninoderkinderen | 0:8d87bc453349 | 269 | igmp_report_groups(struct netif *netif) |
ninoderkinderen | 0:8d87bc453349 | 270 | { |
ninoderkinderen | 0:8d87bc453349 | 271 | struct igmp_group *group = igmp_group_list; |
ninoderkinderen | 0:8d87bc453349 | 272 | |
ninoderkinderen | 0:8d87bc453349 | 273 | LWIP_DEBUGF(IGMP_DEBUG, ("igmp_report_groups: sending IGMP reports on if %p\n", netif)); |
ninoderkinderen | 0:8d87bc453349 | 274 | |
ninoderkinderen | 0:8d87bc453349 | 275 | while (group != NULL) { |
ninoderkinderen | 0:8d87bc453349 | 276 | if (group->netif == netif) { |
ninoderkinderen | 0:8d87bc453349 | 277 | igmp_delaying_member(group, IGMP_JOIN_DELAYING_MEMBER_TMR); |
ninoderkinderen | 0:8d87bc453349 | 278 | } |
ninoderkinderen | 0:8d87bc453349 | 279 | group = group->next; |
ninoderkinderen | 0:8d87bc453349 | 280 | } |
ninoderkinderen | 0:8d87bc453349 | 281 | } |
ninoderkinderen | 0:8d87bc453349 | 282 | |
ninoderkinderen | 0:8d87bc453349 | 283 | /** |
ninoderkinderen | 0:8d87bc453349 | 284 | * Search for a group in the global igmp_group_list |
ninoderkinderen | 0:8d87bc453349 | 285 | * |
ninoderkinderen | 0:8d87bc453349 | 286 | * @param ifp the network interface for which to look |
ninoderkinderen | 0:8d87bc453349 | 287 | * @param addr the group ip address to search for |
ninoderkinderen | 0:8d87bc453349 | 288 | * @return a struct igmp_group* if the group has been found, |
ninoderkinderen | 0:8d87bc453349 | 289 | * NULL if the group wasn't found. |
ninoderkinderen | 0:8d87bc453349 | 290 | */ |
ninoderkinderen | 0:8d87bc453349 | 291 | struct igmp_group * |
ninoderkinderen | 0:8d87bc453349 | 292 | igmp_lookfor_group(struct netif *ifp, ip_addr_t *addr) |
ninoderkinderen | 0:8d87bc453349 | 293 | { |
ninoderkinderen | 0:8d87bc453349 | 294 | struct igmp_group *group = igmp_group_list; |
ninoderkinderen | 0:8d87bc453349 | 295 | |
ninoderkinderen | 0:8d87bc453349 | 296 | while (group != NULL) { |
ninoderkinderen | 0:8d87bc453349 | 297 | if ((group->netif == ifp) && (ip_addr_cmp(&(group->group_address), addr))) { |
ninoderkinderen | 0:8d87bc453349 | 298 | return group; |
ninoderkinderen | 0:8d87bc453349 | 299 | } |
ninoderkinderen | 0:8d87bc453349 | 300 | group = group->next; |
ninoderkinderen | 0:8d87bc453349 | 301 | } |
ninoderkinderen | 0:8d87bc453349 | 302 | |
ninoderkinderen | 0:8d87bc453349 | 303 | /* to be clearer, we return NULL here instead of |
ninoderkinderen | 0:8d87bc453349 | 304 | * 'group' (which is also NULL at this point). |
ninoderkinderen | 0:8d87bc453349 | 305 | */ |
ninoderkinderen | 0:8d87bc453349 | 306 | return NULL; |
ninoderkinderen | 0:8d87bc453349 | 307 | } |
ninoderkinderen | 0:8d87bc453349 | 308 | |
ninoderkinderen | 0:8d87bc453349 | 309 | /** |
ninoderkinderen | 0:8d87bc453349 | 310 | * Search for a specific igmp group and create a new one if not found- |
ninoderkinderen | 0:8d87bc453349 | 311 | * |
ninoderkinderen | 0:8d87bc453349 | 312 | * @param ifp the network interface for which to look |
ninoderkinderen | 0:8d87bc453349 | 313 | * @param addr the group ip address to search |
ninoderkinderen | 0:8d87bc453349 | 314 | * @return a struct igmp_group*, |
ninoderkinderen | 0:8d87bc453349 | 315 | * NULL on memory error. |
ninoderkinderen | 0:8d87bc453349 | 316 | */ |
ninoderkinderen | 0:8d87bc453349 | 317 | struct igmp_group * |
ninoderkinderen | 0:8d87bc453349 | 318 | igmp_lookup_group(struct netif *ifp, ip_addr_t *addr) |
ninoderkinderen | 0:8d87bc453349 | 319 | { |
ninoderkinderen | 0:8d87bc453349 | 320 | struct igmp_group *group = igmp_group_list; |
ninoderkinderen | 0:8d87bc453349 | 321 | |
ninoderkinderen | 0:8d87bc453349 | 322 | /* Search if the group already exists */ |
ninoderkinderen | 0:8d87bc453349 | 323 | group = igmp_lookfor_group(ifp, addr); |
ninoderkinderen | 0:8d87bc453349 | 324 | if (group != NULL) { |
ninoderkinderen | 0:8d87bc453349 | 325 | /* Group already exists. */ |
ninoderkinderen | 0:8d87bc453349 | 326 | return group; |
ninoderkinderen | 0:8d87bc453349 | 327 | } |
ninoderkinderen | 0:8d87bc453349 | 328 | |
ninoderkinderen | 0:8d87bc453349 | 329 | /* Group doesn't exist yet, create a new one */ |
ninoderkinderen | 0:8d87bc453349 | 330 | group = (struct igmp_group *)memp_malloc(MEMP_IGMP_GROUP); |
ninoderkinderen | 0:8d87bc453349 | 331 | if (group != NULL) { |
ninoderkinderen | 0:8d87bc453349 | 332 | group->netif = ifp; |
ninoderkinderen | 0:8d87bc453349 | 333 | ip_addr_set(&(group->group_address), addr); |
ninoderkinderen | 0:8d87bc453349 | 334 | group->timer = 0; /* Not running */ |
ninoderkinderen | 0:8d87bc453349 | 335 | group->group_state = IGMP_GROUP_NON_MEMBER; |
ninoderkinderen | 0:8d87bc453349 | 336 | group->last_reporter_flag = 0; |
ninoderkinderen | 0:8d87bc453349 | 337 | group->use = 0; |
ninoderkinderen | 0:8d87bc453349 | 338 | group->next = igmp_group_list; |
ninoderkinderen | 0:8d87bc453349 | 339 | |
ninoderkinderen | 0:8d87bc453349 | 340 | igmp_group_list = group; |
ninoderkinderen | 0:8d87bc453349 | 341 | } |
ninoderkinderen | 0:8d87bc453349 | 342 | |
ninoderkinderen | 0:8d87bc453349 | 343 | LWIP_DEBUGF(IGMP_DEBUG, ("igmp_lookup_group: %sallocated a new group with address ", (group?"":"impossible to "))); |
ninoderkinderen | 0:8d87bc453349 | 344 | ip_addr_debug_print(IGMP_DEBUG, addr); |
ninoderkinderen | 0:8d87bc453349 | 345 | LWIP_DEBUGF(IGMP_DEBUG, (" on if %p\n", ifp)); |
ninoderkinderen | 0:8d87bc453349 | 346 | |
ninoderkinderen | 0:8d87bc453349 | 347 | return group; |
ninoderkinderen | 0:8d87bc453349 | 348 | } |
ninoderkinderen | 0:8d87bc453349 | 349 | |
ninoderkinderen | 0:8d87bc453349 | 350 | /** |
ninoderkinderen | 0:8d87bc453349 | 351 | * Remove a group in the global igmp_group_list |
ninoderkinderen | 0:8d87bc453349 | 352 | * |
ninoderkinderen | 0:8d87bc453349 | 353 | * @param group the group to remove from the global igmp_group_list |
ninoderkinderen | 0:8d87bc453349 | 354 | * @return ERR_OK if group was removed from the list, an err_t otherwise |
ninoderkinderen | 0:8d87bc453349 | 355 | */ |
ninoderkinderen | 0:8d87bc453349 | 356 | static err_t |
ninoderkinderen | 0:8d87bc453349 | 357 | igmp_remove_group(struct igmp_group *group) |
ninoderkinderen | 0:8d87bc453349 | 358 | { |
ninoderkinderen | 0:8d87bc453349 | 359 | err_t err = ERR_OK; |
ninoderkinderen | 0:8d87bc453349 | 360 | |
ninoderkinderen | 0:8d87bc453349 | 361 | /* Is it the first group? */ |
ninoderkinderen | 0:8d87bc453349 | 362 | if (igmp_group_list == group) { |
ninoderkinderen | 0:8d87bc453349 | 363 | igmp_group_list = group->next; |
ninoderkinderen | 0:8d87bc453349 | 364 | } else { |
ninoderkinderen | 0:8d87bc453349 | 365 | /* look for group further down the list */ |
ninoderkinderen | 0:8d87bc453349 | 366 | struct igmp_group *tmpGroup; |
ninoderkinderen | 0:8d87bc453349 | 367 | for (tmpGroup = igmp_group_list; tmpGroup != NULL; tmpGroup = tmpGroup->next) { |
ninoderkinderen | 0:8d87bc453349 | 368 | if (tmpGroup->next == group) { |
ninoderkinderen | 0:8d87bc453349 | 369 | tmpGroup->next = group->next; |
ninoderkinderen | 0:8d87bc453349 | 370 | break; |
ninoderkinderen | 0:8d87bc453349 | 371 | } |
ninoderkinderen | 0:8d87bc453349 | 372 | } |
ninoderkinderen | 0:8d87bc453349 | 373 | /* Group not found in the global igmp_group_list */ |
ninoderkinderen | 0:8d87bc453349 | 374 | if (tmpGroup == NULL) |
ninoderkinderen | 0:8d87bc453349 | 375 | err = ERR_ARG; |
ninoderkinderen | 0:8d87bc453349 | 376 | } |
ninoderkinderen | 0:8d87bc453349 | 377 | /* free group */ |
ninoderkinderen | 0:8d87bc453349 | 378 | memp_free(MEMP_IGMP_GROUP, group); |
ninoderkinderen | 0:8d87bc453349 | 379 | |
ninoderkinderen | 0:8d87bc453349 | 380 | return err; |
ninoderkinderen | 0:8d87bc453349 | 381 | } |
ninoderkinderen | 0:8d87bc453349 | 382 | |
ninoderkinderen | 0:8d87bc453349 | 383 | /** |
ninoderkinderen | 0:8d87bc453349 | 384 | * Called from ip_input() if a new IGMP packet is received. |
ninoderkinderen | 0:8d87bc453349 | 385 | * |
ninoderkinderen | 0:8d87bc453349 | 386 | * @param p received igmp packet, p->payload pointing to the ip header |
ninoderkinderen | 0:8d87bc453349 | 387 | * @param inp network interface on which the packet was received |
ninoderkinderen | 0:8d87bc453349 | 388 | * @param dest destination ip address of the igmp packet |
ninoderkinderen | 0:8d87bc453349 | 389 | */ |
ninoderkinderen | 0:8d87bc453349 | 390 | void |
ninoderkinderen | 0:8d87bc453349 | 391 | igmp_input(struct pbuf *p, struct netif *inp, ip_addr_t *dest) |
ninoderkinderen | 0:8d87bc453349 | 392 | { |
ninoderkinderen | 0:8d87bc453349 | 393 | struct ip_hdr * iphdr; |
ninoderkinderen | 0:8d87bc453349 | 394 | struct igmp_msg* igmp; |
ninoderkinderen | 0:8d87bc453349 | 395 | struct igmp_group* group; |
ninoderkinderen | 0:8d87bc453349 | 396 | struct igmp_group* groupref; |
ninoderkinderen | 0:8d87bc453349 | 397 | |
ninoderkinderen | 0:8d87bc453349 | 398 | IGMP_STATS_INC(igmp.recv); |
ninoderkinderen | 0:8d87bc453349 | 399 | |
ninoderkinderen | 0:8d87bc453349 | 400 | /* Note that the length CAN be greater than 8 but only 8 are used - All are included in the checksum */ |
ninoderkinderen | 0:8d87bc453349 | 401 | iphdr = (struct ip_hdr *)p->payload; |
ninoderkinderen | 0:8d87bc453349 | 402 | if (pbuf_header(p, -(s16_t)(IPH_HL(iphdr) * 4)) || (p->len < IGMP_MINLEN)) { |
ninoderkinderen | 0:8d87bc453349 | 403 | pbuf_free(p); |
ninoderkinderen | 0:8d87bc453349 | 404 | IGMP_STATS_INC(igmp.lenerr); |
ninoderkinderen | 0:8d87bc453349 | 405 | LWIP_DEBUGF(IGMP_DEBUG, ("igmp_input: length error\n")); |
ninoderkinderen | 0:8d87bc453349 | 406 | return; |
ninoderkinderen | 0:8d87bc453349 | 407 | } |
ninoderkinderen | 0:8d87bc453349 | 408 | |
ninoderkinderen | 0:8d87bc453349 | 409 | LWIP_DEBUGF(IGMP_DEBUG, ("igmp_input: message from ")); |
ninoderkinderen | 0:8d87bc453349 | 410 | ip_addr_debug_print(IGMP_DEBUG, &(iphdr->src)); |
ninoderkinderen | 0:8d87bc453349 | 411 | LWIP_DEBUGF(IGMP_DEBUG, (" to address ")); |
ninoderkinderen | 0:8d87bc453349 | 412 | ip_addr_debug_print(IGMP_DEBUG, &(iphdr->dest)); |
ninoderkinderen | 0:8d87bc453349 | 413 | LWIP_DEBUGF(IGMP_DEBUG, (" on if %p\n", inp)); |
ninoderkinderen | 0:8d87bc453349 | 414 | |
ninoderkinderen | 0:8d87bc453349 | 415 | /* Now calculate and check the checksum */ |
ninoderkinderen | 0:8d87bc453349 | 416 | igmp = (struct igmp_msg *)p->payload; |
ninoderkinderen | 0:8d87bc453349 | 417 | if (inet_chksum(igmp, p->len)) { |
ninoderkinderen | 0:8d87bc453349 | 418 | pbuf_free(p); |
ninoderkinderen | 0:8d87bc453349 | 419 | IGMP_STATS_INC(igmp.chkerr); |
ninoderkinderen | 0:8d87bc453349 | 420 | LWIP_DEBUGF(IGMP_DEBUG, ("igmp_input: checksum error\n")); |
ninoderkinderen | 0:8d87bc453349 | 421 | return; |
ninoderkinderen | 0:8d87bc453349 | 422 | } |
ninoderkinderen | 0:8d87bc453349 | 423 | |
ninoderkinderen | 0:8d87bc453349 | 424 | /* Packet is ok so find an existing group */ |
ninoderkinderen | 0:8d87bc453349 | 425 | group = igmp_lookfor_group(inp, dest); /* use the destination IP address of incoming packet */ |
ninoderkinderen | 0:8d87bc453349 | 426 | |
ninoderkinderen | 0:8d87bc453349 | 427 | /* If group can be found or create... */ |
ninoderkinderen | 0:8d87bc453349 | 428 | if (!group) { |
ninoderkinderen | 0:8d87bc453349 | 429 | pbuf_free(p); |
ninoderkinderen | 0:8d87bc453349 | 430 | IGMP_STATS_INC(igmp.drop); |
ninoderkinderen | 0:8d87bc453349 | 431 | LWIP_DEBUGF(IGMP_DEBUG, ("igmp_input: IGMP frame not for us\n")); |
ninoderkinderen | 0:8d87bc453349 | 432 | return; |
ninoderkinderen | 0:8d87bc453349 | 433 | } |
ninoderkinderen | 0:8d87bc453349 | 434 | |
ninoderkinderen | 0:8d87bc453349 | 435 | /* NOW ACT ON THE INCOMING MESSAGE TYPE... */ |
ninoderkinderen | 0:8d87bc453349 | 436 | switch (igmp->igmp_msgtype) { |
ninoderkinderen | 0:8d87bc453349 | 437 | case IGMP_MEMB_QUERY: { |
ninoderkinderen | 0:8d87bc453349 | 438 | /* IGMP_MEMB_QUERY to the "all systems" address ? */ |
ninoderkinderen | 0:8d87bc453349 | 439 | if ((ip_addr_cmp(dest, &allsystems)) && ip_addr_isany(&igmp->igmp_group_address)) { |
ninoderkinderen | 0:8d87bc453349 | 440 | /* THIS IS THE GENERAL QUERY */ |
ninoderkinderen | 0:8d87bc453349 | 441 | 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))); |
ninoderkinderen | 0:8d87bc453349 | 442 | |
ninoderkinderen | 0:8d87bc453349 | 443 | if (igmp->igmp_maxresp == 0) { |
ninoderkinderen | 0:8d87bc453349 | 444 | IGMP_STATS_INC(igmp.rx_v1); |
ninoderkinderen | 0:8d87bc453349 | 445 | LWIP_DEBUGF(IGMP_DEBUG, ("igmp_input: got an all hosts query with time== 0 - this is V1 and not implemented - treat as v2\n")); |
ninoderkinderen | 0:8d87bc453349 | 446 | igmp->igmp_maxresp = IGMP_V1_DELAYING_MEMBER_TMR; |
ninoderkinderen | 0:8d87bc453349 | 447 | } else { |
ninoderkinderen | 0:8d87bc453349 | 448 | IGMP_STATS_INC(igmp.rx_general); |
ninoderkinderen | 0:8d87bc453349 | 449 | } |
ninoderkinderen | 0:8d87bc453349 | 450 | |
ninoderkinderen | 0:8d87bc453349 | 451 | groupref = igmp_group_list; |
ninoderkinderen | 0:8d87bc453349 | 452 | while (groupref) { |
ninoderkinderen | 0:8d87bc453349 | 453 | /* Do not send messages on the all systems group address! */ |
ninoderkinderen | 0:8d87bc453349 | 454 | if ((groupref->netif == inp) && (!(ip_addr_cmp(&(groupref->group_address), &allsystems)))) { |
ninoderkinderen | 0:8d87bc453349 | 455 | igmp_delaying_member(groupref, igmp->igmp_maxresp); |
ninoderkinderen | 0:8d87bc453349 | 456 | } |
ninoderkinderen | 0:8d87bc453349 | 457 | groupref = groupref->next; |
ninoderkinderen | 0:8d87bc453349 | 458 | } |
ninoderkinderen | 0:8d87bc453349 | 459 | } else { |
ninoderkinderen | 0:8d87bc453349 | 460 | /* IGMP_MEMB_QUERY to a specific group ? */ |
ninoderkinderen | 0:8d87bc453349 | 461 | if (!ip_addr_isany(&igmp->igmp_group_address)) { |
ninoderkinderen | 0:8d87bc453349 | 462 | LWIP_DEBUGF(IGMP_DEBUG, ("igmp_input: IGMP_MEMB_QUERY to a specific group ")); |
ninoderkinderen | 0:8d87bc453349 | 463 | ip_addr_debug_print(IGMP_DEBUG, &igmp->igmp_group_address); |
ninoderkinderen | 0:8d87bc453349 | 464 | if (ip_addr_cmp(dest, &allsystems)) { |
ninoderkinderen | 0:8d87bc453349 | 465 | ip_addr_t groupaddr; |
ninoderkinderen | 0:8d87bc453349 | 466 | LWIP_DEBUGF(IGMP_DEBUG, (" using \"ALL SYSTEMS\" address (224.0.0.1) [igmp_maxresp=%i]\n", (int)(igmp->igmp_maxresp))); |
ninoderkinderen | 0:8d87bc453349 | 467 | /* we first need to re-look for the group since we used dest last time */ |
ninoderkinderen | 0:8d87bc453349 | 468 | ip_addr_copy(groupaddr, igmp->igmp_group_address); |
ninoderkinderen | 0:8d87bc453349 | 469 | group = igmp_lookfor_group(inp, &groupaddr); |
ninoderkinderen | 0:8d87bc453349 | 470 | } else { |
ninoderkinderen | 0:8d87bc453349 | 471 | LWIP_DEBUGF(IGMP_DEBUG, (" with the group address as destination [igmp_maxresp=%i]\n", (int)(igmp->igmp_maxresp))); |
ninoderkinderen | 0:8d87bc453349 | 472 | } |
ninoderkinderen | 0:8d87bc453349 | 473 | |
ninoderkinderen | 0:8d87bc453349 | 474 | if (group != NULL) { |
ninoderkinderen | 0:8d87bc453349 | 475 | IGMP_STATS_INC(igmp.rx_group); |
ninoderkinderen | 0:8d87bc453349 | 476 | igmp_delaying_member(group, igmp->igmp_maxresp); |
ninoderkinderen | 0:8d87bc453349 | 477 | } else { |
ninoderkinderen | 0:8d87bc453349 | 478 | IGMP_STATS_INC(igmp.drop); |
ninoderkinderen | 0:8d87bc453349 | 479 | } |
ninoderkinderen | 0:8d87bc453349 | 480 | } else { |
ninoderkinderen | 0:8d87bc453349 | 481 | IGMP_STATS_INC(igmp.proterr); |
ninoderkinderen | 0:8d87bc453349 | 482 | } |
ninoderkinderen | 0:8d87bc453349 | 483 | } |
ninoderkinderen | 0:8d87bc453349 | 484 | break; |
ninoderkinderen | 0:8d87bc453349 | 485 | } |
ninoderkinderen | 0:8d87bc453349 | 486 | case IGMP_V2_MEMB_REPORT: { |
ninoderkinderen | 0:8d87bc453349 | 487 | LWIP_DEBUGF(IGMP_DEBUG, ("igmp_input: IGMP_V2_MEMB_REPORT\n")); |
ninoderkinderen | 0:8d87bc453349 | 488 | IGMP_STATS_INC(igmp.rx_report); |
ninoderkinderen | 0:8d87bc453349 | 489 | if (group->group_state == IGMP_GROUP_DELAYING_MEMBER) { |
ninoderkinderen | 0:8d87bc453349 | 490 | /* This is on a specific group we have already looked up */ |
ninoderkinderen | 0:8d87bc453349 | 491 | group->timer = 0; /* stopped */ |
ninoderkinderen | 0:8d87bc453349 | 492 | group->group_state = IGMP_GROUP_IDLE_MEMBER; |
ninoderkinderen | 0:8d87bc453349 | 493 | group->last_reporter_flag = 0; |
ninoderkinderen | 0:8d87bc453349 | 494 | } |
ninoderkinderen | 0:8d87bc453349 | 495 | break; |
ninoderkinderen | 0:8d87bc453349 | 496 | } |
ninoderkinderen | 0:8d87bc453349 | 497 | default: { |
ninoderkinderen | 0:8d87bc453349 | 498 | LWIP_DEBUGF(IGMP_DEBUG, ("igmp_input: unexpected msg %d in state %d on group %p on if %p\n", |
ninoderkinderen | 0:8d87bc453349 | 499 | igmp->igmp_msgtype, group->group_state, &group, group->netif)); |
ninoderkinderen | 0:8d87bc453349 | 500 | IGMP_STATS_INC(igmp.proterr); |
ninoderkinderen | 0:8d87bc453349 | 501 | break; |
ninoderkinderen | 0:8d87bc453349 | 502 | } |
ninoderkinderen | 0:8d87bc453349 | 503 | } |
ninoderkinderen | 0:8d87bc453349 | 504 | |
ninoderkinderen | 0:8d87bc453349 | 505 | pbuf_free(p); |
ninoderkinderen | 0:8d87bc453349 | 506 | return; |
ninoderkinderen | 0:8d87bc453349 | 507 | } |
ninoderkinderen | 0:8d87bc453349 | 508 | |
ninoderkinderen | 0:8d87bc453349 | 509 | /** |
ninoderkinderen | 0:8d87bc453349 | 510 | * Join a group on one network interface. |
ninoderkinderen | 0:8d87bc453349 | 511 | * |
ninoderkinderen | 0:8d87bc453349 | 512 | * @param ifaddr ip address of the network interface which should join a new group |
ninoderkinderen | 0:8d87bc453349 | 513 | * @param groupaddr the ip address of the group which to join |
ninoderkinderen | 0:8d87bc453349 | 514 | * @return ERR_OK if group was joined on the netif(s), an err_t otherwise |
ninoderkinderen | 0:8d87bc453349 | 515 | */ |
ninoderkinderen | 0:8d87bc453349 | 516 | err_t |
ninoderkinderen | 0:8d87bc453349 | 517 | igmp_joingroup(ip_addr_t *ifaddr, ip_addr_t *groupaddr) |
ninoderkinderen | 0:8d87bc453349 | 518 | { |
ninoderkinderen | 0:8d87bc453349 | 519 | err_t err = ERR_VAL; /* no matching interface */ |
ninoderkinderen | 0:8d87bc453349 | 520 | struct igmp_group *group; |
ninoderkinderen | 0:8d87bc453349 | 521 | struct netif *netif; |
ninoderkinderen | 0:8d87bc453349 | 522 | |
ninoderkinderen | 0:8d87bc453349 | 523 | /* make sure it is multicast address */ |
ninoderkinderen | 0:8d87bc453349 | 524 | LWIP_ERROR("igmp_joingroup: attempt to join non-multicast address", ip_addr_ismulticast(groupaddr), return ERR_VAL;); |
ninoderkinderen | 0:8d87bc453349 | 525 | LWIP_ERROR("igmp_joingroup: attempt to join allsystems address", (!ip_addr_cmp(groupaddr, &allsystems)), return ERR_VAL;); |
ninoderkinderen | 0:8d87bc453349 | 526 | |
ninoderkinderen | 0:8d87bc453349 | 527 | /* loop through netif's */ |
ninoderkinderen | 0:8d87bc453349 | 528 | netif = netif_list; |
ninoderkinderen | 0:8d87bc453349 | 529 | while (netif != NULL) { |
ninoderkinderen | 0:8d87bc453349 | 530 | /* Should we join this interface ? */ |
ninoderkinderen | 0:8d87bc453349 | 531 | if ((netif->flags & NETIF_FLAG_IGMP) && ((ip_addr_isany(ifaddr) || ip_addr_cmp(&(netif->ip_addr), ifaddr)))) { |
ninoderkinderen | 0:8d87bc453349 | 532 | /* find group or create a new one if not found */ |
ninoderkinderen | 0:8d87bc453349 | 533 | group = igmp_lookup_group(netif, groupaddr); |
ninoderkinderen | 0:8d87bc453349 | 534 | |
ninoderkinderen | 0:8d87bc453349 | 535 | if (group != NULL) { |
ninoderkinderen | 0:8d87bc453349 | 536 | /* This should create a new group, check the state to make sure */ |
ninoderkinderen | 0:8d87bc453349 | 537 | if (group->group_state != IGMP_GROUP_NON_MEMBER) { |
ninoderkinderen | 0:8d87bc453349 | 538 | LWIP_DEBUGF(IGMP_DEBUG, ("igmp_joingroup: join to group not in state IGMP_GROUP_NON_MEMBER\n")); |
ninoderkinderen | 0:8d87bc453349 | 539 | } else { |
ninoderkinderen | 0:8d87bc453349 | 540 | /* OK - it was new group */ |
ninoderkinderen | 0:8d87bc453349 | 541 | LWIP_DEBUGF(IGMP_DEBUG, ("igmp_joingroup: join to new group: ")); |
ninoderkinderen | 0:8d87bc453349 | 542 | ip_addr_debug_print(IGMP_DEBUG, groupaddr); |
ninoderkinderen | 0:8d87bc453349 | 543 | LWIP_DEBUGF(IGMP_DEBUG, ("\n")); |
ninoderkinderen | 0:8d87bc453349 | 544 | |
ninoderkinderen | 0:8d87bc453349 | 545 | /* If first use of the group, allow the group at the MAC level */ |
ninoderkinderen | 0:8d87bc453349 | 546 | if ((group->use==0) && (netif->igmp_mac_filter != NULL)) { |
ninoderkinderen | 0:8d87bc453349 | 547 | LWIP_DEBUGF(IGMP_DEBUG, ("igmp_joingroup: igmp_mac_filter(ADD ")); |
ninoderkinderen | 0:8d87bc453349 | 548 | ip_addr_debug_print(IGMP_DEBUG, groupaddr); |
ninoderkinderen | 0:8d87bc453349 | 549 | LWIP_DEBUGF(IGMP_DEBUG, (") on if %p\n", netif)); |
ninoderkinderen | 0:8d87bc453349 | 550 | netif->igmp_mac_filter(netif, groupaddr, IGMP_ADD_MAC_FILTER); |
ninoderkinderen | 0:8d87bc453349 | 551 | } |
ninoderkinderen | 0:8d87bc453349 | 552 | |
ninoderkinderen | 0:8d87bc453349 | 553 | IGMP_STATS_INC(igmp.tx_join); |
ninoderkinderen | 0:8d87bc453349 | 554 | igmp_send(group, IGMP_V2_MEMB_REPORT); |
ninoderkinderen | 0:8d87bc453349 | 555 | |
ninoderkinderen | 0:8d87bc453349 | 556 | igmp_start_timer(group, IGMP_JOIN_DELAYING_MEMBER_TMR); |
ninoderkinderen | 0:8d87bc453349 | 557 | |
ninoderkinderen | 0:8d87bc453349 | 558 | /* Need to work out where this timer comes from */ |
ninoderkinderen | 0:8d87bc453349 | 559 | group->group_state = IGMP_GROUP_DELAYING_MEMBER; |
ninoderkinderen | 0:8d87bc453349 | 560 | } |
ninoderkinderen | 0:8d87bc453349 | 561 | /* Increment group use */ |
ninoderkinderen | 0:8d87bc453349 | 562 | group->use++; |
ninoderkinderen | 0:8d87bc453349 | 563 | /* Join on this interface */ |
ninoderkinderen | 0:8d87bc453349 | 564 | err = ERR_OK; |
ninoderkinderen | 0:8d87bc453349 | 565 | } else { |
ninoderkinderen | 0:8d87bc453349 | 566 | /* Return an error even if some network interfaces are joined */ |
ninoderkinderen | 0:8d87bc453349 | 567 | /** @todo undo any other netif already joined */ |
ninoderkinderen | 0:8d87bc453349 | 568 | LWIP_DEBUGF(IGMP_DEBUG, ("igmp_joingroup: Not enought memory to join to group\n")); |
ninoderkinderen | 0:8d87bc453349 | 569 | return ERR_MEM; |
ninoderkinderen | 0:8d87bc453349 | 570 | } |
ninoderkinderen | 0:8d87bc453349 | 571 | } |
ninoderkinderen | 0:8d87bc453349 | 572 | /* proceed to next network interface */ |
ninoderkinderen | 0:8d87bc453349 | 573 | netif = netif->next; |
ninoderkinderen | 0:8d87bc453349 | 574 | } |
ninoderkinderen | 0:8d87bc453349 | 575 | |
ninoderkinderen | 0:8d87bc453349 | 576 | return err; |
ninoderkinderen | 0:8d87bc453349 | 577 | } |
ninoderkinderen | 0:8d87bc453349 | 578 | |
ninoderkinderen | 0:8d87bc453349 | 579 | /** |
ninoderkinderen | 0:8d87bc453349 | 580 | * Leave a group on one network interface. |
ninoderkinderen | 0:8d87bc453349 | 581 | * |
ninoderkinderen | 0:8d87bc453349 | 582 | * @param ifaddr ip address of the network interface which should leave a group |
ninoderkinderen | 0:8d87bc453349 | 583 | * @param groupaddr the ip address of the group which to leave |
ninoderkinderen | 0:8d87bc453349 | 584 | * @return ERR_OK if group was left on the netif(s), an err_t otherwise |
ninoderkinderen | 0:8d87bc453349 | 585 | */ |
ninoderkinderen | 0:8d87bc453349 | 586 | err_t |
ninoderkinderen | 0:8d87bc453349 | 587 | igmp_leavegroup(ip_addr_t *ifaddr, ip_addr_t *groupaddr) |
ninoderkinderen | 0:8d87bc453349 | 588 | { |
ninoderkinderen | 0:8d87bc453349 | 589 | err_t err = ERR_VAL; /* no matching interface */ |
ninoderkinderen | 0:8d87bc453349 | 590 | struct igmp_group *group; |
ninoderkinderen | 0:8d87bc453349 | 591 | struct netif *netif; |
ninoderkinderen | 0:8d87bc453349 | 592 | |
ninoderkinderen | 0:8d87bc453349 | 593 | /* make sure it is multicast address */ |
ninoderkinderen | 0:8d87bc453349 | 594 | LWIP_ERROR("igmp_leavegroup: attempt to leave non-multicast address", ip_addr_ismulticast(groupaddr), return ERR_VAL;); |
ninoderkinderen | 0:8d87bc453349 | 595 | LWIP_ERROR("igmp_leavegroup: attempt to leave allsystems address", (!ip_addr_cmp(groupaddr, &allsystems)), return ERR_VAL;); |
ninoderkinderen | 0:8d87bc453349 | 596 | |
ninoderkinderen | 0:8d87bc453349 | 597 | /* loop through netif's */ |
ninoderkinderen | 0:8d87bc453349 | 598 | netif = netif_list; |
ninoderkinderen | 0:8d87bc453349 | 599 | while (netif != NULL) { |
ninoderkinderen | 0:8d87bc453349 | 600 | /* Should we leave this interface ? */ |
ninoderkinderen | 0:8d87bc453349 | 601 | if ((netif->flags & NETIF_FLAG_IGMP) && ((ip_addr_isany(ifaddr) || ip_addr_cmp(&(netif->ip_addr), ifaddr)))) { |
ninoderkinderen | 0:8d87bc453349 | 602 | /* find group */ |
ninoderkinderen | 0:8d87bc453349 | 603 | group = igmp_lookfor_group(netif, groupaddr); |
ninoderkinderen | 0:8d87bc453349 | 604 | |
ninoderkinderen | 0:8d87bc453349 | 605 | if (group != NULL) { |
ninoderkinderen | 0:8d87bc453349 | 606 | /* Only send a leave if the flag is set according to the state diagram */ |
ninoderkinderen | 0:8d87bc453349 | 607 | LWIP_DEBUGF(IGMP_DEBUG, ("igmp_leavegroup: Leaving group: ")); |
ninoderkinderen | 0:8d87bc453349 | 608 | ip_addr_debug_print(IGMP_DEBUG, groupaddr); |
ninoderkinderen | 0:8d87bc453349 | 609 | LWIP_DEBUGF(IGMP_DEBUG, ("\n")); |
ninoderkinderen | 0:8d87bc453349 | 610 | |
ninoderkinderen | 0:8d87bc453349 | 611 | /* If there is no other use of the group */ |
ninoderkinderen | 0:8d87bc453349 | 612 | if (group->use <= 1) { |
ninoderkinderen | 0:8d87bc453349 | 613 | /* If we are the last reporter for this group */ |
ninoderkinderen | 0:8d87bc453349 | 614 | if (group->last_reporter_flag) { |
ninoderkinderen | 0:8d87bc453349 | 615 | LWIP_DEBUGF(IGMP_DEBUG, ("igmp_leavegroup: sending leaving group\n")); |
ninoderkinderen | 0:8d87bc453349 | 616 | IGMP_STATS_INC(igmp.tx_leave); |
ninoderkinderen | 0:8d87bc453349 | 617 | igmp_send(group, IGMP_LEAVE_GROUP); |
ninoderkinderen | 0:8d87bc453349 | 618 | } |
ninoderkinderen | 0:8d87bc453349 | 619 | |
ninoderkinderen | 0:8d87bc453349 | 620 | /* Disable the group at the MAC level */ |
ninoderkinderen | 0:8d87bc453349 | 621 | if (netif->igmp_mac_filter != NULL) { |
ninoderkinderen | 0:8d87bc453349 | 622 | LWIP_DEBUGF(IGMP_DEBUG, ("igmp_leavegroup: igmp_mac_filter(DEL ")); |
ninoderkinderen | 0:8d87bc453349 | 623 | ip_addr_debug_print(IGMP_DEBUG, groupaddr); |
ninoderkinderen | 0:8d87bc453349 | 624 | LWIP_DEBUGF(IGMP_DEBUG, (") on if %p\n", netif)); |
ninoderkinderen | 0:8d87bc453349 | 625 | netif->igmp_mac_filter(netif, groupaddr, IGMP_DEL_MAC_FILTER); |
ninoderkinderen | 0:8d87bc453349 | 626 | } |
ninoderkinderen | 0:8d87bc453349 | 627 | |
ninoderkinderen | 0:8d87bc453349 | 628 | LWIP_DEBUGF(IGMP_DEBUG, ("igmp_leavegroup: remove group: ")); |
ninoderkinderen | 0:8d87bc453349 | 629 | ip_addr_debug_print(IGMP_DEBUG, groupaddr); |
ninoderkinderen | 0:8d87bc453349 | 630 | LWIP_DEBUGF(IGMP_DEBUG, ("\n")); |
ninoderkinderen | 0:8d87bc453349 | 631 | |
ninoderkinderen | 0:8d87bc453349 | 632 | /* Free the group */ |
ninoderkinderen | 0:8d87bc453349 | 633 | igmp_remove_group(group); |
ninoderkinderen | 0:8d87bc453349 | 634 | } else { |
ninoderkinderen | 0:8d87bc453349 | 635 | /* Decrement group use */ |
ninoderkinderen | 0:8d87bc453349 | 636 | group->use--; |
ninoderkinderen | 0:8d87bc453349 | 637 | } |
ninoderkinderen | 0:8d87bc453349 | 638 | /* Leave on this interface */ |
ninoderkinderen | 0:8d87bc453349 | 639 | err = ERR_OK; |
ninoderkinderen | 0:8d87bc453349 | 640 | } else { |
ninoderkinderen | 0:8d87bc453349 | 641 | /* It's not a fatal error on "leavegroup" */ |
ninoderkinderen | 0:8d87bc453349 | 642 | LWIP_DEBUGF(IGMP_DEBUG, ("igmp_leavegroup: not member of group\n")); |
ninoderkinderen | 0:8d87bc453349 | 643 | } |
ninoderkinderen | 0:8d87bc453349 | 644 | } |
ninoderkinderen | 0:8d87bc453349 | 645 | /* proceed to next network interface */ |
ninoderkinderen | 0:8d87bc453349 | 646 | netif = netif->next; |
ninoderkinderen | 0:8d87bc453349 | 647 | } |
ninoderkinderen | 0:8d87bc453349 | 648 | |
ninoderkinderen | 0:8d87bc453349 | 649 | return err; |
ninoderkinderen | 0:8d87bc453349 | 650 | } |
ninoderkinderen | 0:8d87bc453349 | 651 | |
ninoderkinderen | 0:8d87bc453349 | 652 | /** |
ninoderkinderen | 0:8d87bc453349 | 653 | * The igmp timer function (both for NO_SYS=1 and =0) |
ninoderkinderen | 0:8d87bc453349 | 654 | * Should be called every IGMP_TMR_INTERVAL milliseconds (100 ms is default). |
ninoderkinderen | 0:8d87bc453349 | 655 | */ |
ninoderkinderen | 0:8d87bc453349 | 656 | void |
ninoderkinderen | 0:8d87bc453349 | 657 | igmp_tmr(void) |
ninoderkinderen | 0:8d87bc453349 | 658 | { |
ninoderkinderen | 0:8d87bc453349 | 659 | struct igmp_group *group = igmp_group_list; |
ninoderkinderen | 0:8d87bc453349 | 660 | |
ninoderkinderen | 0:8d87bc453349 | 661 | while (group != NULL) { |
ninoderkinderen | 0:8d87bc453349 | 662 | if (group->timer > 0) { |
ninoderkinderen | 0:8d87bc453349 | 663 | group->timer--; |
ninoderkinderen | 0:8d87bc453349 | 664 | if (group->timer == 0) { |
ninoderkinderen | 0:8d87bc453349 | 665 | igmp_timeout(group); |
ninoderkinderen | 0:8d87bc453349 | 666 | } |
ninoderkinderen | 0:8d87bc453349 | 667 | } |
ninoderkinderen | 0:8d87bc453349 | 668 | group = group->next; |
ninoderkinderen | 0:8d87bc453349 | 669 | } |
ninoderkinderen | 0:8d87bc453349 | 670 | } |
ninoderkinderen | 0:8d87bc453349 | 671 | |
ninoderkinderen | 0:8d87bc453349 | 672 | /** |
ninoderkinderen | 0:8d87bc453349 | 673 | * Called if a timeout for one group is reached. |
ninoderkinderen | 0:8d87bc453349 | 674 | * Sends a report for this group. |
ninoderkinderen | 0:8d87bc453349 | 675 | * |
ninoderkinderen | 0:8d87bc453349 | 676 | * @param group an igmp_group for which a timeout is reached |
ninoderkinderen | 0:8d87bc453349 | 677 | */ |
ninoderkinderen | 0:8d87bc453349 | 678 | static void |
ninoderkinderen | 0:8d87bc453349 | 679 | igmp_timeout(struct igmp_group *group) |
ninoderkinderen | 0:8d87bc453349 | 680 | { |
ninoderkinderen | 0:8d87bc453349 | 681 | /* If the state is IGMP_GROUP_DELAYING_MEMBER then we send a report for this group */ |
ninoderkinderen | 0:8d87bc453349 | 682 | if (group->group_state == IGMP_GROUP_DELAYING_MEMBER) { |
ninoderkinderen | 0:8d87bc453349 | 683 | LWIP_DEBUGF(IGMP_DEBUG, ("igmp_timeout: report membership for group with address ")); |
ninoderkinderen | 0:8d87bc453349 | 684 | ip_addr_debug_print(IGMP_DEBUG, &(group->group_address)); |
ninoderkinderen | 0:8d87bc453349 | 685 | LWIP_DEBUGF(IGMP_DEBUG, (" on if %p\n", group->netif)); |
ninoderkinderen | 0:8d87bc453349 | 686 | |
ninoderkinderen | 0:8d87bc453349 | 687 | IGMP_STATS_INC(igmp.tx_report); |
ninoderkinderen | 0:8d87bc453349 | 688 | igmp_send(group, IGMP_V2_MEMB_REPORT); |
ninoderkinderen | 0:8d87bc453349 | 689 | } |
ninoderkinderen | 0:8d87bc453349 | 690 | } |
ninoderkinderen | 0:8d87bc453349 | 691 | |
ninoderkinderen | 0:8d87bc453349 | 692 | /** |
ninoderkinderen | 0:8d87bc453349 | 693 | * Start a timer for an igmp group |
ninoderkinderen | 0:8d87bc453349 | 694 | * |
ninoderkinderen | 0:8d87bc453349 | 695 | * @param group the igmp_group for which to start a timer |
ninoderkinderen | 0:8d87bc453349 | 696 | * @param max_time the time in multiples of IGMP_TMR_INTERVAL (decrease with |
ninoderkinderen | 0:8d87bc453349 | 697 | * every call to igmp_tmr()) |
ninoderkinderen | 0:8d87bc453349 | 698 | */ |
ninoderkinderen | 0:8d87bc453349 | 699 | static void |
ninoderkinderen | 0:8d87bc453349 | 700 | igmp_start_timer(struct igmp_group *group, u8_t max_time) |
ninoderkinderen | 0:8d87bc453349 | 701 | { |
ninoderkinderen | 0:8d87bc453349 | 702 | /* ensure the input value is > 0 */ |
ninoderkinderen | 0:8d87bc453349 | 703 | if (max_time == 0) { |
ninoderkinderen | 0:8d87bc453349 | 704 | max_time = 1; |
ninoderkinderen | 0:8d87bc453349 | 705 | } |
ninoderkinderen | 0:8d87bc453349 | 706 | /* ensure the random value is > 0 */ |
ninoderkinderen | 0:8d87bc453349 | 707 | group->timer = (LWIP_RAND() % (max_time - 1)) + 1; |
ninoderkinderen | 0:8d87bc453349 | 708 | } |
ninoderkinderen | 0:8d87bc453349 | 709 | |
ninoderkinderen | 0:8d87bc453349 | 710 | /** |
ninoderkinderen | 0:8d87bc453349 | 711 | * Stop a timer for an igmp_group |
ninoderkinderen | 0:8d87bc453349 | 712 | * |
ninoderkinderen | 0:8d87bc453349 | 713 | * @param group the igmp_group for which to stop the timer |
ninoderkinderen | 0:8d87bc453349 | 714 | */ |
ninoderkinderen | 0:8d87bc453349 | 715 | static void |
ninoderkinderen | 0:8d87bc453349 | 716 | igmp_stop_timer(struct igmp_group *group) |
ninoderkinderen | 0:8d87bc453349 | 717 | { |
ninoderkinderen | 0:8d87bc453349 | 718 | group->timer = 0; |
ninoderkinderen | 0:8d87bc453349 | 719 | } |
ninoderkinderen | 0:8d87bc453349 | 720 | |
ninoderkinderen | 0:8d87bc453349 | 721 | /** |
ninoderkinderen | 0:8d87bc453349 | 722 | * Delaying membership report for a group if necessary |
ninoderkinderen | 0:8d87bc453349 | 723 | * |
ninoderkinderen | 0:8d87bc453349 | 724 | * @param group the igmp_group for which "delaying" membership report |
ninoderkinderen | 0:8d87bc453349 | 725 | * @param maxresp query delay |
ninoderkinderen | 0:8d87bc453349 | 726 | */ |
ninoderkinderen | 0:8d87bc453349 | 727 | static void |
ninoderkinderen | 0:8d87bc453349 | 728 | igmp_delaying_member(struct igmp_group *group, u8_t maxresp) |
ninoderkinderen | 0:8d87bc453349 | 729 | { |
ninoderkinderen | 0:8d87bc453349 | 730 | if ((group->group_state == IGMP_GROUP_IDLE_MEMBER) || |
ninoderkinderen | 0:8d87bc453349 | 731 | ((group->group_state == IGMP_GROUP_DELAYING_MEMBER) && |
ninoderkinderen | 0:8d87bc453349 | 732 | ((group->timer == 0) || (maxresp < group->timer)))) { |
ninoderkinderen | 0:8d87bc453349 | 733 | igmp_start_timer(group, maxresp); |
ninoderkinderen | 0:8d87bc453349 | 734 | group->group_state = IGMP_GROUP_DELAYING_MEMBER; |
ninoderkinderen | 0:8d87bc453349 | 735 | } |
ninoderkinderen | 0:8d87bc453349 | 736 | } |
ninoderkinderen | 0:8d87bc453349 | 737 | |
ninoderkinderen | 0:8d87bc453349 | 738 | |
ninoderkinderen | 0:8d87bc453349 | 739 | /** |
ninoderkinderen | 0:8d87bc453349 | 740 | * Sends an IP packet on a network interface. This function constructs the IP header |
ninoderkinderen | 0:8d87bc453349 | 741 | * and calculates the IP header checksum. If the source IP address is NULL, |
ninoderkinderen | 0:8d87bc453349 | 742 | * the IP address of the outgoing network interface is filled in as source address. |
ninoderkinderen | 0:8d87bc453349 | 743 | * |
ninoderkinderen | 0:8d87bc453349 | 744 | * @param p the packet to send (p->payload points to the data, e.g. next |
ninoderkinderen | 0:8d87bc453349 | 745 | protocol header; if dest == IP_HDRINCL, p already includes an IP |
ninoderkinderen | 0:8d87bc453349 | 746 | header and p->payload points to that IP header) |
ninoderkinderen | 0:8d87bc453349 | 747 | * @param src the source IP address to send from (if src == IP_ADDR_ANY, the |
ninoderkinderen | 0:8d87bc453349 | 748 | * IP address of the netif used to send is used as source address) |
ninoderkinderen | 0:8d87bc453349 | 749 | * @param dest the destination IP address to send the packet to |
ninoderkinderen | 0:8d87bc453349 | 750 | * @param ttl the TTL value to be set in the IP header |
ninoderkinderen | 0:8d87bc453349 | 751 | * @param proto the PROTOCOL to be set in the IP header |
ninoderkinderen | 0:8d87bc453349 | 752 | * @param netif the netif on which to send this packet |
ninoderkinderen | 0:8d87bc453349 | 753 | * @return ERR_OK if the packet was sent OK |
ninoderkinderen | 0:8d87bc453349 | 754 | * ERR_BUF if p doesn't have enough space for IP/LINK headers |
ninoderkinderen | 0:8d87bc453349 | 755 | * returns errors returned by netif->output |
ninoderkinderen | 0:8d87bc453349 | 756 | */ |
ninoderkinderen | 0:8d87bc453349 | 757 | static err_t |
ninoderkinderen | 0:8d87bc453349 | 758 | igmp_ip_output_if(struct pbuf *p, ip_addr_t *src, ip_addr_t *dest, struct netif *netif) |
ninoderkinderen | 0:8d87bc453349 | 759 | { |
ninoderkinderen | 0:8d87bc453349 | 760 | /* This is the "router alert" option */ |
ninoderkinderen | 0:8d87bc453349 | 761 | u16_t ra[2]; |
ninoderkinderen | 0:8d87bc453349 | 762 | ra[0] = PP_HTONS(ROUTER_ALERT); |
ninoderkinderen | 0:8d87bc453349 | 763 | ra[1] = 0x0000; /* Router shall examine packet */ |
ninoderkinderen | 0:8d87bc453349 | 764 | IGMP_STATS_INC(igmp.xmit); |
ninoderkinderen | 0:8d87bc453349 | 765 | return ip_output_if_opt(p, src, dest, IGMP_TTL, 0, IP_PROTO_IGMP, netif, ra, ROUTER_ALERTLEN); |
ninoderkinderen | 0:8d87bc453349 | 766 | } |
ninoderkinderen | 0:8d87bc453349 | 767 | |
ninoderkinderen | 0:8d87bc453349 | 768 | /** |
ninoderkinderen | 0:8d87bc453349 | 769 | * Send an igmp packet to a specific group. |
ninoderkinderen | 0:8d87bc453349 | 770 | * |
ninoderkinderen | 0:8d87bc453349 | 771 | * @param group the group to which to send the packet |
ninoderkinderen | 0:8d87bc453349 | 772 | * @param type the type of igmp packet to send |
ninoderkinderen | 0:8d87bc453349 | 773 | */ |
ninoderkinderen | 0:8d87bc453349 | 774 | static void |
ninoderkinderen | 0:8d87bc453349 | 775 | igmp_send(struct igmp_group *group, u8_t type) |
ninoderkinderen | 0:8d87bc453349 | 776 | { |
ninoderkinderen | 0:8d87bc453349 | 777 | struct pbuf* p = NULL; |
ninoderkinderen | 0:8d87bc453349 | 778 | struct igmp_msg* igmp = NULL; |
ninoderkinderen | 0:8d87bc453349 | 779 | ip_addr_t src = *IP_ADDR_ANY; |
ninoderkinderen | 0:8d87bc453349 | 780 | ip_addr_t* dest = NULL; |
ninoderkinderen | 0:8d87bc453349 | 781 | |
ninoderkinderen | 0:8d87bc453349 | 782 | /* IP header + "router alert" option + IGMP header */ |
ninoderkinderen | 0:8d87bc453349 | 783 | p = pbuf_alloc(PBUF_TRANSPORT, IGMP_MINLEN, PBUF_RAM); |
ninoderkinderen | 0:8d87bc453349 | 784 | |
ninoderkinderen | 0:8d87bc453349 | 785 | if (p) { |
ninoderkinderen | 0:8d87bc453349 | 786 | igmp = (struct igmp_msg *)p->payload; |
ninoderkinderen | 0:8d87bc453349 | 787 | LWIP_ASSERT("igmp_send: check that first pbuf can hold struct igmp_msg", |
ninoderkinderen | 0:8d87bc453349 | 788 | (p->len >= sizeof(struct igmp_msg))); |
ninoderkinderen | 0:8d87bc453349 | 789 | ip_addr_copy(src, group->netif->ip_addr); |
ninoderkinderen | 0:8d87bc453349 | 790 | |
ninoderkinderen | 0:8d87bc453349 | 791 | if (type == IGMP_V2_MEMB_REPORT) { |
ninoderkinderen | 0:8d87bc453349 | 792 | dest = &(group->group_address); |
ninoderkinderen | 0:8d87bc453349 | 793 | ip_addr_copy(igmp->igmp_group_address, group->group_address); |
ninoderkinderen | 0:8d87bc453349 | 794 | group->last_reporter_flag = 1; /* Remember we were the last to report */ |
ninoderkinderen | 0:8d87bc453349 | 795 | } else { |
ninoderkinderen | 0:8d87bc453349 | 796 | if (type == IGMP_LEAVE_GROUP) { |
ninoderkinderen | 0:8d87bc453349 | 797 | dest = &allrouters; |
ninoderkinderen | 0:8d87bc453349 | 798 | ip_addr_copy(igmp->igmp_group_address, group->group_address); |
ninoderkinderen | 0:8d87bc453349 | 799 | } |
ninoderkinderen | 0:8d87bc453349 | 800 | } |
ninoderkinderen | 0:8d87bc453349 | 801 | |
ninoderkinderen | 0:8d87bc453349 | 802 | if ((type == IGMP_V2_MEMB_REPORT) || (type == IGMP_LEAVE_GROUP)) { |
ninoderkinderen | 0:8d87bc453349 | 803 | igmp->igmp_msgtype = type; |
ninoderkinderen | 0:8d87bc453349 | 804 | igmp->igmp_maxresp = 0; |
ninoderkinderen | 0:8d87bc453349 | 805 | igmp->igmp_checksum = 0; |
ninoderkinderen | 0:8d87bc453349 | 806 | igmp->igmp_checksum = inet_chksum(igmp, IGMP_MINLEN); |
ninoderkinderen | 0:8d87bc453349 | 807 | |
ninoderkinderen | 0:8d87bc453349 | 808 | igmp_ip_output_if(p, &src, dest, group->netif); |
ninoderkinderen | 0:8d87bc453349 | 809 | } |
ninoderkinderen | 0:8d87bc453349 | 810 | |
ninoderkinderen | 0:8d87bc453349 | 811 | pbuf_free(p); |
ninoderkinderen | 0:8d87bc453349 | 812 | } else { |
ninoderkinderen | 0:8d87bc453349 | 813 | LWIP_DEBUGF(IGMP_DEBUG, ("igmp_send: not enough memory for igmp_send\n")); |
ninoderkinderen | 0:8d87bc453349 | 814 | IGMP_STATS_INC(igmp.memerr); |
ninoderkinderen | 0:8d87bc453349 | 815 | } |
ninoderkinderen | 0:8d87bc453349 | 816 | } |
ninoderkinderen | 0:8d87bc453349 | 817 | |
ninoderkinderen | 0:8d87bc453349 | 818 | #endif /* LWIP_IGMP */ |