STM32F769IDiscovery  1.00
uDANTE Audio Networking with STM32F7 DISCO board
udp.c
Go to the documentation of this file.
1 
7 /*
8  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without modification,
12  * are permitted provided that the following conditions are met:
13  *
14  * 1. Redistributions of source code must retain the above copyright notice,
15  * this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright notice,
17  * this list of conditions and the following disclaimer in the documentation
18  * and/or other materials provided with the distribution.
19  * 3. The name of the author may not be used to endorse or promote products
20  * derived from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
23  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
25  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
27  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
30  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
31  * OF SUCH DAMAGE.
32  *
33  * This file is part of the lwIP TCP/IP stack.
34  *
35  * Author: Adam Dunkels <adam@sics.se>
36  *
37  */
38 
39 
40 /* udp.c
41  *
42  * The code for the User Datagram Protocol UDP & UDPLite (RFC 3828).
43  *
44  */
45 
46 /* @todo Check the use of '(struct udp_pcb).chksum_len_rx'!
47  */
48 
49 #include "lwip/opt.h"
50 
51 #if LWIP_UDP /* don't build if not configured for use in lwipopts.h */
52 
53 #include "lwip/udp.h"
54 #include "lwip/def.h"
55 #include "lwip/memp.h"
56 #include "lwip/inet_chksum.h"
57 #include "lwip/ip_addr.h"
58 #include "lwip/ip6.h"
59 #include "lwip/ip6_addr.h"
60 #include "lwip/inet_chksum.h"
61 #include "lwip/netif.h"
62 #include "lwip/icmp.h"
63 #include "lwip/icmp6.h"
64 #include "lwip/stats.h"
65 #include "lwip/snmp.h"
66 #include "lwip/dhcp.h"
67 
68 #include <string.h>
69 
70 #ifndef UDP_LOCAL_PORT_RANGE_START
71 /* From http://www.iana.org/assignments/port-numbers:
72  "The Dynamic and/or Private Ports are those from 49152 through 65535" */
73 #define UDP_LOCAL_PORT_RANGE_START 0xc000
74 #define UDP_LOCAL_PORT_RANGE_END 0xffff
75 #define UDP_ENSURE_LOCAL_PORT_RANGE(port) ((u16_t)(((port) & ~UDP_LOCAL_PORT_RANGE_START) + UDP_LOCAL_PORT_RANGE_START))
76 #endif
77 
78 /* last local UDP port */
79 static u16_t udp_port = UDP_LOCAL_PORT_RANGE_START;
80 
81 /* The list of UDP PCBs */
82 /* exported in udp.h (was static) */
83 struct udp_pcb *udp_pcbs;
84 
88 void
89 udp_init(void)
90 {
91 #if LWIP_RANDOMIZE_INITIAL_LOCAL_PORTS && defined(LWIP_RAND)
92  udp_port = UDP_ENSURE_LOCAL_PORT_RANGE(LWIP_RAND());
93 #endif /* LWIP_RANDOMIZE_INITIAL_LOCAL_PORTS && defined(LWIP_RAND) */
94 }
95 
101 static u16_t
102 udp_new_port(void)
103 {
104  u16_t n = 0;
105  struct udp_pcb *pcb;
106 
107 again:
108  if (udp_port++ == UDP_LOCAL_PORT_RANGE_END) {
109  udp_port = UDP_LOCAL_PORT_RANGE_START;
110  }
111  /* Check all PCBs. */
112  for (pcb = udp_pcbs; pcb != NULL; pcb = pcb->next) {
113  if (pcb->local_port == udp_port) {
114  if (++n > (UDP_LOCAL_PORT_RANGE_END - UDP_LOCAL_PORT_RANGE_START)) {
115  return 0;
116  }
117  goto again;
118  }
119  }
120  return udp_port;
121 #if 0
122  struct udp_pcb *ipcb = udp_pcbs;
123  while ((ipcb != NULL) && (udp_port != UDP_LOCAL_PORT_RANGE_END)) {
124  if (ipcb->local_port == udp_port) {
125  /* port is already used by another udp_pcb */
126  udp_port++;
127  /* restart scanning all udp pcbs */
128  ipcb = udp_pcbs;
129  } else {
130  /* go on with next udp pcb */
131  ipcb = ipcb->next;
132  }
133  }
134  if (ipcb != NULL) {
135  return 0;
136  }
137  return udp_port;
138 #endif
139 }
140 
153 void
154 udp_input(struct pbuf *p, struct netif *inp)
155 {
156  struct udp_hdr *udphdr;
157  struct udp_pcb *pcb, *prev;
158  struct udp_pcb *uncon_pcb;
159  u16_t src, dest;
160  u8_t local_match;
161 #if LWIP_IPV4
162  u8_t broadcast;
163 #endif /* LWIP_IPV4 */
164  u8_t for_us;
165 
166  LWIP_UNUSED_ARG(inp);
167 
168  PERF_START;
169 
170  UDP_STATS_INC(udp.recv);
171 
172  /* Check minimum length (UDP header) */
173  if (p->len < UDP_HLEN) {
174  /* drop short packets */
176  ("udp_input: short UDP datagram (%"U16_F" bytes) discarded\n", p->tot_len));
177  UDP_STATS_INC(udp.lenerr);
178  UDP_STATS_INC(udp.drop);
179  MIB2_STATS_INC(mib2.udpinerrors);
180  pbuf_free(p);
181  goto end;
182  }
183 
184  udphdr = (struct udp_hdr *)p->payload;
185 
186 #if LWIP_IPV4
187  /* is broadcast packet ? */
189 #endif /* LWIP_IPV4 */
190 
191  LWIP_DEBUGF(UDP_DEBUG, ("udp_input: received datagram of length %"U16_F"\n", p->tot_len));
192 
193  /* convert src and dest ports to host byte order */
194  src = ntohs(udphdr->src);
195  dest = ntohs(udphdr->dest);
196 
197  udp_debug_print(udphdr);
198 
199  /* print the UDP source and destination */
200  LWIP_DEBUGF(UDP_DEBUG, ("udp ("));
202  LWIP_DEBUGF(UDP_DEBUG, (", %"U16_F") <-- (", ntohs(udphdr->dest)));
204  LWIP_DEBUGF(UDP_DEBUG, (", %"U16_F")\n", ntohs(udphdr->src)));
205 
206 #if LWIP_DHCP
207  pcb = NULL;
208  /* when LWIP_DHCP is active, packets to DHCP_CLIENT_PORT may only be processed by
209  the dhcp module, no other UDP pcb may use the local UDP port DHCP_CLIENT_PORT */
210  if (dest == DHCP_CLIENT_PORT) {
211  /* all packets for DHCP_CLIENT_PORT not coming from DHCP_SERVER_PORT are dropped! */
212  if (src == DHCP_SERVER_PORT) {
213  if ((inp->dhcp != NULL) && (inp->dhcp->pcb != NULL)) {
214  /* accept the packet if
215  (- broadcast or directed to us) -> DHCP is link-layer-addressed, local ip is always ANY!
216  - inp->dhcp->pcb->remote == ANY or iphdr->src
217  (no need to check for IPv6 since the dhcp struct always uses IPv4) */
218  if (ip_addr_isany_val(inp->dhcp->pcb->remote_ip) ||
219  ip_addr_cmp(&inp->dhcp->pcb->remote_ip, ip_current_src_addr())) {
220  pcb = inp->dhcp->pcb;
221  }
222  }
223  }
224  } else
225 #endif /* LWIP_DHCP */
226  {
227  prev = NULL;
228  local_match = 0;
229  uncon_pcb = NULL;
230  /* Iterate through the UDP pcb list for a matching pcb.
231  * 'Perfect match' pcbs (connected to the remote port & ip address) are
232  * preferred. If no perfect match is found, the first unconnected pcb that
233  * matches the local port and ip address gets the datagram. */
234  for (pcb = udp_pcbs; pcb != NULL; pcb = pcb->next) {
235  local_match = 0;
236  /* print the PCB local and remote address */
237  LWIP_DEBUGF(UDP_DEBUG, ("pcb ("));
238  ip_addr_debug_print(UDP_DEBUG, &pcb->local_ip);
239  LWIP_DEBUGF(UDP_DEBUG, (", %"U16_F") <-- (", pcb->local_port));
240  ip_addr_debug_print(UDP_DEBUG, &pcb->remote_ip);
241  LWIP_DEBUGF(UDP_DEBUG, (", %"U16_F")\n", pcb->remote_port));
242 
243  /* compare PCB local addr+port to UDP destination addr+port */
244  if (pcb->local_port == dest) {
245  if (
246 #if LWIP_IPV6
247  (PCB_ISIPV6(pcb) && (ip_current_is_v6()) &&
248  (ip6_addr_isany(ip_2_ip6(&pcb->local_ip)) ||
249 #if LWIP_IPV6_MLD
250  ip6_addr_ismulticast(ip6_current_dest_addr()) ||
251 #endif /* LWIP_IPV6_MLD */
252  ip6_addr_cmp(ip_2_ip6(&pcb->local_ip), ip6_current_dest_addr())))
253 #endif /* LWIP_IPV6 */
254 #if LWIP_IPV4 && LWIP_IPV6
255  || (!PCB_ISIPV6(pcb) &&
256  (ip4_current_header() != NULL) &&
257 #endif /* LWIP_IPV4 && LWIP_IPV6 */
258 #if LWIP_IPV4
259 #if !LWIP_IPV6
260  (
261 #endif /* !LWIP_IPV6 */
262  ((!broadcast && ip_addr_isany(&pcb->local_ip)) ||
263  ip_addr_cmp(&pcb->local_ip, ip_current_dest_addr()) ||
264 #if LWIP_IGMP
265  (ip_addr_isany(&pcb->local_ip) && ip_addr_ismulticast(ip_current_dest_addr())) ||
266 #endif /* LWIP_IGMP */
268  (broadcast && ip_get_option(pcb, SOF_BROADCAST) &&
269  (ip_addr_isany(&pcb->local_ip) ||
270  ip_addr_netcmp(&pcb->local_ip, ip_current_dest_addr(), netif_ip4_netmask(inp))))))
271 #else /* IP_SOF_BROADCAST_RECV */
272  (broadcast &&
273  (ip_addr_isany(&pcb->local_ip) ||
274  ip_addr_netcmp(&pcb->local_ip, ip_current_dest_addr(), netif_ip4_netmask(inp))))))
275 #endif /* IP_SOF_BROADCAST_RECV */
276 #endif /* LWIP_IPV4 */
277  ) {
278  local_match = 1;
279  if ((uncon_pcb == NULL) &&
280  ((pcb->flags & UDP_FLAGS_CONNECTED) == 0)) {
281  /* the first unconnected matching PCB */
282  uncon_pcb = pcb;
283  }
284  }
285  }
286  /* compare PCB remote addr+port to UDP source addr+port */
287  if ((local_match != 0) &&
288  (pcb->remote_port == src) && IP_PCB_IPVER_INPUT_MATCH(pcb) &&
289  (ip_addr_isany_val(pcb->remote_ip) ||
290  ip_addr_cmp(&pcb->remote_ip, ip_current_src_addr()))) {
291  /* the first fully matching PCB */
292  if (prev != NULL) {
293  /* move the pcb to the front of udp_pcbs so that is
294  found faster next time */
295  prev->next = pcb->next;
296  pcb->next = udp_pcbs;
297  udp_pcbs = pcb;
298  } else {
299  UDP_STATS_INC(udp.cachehit);
300  }
301  break;
302  }
303  prev = pcb;
304  }
305  /* no fully matching pcb found? then look for an unconnected pcb */
306  if (pcb == NULL) {
307  pcb = uncon_pcb;
308  }
309  }
310 
311  /* Check checksum if this is a match or if it was directed at us. */
312  if (pcb != NULL) {
313  for_us = 1;
314  } else {
315 #if LWIP_IPV6
316  if (ip_current_is_v6()) {
317  for_us = netif_get_ip6_addr_match(inp, ip6_current_dest_addr()) >= 0;
318  }
319 #if LWIP_IPV4
320  else
321 #endif /* LWIP_IPV4 */
322 #endif /* LWIP_IPV6 */
323 #if LWIP_IPV4
324  {
325  for_us = ip4_addr_cmp(netif_ip4_addr(inp), ip4_current_dest_addr());
326  }
327 #endif /* LWIP_IPV4 */
328  }
329  if (for_us) {
330  LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE, ("udp_input: calculating checksum\n"));
331 #if CHECKSUM_CHECK_UDP
333 #if LWIP_UDPLITE
334  if (ip_current_header_proto() == IP_PROTO_UDPLITE) {
335  /* Do the UDP Lite checksum */
336  u16_t chklen = ntohs(udphdr->len);
337  if (chklen < sizeof(struct udp_hdr)) {
338  if (chklen == 0) {
339  /* For UDP-Lite, checksum length of 0 means checksum
340  over the complete packet (See RFC 3828 chap. 3.1) */
341  chklen = p->tot_len;
342  } else {
343  /* At least the UDP-Lite header must be covered by the
344  checksum! (Again, see RFC 3828 chap. 3.1) */
345  goto chkerr;
346  }
347  }
349  p->tot_len, chklen,
351  goto chkerr;
352  }
353  } else
354 #endif /* LWIP_UDPLITE */
355  {
356  if (udphdr->chksum != 0) {
359  ip_current_dest_addr()) != 0) {
360  goto chkerr;
361  }
362  }
363  }
364  }
365 #endif /* CHECKSUM_CHECK_UDP */
366  if (pbuf_header(p, -UDP_HLEN)) {
367  /* Can we cope with this failing? Just assert for now */
368  LWIP_ASSERT("pbuf_header failed\n", 0);
369  UDP_STATS_INC(udp.drop);
370  MIB2_STATS_INC(mib2.udpinerrors);
371  pbuf_free(p);
372  goto end;
373  }
374  if (pcb != NULL) {
375  MIB2_STATS_INC(mib2.udpindatagrams);
376 #if SO_REUSE && SO_REUSE_RXTOALL
377  if ((
378 #if LWIP_IPV4
379  broadcast ||
380 #endif /* LWIP_IPV4 */
381 #if LWIP_IPV6
382  ip6_addr_ismulticast(ip6_current_dest_addr()) ||
383 #endif /* LWIP_IPV6 */
386  /* pass broadcast- or multicast packets to all multicast pcbs
387  if SOF_REUSEADDR is set on the first match */
388  struct udp_pcb *mpcb;
389  u8_t p_header_changed = 0;
390  s16_t hdrs_len = (s16_t)(ip_current_header_tot_len() + UDP_HLEN);
391  for (mpcb = udp_pcbs; mpcb != NULL; mpcb = mpcb->next) {
392  if (mpcb != pcb) {
393  /* compare PCB local addr+port to UDP destination addr+port */
394  if ((mpcb->local_port == dest) &&
395 #if LWIP_IPV6
396  ((PCB_ISIPV6(mpcb) &&
397  (ip6_addr_ismulticast(ip6_current_dest_addr()) ||
398  ip6_addr_cmp(ip_2_ip6(&mpcb->local_ip), ip6_current_dest_addr()))) ||
399  (!PCB_ISIPV6(mpcb) &&
400 #else /* LWIP_IPV6 */
401  ((
402 #endif /* LWIP_IPV6 */
403  ((
404 #if LWIP_IPV4
405  !broadcast &&
406 #endif /* LWIP_IPV4 */
407  ip_addr_isany(&mpcb->local_ip)) ||
408  ip_addr_cmp(&mpcb->local_ip, ip_current_dest_addr()) ||
409 #if LWIP_IGMP
410  (ip_addr_isany(&pcb->local_ip) && ip_addr_ismulticast(ip_current_dest_addr())) ||
411 #endif /* LWIP_IGMP */
413  (
414 #if LWIP_IPV4
415  broadcast &&
416 #endif /* LWIP_IPV4 */
417  ip_get_option(mpcb, SOF_BROADCAST)))))) {
418 #else /* IP_SOF_BROADCAST_RECV */
419  (broadcast))))) {
420 #endif /* IP_SOF_BROADCAST_RECV */
421  /* pass a copy of the packet to all local matches */
422  if (mpcb->recv != NULL) {
423  struct pbuf *q;
424  /* for that, move payload to IP header again */
425  if (p_header_changed == 0) {
426  pbuf_header_force(p, hdrs_len);
427  p_header_changed = 1;
428  }
430  if (q != NULL) {
431  err_t err = pbuf_copy(q, p);
432  if (err == ERR_OK) {
433  /* move payload to UDP data */
434  pbuf_header(q, -hdrs_len);
435  mpcb->recv(mpcb->recv_arg, mpcb, q, ip_current_src_addr(), src);
436  }
437  }
438  }
439  }
440  }
441  }
442  if (p_header_changed) {
443  /* and move payload to UDP data again */
444  pbuf_header(p, -hdrs_len);
445  }
446  }
447 #endif /* SO_REUSE && SO_REUSE_RXTOALL */
448  /* callback */
449  if (pcb->recv != NULL) {
450  /* now the recv function is responsible for freeing p */
451  pcb->recv(pcb->recv_arg, pcb, p, ip_current_src_addr(), src);
452  } else {
453  /* no recv function registered? then we have to free the pbuf! */
454  pbuf_free(p);
455  goto end;
456  }
457  } else {
458  LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE, ("udp_input: not for us.\n"));
459 
460 #if LWIP_ICMP || LWIP_ICMP6
461  /* No match was found, send ICMP destination port unreachable unless
462  destination address was broadcast/multicast. */
463  if (
464 #if LWIP_IPV4
465  !broadcast && !ip_addr_ismulticast(ip_current_dest_addr())
466 #if LWIP_IPV6
467  &&
468 #endif /* LWIP_IPV6 */
469 #endif /* LWIP_IPV4 */
470 #if LWIP_IPV6
471  !ip6_addr_ismulticast(ip6_current_dest_addr())
472 #endif /* LWIP_IPV6 */
473  ) {
474  /* move payload pointer back to ip header */
476  icmp_port_unreach(ip_current_is_v6(), p);
477  }
478 #endif /* LWIP_ICMP || LWIP_ICMP6 */
479  UDP_STATS_INC(udp.proterr);
480  UDP_STATS_INC(udp.drop);
481  MIB2_STATS_INC(mib2.udpnoports);
482  pbuf_free(p);
483  }
484  } else {
485  pbuf_free(p);
486  }
487 end:
488  PERF_STOP("udp_input");
489  return;
490 #if CHECKSUM_CHECK_UDP
491 chkerr:
493  ("udp_input: UDP (or UDP Lite) datagram discarded due to failing checksum\n"));
494  UDP_STATS_INC(udp.chkerr);
495  UDP_STATS_INC(udp.drop);
496  MIB2_STATS_INC(mib2.udpinerrors);
497  pbuf_free(p);
498  PERF_STOP("udp_input");
499 #endif /* CHECKSUM_CHECK_UDP */
500 }
501 
520 err_t
521 udp_send(struct udp_pcb *pcb, struct pbuf *p)
522 {
523  /* send to the packet using remote ip and port stored in the pcb */
524  return udp_sendto(pcb, p, &pcb->remote_ip, pcb->remote_port);
525 }
526 
527 #if LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP
528 
530 err_t
531 udp_send_chksum(struct udp_pcb *pcb, struct pbuf *p,
532  u8_t have_chksum, u16_t chksum)
533 {
534  /* send to the packet using remote ip and port stored in the pcb */
535  return udp_sendto_chksum(pcb, p, &pcb->remote_ip, pcb->remote_port,
536  have_chksum, chksum);
537 }
538 #endif /* LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP */
539 
557 err_t
558 udp_sendto(struct udp_pcb *pcb, struct pbuf *p,
559  const ip_addr_t *dst_ip, u16_t dst_port)
560 {
561 #if LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP
562  return udp_sendto_chksum(pcb, p, dst_ip, dst_port, 0, 0);
563 }
564 
566 err_t
567 udp_sendto_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_ip,
568  u16_t dst_port, u8_t have_chksum, u16_t chksum)
569 {
570 #endif /* LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP */
571  struct netif *netif;
572  const ip_addr_t *dst_ip_route = dst_ip;
573 
574  if ((pcb == NULL) || !IP_ADDR_PCB_VERSION_MATCH(pcb, dst_ip)) {
575  return ERR_VAL;
576  }
577 
578  LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE, ("udp_send\n"));
579 
580 #if LWIP_IPV6 || (LWIP_IPV4 && LWIP_MULTICAST_TX_OPTIONS)
581  if (ip_addr_ismulticast(dst_ip_route)) {
582 #if LWIP_IPV6
583  if (PCB_ISIPV6(pcb)) {
584  /* For multicast, find a netif based on source address. */
585  dst_ip_route = &pcb->local_ip;
586  } else
587 #endif /* LWIP_IPV6 */
588  {
589 #if LWIP_IPV4 && LWIP_MULTICAST_TX_OPTIONS
590  /* IPv4 does not use source-based routing by default, so we use an
591  administratively selected interface for multicast by default.
592  However, this can be overridden by setting an interface address
593  in pcb->multicast_ip that is used for routing. */
594  if (!ip_addr_isany_val(pcb->multicast_ip) &&
595  !ip4_addr_cmp(ip_2_ip4(&pcb->multicast_ip), IP4_ADDR_BROADCAST)) {
596  dst_ip_route = & pcb->multicast_ip;
597  }
598 #endif /* LWIP_IPV4 && LWIP_MULTICAST_TX_OPTIONS */
599  }
600  }
601 #endif /* LWIP_IPV6 || (LWIP_IPV4 && LWIP_MULTICAST_TX_OPTIONS) */
602 
603  /* find the outgoing network interface for this packet */
604  netif = ip_route(PCB_ISIPV6(pcb), &pcb->local_ip, dst_ip_route);
605 
606  /* no outgoing network interface could be found? */
607  if (netif == NULL) {
608  LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("udp_send: No route to "));
610  LWIP_DEBUGF(UDP_DEBUG, ("\n"));
611  UDP_STATS_INC(udp.rterr);
612  return ERR_RTE;
613  }
614 #if LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP
615  return udp_sendto_if_chksum(pcb, p, dst_ip, dst_port, netif, have_chksum, chksum);
616 #else /* LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP */
617  return udp_sendto_if(pcb, p, dst_ip, dst_port, netif);
618 #endif /* LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP */
619 }
620 
640 err_t
641 udp_sendto_if(struct udp_pcb *pcb, struct pbuf *p,
642  const ip_addr_t *dst_ip, u16_t dst_port, struct netif *netif)
643 {
644 #if LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP
645  return udp_sendto_if_chksum(pcb, p, dst_ip, dst_port, netif, 0, 0);
646 }
647 
649 err_t
650 udp_sendto_if_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_ip,
651  u16_t dst_port, struct netif *netif, u8_t have_chksum,
652  u16_t chksum)
653 {
654 #endif /* LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP */
655  const ip_addr_t *src_ip;
656 
657  if ((pcb == NULL) || !IP_ADDR_PCB_VERSION_MATCH(pcb, dst_ip)) {
658  return ERR_VAL;
659  }
660 
661  /* PCB local address is IP_ANY_ADDR? */
662 #if LWIP_IPV6
663  if (PCB_ISIPV6(pcb)) {
664  if (ip6_addr_isany(ip_2_ip6(&pcb->local_ip))) {
665  src_ip = ip6_select_source_address(netif, ip_2_ip6(dst_ip));
666  if (src_ip == NULL) {
667  /* No suitable source address was found. */
668  return ERR_RTE;
669  }
670  } else {
671  /* use UDP PCB local IPv6 address as source address, if still valid. */
672  if (netif_get_ip6_addr_match(netif, ip_2_ip6(&pcb->local_ip)) < 0) {
673  /* Address isn't valid anymore. */
674  return ERR_RTE;
675  }
676  src_ip = &pcb->local_ip;
677  }
678  }
679 #endif /* LWIP_IPV6 */
680 #if LWIP_IPV4 && LWIP_IPV6
681  else
682 #endif /* LWIP_IPV4 && LWIP_IPV6 */
683 #if LWIP_IPV4
684  if (ip4_addr_isany(ip_2_ip4(&pcb->local_ip))) {
685  /* use outgoing network interface IP address as source address */
686  src_ip = netif_ip_addr4(netif);
687  } else {
688  /* check if UDP PCB local IP address is correct
689  * this could be an old address if netif->ip_addr has changed */
690  if (!ip4_addr_cmp(ip_2_ip4(&(pcb->local_ip)), netif_ip4_addr(netif))) {
691  /* local_ip doesn't match, drop the packet */
692  return ERR_VAL;
693  }
694  /* use UDP PCB local IP address as source address */
695  src_ip = &pcb->local_ip;
696  }
697 #endif /* LWIP_IPV4 */
698 #if LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP
699  return udp_sendto_if_src_chksum(pcb, p, dst_ip, dst_port, netif, have_chksum, chksum, src_ip);
700 #else /* LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP */
701  return udp_sendto_if_src(pcb, p, dst_ip, dst_port, netif, src_ip);
702 #endif /* LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP */
703 }
704 
706 err_t
707 udp_sendto_if_src(struct udp_pcb *pcb, struct pbuf *p,
708  const ip_addr_t *dst_ip, u16_t dst_port, struct netif *netif, const ip_addr_t *src_ip)
709 {
710 #if LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP
711  return udp_sendto_if_src_chksum(pcb, p, dst_ip, dst_port, netif, 0, 0, src_ip);
712 }
713 
715 err_t
716 udp_sendto_if_src_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_ip,
717  u16_t dst_port, struct netif *netif, u8_t have_chksum,
718  u16_t chksum, const ip_addr_t *src_ip)
719 {
720 #endif /* LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP */
721  struct udp_hdr *udphdr;
722  err_t err;
723  struct pbuf *q; /* q will be sent down the stack */
724  u8_t ip_proto;
725  u8_t ttl;
726 
727  if ((pcb == NULL) || !IP_ADDR_PCB_VERSION_MATCH(pcb, src_ip) ||
728  !IP_ADDR_PCB_VERSION_MATCH(pcb, dst_ip)) {
729  return ERR_VAL;
730  }
731 
732 #if LWIP_IPV4 && IP_SOF_BROADCAST
733  /* broadcast filter? */
734  if (!ip_get_option(pcb, SOF_BROADCAST) &&
735 #if LWIP_IPV6
736  !PCB_ISIPV6(pcb) &&
737 #endif /* LWIP_IPV6 */
738  ip_addr_isbroadcast(dst_ip, netif)) {
740  ("udp_sendto_if: SOF_BROADCAST not enabled on pcb %p\n", (void *)pcb));
741  return ERR_VAL;
742  }
743 #endif /* LWIP_IPV4 && IP_SOF_BROADCAST */
744 
745  /* if the PCB is not yet bound to a port, bind it here */
746  if (pcb->local_port == 0) {
747  LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE, ("udp_send: not yet bound to a port, binding now\n"));
748  err = udp_bind(pcb, &pcb->local_ip, pcb->local_port);
749  if (err != ERR_OK) {
750  LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_SERIOUS, ("udp_send: forced port bind failed\n"));
751  return err;
752  }
753  }
754 
755  /* not enough space to add an UDP header to first pbuf in given p chain? */
756  if (pbuf_header(p, UDP_HLEN)) {
757  /* allocate header in a separate new pbuf */
758  q = pbuf_alloc(PBUF_IP, UDP_HLEN, PBUF_RAM);
759  /* new header pbuf could not be allocated? */
760  if (q == NULL) {
761  LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_SERIOUS, ("udp_send: could not allocate header\n"));
762  return ERR_MEM;
763  }
764  if (p->tot_len != 0) {
765  /* chain header q in front of given pbuf p (only if p contains data) */
766  pbuf_chain(q, p);
767  }
768  /* first pbuf q points to header pbuf */
770  ("udp_send: added header pbuf %p before given pbuf %p\n", (void *)q, (void *)p));
771  } else {
772  /* adding space for header within p succeeded */
773  /* first pbuf q equals given pbuf */
774  q = p;
775  LWIP_DEBUGF(UDP_DEBUG, ("udp_send: added header in given pbuf %p\n", (void *)p));
776  }
777  LWIP_ASSERT("check that first pbuf can hold struct udp_hdr",
778  (q->len >= sizeof(struct udp_hdr)));
779  /* q now represents the packet to be sent */
780  udphdr = (struct udp_hdr *)q->payload;
781  udphdr->src = htons(pcb->local_port);
782  udphdr->dest = htons(dst_port);
783  /* in UDP, 0 checksum means 'no checksum' */
784  udphdr->chksum = 0x0000;
785 
786  /* Multicast Loop? */
787 #if (LWIP_IPV4 && LWIP_MULTICAST_TX_OPTIONS) || (LWIP_IPV6 && LWIP_IPV6_MLD)
788  if (((pcb->flags & UDP_FLAGS_MULTICAST_LOOP) != 0) && ip_addr_ismulticast(dst_ip)) {
790  }
791 #endif /* (LWIP_IPV4 && LWIP_MULTICAST_TX_OPTIONS) || (LWIP_IPV6 && LWIP_IPV6_MLD) */
792 
793  LWIP_DEBUGF(UDP_DEBUG, ("udp_send: sending datagram of length %"U16_F"\n", q->tot_len));
794 
795 #if LWIP_UDPLITE
796  /* UDP Lite protocol? */
797  if (pcb->flags & UDP_FLAGS_UDPLITE) {
798  u16_t chklen, chklen_hdr;
799  LWIP_DEBUGF(UDP_DEBUG, ("udp_send: UDP LITE packet length %"U16_F"\n", q->tot_len));
800  /* set UDP message length in UDP header */
801  chklen_hdr = chklen = pcb->chksum_len_tx;
802  if ((chklen < sizeof(struct udp_hdr)) || (chklen > q->tot_len)) {
803  if (chklen != 0) {
804  LWIP_DEBUGF(UDP_DEBUG, ("udp_send: UDP LITE pcb->chksum_len is illegal: %"U16_F"\n", chklen));
805  }
806  /* For UDP-Lite, checksum length of 0 means checksum
807  over the complete packet. (See RFC 3828 chap. 3.1)
808  At least the UDP-Lite header must be covered by the
809  checksum, therefore, if chksum_len has an illegal
810  value, we generate the checksum over the complete
811  packet to be safe. */
812  chklen_hdr = 0;
813  chklen = q->tot_len;
814  }
815  udphdr->len = htons(chklen_hdr);
816  /* calculate checksum */
817 #if CHECKSUM_GEN_UDP
818  IF__NETIF_CHECKSUM_ENABLED(netif, NETIF_CHECKSUM_GEN_UDP) {
819 #if LWIP_CHECKSUM_ON_COPY
820  if (have_chksum) {
821  chklen = UDP_HLEN;
822  }
823 #endif /* LWIP_CHECKSUM_ON_COPY */
824  udphdr->chksum = ip_chksum_pseudo_partial(q, IP_PROTO_UDPLITE,
825  q->tot_len, chklen, src_ip, dst_ip);
826 #if LWIP_CHECKSUM_ON_COPY
827  if (have_chksum) {
828  u32_t acc;
829  acc = udphdr->chksum + (u16_t)~(chksum);
830  udphdr->chksum = FOLD_U32T(acc);
831  }
832 #endif /* LWIP_CHECKSUM_ON_COPY */
833 
834  /* chksum zero must become 0xffff, as zero means 'no checksum' */
835  if (udphdr->chksum == 0x0000) {
836  udphdr->chksum = 0xffff;
837  }
838  }
839 #endif /* CHECKSUM_GEN_UDP */
840 
841  ip_proto = IP_PROTO_UDPLITE;
842  } else
843 #endif /* LWIP_UDPLITE */
844  { /* UDP */
845  LWIP_DEBUGF(UDP_DEBUG, ("udp_send: UDP packet length %"U16_F"\n", q->tot_len));
846  udphdr->len = htons(q->tot_len);
847  /* calculate checksum */
848 #if CHECKSUM_GEN_UDP
849  IF__NETIF_CHECKSUM_ENABLED(netif, NETIF_CHECKSUM_GEN_UDP) {
850  /* Checksum is mandatory over IPv6. */
851  if (PCB_ISIPV6(pcb) || (pcb->flags & UDP_FLAGS_NOCHKSUM) == 0) {
852  u16_t udpchksum;
853 #if LWIP_CHECKSUM_ON_COPY
854  if (have_chksum) {
855  u32_t acc;
856  udpchksum = ip_chksum_pseudo_partial(q, IP_PROTO_UDP,
857  q->tot_len, UDP_HLEN, src_ip, dst_ip);
858  acc = udpchksum + (u16_t)~(chksum);
859  udpchksum = FOLD_U32T(acc);
860  } else
861 #endif /* LWIP_CHECKSUM_ON_COPY */
862  {
863  udpchksum = ip_chksum_pseudo(q, IP_PROTO_UDP, q->tot_len,
864  src_ip, dst_ip);
865  }
866 
867  /* chksum zero must become 0xffff, as zero means 'no checksum' */
868  if (udpchksum == 0x0000) {
869  udpchksum = 0xffff;
870  }
871  udphdr->chksum = udpchksum;
872  }
873  }
874 #endif /* CHECKSUM_GEN_UDP */
875  ip_proto = IP_PROTO_UDP;
876  }
877 
878  /* Determine TTL to use */
879 #if LWIP_MULTICAST_TX_OPTIONS
880  ttl = (ip_addr_ismulticast(dst_ip) ? pcb->mcast_ttl : pcb->ttl);
881 #else /* LWIP_MULTICAST_TX_OPTIONS */
882  ttl = pcb->ttl;
883 #endif /* LWIP_MULTICAST_TX_OPTIONS */
884 
885  LWIP_DEBUGF(UDP_DEBUG, ("udp_send: UDP checksum 0x%04"X16_F"\n", udphdr->chksum));
886  LWIP_DEBUGF(UDP_DEBUG, ("udp_send: ip_output_if (,,,,0x%02"X16_F",)\n", (u16_t)ip_proto));
887  /* output to IP */
888  NETIF_SET_HWADDRHINT(netif, &(pcb->addr_hint));
889  err = ip_output_if_src(PCB_ISIPV6(pcb), q, src_ip, dst_ip, ttl, pcb->tos, ip_proto, netif);
890  NETIF_SET_HWADDRHINT(netif, NULL);
891 
892  /* TODO: must this be increased even if error occurred? */
893  MIB2_STATS_INC(mib2.udpoutdatagrams);
894 
895  /* did we chain a separate header pbuf earlier? */
896  if (q != p) {
897  /* free the header pbuf */
898  pbuf_free(q);
899  q = NULL;
900  /* p is still referenced by the caller, and will live on */
901  }
902 
903  UDP_STATS_INC(udp.xmit);
904  return err;
905 }
906 
926 err_t
927 udp_bind(struct udp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port)
928 {
929  struct udp_pcb *ipcb;
930  u8_t rebind;
931 
932  if ((pcb == NULL) || !IP_ADDR_PCB_VERSION_MATCH(pcb, ipaddr)) {
933  return ERR_VAL;
934  }
935 
936  LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE, ("udp_bind(ipaddr = "));
938  LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE, (", port = %"U16_F")\n", port));
939 
940  rebind = 0;
941  /* Check for double bind and rebind of the same pcb */
942  for (ipcb = udp_pcbs; ipcb != NULL; ipcb = ipcb->next) {
943  /* is this UDP PCB already on active list? */
944  if (pcb == ipcb) {
945  rebind = 1;
946  break;
947  }
948  }
949 
950  /* no port specified? */
951  if (port == 0) {
952  port = udp_new_port();
953  if (port == 0) {
954  /* no more ports available in local range */
955  LWIP_DEBUGF(UDP_DEBUG, ("udp_bind: out of free UDP ports\n"));
956  return ERR_USE;
957  }
958  } else {
959  for (ipcb = udp_pcbs; ipcb != NULL; ipcb = ipcb->next) {
960  if (pcb != ipcb) {
961  /* By default, we don't allow to bind to a port that any other udp
962  PCB is already bound to, unless *all* PCBs with that port have tha
963  REUSEADDR flag set. */
964 #if SO_REUSE
965  if (!ip_get_option(pcb, SOF_REUSEADDR) ||
967 #endif /* SO_REUSE */
968  {
969  /* port matches that of PCB in list and REUSEADDR not set -> reject */
970  if ((ipcb->local_port == port) && IP_PCB_IPVER_EQ(pcb, ipcb) &&
971  /* IP address matches, or one is IP_ADDR_ANY? */
972  (ip_addr_isany(&ipcb->local_ip) ||
973  ip_addr_isany(ipaddr) ||
974  ip_addr_cmp(&ipcb->local_ip, ipaddr))) {
975  /* other PCB already binds to this local IP and port */
977  ("udp_bind: local port %"U16_F" already bound by another pcb\n", port));
978  return ERR_USE;
979  }
980  }
981  }
982  }
983  }
984 
985  ip_addr_set_ipaddr(&pcb->local_ip, ipaddr);
986 
987  pcb->local_port = port;
988  mib2_udp_bind(pcb);
989  /* pcb not active yet? */
990  if (rebind == 0) {
991  /* place the PCB on the active list if not already there */
992  pcb->next = udp_pcbs;
993  udp_pcbs = pcb;
994  }
995  LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("udp_bind: bound to "));
997  LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, (", port %"U16_F")\n", pcb->local_port));
998  return ERR_OK;
999 }
1000 
1018 err_t
1019 udp_connect(struct udp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port)
1020 {
1021  struct udp_pcb *ipcb;
1022 
1023  if ((pcb == NULL) || !IP_ADDR_PCB_VERSION_MATCH(pcb, ipaddr)) {
1024  return ERR_VAL;
1025  }
1026 
1027  if (pcb->local_port == 0) {
1028  err_t err = udp_bind(pcb, &pcb->local_ip, pcb->local_port);
1029  if (err != ERR_OK) {
1030  return err;
1031  }
1032  }
1033 
1034  ip_addr_set_ipaddr(&pcb->remote_ip, ipaddr);
1035  pcb->remote_port = port;
1036  pcb->flags |= UDP_FLAGS_CONNECTED;
1038 #ifdef LWIP_UDP_TODO
1039 #if LWIP_IPV6
1040  if (!PCB_ISIPV6(pcb))
1041 #endif /* LWIP_IPV6 */
1042  {
1043  /* Nail down local IP for netconn_addr()/getsockname() */
1044  if (ip_addr_isany(&pcb->local_ip) && !ip_addr_isany(&pcb->remote_ip)) {
1045  struct netif *netif;
1046 
1047  if ((netif = ip_route(PCB_ISIPV6(pcb), (const ip_addr_t*)NULL, &pcb->remote_ip)) == NULL) {
1048  LWIP_DEBUGF(UDP_DEBUG, ("udp_connect: No route to %s\n", ipaddr_ntoa(&pcb->remote_ip)));
1049  UDP_STATS_INC(udp.rterr);
1050  return ERR_RTE;
1051  }
1055  ip_addr_set(&pcb->local_ip, ip_netif_get_local_ip(PCB_ISIPV6(pcb), netif, &pcb->remote_ip));
1056  } else if (ip_addr_isany(&pcb->remote_ip)) {
1057  ip_addr_set_any(PCB_ISIPV6(pcb), &pcb->local_ip);
1058  }
1059  }
1060 #endif
1061  LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("udp_connect: connected to "));
1063  &pcb->remote_ip);
1064  LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, (", port %"U16_F")\n", pcb->remote_port));
1065 
1066  /* Insert UDP PCB into the list of active UDP PCBs. */
1067  for (ipcb = udp_pcbs; ipcb != NULL; ipcb = ipcb->next) {
1068  if (pcb == ipcb) {
1069  /* already on the list, just return */
1070  return ERR_OK;
1071  }
1072  }
1073  /* PCB not yet on the list, add PCB now */
1074  pcb->next = udp_pcbs;
1075  udp_pcbs = pcb;
1076  return ERR_OK;
1077 }
1078 
1084 void
1085 udp_disconnect(struct udp_pcb *pcb)
1086 {
1087  /* reset remote address association */
1088  ip_addr_set_any(PCB_ISIPV6(pcb), &pcb->remote_ip);
1089  pcb->remote_port = 0;
1090  /* mark PCB as unconnected */
1091  pcb->flags &= ~UDP_FLAGS_CONNECTED;
1092 }
1093 
1103 void
1104 udp_recv(struct udp_pcb *pcb, udp_recv_fn recv, void *recv_arg)
1105 {
1106  /* remember recv() callback and user data */
1107  pcb->recv = recv;
1108  pcb->recv_arg = recv_arg;
1109 }
1110 
1119 void
1120 udp_remove(struct udp_pcb *pcb)
1121 {
1122  struct udp_pcb *pcb2;
1123 
1124  mib2_udp_unbind(pcb);
1125  /* pcb to be removed is first in list? */
1126  if (udp_pcbs == pcb) {
1127  /* make list start at 2nd pcb */
1128  udp_pcbs = udp_pcbs->next;
1129  /* pcb not 1st in list */
1130  } else {
1131  for (pcb2 = udp_pcbs; pcb2 != NULL; pcb2 = pcb2->next) {
1132  /* find pcb in udp_pcbs list */
1133  if (pcb2->next != NULL && pcb2->next == pcb) {
1134  /* remove pcb from list */
1135  pcb2->next = pcb->next;
1136  break;
1137  }
1138  }
1139  }
1140  memp_free(MEMP_UDP_PCB, pcb);
1141 }
1142 
1151 struct udp_pcb *
1152 udp_new(void)
1153 {
1154  struct udp_pcb *pcb;
1155  pcb = (struct udp_pcb *)memp_malloc(MEMP_UDP_PCB);
1156  /* could allocate UDP PCB? */
1157  if (pcb != NULL) {
1158  /* UDP Lite: by initializing to all zeroes, chksum_len is set to 0
1159  * which means checksum is generated over the whole datagram per default
1160  * (recommended as default by RFC 3828). */
1161  /* initialize PCB to all zeroes */
1162  memset(pcb, 0, sizeof(struct udp_pcb));
1163  pcb->ttl = UDP_TTL;
1164 #if LWIP_MULTICAST_TX_OPTIONS
1165  pcb->mcast_ttl = UDP_TTL;
1166 #endif /* LWIP_MULTICAST_TX_OPTIONS */
1167  }
1168  return pcb;
1169 }
1170 
1171 #if LWIP_IPV6
1172 
1180 struct udp_pcb *
1181 udp_new_ip6(void)
1182 {
1183  struct udp_pcb *pcb;
1184  pcb = udp_new();
1185 #if LWIP_IPV4
1186  ip_set_v6(pcb, 1);
1187 #endif /* LWIP_IPV4 */
1188  return pcb;
1189 }
1190 #endif /* LWIP_IPV6 */
1191 
1192 #if LWIP_IPV4
1193 
1198 void udp_netif_ipv4_addr_changed(const ip4_addr_t* old_addr, const ip4_addr_t* new_addr)
1199 {
1200  struct udp_pcb* upcb;
1201 
1202  if (!ip4_addr_isany(new_addr)) {
1203  for (upcb = udp_pcbs; upcb != NULL; upcb = upcb->next) {
1204  /* Is this an IPv4 pcb? */
1205  if (!IP_IS_V6_VAL(upcb->local_ip)) {
1206  /* PCB bound to current local interface address? */
1207  if (!ip4_addr_isany(ip_2_ip4(&upcb->local_ip)) &&
1208  ip4_addr_cmp(ip_2_ip4(&upcb->local_ip), old_addr)) {
1209  /* The PCB is bound to the old ipaddr and
1210  * is set to bound to the new one instead */
1211  ip_addr_copy_from_ip4(upcb->local_ip, *new_addr);
1212  }
1213  }
1214  }
1215  }
1216 }
1217 #endif /* LWIP_IPV4 */
1218 
1219 #if UDP_DEBUG
1220 
1225 void
1226 udp_debug_print(struct udp_hdr *udphdr)
1227 {
1228  LWIP_DEBUGF(UDP_DEBUG, ("UDP header:\n"));
1229  LWIP_DEBUGF(UDP_DEBUG, ("+-------------------------------+\n"));
1230  LWIP_DEBUGF(UDP_DEBUG, ("| %5"U16_F" | %5"U16_F" | (src port, dest port)\n",
1231  ntohs(udphdr->src), ntohs(udphdr->dest)));
1232  LWIP_DEBUGF(UDP_DEBUG, ("+-------------------------------+\n"));
1233  LWIP_DEBUGF(UDP_DEBUG, ("| %5"U16_F" | 0x%04"X16_F" | (len, chksum)\n",
1234  ntohs(udphdr->len), ntohs(udphdr->chksum)));
1235  LWIP_DEBUGF(UDP_DEBUG, ("+-------------------------------+\n"));
1236 }
1237 #endif /* UDP_DEBUG */
1238 
1239 #endif /* LWIP_UDP */
1240 
u16_t ip_chksum_pseudo(struct pbuf *p, u8_t proto, u16_t proto_len, const ip_addr_t *src, const ip_addr_t *dest)
Definition: inet_chksum.c:382
#define MIB2_STATS_INC(x)
Definition: stats.h:407
#define ip_current_netif()
Definition: ip.h:154
#define ERR_USE
Definition: err.h:60
#define LWIP_DBG_LEVEL_SERIOUS
Definition: debug.h:47
#define SOF_REUSEADDR
Definition: ip.h:118
#define ip_addr_isany(ipaddr)
Definition: ip_addr.h:215
#define IP_SOF_BROADCAST_RECV
Definition: opt.h:657
#define IP_PCB_IPVER_EQ(pcb1, pcb2)
Definition: ip.h:87
#define ip_current_header_tot_len()
Definition: ip.h:160
#define ip_2_ip6(ipaddr)
Definition: ip_addr.h:200
#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
#define FOLD_U32T(u)
Definition: inet_chksum.h:53
#define icmp_port_unreach(isipv6, pbuf)
Definition: icmp.h:130
u8_t pbuf_header(struct pbuf *p, s16_t header_size_increment)
Definition: pbuf.c:603
#define ERR_VAL
Definition: err.h:58
#define LWIP_IPV4
Definition: opt.h:549
#define PERF_STOP(x)
Definition: def.h:42
#define htons(x)
Definition: def.h:86
#define IF__NETIF_CHECKSUM_ENABLED(netif, chksumflag)
Definition: netif.h:313
#define ip_addr_isbroadcast(addr, netif)
Definition: ip_addr.h:219
void memp_free(memp_t type, void *mem)
Definition: memp.c:399
u16_t len
Definition: pbuf.h:125
struct pbuf * pbuf_alloc(pbuf_layer layer, u16_t length, pbuf_type type)
Definition: pbuf.c:199
#define ip_current_dest_addr()
Definition: ip.h:238
#define LWIP_RAND()
Definition: cc.h:95
#define mib2_udp_unbind(pcb)
Definition: snmp.h:174
Definition: pbuf.h:77
#define mib2_udp_bind(pcb)
Definition: snmp.h:173
#define ip_addr_ismulticast(ipaddr)
Definition: ip_addr.h:220
#define IP_ADDR_PCB_VERSION_MATCH(addr, pcb)
Definition: ip_addr.h:153
#define LWIP_DBG_STATE
Definition: debug.h:59
u8_t flags
Definition: pbuf.h:131
#define PBUF_FLAG_MCASTLOOP
Definition: pbuf.h:100
#define LWIP_IPV6_MLD
Definition: opt.h:2487
#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
Definition: pbuf.h:68
err_t pbuf_copy(struct pbuf *p_to, struct pbuf *p_from)
Definition: pbuf.c:886
#define PCB_ISIPV6(pcb)
Definition: ip.h:89
#define ip_addr_netcmp(addr1, addr2, mask)
Definition: ip_addr.h:213
unsigned long u32_t
Definition: cc.h:42
#define ERR_RTE
Definition: err.h:56
void pbuf_chain(struct pbuf *h, struct pbuf *t)
Definition: pbuf.c:820
#define ERR_OK
Definition: err.h:52
#define ip_addr_set_any(is_ipv6, ipaddr)
Definition: ip_addr.h:209
u16_t tot_len
Definition: pbuf.h:122
#define NETIF_SET_HWADDRHINT(netif, hint)
Definition: netif.h:411
#define IP_IS_V6_VAL(ipaddr)
Definition: ip_addr.h:196
#define LWIP_DBG_TRACE
Definition: debug.h:57
Definition: pbuf.h:108
s8_t err_t
Definition: err.h:47
#define ip_addr_cmp(addr1, addr2)
Definition: ip_addr.h:214
#define LWIP_ASSERT(message, assertion)
Definition: debug.h:70
#define ip_addr_set(dest, src)
Definition: ip_addr.h:205
Definition: netif.h:182
#define ip_addr_debug_print(debug, ipaddr)
Definition: ip_addr.h:221
#define LWIP_IGMP
Definition: opt.h:853
#define UDP_DEBUG
Definition: opt.h:2950
#define UDP_TTL
Definition: lwipopts.h:142
#define SOF_BROADCAST
Definition: ip.h:120
#define ipaddr_ntoa(ipaddr)
Definition: ip_addr.h:223
#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
unsigned char u8_t
Definition: cc.h:38
u16_t ip_chksum_pseudo_partial(struct pbuf *p, u8_t proto, u16_t proto_len, u16_t chksum_len, const ip_addr_t *src, const ip_addr_t *dest)
Definition: inet_chksum.c:529
#define IP_PCB_IPVER_INPUT_MATCH(pcb)
Definition: ip.h:88
ip6_addr_t ip_addr_t
Definition: ip_addr.h:194
#define IP_PROTO_UDPLITE
Definition: ip.h:52
Definition: pbuf.h:65
void * memp_malloc(memp_t type)
Definition: memp.c:303
#define LWIP_DEBUGF(debug, message)
Definition: debug.h:113
#define CHECKSUM_CHECK_UDP
Definition: lwipopts.h:179
#define ERR_MEM
Definition: err.h:53
#define LWIP_UNUSED_ARG(x)
Definition: arch.h:89
#define LWIP_IPV6
Definition: opt.h:2444
#define ntohs(x)
Definition: def.h:87
unsigned short u16_t
Definition: cc.h:40
void * payload
Definition: pbuf.h:113
#define ip_get_option(pcb, opt)
Definition: ip.h:241
#define X16_F
Definition: cc.h:50
#define ip_addr_set_ipaddr(dest, src)
Definition: ip_addr.h:206
#define UDP_STATS_INC(x)
Definition: stats.h:270