RCS file: /sources/lwip/lwip/src/core/netif.c,v retrieving revision 1.53 diff -u -r1.53 netif.c --- netif.c 2 Jul 2007 20:41:22 -0000 1.53 +++ netif.c 12 Jul 2007 16:48:43 -0000 @@ -48,6 +48,21 @@ #include "netif/etharp.h" #endif /* LWIP_ARP */ +#if LWIP_NETIF_LINK_CALLBACK +#define NETIF_LINK_CALLBACK(n) { if (n->link_callback) \ +(n->link_callback)(n) } +#else +#define NETIF_LINK_CALLBACK(n) { /* NOP */ } +#define +#endif /* LWIP_NETIF_LINK_CALLBACK */ + +#if LWIP_NETIF_CALLBACK +#define NETIF_STATUS_CALLBACK(n) { if (n->status_callback) \ +(n->status_callback)(n) } +#else +#define NETIF_STATUS_CALLBACK(n) { /* NOP */ } +#define +#endif /* LWIP_NETIF_LINK_CALLBACK */ struct netif *netif_list = NULL; struct netif *netif_default = NULL; @@ -100,6 +115,9 @@ #if LWIP_NETIF_CALLBACK netif->status_callback = NULL; #endif /* LWIP_NETIF_CALLBACK */ +#if LWIP_NETIF_LINK_CALLBACK + netif->link_callback = NULL; +#endif /* remember netif specific state information data */ netif->state = state; @@ -145,9 +163,9 @@ netif_set_addr(struct netif *netif, struct ip_addr *ipaddr, struct ip_addr *netmask, struct ip_addr *gw) { - netif_set_ipaddr(netif, ipaddr); netif_set_netmask(netif, netmask); netif_set_gw(netif, gw); + netif_set_ipaddr(netif, ipaddr); } /** @@ -263,6 +281,19 @@ } } #endif +#if LWIP_ARP + /** For Ethernet network interfaces, we would like to send a + * "gratuitous ARP"; this is an ARP packet sent by a node in order + * to spontaneously cause other nodes to update an entry in their + * ARP cache. From RFC 3220 "IP Mobility Support for IPv4" section 4.6. + */ + if (netif->flags & (NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP)) { // send only for ARP interfaces that have a link + etharp_query(netif, &(netif->ip_addr), NULL); + } +#endif /* LWIP_ARP */ + + NETIF_STATUS_CALLBACK(netif); + snmp_delete_ipaddridx_tree(netif); snmp_delete_iprteidx_tree(0,netif); /* set new IP address to netif */ @@ -350,10 +381,6 @@ * Bring an interface up, available for processing * traffic. * - * @note: Enabling DHCP on a down interface will make it come - * up once configured. - * - * @see dhcp_start() */ void netif_set_up(struct netif *netif) { @@ -364,22 +391,7 @@ snmp_get_sysuptime(&netif->ts); #endif /* LWIP_SNMP */ -#if LWIP_NETIF_CALLBACK - if ( netif->status_callback ) - (netif->status_callback)( netif ); -#endif /* LWIP_NETIF_CALLBACK */ - -#if LWIP_ARP - /** For Ethernet network interfaces, we would like to send a - * "gratuitous ARP"; this is an ARP packet sent by a node in order - * to spontaneously cause other nodes to update an entry in their - * ARP cache. From RFC 3220 "IP Mobility Support for IPv4" section 4.6. - */ - if (netif->flags & NETIF_FLAG_ETHARP) { - etharp_query(netif, &(netif->ip_addr), NULL); - } -#endif /* LWIP_ARP */ - + NETIF_LINK_CALLBACK(netif); } } @@ -407,11 +419,18 @@ #if LWIP_SNMP snmp_get_sysuptime(&netif->ts); #endif + +#if LWIP_DHCP + if ( netif->flags | NETIF_FLAG_DHCP ) + dhcp_stop(netif); +#endif +#if LWIP_AUTOIP + if ( netif->flags | NETIF_FLAG_AUTOIP ) + autoip_stop(netif); +#endif -#if LWIP_NETIF_CALLBACK - if ( netif->status_callback ) - (netif->status_callback)( netif ); -#endif /* LWIP_NETIF_CALLBACK */ + NETIF_LINK_CALLBACK(netif); + NETIF_STATUS_CALLBACK(netif); // maybe not? } } @@ -425,3 +444,30 @@ netif->status_callback = status_callback; } #endif /* LWIP_NETIF_CALLBACK */ + +#if LWIP_NETIF_LINK_CALLBACK +/** + * Called by a driver when its link goes down + */ +void netif_set_link_down( struct netif *netif ) { + netif->flags &= ~NETIF_FLAG_LINK_UP; +} + +/** + * Called by a driver when its link goes up + */ +void netif_set_link_up( struct netif *netif ) { + netif->flags |= NETIF_FLAG_LINK_UP; + +#if LWIP_ARP + /** For Ethernet network interfaces, we would like to send a + * "gratuitous ARP"; this is an ARP packet sent by a node in order + * to spontaneously cause other nodes to update an entry in their + * ARP cache. From RFC 3220 "IP Mobility Support for IPv4" section 4.6. + */ + if (netif->flags & NETIF_FLAG_ETHARP) { + etharp_query(netif, &(netif->ip_addr), NULL); + } +#endif /* LWIP_ARP */ +} +#endif