/[lwip]/lwip/src/core/netif.c
ViewVC logotype

Diff of /lwip/src/core/netif.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.23 by jani, Tue May 27 13:40:54 2003 UTC revision 1.24 by likewise, Mon Jun 9 21:08:55 2003 UTC
# Line 6  Line 6 
6    
7  /*  /*
8   * Copyright (c) 2001-2003 Swedish Institute of Computer Science.   * Copyright (c) 2001-2003 Swedish Institute of Computer Science.
9   * All rights reserved.   * All rights reserved.
10   *   *
11   * Redistribution and use in source and binary forms, with or without modification,   * Redistribution and use in source and binary forms, with or without modification,
12   * are permitted provided that the following conditions are met:   * are permitted provided that the following conditions are met:
13   *   *
14   * 1. Redistributions of source code must retain the above copyright notice,   * 1. Redistributions of source code must retain the above copyright notice,
# Line 17  Line 17 
17   *    this list of conditions and the following disclaimer in the documentation   *    this list of conditions and the following disclaimer in the documentation
18   *    and/or other materials provided with the distribution.   *    and/or other materials provided with the distribution.
19   * 3. The name of the author may not be used to endorse or promote products   * 3. The name of the author may not be used to endorse or promote products
20   *    derived from this software without specific prior written permission.   *    derived from this software without specific prior written permission.
21   *   *
22   * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED   * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
23   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24   * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT   * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
25   * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,   * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26   * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT   * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
27   * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS   * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
30   * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY   * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
31   * OF SUCH DAMAGE.   * OF SUCH DAMAGE.
32   *   *
33   * This file is part of the lwIP TCP/IP stack.   * This file is part of the lwIP TCP/IP stack.
34   *   *
35   * Author: Adam Dunkels <adam@sics.se>   * Author: Adam Dunkels <adam@sics.se>
36   *   *
37   */   */
# Line 70  netif_add(struct ip_addr *ipaddr, struct Line 70  netif_add(struct ip_addr *ipaddr, struct
70    struct netif *netif;    struct netif *netif;
71    static int netifnum = 0;    static int netifnum = 0;
72    
73    /* allocate netif structure */      /* allocate netif structure */
74    netif = mem_malloc(sizeof(struct netif));    netif = mem_malloc(sizeof(struct netif));
75    
76    if (netif == NULL) {    if (netif == NULL) {
# Line 80  netif_add(struct ip_addr *ipaddr, struct Line 80  netif_add(struct ip_addr *ipaddr, struct
80  #if LWIP_DHCP  #if LWIP_DHCP
81    /* netif not under DHCP control by default */    /* netif not under DHCP control by default */
82    netif->dhcp = NULL;    netif->dhcp = NULL;
83  #endif    #endif
84    /* remember netif specific state information data */    /* remember netif specific state information data */
85    netif->state = state;    netif->state = state;
86    netif->num = netifnum++;    netif->num = netifnum++;
87    netif->input = input;    netif->input = input;
88    
89    netif_set_addr(netif, ipaddr, netmask, gw);    netif_set_addr(netif, ipaddr, netmask, gw);
90      
91    /* call user specified initialization function for netif */    /* call user specified initialization function for netif */
92    if (init(netif) != ERR_OK) {    if (init(netif) != ERR_OK) {
93      mem_free(netif);      mem_free(netif);
94      return NULL;      return NULL;
95    }    }
96    
97    /* add this netif to the list */    /* add this netif to the list */
98    netif->next = netif_list;    netif->next = netif_list;
99    netif_list = netif;    netif_list = netif;
# Line 103  netif_add(struct ip_addr *ipaddr, struct Line 103  netif_add(struct ip_addr *ipaddr, struct
103    ip_addr_debug_print(ipaddr);    ip_addr_debug_print(ipaddr);
104    DEBUGF(NETIF_DEBUG, (" netmask "));    DEBUGF(NETIF_DEBUG, (" netmask "));
105    ip_addr_debug_print(netmask);    ip_addr_debug_print(netmask);
106    DEBUGF(NETIF_DEBUG, (" gw "));      DEBUGF(NETIF_DEBUG, (" gw "));
107    ip_addr_debug_print(gw);    ip_addr_debug_print(gw);
108    DEBUGF(NETIF_DEBUG, ("\n"));    DEBUGF(NETIF_DEBUG, ("\n"));
109  #endif /* NETIF_DEBUG */  #endif /* NETIF_DEBUG */
# Line 121  netif_set_addr(struct netif *netif,struc Line 121  netif_set_addr(struct netif *netif,struc
121    
122  void netif_remove(struct netif * netif)  void netif_remove(struct netif * netif)
123  {  {
124    if ( netif == NULL ) return;      if ( netif == NULL ) return;
125    
126    /*  is it the first netif? */    /*  is it the first netif? */
127    if (netif_list == netif) {    if (netif_list == netif) {
128      netif_list = netif->next;      netif_list = netif->next;
129    }    }
130    else {            else {
131      /*  look for netif further down the list */      /*  look for netif further down the list */
132      struct netif * tmpNetif;      struct netif * tmpNetif;
133      for (tmpNetif = netif_list; tmpNetif != NULL; tmpNetif = tmpNetif->next) {      for (tmpNetif = netif_list; tmpNetif != NULL; tmpNetif = tmpNetif->next) {
134                          if (tmpNetif->next == netif) {                          if (tmpNetif->next == netif) {
135                                  tmpNetif->next = netif->next;                                  tmpNetif->next = netif->next;
136          break;          break;
137          }              }
138                  }                  }
139                  if (tmpNetif == NULL)                  if (tmpNetif == NULL)
140                          return; /*  we didn't find any netif today */                          return; /*  we didn't find any netif today */
# Line 152  netif_find(char *name) Line 152  netif_find(char *name)
152  {  {
153    struct netif *netif;    struct netif *netif;
154    u8_t num;    u8_t num;
155      
156    if (name == NULL) {    if (name == NULL) {
157      return NULL;      return NULL;
158    }    }
159    
160    num = name[2] - '0';    num = name[2] - '0';
161    
162    for(netif = netif_list; netif != NULL; netif = netif->next) {    for(netif = netif_list; netif != NULL; netif = netif->next) {
163      if (num == netif->num &&      if (num == netif->num &&
164         name[0] == netif->name[0] &&         name[0] == netif->name[0] &&
165         name[1] == netif->name[1]) {         name[1] == netif->name[1]) {
166        DEBUGF(NETIF_DEBUG, ("netif_find: found %c%c\n", name[0], name[1]));        DEBUGF(NETIF_DEBUG, ("netif_find: found %c%c\n", name[0], name[1]));
167        return netif;        return netif;
168      }          }
169    }    }
170    DEBUGF(NETIF_DEBUG, ("netif_find: didn't find %c%c\n", name[0], name[1]));    DEBUGF(NETIF_DEBUG, ("netif_find: didn't find %c%c\n", name[0], name[1]));
171    return NULL;    return NULL;
# Line 176  netif_set_ipaddr(struct netif *netif, st Line 176  netif_set_ipaddr(struct netif *netif, st
176  {  {
177    /* TODO: Handling of obsolete pcbs */    /* TODO: Handling of obsolete pcbs */
178    /* 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 */
179  #if LWIP_TCP  #if LWIP_TCP
180    struct tcp_pcb *pcb;    struct tcp_pcb *pcb;
181    struct tcp_pcb_listen *lpcb;    struct tcp_pcb_listen *lpcb;
182    
183    /* address has changed? */    /* address is actually being changed? */
184    if ((ip_addr_cmp(ipaddr, &(netif->ip_addr))) == 0)    if ((ip_addr_cmp(ipaddr, &(netif->ip_addr))) == 0)
185    {    {
186      extern struct tcp_pcb *tcp_active_pcbs;      extern struct tcp_pcb *tcp_active_pcbs;
187      DEBUGF(NETIF_DEBUG | 1, ("netif_set_ipaddr: netif address changed\n"));      DEBUGF(NETIF_DEBUG | 1, ("netif_set_ipaddr: netif address being changed\n"));
188      pcb = tcp_active_pcbs;      pcb = tcp_active_pcbs;
189      while (pcb != NULL) {      while (pcb != NULL) {
190          /* PCB bound to current local interface address? */
191        if (ip_addr_cmp(&(pcb->local_ip), &(netif->ip_addr))) {        if (ip_addr_cmp(&(pcb->local_ip), &(netif->ip_addr))) {
192          /* The PCB is connected using the old ipaddr and must be aborted */          /* this connection must be aborted */
193          struct tcp_pcb *next = pcb->next;          struct tcp_pcb *next = pcb->next;
194          DEBUGF(NETIF_DEBUG | 1, ("netif_set_ipaddr: aborting pcb %p\n", (void *)pcb));          DEBUGF(NETIF_DEBUG | 1, ("netif_set_ipaddr: aborting pcb %p\n", (void *)pcb));
195          tcp_abort(pcb);          tcp_abort(pcb);
# Line 198  netif_set_ipaddr(struct netif *netif, st Line 199  netif_set_ipaddr(struct netif *netif, st
199        }        }
200      }      }
201      for (lpcb = tcp_listen_pcbs; lpcb != NULL; lpcb = lpcb->next) {      for (lpcb = tcp_listen_pcbs; lpcb != NULL; lpcb = lpcb->next) {
202          /* PCB bound to current local interface address? */
203        if (ip_addr_cmp(&(lpcb->local_ip), &(netif->ip_addr))) {        if (ip_addr_cmp(&(lpcb->local_ip), &(netif->ip_addr))) {
204          /* The PCB is listening to the old ipaddr and          /* The PCB is listening to the old ipaddr and
205           * is set to listen to the  new one instead */           * is set to listen to the new one instead */
206             * TODO: how do we know it is _listening_? */
207          ip_addr_set(&(lpcb->local_ip), ipaddr);          ip_addr_set(&(lpcb->local_ip), ipaddr);
208        }        }
209      }      }
# Line 208  netif_set_ipaddr(struct netif *netif, st Line 211  netif_set_ipaddr(struct netif *netif, st
211  #endif  #endif
212    ip_addr_set(&(netif->ip_addr), ipaddr);    ip_addr_set(&(netif->ip_addr), ipaddr);
213    DEBUGF(NETIF_DEBUG | DBG_TRACE | DBG_STATE | 3, ("netif: IP address of interface %c%c set to %u.%u.%u.%u\n",    DEBUGF(NETIF_DEBUG | DBG_TRACE | DBG_STATE | 3, ("netif: IP address of interface %c%c set to %u.%u.%u.%u\n",
214                         netif->name[0], netif->name[1],                         netif->name[0], netif->name[1],
215      (u8_t)(ntohl(netif->ip_addr.addr) >> 24 & 0xff),      (u8_t)(ntohl(netif->ip_addr.addr) >> 24 & 0xff),
216      (u8_t)(ntohl(netif->ip_addr.addr) >> 16 & 0xff),      (u8_t)(ntohl(netif->ip_addr.addr) >> 16 & 0xff),
217      (u8_t)(ntohl(netif->ip_addr.addr) >> 8 & 0xff),      (u8_t)(ntohl(netif->ip_addr.addr) >> 8 & 0xff),
# Line 220  netif_set_gw(struct netif *netif, struct Line 223  netif_set_gw(struct netif *netif, struct
223  {  {
224    ip_addr_set(&(netif->gw), gw);    ip_addr_set(&(netif->gw), gw);
225    DEBUGF(NETIF_DEBUG | DBG_TRACE | DBG_STATE | 3, ("netif: GW address of interface %c%c set to %u.%u.%u.%u\n",    DEBUGF(NETIF_DEBUG | DBG_TRACE | DBG_STATE | 3, ("netif: GW address of interface %c%c set to %u.%u.%u.%u\n",
226                         netif->name[0], netif->name[1],                         netif->name[0], netif->name[1],
227                         (u8_t)(ntohl(netif->gw.addr) >> 24 & 0xff),                         (u8_t)(ntohl(netif->gw.addr) >> 24 & 0xff),
228                         (u8_t)(ntohl(netif->gw.addr) >> 16 & 0xff),                         (u8_t)(ntohl(netif->gw.addr) >> 16 & 0xff),
229                         (u8_t)(ntohl(netif->gw.addr) >> 8 & 0xff),                         (u8_t)(ntohl(netif->gw.addr) >> 8 & 0xff),

Legend:
Removed from v.1.23  
changed lines
  Added in v.1.24

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26