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