in addition to http://lists.gnu.org/archive/html/lwip-users/2003-03/msg00118.html
I've extended pcb remove code code to use it in netif_remove too. My
edition solves problem when PPP connection is suddenly lost, netif is
removed and there's some PCBs left in stack.
patch to 1.4.1 is attached
*#if* LWIP_TCP
*static* *void* *netif_remove_pcbs*(*struct* netif *netif){
*struct* tcp_pcb *pcb;
pcb = tcp_active_pcbs;
*while* (pcb != NULL) {
/* PCB bound to current local interface address? */
*if* (ip_addr_cmp(&(pcb->local_ip), &(netif->ip_addr))
*#if* LWIP_AUTOIP
/* connections to link-local addresses must persist (RFC3927 ch. 1.9)
*/
&& !ip_addr_islinklocal(&(pcb->local_ip))
*#endif* /* LWIP_AUTOIP */
) {
/* this connection must be aborted */
*struct* tcp_pcb *next = pcb->next;
LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_STATE, ("netif_remove_pcbs:
aborting TCP pcb %p\n", (*void* *)pcb));
tcp_abort(pcb);
pcb = next;
} *else* {
pcb = pcb->next;
}
}
}
*#endif*
/**
* Remove a network interface from the list of lwIP netifs.
*
* @param netif the network interface to remove
*/
*void*
*netif_remove*(*struct* netif *netif)
{
*if* (netif == NULL) {
*return*;
}
*#if* LWIP_TCP
netif_remove_pcbs(netif);
*#endif*
*#if* LWIP_IGMP
/* stop IGMP processing */
*if* (netif->flags & NETIF_FLAG_IGMP) {
igmp_stop(netif);
}
*#endif* /* LWIP_IGMP */
*if* (netif_is_up(netif)) {
/* set netif down before removing (call callback function) */
netif_set_down(netif);
}
snmp_delete_ipaddridx_tree(netif);
/* is it the first netif? */
*if* (netif_list == netif) {
netif_list = netif->next;
} *else* {
/* look for netif further down the list */
*struct* netif * tmpNetif;
*for* (tmpNetif = netif_list; tmpNetif != NULL; tmpNetif = tmpNetif->
next) {
*if* (tmpNetif->next == netif) {
tmpNetif->next = netif->next;
*break*;
}
}
*if* (tmpNetif == NULL)
*return*; /* we didn't find any netif today */
}
snmp_dec_iflist();
/* this netif is default? */
*if* (netif_default == netif) {
/* reset default netif */
netif_set_default(NULL);
}
*#if* LWIP_NETIF_REMOVE_CALLBACK
*if* (netif->remove_callback) {
netif->remove_callback(netif);
}
*#endif* /* LWIP_NETIF_REMOVE_CALLBACK */
LWIP_DEBUGF( NETIF_DEBUG, ("netif_remove: removed netif\n") );
}
*void*
*netif_set_ipaddr*(*struct* netif *netif, ip_addr_t *ipaddr)
{
/* *TODO*: Handling of obsolete pcbs */
/* See: http://mail.gnu.org/archive/html/lwip-users/2003-03/msg00118.html*/
*#if* LWIP_TCP
*struct* tcp_pcb_listen *lpcb;
/* address is actually being changed? */
*if* (ipaddr && (ip_addr_cmp(ipaddr, &(netif->ip_addr))) == 0) {
/* extern struct tcp_pcb *tcp_active_pcbs; defined by tcp.h */
LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_STATE, ("netif_set_ipaddr:
netifaddress being changed\n"
));
netif_remove_pcbs(netif);
*for* (lpcb = tcp_listen_pcbs.listen_pcbs; lpcb != NULL; lpcb = lpcb->
next) {
/* PCB bound to current local interface address? */
*if* ((!(ip_addr_isany(&(lpcb->local_ip)))) &&
(ip_addr_cmp(&(lpcb->local_ip), &(netif->ip_addr)))) {
/* The PCB is listening to the old ipaddr and
* is set to listen to the new one instead */
ip_addr_set(&(lpcb->local_ip), ipaddr);
}
}
}
*#endif*
snmp_delete_ipaddridx_tree(netif);
snmp_delete_iprteidx_tree(0,netif);
/* set new IP address to netif */
ip_addr_set(&(netif->ip_addr), ipaddr);
snmp_insert_ipaddridx_tree(netif);
snmp_insert_iprteidx_tree(0,netif);
LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("netif: IP
address of interface %c%c set to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
netif->name[0], netif->name[1],
ip4_addr1_16(&netif->ip_addr),
ip4_addr2_16(&netif->ip_addr),
ip4_addr3_16(&netif->ip_addr),
ip4_addr4_16(&netif->ip_addr)));
}
--
Best Regards,
Roman Savrulin
Phone: +7 (921) 562 40 07
--
Best Regards,
Roman Savrulin
Phone: +7 (921) 562 40 07 [email protected]
netif.c.patch
Description: Binary data
_______________________________________________ lwip-users mailing list [email protected] https://lists.nongnu.org/mailman/listinfo/lwip-users
