source: arduino-1-6-7/trunk/fuentes/arduino-ide-amd64/hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/core/netif.c @ 46

Last change on this file since 46 was 46, checked in by jrpelegrina, 4 years ago

First release to Xenial

File size: 19.0 KB
Line 
1/* This source file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
2
3/**
4 * @file
5 * lwIP network interface abstraction
6 *
7 */
8
9/*
10 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
11 * All rights reserved.
12 *
13 * Redistribution and use in source and binary forms, with or without modification,
14 * are permitted provided that the following conditions are met:
15 *
16 * 1. Redistributions of source code must retain the above copyright notice,
17 *    this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright notice,
19 *    this list of conditions and the following disclaimer in the documentation
20 *    and/or other materials provided with the distribution.
21 * 3. The name of the author may not be used to endorse or promote products
22 *    derived from this software without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
25 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
27 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
29 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
32 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
33 * OF SUCH DAMAGE.
34 *
35 * This file is part of the lwIP TCP/IP stack.
36 *
37 * Author: Adam Dunkels <adam@sics.se>
38 *
39 */
40
41#include "lwip/opt.h"
42
43#include "lwip/def.h"
44#include "lwip/ip_addr.h"
45#include "lwip/netif.h"
46#include "lwip/tcp.h"
47#include "lwip/snmp.h"
48#include "lwip/igmp.h"
49#include "netif/etharp.h"
50#if ENABLE_LOOPBACK
51#include "lwip/sys.h"
52#if LWIP_NETIF_LOOPBACK_MULTITHREADING
53#include "lwip/tcpip.h"
54#endif /* LWIP_NETIF_LOOPBACK_MULTITHREADING */
55#endif /* ENABLE_LOOPBACK */
56
57#if LWIP_AUTOIP
58#include "lwip/autoip.h"
59#endif /* LWIP_AUTOIP */
60#if LWIP_DHCP
61#include "lwip/dhcp.h"
62#endif /* LWIP_DHCP */
63
64#if LWIP_NETIF_STATUS_CALLBACK
65#define NETIF_STATUS_CALLBACK(n) { if (n->status_callback) (n->status_callback)(n); }
66#else
67#define NETIF_STATUS_CALLBACK(n) { /* NOP */ }
68#endif /* LWIP_NETIF_STATUS_CALLBACK */ 
69
70#if LWIP_NETIF_LINK_CALLBACK
71#define NETIF_LINK_CALLBACK(n) { if (n->link_callback) (n->link_callback)(n); }
72#else
73#define NETIF_LINK_CALLBACK(n) { /* NOP */ }
74#endif /* LWIP_NETIF_LINK_CALLBACK */ 
75
76struct netif *netif_list;
77struct netif *netif_default;
78
79/**
80 * Add a network interface to the list of lwIP netifs.
81 *
82 * @param netif a pre-allocated netif structure
83 * @param ipaddr IP address for the new netif
84 * @param netmask network mask for the new netif
85 * @param gw default gateway IP address for the new netif
86 * @param state opaque data passed to the new netif
87 * @param init callback function that initializes the interface
88 * @param input callback function that is called to pass
89 * ingress packets up in the protocol layer stack.
90 *
91 * @return netif, or NULL if failed.
92 */
93struct netif *
94netif_add(struct netif *netif, struct ip_addr *ipaddr, struct ip_addr *netmask,
95  struct ip_addr *gw,
96  void *state,
97  err_t (* init)(struct netif *netif),
98  err_t (* input)(struct pbuf *p, struct netif *netif))
99{
100  static u8_t netifnum = 0;
101
102  /* reset new interface configuration state */
103  netif->ip_addr.addr = 0;
104  netif->netmask.addr = 0;
105  netif->gw.addr = 0;
106  netif->flags = 0;
107#if LWIP_DHCP
108  /* netif not under DHCP control by default */
109  netif->dhcp = NULL;
110#endif /* LWIP_DHCP */
111#if LWIP_AUTOIP
112  /* netif not under AutoIP control by default */
113  netif->autoip = NULL;
114#endif /* LWIP_AUTOIP */
115#if LWIP_NETIF_STATUS_CALLBACK
116  netif->status_callback = NULL;
117#endif /* LWIP_NETIF_STATUS_CALLBACK */
118#if LWIP_NETIF_LINK_CALLBACK
119  netif->link_callback = NULL;
120#endif /* LWIP_NETIF_LINK_CALLBACK */
121#if LWIP_IGMP
122  netif->igmp_mac_filter = NULL;
123#endif /* LWIP_IGMP */
124#if ENABLE_LOOPBACK
125  netif->loop_first = NULL;
126  netif->loop_last = NULL;
127#endif /* ENABLE_LOOPBACK */
128
129  /* remember netif specific state information data */
130  netif->state = state;
131  netif->num = netifnum++;
132  netif->input = input;
133#if LWIP_NETIF_HWADDRHINT
134  netif->addr_hint = NULL;
135#endif /* LWIP_NETIF_HWADDRHINT*/
136#if ENABLE_LOOPBACK && LWIP_LOOPBACK_MAX_PBUFS
137  netif->loop_cnt_current = 0;
138#endif /* ENABLE_LOOPBACK && LWIP_LOOPBACK_MAX_PBUFS */
139
140  netif_set_addr(netif, ipaddr, netmask, gw);
141
142  /* call user specified initialization function for netif */
143  if (init(netif) != ERR_OK) {
144    return NULL;
145  }
146
147  /* add this netif to the list */
148  netif->next = netif_list;
149  netif_list = netif;
150  snmp_inc_iflist();
151
152#if LWIP_IGMP
153  /* start IGMP processing */
154  if (netif->flags & NETIF_FLAG_IGMP) {
155    igmp_start( netif);
156  }
157#endif /* LWIP_IGMP */
158
159  LWIP_DEBUGF(NETIF_DEBUG, ("netif: added interface %c%c IP addr ",
160    netif->name[0], netif->name[1]));
161  ip_addr_debug_print(NETIF_DEBUG, ipaddr);
162  LWIP_DEBUGF(NETIF_DEBUG, (" netmask "));
163  ip_addr_debug_print(NETIF_DEBUG, netmask);
164  LWIP_DEBUGF(NETIF_DEBUG, (" gw "));
165  ip_addr_debug_print(NETIF_DEBUG, gw);
166  LWIP_DEBUGF(NETIF_DEBUG, ("\n"));
167  return netif;
168}
169
170/**
171 * Change IP address configuration for a network interface (including netmask
172 * and default gateway).
173 *
174 * @param netif the network interface to change
175 * @param ipaddr the new IP address
176 * @param netmask the new netmask
177 * @param gw the new default gateway
178 */
179void
180netif_set_addr(struct netif *netif, struct ip_addr *ipaddr, struct ip_addr *netmask,
181    struct ip_addr *gw)
182{
183  netif_set_ipaddr(netif, ipaddr);
184  netif_set_netmask(netif, netmask);
185  netif_set_gw(netif, gw);
186}
187
188/**
189 * Remove a network interface from the list of lwIP netifs.
190 *
191 * @param netif the network interface to remove
192 */
193void netif_remove(struct netif * netif)
194{
195  if ( netif == NULL ) return;
196
197#if LWIP_IGMP
198  /* stop IGMP processing */
199  if (netif->flags & NETIF_FLAG_IGMP) {
200    igmp_stop( netif);
201  }
202#endif /* LWIP_IGMP */
203
204  snmp_delete_ipaddridx_tree(netif);
205
206  /*  is it the first netif? */
207  if (netif_list == netif) {
208    netif_list = netif->next;
209    snmp_dec_iflist();
210  }
211  else {
212    /*  look for netif further down the list */
213    struct netif * tmpNetif;
214    for (tmpNetif = netif_list; tmpNetif != NULL; tmpNetif = tmpNetif->next) {
215      if (tmpNetif->next == netif) {
216        tmpNetif->next = netif->next;
217        snmp_dec_iflist();
218        break;
219      }
220    }
221    if (tmpNetif == NULL)
222      return; /*  we didn't find any netif today */
223  }
224  /* this netif is default? */
225  if (netif_default == netif)
226    /* reset default netif */
227    netif_set_default(NULL);
228  LWIP_DEBUGF( NETIF_DEBUG, ("netif_remove: removed netif\n") );
229}
230
231/**
232 * Find a network interface by searching for its name
233 *
234 * @param name the name of the netif (like netif->name) plus concatenated number
235 * in ascii representation (e.g. 'en0')
236 */
237struct netif *
238netif_find(char *name)
239{
240  struct netif *netif;
241  u8_t num;
242
243  if (name == NULL) {
244    return NULL;
245  }
246
247  num = name[2] - '0';
248
249  for(netif = netif_list; netif != NULL; netif = netif->next) {
250    if (num == netif->num &&
251       name[0] == netif->name[0] &&
252       name[1] == netif->name[1]) {
253      LWIP_DEBUGF(NETIF_DEBUG, ("netif_find: found %c%c\n", name[0], name[1]));
254      return netif;
255    }
256  }
257  LWIP_DEBUGF(NETIF_DEBUG, ("netif_find: didn't find %c%c\n", name[0], name[1]));
258  return NULL;
259}
260
261/**
262 * Change the IP address of a network interface
263 *
264 * @param netif the network interface to change
265 * @param ipaddr the new IP address
266 *
267 * @note call netif_set_addr() if you also want to change netmask and
268 * default gateway
269 */
270void
271netif_set_ipaddr(struct netif *netif, struct ip_addr *ipaddr)
272{
273  /* TODO: Handling of obsolete pcbs */
274  /* See:  http://mail.gnu.org/archive/html/lwip-users/2003-03/msg00118.html */
275#if LWIP_TCP
276  struct tcp_pcb *pcb;
277  struct tcp_pcb_listen *lpcb;
278
279  /* address is actually being changed? */
280  if ((ip_addr_cmp(ipaddr, &(netif->ip_addr))) == 0)
281  {
282    /* extern struct tcp_pcb *tcp_active_pcbs; defined by tcp.h */
283    LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_STATE, ("netif_set_ipaddr: netif address being changed\n"));
284    pcb = tcp_active_pcbs;
285    while (pcb != NULL) {
286      /* PCB bound to current local interface address? */
287      if (ip_addr_cmp(&(pcb->local_ip), &(netif->ip_addr))) {
288        /* this connection must be aborted */
289        struct tcp_pcb *next = pcb->next;
290        LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_STATE, ("netif_set_ipaddr: aborting TCP pcb %p\n", (void *)pcb));
291        tcp_abort(pcb);
292        pcb = next;
293      } else {
294        pcb = pcb->next;
295      }
296    }
297    for (lpcb = tcp_listen_pcbs.listen_pcbs; lpcb != NULL; lpcb = lpcb->next) {
298      /* PCB bound to current local interface address? */
299      if ((!(ip_addr_isany(&(lpcb->local_ip)))) &&
300          (ip_addr_cmp(&(lpcb->local_ip), &(netif->ip_addr)))) {
301        /* The PCB is listening to the old ipaddr and
302         * is set to listen to the new one instead */
303        ip_addr_set(&(lpcb->local_ip), ipaddr);
304      }
305    }
306  }
307#endif
308  snmp_delete_ipaddridx_tree(netif);
309  snmp_delete_iprteidx_tree(0,netif);
310  /* set new IP address to netif */
311  ip_addr_set(&(netif->ip_addr), ipaddr);
312  snmp_insert_ipaddridx_tree(netif);
313  snmp_insert_iprteidx_tree(0,netif);
314
315  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",
316    netif->name[0], netif->name[1],
317    ip4_addr1(&netif->ip_addr),
318    ip4_addr2(&netif->ip_addr),
319    ip4_addr3(&netif->ip_addr),
320    ip4_addr4(&netif->ip_addr)));
321}
322
323/**
324 * Change the default gateway for a network interface
325 *
326 * @param netif the network interface to change
327 * @param gw the new default gateway
328 *
329 * @note call netif_set_addr() if you also want to change ip address and netmask
330 */
331void
332netif_set_gw(struct netif *netif, struct ip_addr *gw)
333{
334  ip_addr_set(&(netif->gw), gw);
335  LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("netif: GW address of interface %c%c set to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
336    netif->name[0], netif->name[1],
337    ip4_addr1(&netif->gw),
338    ip4_addr2(&netif->gw),
339    ip4_addr3(&netif->gw),
340    ip4_addr4(&netif->gw)));
341}
342
343/**
344 * Change the netmask of a network interface
345 *
346 * @param netif the network interface to change
347 * @param netmask the new netmask
348 *
349 * @note call netif_set_addr() if you also want to change ip address and
350 * default gateway
351 */
352void
353netif_set_netmask(struct netif *netif, struct ip_addr *netmask)
354{
355  snmp_delete_iprteidx_tree(0, netif);
356  /* set new netmask to netif */
357  ip_addr_set(&(netif->netmask), netmask);
358  snmp_insert_iprteidx_tree(0, netif);
359  LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("netif: netmask of interface %c%c set to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
360    netif->name[0], netif->name[1],
361    ip4_addr1(&netif->netmask),
362    ip4_addr2(&netif->netmask),
363    ip4_addr3(&netif->netmask),
364    ip4_addr4(&netif->netmask)));
365}
366
367/**
368 * Set a network interface as the default network interface
369 * (used to output all packets for which no specific route is found)
370 *
371 * @param netif the default network interface
372 */
373void
374netif_set_default(struct netif *netif)
375{
376  if (netif == NULL)
377  {
378    /* remove default route */
379    snmp_delete_iprteidx_tree(1, netif);
380  }
381  else
382  {
383    /* install default route */
384    snmp_insert_iprteidx_tree(1, netif);
385  }
386  netif_default = netif;
387  LWIP_DEBUGF(NETIF_DEBUG, ("netif: setting default interface %c%c\n",
388           netif ? netif->name[0] : '\'', netif ? netif->name[1] : '\''));
389}
390
391/**
392 * Bring an interface up, available for processing
393 * traffic.
394 *
395 * @note: Enabling DHCP on a down interface will make it come
396 * up once configured.
397 *
398 * @see dhcp_start()
399 */ 
400void netif_set_up(struct netif *netif)
401{
402  if ( !(netif->flags & NETIF_FLAG_UP )) {
403    netif->flags |= NETIF_FLAG_UP;
404   
405#if LWIP_SNMP
406    snmp_get_sysuptime(&netif->ts);
407#endif /* LWIP_SNMP */
408
409    NETIF_LINK_CALLBACK(netif);
410    NETIF_STATUS_CALLBACK(netif);
411
412#if LWIP_ARP
413    /* For Ethernet network interfaces, we would like to send a "gratuitous ARP" */ 
414    if (netif->flags & NETIF_FLAG_ETHARP) {
415      etharp_gratuitous(netif);
416    }
417#endif /* LWIP_ARP */
418
419#if LWIP_IGMP
420    /* resend IGMP memberships */
421    if (netif->flags & NETIF_FLAG_IGMP) {
422      igmp_report_groups( netif);
423    }
424#endif /* LWIP_IGMP */
425  }
426}
427
428/**
429 * Bring an interface down, disabling any traffic processing.
430 *
431 * @note: Enabling DHCP on a down interface will make it come
432 * up once configured.
433 *
434 * @see dhcp_start()
435 */ 
436void netif_set_down(struct netif *netif)
437{
438  if ( netif->flags & NETIF_FLAG_UP )
439    {
440      netif->flags &= ~NETIF_FLAG_UP;
441#if LWIP_SNMP
442      snmp_get_sysuptime(&netif->ts);
443#endif
444     
445      NETIF_LINK_CALLBACK(netif);
446      NETIF_STATUS_CALLBACK(netif);
447    }
448}
449
450/**
451 * Ask if an interface is up
452 */ 
453u8_t netif_is_up(struct netif *netif)
454{
455  return (netif->flags & NETIF_FLAG_UP)?1:0;
456}
457
458#if LWIP_NETIF_STATUS_CALLBACK
459/**
460 * Set callback to be called when interface is brought up/down
461 */
462void netif_set_status_callback(struct netif *netif, void (* status_callback)(struct netif *netif ))
463{
464    if ( netif )
465        netif->status_callback = status_callback;
466}
467#endif /* LWIP_NETIF_STATUS_CALLBACK */
468
469#if LWIP_NETIF_LINK_CALLBACK
470/**
471 * Called by a driver when its link goes up
472 */
473void netif_set_link_up(struct netif *netif )
474{
475  netif->flags |= NETIF_FLAG_LINK_UP;
476
477#if LWIP_DHCP
478  if (netif->dhcp) {
479    dhcp_network_changed(netif);
480  }
481#endif /* LWIP_DHCP */
482
483#if LWIP_AUTOIP
484  if (netif->autoip) {
485    autoip_network_changed(netif);
486  }
487#endif /* LWIP_AUTOIP */
488
489  if (netif->flags & NETIF_FLAG_UP) {
490#if LWIP_ARP
491  /* For Ethernet network interfaces, we would like to send a "gratuitous ARP" */ 
492  if (netif->flags & NETIF_FLAG_ETHARP) {
493    etharp_gratuitous(netif);
494  }
495#endif /* LWIP_ARP */
496
497#if LWIP_IGMP
498    /* resend IGMP memberships */
499    if (netif->flags & NETIF_FLAG_IGMP) {
500      igmp_report_groups( netif);
501    }
502#endif /* LWIP_IGMP */
503  }
504  NETIF_LINK_CALLBACK(netif);
505}
506
507/**
508 * Called by a driver when its link goes down
509 */
510void netif_set_link_down(struct netif *netif )
511{
512  netif->flags &= ~NETIF_FLAG_LINK_UP;
513  NETIF_LINK_CALLBACK(netif);
514}
515
516/**
517 * Ask if a link is up
518 */ 
519u8_t netif_is_link_up(struct netif *netif)
520{
521  return (netif->flags & NETIF_FLAG_LINK_UP) ? 1 : 0;
522}
523
524/**
525 * Set callback to be called when link is brought up/down
526 */
527void netif_set_link_callback(struct netif *netif, void (* link_callback)(struct netif *netif ))
528{
529  if (netif) {
530    netif->link_callback = link_callback;
531  }
532}
533#endif /* LWIP_NETIF_LINK_CALLBACK */
534
535#if ENABLE_LOOPBACK
536/**
537 * Send an IP packet to be received on the same netif (loopif-like).
538 * The pbuf is simply copied and handed back to netif->input.
539 * In multithreaded mode, this is done directly since netif->input must put
540 * the packet on a queue.
541 * In callback mode, the packet is put on an internal queue and is fed to
542 * netif->input by netif_poll().
543 *
544 * @param netif the lwip network interface structure
545 * @param p the (IP) packet to 'send'
546 * @param ipaddr the ip address to send the packet to (not used)
547 * @return ERR_OK if the packet has been sent
548 *         ERR_MEM if the pbuf used to copy the packet couldn't be allocated
549 */
550err_t
551netif_loop_output(struct netif *netif, struct pbuf *p,
552       struct ip_addr *ipaddr)
553{
554  struct pbuf *r;
555  err_t err;
556  struct pbuf *last;
557#if LWIP_LOOPBACK_MAX_PBUFS
558  u8_t clen = 0;
559#endif /* LWIP_LOOPBACK_MAX_PBUFS */
560  SYS_ARCH_DECL_PROTECT(lev);
561  LWIP_UNUSED_ARG(ipaddr);
562
563  /* Allocate a new pbuf */
564  r = pbuf_alloc(PBUF_LINK, p->tot_len, PBUF_RAM);
565  if (r == NULL) {
566    return ERR_MEM;
567  }
568#if LWIP_LOOPBACK_MAX_PBUFS
569  clen = pbuf_clen(r);
570  /* check for overflow or too many pbuf on queue */
571  if(((netif->loop_cnt_current + clen) < netif->loop_cnt_current) ||
572    ((netif->loop_cnt_current + clen) > LWIP_LOOPBACK_MAX_PBUFS)) {
573      pbuf_free(r);
574      r = NULL;
575      return ERR_MEM;
576  }
577  netif->loop_cnt_current += clen;
578#endif /* LWIP_LOOPBACK_MAX_PBUFS */
579
580  /* Copy the whole pbuf queue p into the single pbuf r */
581  if ((err = pbuf_copy(r, p)) != ERR_OK) {
582    pbuf_free(r);
583    r = NULL;
584    return err;
585  }
586
587  /* Put the packet on a linked list which gets emptied through calling
588     netif_poll(). */
589
590  /* let last point to the last pbuf in chain r */
591  for (last = r; last->next != NULL; last = last->next);
592
593  SYS_ARCH_PROTECT(lev);
594  if(netif->loop_first != NULL) {
595    LWIP_ASSERT("if first != NULL, last must also be != NULL", netif->loop_last != NULL);
596    netif->loop_last->next = r;
597    netif->loop_last = last;
598  } else {
599    netif->loop_first = r;
600    netif->loop_last = last;
601  }
602  SYS_ARCH_UNPROTECT(lev);
603
604#if LWIP_NETIF_LOOPBACK_MULTITHREADING
605  /* For multithreading environment, schedule a call to netif_poll */
606  tcpip_callback((void (*)(void *))(netif_poll), netif);
607#endif /* LWIP_NETIF_LOOPBACK_MULTITHREADING */
608
609  return ERR_OK;
610}
611
612/**
613 * Call netif_poll() in the main loop of your application. This is to prevent
614 * reentering non-reentrant functions like tcp_input(). Packets passed to
615 * netif_loop_output() are put on a list that is passed to netif->input() by
616 * netif_poll().
617 */
618void
619netif_poll(struct netif *netif)
620{
621  struct pbuf *in;
622  SYS_ARCH_DECL_PROTECT(lev);
623
624  do {
625    /* Get a packet from the list. With SYS_LIGHTWEIGHT_PROT=1, this is protected */
626    SYS_ARCH_PROTECT(lev);
627    in = netif->loop_first;
628    if(in != NULL) {
629      struct pbuf *in_end = in;
630#if LWIP_LOOPBACK_MAX_PBUFS
631      u8_t clen = pbuf_clen(in);
632      /* adjust the number of pbufs on queue */
633      LWIP_ASSERT("netif->loop_cnt_current underflow",
634        ((netif->loop_cnt_current - clen) < netif->loop_cnt_current));
635      netif->loop_cnt_current -= clen;
636#endif /* LWIP_LOOPBACK_MAX_PBUFS */
637      while(in_end->len != in_end->tot_len) {
638        LWIP_ASSERT("bogus pbuf: len != tot_len but next == NULL!", in_end->next != NULL);
639        in_end = in_end->next;
640      }
641      /* 'in_end' now points to the last pbuf from 'in' */
642      if(in_end == netif->loop_last) {
643        /* this was the last pbuf in the list */
644        netif->loop_first = netif->loop_last = NULL;
645      } else {
646        /* pop the pbuf off the list */
647        netif->loop_first = in_end->next;
648        LWIP_ASSERT("should not be null since first != last!", netif->loop_first != NULL);
649      }
650      /* De-queue the pbuf from its successors on the 'loop_' list. */
651      in_end->next = NULL;
652    }
653    SYS_ARCH_UNPROTECT(lev);
654
655    if(in != NULL) {
656      /* loopback packets are always IP packets! */
657      if(ip_input(in, netif) != ERR_OK) {
658        pbuf_free(in);
659      }
660      /* Don't reference the packet any more! */
661      in = NULL;
662    }
663  /* go on while there is a packet on the list */
664  } while(netif->loop_first != NULL);
665}
666
667#if !LWIP_NETIF_LOOPBACK_MULTITHREADING
668/**
669 * Calls netif_poll() for every netif on the netif_list.
670 */
671void
672netif_poll_all(void)
673{
674  struct netif *netif = netif_list;
675  /* loop through netifs */
676  while (netif != NULL) {
677    netif_poll(netif);
678    /* proceed to next network interface */
679    netif = netif->next;
680  }
681}
682#endif /* !LWIP_NETIF_LOOPBACK_MULTITHREADING */
683#endif /* ENABLE_LOOPBACK */
Note: See TracBrowser for help on using the repository browser.