From cd208314e0278d06ac9cbcaa6423bb3a0e7bae55 Mon Sep 17 00:00:00 2001 From: fbernon Date: Wed, 29 Aug 2007 21:12:32 +0000 Subject: [PATCH] igmp.h, igmp.c, tcpip.c, init.c, netif.c: change igmp_init and add igmp_start. igmp_start is call inside netif_add. Now, igmp initialization is in the same spirit than the others modules. Modify some IGMP debug traces. --- CHANGELOG | 5 +++ src/api/tcpip.c | 8 ++-- src/core/init.c | 6 ++- src/core/ipv4/igmp.c | 75 ++++++++++++++++++++++++------------ src/core/netif.c | 6 +++ src/include/ipv4/lwip/igmp.h | 2 + 6 files changed, 71 insertions(+), 31 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index b787c9ff..9c0f6644 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -19,6 +19,11 @@ HISTORY ++ New features: + 2007-08-29 Frédéric Bernon + * igmp.h, igmp.c, tcpip.c, init.c, netif.c: change igmp_init and add igmp_start. + igmp_start is call inside netif_add. Now, igmp initialization is in the same + spirit than the others modules. Modify some IGMP debug traces. + 2007-08-29 Frédéric Bernon * Add init.h, init.c, Change opt.h, tcpip.c: Task #7213 "Add a lwip_init function" Add lwip_init function to regroup all modules initializations, and to provide diff --git a/src/api/tcpip.c b/src/api/tcpip.c index 215118e5..c0302a79 100644 --- a/src/api/tcpip.c +++ b/src/api/tcpip.c @@ -292,16 +292,14 @@ tcpip_thread(void *arg) #if LWIP_AUTOIP sys_timeout(AUTOIP_TMR_INTERVAL, autoip_timer, NULL); #endif /* LWIP_AUTOIP */ +#if LWIP_IGMP + sys_timeout(IGMP_TMR_INTERVAL, igmp_timer, NULL); +#endif /* LWIP_IGMP */ if (tcpip_init_done != NULL) { tcpip_init_done(tcpip_init_done_arg); } -#if LWIP_IGMP - igmp_init(); - sys_timeout(IGMP_TMR_INTERVAL, igmp_timer, NULL); -#endif /* LWIP_IGMP */ - LOCK_TCPIP_CORE(); while (1) { /* MAIN Loop */ sys_mbox_fetch(mbox, (void *)&msg); diff --git a/src/core/init.c b/src/core/init.c index 9885c2f0..dc7f70d0 100644 --- a/src/core/init.c +++ b/src/core/init.c @@ -50,6 +50,7 @@ #include "lwip/raw.h" #include "lwip/udp.h" #include "lwip/tcp.h" +#include "lwip/igmp.h" #include "lwip/autoip.h" void @@ -63,7 +64,7 @@ lwip_init(void) memp_init(); pbuf_init(); netif_init(); -#if LWIP_SOCKET /** @todo Add this option in opt.h, in a first time, add it in lwipopts.h */ +#if LWIP_SOCKET lwip_socket_init(); #endif /* LWIP_SOCKET */ ip_init(); @@ -82,4 +83,7 @@ lwip_init(void) #if LWIP_AUTOIP autoip_init(); #endif /* LWIP_AUTOIP */ +#if LWIP_IGMP + igmp_init(); +#endif /* LWIP_IGMP */ } diff --git a/src/core/ipv4/igmp.c b/src/core/ipv4/igmp.c index c0dcb231..dbda5973 100644 --- a/src/core/ipv4/igmp.c +++ b/src/core/ipv4/igmp.c @@ -108,39 +108,45 @@ static struct ip_addr allsystems; static struct ip_addr allrouters; /** - * Initialize this module - * - * Only network interfaces registered when this function is called - * are igmp-enabled. - * - * This will enable igmp on all interface. In the current implementation it - * is not possible to have igmp on one interface but not the other. + * Initialize the IGMP module */ void igmp_init(void) { - struct igmp_group* group; - struct netif* netif; - LWIP_DEBUGF(IGMP_DEBUG, ("igmp_init: initializing\n")); IP4_ADDR(&allsystems, 224, 0, 0, 1); IP4_ADDR(&allrouters, 224, 0, 0, 2); igmp_group_list = NULL; +} - for (netif = netif_list; netif != NULL; netif = netif->next) { - group = igmp_lookup_group(netif, &allsystems); - - if (group != NULL) { - group->group_state = IDLE_MEMBER; +/** + * 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; - /* Allow the igmp messages at the MAC level */ - if (netif->igmp_mac_filter != NULL) { - netif->igmp_mac_filter(netif, &allsystems, IGMP_ADD_MAC_FILTER); - } + LWIP_DEBUGF(IGMP_DEBUG, ("igmp_start: starting IGMP processing on if %x\n", (int) netif)); + + group = igmp_lookup_group(netif, &allsystems); + + if (group != NULL) { + group->group_state = IDLE_MEMBER; + + /* Allow the igmp messages at the MAC level */ + if (netif->igmp_mac_filter != NULL) { + netif->igmp_mac_filter( netif, &allsystems, IGMP_ADD_MAC_FILTER); } + + return ERR_OK; } + + return ERR_MEM; } /** @@ -200,10 +206,20 @@ igmp_lookup_group(struct netif *ifp, struct ip_addr *addr) group->next = igmp_group_list; igmp_group_list = group; - - LWIP_DEBUGF(IGMP_DEBUG, ("igmp_lookup_group: allocated a new group with address %x on if %x \n", (int) addr, (int) ifp)); + + LWIP_DEBUGF(IGMP_DEBUG, ("igmp_lookup_group: allocated a new group with address %"U16_F".%"U16_F".%"U16_F".%"U16_F" on if %x \n", + (u16_t)(ntohl(addr->addr) >> 24 & 0xff), + (u16_t)(ntohl(addr->addr) >> 16 & 0xff), + (u16_t)(ntohl(addr->addr) >> 8 & 0xff), + (u16_t)(ntohl(addr->addr) & 0xff), + (int) ifp)); } else { - LWIP_DEBUGF(IGMP_DEBUG, ("igmp_lookup_group: impossible to allocated a new group with address %x on if %x \n", (int) addr, (int) ifp)); + LWIP_DEBUGF(IGMP_DEBUG, ("igmp_lookup_group: impossible to allocated a new group with address %"U16_F".%"U16_F".%"U16_F".%"U16_F" on if %x \n", + (u16_t)(ntohl(addr->addr) >> 24 & 0xff), + (u16_t)(ntohl(addr->addr) >> 16 & 0xff), + (u16_t)(ntohl(addr->addr) >> 8 & 0xff), + (u16_t)(ntohl(addr->addr) & 0xff), + (int) ifp)); } return group; @@ -233,7 +249,12 @@ igmp_input(struct pbuf *p, struct netif *inp, struct ip_addr *dest) return; } - LWIP_DEBUGF(IGMP_DEBUG, ("igmp_input: message to address %l \n", (long)dest->addr)); + LWIP_DEBUGF(IGMP_DEBUG, ("igmp_input: message to address %"U16_F".%"U16_F".%"U16_F".%"U16_F" on if %x \n", + (u16_t)(ntohl(dest->addr) >> 24 & 0xff), + (u16_t)(ntohl(dest->addr) >> 16 & 0xff), + (u16_t)(ntohl(dest->addr) >> 8 & 0xff), + (u16_t)(ntohl(dest->addr) & 0xff), + (int) inp)); /* Now calculate and check the checksum */ igmp = (struct igmp_msg *)p->payload; @@ -457,9 +478,13 @@ 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_timeout: got a timeout\n")); - if (group->group_state == DELAYING_MEMBER) { + LWIP_DEBUGF(IGMP_DEBUG, ("igmp_timeout: report membership for group with address %"U16_F".%"U16_F".%"U16_F".%"U16_F" on if %x \n", + (u16_t)(ntohl(group->group_address.addr) >> 24 & 0xff), + (u16_t)(ntohl(group->group_address.addr) >> 16 & 0xff), + (u16_t)(ntohl(group->group_address.addr) >> 8 & 0xff), + (u16_t)(ntohl(group->group_address.addr) & 0xff), + (int) group->interface)); igmp_send(group, IGMP_V2_MEMB_REPORT); } } diff --git a/src/core/netif.c b/src/core/netif.c index 968bcad8..d6071cd1 100644 --- a/src/core/netif.c +++ b/src/core/netif.c @@ -43,6 +43,7 @@ #include "lwip/netif.h" #include "lwip/tcp.h" #include "lwip/snmp.h" +#include "lwip/igmp.h" #if LWIP_ARP #include "netif/etharp.h" @@ -135,6 +136,11 @@ netif_add(struct netif *netif, struct ip_addr *ipaddr, struct ip_addr *netmask, netif_list = netif; snmp_inc_iflist(); +#if LWIP_IGMP + /* start IGMP processing */ + igmp_start( netif); +#endif /* LWIP_IGMP */ + LWIP_DEBUGF(NETIF_DEBUG, ("netif: added interface %c%c IP addr ", netif->name[0], netif->name[1])); ip_addr_debug_print(NETIF_DEBUG, ipaddr); diff --git a/src/include/ipv4/lwip/igmp.h b/src/include/ipv4/lwip/igmp.h index 8f31fbe5..db7007f3 100644 --- a/src/include/ipv4/lwip/igmp.h +++ b/src/include/ipv4/lwip/igmp.h @@ -107,6 +107,8 @@ struct igmp_group { /* Prototypes */ void igmp_init(void); +err_t igmp_start( struct netif *netif); + struct igmp_group *igmp_lookfor_group(struct netif *ifp, struct ip_addr *addr); struct igmp_group *igmp_lookup_group(struct netif *ifp, struct ip_addr *addr);