udp.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013
  1. /**
  2. * @file
  3. * User Datagram Protocol module
  4. *
  5. */
  6. /*
  7. * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without modification,
  11. * are permitted provided that the following conditions are met:
  12. *
  13. * 1. Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * 3. The name of the author may not be used to endorse or promote products
  19. * derived from this software without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  22. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  23. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
  24. * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  25. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
  26. * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  27. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  28. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  29. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  30. * OF SUCH DAMAGE.
  31. *
  32. * This file is part of the lwIP TCP/IP stack.
  33. *
  34. * Author: Adam Dunkels <adam@sics.se>
  35. *
  36. */
  37. /* udp.c
  38. *
  39. * The code for the User Datagram Protocol UDP & UDPLite (RFC 3828).
  40. *
  41. */
  42. /* @todo Check the use of '(struct udp_pcb).chksum_len_rx'!
  43. */
  44. #include "lwip/opt.h"
  45. #if LWIP_UDP /* don't build if not configured for use in lwipopts.h */
  46. #include "lwip/udp.h"
  47. #include "lwip/def.h"
  48. #include "lwip/memp.h"
  49. #include "lwip/inet_chksum.h"
  50. #include "lwip/ip_addr.h"
  51. #include "lwip/netif.h"
  52. #include "lwip/icmp.h"
  53. #include "lwip/stats.h"
  54. #include "lwip/snmp.h"
  55. #include "arch/perf.h"
  56. #include "lwip/dhcp.h"
  57. #include <string.h>
  58. #ifndef UDP_LOCAL_PORT_RANGE_START
  59. /* From http://www.iana.org/assignments/port-numbers:
  60. "The Dynamic and/or Private Ports are those from 49152 through 65535" */
  61. #define UDP_LOCAL_PORT_RANGE_START 0xc000
  62. #define UDP_LOCAL_PORT_RANGE_END 0xffff
  63. #define UDP_ENSURE_LOCAL_PORT_RANGE(port) (((port) & ~UDP_LOCAL_PORT_RANGE_START) + UDP_LOCAL_PORT_RANGE_START)
  64. #endif
  65. /* last local UDP port */
  66. static u16_t udp_port = UDP_LOCAL_PORT_RANGE_START;
  67. /* The list of UDP PCBs */
  68. /* exported in udp.h (was static) */
  69. struct udp_pcb *udp_pcbs;
  70. /**
  71. * Initialize this module.
  72. */
  73. void
  74. udp_init(void)
  75. {
  76. #if LWIP_RANDOMIZE_INITIAL_LOCAL_PORTS && defined(LWIP_RAND)
  77. udp_port = UDP_ENSURE_LOCAL_PORT_RANGE(LWIP_RAND());
  78. #endif /* LWIP_RANDOMIZE_INITIAL_LOCAL_PORTS && defined(LWIP_RAND) */
  79. }
  80. /**
  81. * Allocate a new local UDP port.
  82. *
  83. * @return a new (free) local UDP port number
  84. */
  85. static u16_t
  86. udp_new_port(void)
  87. {
  88. u16_t n = 0;
  89. struct udp_pcb *pcb;
  90. again:
  91. if (udp_port++ == UDP_LOCAL_PORT_RANGE_END) {
  92. udp_port = UDP_LOCAL_PORT_RANGE_START;
  93. }
  94. /* Check all PCBs. */
  95. for(pcb = udp_pcbs; pcb != NULL; pcb = pcb->next) {
  96. if (pcb->local_port == udp_port) {
  97. if (++n > (UDP_LOCAL_PORT_RANGE_END - UDP_LOCAL_PORT_RANGE_START)) {
  98. return 0;
  99. }
  100. goto again;
  101. }
  102. }
  103. return udp_port;
  104. #if 0
  105. struct udp_pcb *ipcb = udp_pcbs;
  106. while ((ipcb != NULL) && (udp_port != UDP_LOCAL_PORT_RANGE_END)) {
  107. if (ipcb->local_port == udp_port) {
  108. /* port is already used by another udp_pcb */
  109. udp_port++;
  110. /* restart scanning all udp pcbs */
  111. ipcb = udp_pcbs;
  112. } else {
  113. /* go on with next udp pcb */
  114. ipcb = ipcb->next;
  115. }
  116. }
  117. if (ipcb != NULL) {
  118. return 0;
  119. }
  120. return udp_port;
  121. #endif
  122. }
  123. /**
  124. * Process an incoming UDP datagram.
  125. *
  126. * Given an incoming UDP datagram (as a chain of pbufs) this function
  127. * finds a corresponding UDP PCB and hands over the pbuf to the pcbs
  128. * recv function. If no pcb is found or the datagram is incorrect, the
  129. * pbuf is freed.
  130. *
  131. * @param p pbuf to be demultiplexed to a UDP PCB.
  132. * @param inp network interface on which the datagram was received.
  133. *
  134. */
  135. void
  136. udp_input(struct pbuf *p, struct netif *inp)
  137. {
  138. struct udp_hdr *udphdr;
  139. struct udp_pcb *pcb, *prev;
  140. struct udp_pcb *uncon_pcb;
  141. struct ip_hdr *iphdr;
  142. u16_t src, dest;
  143. u8_t local_match;
  144. u8_t broadcast;
  145. PERF_START;
  146. UDP_STATS_INC(udp.recv);
  147. iphdr = (struct ip_hdr *)p->payload;
  148. /* Check minimum length (IP header + UDP header)
  149. * and move payload pointer to UDP header */
  150. if (p->tot_len < (IPH_HL(iphdr) * 4 + UDP_HLEN) || pbuf_header(p, -(s16_t)(IPH_HL(iphdr) * 4))) {
  151. /* drop short packets */
  152. LWIP_DEBUGF(UDP_DEBUG,
  153. ("udp_input: short UDP datagram (%"U16_F" bytes) discarded\n", p->tot_len));
  154. UDP_STATS_INC(udp.lenerr);
  155. UDP_STATS_INC(udp.drop);
  156. snmp_inc_udpinerrors();
  157. pbuf_free(p);
  158. goto end;
  159. }
  160. udphdr = (struct udp_hdr *)p->payload;
  161. /* is broadcast packet ? */
  162. broadcast = ip_addr_isbroadcast(&current_iphdr_dest, inp);
  163. LWIP_DEBUGF(UDP_DEBUG, ("udp_input: received datagram of length %"U16_F"\n", p->tot_len));
  164. /* convert src and dest ports to host byte order */
  165. src = ntohs(udphdr->src);
  166. dest = ntohs(udphdr->dest);
  167. udp_debug_print(udphdr);
  168. /* print the UDP source and destination */
  169. LWIP_DEBUGF(UDP_DEBUG,
  170. ("udp (%"U16_F".%"U16_F".%"U16_F".%"U16_F", %"U16_F") <-- "
  171. "(%"U16_F".%"U16_F".%"U16_F".%"U16_F", %"U16_F")\n",
  172. ip4_addr1_16(&iphdr->dest), ip4_addr2_16(&iphdr->dest),
  173. ip4_addr3_16(&iphdr->dest), ip4_addr4_16(&iphdr->dest), ntohs(udphdr->dest),
  174. ip4_addr1_16(&iphdr->src), ip4_addr2_16(&iphdr->src),
  175. ip4_addr3_16(&iphdr->src), ip4_addr4_16(&iphdr->src), ntohs(udphdr->src)));
  176. #if LWIP_DHCP
  177. pcb = NULL;
  178. /* when LWIP_DHCP is active, packets to DHCP_CLIENT_PORT may only be processed by
  179. the dhcp module, no other UDP pcb may use the local UDP port DHCP_CLIENT_PORT */
  180. if (dest == DHCP_CLIENT_PORT) {
  181. /* all packets for DHCP_CLIENT_PORT not coming from DHCP_SERVER_PORT are dropped! */
  182. if (src == DHCP_SERVER_PORT) {
  183. if ((inp->dhcp != NULL) && (inp->dhcp->pcb != NULL)) {
  184. /* accept the packe if
  185. (- broadcast or directed to us) -> DHCP is link-layer-addressed, local ip is always ANY!
  186. - inp->dhcp->pcb->remote == ANY or iphdr->src */
  187. if ((ip_addr_isany(&inp->dhcp->pcb->remote_ip) ||
  188. ip_addr_cmp(&(inp->dhcp->pcb->remote_ip), &current_iphdr_src))) {
  189. pcb = inp->dhcp->pcb;
  190. }
  191. }
  192. }
  193. } else
  194. #endif /* LWIP_DHCP */
  195. {
  196. prev = NULL;
  197. local_match = 0;
  198. uncon_pcb = NULL;
  199. /* Iterate through the UDP pcb list for a matching pcb.
  200. * 'Perfect match' pcbs (connected to the remote port & ip address) are
  201. * preferred. If no perfect match is found, the first unconnected pcb that
  202. * matches the local port and ip address gets the datagram. */
  203. for (pcb = udp_pcbs; pcb != NULL; pcb = pcb->next) {
  204. local_match = 0;
  205. /* print the PCB local and remote address */
  206. LWIP_DEBUGF(UDP_DEBUG,
  207. ("pcb (%"U16_F".%"U16_F".%"U16_F".%"U16_F", %"U16_F") --- "
  208. "(%"U16_F".%"U16_F".%"U16_F".%"U16_F", %"U16_F")\n",
  209. ip4_addr1_16(&pcb->local_ip), ip4_addr2_16(&pcb->local_ip),
  210. ip4_addr3_16(&pcb->local_ip), ip4_addr4_16(&pcb->local_ip), pcb->local_port,
  211. ip4_addr1_16(&pcb->remote_ip), ip4_addr2_16(&pcb->remote_ip),
  212. ip4_addr3_16(&pcb->remote_ip), ip4_addr4_16(&pcb->remote_ip), pcb->remote_port));
  213. /* compare PCB local addr+port to UDP destination addr+port */
  214. if (pcb->local_port == dest) {
  215. if (
  216. (!broadcast && ip_addr_isany(&pcb->local_ip)) ||
  217. ip_addr_cmp(&(pcb->local_ip), &current_iphdr_dest) ||
  218. #if LWIP_IGMP
  219. ip_addr_ismulticast(&current_iphdr_dest) ||
  220. #endif /* LWIP_IGMP */
  221. #if IP_SOF_BROADCAST_RECV
  222. (broadcast && ip_get_option(pcb, SOF_BROADCAST) &&
  223. (ip_addr_isany(&pcb->local_ip) ||
  224. ip_addr_netcmp(&pcb->local_ip, ip_current_dest_addr(), &inp->netmask)))) {
  225. #else /* IP_SOF_BROADCAST_RECV */
  226. (broadcast &&
  227. (ip_addr_isany(&pcb->local_ip) ||
  228. ip_addr_netcmp(&pcb->local_ip, ip_current_dest_addr(), &inp->netmask)))) {
  229. #endif /* IP_SOF_BROADCAST_RECV */
  230. local_match = 1;
  231. if ((uncon_pcb == NULL) &&
  232. ((pcb->flags & UDP_FLAGS_CONNECTED) == 0)) {
  233. /* the first unconnected matching PCB */
  234. uncon_pcb = pcb;
  235. }
  236. }
  237. }
  238. /* compare PCB remote addr+port to UDP source addr+port */
  239. if ((local_match != 0) &&
  240. (pcb->remote_port == src) &&
  241. (ip_addr_isany(&pcb->remote_ip) ||
  242. ip_addr_cmp(&(pcb->remote_ip), &current_iphdr_src))) {
  243. /* the first fully matching PCB */
  244. if (prev != NULL) {
  245. /* move the pcb to the front of udp_pcbs so that is
  246. found faster next time */
  247. prev->next = pcb->next;
  248. pcb->next = udp_pcbs;
  249. udp_pcbs = pcb;
  250. } else {
  251. UDP_STATS_INC(udp.cachehit);
  252. }
  253. break;
  254. }
  255. prev = pcb;
  256. }
  257. /* no fully matching pcb found? then look for an unconnected pcb */
  258. if (pcb == NULL) {
  259. pcb = uncon_pcb;
  260. }
  261. }
  262. /* Check checksum if this is a match or if it was directed at us. */
  263. if (pcb != NULL || ip_addr_cmp(&inp->ip_addr, &current_iphdr_dest)) {
  264. LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE, ("udp_input: calculating checksum\n"));
  265. #if LWIP_UDPLITE
  266. if (IPH_PROTO(iphdr) == IP_PROTO_UDPLITE) {
  267. /* Do the UDP Lite checksum */
  268. #if CHECKSUM_CHECK_UDP
  269. u16_t chklen = ntohs(udphdr->len);
  270. if (chklen < sizeof(struct udp_hdr)) {
  271. if (chklen == 0) {
  272. /* For UDP-Lite, checksum length of 0 means checksum
  273. over the complete packet (See RFC 3828 chap. 3.1) */
  274. chklen = p->tot_len;
  275. } else {
  276. /* At least the UDP-Lite header must be covered by the
  277. checksum! (Again, see RFC 3828 chap. 3.1) */
  278. UDP_STATS_INC(udp.chkerr);
  279. UDP_STATS_INC(udp.drop);
  280. snmp_inc_udpinerrors();
  281. pbuf_free(p);
  282. goto end;
  283. }
  284. }
  285. if (inet_chksum_pseudo_partial(p, &current_iphdr_src, &current_iphdr_dest,
  286. IP_PROTO_UDPLITE, p->tot_len, chklen) != 0) {
  287. LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_LEVEL_SERIOUS,
  288. ("udp_input: UDP Lite datagram discarded due to failing checksum\n"));
  289. UDP_STATS_INC(udp.chkerr);
  290. UDP_STATS_INC(udp.drop);
  291. snmp_inc_udpinerrors();
  292. pbuf_free(p);
  293. goto end;
  294. }
  295. #endif /* CHECKSUM_CHECK_UDP */
  296. } else
  297. #endif /* LWIP_UDPLITE */
  298. {
  299. #if CHECKSUM_CHECK_UDP
  300. if (udphdr->chksum != 0) {
  301. if (inet_chksum_pseudo(p, ip_current_src_addr(), ip_current_dest_addr(),
  302. IP_PROTO_UDP, p->tot_len) != 0) {
  303. LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_LEVEL_SERIOUS,
  304. ("udp_input: UDP datagram discarded due to failing checksum\n"));
  305. UDP_STATS_INC(udp.chkerr);
  306. UDP_STATS_INC(udp.drop);
  307. snmp_inc_udpinerrors();
  308. pbuf_free(p);
  309. goto end;
  310. }
  311. }
  312. #endif /* CHECKSUM_CHECK_UDP */
  313. }
  314. if(pbuf_header(p, -UDP_HLEN)) {
  315. /* Can we cope with this failing? Just assert for now */
  316. LWIP_ASSERT("pbuf_header failed\n", 0);
  317. UDP_STATS_INC(udp.drop);
  318. snmp_inc_udpinerrors();
  319. pbuf_free(p);
  320. goto end;
  321. }
  322. if (pcb != NULL) {
  323. snmp_inc_udpindatagrams();
  324. #if SO_REUSE && SO_REUSE_RXTOALL
  325. if ((broadcast || ip_addr_ismulticast(&current_iphdr_dest)) &&
  326. ip_get_option(pcb, SOF_REUSEADDR)) {
  327. /* pass broadcast- or multicast packets to all multicast pcbs
  328. if SOF_REUSEADDR is set on the first match */
  329. struct udp_pcb *mpcb;
  330. u8_t p_header_changed = 0;
  331. for (mpcb = udp_pcbs; mpcb != NULL; mpcb = mpcb->next) {
  332. if (mpcb != pcb) {
  333. /* compare PCB local addr+port to UDP destination addr+port */
  334. if ((mpcb->local_port == dest) &&
  335. ((!broadcast && ip_addr_isany(&mpcb->local_ip)) ||
  336. ip_addr_cmp(&(mpcb->local_ip), &current_iphdr_dest) ||
  337. #if LWIP_IGMP
  338. ip_addr_ismulticast(&current_iphdr_dest) ||
  339. #endif /* LWIP_IGMP */
  340. #if IP_SOF_BROADCAST_RECV
  341. (broadcast && ip_get_option(mpcb, SOF_BROADCAST)))) {
  342. #else /* IP_SOF_BROADCAST_RECV */
  343. (broadcast))) {
  344. #endif /* IP_SOF_BROADCAST_RECV */
  345. /* pass a copy of the packet to all local matches */
  346. if (mpcb->recv != NULL) {
  347. struct pbuf *q;
  348. /* for that, move payload to IP header again */
  349. if (p_header_changed == 0) {
  350. pbuf_header(p, (s16_t)((IPH_HL(iphdr) * 4) + UDP_HLEN));
  351. p_header_changed = 1;
  352. }
  353. q = pbuf_alloc(PBUF_RAW, p->tot_len, PBUF_RAM);
  354. if (q != NULL) {
  355. err_t err = pbuf_copy(q, p);
  356. if (err == ERR_OK) {
  357. /* move payload to UDP data */
  358. pbuf_header(q, -(s16_t)((IPH_HL(iphdr) * 4) + UDP_HLEN));
  359. mpcb->recv(mpcb->recv_arg, mpcb, q, ip_current_src_addr(), src);
  360. }
  361. }
  362. }
  363. }
  364. }
  365. }
  366. if (p_header_changed) {
  367. /* and move payload to UDP data again */
  368. pbuf_header(p, -(s16_t)((IPH_HL(iphdr) * 4) + UDP_HLEN));
  369. }
  370. }
  371. #endif /* SO_REUSE && SO_REUSE_RXTOALL */
  372. /* callback */
  373. if (pcb->recv != NULL) {
  374. /* now the recv function is responsible for freeing p */
  375. pcb->recv(pcb->recv_arg, pcb, p, ip_current_src_addr(), src);
  376. } else {
  377. /* no recv function registered? then we have to free the pbuf! */
  378. pbuf_free(p);
  379. goto end;
  380. }
  381. } else {
  382. LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE, ("udp_input: not for us.\n"));
  383. #if LWIP_ICMP
  384. /* No match was found, send ICMP destination port unreachable unless
  385. destination address was broadcast/multicast. */
  386. if (!broadcast &&
  387. !ip_addr_ismulticast(&current_iphdr_dest)) {
  388. /* move payload pointer back to ip header */
  389. pbuf_header(p, (IPH_HL(iphdr) * 4) + UDP_HLEN);
  390. LWIP_ASSERT("p->payload == iphdr", (p->payload == iphdr));
  391. icmp_dest_unreach(p, ICMP_DUR_PORT);
  392. }
  393. #endif /* LWIP_ICMP */
  394. UDP_STATS_INC(udp.proterr);
  395. UDP_STATS_INC(udp.drop);
  396. snmp_inc_udpnoports();
  397. pbuf_free(p);
  398. }
  399. } else {
  400. pbuf_free(p);
  401. }
  402. end:
  403. PERF_STOP("udp_input");
  404. }
  405. /**
  406. * Send data using UDP.
  407. *
  408. * @param pcb UDP PCB used to send the data.
  409. * @param p chain of pbuf's to be sent.
  410. *
  411. * The datagram will be sent to the current remote_ip & remote_port
  412. * stored in pcb. If the pcb is not bound to a port, it will
  413. * automatically be bound to a random port.
  414. *
  415. * @return lwIP error code.
  416. * - ERR_OK. Successful. No error occured.
  417. * - ERR_MEM. Out of memory.
  418. * - ERR_RTE. Could not find route to destination address.
  419. * - More errors could be returned by lower protocol layers.
  420. *
  421. * @see udp_disconnect() udp_sendto()
  422. */
  423. err_t
  424. udp_send(struct udp_pcb *pcb, struct pbuf *p)
  425. {
  426. /* send to the packet using remote ip and port stored in the pcb */
  427. return udp_sendto(pcb, p, &pcb->remote_ip, pcb->remote_port);
  428. }
  429. #if LWIP_CHECKSUM_ON_COPY
  430. /** Same as udp_send() but with checksum
  431. */
  432. err_t
  433. udp_send_chksum(struct udp_pcb *pcb, struct pbuf *p,
  434. u8_t have_chksum, u16_t chksum)
  435. {
  436. /* send to the packet using remote ip and port stored in the pcb */
  437. return udp_sendto_chksum(pcb, p, &pcb->remote_ip, pcb->remote_port,
  438. have_chksum, chksum);
  439. }
  440. #endif /* LWIP_CHECKSUM_ON_COPY */
  441. /**
  442. * Send data to a specified address using UDP.
  443. *
  444. * @param pcb UDP PCB used to send the data.
  445. * @param p chain of pbuf's to be sent.
  446. * @param dst_ip Destination IP address.
  447. * @param dst_port Destination UDP port.
  448. *
  449. * dst_ip & dst_port are expected to be in the same byte order as in the pcb.
  450. *
  451. * If the PCB already has a remote address association, it will
  452. * be restored after the data is sent.
  453. *
  454. * @return lwIP error code (@see udp_send for possible error codes)
  455. *
  456. * @see udp_disconnect() udp_send()
  457. */
  458. err_t
  459. udp_sendto(struct udp_pcb *pcb, struct pbuf *p,
  460. ip_addr_t *dst_ip, u16_t dst_port)
  461. {
  462. #if LWIP_CHECKSUM_ON_COPY
  463. return udp_sendto_chksum(pcb, p, dst_ip, dst_port, 0, 0);
  464. }
  465. /** Same as udp_sendto(), but with checksum */
  466. err_t
  467. udp_sendto_chksum(struct udp_pcb *pcb, struct pbuf *p, ip_addr_t *dst_ip,
  468. u16_t dst_port, u8_t have_chksum, u16_t chksum)
  469. {
  470. #endif /* LWIP_CHECKSUM_ON_COPY */
  471. struct netif *netif;
  472. LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE, ("udp_send\n"));
  473. /* find the outgoing network interface for this packet */
  474. #if LWIP_IGMP
  475. netif = ip_route((ip_addr_ismulticast(dst_ip))?(&(pcb->multicast_ip)):(dst_ip));
  476. #else
  477. netif = ip_route(dst_ip);
  478. #endif /* LWIP_IGMP */
  479. /* no outgoing network interface could be found? */
  480. if (netif == NULL) {
  481. LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("udp_send: No route to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
  482. ip4_addr1_16(dst_ip), ip4_addr2_16(dst_ip), ip4_addr3_16(dst_ip), ip4_addr4_16(dst_ip)));
  483. UDP_STATS_INC(udp.rterr);
  484. return ERR_RTE;
  485. }
  486. #if LWIP_CHECKSUM_ON_COPY
  487. return udp_sendto_if_chksum(pcb, p, dst_ip, dst_port, netif, have_chksum, chksum);
  488. #else /* LWIP_CHECKSUM_ON_COPY */
  489. return udp_sendto_if(pcb, p, dst_ip, dst_port, netif);
  490. #endif /* LWIP_CHECKSUM_ON_COPY */
  491. }
  492. /**
  493. * Send data to a specified address using UDP.
  494. * The netif used for sending can be specified.
  495. *
  496. * This function exists mainly for DHCP, to be able to send UDP packets
  497. * on a netif that is still down.
  498. *
  499. * @param pcb UDP PCB used to send the data.
  500. * @param p chain of pbuf's to be sent.
  501. * @param dst_ip Destination IP address.
  502. * @param dst_port Destination UDP port.
  503. * @param netif the netif used for sending.
  504. *
  505. * dst_ip & dst_port are expected to be in the same byte order as in the pcb.
  506. *
  507. * @return lwIP error code (@see udp_send for possible error codes)
  508. *
  509. * @see udp_disconnect() udp_send()
  510. */
  511. err_t
  512. udp_sendto_if(struct udp_pcb *pcb, struct pbuf *p,
  513. ip_addr_t *dst_ip, u16_t dst_port, struct netif *netif)
  514. {
  515. #if LWIP_CHECKSUM_ON_COPY
  516. return udp_sendto_if_chksum(pcb, p, dst_ip, dst_port, netif, 0, 0);
  517. }
  518. /** Same as udp_sendto_if(), but with checksum */
  519. err_t
  520. udp_sendto_if_chksum(struct udp_pcb *pcb, struct pbuf *p, ip_addr_t *dst_ip,
  521. u16_t dst_port, struct netif *netif, u8_t have_chksum,
  522. u16_t chksum)
  523. {
  524. #endif /* LWIP_CHECKSUM_ON_COPY */
  525. struct udp_hdr *udphdr;
  526. ip_addr_t *src_ip;
  527. err_t err;
  528. struct pbuf *q; /* q will be sent down the stack */
  529. #if IP_SOF_BROADCAST
  530. /* broadcast filter? */
  531. if (!ip_get_option(pcb, SOF_BROADCAST) && ip_addr_isbroadcast(dst_ip, netif)) {
  532. LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_LEVEL_SERIOUS,
  533. ("udp_sendto_if: SOF_BROADCAST not enabled on pcb %p\n", (void *)pcb));
  534. return ERR_VAL;
  535. }
  536. #endif /* IP_SOF_BROADCAST */
  537. /* if the PCB is not yet bound to a port, bind it here */
  538. if (pcb->local_port == 0) {
  539. LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE, ("udp_send: not yet bound to a port, binding now\n"));
  540. err = udp_bind(pcb, &pcb->local_ip, pcb->local_port);
  541. if (err != ERR_OK) {
  542. LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_SERIOUS, ("udp_send: forced port bind failed\n"));
  543. return err;
  544. }
  545. }
  546. /* not enough space to add an UDP header to first pbuf in given p chain? */
  547. if (pbuf_header(p, UDP_HLEN)) {
  548. /* allocate header in a separate new pbuf */
  549. q = pbuf_alloc(PBUF_IP, UDP_HLEN, PBUF_RAM);
  550. /* new header pbuf could not be allocated? */
  551. if (q == NULL) {
  552. LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_SERIOUS, ("udp_send: could not allocate header\n"));
  553. return ERR_MEM;
  554. }
  555. if (p->tot_len != 0) {
  556. /* chain header q in front of given pbuf p (only if p contains data) */
  557. pbuf_chain(q, p);
  558. }
  559. /* first pbuf q points to header pbuf */
  560. LWIP_DEBUGF(UDP_DEBUG,
  561. ("udp_send: added header pbuf %p before given pbuf %p\n", (void *)q, (void *)p));
  562. } else {
  563. /* adding space for header within p succeeded */
  564. /* first pbuf q equals given pbuf */
  565. q = p;
  566. LWIP_DEBUGF(UDP_DEBUG, ("udp_send: added header in given pbuf %p\n", (void *)p));
  567. }
  568. LWIP_ASSERT("check that first pbuf can hold struct udp_hdr",
  569. (q->len >= sizeof(struct udp_hdr)));
  570. /* q now represents the packet to be sent */
  571. udphdr = (struct udp_hdr *)q->payload;
  572. udphdr->src = htons(pcb->local_port);
  573. udphdr->dest = htons(dst_port);
  574. /* in UDP, 0 checksum means 'no checksum' */
  575. udphdr->chksum = 0x0000;
  576. /* Multicast Loop? */
  577. #if LWIP_IGMP
  578. if (ip_addr_ismulticast(dst_ip) && ((pcb->flags & UDP_FLAGS_MULTICAST_LOOP) != 0)) {
  579. q->flags |= PBUF_FLAG_MCASTLOOP;
  580. }
  581. #endif /* LWIP_IGMP */
  582. /* PCB local address is IP_ANY_ADDR? */
  583. if (ip_addr_isany(&pcb->local_ip)) {
  584. /* use outgoing network interface IP address as source address */
  585. src_ip = &(netif->ip_addr);
  586. } else {
  587. /* check if UDP PCB local IP address is correct
  588. * this could be an old address if netif->ip_addr has changed */
  589. if (!ip_addr_cmp(&(pcb->local_ip), &(netif->ip_addr))) {
  590. /* local_ip doesn't match, drop the packet */
  591. if (q != p) {
  592. /* free the header pbuf */
  593. pbuf_free(q);
  594. q = NULL;
  595. /* p is still referenced by the caller, and will live on */
  596. }
  597. return ERR_VAL;
  598. }
  599. /* use UDP PCB local IP address as source address */
  600. src_ip = &(pcb->local_ip);
  601. }
  602. LWIP_DEBUGF(UDP_DEBUG, ("udp_send: sending datagram of length %"U16_F"\n", q->tot_len));
  603. #if LWIP_UDPLITE
  604. /* UDP Lite protocol? */
  605. if (pcb->flags & UDP_FLAGS_UDPLITE) {
  606. u16_t chklen, chklen_hdr;
  607. LWIP_DEBUGF(UDP_DEBUG, ("udp_send: UDP LITE packet length %"U16_F"\n", q->tot_len));
  608. /* set UDP message length in UDP header */
  609. chklen_hdr = chklen = pcb->chksum_len_tx;
  610. if ((chklen < sizeof(struct udp_hdr)) || (chklen > q->tot_len)) {
  611. if (chklen != 0) {
  612. LWIP_DEBUGF(UDP_DEBUG, ("udp_send: UDP LITE pcb->chksum_len is illegal: %"U16_F"\n", chklen));
  613. }
  614. /* For UDP-Lite, checksum length of 0 means checksum
  615. over the complete packet. (See RFC 3828 chap. 3.1)
  616. At least the UDP-Lite header must be covered by the
  617. checksum, therefore, if chksum_len has an illegal
  618. value, we generate the checksum over the complete
  619. packet to be safe. */
  620. chklen_hdr = 0;
  621. chklen = q->tot_len;
  622. }
  623. udphdr->len = htons(chklen_hdr);
  624. /* calculate checksum */
  625. #if CHECKSUM_GEN_UDP
  626. udphdr->chksum = inet_chksum_pseudo_partial(q, src_ip, dst_ip,
  627. IP_PROTO_UDPLITE, q->tot_len,
  628. #if !LWIP_CHECKSUM_ON_COPY
  629. chklen);
  630. #else /* !LWIP_CHECKSUM_ON_COPY */
  631. (have_chksum ? UDP_HLEN : chklen));
  632. if (have_chksum) {
  633. u32_t acc;
  634. acc = udphdr->chksum + (u16_t)~(chksum);
  635. udphdr->chksum = FOLD_U32T(acc);
  636. }
  637. #endif /* !LWIP_CHECKSUM_ON_COPY */
  638. /* chksum zero must become 0xffff, as zero means 'no checksum' */
  639. if (udphdr->chksum == 0x0000) {
  640. udphdr->chksum = 0xffff;
  641. }
  642. #endif /* CHECKSUM_GEN_UDP */
  643. /* output to IP */
  644. LWIP_DEBUGF(UDP_DEBUG, ("udp_send: ip_output_if (,,,,IP_PROTO_UDPLITE,)\n"));
  645. NETIF_SET_HWADDRHINT(netif, &pcb->addr_hint);
  646. err = ip_output_if(q, src_ip, dst_ip, pcb->ttl, pcb->tos, IP_PROTO_UDPLITE, netif);
  647. NETIF_SET_HWADDRHINT(netif, NULL);
  648. } else
  649. #endif /* LWIP_UDPLITE */
  650. { /* UDP */
  651. LWIP_DEBUGF(UDP_DEBUG, ("udp_send: UDP packet length %"U16_F"\n", q->tot_len));
  652. udphdr->len = htons(q->tot_len);
  653. /* calculate checksum */
  654. #if CHECKSUM_GEN_UDP
  655. if ((pcb->flags & UDP_FLAGS_NOCHKSUM) == 0) {
  656. u16_t udpchksum;
  657. #if LWIP_CHECKSUM_ON_COPY
  658. if (have_chksum) {
  659. u32_t acc;
  660. udpchksum = inet_chksum_pseudo_partial(q, src_ip, dst_ip, IP_PROTO_UDP,
  661. q->tot_len, UDP_HLEN);
  662. acc = udpchksum + (u16_t)~(chksum);
  663. udpchksum = FOLD_U32T(acc);
  664. } else
  665. #endif /* LWIP_CHECKSUM_ON_COPY */
  666. {
  667. udpchksum = inet_chksum_pseudo(q, src_ip, dst_ip, IP_PROTO_UDP, q->tot_len);
  668. }
  669. /* chksum zero must become 0xffff, as zero means 'no checksum' */
  670. if (udpchksum == 0x0000) {
  671. udpchksum = 0xffff;
  672. }
  673. udphdr->chksum = udpchksum;
  674. }
  675. #endif /* CHECKSUM_GEN_UDP */
  676. LWIP_DEBUGF(UDP_DEBUG, ("udp_send: UDP checksum 0x%04"X16_F"\n", udphdr->chksum));
  677. LWIP_DEBUGF(UDP_DEBUG, ("udp_send: ip_output_if (,,,,IP_PROTO_UDP,)\n"));
  678. /* output to IP */
  679. NETIF_SET_HWADDRHINT(netif, &pcb->addr_hint);
  680. err = ip_output_if(q, src_ip, dst_ip, pcb->ttl, pcb->tos, IP_PROTO_UDP, netif);
  681. NETIF_SET_HWADDRHINT(netif, NULL);
  682. }
  683. /* TODO: must this be increased even if error occured? */
  684. snmp_inc_udpoutdatagrams();
  685. /* did we chain a separate header pbuf earlier? */
  686. if (q != p) {
  687. /* free the header pbuf */
  688. pbuf_free(q);
  689. q = NULL;
  690. /* p is still referenced by the caller, and will live on */
  691. }
  692. UDP_STATS_INC(udp.xmit);
  693. return err;
  694. }
  695. /**
  696. * Bind an UDP PCB.
  697. *
  698. * @param pcb UDP PCB to be bound with a local address ipaddr and port.
  699. * @param ipaddr local IP address to bind with. Use IP_ADDR_ANY to
  700. * bind to all local interfaces.
  701. * @param port local UDP port to bind with. Use 0 to automatically bind
  702. * to a random port between UDP_LOCAL_PORT_RANGE_START and
  703. * UDP_LOCAL_PORT_RANGE_END.
  704. *
  705. * ipaddr & port are expected to be in the same byte order as in the pcb.
  706. *
  707. * @return lwIP error code.
  708. * - ERR_OK. Successful. No error occured.
  709. * - ERR_USE. The specified ipaddr and port are already bound to by
  710. * another UDP PCB.
  711. *
  712. * @see udp_disconnect()
  713. */
  714. err_t
  715. udp_bind(struct udp_pcb *pcb, ip_addr_t *ipaddr, u16_t port)
  716. {
  717. struct udp_pcb *ipcb;
  718. u8_t rebind;
  719. LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE, ("udp_bind(ipaddr = "));
  720. ip_addr_debug_print(UDP_DEBUG, ipaddr);
  721. LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE, (", port = %"U16_F")\n", port));
  722. rebind = 0;
  723. /* Check for double bind and rebind of the same pcb */
  724. for (ipcb = udp_pcbs; ipcb != NULL; ipcb = ipcb->next) {
  725. /* is this UDP PCB already on active list? */
  726. if (pcb == ipcb) {
  727. /* pcb may occur at most once in active list */
  728. LWIP_ASSERT("rebind == 0", rebind == 0);
  729. /* pcb already in list, just rebind */
  730. rebind = 1;
  731. }
  732. /* By default, we don't allow to bind to a port that any other udp
  733. PCB is alread bound to, unless *all* PCBs with that port have tha
  734. REUSEADDR flag set. */
  735. #if SO_REUSE
  736. else if (!ip_get_option(pcb, SOF_REUSEADDR) &&
  737. !ip_get_option(ipcb, SOF_REUSEADDR)) {
  738. #else /* SO_REUSE */
  739. /* port matches that of PCB in list and REUSEADDR not set -> reject */
  740. else {
  741. #endif /* SO_REUSE */
  742. if ((ipcb->local_port == port) &&
  743. /* IP address matches, or one is IP_ADDR_ANY? */
  744. (ip_addr_isany(&(ipcb->local_ip)) ||
  745. ip_addr_isany(ipaddr) ||
  746. ip_addr_cmp(&(ipcb->local_ip), ipaddr))) {
  747. /* other PCB already binds to this local IP and port */
  748. LWIP_DEBUGF(UDP_DEBUG,
  749. ("udp_bind: local port %"U16_F" already bound by another pcb\n", port));
  750. return ERR_USE;
  751. }
  752. }
  753. }
  754. ip_addr_set(&pcb->local_ip, ipaddr);
  755. /* no port specified? */
  756. if (port == 0) {
  757. port = udp_new_port();
  758. if (port == 0) {
  759. /* no more ports available in local range */
  760. LWIP_DEBUGF(UDP_DEBUG, ("udp_bind: out of free UDP ports\n"));
  761. return ERR_USE;
  762. }
  763. }
  764. pcb->local_port = port;
  765. snmp_insert_udpidx_tree(pcb);
  766. /* pcb not active yet? */
  767. if (rebind == 0) {
  768. /* place the PCB on the active list if not already there */
  769. pcb->next = udp_pcbs;
  770. udp_pcbs = pcb;
  771. }
  772. LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE,
  773. ("udp_bind: bound to %"U16_F".%"U16_F".%"U16_F".%"U16_F", port %"U16_F"\n",
  774. ip4_addr1_16(&pcb->local_ip), ip4_addr2_16(&pcb->local_ip),
  775. ip4_addr3_16(&pcb->local_ip), ip4_addr4_16(&pcb->local_ip),
  776. pcb->local_port));
  777. return ERR_OK;
  778. }
  779. /**
  780. * Connect an UDP PCB.
  781. *
  782. * This will associate the UDP PCB with the remote address.
  783. *
  784. * @param pcb UDP PCB to be connected with remote address ipaddr and port.
  785. * @param ipaddr remote IP address to connect with.
  786. * @param port remote UDP port to connect with.
  787. *
  788. * @return lwIP error code
  789. *
  790. * ipaddr & port are expected to be in the same byte order as in the pcb.
  791. *
  792. * The udp pcb is bound to a random local port if not already bound.
  793. *
  794. * @see udp_disconnect()
  795. */
  796. err_t
  797. udp_connect(struct udp_pcb *pcb, ip_addr_t *ipaddr, u16_t port)
  798. {
  799. struct udp_pcb *ipcb;
  800. if (pcb->local_port == 0) {
  801. err_t err = udp_bind(pcb, &pcb->local_ip, pcb->local_port);
  802. if (err != ERR_OK) {
  803. return err;
  804. }
  805. }
  806. ip_addr_set(&pcb->remote_ip, ipaddr);
  807. pcb->remote_port = port;
  808. pcb->flags |= UDP_FLAGS_CONNECTED;
  809. /** TODO: this functionality belongs in upper layers */
  810. #ifdef LWIP_UDP_TODO
  811. /* Nail down local IP for netconn_addr()/getsockname() */
  812. if (ip_addr_isany(&pcb->local_ip) && !ip_addr_isany(&pcb->remote_ip)) {
  813. struct netif *netif;
  814. if ((netif = ip_route(&(pcb->remote_ip))) == NULL) {
  815. LWIP_DEBUGF(UDP_DEBUG, ("udp_connect: No route to 0x%lx\n", pcb->remote_ip.addr));
  816. UDP_STATS_INC(udp.rterr);
  817. return ERR_RTE;
  818. }
  819. /** TODO: this will bind the udp pcb locally, to the interface which
  820. is used to route output packets to the remote address. However, we
  821. might want to accept incoming packets on any interface! */
  822. pcb->local_ip = netif->ip_addr;
  823. } else if (ip_addr_isany(&pcb->remote_ip)) {
  824. pcb->local_ip.addr = 0;
  825. }
  826. #endif
  827. LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE,
  828. ("udp_connect: connected to %"U16_F".%"U16_F".%"U16_F".%"U16_F",port %"U16_F"\n",
  829. ip4_addr1_16(&pcb->local_ip), ip4_addr2_16(&pcb->local_ip),
  830. ip4_addr3_16(&pcb->local_ip), ip4_addr4_16(&pcb->local_ip),
  831. pcb->local_port));
  832. /* Insert UDP PCB into the list of active UDP PCBs. */
  833. for (ipcb = udp_pcbs; ipcb != NULL; ipcb = ipcb->next) {
  834. if (pcb == ipcb) {
  835. /* already on the list, just return */
  836. return ERR_OK;
  837. }
  838. }
  839. /* PCB not yet on the list, add PCB now */
  840. pcb->next = udp_pcbs;
  841. udp_pcbs = pcb;
  842. return ERR_OK;
  843. }
  844. /**
  845. * Disconnect a UDP PCB
  846. *
  847. * @param pcb the udp pcb to disconnect.
  848. */
  849. void
  850. udp_disconnect(struct udp_pcb *pcb)
  851. {
  852. /* reset remote address association */
  853. ip_addr_set_any(&pcb->remote_ip);
  854. pcb->remote_port = 0;
  855. /* mark PCB as unconnected */
  856. pcb->flags &= ~UDP_FLAGS_CONNECTED;
  857. }
  858. /**
  859. * Set a receive callback for a UDP PCB
  860. *
  861. * This callback will be called when receiving a datagram for the pcb.
  862. *
  863. * @param pcb the pcb for wich to set the recv callback
  864. * @param recv function pointer of the callback function
  865. * @param recv_arg additional argument to pass to the callback function
  866. */
  867. void
  868. udp_recv(struct udp_pcb *pcb, udp_recv_fn recv, void *recv_arg)
  869. {
  870. /* remember recv() callback and user data */
  871. pcb->recv = recv;
  872. pcb->recv_arg = recv_arg;
  873. }
  874. /**
  875. * Remove an UDP PCB.
  876. *
  877. * @param pcb UDP PCB to be removed. The PCB is removed from the list of
  878. * UDP PCB's and the data structure is freed from memory.
  879. *
  880. * @see udp_new()
  881. */
  882. void
  883. udp_remove(struct udp_pcb *pcb)
  884. {
  885. struct udp_pcb *pcb2;
  886. snmp_delete_udpidx_tree(pcb);
  887. /* pcb to be removed is first in list? */
  888. if (udp_pcbs == pcb) {
  889. /* make list start at 2nd pcb */
  890. udp_pcbs = udp_pcbs->next;
  891. /* pcb not 1st in list */
  892. } else {
  893. for (pcb2 = udp_pcbs; pcb2 != NULL; pcb2 = pcb2->next) {
  894. /* find pcb in udp_pcbs list */
  895. if (pcb2->next != NULL && pcb2->next == pcb) {
  896. /* remove pcb from list */
  897. pcb2->next = pcb->next;
  898. }
  899. }
  900. }
  901. memp_free(MEMP_UDP_PCB, pcb);
  902. }
  903. /**
  904. * Create a UDP PCB.
  905. *
  906. * @return The UDP PCB which was created. NULL if the PCB data structure
  907. * could not be allocated.
  908. *
  909. * @see udp_remove()
  910. */
  911. struct udp_pcb *
  912. udp_new(void)
  913. {
  914. struct udp_pcb *pcb;
  915. pcb = (struct udp_pcb *)memp_malloc(MEMP_UDP_PCB);
  916. /* could allocate UDP PCB? */
  917. if (pcb != NULL) {
  918. /* UDP Lite: by initializing to all zeroes, chksum_len is set to 0
  919. * which means checksum is generated over the whole datagram per default
  920. * (recommended as default by RFC 3828). */
  921. /* initialize PCB to all zeroes */
  922. memset(pcb, 0, sizeof(struct udp_pcb));
  923. pcb->ttl = UDP_TTL;
  924. }
  925. return pcb;
  926. }
  927. #if UDP_DEBUG
  928. /**
  929. * Print UDP header information for debug purposes.
  930. *
  931. * @param udphdr pointer to the udp header in memory.
  932. */
  933. void
  934. udp_debug_print(struct udp_hdr *udphdr)
  935. {
  936. LWIP_DEBUGF(UDP_DEBUG, ("UDP header:\n"));
  937. LWIP_DEBUGF(UDP_DEBUG, ("+-------------------------------+\n"));
  938. LWIP_DEBUGF(UDP_DEBUG, ("| %5"U16_F" | %5"U16_F" | (src port, dest port)\n",
  939. ntohs(udphdr->src), ntohs(udphdr->dest)));
  940. LWIP_DEBUGF(UDP_DEBUG, ("+-------------------------------+\n"));
  941. LWIP_DEBUGF(UDP_DEBUG, ("| %5"U16_F" | 0x%04"X16_F" | (len, chksum)\n",
  942. ntohs(udphdr->len), ntohs(udphdr->chksum)));
  943. LWIP_DEBUGF(UDP_DEBUG, ("+-------------------------------+\n"));
  944. }
  945. #endif /* UDP_DEBUG */
  946. #endif /* LWIP_UDP */