]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lwip.git/blob - src/core/ipv4/ip.c
Minor changes (documentation).
[pes-rpp/rpp-lwip.git] / src / core / ipv4 / ip.c
1 /**
2  * @file
3  * This is the IPv4 layer implementation for incoming and outgoing IP traffic.
4  * 
5  * @see ip_frag.c
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 #include "lwip/ip.h"
43 #include "lwip/def.h"
44 #include "lwip/mem.h"
45 #include "lwip/ip_frag.h"
46 #include "lwip/inet.h"
47 #include "lwip/inet_chksum.h"
48 #include "lwip/netif.h"
49 #include "lwip/icmp.h"
50 #include "lwip/igmp.h"
51 #include "lwip/raw.h"
52 #include "lwip/udp.h"
53 #include "lwip/tcp.h"
54 #include "lwip/snmp.h"
55 #include "lwip/dhcp.h"
56 #include "lwip/stats.h"
57 #include "arch/perf.h"
58
59 /**
60  * Finds the appropriate network interface for a given IP address. It
61  * searches the list of network interfaces linearly. A match is found
62  * if the masked IP address of the network interface equals the masked
63  * IP address given to the function.
64  *
65  * @param dest the destination IP address for which to find the route
66  * @return the netif on which to send to reach dest
67  */
68 struct netif *
69 ip_route(struct ip_addr *dest)
70 {
71   struct netif *netif;
72
73   /* iterate through netifs */
74   for(netif = netif_list; netif != NULL; netif = netif->next) {
75     /* network mask matches? */
76     if (ip_addr_netcmp(dest, &(netif->ip_addr), &(netif->netmask))) {
77       /* return netif on which to forward IP packet */
78       return netif;
79     }
80   }
81   if (netif_default == NULL) {
82     LWIP_DEBUGF(IP_DEBUG | 2, ("ip_route: No route to 0x%"X32_F"\n", dest->addr));
83     IP_STATS_INC(ip.rterr);
84     snmp_inc_ipoutnoroutes();
85   }
86   /* no matching netif found, use default netif */
87   return netif_default;
88 }
89
90 #if IP_FORWARD
91 /**
92  * Forwards an IP packet. It finds an appropriate route for the
93  * packet, decrements the TTL value of the packet, adjusts the
94  * checksum and outputs the packet on the appropriate interface.
95  *
96  * @param p the packet to forward (p->payload points to IP header)
97  * @param iphdr the IP header of the input packet
98  * @param inp the netif on which this packet was received
99  * @return the netif on which the packet was sent (NULL if it wasn't sent)
100  */
101 static struct netif *
102 ip_forward(struct pbuf *p, struct ip_hdr *iphdr, struct netif *inp)
103 {
104   struct netif *netif;
105
106   PERF_START;
107   /* Find network interface where to forward this IP packet to. */
108   netif = ip_route((struct ip_addr *)&(iphdr->dest));
109   if (netif == NULL) {
110     LWIP_DEBUGF(IP_DEBUG, ("ip_forward: no forwarding route for 0x%"X32_F" found\n",
111                       iphdr->dest.addr));
112     snmp_inc_ipoutnoroutes();
113     return (struct netif *)NULL;
114   }
115   /* Do not forward packets onto the same network interface on which
116    * they arrived. */
117   if (netif == inp) {
118     LWIP_DEBUGF(IP_DEBUG, ("ip_forward: not bouncing packets back on incoming interface.\n"));
119     snmp_inc_ipoutnoroutes();
120     return (struct netif *)NULL;
121   }
122
123   /* decrement TTL */
124   IPH_TTL_SET(iphdr, IPH_TTL(iphdr) - 1);
125   /* send ICMP if TTL == 0 */
126   if (IPH_TTL(iphdr) == 0) {
127     snmp_inc_ipinhdrerrors();
128 #if LWIP_ICMP
129     /* Don't send ICMP messages in response to ICMP messages */
130     if (IPH_PROTO(iphdr) != IP_PROTO_ICMP) {
131       icmp_time_exceeded(p, ICMP_TE_TTL);
132     }
133 #endif /* LWIP_ICMP */
134     return (struct netif *)NULL;
135   }
136
137   /* Incrementally update the IP checksum. */
138   if (IPH_CHKSUM(iphdr) >= htons(0xffff - 0x100)) {
139     IPH_CHKSUM_SET(iphdr, IPH_CHKSUM(iphdr) + htons(0x100) + 1);
140   } else {
141     IPH_CHKSUM_SET(iphdr, IPH_CHKSUM(iphdr) + htons(0x100));
142   }
143
144   LWIP_DEBUGF(IP_DEBUG, ("ip_forward: forwarding packet to 0x%"X32_F"\n",
145                     iphdr->dest.addr));
146
147   IP_STATS_INC(ip.fw);
148   IP_STATS_INC(ip.xmit);
149   snmp_inc_ipforwdatagrams();
150
151   PERF_STOP("ip_forward");
152   /* transmit pbuf on chosen interface */
153   netif->output(netif, p, (struct ip_addr *)&(iphdr->dest));
154   return netif;
155 }
156 #endif /* IP_FORWARD */
157
158 /**
159  * This function is called by the network interface device driver when
160  * an IP packet is received. The function does the basic checks of the
161  * IP header such as packet size being at least larger than the header
162  * size etc. If the packet was not destined for us, the packet is
163  * forwarded (using ip_forward). The IP checksum is always checked.
164  *
165  * Finally, the packet is sent to the upper layer protocol input function.
166  * 
167  * @param p the received IP packet (p->payload points to IP header)
168  * @param inp the netif on which this packet was received
169  * @return ERR_OK if the packet was processed (could return ERR_* if it wasn't
170  *         processed, but currently always returns ERR_OK)
171  */
172 err_t
173 ip_input(struct pbuf *p, struct netif *inp) {
174   struct ip_hdr *iphdr;
175   struct netif *netif;
176   u16_t iphdrlen;
177
178   IP_STATS_INC(ip.recv);
179   snmp_inc_ipinreceives();
180
181   /* identify the IP header */
182   iphdr = p->payload;
183   if (IPH_V(iphdr) != 4) {
184     LWIP_DEBUGF(IP_DEBUG | 1, ("IP packet dropped due to bad version number %"U16_F"\n", IPH_V(iphdr)));
185     ip_debug_print(p);
186     pbuf_free(p);
187     IP_STATS_INC(ip.err);
188     IP_STATS_INC(ip.drop);
189     snmp_inc_ipinhdrerrors();
190     return ERR_OK;
191   }
192   /* obtain IP header length in number of 32-bit words */
193   iphdrlen = IPH_HL(iphdr);
194   /* calculate IP header length in bytes */
195   iphdrlen *= 4;
196
197   /* header length exceeds first pbuf length? */
198   if (iphdrlen > p->len) {
199     LWIP_DEBUGF(IP_DEBUG | 2, ("IP header (len %"U16_F") does not fit in first pbuf (len %"U16_F"), IP packet droppped.\n",
200       iphdrlen, p->len));
201     /* free (drop) packet pbufs */
202     pbuf_free(p);
203     IP_STATS_INC(ip.lenerr);
204     IP_STATS_INC(ip.drop);
205     snmp_inc_ipindiscards();
206     return ERR_OK;
207   }
208
209   /* verify checksum */
210 #if CHECKSUM_CHECK_IP
211   if (inet_chksum(iphdr, iphdrlen) != 0) {
212
213     LWIP_DEBUGF(IP_DEBUG | 2, ("Checksum (0x%"X16_F") failed, IP packet dropped.\n", inet_chksum(iphdr, iphdrlen)));
214     ip_debug_print(p);
215     pbuf_free(p);
216     IP_STATS_INC(ip.chkerr);
217     IP_STATS_INC(ip.drop);
218     snmp_inc_ipinhdrerrors();
219     return ERR_OK;
220   }
221 #endif
222
223   /* Trim pbuf. This should have been done at the netif layer,
224    * but we'll do it anyway just to be sure that its done. */
225   pbuf_realloc(p, ntohs(IPH_LEN(iphdr)));
226
227   /* match packet against an interface, i.e. is this packet for us? */
228 #if LWIP_IGMP
229   if (ip_addr_ismulticast(&(iphdr->dest)))
230    { if ((inp->flags & NETIF_FLAG_IGMP) && (igmp_lookfor_group( inp, &(iphdr->dest))))
231       { netif = inp;
232       }
233      else
234       { netif = NULL;
235       } 
236    }
237   else
238    {
239 #endif /* LWIP_IGMP */
240    for (netif = netif_list; netif != NULL; netif = netif->next) {
241
242      LWIP_DEBUGF(IP_DEBUG, ("ip_input: iphdr->dest 0x%"X32_F" netif->ip_addr 0x%"X32_F" (0x%"X32_F", 0x%"X32_F", 0x%"X32_F")\n",
243        iphdr->dest.addr, netif->ip_addr.addr,
244        iphdr->dest.addr & netif->netmask.addr,
245        netif->ip_addr.addr & netif->netmask.addr,
246        iphdr->dest.addr & ~(netif->netmask.addr)));
247
248      /* interface is up and configured? */
249      if ((netif_is_up(netif)) && (!ip_addr_isany(&(netif->ip_addr))))
250      {
251        /* unicast to this interface address? */
252        if (ip_addr_cmp(&(iphdr->dest), &(netif->ip_addr)) ||
253           /* or broadcast on this interface network address? */
254           ip_addr_isbroadcast(&(iphdr->dest), netif)) {
255          LWIP_DEBUGF(IP_DEBUG, ("ip_input: packet accepted on interface %c%c\n",
256            netif->name[0], netif->name[1]));
257          /* break out of for loop */
258          break;
259        }
260      }
261    }
262  #if LWIP_IGMP
263  }
264  #endif /* LWIP_IGMP */
265  
266 #if LWIP_DHCP
267   /* Pass DHCP messages regardless of destination address. DHCP traffic is addressed
268    * using link layer addressing (such as Ethernet MAC) so we must not filter on IP.
269    * According to RFC 1542 section 3.1.1, referred by RFC 2131).
270    */
271   if (netif == NULL) {
272     /* remote port is DHCP server? */
273     if (IPH_PROTO(iphdr) == IP_PROTO_UDP) {
274       LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_TRACE | 1, ("ip_input: UDP packet to DHCP client port %"U16_F"\n",
275         ntohs(((struct udp_hdr *)((u8_t *)iphdr + iphdrlen))->dest)));
276       if (ntohs(((struct udp_hdr *)((u8_t *)iphdr + iphdrlen))->dest) == DHCP_CLIENT_PORT) {
277         LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_TRACE | 1, ("ip_input: DHCP packet accepted.\n"));
278         netif = inp;
279       }
280     }
281   }
282 #endif /* LWIP_DHCP */
283   /* packet not for us? */
284   if (netif == NULL) {
285     /* packet not for us, route or discard */
286     LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_TRACE | 1, ("ip_input: packet not for us.\n"));
287 #if IP_FORWARD
288     /* non-broadcast packet? */
289     if (!ip_addr_isbroadcast(&(iphdr->dest), inp)) {
290       /* try to forward IP packet on (other) interfaces */
291       ip_forward(p, iphdr, inp);
292     }
293     else
294 #endif /* IP_FORWARD */
295     {
296       snmp_inc_ipinaddrerrors();
297       snmp_inc_ipindiscards();
298     }
299     pbuf_free(p);
300     return ERR_OK;
301   }
302   /* packet consists of multiple fragments? */
303   if ((IPH_OFFSET(iphdr) & htons(IP_OFFMASK | IP_MF)) != 0) {
304 #if IP_REASSEMBLY /* packet fragment reassembly code present? */
305     LWIP_DEBUGF(IP_DEBUG, ("IP packet is a fragment (id=0x%04"X16_F" tot_len=%"U16_F" len=%"U16_F" MF=%"U16_F" offset=%"U16_F"), calling ip_reass()\n",
306       ntohs(IPH_ID(iphdr)), p->tot_len, ntohs(IPH_LEN(iphdr)), !!(IPH_OFFSET(iphdr) & htons(IP_MF)), (ntohs(IPH_OFFSET(iphdr)) & IP_OFFMASK)*8));
307     /* reassemble the packet*/
308     p = ip_reass(p);
309     /* packet not fully reassembled yet? */
310     if (p == NULL) {
311       return ERR_OK;
312     }
313     iphdr = p->payload;
314 #else /* IP_REASSEMBLY == 0, no packet fragment reassembly code present */
315     pbuf_free(p);
316     LWIP_DEBUGF(IP_DEBUG | 2, ("IP packet dropped since it was fragmented (0x%"X16_F") (while IP_REASSEMBLY == 0).\n",
317       ntohs(IPH_OFFSET(iphdr))));
318     IP_STATS_INC(ip.opterr);
319     IP_STATS_INC(ip.drop);
320     /* unsupported protocol feature */
321     snmp_inc_ipinunknownprotos();
322     return ERR_OK;
323 #endif /* IP_REASSEMBLY */
324   }
325
326 #if IP_OPTIONS == 0 /* no support for IP options in the IP header? */
327
328 #if LWIP_IGMP
329   /* there is an extra "router alert" option in IGMP messages which we allow for but do not police */
330   if((iphdrlen > IP_HLEN &&  (IPH_PROTO(iphdr) != IP_PROTO_IGMP)) {
331 #else
332   if (iphdrlen > IP_HLEN) {
333 #endif /* LWIP_IGMP */
334     LWIP_DEBUGF(IP_DEBUG | 2, ("IP packet dropped since there were IP options (while IP_OPTIONS == 0).\n"));
335     pbuf_free(p);
336     IP_STATS_INC(ip.opterr);
337     IP_STATS_INC(ip.drop);
338     /* unsupported protocol feature */
339     snmp_inc_ipinunknownprotos();
340     return ERR_OK;
341   }
342 #endif /* IP_OPTIONS == 0 */
343
344   /* send to upper layers */
345   LWIP_DEBUGF(IP_DEBUG, ("ip_input: \n"));
346   ip_debug_print(p);
347   LWIP_DEBUGF(IP_DEBUG, ("ip_input: p->len %"U16_F" p->tot_len %"U16_F"\n", p->len, p->tot_len));
348
349 #if LWIP_RAW
350   /* raw input did not eat the packet? */
351   if (raw_input(p, inp) == 0) {
352 #endif /* LWIP_RAW */
353
354   switch (IPH_PROTO(iphdr)) {
355 #if LWIP_UDP
356   case IP_PROTO_UDP:
357 #if LWIP_UDPLITE
358   case IP_PROTO_UDPLITE:
359 #endif /* LWIP_UDPLITE */
360     snmp_inc_ipindelivers();
361     udp_input(p, inp);
362     break;
363 #endif /* LWIP_UDP */
364 #if LWIP_TCP
365   case IP_PROTO_TCP:
366     snmp_inc_ipindelivers();
367     tcp_input(p, inp);
368     break;
369 #endif /* LWIP_TCP */
370 #if LWIP_ICMP
371   case IP_PROTO_ICMP:
372     snmp_inc_ipindelivers();
373     icmp_input(p, inp);
374     break;
375 #endif /* LWIP_ICMP */
376 #if LWIP_IGMP
377   case IP_PROTO_IGMP:
378     igmp_input(p,inp,&(iphdr->dest));
379     break;
380 #endif /* LWIP_IGMP */
381   default:
382 #if LWIP_ICMP
383     /* send ICMP destination protocol unreachable unless is was a broadcast */
384     if (!ip_addr_isbroadcast(&(iphdr->dest), inp) &&
385         !ip_addr_ismulticast(&(iphdr->dest))) {
386       p->payload = iphdr;
387       icmp_dest_unreach(p, ICMP_DUR_PROTO);
388     }
389 #endif /* LWIP_ICMP */
390     pbuf_free(p);
391
392     LWIP_DEBUGF(IP_DEBUG | 2, ("Unsupported transport protocol %"U16_F"\n", IPH_PROTO(iphdr)));
393
394     IP_STATS_INC(ip.proterr);
395     IP_STATS_INC(ip.drop);
396     snmp_inc_ipinunknownprotos();
397   }
398 #if LWIP_RAW
399   } /* LWIP_RAW */
400 #endif
401   return ERR_OK;
402 }
403
404 /**
405  * Sends an IP packet on a network interface. This function constructs
406  * the IP header and calculates the IP header checksum. If the source
407  * IP address is NULL, the IP address of the outgoing network
408  * interface is filled in as source address.
409  * If the destination IP address is IP_HDRINCL, p is assumed to already
410  * include an IP header and p->payload points to it instead of the data.
411  *
412  * @param p the packet to send (p->payload points to the data, e.g. next
413             protocol header; if dest == IP_HDRINCL, p already includes an IP
414             header and p->payload points to that IP header)
415  * @param src the source IP address to send from (if src == IP_ADDR_ANY, the
416  *         IP  address of the netif used to send is used as source address)
417  * @param dest the destination IP address to send the packet to
418  * @param ttl the TTL value to be set in the IP header
419  * @param tos the TOS value to be set in the IP header
420  * @param proto the PROTOCOL to be set in the IP header
421  * @param netif the netif on which to send this packet
422  * @return ERR_OK if the packet was sent OK
423  *         ERR_BUF if p doesn't have enough space for IP/LINK headers
424  *         returns errors returned by netif->output
425  *
426  * @note ip_id: RFC791 "some host may be able to simply use
427  *  unique identifiers independent of destination"
428  */
429 err_t
430 ip_output_if(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
431              u8_t ttl, u8_t tos,
432              u8_t proto, struct netif *netif)
433 {
434   struct ip_hdr *iphdr;
435   static u16_t ip_id = 0;
436
437   snmp_inc_ipoutrequests();
438
439   /* Should the IP header be generated or is it already included in p? */
440   if (dest != IP_HDRINCL) {
441     /* generate IP header */
442     if (pbuf_header(p, IP_HLEN)) {
443       LWIP_DEBUGF(IP_DEBUG | 2, ("ip_output: not enough room for IP header in pbuf\n"));
444
445       IP_STATS_INC(ip.err);
446       snmp_inc_ipoutdiscards();
447       return ERR_BUF;
448     }
449
450     iphdr = p->payload;
451     LWIP_ASSERT("check that first pbuf can hold struct ip_hdr",
452                (p->len >= sizeof(struct ip_hdr)));
453
454     IPH_TTL_SET(iphdr, ttl);
455     IPH_PROTO_SET(iphdr, proto);
456
457     ip_addr_set(&(iphdr->dest), dest);
458
459     IPH_VHLTOS_SET(iphdr, 4, IP_HLEN / 4, tos);
460     IPH_LEN_SET(iphdr, htons(p->tot_len));
461     IPH_OFFSET_SET(iphdr, 0);
462     IPH_ID_SET(iphdr, htons(ip_id));
463     ++ip_id;
464
465     if (ip_addr_isany(src)) {
466       ip_addr_set(&(iphdr->src), &(netif->ip_addr));
467     } else {
468       ip_addr_set(&(iphdr->src), src);
469     }
470
471     IPH_CHKSUM_SET(iphdr, 0);
472 #if CHECKSUM_GEN_IP
473     IPH_CHKSUM_SET(iphdr, inet_chksum(iphdr, IP_HLEN));
474 #endif
475   } else {
476     /* IP header already included in p */
477     iphdr = p->payload;
478     dest = &(iphdr->dest);
479   }
480
481 #if IP_FRAG
482   /* don't fragment if interface has mtu set to 0 [loopif] */
483   if (netif->mtu && (p->tot_len > netif->mtu))
484     return ip_frag(p,netif,dest);
485 #endif
486
487   IP_STATS_INC(ip.xmit);
488
489   LWIP_DEBUGF(IP_DEBUG, ("ip_output_if: %c%c%"U16_F"\n", netif->name[0], netif->name[1], netif->num));
490   ip_debug_print(p);
491
492   LWIP_DEBUGF(IP_DEBUG, ("netif->output()"));
493
494   return netif->output(netif, p, dest);
495 }
496
497 /**
498  * Simple interface to ip_output_if. It finds the outgoing network
499  * interface and calls upon ip_output_if to do the actual work.
500  *
501  * @param p the packet to send (p->payload points to the data, e.g. next
502             protocol header; if dest == IP_HDRINCL, p already includes an IP
503             header and p->payload points to that IP header)
504  * @param src the source IP address to send from (if src == IP_ADDR_ANY, the
505  *         IP  address of the netif used to send is used as source address)
506  * @param dest the destination IP address to send the packet to
507  * @param ttl the TTL value to be set in the IP header
508  * @param tos the TOS value to be set in the IP header
509  * @param proto the PROTOCOL to be set in the IP header
510  *
511  * @return ERR_RTE if no route is found
512  *         see ip_output_if() for more return values
513  */
514 err_t
515 ip_output(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
516           u8_t ttl, u8_t tos, u8_t proto)
517 {
518   struct netif *netif;
519
520   if ((netif = ip_route(dest)) == NULL) {
521     return ERR_RTE;
522   }
523
524   return ip_output_if(p, src, dest, ttl, tos, proto, netif);
525 }
526
527 #if IP_DEBUG
528 /* Print an IP header by using LWIP_DEBUGF
529  * @param p an IP packet, p->payload pointing to the IP header
530  */
531 void
532 ip_debug_print(struct pbuf *p)
533 {
534   struct ip_hdr *iphdr = p->payload;
535   u8_t *payload;
536
537   payload = (u8_t *)iphdr + IP_HLEN;
538
539   LWIP_DEBUGF(IP_DEBUG, ("IP header:\n"));
540   LWIP_DEBUGF(IP_DEBUG, ("+-------------------------------+\n"));
541   LWIP_DEBUGF(IP_DEBUG, ("|%2"S16_F" |%2"S16_F" |  0x%02"X16_F" |     %5"U16_F"     | (v, hl, tos, len)\n",
542                     IPH_V(iphdr),
543                     IPH_HL(iphdr),
544                     IPH_TOS(iphdr),
545                     ntohs(IPH_LEN(iphdr))));
546   LWIP_DEBUGF(IP_DEBUG, ("+-------------------------------+\n"));
547   LWIP_DEBUGF(IP_DEBUG, ("|    %5"U16_F"      |%"U16_F"%"U16_F"%"U16_F"|    %4"U16_F"   | (id, flags, offset)\n",
548                     ntohs(IPH_ID(iphdr)),
549                     ntohs(IPH_OFFSET(iphdr)) >> 15 & 1,
550                     ntohs(IPH_OFFSET(iphdr)) >> 14 & 1,
551                     ntohs(IPH_OFFSET(iphdr)) >> 13 & 1,
552                     ntohs(IPH_OFFSET(iphdr)) & IP_OFFMASK));
553   LWIP_DEBUGF(IP_DEBUG, ("+-------------------------------+\n"));
554   LWIP_DEBUGF(IP_DEBUG, ("|  %3"U16_F"  |  %3"U16_F"  |    0x%04"X16_F"     | (ttl, proto, chksum)\n",
555                     IPH_TTL(iphdr),
556                     IPH_PROTO(iphdr),
557                     ntohs(IPH_CHKSUM(iphdr))));
558   LWIP_DEBUGF(IP_DEBUG, ("+-------------------------------+\n"));
559   LWIP_DEBUGF(IP_DEBUG, ("|  %3"U16_F"  |  %3"U16_F"  |  %3"U16_F"  |  %3"U16_F"  | (src)\n",
560                     ip4_addr1(&iphdr->src),
561                     ip4_addr2(&iphdr->src),
562                     ip4_addr3(&iphdr->src),
563                     ip4_addr4(&iphdr->src)));
564   LWIP_DEBUGF(IP_DEBUG, ("+-------------------------------+\n"));
565   LWIP_DEBUGF(IP_DEBUG, ("|  %3"U16_F"  |  %3"U16_F"  |  %3"U16_F"  |  %3"U16_F"  | (dest)\n",
566                     ip4_addr1(&iphdr->dest),
567                     ip4_addr2(&iphdr->dest),
568                     ip4_addr3(&iphdr->dest),
569                     ip4_addr4(&iphdr->dest)));
570   LWIP_DEBUGF(IP_DEBUG, ("+-------------------------------+\n"));
571 }
572 #endif /* IP_DEBUG */