UbixOS  2.0
udp.c
Go to the documentation of this file.
1 
13 /*
14  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
15  * All rights reserved.
16  *
17  * Redistribution and use in source and binary forms, with or without modification,
18  * are permitted provided that the following conditions are met:
19  *
20  * 1. Redistributions of source code must retain the above copyright notice,
21  * this list of conditions and the following disclaimer.
22  * 2. Redistributions in binary form must reproduce the above copyright notice,
23  * this list of conditions and the following disclaimer in the documentation
24  * and/or other materials provided with the distribution.
25  * 3. The name of the author may not be used to endorse or promote products
26  * derived from this software without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
29  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
30  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
31  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
32  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
33  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
36  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
37  * OF SUCH DAMAGE.
38  *
39  * This file is part of the lwIP TCP/IP stack.
40  *
41  * Author: Adam Dunkels <adam@sics.se>
42  *
43  */
44 
45 /* @todo Check the use of '(struct udp_pcb).chksum_len_rx'!
46  */
47 
48 #include "net/opt.h"
49 
50 #if LWIP_UDP /* don't build if not configured for use in lwipopts.h */
51 
52 #include "net/udp.h"
53 #include "net/def.h"
54 #include "net/memp.h"
55 #include "net/inet_chksum.h"
56 #include "net/ip_addr.h"
57 #include "net/ip6.h"
58 #include "net/ip6_addr.h"
59 #include "net/netif.h"
60 #include "net/icmp.h"
61 #include "net/icmp6.h"
62 #include "net/stats.h"
63 #include "net/snmp.h"
64 #include "net/dhcp.h"
65 
66 #include <string.h>
67 
68 #ifndef UDP_LOCAL_PORT_RANGE_START
69 /* From http://www.iana.org/assignments/port-numbers:
70  "The Dynamic and/or Private Ports are those from 49152 through 65535" */
71 #define UDP_LOCAL_PORT_RANGE_START 0xc000
72 #define UDP_LOCAL_PORT_RANGE_END 0xffff
73 #define UDP_ENSURE_LOCAL_PORT_RANGE(port) ((u16_t)(((port) & ~UDP_LOCAL_PORT_RANGE_START) + UDP_LOCAL_PORT_RANGE_START))
74 #endif
75 
76 /* last local UDP port */
77 static u16_t udp_port = UDP_LOCAL_PORT_RANGE_START;
78 
79 /* The list of UDP PCBs */
80 /* exported in udp.h (was static) */
81 struct udp_pcb *udp_pcbs;
82 
86 void
87 udp_init(void)
88 {
89 #if LWIP_RANDOMIZE_INITIAL_LOCAL_PORTS && defined(LWIP_RAND)
90  udp_port = UDP_ENSURE_LOCAL_PORT_RANGE(LWIP_RAND());
91 #endif /* LWIP_RANDOMIZE_INITIAL_LOCAL_PORTS && defined(LWIP_RAND) */
92 }
93 
99 static u16_t
100 udp_new_port(void)
101 {
102  u16_t n = 0;
103  struct udp_pcb *pcb;
104 
105 again:
106  if (udp_port++ == UDP_LOCAL_PORT_RANGE_END) {
107  udp_port = UDP_LOCAL_PORT_RANGE_START;
108  }
109  /* Check all PCBs. */
110  for (pcb = udp_pcbs; pcb != NULL; pcb = pcb->next) {
111  if (pcb->local_port == udp_port) {
112  if (++n > (UDP_LOCAL_PORT_RANGE_END - UDP_LOCAL_PORT_RANGE_START)) {
113  return 0;
114  }
115  goto again;
116  }
117  }
118  return udp_port;
119 }
120 
129 static u8_t
130 udp_input_local_match(struct udp_pcb *pcb, struct netif *inp, u8_t broadcast)
131 {
132  LWIP_UNUSED_ARG(inp); /* in IPv6 only case */
133  LWIP_UNUSED_ARG(broadcast); /* in IPv6 only case */
134 
135  /* Dual-stack: PCBs listening to any IP type also listen to any IP address */
136  if (IP_IS_ANY_TYPE_VAL(pcb->local_ip)) {
137 #if LWIP_IPV4 && IP_SOF_BROADCAST_RECV
138  if ((broadcast != 0) && !ip_get_option(pcb, SOF_BROADCAST)) {
139  return 0;
140  }
141 #endif /* LWIP_IPV4 && IP_SOF_BROADCAST_RECV */
142  return 1;
143  }
144 
145  /* Only need to check PCB if incoming IP version matches PCB IP version */
147 #if LWIP_IPV4
148  /* Special case: IPv4 broadcast: all or broadcasts in my subnet
149  * Note: broadcast variable can only be 1 if it is an IPv4 broadcast */
150  if (broadcast != 0) {
151 #if IP_SOF_BROADCAST_RECV
152  if (ip_get_option(pcb, SOF_BROADCAST))
153 #endif /* IP_SOF_BROADCAST_RECV */
154  {
155  if (ip4_addr_isany(ip_2_ip4(&pcb->local_ip)) ||
156  ((ip4_current_dest_addr()->addr == IPADDR_BROADCAST)) ||
157  ip4_addr_netcmp(ip_2_ip4(&pcb->local_ip), ip4_current_dest_addr(), netif_ip4_netmask(inp))) {
158  return 1;
159  }
160  }
161  } else
162 #endif /* LWIP_IPV4 */
163  /* Handle IPv4 and IPv6: all or exact match */
164  if (ip_addr_isany(&pcb->local_ip) || ip_addr_cmp(&pcb->local_ip, ip_current_dest_addr())) {
165  return 1;
166  }
167  }
168 
169  return 0;
170 }
171 
184 void
185 udp_input(struct pbuf *p, struct netif *inp)
186 {
187  struct udp_hdr *udphdr;
188  struct udp_pcb *pcb, *prev;
189  struct udp_pcb *uncon_pcb;
190  u16_t src, dest;
191  u8_t broadcast;
192  u8_t for_us = 0;
193 
194  LWIP_UNUSED_ARG(inp);
195 
196  PERF_START;
197 
198  UDP_STATS_INC(udp.recv);
199 
200  /* Check minimum length (UDP header) */
201  if (p->len < UDP_HLEN) {
202  /* drop short packets */
204  ("udp_input: short UDP datagram (%"U16_F" bytes) discarded\n", p->tot_len));
205  UDP_STATS_INC(udp.lenerr);
206  UDP_STATS_INC(udp.drop);
207  MIB2_STATS_INC(mib2.udpinerrors);
208  pbuf_free(p);
209  goto end;
210  }
211 
212  udphdr = (struct udp_hdr *)p->payload;
213 
214  /* is broadcast packet ? */
216 
217  LWIP_DEBUGF(UDP_DEBUG, ("udp_input: received datagram of length %"U16_F"\n", p->tot_len));
218 
219  /* convert src and dest ports to host byte order */
220  src = lwip_ntohs(udphdr->src);
221  dest = lwip_ntohs(udphdr->dest);
222 
223  udp_debug_print(udphdr);
224 
225  /* print the UDP source and destination */
226  LWIP_DEBUGF(UDP_DEBUG, ("udp ("));
228  LWIP_DEBUGF(UDP_DEBUG, (", %"U16_F") <-- (", lwip_ntohs(udphdr->dest)));
230  LWIP_DEBUGF(UDP_DEBUG, (", %"U16_F")\n", lwip_ntohs(udphdr->src)));
231 
232  pcb = NULL;
233  prev = NULL;
234  uncon_pcb = NULL;
235  /* Iterate through the UDP pcb list for a matching pcb.
236  * 'Perfect match' pcbs (connected to the remote port & ip address) are
237  * preferred. If no perfect match is found, the first unconnected pcb that
238  * matches the local port and ip address gets the datagram. */
239  for (pcb = udp_pcbs; pcb != NULL; pcb = pcb->next) {
240  /* print the PCB local and remote address */
241  LWIP_DEBUGF(UDP_DEBUG, ("pcb ("));
242  ip_addr_debug_print(UDP_DEBUG, &pcb->local_ip);
243  LWIP_DEBUGF(UDP_DEBUG, (", %"U16_F") <-- (", pcb->local_port));
244  ip_addr_debug_print(UDP_DEBUG, &pcb->remote_ip);
245  LWIP_DEBUGF(UDP_DEBUG, (", %"U16_F")\n", pcb->remote_port));
246 
247  /* compare PCB local addr+port to UDP destination addr+port */
248  if ((pcb->local_port == dest) &&
249  (udp_input_local_match(pcb, inp, broadcast) != 0)) {
250  if (((pcb->flags & UDP_FLAGS_CONNECTED) == 0) &&
251  ((uncon_pcb == NULL)
252 #if SO_REUSE
253  /* prefer specific IPs over cath-all */
254  || !ip_addr_isany(&pcb->local_ip)
255 #endif /* SO_REUSE */
256  )) {
257  /* the first unconnected matching PCB */
258  uncon_pcb = pcb;
259  }
260 
261  /* compare PCB remote addr+port to UDP source addr+port */
262  if ((pcb->remote_port == src) &&
263  (ip_addr_isany_val(pcb->remote_ip) ||
264  ip_addr_cmp(&pcb->remote_ip, ip_current_src_addr()))) {
265  /* the first fully matching PCB */
266  if (prev != NULL) {
267  /* move the pcb to the front of udp_pcbs so that is
268  found faster next time */
269  prev->next = pcb->next;
270  pcb->next = udp_pcbs;
271  udp_pcbs = pcb;
272  } else {
273  UDP_STATS_INC(udp.cachehit);
274  }
275  break;
276  }
277  }
278 
279  prev = pcb;
280  }
281  /* no fully matching pcb found? then look for an unconnected pcb */
282  if (pcb == NULL) {
283  pcb = uncon_pcb;
284  }
285 
286  /* Check checksum if this is a match or if it was directed at us. */
287  if (pcb != NULL) {
288  for_us = 1;
289  } else {
290 #if LWIP_IPV6
291  if (ip_current_is_v6()) {
292  for_us = netif_get_ip6_addr_match(inp, ip6_current_dest_addr()) >= 0;
293  }
294 #endif /* LWIP_IPV6 */
295 #if LWIP_IPV4
296  if (!ip_current_is_v6()) {
297  for_us = ip4_addr_cmp(netif_ip4_addr(inp), ip4_current_dest_addr());
298  }
299 #endif /* LWIP_IPV4 */
300  }
301 
302  if (for_us) {
303  LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE, ("udp_input: calculating checksum\n"));
304 #if CHECKSUM_CHECK_UDP
306 #if LWIP_UDPLITE
307  if (ip_current_header_proto() == IP_PROTO_UDPLITE) {
308  /* Do the UDP Lite checksum */
309  u16_t chklen = lwip_ntohs(udphdr->len);
310  if (chklen < sizeof(struct udp_hdr)) {
311  if (chklen == 0) {
312  /* For UDP-Lite, checksum length of 0 means checksum
313  over the complete packet (See RFC 3828 chap. 3.1) */
314  chklen = p->tot_len;
315  } else {
316  /* At least the UDP-Lite header must be covered by the
317  checksum! (Again, see RFC 3828 chap. 3.1) */
318  goto chkerr;
319  }
320  }
322  p->tot_len, chklen,
324  goto chkerr;
325  }
326  } else
327 #endif /* LWIP_UDPLITE */
328  {
329  if (udphdr->chksum != 0) {
332  ip_current_dest_addr()) != 0) {
333  goto chkerr;
334  }
335  }
336  }
337  }
338 #endif /* CHECKSUM_CHECK_UDP */
339  if (pbuf_header(p, -UDP_HLEN)) {
340  /* Can we cope with this failing? Just assert for now */
341  LWIP_ASSERT("pbuf_header failed\n", 0);
342  UDP_STATS_INC(udp.drop);
343  MIB2_STATS_INC(mib2.udpinerrors);
344  pbuf_free(p);
345  goto end;
346  }
347 
348  if (pcb != NULL) {
349  MIB2_STATS_INC(mib2.udpindatagrams);
350 #if SO_REUSE && SO_REUSE_RXTOALL
351  if (ip_get_option(pcb, SOF_REUSEADDR) &&
352  (broadcast || ip_addr_ismulticast(ip_current_dest_addr()))) {
353  /* pass broadcast- or multicast packets to all multicast pcbs
354  if SOF_REUSEADDR is set on the first match */
355  struct udp_pcb *mpcb;
356  u8_t p_header_changed = 0;
357  s16_t hdrs_len = (s16_t)(ip_current_header_tot_len() + UDP_HLEN);
358  for (mpcb = udp_pcbs; mpcb != NULL; mpcb = mpcb->next) {
359  if (mpcb != pcb) {
360  /* compare PCB local addr+port to UDP destination addr+port */
361  if ((mpcb->local_port == dest) &&
362  (udp_input_local_match(mpcb, inp, broadcast) != 0)) {
363  /* pass a copy of the packet to all local matches */
364  if (mpcb->recv != NULL) {
365  struct pbuf *q;
366  /* for that, move payload to IP header again */
367  if (p_header_changed == 0) {
368  pbuf_header_force(p, hdrs_len);
369  p_header_changed = 1;
370  }
372  if (q != NULL) {
373  err_t err = pbuf_copy(q, p);
374  if (err == ERR_OK) {
375  /* move payload to UDP data */
376  pbuf_header(q, -hdrs_len);
377  mpcb->recv(mpcb->recv_arg, mpcb, q, ip_current_src_addr(), src);
378  }
379  }
380  }
381  }
382  }
383  }
384  if (p_header_changed) {
385  /* and move payload to UDP data again */
386  pbuf_header(p, -hdrs_len);
387  }
388  }
389 #endif /* SO_REUSE && SO_REUSE_RXTOALL */
390  /* callback */
391  if (pcb->recv != NULL) {
392  /* now the recv function is responsible for freeing p */
393  pcb->recv(pcb->recv_arg, pcb, p, ip_current_src_addr(), src);
394  } else {
395  /* no recv function registered? then we have to free the pbuf! */
396  pbuf_free(p);
397  goto end;
398  }
399  } else {
400  LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE, ("udp_input: not for us.\n"));
401 
402 #if LWIP_ICMP || LWIP_ICMP6
403  /* No match was found, send ICMP destination port unreachable unless
404  destination address was broadcast/multicast. */
405  if (!broadcast && !ip_addr_ismulticast(ip_current_dest_addr())) {
406  /* move payload pointer back to ip header */
408  icmp_port_unreach(ip_current_is_v6(), p);
409  }
410 #endif /* LWIP_ICMP || LWIP_ICMP6 */
411  UDP_STATS_INC(udp.proterr);
412  UDP_STATS_INC(udp.drop);
413  MIB2_STATS_INC(mib2.udpnoports);
414  pbuf_free(p);
415  }
416  } else {
417  pbuf_free(p);
418  }
419 end:
420  PERF_STOP("udp_input");
421  return;
422 #if CHECKSUM_CHECK_UDP
423 chkerr:
425  ("udp_input: UDP (or UDP Lite) datagram discarded due to failing checksum\n"));
426  UDP_STATS_INC(udp.chkerr);
427  UDP_STATS_INC(udp.drop);
428  MIB2_STATS_INC(mib2.udpinerrors);
429  pbuf_free(p);
430  PERF_STOP("udp_input");
431 #endif /* CHECKSUM_CHECK_UDP */
432 }
433 
454 err_t
455 udp_send(struct udp_pcb *pcb, struct pbuf *p)
456 {
457  if ((pcb == NULL) || IP_IS_ANY_TYPE_VAL(pcb->remote_ip)) {
458  return ERR_VAL;
459  }
460 
461  /* send to the packet using remote ip and port stored in the pcb */
462  return udp_sendto(pcb, p, &pcb->remote_ip, pcb->remote_port);
463 }
464 
465 #if LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP
466 
469 err_t
470 udp_send_chksum(struct udp_pcb *pcb, struct pbuf *p,
471  u8_t have_chksum, u16_t chksum)
472 {
473  if ((pcb == NULL) || IP_IS_ANY_TYPE_VAL(pcb->remote_ip)) {
474  return ERR_VAL;
475  }
476 
477  /* send to the packet using remote ip and port stored in the pcb */
478  return udp_sendto_chksum(pcb, p, &pcb->remote_ip, pcb->remote_port,
479  have_chksum, chksum);
480 }
481 #endif /* LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP */
482 
501 err_t
502 udp_sendto(struct udp_pcb *pcb, struct pbuf *p,
503  const ip_addr_t *dst_ip, u16_t dst_port)
504 {
505 #if LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP
506  return udp_sendto_chksum(pcb, p, dst_ip, dst_port, 0, 0);
507 }
508 
511 err_t
512 udp_sendto_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_ip,
513  u16_t dst_port, u8_t have_chksum, u16_t chksum)
514 {
515 #endif /* LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP */
516  struct netif *netif;
517  const ip_addr_t *dst_ip_route = dst_ip;
518 
519  if ((pcb == NULL) || (dst_ip == NULL) || !IP_ADDR_PCB_VERSION_MATCH(pcb, dst_ip)) {
520  return ERR_VAL;
521  }
522 
523  LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE, ("udp_send\n"));
524 
525 #if LWIP_IPV6 || (LWIP_IPV4 && LWIP_MULTICAST_TX_OPTIONS)
526  if (ip_addr_ismulticast(dst_ip_route)) {
527 #if LWIP_IPV6
528  if (IP_IS_V6(dst_ip)) {
529  /* For multicast, find a netif based on source address. */
530  dst_ip_route = &pcb->local_ip;
531  } else
532 #endif /* LWIP_IPV6 */
533  {
534 #if LWIP_IPV4 && LWIP_MULTICAST_TX_OPTIONS
535  /* IPv4 does not use source-based routing by default, so we use an
536  administratively selected interface for multicast by default.
537  However, this can be overridden by setting an interface address
538  in pcb->multicast_ip that is used for routing. */
539  if (!ip_addr_isany_val(pcb->multicast_ip) &&
540  !ip4_addr_cmp(ip_2_ip4(&pcb->multicast_ip), IP4_ADDR_BROADCAST)) {
541  dst_ip_route = &pcb->multicast_ip;
542  }
543 #endif /* LWIP_IPV4 && LWIP_MULTICAST_TX_OPTIONS */
544  }
545  }
546 #endif /* LWIP_IPV6 || (LWIP_IPV4 && LWIP_MULTICAST_TX_OPTIONS) */
547 
548  /* find the outgoing network interface for this packet */
549  if(IP_IS_ANY_TYPE_VAL(pcb->local_ip)) {
550  /* Don't call ip_route() with IP_ANY_TYPE */
551  netif = ip_route(IP46_ADDR_ANY(IP_GET_TYPE(dst_ip_route)), dst_ip_route);
552  } else {
553  netif = ip_route(&pcb->local_ip, dst_ip_route);
554  }
555 
556  /* no outgoing network interface could be found? */
557  if (netif == NULL) {
558  LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("udp_send: No route to "));
560  LWIP_DEBUGF(UDP_DEBUG, ("\n"));
561  UDP_STATS_INC(udp.rterr);
562  return ERR_RTE;
563  }
564 #if LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP
565  return udp_sendto_if_chksum(pcb, p, dst_ip, dst_port, netif, have_chksum, chksum);
566 #else /* LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP */
567  return udp_sendto_if(pcb, p, dst_ip, dst_port, netif);
568 #endif /* LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP */
569 }
570 
591 err_t
592 udp_sendto_if(struct udp_pcb *pcb, struct pbuf *p,
593  const ip_addr_t *dst_ip, u16_t dst_port, struct netif *netif)
594 {
595 #if LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP
596  return udp_sendto_if_chksum(pcb, p, dst_ip, dst_port, netif, 0, 0);
597 }
598 
600 err_t
601 udp_sendto_if_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_ip,
602  u16_t dst_port, struct netif *netif, u8_t have_chksum,
603  u16_t chksum)
604 {
605 #endif /* LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP */
606  const ip_addr_t *src_ip;
607 
608  if ((pcb == NULL) || (dst_ip == NULL) || !IP_ADDR_PCB_VERSION_MATCH(pcb, dst_ip)) {
609  return ERR_VAL;
610  }
611 
612  /* PCB local address is IP_ANY_ADDR? */
613 #if LWIP_IPV6
614  if (IP_IS_V6(dst_ip)) {
615  if (ip6_addr_isany(ip_2_ip6(&pcb->local_ip))) {
616  src_ip = ip6_select_source_address(netif, ip_2_ip6(dst_ip));
617  if (src_ip == NULL) {
618  /* No suitable source address was found. */
619  return ERR_RTE;
620  }
621  } else {
622  /* use UDP PCB local IPv6 address as source address, if still valid. */
623  if (netif_get_ip6_addr_match(netif, ip_2_ip6(&pcb->local_ip)) < 0) {
624  /* Address isn't valid anymore. */
625  return ERR_RTE;
626  }
627  src_ip = &pcb->local_ip;
628  }
629  }
630 #endif /* LWIP_IPV6 */
631 #if LWIP_IPV4 && LWIP_IPV6
632  else
633 #endif /* LWIP_IPV4 && LWIP_IPV6 */
634 #if LWIP_IPV4
635  if (ip4_addr_isany(ip_2_ip4(&pcb->local_ip)) ||
636  ip4_addr_ismulticast(ip_2_ip4(&pcb->local_ip))) {
637  /* if the local_ip is any or multicast
638  * use the outgoing network interface IP address as source address */
639  src_ip = netif_ip_addr4(netif);
640  } else {
641  /* check if UDP PCB local IP address is correct
642  * this could be an old address if netif->ip_addr has changed */
643  if (!ip4_addr_cmp(ip_2_ip4(&(pcb->local_ip)), netif_ip4_addr(netif))) {
644  /* local_ip doesn't match, drop the packet */
645  return ERR_RTE;
646  }
647  /* use UDP PCB local IP address as source address */
648  src_ip = &pcb->local_ip;
649  }
650 #endif /* LWIP_IPV4 */
651 #if LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP
652  return udp_sendto_if_src_chksum(pcb, p, dst_ip, dst_port, netif, have_chksum, chksum, src_ip);
653 #else /* LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP */
654  return udp_sendto_if_src(pcb, p, dst_ip, dst_port, netif, src_ip);
655 #endif /* LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP */
656 }
657 
660 err_t
661 udp_sendto_if_src(struct udp_pcb *pcb, struct pbuf *p,
662  const ip_addr_t *dst_ip, u16_t dst_port, struct netif *netif, const ip_addr_t *src_ip)
663 {
664 #if LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP
665  return udp_sendto_if_src_chksum(pcb, p, dst_ip, dst_port, netif, 0, 0, src_ip);
666 }
667 
669 err_t
670 udp_sendto_if_src_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_ip,
671  u16_t dst_port, struct netif *netif, u8_t have_chksum,
672  u16_t chksum, const ip_addr_t *src_ip)
673 {
674 #endif /* LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP */
675  struct udp_hdr *udphdr;
676  err_t err;
677  struct pbuf *q; /* q will be sent down the stack */
678  u8_t ip_proto;
679  u8_t ttl;
680 
681  if ((pcb == NULL) || (dst_ip == NULL) || !IP_ADDR_PCB_VERSION_MATCH(pcb, src_ip) ||
682  !IP_ADDR_PCB_VERSION_MATCH(pcb, dst_ip)) {
683  return ERR_VAL;
684  }
685 
686 #if LWIP_IPV4 && IP_SOF_BROADCAST
687  /* broadcast filter? */
688  if (!ip_get_option(pcb, SOF_BROADCAST) &&
689 #if LWIP_IPV6
690  IP_IS_V4(dst_ip) &&
691 #endif /* LWIP_IPV6 */
692  ip_addr_isbroadcast(dst_ip, netif)) {
694  ("udp_sendto_if: SOF_BROADCAST not enabled on pcb %p\n", (void *)pcb));
695  return ERR_VAL;
696  }
697 #endif /* LWIP_IPV4 && IP_SOF_BROADCAST */
698 
699  /* if the PCB is not yet bound to a port, bind it here */
700  if (pcb->local_port == 0) {
701  LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE, ("udp_send: not yet bound to a port, binding now\n"));
702  err = udp_bind(pcb, &pcb->local_ip, pcb->local_port);
703  if (err != ERR_OK) {
704  LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_SERIOUS, ("udp_send: forced port bind failed\n"));
705  return err;
706  }
707  }
708 
709  /* not enough space to add an UDP header to first pbuf in given p chain? */
710  if (pbuf_header(p, UDP_HLEN)) {
711  /* allocate header in a separate new pbuf */
713  /* new header pbuf could not be allocated? */
714  if (q == NULL) {
715  LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_SERIOUS, ("udp_send: could not allocate header\n"));
716  return ERR_MEM;
717  }
718  if (p->tot_len != 0) {
719  /* chain header q in front of given pbuf p (only if p contains data) */
720  pbuf_chain(q, p);
721  }
722  /* first pbuf q points to header pbuf */
724  ("udp_send: added header pbuf %p before given pbuf %p\n", (void *)q, (void *)p));
725  } else {
726  /* adding space for header within p succeeded */
727  /* first pbuf q equals given pbuf */
728  q = p;
729  LWIP_DEBUGF(UDP_DEBUG, ("udp_send: added header in given pbuf %p\n", (void *)p));
730  }
731  LWIP_ASSERT("check that first pbuf can hold struct udp_hdr",
732  (q->len >= sizeof(struct udp_hdr)));
733  /* q now represents the packet to be sent */
734  udphdr = (struct udp_hdr *)q->payload;
735  udphdr->src = lwip_htons(pcb->local_port);
736  udphdr->dest = lwip_htons(dst_port);
737  /* in UDP, 0 checksum means 'no checksum' */
738  udphdr->chksum = 0x0000;
739 
740  /* Multicast Loop? */
741 #if (LWIP_IPV4 && LWIP_MULTICAST_TX_OPTIONS) || (LWIP_IPV6 && LWIP_IPV6_MLD)
742  if (((pcb->flags & UDP_FLAGS_MULTICAST_LOOP) != 0) && ip_addr_ismulticast(dst_ip)) {
744  }
745 #endif /* (LWIP_IPV4 && LWIP_MULTICAST_TX_OPTIONS) || (LWIP_IPV6 && LWIP_IPV6_MLD) */
746 
747  LWIP_DEBUGF(UDP_DEBUG, ("udp_send: sending datagram of length %"U16_F"\n", q->tot_len));
748 
749 #if LWIP_UDPLITE
750  /* UDP Lite protocol? */
751  if (pcb->flags & UDP_FLAGS_UDPLITE) {
752  u16_t chklen, chklen_hdr;
753  LWIP_DEBUGF(UDP_DEBUG, ("udp_send: UDP LITE packet length %"U16_F"\n", q->tot_len));
754  /* set UDP message length in UDP header */
755  chklen_hdr = chklen = pcb->chksum_len_tx;
756  if ((chklen < sizeof(struct udp_hdr)) || (chklen > q->tot_len)) {
757  if (chklen != 0) {
758  LWIP_DEBUGF(UDP_DEBUG, ("udp_send: UDP LITE pcb->chksum_len is illegal: %"U16_F"\n", chklen));
759  }
760  /* For UDP-Lite, checksum length of 0 means checksum
761  over the complete packet. (See RFC 3828 chap. 3.1)
762  At least the UDP-Lite header must be covered by the
763  checksum, therefore, if chksum_len has an illegal
764  value, we generate the checksum over the complete
765  packet to be safe. */
766  chklen_hdr = 0;
767  chklen = q->tot_len;
768  }
769  udphdr->len = lwip_htons(chklen_hdr);
770  /* calculate checksum */
771 #if CHECKSUM_GEN_UDP
772  IF__NETIF_CHECKSUM_ENABLED(netif, NETIF_CHECKSUM_GEN_UDP) {
773 #if LWIP_CHECKSUM_ON_COPY
774  if (have_chksum) {
775  chklen = UDP_HLEN;
776  }
777 #endif /* LWIP_CHECKSUM_ON_COPY */
778  udphdr->chksum = ip_chksum_pseudo_partial(q, IP_PROTO_UDPLITE,
779  q->tot_len, chklen, src_ip, dst_ip);
780 #if LWIP_CHECKSUM_ON_COPY
781  if (have_chksum) {
782  u32_t acc;
783  acc = udphdr->chksum + (u16_t)~(chksum);
784  udphdr->chksum = FOLD_U32T(acc);
785  }
786 #endif /* LWIP_CHECKSUM_ON_COPY */
787 
788  /* chksum zero must become 0xffff, as zero means 'no checksum' */
789  if (udphdr->chksum == 0x0000) {
790  udphdr->chksum = 0xffff;
791  }
792  }
793 #endif /* CHECKSUM_GEN_UDP */
794 
795  ip_proto = IP_PROTO_UDPLITE;
796  } else
797 #endif /* LWIP_UDPLITE */
798  { /* UDP */
799  LWIP_DEBUGF(UDP_DEBUG, ("udp_send: UDP packet length %"U16_F"\n", q->tot_len));
800  udphdr->len = lwip_htons(q->tot_len);
801  /* calculate checksum */
802 #if CHECKSUM_GEN_UDP
803  IF__NETIF_CHECKSUM_ENABLED(netif, NETIF_CHECKSUM_GEN_UDP) {
804  /* Checksum is mandatory over IPv6. */
805  if (IP_IS_V6(dst_ip) || (pcb->flags & UDP_FLAGS_NOCHKSUM) == 0) {
806  u16_t udpchksum;
807 #if LWIP_CHECKSUM_ON_COPY
808  if (have_chksum) {
809  u32_t acc;
810  udpchksum = ip_chksum_pseudo_partial(q, IP_PROTO_UDP,
811  q->tot_len, UDP_HLEN, src_ip, dst_ip);
812  acc = udpchksum + (u16_t)~(chksum);
813  udpchksum = FOLD_U32T(acc);
814  } else
815 #endif /* LWIP_CHECKSUM_ON_COPY */
816  {
817  udpchksum = ip_chksum_pseudo(q, IP_PROTO_UDP, q->tot_len,
818  src_ip, dst_ip);
819  }
820 
821  /* chksum zero must become 0xffff, as zero means 'no checksum' */
822  if (udpchksum == 0x0000) {
823  udpchksum = 0xffff;
824  }
825  udphdr->chksum = udpchksum;
826  }
827  }
828 #endif /* CHECKSUM_GEN_UDP */
829  ip_proto = IP_PROTO_UDP;
830  }
831 
832  /* Determine TTL to use */
833 #if LWIP_MULTICAST_TX_OPTIONS
834  ttl = (ip_addr_ismulticast(dst_ip) ? udp_get_multicast_ttl(pcb) : pcb->ttl);
835 #else /* LWIP_MULTICAST_TX_OPTIONS */
836  ttl = pcb->ttl;
837 #endif /* LWIP_MULTICAST_TX_OPTIONS */
838 
839  LWIP_DEBUGF(UDP_DEBUG, ("udp_send: UDP checksum 0x%04"X16_F"\n", udphdr->chksum));
840  LWIP_DEBUGF(UDP_DEBUG, ("udp_send: ip_output_if (,,,,0x%02"X16_F",)\n", (u16_t)ip_proto));
841  /* output to IP */
842  NETIF_SET_HWADDRHINT(netif, &(pcb->addr_hint));
843  err = ip_output_if_src(q, src_ip, dst_ip, ttl, pcb->tos, ip_proto, netif);
845 
846  /* @todo: must this be increased even if error occurred? */
847  MIB2_STATS_INC(mib2.udpoutdatagrams);
848 
849  /* did we chain a separate header pbuf earlier? */
850  if (q != p) {
851  /* free the header pbuf */
852  pbuf_free(q);
853  q = NULL;
854  /* p is still referenced by the caller, and will live on */
855  }
856 
857  UDP_STATS_INC(udp.xmit);
858  return err;
859 }
860 
881 err_t
882 udp_bind(struct udp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port)
883 {
884  struct udp_pcb *ipcb;
885  u8_t rebind;
886 
887 #if LWIP_IPV4
888  /* Don't propagate NULL pointer (IPv4 ANY) to subsequent functions */
889  if (ipaddr == NULL) {
890  ipaddr = IP4_ADDR_ANY;
891  }
892 #endif /* LWIP_IPV4 */
893 
894  /* still need to check for ipaddr == NULL in IPv6 only case */
895  if ((pcb == NULL) || (ipaddr == NULL)) {
896  return ERR_VAL;
897  }
898 
899  LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE, ("udp_bind(ipaddr = "));
901  LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE, (", port = %"U16_F")\n", port));
902 
903  rebind = 0;
904  /* Check for double bind and rebind of the same pcb */
905  for (ipcb = udp_pcbs; ipcb != NULL; ipcb = ipcb->next) {
906  /* is this UDP PCB already on active list? */
907  if (pcb == ipcb) {
908  rebind = 1;
909  break;
910  }
911  }
912 
913  /* no port specified? */
914  if (port == 0) {
915  port = udp_new_port();
916  if (port == 0) {
917  /* no more ports available in local range */
918  LWIP_DEBUGF(UDP_DEBUG, ("udp_bind: out of free UDP ports\n"));
919  return ERR_USE;
920  }
921  } else {
922  for (ipcb = udp_pcbs; ipcb != NULL; ipcb = ipcb->next) {
923  if (pcb != ipcb) {
924  /* By default, we don't allow to bind to a port that any other udp
925  PCB is already bound to, unless *all* PCBs with that port have tha
926  REUSEADDR flag set. */
927 #if SO_REUSE
928  if (!ip_get_option(pcb, SOF_REUSEADDR) ||
930 #endif /* SO_REUSE */
931  {
932  /* port matches that of PCB in list and REUSEADDR not set -> reject */
933  if ((ipcb->local_port == port) &&
934  /* IP address matches? */
935  ip_addr_cmp(&ipcb->local_ip, ipaddr)) {
936  /* other PCB already binds to this local IP and port */
938  ("udp_bind: local port %"U16_F" already bound by another pcb\n", port));
939  return ERR_USE;
940  }
941  }
942  }
943  }
944  }
945 
946  ip_addr_set_ipaddr(&pcb->local_ip, ipaddr);
947 
948  pcb->local_port = port;
949  mib2_udp_bind(pcb);
950  /* pcb not active yet? */
951  if (rebind == 0) {
952  /* place the PCB on the active list if not already there */
953  pcb->next = udp_pcbs;
954  udp_pcbs = pcb;
955  }
956  LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("udp_bind: bound to "));
958  LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, (", port %"U16_F")\n", pcb->local_port));
959  return ERR_OK;
960 }
961 
980 err_t
981 udp_connect(struct udp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port)
982 {
983  struct udp_pcb *ipcb;
984 
985  if ((pcb == NULL) || (ipaddr == NULL)) {
986  return ERR_VAL;
987  }
988 
989  if (pcb->local_port == 0) {
990  err_t err = udp_bind(pcb, &pcb->local_ip, pcb->local_port);
991  if (err != ERR_OK) {
992  return err;
993  }
994  }
995 
996  ip_addr_set_ipaddr(&pcb->remote_ip, ipaddr);
997  pcb->remote_port = port;
998  pcb->flags |= UDP_FLAGS_CONNECTED;
999 
1000  LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("udp_connect: connected to "));
1002  &pcb->remote_ip);
1003  LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, (", port %"U16_F")\n", pcb->remote_port));
1004 
1005  /* Insert UDP PCB into the list of active UDP PCBs. */
1006  for (ipcb = udp_pcbs; ipcb != NULL; ipcb = ipcb->next) {
1007  if (pcb == ipcb) {
1008  /* already on the list, just return */
1009  return ERR_OK;
1010  }
1011  }
1012  /* PCB not yet on the list, add PCB now */
1013  pcb->next = udp_pcbs;
1014  udp_pcbs = pcb;
1015  return ERR_OK;
1016 }
1017 
1024 void
1025 udp_disconnect(struct udp_pcb *pcb)
1026 {
1027  /* reset remote address association */
1028 #if LWIP_IPV4 && LWIP_IPV6
1029  if (IP_IS_ANY_TYPE_VAL(pcb->local_ip)) {
1030  ip_addr_copy(pcb->remote_ip, *IP_ANY_TYPE);
1031  } else {
1032 #endif
1033  ip_addr_set_any(IP_IS_V6_VAL(pcb->remote_ip), &pcb->remote_ip);
1034 #if LWIP_IPV4 && LWIP_IPV6
1035  }
1036 #endif
1037  pcb->remote_port = 0;
1038  /* mark PCB as unconnected */
1039  pcb->flags &= ~UDP_FLAGS_CONNECTED;
1040 }
1041 
1052 void
1053 udp_recv(struct udp_pcb *pcb, udp_recv_fn recv, void *recv_arg)
1054 {
1055  /* remember recv() callback and user data */
1056  pcb->recv = recv;
1057  pcb->recv_arg = recv_arg;
1058 }
1059 
1069 void
1070 udp_remove(struct udp_pcb *pcb)
1071 {
1072  struct udp_pcb *pcb2;
1073 
1074  mib2_udp_unbind(pcb);
1075  /* pcb to be removed is first in list? */
1076  if (udp_pcbs == pcb) {
1077  /* make list start at 2nd pcb */
1078  udp_pcbs = udp_pcbs->next;
1079  /* pcb not 1st in list */
1080  } else {
1081  for (pcb2 = udp_pcbs; pcb2 != NULL; pcb2 = pcb2->next) {
1082  /* find pcb in udp_pcbs list */
1083  if (pcb2->next != NULL && pcb2->next == pcb) {
1084  /* remove pcb from list */
1085  pcb2->next = pcb->next;
1086  break;
1087  }
1088  }
1089  }
1090  memp_free(MEMP_UDP_PCB, pcb);
1091 }
1092 
1102 struct udp_pcb *
1103 udp_new(void)
1104 {
1105  struct udp_pcb *pcb;
1106  pcb = (struct udp_pcb *)memp_malloc(MEMP_UDP_PCB);
1107  /* could allocate UDP PCB? */
1108  if (pcb != NULL) {
1109  /* UDP Lite: by initializing to all zeroes, chksum_len is set to 0
1110  * which means checksum is generated over the whole datagram per default
1111  * (recommended as default by RFC 3828). */
1112  /* initialize PCB to all zeroes */
1113  memset(pcb, 0, sizeof(struct udp_pcb));
1114  pcb->ttl = UDP_TTL;
1115 #if LWIP_MULTICAST_TX_OPTIONS
1116  udp_set_multicast_ttl(pcb, UDP_TTL);
1117 #endif /* LWIP_MULTICAST_TX_OPTIONS */
1118  }
1119  return pcb;
1120 }
1121 
1134 struct udp_pcb *
1135 udp_new_ip_type(u8_t type)
1136 {
1137  struct udp_pcb *pcb;
1138  pcb = udp_new();
1139 #if LWIP_IPV4 && LWIP_IPV6
1140  if (pcb != NULL) {
1141  IP_SET_TYPE_VAL(pcb->local_ip, type);
1142  IP_SET_TYPE_VAL(pcb->remote_ip, type);
1143  }
1144 #else
1145  LWIP_UNUSED_ARG(type);
1146 #endif /* LWIP_IPV4 && LWIP_IPV6 */
1147  return pcb;
1148 }
1149 
1155 void udp_netif_ip_addr_changed(const ip_addr_t* old_addr, const ip_addr_t* new_addr)
1156 {
1157  struct udp_pcb* upcb;
1158 
1159  if (!ip_addr_isany(old_addr) && !ip_addr_isany(new_addr)) {
1160  for (upcb = udp_pcbs; upcb != NULL; upcb = upcb->next) {
1161  /* PCB bound to current local interface address? */
1162  if (ip_addr_cmp(&upcb->local_ip, old_addr)) {
1163  /* The PCB is bound to the old ipaddr and
1164  * is set to bound to the new one instead */
1165  ip_addr_copy(upcb->local_ip, *new_addr);
1166  }
1167  }
1168  }
1169 }
1170 
1171 #if UDP_DEBUG
1172 
1177 void
1178 udp_debug_print(struct udp_hdr *udphdr)
1179 {
1180  LWIP_DEBUGF(UDP_DEBUG, ("UDP header:\n"));
1181  LWIP_DEBUGF(UDP_DEBUG, ("+-------------------------------+\n"));
1182  LWIP_DEBUGF(UDP_DEBUG, ("| %5"U16_F" | %5"U16_F" | (src port, dest port)\n",
1183  lwip_ntohs(udphdr->src), lwip_ntohs(udphdr->dest)));
1184  LWIP_DEBUGF(UDP_DEBUG, ("+-------------------------------+\n"));
1185  LWIP_DEBUGF(UDP_DEBUG, ("| %5"U16_F" | 0x%04"X16_F" | (len, chksum)\n",
1186  lwip_ntohs(udphdr->len), lwip_ntohs(udphdr->chksum)));
1187  LWIP_DEBUGF(UDP_DEBUG, ("+-------------------------------+\n"));
1188 }
1189 #endif /* UDP_DEBUG */
1190 
1191 #endif /* LWIP_UDP */
ip_addr_set_ipaddr
#define ip_addr_set_ipaddr(dest, src)
Definition: ip_addr.h:308
SOF_BROADCAST
#define SOF_BROADCAST
Definition: ip.h:99
mib2_udp_bind
#define mib2_udp_bind(pcb)
Definition: snmp.h:191
lwip_ntohs
#define lwip_ntohs(x)
Definition: def.h:76
opt.h
ip_addr_cmp
#define ip_addr_cmp(addr1, addr2)
Definition: ip_addr.h:316
IP_IS_V6
#define IP_IS_V6(ipaddr)
Definition: ip_addr.h:296
pbuf::len
u16_t len
Definition: pbuf.h:159
udp_hdr
Definition: udp.h:53
s16_t
int16_t s16_t
Definition: arch.h:125
def.h
PERF_STOP
#define PERF_STOP(x)
Definition: perf.h:21
IP_IS_V4
#define IP_IS_V4(ipaddr)
Definition: ip_addr.h:295
IP_IS_V6_VAL
#define IP_IS_V6_VAL(ipaddr)
Definition: ip_addr.h:294
LWIP_ASSERT
#define LWIP_ASSERT(message, assertion)
Definition: debug.h:116
PBUF_RAW
Definition: pbuf.h:94
ip_current_header_tot_len
#define ip_current_header_tot_len()
Definition: ip.h:139
ip_current_dest_addr
#define ip_current_dest_addr()
Definition: ip.h:212
LWIP_IPV6
#define LWIP_IPV6
Definition: lwipopts.h:366
u16_t
uint16_t u16_t
Definition: arch.h:124
string.h
PERF_START
#define PERF_START
Definition: perf.h:20
PBUF_IP
Definition: pbuf.h:80
ip_addr_ismulticast
#define ip_addr_ismulticast(ipaddr)
Definition: ip_addr.h:322
IP46_ADDR_ANY
#define IP46_ADDR_ANY(type)
Definition: ip_addr.h:331
IP_IS_ANY_TYPE_VAL
#define IP_IS_ANY_TYPE_VAL(ipaddr)
Definition: ip_addr.h:297
ip_addr_isany
#define ip_addr_isany(ipaddr)
Definition: ip_addr.h:317
pbuf::tot_len
u16_t tot_len
Definition: pbuf.h:156
IP_ANY_TYPE
#define IP_ANY_TYPE
Definition: ip_addr.h:400
u32_t
uint32_t u32_t
Definition: arch.h:126
PBUF_FLAG_MCASTLOOP
#define PBUF_FLAG_MCASTLOOP
Definition: pbuf.h:133
pbuf_free
u8_t pbuf_free(struct pbuf *p)
Definition: pbuf.c:715
ip_chksum_pseudo_partial
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:526
ip_addr_isbroadcast
#define ip_addr_isbroadcast(addr, netif)
Definition: ip_addr.h:321
memp_malloc
void * memp_malloc(memp_t type)
Definition: memp.c:385
LWIP_DBG_TRACE
#define LWIP_DBG_TRACE
Definition: debug.h:83
IP_ADDR_PCB_VERSION_MATCH_EXACT
#define IP_ADDR_PCB_VERSION_MATCH_EXACT(pcb, ipaddr)
Definition: ip_addr.h:240
SO_REUSE
#define SO_REUSE
Definition: lwipopts.h:303
ip_chksum_pseudo
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:379
NETIF_SET_HWADDRHINT
#define NETIF_SET_HWADDRHINT(netif, hint)
Definition: netif.h:475
X16_F
#define X16_F
Definition: arch.h:154
memp_free
void memp_free(memp_t type, void *mem)
Definition: memp.c:469
IF__NETIF_CHECKSUM_ENABLED
#define IF__NETIF_CHECKSUM_ENABLED(netif, chksumflag)
Definition: netif.h:357
ip_addr_isany_val
#define ip_addr_isany_val(ipaddr)
Definition: ip_addr.h:318
icmp.h
pbuf::flags
u8_t flags
Definition: pbuf.h:165
ip_addr_debug_print
#define ip_addr_debug_print(debug, ipaddr)
Definition: ip_addr.h:323
CHECKSUM_CHECK_UDP
#define CHECKSUM_CHECK_UDP
Definition: lwipopts.h:360
snmp.h
stats.h
ERR_MEM
Definition: err.h:65
LWIP_DBG_LEVEL_SERIOUS
#define LWIP_DBG_LEVEL_SERIOUS
Definition: debug.h:57
icmp6.h
netif.h
icmp_port_unreach
#define icmp_port_unreach(isipv6, pbuf)
Definition: icmp.h:103
mib2_udp_unbind
#define mib2_udp_unbind(pcb)
Definition: snmp.h:192
ip_current_netif
#define ip_current_netif()
Definition: ip.h:133
pbuf_alloc
struct pbuf * pbuf_alloc(pbuf_layer l, u16_t length, pbuf_type type)
Definition: pbuf.c:248
u8_t
uint8_t u8_t
Definition: arch.h:122
ip_addr_t
ip6_addr_t ip_addr_t
Definition: ip_addr.h:290
IP_ADDR_PCB_VERSION_MATCH
#define IP_ADDR_PCB_VERSION_MATCH(addr, pcb)
Definition: ip_addr.h:239
ip_addr_set_any
#define ip_addr_set_any(is_ipv6, ipaddr)
Definition: ip_addr.h:311
ip_current_src_addr
#define ip_current_src_addr()
Definition: ip.h:210
netif
Definition: netif.h:233
UDP_STATS_INC
#define UDP_STATS_INC(x)
Definition: stats.h:336
ip_2_ip6
#define ip_2_ip6(ipaddr)
Definition: ip_addr.h:301
pbuf_copy
err_t pbuf_copy(struct pbuf *p_to, const struct pbuf *p_from)
Definition: pbuf.c:949
MIB2_STATS_INC
#define MIB2_STATS_INC(x)
Definition: stats.h:467
LWIP_UNUSED_ARG
#define LWIP_UNUSED_ARG(x)
Definition: arch.h:315
lwip_htons
u16_t lwip_htons(u16_t n)
Definition: def.c:75
pbuf_chain
void pbuf_chain(struct pbuf *head, struct pbuf *tail)
Definition: pbuf.c:883
PBUF_RAM
Definition: pbuf.h:108
U16_F
#define U16_F
Definition: arch.h:148
dhcp.h
ERR_OK
Definition: err.h:63
SOF_REUSEADDR
#define SOF_REUSEADDR
Definition: ip.h:97
IP_PROTO_UDPLITE
#define IP_PROTO_UDPLITE
Definition: ip.h:45
err_t
s8_t err_t
Definition: err.h:57
ip_addr_copy
#define ip_addr_copy(dest, src)
Definition: ip_addr.h:305
udp.h
ip6_addr.h
IP_SET_TYPE_VAL
#define IP_SET_TYPE_VAL(ipaddr, iptype)
Definition: ip_addr.h:298
memset
void * memset(void *dst, int c, size_t length)
ip_get_option
#define ip_get_option(pcb, opt)
Definition: ip.h:215
memp.h
ERR_USE
Definition: err.h:79
pbuf_header_force
u8_t pbuf_header_force(struct pbuf *p, s16_t header_size)
Definition: pbuf.c:675
ERR_RTE
Definition: err.h:71
ERR_VAL
Definition: err.h:75
FOLD_U32T
#define FOLD_U32T(u)
Definition: inet_chksum.h:52
pbuf
Definition: pbuf.h:142
LWIP_DEBUGF
#define LWIP_DEBUGF(debug, message)
Definition: debug.h:164
ip6.h
LWIP_DBG_STATE
#define LWIP_DBG_STATE
Definition: debug.h:85
ip_addr.h
UDP_HLEN
#define UDP_HLEN
Definition: udp.h:46
inet_chksum.h
pbuf_header
u8_t pbuf_header(struct pbuf *p, s16_t header_size)
Definition: pbuf.c:665
pbuf::payload
void * payload
Definition: pbuf.h:147
IP_GET_TYPE
#define IP_GET_TYPE(ipaddr)
Definition: ip_addr.h:300
UDP_TTL
#define UDP_TTL
Definition: lwipopts.h:168
IP_PROTO_UDP
#define IP_PROTO_UDP
Definition: ip.h:44
UDP_DEBUG
#define UDP_DEBUG
Definition: lwipopts.h:481
NULL
#define NULL
Definition: fat_string.h:17