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