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