ReactOS 0.4.16-dev-338-g34e76ad
ip4.c
Go to the documentation of this file.
1
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
43#if LWIP_IPV4
44
45#include "lwip/ip.h"
46#include "lwip/def.h"
47#include "lwip/mem.h"
48#include "lwip/ip4_frag.h"
49#include "lwip/inet_chksum.h"
50#include "lwip/netif.h"
51#include "lwip/icmp.h"
52#include "lwip/igmp.h"
53#include "lwip/priv/raw_priv.h"
54#include "lwip/udp.h"
55#include "lwip/priv/tcp_priv.h"
56#include "lwip/autoip.h"
57#include "lwip/stats.h"
58#include "lwip/prot/iana.h"
59
60#include <string.h>
61
62#ifdef LWIP_HOOK_FILENAME
63#include LWIP_HOOK_FILENAME
64#endif
65
68#ifndef LWIP_INLINE_IP_CHKSUM
69#if LWIP_CHECKSUM_CTRL_PER_NETIF
70#define LWIP_INLINE_IP_CHKSUM 0
71#else /* LWIP_CHECKSUM_CTRL_PER_NETIF */
72#define LWIP_INLINE_IP_CHKSUM 1
73#endif /* LWIP_CHECKSUM_CTRL_PER_NETIF */
74#endif
75
76#if LWIP_INLINE_IP_CHKSUM && CHECKSUM_GEN_IP
77#define CHECKSUM_GEN_IP_INLINE 1
78#else
79#define CHECKSUM_GEN_IP_INLINE 0
80#endif
81
82#if LWIP_DHCP || defined(LWIP_IP_ACCEPT_UDP_PORT)
83#define IP_ACCEPT_LINK_LAYER_ADDRESSING 1
84
90#if LWIP_DHCP && defined(LWIP_IP_ACCEPT_UDP_PORT)
91/* accept DHCP client port and custom port */
92#define IP_ACCEPT_LINK_LAYER_ADDRESSED_PORT(port) (((port) == PP_NTOHS(LWIP_IANA_PORT_DHCP_CLIENT)) \
93 || (LWIP_IP_ACCEPT_UDP_PORT(port)))
94#elif defined(LWIP_IP_ACCEPT_UDP_PORT) /* LWIP_DHCP && defined(LWIP_IP_ACCEPT_UDP_PORT) */
95/* accept custom port only */
96#define IP_ACCEPT_LINK_LAYER_ADDRESSED_PORT(port) (LWIP_IP_ACCEPT_UDP_PORT(port))
97#else /* LWIP_DHCP && defined(LWIP_IP_ACCEPT_UDP_PORT) */
98/* accept DHCP client port only */
99#define IP_ACCEPT_LINK_LAYER_ADDRESSED_PORT(port) ((port) == PP_NTOHS(LWIP_IANA_PORT_DHCP_CLIENT))
100#endif /* LWIP_DHCP && defined(LWIP_IP_ACCEPT_UDP_PORT) */
101
102#else /* LWIP_DHCP */
103#define IP_ACCEPT_LINK_LAYER_ADDRESSING 0
104#endif /* LWIP_DHCP */
105
107static u16_t ip_id;
108
109#if LWIP_MULTICAST_TX_OPTIONS
111static struct netif *ip4_default_multicast_netif;
112
116void
117ip4_set_default_multicast_netif(struct netif *default_multicast_netif)
118{
119 ip4_default_multicast_netif = default_multicast_netif;
120}
121#endif /* LWIP_MULTICAST_TX_OPTIONS */
122
123#ifdef LWIP_HOOK_IP4_ROUTE_SRC
128struct netif *
129ip4_route_src(const ip4_addr_t *src, const ip4_addr_t *dest)
130{
131 if (src != NULL) {
132 /* when src==NULL, the hook is called from ip4_route(dest) */
133 struct netif *netif = LWIP_HOOK_IP4_ROUTE_SRC(src, dest);
134 if (netif != NULL) {
135 return netif;
136 }
137 }
138 return ip4_route(dest);
139}
140#endif /* LWIP_HOOK_IP4_ROUTE_SRC */
141
151struct netif *
152ip4_route(const ip4_addr_t *dest)
153{
154#if !LWIP_SINGLE_NETIF
155 struct netif *netif;
156
158
159#if LWIP_MULTICAST_TX_OPTIONS
160 /* Use administratively selected interface for multicast by default */
161 if (ip4_addr_ismulticast(dest) && ip4_default_multicast_netif) {
162 return ip4_default_multicast_netif;
163 }
164#endif /* LWIP_MULTICAST_TX_OPTIONS */
165
166 /* bug #54569: in case LWIP_SINGLE_NETIF=1 and LWIP_DEBUGF() disabled, the following loop is optimized away */
168
169 /* iterate through netifs */
171 /* is the netif up, does it have a link and a valid address? */
172 if (netif_is_up(netif) && netif_is_link_up(netif) && !ip4_addr_isany_val(*netif_ip4_addr(netif))) {
173 /* network mask matches? */
174 if (ip4_addr_net_eq(dest, netif_ip4_addr(netif), netif_ip4_netmask(netif))) {
175 /* return netif on which to forward IP packet */
176 return netif;
177 }
178 /* gateway matches on a non broadcast interface? (i.e. peer in a point to point interface) */
179 if (((netif->flags & NETIF_FLAG_BROADCAST) == 0) && ip4_addr_eq(dest, netif_ip4_gw(netif))) {
180 /* return netif on which to forward IP packet */
181 return netif;
182 }
183 }
184 }
185
186#if LWIP_NETIF_LOOPBACK && !LWIP_HAVE_LOOPIF
187 /* loopif is disabled, loopback traffic is passed through any netif */
188 if (ip4_addr_isloopback(dest)) {
189 /* don't check for link on loopback traffic */
191 return netif_default;
192 }
193 /* default netif is not up, just use any netif for loopback traffic */
195 if (netif_is_up(netif)) {
196 return netif;
197 }
198 }
199 return NULL;
200 }
201#endif /* LWIP_NETIF_LOOPBACK && !LWIP_HAVE_LOOPIF */
202
203#ifdef LWIP_HOOK_IP4_ROUTE_SRC
204 netif = LWIP_HOOK_IP4_ROUTE_SRC(NULL, dest);
205 if (netif != NULL) {
206 return netif;
207 }
208#elif defined(LWIP_HOOK_IP4_ROUTE)
209 netif = LWIP_HOOK_IP4_ROUTE(dest);
210 if (netif != NULL) {
211 return netif;
212 }
213#endif
214#endif /* !LWIP_SINGLE_NETIF */
215
217 ip4_addr_isany_val(*netif_ip4_addr(netif_default)) || ip4_addr_isloopback(dest)) {
218 /* No matching netif found and default netif is not usable.
219 If this is not good enough for you, use LWIP_HOOK_IP4_ROUTE() */
220 LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("ip4_route: No route to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
221 ip4_addr1_16(dest), ip4_addr2_16(dest), ip4_addr3_16(dest), ip4_addr4_16(dest)));
222 IP_STATS_INC(ip.rterr);
223 MIB2_STATS_INC(mib2.ipoutnoroutes);
224 return NULL;
225 }
226
227 return netif_default;
228}
229
230#if IP_FORWARD
238static int
239ip4_canforward(struct pbuf *p)
240{
241 u32_t addr = lwip_htonl(ip4_addr_get_u32(ip4_current_dest_addr()));
242
243#ifdef LWIP_HOOK_IP4_CANFORWARD
244 int ret = LWIP_HOOK_IP4_CANFORWARD(p, addr);
245 if (ret >= 0) {
246 return ret;
247 }
248#endif /* LWIP_HOOK_IP4_CANFORWARD */
249
250 if (p->flags & PBUF_FLAG_LLBCAST) {
251 /* don't route link-layer broadcasts */
252 return 0;
253 }
254 if ((p->flags & PBUF_FLAG_LLMCAST) || IP_MULTICAST(addr)) {
255 /* don't route link-layer multicasts (use LWIP_HOOK_IP4_CANFORWARD instead) */
256 return 0;
257 }
258 if (IP_EXPERIMENTAL(addr)) {
259 return 0;
260 }
261 if (IP_CLASSA(addr)) {
262 u32_t net = addr & IP_CLASSA_NET;
263 if ((net == 0) || (net == ((u32_t)IP_LOOPBACKNET << IP_CLASSA_NSHIFT))) {
264 /* don't route loopback packets */
265 return 0;
266 }
267 }
268 return 1;
269}
270
280static void
281ip4_forward(struct pbuf *p, struct ip_hdr *iphdr, struct netif *inp)
282{
283 struct netif *netif;
284
286 LWIP_UNUSED_ARG(inp);
287
288 if (!ip4_canforward(p)) {
289 goto return_noroute;
290 }
291
292 /* RFC3927 2.7: do not forward link-local addresses */
293 if (ip4_addr_islinklocal(ip4_current_dest_addr())) {
294 LWIP_DEBUGF(IP_DEBUG, ("ip4_forward: not forwarding LLA %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
295 ip4_addr1_16(ip4_current_dest_addr()), ip4_addr2_16(ip4_current_dest_addr()),
296 ip4_addr3_16(ip4_current_dest_addr()), ip4_addr4_16(ip4_current_dest_addr())));
297 goto return_noroute;
298 }
299
300 /* Find network interface where to forward this IP packet to. */
301 netif = ip4_route_src(ip4_current_src_addr(), ip4_current_dest_addr());
302 if (netif == NULL) {
303 LWIP_DEBUGF(IP_DEBUG, ("ip4_forward: no forwarding route for %"U16_F".%"U16_F".%"U16_F".%"U16_F" found\n",
304 ip4_addr1_16(ip4_current_dest_addr()), ip4_addr2_16(ip4_current_dest_addr()),
305 ip4_addr3_16(ip4_current_dest_addr()), ip4_addr4_16(ip4_current_dest_addr())));
306 /* @todo: send ICMP_DUR_NET? */
307 goto return_noroute;
308 }
309#if !IP_FORWARD_ALLOW_TX_ON_RX_NETIF
310 /* Do not forward packets onto the same network interface on which
311 * they arrived. */
312 if (netif == inp) {
313 LWIP_DEBUGF(IP_DEBUG, ("ip4_forward: not bouncing packets back on incoming interface.\n"));
314 goto return_noroute;
315 }
316#endif /* IP_FORWARD_ALLOW_TX_ON_RX_NETIF */
317
318 /* decrement TTL */
319 IPH_TTL_SET(iphdr, IPH_TTL(iphdr) - 1);
320 /* send ICMP if TTL == 0 */
321 if (IPH_TTL(iphdr) == 0) {
322 MIB2_STATS_INC(mib2.ipinhdrerrors);
323#if LWIP_ICMP
324 /* Don't send ICMP messages in response to ICMP messages */
325 if (IPH_PROTO(iphdr) != IP_PROTO_ICMP) {
326 icmp_time_exceeded(p, ICMP_TE_TTL);
327 }
328#endif /* LWIP_ICMP */
329 return;
330 }
331
332 /* Incrementally update the IP checksum. */
333 if (IPH_CHKSUM(iphdr) >= PP_HTONS(0xffffU - 0x100)) {
334 IPH_CHKSUM_SET(iphdr, (u16_t)(IPH_CHKSUM(iphdr) + PP_HTONS(0x100) + 1));
335 } else {
336 IPH_CHKSUM_SET(iphdr, (u16_t)(IPH_CHKSUM(iphdr) + PP_HTONS(0x100)));
337 }
338
339 /* Take care of setting checksums to 0 for checksum offload netifs */
340 if (CHECKSUM_GEN_IP || NETIF_CHECKSUM_ENABLED(inp, NETIF_CHECKSUM_GEN_IP)) {
341 IPH_CHKSUM_SET(iphdr, 0);
342 }
343 switch (IPH_PROTO(iphdr)) {
344#if LWIP_UDP
345#if LWIP_UDPLITE
346 case IP_PROTO_UDPLITE:
347#endif
348 case IP_PROTO_UDP:
349 if (CHECKSUM_GEN_UDP || NETIF_CHECKSUM_ENABLED(inp, NETIF_CHECKSUM_GEN_UDP)) {
350 ((struct udp_hdr *)((u8_t *)iphdr + IPH_HL_BYTES(iphdr)))->chksum = 0;
351 }
352 break;
353#endif
354#if LWIP_TCP
355 case IP_PROTO_TCP:
356 if (CHECKSUM_GEN_TCP || NETIF_CHECKSUM_ENABLED(inp, NETIF_CHECKSUM_GEN_TCP)) {
357 ((struct tcp_hdr *)((u8_t *)iphdr + IPH_HL_BYTES(iphdr)))->chksum = 0;
358 }
359 break;
360#endif
361#if LWIP_ICMP
362 case IP_PROTO_ICMP:
363 if (CHECKSUM_GEN_ICMP || NETIF_CHECKSUM_ENABLED(inp, NETIF_CHECKSUM_GEN_ICMP)) {
364 ((struct icmp_hdr *)((u8_t *)iphdr + IPH_HL_BYTES(iphdr)))->chksum = 0;
365 }
366 break;
367#endif
368 default:
369 /* there's really nothing to do here other than satisfying 'switch-default' */
370 break;
371 }
372
373 LWIP_DEBUGF(IP_DEBUG, ("ip4_forward: forwarding packet to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
374 ip4_addr1_16(ip4_current_dest_addr()), ip4_addr2_16(ip4_current_dest_addr()),
375 ip4_addr3_16(ip4_current_dest_addr()), ip4_addr4_16(ip4_current_dest_addr())));
376
377 IP_STATS_INC(ip.fw);
378 MIB2_STATS_INC(mib2.ipforwdatagrams);
379 IP_STATS_INC(ip.xmit);
380
381 PERF_STOP("ip4_forward");
382 /* don't fragment if interface has mtu set to 0 [loopif] */
383 if (netif->mtu && (p->tot_len > netif->mtu)) {
384 if ((IPH_OFFSET(iphdr) & PP_NTOHS(IP_DF)) == 0) {
385#if IP_FRAG
386 ip4_frag(p, netif, ip4_current_dest_addr());
387#else /* IP_FRAG */
388 /* @todo: send ICMP Destination Unreachable code 13 "Communication administratively prohibited"? */
389#endif /* IP_FRAG */
390 } else {
391#if LWIP_ICMP
392 /* send ICMP Destination Unreachable code 4: "Fragmentation Needed and DF Set" */
393 icmp_dest_unreach(p, ICMP_DUR_FRAG);
394#endif /* LWIP_ICMP */
395 }
396 return;
397 }
398 /* transmit pbuf on chosen interface */
399 netif->output(netif, p, ip4_current_dest_addr());
400 return;
401return_noroute:
402 MIB2_STATS_INC(mib2.ipoutnoroutes);
403}
404#endif /* IP_FORWARD */
405
407static int
408ip4_input_accept(struct netif *netif)
409{
410 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",
411 ip4_addr_get_u32(ip4_current_dest_addr()), ip4_addr_get_u32(netif_ip4_addr(netif)),
412 ip4_addr_get_u32(ip4_current_dest_addr()) & ip4_addr_get_u32(netif_ip4_netmask(netif)),
413 ip4_addr_get_u32(netif_ip4_addr(netif)) & ip4_addr_get_u32(netif_ip4_netmask(netif)),
414 ip4_addr_get_u32(ip4_current_dest_addr()) & ~ip4_addr_get_u32(netif_ip4_netmask(netif))));
415
416 /* interface is up and configured? */
417 if ((netif_is_up(netif)) && (!ip4_addr_isany_val(*netif_ip4_addr(netif)))) {
418 /* unicast to this interface address? */
419 if (ip4_addr_eq(ip4_current_dest_addr(), netif_ip4_addr(netif)) ||
420 /* or broadcast on this interface network address? */
421 ip4_addr_isbroadcast(ip4_current_dest_addr(), netif)
423 || (ip4_addr_get_u32(ip4_current_dest_addr()) == PP_HTONL(IPADDR_LOOPBACK))
424#endif /* LWIP_NETIF_LOOPBACK && !LWIP_HAVE_LOOPIF */
425 ) {
426 LWIP_DEBUGF(IP_DEBUG, ("ip4_input: packet accepted on interface %c%c\n",
427 netif->name[0], netif->name[1]));
428 /* accept on this netif */
429 return 1;
430 }
431#if LWIP_AUTOIP
432 /* connections to link-local addresses must persist after changing
433 the netif's address (RFC3927 ch. 1.9) */
434 if (autoip_accept_packet(netif, ip4_current_dest_addr())) {
435 LWIP_DEBUGF(IP_DEBUG, ("ip4_input: LLA packet accepted on interface %c%c\n",
436 netif->name[0], netif->name[1]));
437 /* accept on this netif */
438 return 1;
439 }
440#endif /* LWIP_AUTOIP */
441 }
442 return 0;
443}
444
459err_t
460ip4_input(struct pbuf *p, struct netif *inp)
461{
462 const struct ip_hdr *iphdr;
463 struct netif *netif;
464 u16_t iphdr_hlen;
465 u16_t iphdr_len;
466#if IP_ACCEPT_LINK_LAYER_ADDRESSING || LWIP_IGMP
467 int check_ip_src = 1;
468#endif /* IP_ACCEPT_LINK_LAYER_ADDRESSING || LWIP_IGMP */
469#if LWIP_RAW
470 raw_input_state_t raw_status;
471#endif /* LWIP_RAW */
472
474
475 IP_STATS_INC(ip.recv);
476 MIB2_STATS_INC(mib2.ipinreceives);
477
478 /* identify the IP header */
479 iphdr = (struct ip_hdr *)p->payload;
480 if (IPH_V(iphdr) != 4) {
481 LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_LEVEL_WARNING, ("IP packet dropped due to bad version number %"U16_F"\n", (u16_t)IPH_V(iphdr)));
482 ip4_debug_print(p);
483 pbuf_free(p);
484 IP_STATS_INC(ip.err);
485 IP_STATS_INC(ip.drop);
486 MIB2_STATS_INC(mib2.ipinhdrerrors);
487 return ERR_OK;
488 }
489
490#ifdef LWIP_HOOK_IP4_INPUT
491 if (LWIP_HOOK_IP4_INPUT(p, inp)) {
492 /* the packet has been eaten */
493 return ERR_OK;
494 }
495#endif
496
497 /* obtain IP header length in bytes */
498 iphdr_hlen = IPH_HL_BYTES(iphdr);
499 /* obtain ip length in bytes */
500 iphdr_len = lwip_ntohs(IPH_LEN(iphdr));
501
502 /* Trim pbuf. This is especially required for packets < 60 bytes. */
503 if (iphdr_len < p->tot_len) {
504 pbuf_realloc(p, iphdr_len);
505 }
506
507 /* header length exceeds first pbuf length, or ip length exceeds total pbuf length? */
508 if ((iphdr_hlen > p->len) || (iphdr_len > p->tot_len) || (iphdr_hlen < IP_HLEN)) {
509 if (iphdr_hlen < IP_HLEN) {
511 ("ip4_input: short IP header (%"U16_F" bytes) received, IP packet dropped\n", iphdr_hlen));
512 }
513 if (iphdr_hlen > p->len) {
515 ("IP header (len %"U16_F") does not fit in first pbuf (len %"U16_F"), IP packet dropped.\n",
516 iphdr_hlen, p->len));
517 }
518 if (iphdr_len > p->tot_len) {
520 ("IP (len %"U16_F") is longer than pbuf (len %"U16_F"), IP packet dropped.\n",
521 iphdr_len, p->tot_len));
522 }
523 /* free (drop) packet pbufs */
524 pbuf_free(p);
525 IP_STATS_INC(ip.lenerr);
526 IP_STATS_INC(ip.drop);
527 MIB2_STATS_INC(mib2.ipindiscards);
528 return ERR_OK;
529 }
530
531 /* verify checksum */
532#if CHECKSUM_CHECK_IP
533 IF__NETIF_CHECKSUM_ENABLED(inp, NETIF_CHECKSUM_CHECK_IP) {
534 if (inet_chksum(iphdr, iphdr_hlen) != 0) {
535
537 ("Checksum (0x%"X16_F") failed, IP packet dropped.\n", inet_chksum(iphdr, iphdr_hlen)));
538 ip4_debug_print(p);
539 pbuf_free(p);
540 IP_STATS_INC(ip.chkerr);
541 IP_STATS_INC(ip.drop);
542 MIB2_STATS_INC(mib2.ipinhdrerrors);
543 return ERR_OK;
544 }
545 }
546#endif
547
548 /* copy IP addresses to aligned ip_addr_t */
549 ip_addr_copy_from_ip4(ip_data.current_iphdr_dest, iphdr->dest);
550 ip_addr_copy_from_ip4(ip_data.current_iphdr_src, iphdr->src);
551
552 /* match packet against an interface, i.e. is this packet for us? */
553 if (ip4_addr_ismulticast(ip4_current_dest_addr())) {
554#if LWIP_IGMP
555 if ((inp->flags & NETIF_FLAG_IGMP) && (igmp_lookfor_group(inp, ip4_current_dest_addr()))) {
556 /* IGMP snooping switches need 0.0.0.0 to be allowed as source address (RFC 4541) */
557 ip4_addr_t allsystems;
558 IP4_ADDR(&allsystems, 224, 0, 0, 1);
559 if (ip4_addr_eq(ip4_current_dest_addr(), &allsystems) &&
560 ip4_addr_isany(ip4_current_src_addr())) {
561 check_ip_src = 0;
562 }
563 netif = inp;
564 } else {
565 netif = NULL;
566 }
567#else /* LWIP_IGMP */
568 if ((netif_is_up(inp)) && (!ip4_addr_isany_val(*netif_ip4_addr(inp)))) {
569 netif = inp;
570 } else {
571 netif = NULL;
572 }
573#endif /* LWIP_IGMP */
574 } else {
575 /* start trying with inp. if that's not acceptable, start walking the
576 list of configured netifs. */
577 if (ip4_input_accept(inp)) {
578 netif = inp;
579 } else {
580 netif = NULL;
581#if !LWIP_NETIF_LOOPBACK || LWIP_HAVE_LOOPIF
582 /* Packets sent to the loopback address must not be accepted on an
583 * interface that does not have the loopback address assigned to it,
584 * unless a non-loopback interface is used for loopback traffic. */
585 if (!ip4_addr_isloopback(ip4_current_dest_addr()))
586#endif /* !LWIP_NETIF_LOOPBACK || LWIP_HAVE_LOOPIF */
587 {
588#if !LWIP_SINGLE_NETIF
590 if (netif == inp) {
591 /* we checked that before already */
592 continue;
593 }
594 if (ip4_input_accept(netif)) {
595 break;
596 }
597 }
598#endif /* !LWIP_SINGLE_NETIF */
599 }
600 }
601 }
602
603#if IP_ACCEPT_LINK_LAYER_ADDRESSING
604 /* Pass DHCP messages regardless of destination address. DHCP traffic is addressed
605 * using link layer addressing (such as Ethernet MAC) so we must not filter on IP.
606 * According to RFC 1542 section 3.1.1, referred by RFC 2131).
607 *
608 * If you want to accept private broadcast communication while a netif is down,
609 * define LWIP_IP_ACCEPT_UDP_PORT(dst_port), e.g.:
610 *
611 * #define LWIP_IP_ACCEPT_UDP_PORT(dst_port) ((dst_port) == PP_NTOHS(12345))
612 */
613 if (netif == NULL) {
614 /* remote port is DHCP server? */
615 if (IPH_PROTO(iphdr) == IP_PROTO_UDP) {
616 const struct udp_hdr *udphdr = (const struct udp_hdr *)((const u8_t *)iphdr + iphdr_hlen);
617 LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_TRACE, ("ip4_input: UDP packet to DHCP client port %"U16_F"\n",
618 lwip_ntohs(udphdr->dest)));
619 if (IP_ACCEPT_LINK_LAYER_ADDRESSED_PORT(udphdr->dest)) {
620 LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_TRACE, ("ip4_input: DHCP packet accepted.\n"));
621 netif = inp;
622 check_ip_src = 0;
623 }
624 }
625 }
626#endif /* IP_ACCEPT_LINK_LAYER_ADDRESSING */
627
628 /* broadcast or multicast packet source address? Compliant with RFC 1122: 3.2.1.3 */
629#if LWIP_IGMP || IP_ACCEPT_LINK_LAYER_ADDRESSING
630 if (check_ip_src
631#if IP_ACCEPT_LINK_LAYER_ADDRESSING
632 /* DHCP servers need 0.0.0.0 to be allowed as source address (RFC 1.1.2.2: 3.2.1.3/a) */
633 && !ip4_addr_isany_val(*ip4_current_src_addr())
634#endif /* IP_ACCEPT_LINK_LAYER_ADDRESSING */
635 )
636#endif /* LWIP_IGMP || IP_ACCEPT_LINK_LAYER_ADDRESSING */
637 {
638 if ((ip4_addr_isbroadcast(ip4_current_src_addr(), inp)) ||
639 (ip4_addr_ismulticast(ip4_current_src_addr()))) {
640 /* packet source is not valid */
641 LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_WARNING, ("ip4_input: packet source is not valid.\n"));
642 /* free (drop) packet pbufs */
643 pbuf_free(p);
644 IP_STATS_INC(ip.drop);
645 MIB2_STATS_INC(mib2.ipinaddrerrors);
646 MIB2_STATS_INC(mib2.ipindiscards);
647 return ERR_OK;
648 }
649 }
650
651 /* packet not for us? */
652 if (netif == NULL) {
653 /* packet not for us, route or discard */
654 LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_TRACE, ("ip4_input: packet not for us.\n"));
655#if IP_FORWARD
656 /* non-broadcast packet? */
657 if (!ip4_addr_isbroadcast(ip4_current_dest_addr(), inp)) {
658 /* try to forward IP packet on (other) interfaces */
659 ip4_forward(p, (struct ip_hdr *)p->payload, inp);
660 } else
661#endif /* IP_FORWARD */
662 {
663 IP_STATS_INC(ip.drop);
664 MIB2_STATS_INC(mib2.ipinaddrerrors);
665 MIB2_STATS_INC(mib2.ipindiscards);
666 }
667 pbuf_free(p);
668 return ERR_OK;
669 }
670 /* packet consists of multiple fragments? */
671 if ((IPH_OFFSET(iphdr) & PP_HTONS(IP_OFFMASK | IP_MF)) != 0) {
672#if IP_REASSEMBLY /* packet fragment reassembly code present? */
673 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 ip4_reass()\n",
674 lwip_ntohs(IPH_ID(iphdr)), p->tot_len, lwip_ntohs(IPH_LEN(iphdr)), (u16_t)!!(IPH_OFFSET(iphdr) & PP_HTONS(IP_MF)), (u16_t)((lwip_ntohs(IPH_OFFSET(iphdr)) & IP_OFFMASK) * 8)));
675 /* reassemble the packet*/
676 p = ip4_reass(p);
677 /* packet not fully reassembled yet? */
678 if (p == NULL) {
679 return ERR_OK;
680 }
681 iphdr = (const struct ip_hdr *)p->payload;
682#else /* IP_REASSEMBLY == 0, no packet fragment reassembly code present */
683 pbuf_free(p);
684 LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("IP packet dropped since it was fragmented (0x%"X16_F") (while IP_REASSEMBLY == 0).\n",
685 lwip_ntohs(IPH_OFFSET(iphdr))));
686 IP_STATS_INC(ip.opterr);
687 IP_STATS_INC(ip.drop);
688 /* unsupported protocol feature */
689 MIB2_STATS_INC(mib2.ipinunknownprotos);
690 return ERR_OK;
691#endif /* IP_REASSEMBLY */
692 }
693
694#if IP_OPTIONS_ALLOWED == 0 /* no support for IP options in the IP header? */
695
696#if LWIP_IGMP
697 /* there is an extra "router alert" option in IGMP messages which we allow for but do not police */
698 if ((iphdr_hlen > IP_HLEN) && (IPH_PROTO(iphdr) != IP_PROTO_IGMP)) {
699#else
700 if (iphdr_hlen > IP_HLEN) {
701#endif /* LWIP_IGMP */
702 LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("IP packet dropped since there were IP options (while IP_OPTIONS_ALLOWED == 0).\n"));
703 pbuf_free(p);
704 IP_STATS_INC(ip.opterr);
705 IP_STATS_INC(ip.drop);
706 /* unsupported protocol feature */
707 MIB2_STATS_INC(mib2.ipinunknownprotos);
708 return ERR_OK;
709 }
710#endif /* IP_OPTIONS_ALLOWED == 0 */
711
712 /* send to upper layers */
713 LWIP_DEBUGF(IP_DEBUG, ("ip4_input: \n"));
714 ip4_debug_print(p);
715 LWIP_DEBUGF(IP_DEBUG, ("ip4_input: p->len %"U16_F" p->tot_len %"U16_F"\n", p->len, p->tot_len));
716
717 ip_data.current_netif = netif;
718 ip_data.current_input_netif = inp;
719 ip_data.current_ip4_header = iphdr;
720 ip_data.current_ip_header_tot_len = IPH_HL_BYTES(iphdr);
721
722#if LWIP_RAW
723 /* raw input did not eat the packet? */
724 raw_status = raw_input(p, inp);
725 if (raw_status != RAW_INPUT_EATEN)
726#endif /* LWIP_RAW */
727 {
728 pbuf_remove_header(p, iphdr_hlen); /* Move to payload, no check necessary. */
729
730 switch (IPH_PROTO(iphdr)) {
731#if LWIP_UDP
732 case IP_PROTO_UDP:
733#if LWIP_UDPLITE
734 case IP_PROTO_UDPLITE:
735#endif /* LWIP_UDPLITE */
736 MIB2_STATS_INC(mib2.ipindelivers);
737 udp_input(p, inp);
738 break;
739#endif /* LWIP_UDP */
740#if LWIP_TCP
741 case IP_PROTO_TCP:
742 MIB2_STATS_INC(mib2.ipindelivers);
743 tcp_input(p, inp);
744 break;
745#endif /* LWIP_TCP */
746#if LWIP_ICMP
747 case IP_PROTO_ICMP:
748 MIB2_STATS_INC(mib2.ipindelivers);
749 icmp_input(p, inp);
750 break;
751#endif /* LWIP_ICMP */
752#if LWIP_IGMP
753 case IP_PROTO_IGMP:
754 igmp_input(p, inp, ip4_current_dest_addr());
755 break;
756#endif /* LWIP_IGMP */
757 default:
758#if LWIP_RAW
759 if (raw_status == RAW_INPUT_DELIVERED) {
760 MIB2_STATS_INC(mib2.ipindelivers);
761 } else
762#endif /* LWIP_RAW */
763 {
764#if LWIP_ICMP
765 /* send ICMP destination protocol unreachable unless is was a broadcast */
766 if (!ip4_addr_isbroadcast(ip4_current_dest_addr(), netif) &&
767 !ip4_addr_ismulticast(ip4_current_dest_addr())) {
768 pbuf_header_force(p, (s16_t)iphdr_hlen); /* Move to ip header, no check necessary. */
769 icmp_dest_unreach(p, ICMP_DUR_PROTO);
770 }
771#endif /* LWIP_ICMP */
772
773 LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("Unsupported transport protocol %"U16_F"\n", (u16_t)IPH_PROTO(iphdr)));
774
775 IP_STATS_INC(ip.proterr);
776 IP_STATS_INC(ip.drop);
777 MIB2_STATS_INC(mib2.ipinunknownprotos);
778 }
779 pbuf_free(p);
780 break;
781 }
782 }
783
784 /* @todo: this is not really necessary... */
785 ip_data.current_netif = NULL;
786 ip_data.current_input_netif = NULL;
787 ip_data.current_ip4_header = NULL;
788 ip_data.current_ip_header_tot_len = 0;
789 ip4_addr_set_any(ip4_current_src_addr());
790 ip4_addr_set_any(ip4_current_dest_addr());
791
792 return ERR_OK;
793}
794
820err_t
821ip4_output_if(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest,
822 u8_t ttl, u8_t tos,
823 u8_t proto, struct netif *netif)
824{
825#if IP_OPTIONS_SEND
826 return ip4_output_if_opt(p, src, dest, ttl, tos, proto, netif, NULL, 0);
827}
828
835err_t
836ip4_output_if_opt(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest,
837 u8_t ttl, u8_t tos, u8_t proto, struct netif *netif, void *ip_options,
838 u16_t optlen)
839{
840#endif /* IP_OPTIONS_SEND */
841 const ip4_addr_t *src_used = src;
842 if (dest != LWIP_IP_HDRINCL) {
843 if (ip4_addr_isany(src)) {
844 src_used = netif_ip4_addr(netif);
845 }
846 }
847
848#if IP_OPTIONS_SEND
849 return ip4_output_if_opt_src(p, src_used, dest, ttl, tos, proto, netif,
850 ip_options, optlen);
851#else /* IP_OPTIONS_SEND */
852 return ip4_output_if_src(p, src_used, dest, ttl, tos, proto, netif);
853#endif /* IP_OPTIONS_SEND */
854}
855
860err_t
861ip4_output_if_src(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest,
862 u8_t ttl, u8_t tos,
863 u8_t proto, struct netif *netif)
864{
865#if IP_OPTIONS_SEND
866 return ip4_output_if_opt_src(p, src, dest, ttl, tos, proto, netif, NULL, 0);
867}
868
873err_t
874ip4_output_if_opt_src(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest,
875 u8_t ttl, u8_t tos, u8_t proto, struct netif *netif, void *ip_options,
876 u16_t optlen)
877{
878#endif /* IP_OPTIONS_SEND */
879 struct ip_hdr *iphdr;
880 ip4_addr_t dest_addr;
881#if CHECKSUM_GEN_IP_INLINE
882 u32_t chk_sum = 0;
883#endif /* CHECKSUM_GEN_IP_INLINE */
884
887
888 MIB2_STATS_INC(mib2.ipoutrequests);
889
890 /* Should the IP header be generated or is it already included in p? */
891 if (dest != LWIP_IP_HDRINCL) {
892 u16_t ip_hlen = IP_HLEN;
893#if IP_OPTIONS_SEND
894 u16_t optlen_aligned = 0;
895 if (optlen != 0) {
896#if CHECKSUM_GEN_IP_INLINE
897 int i;
898#endif /* CHECKSUM_GEN_IP_INLINE */
899 if (optlen > (IP_HLEN_MAX - IP_HLEN)) {
900 /* optlen too long */
901 LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("ip4_output_if_opt: optlen too long\n"));
902 IP_STATS_INC(ip.err);
903 MIB2_STATS_INC(mib2.ipoutdiscards);
904 return ERR_VAL;
905 }
906 /* round up to a multiple of 4 */
907 optlen_aligned = (u16_t)((optlen + 3) & ~3);
908 ip_hlen = (u16_t)(ip_hlen + optlen_aligned);
909 /* First write in the IP options */
910 if (pbuf_add_header(p, optlen_aligned)) {
911 LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("ip4_output_if_opt: not enough room for IP options in pbuf\n"));
912 IP_STATS_INC(ip.err);
913 MIB2_STATS_INC(mib2.ipoutdiscards);
914 return ERR_BUF;
915 }
916 MEMCPY(p->payload, ip_options, optlen);
917 if (optlen < optlen_aligned) {
918 /* zero the remaining bytes */
919 memset(((char *)p->payload) + optlen, 0, (size_t)(optlen_aligned - optlen));
920 }
921#if CHECKSUM_GEN_IP_INLINE
922 for (i = 0; i < optlen_aligned / 2; i++) {
923 chk_sum += ((u16_t *)p->payload)[i];
924 }
925#endif /* CHECKSUM_GEN_IP_INLINE */
926 }
927#endif /* IP_OPTIONS_SEND */
928 /* generate IP header */
929 if (pbuf_add_header(p, IP_HLEN)) {
930 LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("ip4_output: not enough room for IP header in pbuf\n"));
931
932 IP_STATS_INC(ip.err);
933 MIB2_STATS_INC(mib2.ipoutdiscards);
934 return ERR_BUF;
935 }
936
937 iphdr = (struct ip_hdr *)p->payload;
938 LWIP_ASSERT("check that first pbuf can hold struct ip_hdr",
939 (p->len >= sizeof(struct ip_hdr)));
940
941 IPH_TTL_SET(iphdr, ttl);
942 IPH_PROTO_SET(iphdr, proto);
943#if CHECKSUM_GEN_IP_INLINE
944 chk_sum += PP_NTOHS(proto | (ttl << 8));
945#endif /* CHECKSUM_GEN_IP_INLINE */
946
947 /* dest cannot be NULL here */
948 ip4_addr_copy(iphdr->dest, *dest);
949#if CHECKSUM_GEN_IP_INLINE
950 chk_sum += ip4_addr_get_u32(&iphdr->dest) & 0xFFFF;
951 chk_sum += ip4_addr_get_u32(&iphdr->dest) >> 16;
952#endif /* CHECKSUM_GEN_IP_INLINE */
953
954 IPH_VHL_SET(iphdr, 4, ip_hlen / 4);
955 IPH_TOS_SET(iphdr, tos);
956#if CHECKSUM_GEN_IP_INLINE
957 chk_sum += PP_NTOHS(tos | (iphdr->_v_hl << 8));
958#endif /* CHECKSUM_GEN_IP_INLINE */
959 IPH_LEN_SET(iphdr, lwip_htons(p->tot_len));
960#if CHECKSUM_GEN_IP_INLINE
961 chk_sum += iphdr->_len;
962#endif /* CHECKSUM_GEN_IP_INLINE */
963 IPH_OFFSET_SET(iphdr, 0);
964 IPH_ID_SET(iphdr, lwip_htons(ip_id));
965#if CHECKSUM_GEN_IP_INLINE
966 chk_sum += iphdr->_id;
967#endif /* CHECKSUM_GEN_IP_INLINE */
968 ++ip_id;
969
970 if (src == NULL) {
971 ip4_addr_copy(iphdr->src, *IP4_ADDR_ANY4);
972 } else {
973 /* src cannot be NULL here */
974 ip4_addr_copy(iphdr->src, *src);
975 }
976
977#if CHECKSUM_GEN_IP_INLINE
978 chk_sum += ip4_addr_get_u32(&iphdr->src) & 0xFFFF;
979 chk_sum += ip4_addr_get_u32(&iphdr->src) >> 16;
980 chk_sum = (chk_sum >> 16) + (chk_sum & 0xFFFF);
981 chk_sum = (chk_sum >> 16) + chk_sum;
982 chk_sum = ~chk_sum;
983 IF__NETIF_CHECKSUM_ENABLED(netif, NETIF_CHECKSUM_GEN_IP) {
984 iphdr->_chksum = (u16_t)chk_sum; /* network order */
985 }
986#if LWIP_CHECKSUM_CTRL_PER_NETIF
987 else {
988 IPH_CHKSUM_SET(iphdr, 0);
989 }
990#endif /* LWIP_CHECKSUM_CTRL_PER_NETIF*/
991#else /* CHECKSUM_GEN_IP_INLINE */
992 IPH_CHKSUM_SET(iphdr, 0);
993#if CHECKSUM_GEN_IP
994 IF__NETIF_CHECKSUM_ENABLED(netif, NETIF_CHECKSUM_GEN_IP) {
995 IPH_CHKSUM_SET(iphdr, inet_chksum(iphdr, ip_hlen));
996 }
997#endif /* CHECKSUM_GEN_IP */
998#endif /* CHECKSUM_GEN_IP_INLINE */
999 } else {
1000 /* IP header already included in p */
1001 if (p->len < IP_HLEN) {
1002 LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("ip4_output: LWIP_IP_HDRINCL but pbuf is too short\n"));
1003 IP_STATS_INC(ip.err);
1004 MIB2_STATS_INC(mib2.ipoutdiscards);
1005 return ERR_BUF;
1006 }
1007 iphdr = (struct ip_hdr *)p->payload;
1008 ip4_addr_copy(dest_addr, iphdr->dest);
1009 dest = &dest_addr;
1010 }
1011
1012 IP_STATS_INC(ip.xmit);
1013
1014 LWIP_DEBUGF(IP_DEBUG, ("ip4_output_if: %c%c%"U16_F"\n", netif->name[0], netif->name[1], (u16_t)netif->num));
1015 ip4_debug_print(p);
1016
1017#if ENABLE_LOOPBACK
1018 if (ip4_addr_eq(dest, netif_ip4_addr(netif))
1020 || ip4_addr_isloopback(dest)
1021#endif /* !LWIP_HAVE_LOOPIF */
1022 ) {
1023 /* Packet to self, enqueue it for loopback */
1024 LWIP_DEBUGF(IP_DEBUG, ("netif_loop_output()\n"));
1025 return netif_loop_output(netif, p);
1026 }
1027#if LWIP_MULTICAST_TX_OPTIONS
1028 if ((p->flags & PBUF_FLAG_MCASTLOOP) != 0) {
1029 netif_loop_output(netif, p);
1030 }
1031#endif /* LWIP_MULTICAST_TX_OPTIONS */
1032#endif /* ENABLE_LOOPBACK */
1033#if IP_FRAG
1034 /* don't fragment if interface has mtu set to 0 [loopif] */
1035 if (netif->mtu && (p->tot_len > netif->mtu)) {
1036 return ip4_frag(p, netif, dest);
1037 }
1038#endif /* IP_FRAG */
1039
1040 LWIP_DEBUGF(IP_DEBUG, ("ip4_output_if: call netif->output()\n"));
1041 return netif->output(netif, p, dest);
1042}
1043
1061err_t
1062ip4_output(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest,
1063 u8_t ttl, u8_t tos, u8_t proto)
1064{
1065 struct netif *netif;
1066
1068
1069 if ((netif = ip4_route_src(src, dest)) == NULL) {
1070 LWIP_DEBUGF(IP_DEBUG, ("ip4_output: No route to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
1071 ip4_addr1_16(dest), ip4_addr2_16(dest), ip4_addr3_16(dest), ip4_addr4_16(dest)));
1072 IP_STATS_INC(ip.rterr);
1073 return ERR_RTE;
1074 }
1075
1076 return ip4_output_if(p, src, dest, ttl, tos, proto, netif);
1077}
1078
1079#if LWIP_NETIF_USE_HINTS
1098err_t
1099ip4_output_hinted(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest,
1100 u8_t ttl, u8_t tos, u8_t proto, struct netif_hint *netif_hint)
1101{
1102 struct netif *netif;
1103 err_t err;
1104
1106
1107 if ((netif = ip4_route_src(src, dest)) == NULL) {
1108 LWIP_DEBUGF(IP_DEBUG, ("ip4_output: No route to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
1109 ip4_addr1_16(dest), ip4_addr2_16(dest), ip4_addr3_16(dest), ip4_addr4_16(dest)));
1110 IP_STATS_INC(ip.rterr);
1111 return ERR_RTE;
1112 }
1113
1114 NETIF_SET_HINTS(netif, netif_hint);
1115 err = ip4_output_if(p, src, dest, ttl, tos, proto, netif);
1117
1118 return err;
1119}
1120#endif /* LWIP_NETIF_USE_HINTS*/
1121
1122#if IP_DEBUG
1123/* Print an IP header by using LWIP_DEBUGF
1124 * @param p an IP packet, p->payload pointing to the IP header
1125 */
1126void
1127ip4_debug_print(struct pbuf *p)
1128{
1129 struct ip_hdr *iphdr = (struct ip_hdr *)p->payload;
1130
1131 LWIP_DEBUGF(IP_DEBUG, ("IP header:\n"));
1132 LWIP_DEBUGF(IP_DEBUG, ("+-------------------------------+\n"));
1133 LWIP_DEBUGF(IP_DEBUG, ("|%2"S16_F" |%2"S16_F" | 0x%02"X16_F" | %5"U16_F" | (v, hl, tos, len)\n",
1134 (u16_t)IPH_V(iphdr),
1135 (u16_t)IPH_HL(iphdr),
1136 (u16_t)IPH_TOS(iphdr),
1137 lwip_ntohs(IPH_LEN(iphdr))));
1138 LWIP_DEBUGF(IP_DEBUG, ("+-------------------------------+\n"));
1139 LWIP_DEBUGF(IP_DEBUG, ("| %5"U16_F" |%"U16_F"%"U16_F"%"U16_F"| %4"U16_F" | (id, flags, offset)\n",
1140 lwip_ntohs(IPH_ID(iphdr)),
1141 (u16_t)(lwip_ntohs(IPH_OFFSET(iphdr)) >> 15 & 1),
1142 (u16_t)(lwip_ntohs(IPH_OFFSET(iphdr)) >> 14 & 1),
1143 (u16_t)(lwip_ntohs(IPH_OFFSET(iphdr)) >> 13 & 1),
1144 (u16_t)(lwip_ntohs(IPH_OFFSET(iphdr)) & IP_OFFMASK)));
1145 LWIP_DEBUGF(IP_DEBUG, ("+-------------------------------+\n"));
1146 LWIP_DEBUGF(IP_DEBUG, ("| %3"U16_F" | %3"U16_F" | 0x%04"X16_F" | (ttl, proto, chksum)\n",
1147 (u16_t)IPH_TTL(iphdr),
1148 (u16_t)IPH_PROTO(iphdr),
1149 lwip_ntohs(IPH_CHKSUM(iphdr))));
1150 LWIP_DEBUGF(IP_DEBUG, ("+-------------------------------+\n"));
1151 LWIP_DEBUGF(IP_DEBUG, ("| %3"U16_F" | %3"U16_F" | %3"U16_F" | %3"U16_F" | (src)\n",
1152 ip4_addr1_16_val(iphdr->src),
1153 ip4_addr2_16_val(iphdr->src),
1154 ip4_addr3_16_val(iphdr->src),
1155 ip4_addr4_16_val(iphdr->src)));
1156 LWIP_DEBUGF(IP_DEBUG, ("+-------------------------------+\n"));
1157 LWIP_DEBUGF(IP_DEBUG, ("| %3"U16_F" | %3"U16_F" | %3"U16_F" | %3"U16_F" | (dest)\n",
1158 ip4_addr1_16_val(iphdr->dest),
1159 ip4_addr2_16_val(iphdr->dest),
1160 ip4_addr3_16_val(iphdr->dest),
1161 ip4_addr4_16_val(iphdr->dest)));
1162 LWIP_DEBUGF(IP_DEBUG, ("+-------------------------------+\n"));
1163}
1164#endif /* IP_DEBUG */
1165
1166#endif /* LWIP_IPV4 */
#define PP_HTONS(x)
Definition: def.h:90
#define lwip_htons(x)
Definition: def.h:86
#define PP_NTOHS(x)
Definition: def.h:91
#define lwip_htonl(x)
Definition: def.h:88
#define lwip_ntohs(x)
Definition: def.h:87
#define PP_HTONL(x)
Definition: def.h:92
#define IP_OFFMASK
Definition: dhcpd.h:72
#define IP_DF
Definition: dhcpd.h:70
#define IP_MF
Definition: dhcpd.h:71
#define NULL
Definition: types.h:112
static UINT mib2[]
Definition: main.c:83
#define X16_F
Definition: cc.h:21
#define U16_F
Definition: cc.h:19
#define S16_F
Definition: cc.h:20
#define X32_F
Definition: cc.h:24
#define LWIP_DEBUGF(debug, message)
Definition: debug.h:158
#define LWIP_ASSERT(message, assertion)
Definition: debug.h:116
#define LWIP_IP_HDRINCL
Definition: ip.h:58
#define LWIP_IP_CHECK_PBUF_REF_COUNT_FOR_TX(p)
Definition: ip.h:63
struct ip_globals ip_data
#define IP_PROTO_UDPLITE
Definition: ip.h:49
#define IP_PROTO_IGMP
Definition: ip.h:47
#define IP_PROTO_TCP
Definition: ip.h:50
#define IP_PROTO_UDP
Definition: ip.h:48
#define IP_PROTO_ICMP
Definition: ip.h:46
GLenum src
Definition: glext.h:6340
GLenum const GLvoid * addr
Definition: glext.h:9621
GLfloat GLfloat p
Definition: glext.h:8902
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
uint32_t u32_t
Definition: arch.h:129
uint8_t u8_t
Definition: arch.h:125
#define LWIP_UNUSED_ARG(x)
Definition: arch.h:373
uint16_t u16_t
Definition: arch.h:127
int16_t s16_t
Definition: arch.h:128
#define LWIP_DBG_LEVEL_SERIOUS
Definition: debug.h:57
#define LWIP_DBG_LEVEL_WARNING
Definition: debug.h:55
#define LWIP_DBG_TRACE
Definition: debug.h:83
s8_t err_t
Definition: err.h:96
@ ERR_BUF
Definition: err.h:59
@ ERR_RTE
Definition: err.h:63
@ ERR_OK
Definition: err.h:55
@ ERR_VAL
Definition: err.h:67
#define CHECKSUM_GEN_ICMP
Definition: opt.h:2370
#define CHECKSUM_GEN_TCP
Definition: opt.h:2363
#define CHECKSUM_GEN_IP
Definition: opt.h:2349
#define CHECKSUM_GEN_UDP
Definition: opt.h:2356
#define IP_DEBUG
Definition: opt.h:3392
#define LWIP_ASSERT_CORE_LOCKED()
Definition: opt.h:227
#define LWIP_NETIF_LOOPBACK
Definition: opt.h:1762
#define LWIP_HAVE_LOOPIF
Definition: opt.h:1747
#define NETIF_FLAG_IGMP
Definition: netif.h:104
#define NETIF_FLAG_BROADCAST
Definition: netif.h:87
#define netif_is_up(netif)
Definition: netif.h:479
void pbuf_realloc(struct pbuf *p, u16_t new_len)
Definition: pbuf.c:402
u8_t pbuf_free(struct pbuf *p)
Definition: pbuf.c:727
u16_t inet_chksum(const void *dataptr, u16_t len)
Definition: inet_chksum.c:555
if(dx< 0)
Definition: linetemp.h:194
@ ICMP_TE_TTL
Definition: icmp.h:73
@ ICMP_DUR_PROTO
Definition: icmp.h:61
@ ICMP_DUR_FRAG
Definition: icmp.h:65
#define MEMCPY(DST, SRC, BYTES)
Definition: macros.h:231
static char * dest
Definition: rtl.c:135
struct netif * netif_default
Definition: netif.c:115
#define netif_is_link_up(netif)
Definition: netif.h:491
#define NETIF_FOREACH(netif)
Definition: netif.h:424
#define NETIF_RESET_HINTS(netif)
Definition: netif.h:570
#define NETIF_CHECKSUM_ENABLED(netif, chksumflag)
Definition: netif.h:414
#define IF__NETIF_CHECKSUM_ENABLED(netif, chksumflag)
Definition: netif.h:416
#define NETIF_SET_HINTS(netif, netifhint)
Definition: netif.h:569
u8_t pbuf_add_header(struct pbuf *p, size_t header_size_increment)
Definition: pbuf.c:554
u8_t pbuf_remove_header(struct pbuf *p, size_t header_size_decrement)
Definition: pbuf.c:585
u8_t pbuf_header_force(struct pbuf *p, s16_t header_size_increment)
Definition: pbuf.c:659
#define PBUF_FLAG_LLBCAST
Definition: pbuf.h:179
#define PBUF_FLAG_MCASTLOOP
Definition: pbuf.h:177
#define PBUF_FLAG_LLMCAST
Definition: pbuf.h:181
#define PERF_START
Definition: perf.h:3
#define PERF_STOP
Definition: perf.h:4
#define IPH_VHL_SET(hdr, v, hl)
Definition: ip4.h:117
#define IPH_V(hdr)
Definition: ip4.h:104
#define IPH_LEN_SET(hdr, len)
Definition: ip4.h:119
#define IPH_TTL(hdr)
Definition: ip4.h:112
#define IPH_TOS(hdr)
Definition: ip4.h:107
#define IPH_HL_BYTES(hdr)
Definition: ip4.h:106
#define IPH_ID_SET(hdr, id)
Definition: ip4.h:120
#define IP_HLEN_MAX
Definition: ip4.h:66
#define IPH_PROTO_SET(hdr, proto)
Definition: ip4.h:123
#define IPH_OFFSET_SET(hdr, off)
Definition: ip4.h:121
#define IPH_OFFSET(hdr)
Definition: ip4.h:110
#define IPH_CHKSUM(hdr)
Definition: ip4.h:114
#define IPH_HL(hdr)
Definition: ip4.h:105
#define IPH_TTL_SET(hdr, ttl)
Definition: ip4.h:122
#define IPH_PROTO(hdr)
Definition: ip4.h:113
#define IP_HLEN
Definition: ip4.h:64
#define IPH_ID(hdr)
Definition: ip4.h:109
#define IPH_LEN(hdr)
Definition: ip4.h:108
#define IPH_CHKSUM_SET(hdr, chksum)
Definition: ip4.h:124
#define IPH_TOS_SET(hdr, tos)
Definition: ip4.h:118
#define err(...)
#define memset(x, y, z)
Definition: compat.h:39
#define MIB2_STATS_INC(x)
Definition: stats.h:467
#define IP_STATS_INC(x)
Definition: stats.h:360
Definition: icmp.h:65
Definition: ip4.h:73
Definition: dhcpd.h:62
Definition: netif.h:269
u8_t flags
Definition: netif.h:354
char name[2]
Definition: netif.h:356
u8_t num
Definition: netif.h:359
u16_t mtu
Definition: netif.h:344
Definition: pbuf.h:186
Definition: tcp.h:56
Definition: udp.h:53
Definition: dhcpd.h:79
static TNetwork net
Definition: tncon.cpp:351
int ret