STM32F769IDiscovery  1.00
uDANTE Audio Networking with STM32F7 DISCO board
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/ip_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/raw.h"
54 #include "lwip/udp.h"
55 #include "lwip/priv/tcp_priv.h"
56 #include "lwip/dhcp.h"
57 #include "lwip/autoip.h"
58 #include "lwip/stats.h"
59 
60 #include <string.h>
61 
64 #ifndef LWIP_INLINE_IP_CHKSUM
65 #if LWIP_CHECKSUM_CTRL_PER_NETIF
66 #define LWIP_INLINE_IP_CHKSUM 0
67 #else /* LWIP_CHECKSUM_CTRL_PER_NETIF */
68 #define LWIP_INLINE_IP_CHKSUM 1
69 #endif /* LWIP_CHECKSUM_CTRL_PER_NETIF */
70 #endif
71 
72 #if LWIP_INLINE_IP_CHKSUM && CHECKSUM_GEN_IP
73 #define CHECKSUM_GEN_IP_INLINE 1
74 #else
75 #define CHECKSUM_GEN_IP_INLINE 0
76 #endif
77 
78 #if LWIP_DHCP || defined(LWIP_IP_ACCEPT_UDP_PORT)
79 #define IP_ACCEPT_LINK_LAYER_ADDRESSING 1
80 
86 #if LWIP_DHCP && defined(LWIP_IP_ACCEPT_UDP_PORT)
87 /* accept DHCP client port and custom port */
88 #define IP_ACCEPT_LINK_LAYER_ADDRESSED_PORT(port) (((port) == PP_NTOHS(DHCP_CLIENT_PORT)) \
89  || (LWIP_IP_ACCEPT_UDP_PORT(port)))
90 #elif defined(LWIP_IP_ACCEPT_UDP_PORT) /* LWIP_DHCP && defined(LWIP_IP_ACCEPT_UDP_PORT) */
91 /* accept custom port only */
92 #define IP_ACCEPT_LINK_LAYER_ADDRESSED_PORT(port) (LWIP_IP_ACCEPT_UDP_PORT(port))
93 #else /* LWIP_DHCP && defined(LWIP_IP_ACCEPT_UDP_PORT) */
94 /* accept DHCP client port only */
95 #define IP_ACCEPT_LINK_LAYER_ADDRESSED_PORT(port) ((port) == PP_NTOHS(DHCP_CLIENT_PORT))
96 #endif /* LWIP_DHCP && defined(LWIP_IP_ACCEPT_UDP_PORT) */
97 
98 #else /* LWIP_DHCP */
99 #define IP_ACCEPT_LINK_LAYER_ADDRESSING 0
100 #endif /* LWIP_DHCP */
101 
103 struct ip_globals ip_data;
104 
106 static u16_t ip_id;
107 
108 #if LWIP_MULTICAST_TX_OPTIONS
109 
110 static struct netif* ip4_default_multicast_netif;
111 
113 void
114 ip4_set_default_multicast_netif(struct netif* default_multicast_netif)
115 {
116  ip4_default_multicast_netif = default_multicast_netif;
117 }
118 #endif /* LWIP_MULTICAST_TX_OPTIONS */
119 
120 #ifdef LWIP_HOOK_IP4_ROUTE_SRC
121 
125 struct netif *
126 ip4_route_src(const ip4_addr_t *dest, const ip4_addr_t *src)
127 {
128  if (src != NULL) {
129  struct netif *netif = LWIP_HOOK_IP4_ROUTE_SRC(dest, src);
130  if (netif != NULL) {
131  return netif;
132  }
133  }
134  return ip4_route(dest);
135 }
136 #endif /* LWIP_HOOK_IP4_ROUTE_SRC */
137 
147 struct netif *
148 ip4_route(const ip4_addr_t *dest)
149 {
150  struct netif *netif;
151 
152 #ifdef LWIP_HOOK_IP4_ROUTE_SRC
153  netif = LWIP_HOOK_IP4_ROUTE_SRC(dest, NULL);
154  if (netif != NULL) {
155  return netif;
156  }
157 #elif defined(LWIP_HOOK_IP4_ROUTE)
158  netif = LWIP_HOOK_IP4_ROUTE(dest);
159  if (netif != NULL) {
160  return netif;
161  }
162 #endif
163 
164 #if LWIP_MULTICAST_TX_OPTIONS
165  /* Use administratively selected interface for multicast by default */
166  if (ip4_addr_ismulticast(dest) && ip4_default_multicast_netif) {
167  return ip4_default_multicast_netif;
168  }
169 #endif /* LWIP_MULTICAST_TX_OPTIONS */
170 
171  /* iterate through netifs */
172  for (netif = netif_list; netif != NULL; netif = netif->next) {
173  /* is the netif up, does it have a link and a valid address? */
174  if (netif_is_up(netif) && netif_is_link_up(netif) && !ip4_addr_isany_val(*netif_ip4_addr(netif))) {
175  /* network mask matches? */
176  if (ip4_addr_netcmp(dest, netif_ip4_addr(netif), netif_ip4_netmask(netif))) {
177  /* return netif on which to forward IP packet */
178  return netif;
179  }
180  /* gateway matches on a non broadcast interface? (i.e. peer in a point to point interface) */
181  if (((netif->flags & NETIF_FLAG_BROADCAST) == 0) && ip4_addr_cmp(dest, netif_ip4_gw(netif))) {
182  /* return netif on which to forward IP packet */
183  return netif;
184  }
185  }
186  }
187 
188 #if LWIP_NETIF_LOOPBACK && !LWIP_HAVE_LOOPIF
189  /* loopif is disabled, looopback traffic is passed through any netif */
190  if (ip4_addr_isloopback(dest)) {
191  /* don't check for link on loopback traffic */
192  if (netif_is_up(netif_default)) {
193  return netif_default;
194  }
195  /* default netif is not up, just use any netif for loopback traffic */
196  for (netif = netif_list; netif != NULL; netif = netif->next) {
197  if (netif_is_up(netif)) {
198  return netif;
199  }
200  }
201  return NULL;
202  }
203 #endif /* LWIP_NETIF_LOOPBACK && !LWIP_HAVE_LOOPIF */
204 
206  ip4_addr_isany_val(*netif_ip4_addr(netif_default))) {
207  /* No matching netif found and default netif is not usable.
208  If this is not good enough for you, use LWIP_HOOK_IP4_ROUTE() */
209  LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("ip_route: No route to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
210  ip4_addr1_16(dest), ip4_addr2_16(dest), ip4_addr3_16(dest), ip4_addr4_16(dest)));
211  IP_STATS_INC(ip.rterr);
212  MIB2_STATS_INC(mib2.ipoutnoroutes);
213  return NULL;
214  }
215 
216  return netif_default;
217 }
218 
219 #if IP_FORWARD
220 
228 static int
229 ip4_canforward(struct pbuf *p)
230 {
231  u32_t addr = htonl(ip4_addr_get_u32(ip4_current_dest_addr()));
232 
233  if (p->flags & PBUF_FLAG_LLBCAST) {
234  /* don't route link-layer broadcasts */
235  return 0;
236  }
237  if ((p->flags & PBUF_FLAG_LLMCAST) && !IP_MULTICAST(addr)) {
238  /* don't route link-layer multicasts unless the destination address is an IP
239  multicast address */
240  return 0;
241  }
242  if (IP_EXPERIMENTAL(addr)) {
243  return 0;
244  }
245  if (IP_CLASSA(addr)) {
246  u32_t net = addr & IP_CLASSA_NET;
247  if ((net == 0) || (net == ((u32_t)IP_LOOPBACKNET << IP_CLASSA_NSHIFT))) {
248  /* don't route loopback packets */
249  return 0;
250  }
251  }
252  return 1;
253 }
254 
264 static void
265 ip4_forward(struct pbuf *p, struct ip_hdr *iphdr, struct netif *inp)
266 {
267  struct netif *netif;
268 
269  PERF_START;
270 
271  if (!ip4_canforward(p)) {
272  goto return_noroute;
273  }
274 
275  /* RFC3927 2.7: do not forward link-local addresses */
276  if (ip4_addr_islinklocal(ip4_current_dest_addr())) {
277  LWIP_DEBUGF(IP_DEBUG, ("ip_forward: not forwarding LLA %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
278  ip4_addr1_16(ip4_current_dest_addr()), ip4_addr2_16(ip4_current_dest_addr()),
279  ip4_addr3_16(ip4_current_dest_addr()), ip4_addr4_16(ip4_current_dest_addr())));
280  goto return_noroute;
281  }
282 
283  /* Find network interface where to forward this IP packet to. */
284  netif = ip4_route_src(ip4_current_dest_addr(), ip4_current_src_addr());
285  if (netif == NULL) {
286  LWIP_DEBUGF(IP_DEBUG, ("ip_forward: no forwarding route for %"U16_F".%"U16_F".%"U16_F".%"U16_F" found\n",
287  ip4_addr1_16(ip4_current_dest_addr()), ip4_addr2_16(ip4_current_dest_addr()),
288  ip4_addr3_16(ip4_current_dest_addr()), ip4_addr4_16(ip4_current_dest_addr())));
289  /* @todo: send ICMP_DUR_NET? */
290  goto return_noroute;
291  }
292 #if !IP_FORWARD_ALLOW_TX_ON_RX_NETIF
293  /* Do not forward packets onto the same network interface on which
294  * they arrived. */
295  if (netif == inp) {
296  LWIP_DEBUGF(IP_DEBUG, ("ip_forward: not bouncing packets back on incoming interface.\n"));
297  goto return_noroute;
298  }
299 #endif /* IP_FORWARD_ALLOW_TX_ON_RX_NETIF */
300 
301  /* decrement TTL */
302  IPH_TTL_SET(iphdr, IPH_TTL(iphdr) - 1);
303  /* send ICMP if TTL == 0 */
304  if (IPH_TTL(iphdr) == 0) {
305  MIB2_STATS_INC(mib2.ipinhdrerrors);
306 #if LWIP_ICMP
307  /* Don't send ICMP messages in response to ICMP messages */
308  if (IPH_PROTO(iphdr) != IP_PROTO_ICMP) {
309  icmp_time_exceeded(p, ICMP_TE_TTL);
310  }
311 #endif /* LWIP_ICMP */
312  return;
313  }
314 
315  /* Incrementally update the IP checksum. */
316  if (IPH_CHKSUM(iphdr) >= PP_HTONS(0xffffU - 0x100)) {
317  IPH_CHKSUM_SET(iphdr, IPH_CHKSUM(iphdr) + PP_HTONS(0x100) + 1);
318  } else {
319  IPH_CHKSUM_SET(iphdr, IPH_CHKSUM(iphdr) + PP_HTONS(0x100));
320  }
321 
322  LWIP_DEBUGF(IP_DEBUG, ("ip_forward: forwarding packet to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
323  ip4_addr1_16(ip4_current_dest_addr()), ip4_addr2_16(ip4_current_dest_addr()),
324  ip4_addr3_16(ip4_current_dest_addr()), ip4_addr4_16(ip4_current_dest_addr())));
325 
326  IP_STATS_INC(ip.fw);
327  MIB2_STATS_INC(mib2.ipforwdatagrams);
328  IP_STATS_INC(ip.xmit);
329 
330  PERF_STOP("ip_forward");
331  /* don't fragment if interface has mtu set to 0 [loopif] */
332  if (netif->mtu && (p->tot_len > netif->mtu)) {
333  if ((IPH_OFFSET(iphdr) & PP_NTOHS(IP_DF)) == 0) {
334 #if IP_FRAG
335  ip4_frag(p, netif, ip4_current_dest_addr());
336 #else /* IP_FRAG */
337  /* @todo: send ICMP Destination Unreachable code 13 "Communication administratively prohibited"? */
338 #endif /* IP_FRAG */
339  } else {
340 #if LWIP_ICMP
341  /* send ICMP Destination Unreachable code 4: "Fragmentation Needed and DF Set" */
342  icmp_dest_unreach(p, ICMP_DUR_FRAG);
343 #endif /* LWIP_ICMP */
344  }
345  return;
346  }
347  /* transmit pbuf on chosen interface */
348  netif->output(netif, p, ip4_current_dest_addr());
349  return;
350 return_noroute:
351  MIB2_STATS_INC(mib2.ipoutnoroutes);
352 }
353 #endif /* IP_FORWARD */
354 
355 /* If both IP versions are enabled, this function can dispatch packets to the correct one.
356  * If only IPv4 is enabled, this directly maps at ip4_input.
357  * May be used as netif input function.
358  */
359 err_t
360 ip_input(struct pbuf *p, struct netif *inp)
361 {
362 #if LWIP_IPV6
363  if (p != NULL) {
364  if (IP_HDR_GET_VERSION(p->payload) == 6) {
365  return ip6_input(p, inp);
366  }
367  return ip4_input(p, inp);
368  }
369  return ERR_VAL;
370 #else /* LWIP_IPV6 */
371  return ip4_input(p, inp);
372 #endif /* LWIP_IPV6 */
373 }
374 
375 #if 1
376 ip_addr_t UDANTE_IPAddr = {0};
377 u16_t UDANTE_UDPPort = 0;
378 #endif
379 
394 err_t
395 ip4_input(struct pbuf *p, struct netif *inp)
396 {
397  struct ip_hdr *iphdr;
398  struct netif *netif;
399  u16_t iphdr_hlen;
400  u16_t iphdr_len;
401 #if IP_ACCEPT_LINK_LAYER_ADDRESSING || LWIP_IGMP
402  int check_ip_src = 1;
403 #endif /* IP_ACCEPT_LINK_LAYER_ADDRESSING || LWIP_IGMP */
404 
405  //should we check that p is valid?
406  if ( !p )
407  return ERR_VAL;
408 
409  IP_STATS_INC(ip.recv);
410  MIB2_STATS_INC(mib2.ipinreceives);
411 
412  /* identify the IP header */
413  iphdr = (struct ip_hdr *)p->payload;
414  if (IPH_V(iphdr) != 4) {
415  LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_LEVEL_WARNING, ("IP packet dropped due to bad version number %"U16_F"\n", IPH_V(iphdr)));
416  ip4_debug_print(p);
417  pbuf_free(p);
418  IP_STATS_INC(ip.err);
419  IP_STATS_INC(ip.drop);
420  MIB2_STATS_INC(mib2.ipinhdrerrors);
421  return ERR_OK;
422  }
423 
424 #ifdef LWIP_HOOK_IP4_INPUT
425  if (LWIP_HOOK_IP4_INPUT(p, inp)) {
426  /* the packet has been eaten */
427  return ERR_OK;
428  }
429 #endif
430 
431  /* obtain IP header length in number of 32-bit words */
432  iphdr_hlen = IPH_HL(iphdr);
433  /* calculate IP header length in bytes */
434  iphdr_hlen *= 4;
435  /* obtain ip length in bytes */
436  iphdr_len = ntohs(IPH_LEN(iphdr));
437 
438  /* Trim pbuf. This is especially required for packets < 60 bytes. */
439  if (iphdr_len < p->tot_len) {
440  pbuf_realloc(p, iphdr_len);
441  }
442 
443  /* header length exceeds first pbuf length, or ip length exceeds total pbuf length? */
444  if ((iphdr_hlen > p->len) || (iphdr_len > p->tot_len)) {
445  if (iphdr_hlen > p->len) {
447  ("IP header (len %"U16_F") does not fit in first pbuf (len %"U16_F"), IP packet dropped.\n",
448  iphdr_hlen, p->len));
449  }
450  if (iphdr_len > p->tot_len) {
452  ("IP (len %"U16_F") is longer than pbuf (len %"U16_F"), IP packet dropped.\n",
453  iphdr_len, p->tot_len));
454  }
455  /* free (drop) packet pbufs */
456  pbuf_free(p);
457  IP_STATS_INC(ip.lenerr);
458  IP_STATS_INC(ip.drop);
459  MIB2_STATS_INC(mib2.ipindiscards);
460  return ERR_OK;
461  }
462 
463  /* verify checksum */
464 #if CHECKSUM_CHECK_IP
465  IF__NETIF_CHECKSUM_ENABLED(inp, NETIF_CHECKSUM_CHECK_IP) {
466  if (inet_chksum(iphdr, iphdr_hlen) != 0) {
467 
469  ("Checksum (0x%"X16_F") failed, IP packet dropped.\n", inet_chksum(iphdr, iphdr_hlen)));
470  ip4_debug_print(p);
471  pbuf_free(p);
472  IP_STATS_INC(ip.chkerr);
473  IP_STATS_INC(ip.drop);
474  MIB2_STATS_INC(mib2.ipinhdrerrors);
475  return ERR_OK;
476  }
477  }
478 #endif
479 
480  /* copy IP addresses to aligned ip_addr_t */
481  ip_addr_copy_from_ip4(ip_data.current_iphdr_dest, iphdr->dest);
482  ip_addr_copy_from_ip4(ip_data.current_iphdr_src, iphdr->src);
483 
484 #if 1
485  //XXXX - figure out where DANTA audio is
486  if (p->len == 325)
487  {
488  //take the UDP destination port, offset +22
489  unsigned char *udp = (unsigned char *)p->payload;
490  udp += 22;
491  UDANTE_UDPPort = *udp++ << 8;
492  UDANTE_UDPPort |= *udp;
493  if ((UDANTE_UDPPort >= 14336) && (UDANTE_UDPPort <= 14600))
494  {
495  ip_addr_copy_from_ip4(UDANTE_IPAddr, iphdr->dest);
496  }
497  }
498 #endif
499 
500  /* match packet against an interface, i.e. is this packet for us? */
501 #if LWIP_IGMP
502  if (ip4_addr_ismulticast(ip4_current_dest_addr())) {
503  if ((inp->flags & NETIF_FLAG_IGMP) && (igmp_lookfor_group(inp, ip4_current_dest_addr()))) {
504  /* IGMP snooping switches need 0.0.0.0 to be allowed as source address (RFC 4541) */
505  ip4_addr_t allsystems;
506  IP4_ADDR(&allsystems, 224, 0, 0, 1);
507  if (ip4_addr_cmp(ip4_current_dest_addr(), &allsystems) &&
509  check_ip_src = 0;
510  }
511  netif = inp;
512  } else {
513  netif = NULL;
514  }
515  } else
516 #endif /* LWIP_IGMP */
517  {
518  /* start trying with inp. if that's not acceptable, start walking the
519  list of configured netifs.
520  'first' is used as a boolean to mark whether we started walking the list */
521  int first = 1;
522  netif = inp;
523  do {
524  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",
525  ip4_addr_get_u32(&iphdr->dest), ip4_addr_get_u32(netif_ip4_addr(netif)),
526  ip4_addr_get_u32(&iphdr->dest) & ip4_addr_get_u32(netif_ip4_netmask(netif)),
527  ip4_addr_get_u32(netif_ip4_addr(netif)) & ip4_addr_get_u32(netif_ip4_netmask(netif)),
528  ip4_addr_get_u32(&iphdr->dest) & ~ip4_addr_get_u32(netif_ip4_netmask(netif))));
529 
530  /* interface is up and configured? */
531  if ((netif_is_up(netif)) && (!ip4_addr_isany_val(*netif_ip4_addr(netif)))) {
532  /* unicast to this interface address? */
533  if (ip4_addr_cmp(ip4_current_dest_addr(), netif_ip4_addr(netif)) ||
534  /* or broadcast on this interface network address? */
537  || (ip4_addr_get_u32(ip4_current_dest_addr()) == PP_HTONL(IPADDR_LOOPBACK))
538 #endif /* LWIP_NETIF_LOOPBACK && !LWIP_HAVE_LOOPIF */
539  ) {
540  LWIP_DEBUGF(IP_DEBUG, ("ip_input: packet accepted on interface %c%c\n",
541  netif->name[0], netif->name[1]));
542  /* break out of for loop */
543  break;
544  }
545 #if LWIP_AUTOIP
546  /* connections to link-local addresses must persist after changing
547  the netif's address (RFC3927 ch. 1.9) */
548  if ((netif->autoip != NULL) &&
549  ip4_addr_cmp(ip4_current_dest_addr(), &(netif->autoip->llipaddr))) {
550  LWIP_DEBUGF(IP_DEBUG, ("ip_input: LLA packet accepted on interface %c%c\n",
551  netif->name[0], netif->name[1]));
552  /* break out of for loop */
553  break;
554  }
555 #endif /* LWIP_AUTOIP */
556  }
557  if (first) {
558  first = 0;
559  netif = netif_list;
560  } else {
561  netif = netif->next;
562  }
563  if (netif == inp) {
564  netif = netif->next;
565  }
566  } while (netif != NULL);
567  }
568 
569 #if IP_ACCEPT_LINK_LAYER_ADDRESSING
570  /* Pass DHCP messages regardless of destination address. DHCP traffic is addressed
571  * using link layer addressing (such as Ethernet MAC) so we must not filter on IP.
572  * According to RFC 1542 section 3.1.1, referred by RFC 2131).
573  *
574  * If you want to accept private broadcast communication while a netif is down,
575  * define LWIP_IP_ACCEPT_UDP_PORT(dst_port), e.g.:
576  *
577  * #define LWIP_IP_ACCEPT_UDP_PORT(dst_port) ((dst_port) == PP_NTOHS(12345))
578  */
579  if (netif == NULL) {
580  /* remote port is DHCP server? */
581  if (IPH_PROTO(iphdr) == IP_PROTO_UDP) {
582  struct udp_hdr *udphdr = (struct udp_hdr *)((u8_t *)iphdr + iphdr_hlen);
583  LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_TRACE, ("ip_input: UDP packet to DHCP client port %"U16_F"\n",
584  ntohs(udphdr->dest)));
585  if (IP_ACCEPT_LINK_LAYER_ADDRESSED_PORT(udphdr->dest)) {
586  LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_TRACE, ("ip_input: DHCP packet accepted.\n"));
587  netif = inp;
588  check_ip_src = 0;
589  }
590  }
591  }
592 #endif /* IP_ACCEPT_LINK_LAYER_ADDRESSING */
593 
594  /* broadcast or multicast packet source address? Compliant with RFC 1122: 3.2.1.3 */
595 #if LWIP_IGMP || IP_ACCEPT_LINK_LAYER_ADDRESSING
596  if (check_ip_src
597 #if IP_ACCEPT_LINK_LAYER_ADDRESSING
598  /* DHCP servers need 0.0.0.0 to be allowed as source address (RFC 1.1.2.2: 3.2.1.3/a) */
600 #endif /* IP_ACCEPT_LINK_LAYER_ADDRESSING */
601  )
602 #endif /* LWIP_IGMP || IP_ACCEPT_LINK_LAYER_ADDRESSING */
603  {
606  /* packet source is not valid */
607  LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_WARNING, ("ip_input: packet source is not valid.\n"));
608  /* free (drop) packet pbufs */
609  pbuf_free(p);
610  IP_STATS_INC(ip.drop);
611  MIB2_STATS_INC(mib2.ipinaddrerrors);
612  MIB2_STATS_INC(mib2.ipindiscards);
613  return ERR_OK;
614  }
615  }
616 
617  /* packet not for us? */
618  if (netif == NULL) {
619  /* packet not for us, route or discard */
620  LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_TRACE, ("ip_input: packet not for us.\n"));
621 #if IP_FORWARD
622  /* non-broadcast packet? */
624  /* try to forward IP packet on (other) interfaces */
625  ip4_forward(p, iphdr, inp);
626  } else
627 #endif /* IP_FORWARD */
628  {
629  MIB2_STATS_INC(mib2.ipinaddrerrors);
630  MIB2_STATS_INC(mib2.ipindiscards);
631  }
632  pbuf_free(p);
633  return ERR_OK;
634  }
635  /* packet consists of multiple fragments? */
636  if ((IPH_OFFSET(iphdr) & PP_HTONS(IP_OFFMASK | IP_MF)) != 0) {
637 #if IP_REASSEMBLY /* packet fragment reassembly code present? */
638  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",
639  ntohs(IPH_ID(iphdr)), p->tot_len, ntohs(IPH_LEN(iphdr)), !!(IPH_OFFSET(iphdr) & PP_HTONS(IP_MF)), (ntohs(IPH_OFFSET(iphdr)) & IP_OFFMASK)*8));
640  /* reassemble the packet*/
641  p = ip4_reass(p);
642  /* packet not fully reassembled yet? */
643  if (p == NULL) {
644  return ERR_OK;
645  }
646  iphdr = (struct ip_hdr *)p->payload;
647 #else /* IP_REASSEMBLY == 0, no packet fragment reassembly code present */
648  pbuf_free(p);
649  LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("IP packet dropped since it was fragmented (0x%"X16_F") (while IP_REASSEMBLY == 0).\n",
650  ntohs(IPH_OFFSET(iphdr))));
651  IP_STATS_INC(ip.opterr);
652  IP_STATS_INC(ip.drop);
653  /* unsupported protocol feature */
654  MIB2_STATS_INC(mib2.ipinunknownprotos);
655  return ERR_OK;
656 #endif /* IP_REASSEMBLY */
657  }
658 
659 #if IP_OPTIONS_ALLOWED == 0 /* no support for IP options in the IP header? */
660 
661 #if LWIP_IGMP
662  /* there is an extra "router alert" option in IGMP messages which we allow for but do not police */
663  if ((iphdr_hlen > IP_HLEN) && (IPH_PROTO(iphdr) != IP_PROTO_IGMP)) {
664 #else
665  if (iphdr_hlen > IP_HLEN) {
666 #endif /* LWIP_IGMP */
667  LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("IP packet dropped since there were IP options (while IP_OPTIONS_ALLOWED == 0).\n"));
668  pbuf_free(p);
669  IP_STATS_INC(ip.opterr);
670  IP_STATS_INC(ip.drop);
671  /* unsupported protocol feature */
672  MIB2_STATS_INC(mib2.ipinunknownprotos);
673  return ERR_OK;
674  }
675 #endif /* IP_OPTIONS_ALLOWED == 0 */
676 
677  /* send to upper layers */
678  LWIP_DEBUGF(IP_DEBUG, ("ip_input: \n"));
679  ip4_debug_print(p);
680  LWIP_DEBUGF(IP_DEBUG, ("ip_input: p->len %"U16_F" p->tot_len %"U16_F"\n", p->len, p->tot_len));
681 
682  ip_data.current_netif = netif;
684  ip_data.current_ip4_header = iphdr;
685  ip_data.current_ip_header_tot_len = IPH_HL(iphdr) * 4;
686 
687 #if LWIP_RAW
688  /* raw input did not eat the packet? */
689  if (raw_input(p, inp) == 0)
690 #endif /* LWIP_RAW */
691  {
692  pbuf_header(p, -(s16_t)iphdr_hlen); /* Move to payload, no check necessary. */
693 
694  switch (IPH_PROTO(iphdr)) {
695 #if LWIP_UDP
696  case IP_PROTO_UDP:
697 #if LWIP_UDPLITE
698  case IP_PROTO_UDPLITE:
699 #endif /* LWIP_UDPLITE */
700  MIB2_STATS_INC(mib2.ipindelivers);
701  udp_input(p, inp);
702  break;
703 #endif /* LWIP_UDP */
704 #if LWIP_TCP
705  case IP_PROTO_TCP:
706  MIB2_STATS_INC(mib2.ipindelivers);
707  tcp_input(p, inp);
708  break;
709 #endif /* LWIP_TCP */
710 #if LWIP_ICMP
711  case IP_PROTO_ICMP:
712  MIB2_STATS_INC(mib2.ipindelivers);
713  icmp_input(p, inp);
714  break;
715 #endif /* LWIP_ICMP */
716 #if LWIP_IGMP
717  case IP_PROTO_IGMP:
718  igmp_input(p, inp, ip4_current_dest_addr());
719  break;
720 #endif /* LWIP_IGMP */
721  default:
722 #if LWIP_ICMP
723  /* send ICMP destination protocol unreachable unless is was a broadcast */
724  if (!ip_addr_isbroadcast(ip_current_dest_addr(), netif) &&
726  pbuf_header_force(p, iphdr_hlen); /* Move to ip header, no check necessary. */
727  p->payload = iphdr;
728  icmp_dest_unreach(p, ICMP_DUR_PROTO);
729  }
730 #endif /* LWIP_ICMP */
731  pbuf_free(p);
732 
733  LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("Unsupported transport protocol %"U16_F"\n", IPH_PROTO(iphdr)));
734 
735  IP_STATS_INC(ip.proterr);
736  IP_STATS_INC(ip.drop);
737  MIB2_STATS_INC(mib2.ipinunknownprotos);
738  }
739  }
740 
741  /* @todo: this is not really necessary... */
744  ip_data.current_ip4_header = NULL;
746  ip4_addr_set_any(ip4_current_src_addr());
747  ip4_addr_set_any(ip4_current_dest_addr());
748 
749  return ERR_OK;
750 }
751 
777 err_t
778 ip4_output_if(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest,
779  u8_t ttl, u8_t tos,
780  u8_t proto, struct netif *netif)
781 {
782 #if IP_OPTIONS_SEND
783  return ip4_output_if_opt(p, src, dest, ttl, tos, proto, netif, NULL, 0);
784 }
785 
792 err_t ip4_output_if_opt(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest,
793  u8_t ttl, u8_t tos, u8_t proto, struct netif *netif, void *ip_options,
794  u16_t optlen)
795 {
796 #endif /* IP_OPTIONS_SEND */
797  const ip4_addr_t *src_used = src;
798  if (dest != IP_HDRINCL) {
799  if (ip4_addr_isany(src)) {
800  src_used = netif_ip4_addr(netif);
801  }
802  }
803 
804 #if IP_OPTIONS_SEND
805  return ip4_output_if_opt_src(p, src_used, dest, ttl, tos, proto, netif,
806  ip_options, optlen);
807 #else /* IP_OPTIONS_SEND */
808  return ip4_output_if_src(p, src_used, dest, ttl, tos, proto, netif);
809 #endif /* IP_OPTIONS_SEND */
810 }
811 
816 err_t
817 ip4_output_if_src(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest,
818  u8_t ttl, u8_t tos,
819  u8_t proto, struct netif *netif)
820 {
821 #if IP_OPTIONS_SEND
822  return ip4_output_if_opt_src(p, src, dest, ttl, tos, proto, netif, NULL, 0);
823 }
824 
829 err_t ip4_output_if_opt_src(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest,
830  u8_t ttl, u8_t tos, u8_t proto, struct netif *netif, void *ip_options,
831  u16_t optlen)
832 {
833 #endif /* IP_OPTIONS_SEND */
834  struct ip_hdr *iphdr;
835  ip4_addr_t dest_addr;
836 #if CHECKSUM_GEN_IP_INLINE
837  u32_t chk_sum = 0;
838 #endif /* CHECKSUM_GEN_IP_INLINE */
839 
841 
842  MIB2_STATS_INC(mib2.ipoutrequests);
843 
844  /* Should the IP header be generated or is it already included in p? */
845  if (dest != IP_HDRINCL) {
846  u16_t ip_hlen = IP_HLEN;
847 #if IP_OPTIONS_SEND
848  u16_t optlen_aligned = 0;
849  if (optlen != 0) {
850 #if CHECKSUM_GEN_IP_INLINE
851  int i;
852 #endif /* CHECKSUM_GEN_IP_INLINE */
853  /* round up to a multiple of 4 */
854  optlen_aligned = ((optlen + 3) & ~3);
855  ip_hlen += optlen_aligned;
856  /* First write in the IP options */
857  if (pbuf_header(p, optlen_aligned)) {
858  LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("ip_output_if_opt: not enough room for IP options in pbuf\n"));
859  IP_STATS_INC(ip.err);
860  MIB2_STATS_INC(mib2.ipoutdiscards);
861  return ERR_BUF;
862  }
863  MEMCPY(p->payload, ip_options, optlen);
864  if (optlen < optlen_aligned) {
865  /* zero the remaining bytes */
866  memset(((char*)p->payload) + optlen, 0, optlen_aligned - optlen);
867  }
868 #if CHECKSUM_GEN_IP_INLINE
869  for (i = 0; i < optlen_aligned/2; i++) {
870  chk_sum += ((u16_t*)p->payload)[i];
871  }
872 #endif /* CHECKSUM_GEN_IP_INLINE */
873  }
874 #endif /* IP_OPTIONS_SEND */
875  /* generate IP header */
876  if (pbuf_header(p, IP_HLEN)) {
877  LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("ip_output: not enough room for IP header in pbuf\n"));
878 
879  IP_STATS_INC(ip.err);
880  MIB2_STATS_INC(mib2.ipoutdiscards);
881  return ERR_BUF;
882  }
883 
884  iphdr = (struct ip_hdr *)p->payload;
885  LWIP_ASSERT("check that first pbuf can hold struct ip_hdr",
886  (p->len >= sizeof(struct ip_hdr)));
887 
888  IPH_TTL_SET(iphdr, ttl);
889  IPH_PROTO_SET(iphdr, proto);
890 #if CHECKSUM_GEN_IP_INLINE
891  chk_sum += LWIP_MAKE_U16(proto, ttl);
892 #endif /* CHECKSUM_GEN_IP_INLINE */
893 
894  /* dest cannot be NULL here */
895  ip4_addr_copy(iphdr->dest, *dest);
896 #if CHECKSUM_GEN_IP_INLINE
897  chk_sum += ip4_addr_get_u32(&iphdr->dest) & 0xFFFF;
898  chk_sum += ip4_addr_get_u32(&iphdr->dest) >> 16;
899 #endif /* CHECKSUM_GEN_IP_INLINE */
900 
901  IPH_VHL_SET(iphdr, 4, ip_hlen / 4);
902  IPH_TOS_SET(iphdr, tos);
903 #if CHECKSUM_GEN_IP_INLINE
904  chk_sum += LWIP_MAKE_U16(tos, iphdr->_v_hl);
905 #endif /* CHECKSUM_GEN_IP_INLINE */
906  IPH_LEN_SET(iphdr, htons(p->tot_len));
907 #if CHECKSUM_GEN_IP_INLINE
908  chk_sum += iphdr->_len;
909 #endif /* CHECKSUM_GEN_IP_INLINE */
910  IPH_OFFSET_SET(iphdr, 0);
911  IPH_ID_SET(iphdr, htons(ip_id));
912 #if CHECKSUM_GEN_IP_INLINE
913  chk_sum += iphdr->_id;
914 #endif /* CHECKSUM_GEN_IP_INLINE */
915  ++ip_id;
916 
917  if (src == NULL) {
918  ip4_addr_copy(iphdr->src, *IP4_ADDR_ANY);
919  } else {
920  /* src cannot be NULL here */
921  ip4_addr_copy(iphdr->src, *src);
922  }
923 
924 #if CHECKSUM_GEN_IP_INLINE
925  chk_sum += ip4_addr_get_u32(&iphdr->src) & 0xFFFF;
926  chk_sum += ip4_addr_get_u32(&iphdr->src) >> 16;
927  chk_sum = (chk_sum >> 16) + (chk_sum & 0xFFFF);
928  chk_sum = (chk_sum >> 16) + chk_sum;
929  chk_sum = ~chk_sum;
930  IF__NETIF_CHECKSUM_ENABLED(netif, NETIF_CHECKSUM_GEN_IP) {
931  iphdr->_chksum = (u16_t)chk_sum; /* network order */
932  }
933 #if LWIP_CHECKSUM_CTRL_PER_NETIF
934  else {
935  IPH_CHKSUM_SET(iphdr, 0);
936  }
937 #endif /* LWIP_CHECKSUM_CTRL_PER_NETIF*/
938 #else /* CHECKSUM_GEN_IP_INLINE */
939  IPH_CHKSUM_SET(iphdr, 0);
940 #if CHECKSUM_GEN_IP
941  IF__NETIF_CHECKSUM_ENABLED(netif, NETIF_CHECKSUM_GEN_IP) {
942  IPH_CHKSUM_SET(iphdr, inet_chksum(iphdr, ip_hlen));
943  }
944 #endif /* CHECKSUM_GEN_IP */
945 #endif /* CHECKSUM_GEN_IP_INLINE */
946  } else {
947  /* IP header already included in p */
948  iphdr = (struct ip_hdr *)p->payload;
949  ip4_addr_copy(dest_addr, iphdr->dest);
950  dest = &dest_addr;
951  }
952 
953  IP_STATS_INC(ip.xmit);
954 
955  LWIP_DEBUGF(IP_DEBUG, ("ip_output_if: %c%c%"U16_F"\n", netif->name[0], netif->name[1], netif->num));
956  ip4_debug_print(p);
957 
958 #if ENABLE_LOOPBACK
959  if (ip4_addr_cmp(dest, netif_ip4_addr(netif))
960 #if !LWIP_HAVE_LOOPIF
961  || ip4_addr_isloopback(dest)
962 #endif /* !LWIP_HAVE_LOOPIF */
963  ) {
964  /* Packet to self, enqueue it for loopback */
965  LWIP_DEBUGF(IP_DEBUG, ("netif_loop_output()"));
966  return netif_loop_output(netif, p);
967  }
968 #if LWIP_MULTICAST_TX_OPTIONS
969  if ((p->flags & PBUF_FLAG_MCASTLOOP) != 0) {
970  netif_loop_output(netif, p);
971  }
972 #endif /* LWIP_MULTICAST_TX_OPTIONS */
973 #endif /* ENABLE_LOOPBACK */
974 #if IP_FRAG
975  /* don't fragment if interface has mtu set to 0 [loopif] */
976  if (netif->mtu && (p->tot_len > netif->mtu)) {
977  return ip4_frag(p, netif, dest);
978  }
979 #endif /* IP_FRAG */
980 
981  LWIP_DEBUGF(IP_DEBUG, ("ip4_output_if: call netif->output()\n"));
982  return netif->output(netif, p, dest);
983 }
984 
1002 err_t
1003 ip4_output(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest,
1004  u8_t ttl, u8_t tos, u8_t proto)
1005 {
1006  struct netif *netif;
1007 
1009 
1010  if ((netif = ip4_route_src(dest, src)) == NULL) {
1011  LWIP_DEBUGF(IP_DEBUG, ("ip_output: No route to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
1012  ip4_addr1_16(dest), ip4_addr2_16(dest), ip4_addr3_16(dest), ip4_addr4_16(dest)));
1013  IP_STATS_INC(ip.rterr);
1014  return ERR_RTE;
1015  }
1016 
1017  return ip4_output_if(p, src, dest, ttl, tos, proto, netif);
1018 }
1019 
1020 #if LWIP_NETIF_HWADDRHINT
1021 
1039 err_t
1040 ip4_output_hinted(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest,
1041  u8_t ttl, u8_t tos, u8_t proto, u8_t *addr_hint)
1042 {
1043  struct netif *netif;
1044  err_t err;
1045 
1047 
1048  if ((netif = ip4_route_src(dest, src)) == NULL) {
1049  LWIP_DEBUGF(IP_DEBUG, ("ip_output: No route to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
1050  ip4_addr1_16(dest), ip4_addr2_16(dest), ip4_addr3_16(dest), ip4_addr4_16(dest)));
1051  IP_STATS_INC(ip.rterr);
1052  return ERR_RTE;
1053  }
1054 
1055  NETIF_SET_HWADDRHINT(netif, addr_hint);
1056  err = ip4_output_if(p, src, dest, ttl, tos, proto, netif);
1057  NETIF_SET_HWADDRHINT(netif, NULL);
1058 
1059  return err;
1060 }
1061 #endif /* LWIP_NETIF_HWADDRHINT*/
1062 
1063 #if IP_DEBUG
1064 /* Print an IP header by using LWIP_DEBUGF
1065  * @param p an IP packet, p->payload pointing to the IP header
1066  */
1067 void
1068 ip4_debug_print(struct pbuf *p)
1069 {
1070  struct ip_hdr *iphdr = (struct ip_hdr *)p->payload;
1071 
1072  LWIP_DEBUGF(IP_DEBUG, ("IP header:\n"));
1073  LWIP_DEBUGF(IP_DEBUG, ("+-------------------------------+\n"));
1074  LWIP_DEBUGF(IP_DEBUG, ("|%2"S16_F" |%2"S16_F" | 0x%02"X16_F" | %5"U16_F" | (v, hl, tos, len)\n",
1075  IPH_V(iphdr),
1076  IPH_HL(iphdr),
1077  IPH_TOS(iphdr),
1078  ntohs(IPH_LEN(iphdr))));
1079  LWIP_DEBUGF(IP_DEBUG, ("+-------------------------------+\n"));
1080  LWIP_DEBUGF(IP_DEBUG, ("| %5"U16_F" |%"U16_F"%"U16_F"%"U16_F"| %4"U16_F" | (id, flags, offset)\n",
1081  ntohs(IPH_ID(iphdr)),
1082  ntohs(IPH_OFFSET(iphdr)) >> 15 & 1,
1083  ntohs(IPH_OFFSET(iphdr)) >> 14 & 1,
1084  ntohs(IPH_OFFSET(iphdr)) >> 13 & 1,
1085  ntohs(IPH_OFFSET(iphdr)) & IP_OFFMASK));
1086  LWIP_DEBUGF(IP_DEBUG, ("+-------------------------------+\n"));
1087  LWIP_DEBUGF(IP_DEBUG, ("| %3"U16_F" | %3"U16_F" | 0x%04"X16_F" | (ttl, proto, chksum)\n",
1088  IPH_TTL(iphdr),
1089  IPH_PROTO(iphdr),
1090  ntohs(IPH_CHKSUM(iphdr))));
1091  LWIP_DEBUGF(IP_DEBUG, ("+-------------------------------+\n"));
1092  LWIP_DEBUGF(IP_DEBUG, ("| %3"U16_F" | %3"U16_F" | %3"U16_F" | %3"U16_F" | (src)\n",
1093  ip4_addr1_16(&iphdr->src),
1094  ip4_addr2_16(&iphdr->src),
1095  ip4_addr3_16(&iphdr->src),
1096  ip4_addr4_16(&iphdr->src)));
1097  LWIP_DEBUGF(IP_DEBUG, ("+-------------------------------+\n"));
1098  LWIP_DEBUGF(IP_DEBUG, ("| %3"U16_F" | %3"U16_F" | %3"U16_F" | %3"U16_F" | (dest)\n",
1099  ip4_addr1_16(&iphdr->dest),
1100  ip4_addr2_16(&iphdr->dest),
1101  ip4_addr3_16(&iphdr->dest),
1102  ip4_addr4_16(&iphdr->dest)));
1103  LWIP_DEBUGF(IP_DEBUG, ("+-------------------------------+\n"));
1104 }
1105 #endif /* IP_DEBUG */
1106 
1107 #endif /* LWIP_IPV4 */
1108 
#define PP_HTONL(x)
Definition: def.h:99
#define MIB2_STATS_INC(x)
Definition: stats.h:407
#define IP_PROTO_ICMP
Definition: ip.h:49
u8_t flags
Definition: netif.h:269
struct netif * netif_list
Definition: netif.c:84
#define LWIP_DBG_LEVEL_SERIOUS
Definition: debug.h:47
#define ip_addr_isany(ipaddr)
Definition: ip_addr.h:215
struct netif * netif_default
Definition: netif.c:85
#define LWIP_DBG_LEVEL_WARNING
Definition: debug.h:46
#define U16_F
Definition: cc.h:48
signed short s16_t
Definition: cc.h:41
#define ip_addr_isany_val(ipaddr)
Definition: ip_addr.h:216
u8_t pbuf_header(struct pbuf *p, s16_t header_size_increment)
Definition: pbuf.c:603
void pbuf_realloc(struct pbuf *p, u16_t new_len)
Definition: pbuf.c:431
#define ERR_VAL
Definition: err.h:58
#define netif_is_link_up(netif)
Definition: netif.h:368
ip_addr_t current_iphdr_dest
Definition: ip.h:145
struct netif * next
Definition: netif.h:184
u16_t mtu
Definition: netif.h:263
#define PERF_STOP(x)
Definition: def.h:42
#define htons(x)
Definition: def.h:86
err_t ip_input(struct pbuf *p, struct netif *inp)
#define IP_PROTO_TCP
Definition: ip.h:53
#define PBUF_FLAG_LLBCAST
Definition: pbuf.h:102
#define IF__NETIF_CHECKSUM_ENABLED(netif, chksumflag)
Definition: netif.h:313
#define MEMCPY(dst, src, len)
Definition: opt.h:84
if(LCD_Lock==DISABLE)
Definition: lcd_log.c:249
#define ip_addr_isbroadcast(addr, netif)
Definition: ip_addr.h:219
u16_t len
Definition: pbuf.h:125
#define ip_current_dest_addr()
Definition: ip.h:238
u16_t current_ip_header_tot_len
Definition: ip.h:141
#define IP_HDRINCL
Definition: ip.h:64
#define IP_PROTO_IGMP
Definition: ip.h:50
#define ip_addr_ismulticast(ipaddr)
Definition: ip_addr.h:220
#define IP_DEBUG
Definition: opt.h:2837
u16_t inet_chksum(const void *dataptr, u16_t len)
Definition: inet_chksum.c:558
ip_addr_t current_iphdr_src
Definition: ip.h:143
char name[2]
Definition: netif.h:271
u8_t flags
Definition: pbuf.h:131
#define PBUF_FLAG_MCASTLOOP
Definition: pbuf.h:100
struct netif * current_netif
Definition: ip.h:129
#define PERF_START
Definition: def.h:41
#define NULL
Definition: usbd_def.h:53
u8_t pbuf_free(struct pbuf *p)
Definition: pbuf.c:652
#define LWIP_NETIF_LOOPBACK
Definition: opt.h:1265
#define PP_HTONS(x)
Definition: def.h:97
unsigned long u32_t
Definition: cc.h:42
#define ERR_RTE
Definition: err.h:56
u8_t num
Definition: netif.h:273
#define ERR_OK
Definition: err.h:52
u16_t tot_len
Definition: pbuf.h:122
#define NETIF_SET_HWADDRHINT(netif, hint)
Definition: netif.h:411
#define LWIP_DBG_TRACE
Definition: debug.h:57
Definition: pbuf.h:108
#define NETIF_FLAG_BROADCAST
Definition: netif.h:80
s8_t err_t
Definition: err.h:47
#define LWIP_ASSERT(message, assertion)
Definition: debug.h:70
Definition: netif.h:182
#define NETIF_FLAG_IGMP
Definition: netif.h:97
#define PBUF_FLAG_LLMCAST
Definition: pbuf.h:104
struct ip_globals ip_data
Definition: ip.h:126
#define S16_F
Definition: cc.h:49
#define LWIP_HAVE_LOOPIF
Definition: opt.h:1317
#define LWIP_IP_CHECK_PBUF_REF_COUNT_FOR_TX(p)
Definition: ip.h:69
#define IP_PROTO_UDP
Definition: ip.h:51
#define ip_current_src_addr()
Definition: ip.h:236
u8_t pbuf_header_force(struct pbuf *p, s16_t header_size_increment)
Definition: pbuf.c:613
#define PP_NTOHS(x)
Definition: def.h:98
unsigned char u8_t
Definition: cc.h:38
ip6_addr_t ip_addr_t
Definition: ip_addr.h:194
#define IP_STATS_INC(x)
Definition: stats.h:294
#define IP_PROTO_UDPLITE
Definition: ip.h:52
#define netif_is_up(netif)
Definition: netif.h:356
#define X32_F
Definition: cc.h:53
#define IP_HDR_GET_VERSION(ptr)
Definition: ip.h:56
#define LWIP_MAKE_U16(a, b)
Definition: def.h:61
#define LWIP_DEBUGF(debug, message)
Definition: debug.h:113
struct netif * current_input_netif
Definition: ip.h:131
#define ntohs(x)
Definition: def.h:87
#define htonl(x)
Definition: def.h:88
unsigned short u16_t
Definition: cc.h:40
void * payload
Definition: pbuf.h:113
#define X16_F
Definition: cc.h:50
#define ERR_BUF
Definition: err.h:54