You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tftp.c 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. /*
  2. * Copyright (C) 2006 Michael Brown <mbrown@fensystems.co.uk>.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of the
  7. * License, or any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. #include <stdint.h>
  19. #include <stdlib.h>
  20. #include <stdio.h>
  21. #include <string.h>
  22. #include <strings.h>
  23. #include <byteswap.h>
  24. #include <errno.h>
  25. #include <assert.h>
  26. #include <gpxe/refcnt.h>
  27. #include <gpxe/xfer.h>
  28. #include <gpxe/open.h>
  29. #include <gpxe/uri.h>
  30. #include <gpxe/tcpip.h>
  31. #include <gpxe/retry.h>
  32. #include <gpxe/tftp.h>
  33. /** @file
  34. *
  35. * TFTP protocol
  36. *
  37. */
  38. /**
  39. * A TFTP request
  40. *
  41. * This data structure holds the state for an ongoing TFTP transfer.
  42. */
  43. struct tftp_request {
  44. /** Reference count */
  45. struct refcnt refcnt;
  46. /** Data transfer interface */
  47. struct xfer_interface xfer;
  48. /** URI being fetched */
  49. struct uri *uri;
  50. /** Transport layer interface */
  51. struct xfer_interface socket;
  52. /** Data block size
  53. *
  54. * This is the "blksize" option negotiated with the TFTP
  55. * server. (If the TFTP server does not support TFTP options,
  56. * this will default to 512).
  57. */
  58. unsigned int blksize;
  59. /** File size
  60. *
  61. * This is the value returned in the "tsize" option from the
  62. * TFTP server. If the TFTP server does not support the
  63. * "tsize" option, this value will be zero.
  64. */
  65. unsigned long tsize;
  66. /** Request state
  67. *
  68. * This is the block number to be used in the next ACK sent
  69. * back to the server, i.e. the number of the last received
  70. * data block. The value zero indicates that the last
  71. * received block was an OACK (i.e. that the next ACK will
  72. * contain a block number of zero), and any value less than
  73. * zero indicates that the connection has not yet been opened
  74. * (i.e. that no blocks have yet been received).
  75. */
  76. int state;
  77. /** Peer address
  78. *
  79. * The peer address is determined by the first response
  80. * received to the TFTP RRQ.
  81. */
  82. struct sockaddr_tcpip peer;
  83. /** Retransmission timer */
  84. struct retry_timer timer;
  85. };
  86. /**
  87. * Free TFTP request
  88. *
  89. * @v refcnt Reference counter
  90. */
  91. static void tftp_free ( struct refcnt *refcnt ) {
  92. struct tftp_request *tftp =
  93. container_of ( refcnt, struct tftp_request, refcnt );
  94. uri_put ( tftp->uri );
  95. free ( tftp );
  96. }
  97. /**
  98. * Mark TFTP request as complete
  99. *
  100. * @v tftp TFTP connection
  101. * @v rc Return status code
  102. */
  103. static void tftp_done ( struct tftp_request *tftp, int rc ) {
  104. DBGC ( tftp, "TFTP %p finished with status %d (%s)\n",
  105. tftp, rc, strerror ( rc ) );
  106. /* Stop the retry timer */
  107. stop_timer ( &tftp->timer );
  108. /* Close all data transfer interfaces */
  109. xfer_nullify ( &tftp->socket );
  110. xfer_close ( &tftp->socket, rc );
  111. xfer_nullify ( &tftp->xfer );
  112. xfer_close ( &tftp->xfer, rc );
  113. }
  114. /**
  115. * TFTP requested blocksize
  116. *
  117. * This is treated as a global configuration parameter.
  118. */
  119. static unsigned int tftp_request_blksize = TFTP_MAX_BLKSIZE;
  120. /**
  121. * Set TFTP request blocksize
  122. *
  123. * @v blksize Requested block size
  124. */
  125. void tftp_set_request_blksize ( unsigned int blksize ) {
  126. if ( blksize < TFTP_DEFAULT_BLKSIZE )
  127. blksize = TFTP_DEFAULT_BLKSIZE;
  128. tftp_request_blksize = blksize;
  129. }
  130. /**
  131. * Transmit RRQ
  132. *
  133. * @v tftp TFTP connection
  134. * @ret rc Return status code
  135. */
  136. static int tftp_send_rrq ( struct tftp_request *tftp ) {
  137. struct tftp_rrq *rrq;
  138. const char *path = tftp->uri->path;
  139. size_t len = ( sizeof ( *rrq ) + strlen ( path ) + 1 /* NUL */
  140. + 5 + 1 /* "octet" + NUL */
  141. + 7 + 1 + 5 + 1 /* "blksize" + NUL + ddddd + NUL */
  142. + 5 + 1 + 1 + 1 /* "tsize" + NUL + "0" + NUL */ );
  143. struct io_buffer *iobuf;
  144. DBGC ( tftp, "TFTP %p requesting \"%s\"\n", tftp, path );
  145. /* Allocate buffer */
  146. iobuf = xfer_alloc_iob ( &tftp->socket, len );
  147. if ( ! iobuf )
  148. return -ENOMEM;
  149. /* Build request */
  150. rrq = iob_put ( iobuf, sizeof ( *rrq ) );
  151. rrq->opcode = htons ( TFTP_RRQ );
  152. iob_put ( iobuf,
  153. snprintf ( rrq->data, iob_tailroom ( iobuf ),
  154. "%s%coctet%cblksize%c%d%ctsize%c0", path, 0,
  155. 0, 0, tftp_request_blksize, 0, 0 ) + 1 );
  156. /* RRQ always goes to the address specified in the initial
  157. * xfer_open() call
  158. */
  159. return xfer_deliver_iob ( &tftp->socket, iobuf );
  160. }
  161. /**
  162. * Transmit ACK
  163. *
  164. * @v tftp TFTP connection
  165. * @ret rc Return status code
  166. */
  167. static int tftp_send_ack ( struct tftp_request *tftp ) {
  168. struct tftp_ack *ack;
  169. struct io_buffer *iobuf;
  170. struct xfer_metadata meta = {
  171. .dest = ( struct sockaddr * ) &tftp->peer,
  172. };
  173. DBGC2 ( tftp, "TFTP %p sending ACK for block %d\n",
  174. tftp, tftp->state );
  175. /* Allocate buffer */
  176. iobuf = xfer_alloc_iob ( &tftp->socket, sizeof ( *ack ) );
  177. if ( ! iobuf )
  178. return -ENOMEM;
  179. /* Build ACK */
  180. ack = iob_put ( iobuf, sizeof ( *ack ) );
  181. ack->opcode = htons ( TFTP_ACK );
  182. ack->block = htons ( tftp->state );
  183. /* ACK always goes to the peer recorded from the RRQ response */
  184. return xfer_deliver_iob_meta ( &tftp->socket, iobuf, &meta );
  185. }
  186. /**
  187. * Transmit data
  188. *
  189. * @v tftp TFTP connection
  190. * @ret rc Return status code
  191. */
  192. static int tftp_send_packet ( struct tftp_request *tftp ) {
  193. /* Start retransmission timer */
  194. start_timer ( &tftp->timer );
  195. /* Send RRQ or ACK as appropriate */
  196. if ( tftp->state < 0 ) {
  197. return tftp_send_rrq ( tftp );
  198. } else {
  199. return tftp_send_ack ( tftp );
  200. }
  201. }
  202. /**
  203. * Handle TFTP retransmission timer expiry
  204. *
  205. * @v timer Retry timer
  206. * @v fail Failure indicator
  207. */
  208. static void tftp_timer_expired ( struct retry_timer *timer, int fail ) {
  209. struct tftp_request *tftp =
  210. container_of ( timer, struct tftp_request, timer );
  211. if ( fail ) {
  212. tftp_done ( tftp, -ETIMEDOUT );
  213. } else {
  214. tftp_send_packet ( tftp );
  215. }
  216. }
  217. /**
  218. * Mark TFTP block as received
  219. *
  220. * @v tftp TFTP connection
  221. * @v block Block number
  222. */
  223. static void tftp_received ( struct tftp_request *tftp, unsigned int block ) {
  224. /* Stop the retry timer */
  225. stop_timer ( &tftp->timer );
  226. /* Update state to indicate which block we're now waiting for */
  227. tftp->state = block;
  228. /* Send next packet */
  229. tftp_send_packet ( tftp );
  230. }
  231. /**
  232. * Process TFTP "blksize" option
  233. *
  234. * @v tftp TFTP connection
  235. * @v value Option value
  236. * @ret rc Return status code
  237. */
  238. static int tftp_process_blksize ( struct tftp_request *tftp,
  239. const char *value ) {
  240. char *end;
  241. tftp->blksize = strtoul ( value, &end, 10 );
  242. if ( *end ) {
  243. DBGC ( tftp, "TFTP %p got invalid blksize \"%s\"\n",
  244. tftp, value );
  245. return -EINVAL;
  246. }
  247. DBGC ( tftp, "TFTP %p blksize=%d\n", tftp, tftp->blksize );
  248. return 0;
  249. }
  250. /**
  251. * Process TFTP "tsize" option
  252. *
  253. * @v tftp TFTP connection
  254. * @v value Option value
  255. * @ret rc Return status code
  256. */
  257. static int tftp_process_tsize ( struct tftp_request *tftp,
  258. const char *value ) {
  259. char *end;
  260. tftp->tsize = strtoul ( value, &end, 10 );
  261. if ( *end ) {
  262. DBGC ( tftp, "TFTP %p got invalid tsize \"%s\"\n",
  263. tftp, value );
  264. return -EINVAL;
  265. }
  266. DBGC ( tftp, "TFTP %p tsize=%ld\n", tftp, tftp->tsize );
  267. /* Notify recipient of file size */
  268. xfer_seek ( &tftp->xfer, tftp->tsize, SEEK_SET );
  269. xfer_seek ( &tftp->xfer, 0, SEEK_SET );
  270. return 0;
  271. }
  272. /** A TFTP option */
  273. struct tftp_option {
  274. /** Option name */
  275. const char *name;
  276. /** Option processor
  277. *
  278. * @v tftp TFTP connection
  279. * @v value Option value
  280. * @ret rc Return status code
  281. */
  282. int ( * process ) ( struct tftp_request *tftp, const char *value );
  283. };
  284. /** Recognised TFTP options */
  285. static struct tftp_option tftp_options[] = {
  286. { "blksize", tftp_process_blksize },
  287. { "tsize", tftp_process_tsize },
  288. { NULL, NULL }
  289. };
  290. /**
  291. * Process TFTP option
  292. *
  293. * @v tftp TFTP connection
  294. * @v name Option name
  295. * @v value Option value
  296. * @ret rc Return status code
  297. */
  298. static int tftp_process_option ( struct tftp_request *tftp,
  299. const char *name, const char *value ) {
  300. struct tftp_option *option;
  301. for ( option = tftp_options ; option->name ; option++ ) {
  302. if ( strcasecmp ( name, option->name ) == 0 )
  303. return option->process ( tftp, value );
  304. }
  305. DBGC ( tftp, "TFTP %p received unknown option \"%s\" = \"%s\"\n",
  306. tftp, name, value );
  307. return -EINVAL;
  308. }
  309. /**
  310. * Receive OACK
  311. *
  312. * @v tftp TFTP connection
  313. * @v buf Temporary data buffer
  314. * @v len Length of temporary data buffer
  315. * @ret rc Return status code
  316. */
  317. static int tftp_rx_oack ( struct tftp_request *tftp, void *buf, size_t len ) {
  318. struct tftp_oack *oack = buf;
  319. char *end = buf + len;
  320. char *name;
  321. char *value;
  322. int rc;
  323. /* Sanity check */
  324. if ( len < sizeof ( *oack ) ) {
  325. DBGC ( tftp, "TFTP %p received underlength OACK packet "
  326. "length %d\n", tftp, len );
  327. return -EINVAL;
  328. }
  329. if ( end[-1] != '\0' ) {
  330. DBGC ( tftp, "TFTP %p received OACK missing final NUL\n",
  331. tftp );
  332. return -EINVAL;
  333. }
  334. /* Process each option in turn */
  335. name = oack->data;
  336. while ( name < end ) {
  337. value = ( name + strlen ( name ) + 1 );
  338. if ( value == end ) {
  339. DBGC ( tftp, "TFTP %p received OACK missing value "
  340. "for option \"%s\"\n", tftp, name );
  341. return -EINVAL;
  342. }
  343. if ( ( rc = tftp_process_option ( tftp, name, value ) ) != 0 )
  344. return rc;
  345. name = ( value + strlen ( value ) + 1 );
  346. }
  347. /* Mark as received block 0 (the OACK) */
  348. tftp_received ( tftp, 0 );
  349. return 0;
  350. }
  351. /**
  352. * Receive DATA
  353. *
  354. * @v tftp TFTP connection
  355. * @v iobuf I/O buffer
  356. * @ret rc Return status code
  357. *
  358. * Takes ownership of I/O buffer.
  359. */
  360. static int tftp_rx_data ( struct tftp_request *tftp,
  361. struct io_buffer *iobuf ) {
  362. struct tftp_data *data = iobuf->data;
  363. unsigned int block;
  364. size_t data_len;
  365. int rc;
  366. /* Sanity check */
  367. if ( iob_len ( iobuf ) < sizeof ( *data ) ) {
  368. DBGC ( tftp, "TFTP %p received underlength DATA packet "
  369. "length %d\n", tftp, iob_len ( iobuf ) );
  370. free_iob ( iobuf );
  371. return -EINVAL;
  372. }
  373. /* Extract data */
  374. block = ntohs ( data->block );
  375. iob_pull ( iobuf, sizeof ( *data ) );
  376. data_len = iob_len ( iobuf );
  377. /* Deliver data */
  378. if ( ( rc = xfer_deliver_iob ( &tftp->xfer, iobuf ) ) != 0 ) {
  379. DBGC ( tftp, "TFTP %p could not deliver data: %s\n",
  380. tftp, strerror ( rc ) );
  381. tftp_done ( tftp, rc );
  382. return rc;
  383. }
  384. /* Mark block as received */
  385. tftp_received ( tftp, block );
  386. /* Finish when final block received */
  387. if ( data_len < tftp->blksize )
  388. tftp_done ( tftp, 0 );
  389. return 0;
  390. }
  391. /** Translation between TFTP errors and internal error numbers */
  392. static const uint8_t tftp_errors[] = {
  393. [TFTP_ERR_FILE_NOT_FOUND] = PXENV_STATUS_TFTP_FILE_NOT_FOUND,
  394. [TFTP_ERR_ACCESS_DENIED] = PXENV_STATUS_TFTP_ACCESS_VIOLATION,
  395. [TFTP_ERR_ILLEGAL_OP] = PXENV_STATUS_TFTP_UNKNOWN_OPCODE,
  396. };
  397. /**
  398. * Receive ERROR
  399. *
  400. * @v tftp TFTP connection
  401. * @v buf Temporary data buffer
  402. * @v len Length of temporary data buffer
  403. * @ret rc Return status code
  404. */
  405. static int tftp_rx_error ( struct tftp_request *tftp, void *buf, size_t len ) {
  406. struct tftp_error *error = buf;
  407. unsigned int err;
  408. int rc = 0;
  409. /* Sanity check */
  410. if ( len < sizeof ( *error ) ) {
  411. DBGC ( tftp, "TFTP %p received underlength ERROR packet "
  412. "length %d\n", tftp, len );
  413. return -EINVAL;
  414. }
  415. DBGC ( tftp, "TFTP %p received ERROR packet with code %d, message "
  416. "\"%s\"\n", tftp, ntohs ( error->errcode ), error->errmsg );
  417. /* Determine final operation result */
  418. err = ntohs ( error->errcode );
  419. if ( err < ( sizeof ( tftp_errors ) / sizeof ( tftp_errors[0] ) ) )
  420. rc = -tftp_errors[err];
  421. if ( ! rc )
  422. rc = -PXENV_STATUS_TFTP_CANNOT_OPEN_CONNECTION;
  423. /* Close TFTP request */
  424. tftp_done ( tftp, rc );
  425. return 0;
  426. }
  427. /**
  428. * Receive new data
  429. *
  430. * @v udp UDP connection
  431. * @v data Received data
  432. * @v len Length of received data
  433. * @v st_src Partially-filled source address
  434. * @v st_dest Partially-filled destination address
  435. */
  436. static int tftp_socket_deliver_iob ( struct xfer_interface *socket,
  437. struct io_buffer *iobuf,
  438. struct xfer_metadata *meta ) {
  439. struct tftp_request *tftp =
  440. container_of ( socket, struct tftp_request, socket );
  441. struct sockaddr_tcpip *st_src;
  442. struct tftp_common *common = iobuf->data;
  443. size_t len = iob_len ( iobuf );
  444. int rc = -EINVAL;
  445. /* Sanity checks */
  446. if ( len < sizeof ( *common ) ) {
  447. DBGC ( tftp, "TFTP %p received underlength packet length %d\n",
  448. tftp, len );
  449. goto done;
  450. }
  451. if ( ! meta ) {
  452. DBGC ( tftp, "TFTP %p received packet without metadata\n",
  453. tftp );
  454. goto done;
  455. }
  456. if ( ! meta->src ) {
  457. DBGC ( tftp, "TFTP %p received packet without source port\n",
  458. tftp );
  459. goto done;
  460. }
  461. /* Filter by TID. Set TID on first response received */
  462. st_src = ( struct sockaddr_tcpip * ) meta->src;
  463. if ( tftp->state < 0 ) {
  464. memcpy ( &tftp->peer, st_src, sizeof ( tftp->peer ) );
  465. DBGC ( tftp, "TFTP %p using remote port %d\n", tftp,
  466. ntohs ( tftp->peer.st_port ) );
  467. } else if ( memcmp ( &tftp->peer, st_src,
  468. sizeof ( tftp->peer ) ) != 0 ) {
  469. DBGC ( tftp, "TFTP %p received packet from wrong source (got "
  470. "%d, wanted %d)\n", tftp, ntohs ( st_src->st_port ),
  471. ntohs ( tftp->peer.st_port ) );
  472. goto done;
  473. }
  474. switch ( common->opcode ) {
  475. case htons ( TFTP_OACK ):
  476. rc = tftp_rx_oack ( tftp, iobuf->data, len );
  477. break;
  478. case htons ( TFTP_DATA ):
  479. rc = tftp_rx_data ( tftp, iobuf );
  480. iobuf = NULL;
  481. break;
  482. case htons ( TFTP_ERROR ):
  483. rc = tftp_rx_error ( tftp, iobuf->data, len );
  484. break;
  485. default:
  486. DBGC ( tftp, "TFTP %p received strange packet type %d\n",
  487. tftp, ntohs ( common->opcode ) );
  488. break;
  489. };
  490. done:
  491. free_iob ( iobuf );
  492. return rc;
  493. }
  494. /**
  495. * TFTP connection closed by network stack
  496. *
  497. * @v socket Transport layer interface
  498. * @v rc Reason for close
  499. */
  500. static void tftp_socket_close ( struct xfer_interface *socket, int rc ) {
  501. struct tftp_request *tftp =
  502. container_of ( socket, struct tftp_request, socket );
  503. DBGC ( tftp, "TFTP %p socket closed: %s\n",
  504. tftp, strerror ( rc ) );
  505. tftp_done ( tftp, rc );
  506. }
  507. /** TFTP socket operations */
  508. static struct xfer_interface_operations tftp_socket_operations = {
  509. .close = tftp_socket_close,
  510. .vredirect = xfer_vopen,
  511. .seek = ignore_xfer_seek,
  512. .alloc_iob = default_xfer_alloc_iob,
  513. .deliver_iob = tftp_socket_deliver_iob,
  514. .deliver_raw = xfer_deliver_as_iob,
  515. };
  516. /**
  517. * Close TFTP data transfer interface
  518. *
  519. * @v xfer Data transfer interface
  520. * @v rc Reason for close
  521. */
  522. static void tftp_xfer_close ( struct xfer_interface *xfer, int rc ) {
  523. struct tftp_request *tftp =
  524. container_of ( xfer, struct tftp_request, xfer );
  525. DBGC ( tftp, "TFTP %p interface closed: %s\n",
  526. tftp, strerror ( rc ) );
  527. tftp_done ( tftp, rc );
  528. }
  529. /** TFTP data transfer interface operations */
  530. static struct xfer_interface_operations tftp_xfer_operations = {
  531. .close = tftp_xfer_close,
  532. .vredirect = ignore_xfer_vredirect,
  533. .seek = ignore_xfer_seek,
  534. .alloc_iob = default_xfer_alloc_iob,
  535. .deliver_iob = xfer_deliver_as_raw,
  536. .deliver_raw = ignore_xfer_deliver_raw,
  537. };
  538. /**
  539. * Initiate TFTP download
  540. *
  541. * @v xfer Data transfer interface
  542. * @v uri Uniform Resource Identifier
  543. * @ret rc Return status code
  544. */
  545. int tftp_open ( struct xfer_interface *xfer, struct uri *uri ) {
  546. struct tftp_request *tftp;
  547. struct sockaddr_tcpip server;
  548. int rc;
  549. /* Sanity checks */
  550. if ( ! uri->host )
  551. return -EINVAL;
  552. if ( ! uri->path )
  553. return -EINVAL;
  554. /* Allocate and populate TFTP structure */
  555. tftp = zalloc ( sizeof ( *tftp ) );
  556. if ( ! tftp )
  557. return -ENOMEM;
  558. tftp->refcnt.free = tftp_free;
  559. xfer_init ( &tftp->xfer, &tftp_xfer_operations, &tftp->refcnt );
  560. tftp->uri = uri_get ( uri );
  561. xfer_init ( &tftp->socket, &tftp_socket_operations, &tftp->refcnt );
  562. tftp->state = -1;
  563. tftp->timer.expired = tftp_timer_expired;
  564. /* Open socket */
  565. memset ( &server, 0, sizeof ( server ) );
  566. server.st_port = htons ( uri_port ( tftp->uri, TFTP_PORT ) );
  567. if ( ( rc = xfer_open_named_socket ( &tftp->socket, SOCK_DGRAM,
  568. ( struct sockaddr * ) &server,
  569. uri->host, NULL ) ) != 0 )
  570. goto err;
  571. /* Start timer to initiate RRQ */
  572. start_timer ( &tftp->timer );
  573. /* Attach to parent interface, mortalise self, and return */
  574. xfer_plug_plug ( &tftp->xfer, xfer );
  575. ref_put ( &tftp->refcnt );
  576. return 0;
  577. err:
  578. DBGC ( tftp, "TFTP %p could not create request: %s\n",
  579. tftp, strerror ( rc ) );
  580. tftp_done ( tftp, rc );
  581. ref_put ( &tftp->refcnt );
  582. return rc;
  583. }
  584. /** TFTP URI opener */
  585. struct uri_opener tftp_uri_opener __uri_opener = {
  586. .scheme = "tftp",
  587. .open = tftp_open,
  588. };