Enabled code to abort/replace TCP pcbs upon netif address change.

This commit is contained in:
likewise 2003-04-09 15:17:57 +00:00
parent a389b630ac
commit 1254b42e66

View File

@ -42,6 +42,7 @@
#include "lwip/mem.h" #include "lwip/mem.h"
#include "lwip/netif.h" #include "lwip/netif.h"
#include "lwip/ip_addr.h" #include "lwip/ip_addr.h"
#include "lwip/tcp.h"
struct netif *netif_list = NULL; struct netif *netif_list = NULL;
@ -179,40 +180,43 @@ netif_set_ipaddr(struct netif *netif, struct ip_addr *ipaddr)
{ {
/* TODO: Handling of obsolete pcbs */ /* TODO: Handling of obsolete pcbs */
/* See: http://mail.gnu.org/archive/html/lwip-users/2003-03/msg00118.html */ /* See: http://mail.gnu.org/archive/html/lwip-users/2003-03/msg00118.html */
#if 0 #if 1
struct tcp_pcb *pcb; struct tcp_pcb *pcb;
struct tcp_pcb_listen *lpcb; struct tcp_pcb_listen *lpcb;
/* address has changed? */ /* address has changed? */
if ((ip_addr_cmp(&(pcb->local_ip), &(netif->ip_addr))) == 0) if ((ip_addr_cmp(ipaddr, &(netif->ip_addr))) == 0)
{ {
pcb = tcp_active_pcbs; extern struct tcp_pcb *tcp_active_pcbs;
while (pcb != NULL) { DEBUGF(NETIF_DEBUG | 1, ("netif_set_ipaddr: netif address changed\n"));
if (ip_addr_cmp(&(pcb->local_ip), &(netif->ip_addr))) { pcb = tcp_active_pcbs;
/* The PCB is connected using the old ipaddr and must be aborted */ while (pcb != NULL) {
struct tcp_pcb *next = pcb->next; if (ip_addr_cmp(&(pcb->local_ip), &(netif->ip_addr))) {
tcp_abort(pcb); /* The PCB is connected using the old ipaddr and must be aborted */
pcb = next; struct tcp_pcb *next = pcb->next;
} else { DEBUGF(NETIF_DEBUG | 1, ("netif_set_ipaddr: aborting pcb %p\n", pcb));
pcb=pcb->next; tcp_abort(pcb);
pcb = next;
} else {
pcb = pcb->next;
}
} }
} for (lpcb = tcp_listen_pcbs; lpcb != NULL; lpcb = lpcb->next) {
for (lpcb = tcp_listen_pcbs; lpcb != NULL; lpcb = lpcb->next) { if (ip_addr_cmp(&(lpcb->local_ip), &(netif->ip_addr))) {
if (ip_addr_cmp(&(lpcb->local_ip), &(netif->ip_addr))) { /* The PCB is listening to the old ipaddr and
/* The PCB is listening to the old ipaddr and * is set to listen to the new one instead */
* is set to listen to the new one instead */ ip_addr_set(&(lpcb->local_ip), ipaddr);
ip_addr_set(&(lpcb->local_ip), ipaddr); }
} }
} }
}
#endif #endif
DEBUGF(NETIF_DEBUG | DBG_TRACE | DBG_STATE, ("netif: setting IP address of interface %c%c%u to %u.%u.%u.%u\n",
netif->name[0], netif->name[1], netif->num,
(u8_t)(ntohl(ipaddr->addr) >> 24 & 0xff),
(u8_t)(ntohl(ipaddr->addr) >> 16 & 0xff),
(u8_t)(ntohl(ipaddr->addr) >> 8 & 0xff),
(u8_t)(ntohl(ipaddr->addr) & 0xff)));
ip_addr_set(&(netif->ip_addr), ipaddr); ip_addr_set(&(netif->ip_addr), ipaddr);
DEBUGF(NETIF_DEBUG | DBG_TRACE | DBG_STATE, ("netif: new IP address of interface %c%c%u is %u.%u.%u.%u\n",
netif->name[0], netif->name[1], netif->num,
(u8_t)(ntohl(netif->ip_addr.addr) >> 24 & 0xff),
(u8_t)(ntohl(netif->ip_addr.addr) >> 16 & 0xff),
(u8_t)(ntohl(netif->ip_addr.addr) >> 8 & 0xff),
(u8_t)(ntohl(netif->ip_addr.addr) & 0xff)));
} }
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
void void