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