mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2024-10-05 22:29:49 +00:00
More precise comments on address change.
This commit is contained in:
parent
734400cafa
commit
829744dfe6
@ -6,9 +6,9 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
@ -17,21 +17,21 @@
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
||||
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
||||
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
||||
* OF SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the lwIP TCP/IP stack.
|
||||
*
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
*/
|
||||
@ -70,7 +70,7 @@ netif_add(struct ip_addr *ipaddr, struct ip_addr *netmask,
|
||||
struct netif *netif;
|
||||
static int netifnum = 0;
|
||||
|
||||
/* allocate netif structure */
|
||||
/* allocate netif structure */
|
||||
netif = mem_malloc(sizeof(struct netif));
|
||||
|
||||
if (netif == NULL) {
|
||||
@ -80,20 +80,20 @@ netif_add(struct ip_addr *ipaddr, struct ip_addr *netmask,
|
||||
#if LWIP_DHCP
|
||||
/* netif not under DHCP control by default */
|
||||
netif->dhcp = NULL;
|
||||
#endif
|
||||
#endif
|
||||
/* remember netif specific state information data */
|
||||
netif->state = state;
|
||||
netif->num = netifnum++;
|
||||
netif->input = input;
|
||||
|
||||
netif_set_addr(netif, ipaddr, netmask, gw);
|
||||
|
||||
|
||||
/* call user specified initialization function for netif */
|
||||
if (init(netif) != ERR_OK) {
|
||||
mem_free(netif);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/* add this netif to the list */
|
||||
netif->next = netif_list;
|
||||
netif_list = netif;
|
||||
@ -103,7 +103,7 @@ netif_add(struct ip_addr *ipaddr, struct ip_addr *netmask,
|
||||
ip_addr_debug_print(ipaddr);
|
||||
DEBUGF(NETIF_DEBUG, (" netmask "));
|
||||
ip_addr_debug_print(netmask);
|
||||
DEBUGF(NETIF_DEBUG, (" gw "));
|
||||
DEBUGF(NETIF_DEBUG, (" gw "));
|
||||
ip_addr_debug_print(gw);
|
||||
DEBUGF(NETIF_DEBUG, ("\n"));
|
||||
#endif /* NETIF_DEBUG */
|
||||
@ -121,20 +121,20 @@ netif_set_addr(struct netif *netif,struct ip_addr *ipaddr, struct ip_addr *netma
|
||||
|
||||
void netif_remove(struct netif * netif)
|
||||
{
|
||||
if ( netif == NULL ) return;
|
||||
if ( netif == NULL ) return;
|
||||
|
||||
/* is it the first netif? */
|
||||
if (netif_list == netif) {
|
||||
netif_list = netif->next;
|
||||
}
|
||||
else {
|
||||
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 */
|
||||
@ -152,20 +152,20 @@ netif_find(char *name)
|
||||
{
|
||||
struct netif *netif;
|
||||
u8_t num;
|
||||
|
||||
|
||||
if (name == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
num = name[2] - '0';
|
||||
|
||||
|
||||
for(netif = netif_list; netif != NULL; netif = netif->next) {
|
||||
if (num == netif->num &&
|
||||
name[0] == netif->name[0] &&
|
||||
name[1] == netif->name[1]) {
|
||||
DEBUGF(NETIF_DEBUG, ("netif_find: found %c%c\n", name[0], name[1]));
|
||||
return netif;
|
||||
}
|
||||
}
|
||||
}
|
||||
DEBUGF(NETIF_DEBUG, ("netif_find: didn't find %c%c\n", name[0], name[1]));
|
||||
return NULL;
|
||||
@ -176,19 +176,20 @@ netif_set_ipaddr(struct netif *netif, struct ip_addr *ipaddr)
|
||||
{
|
||||
/* TODO: Handling of obsolete pcbs */
|
||||
/* See: http://mail.gnu.org/archive/html/lwip-users/2003-03/msg00118.html */
|
||||
#if LWIP_TCP
|
||||
#if LWIP_TCP
|
||||
struct tcp_pcb *pcb;
|
||||
struct tcp_pcb_listen *lpcb;
|
||||
|
||||
/* address has changed? */
|
||||
/* address is actually being changed? */
|
||||
if ((ip_addr_cmp(ipaddr, &(netif->ip_addr))) == 0)
|
||||
{
|
||||
extern struct tcp_pcb *tcp_active_pcbs;
|
||||
DEBUGF(NETIF_DEBUG | 1, ("netif_set_ipaddr: netif address changed\n"));
|
||||
DEBUGF(NETIF_DEBUG | 1, ("netif_set_ipaddr: netif address being changed\n"));
|
||||
pcb = tcp_active_pcbs;
|
||||
while (pcb != NULL) {
|
||||
/* PCB bound to current local interface address? */
|
||||
if (ip_addr_cmp(&(pcb->local_ip), &(netif->ip_addr))) {
|
||||
/* The PCB is connected using the old ipaddr and must be aborted */
|
||||
/* this connection must be aborted */
|
||||
struct tcp_pcb *next = pcb->next;
|
||||
DEBUGF(NETIF_DEBUG | 1, ("netif_set_ipaddr: aborting pcb %p\n", (void *)pcb));
|
||||
tcp_abort(pcb);
|
||||
@ -198,9 +199,11 @@ netif_set_ipaddr(struct netif *netif, struct ip_addr *ipaddr)
|
||||
}
|
||||
}
|
||||
for (lpcb = tcp_listen_pcbs; lpcb != NULL; lpcb = lpcb->next) {
|
||||
/* PCB bound to current local interface address? */
|
||||
if (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 */
|
||||
* is set to listen to the new one instead */
|
||||
* TODO: how do we know it is _listening_? */
|
||||
ip_addr_set(&(lpcb->local_ip), ipaddr);
|
||||
}
|
||||
}
|
||||
@ -208,7 +211,7 @@ netif_set_ipaddr(struct netif *netif, struct ip_addr *ipaddr)
|
||||
#endif
|
||||
ip_addr_set(&(netif->ip_addr), ipaddr);
|
||||
DEBUGF(NETIF_DEBUG | DBG_TRACE | DBG_STATE | 3, ("netif: IP address of interface %c%c set to %u.%u.%u.%u\n",
|
||||
netif->name[0], netif->name[1],
|
||||
netif->name[0], netif->name[1],
|
||||
(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),
|
||||
@ -220,7 +223,7 @@ netif_set_gw(struct netif *netif, struct ip_addr *gw)
|
||||
{
|
||||
ip_addr_set(&(netif->gw), gw);
|
||||
DEBUGF(NETIF_DEBUG | DBG_TRACE | DBG_STATE | 3, ("netif: GW address of interface %c%c set to %u.%u.%u.%u\n",
|
||||
netif->name[0], netif->name[1],
|
||||
netif->name[0], netif->name[1],
|
||||
(u8_t)(ntohl(netif->gw.addr) >> 24 & 0xff),
|
||||
(u8_t)(ntohl(netif->gw.addr) >> 16 & 0xff),
|
||||
(u8_t)(ntohl(netif->gw.addr) >> 8 & 0xff),
|
||||
|
Loading…
Reference in New Issue
Block a user