home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1997 December / Internet_Info_CD-ROM_Walnut_Creek_December_1997.iso / ien / ien-133 < prev    next >
Text File  |  1988-12-02  |  18KB  |  741 lines

  1. IEN 133
  2.  
  3.  
  4.  
  5.  
  6.  
  7.                            The TFTP Protocol
  8.  
  9.                             January 29, 1980
  10.  
  11.  
  12.  
  13.                             Karen R. Sollins
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22. Summary
  23.  
  24.  
  25.      TFTP is a very simple protocol used to transfer files.  It is from
  26. this that its name comes, Trivial File Transfer Protocol or TFTP.  Each
  27. nonterminal packet is acknowledged separately.  This document describes
  28. the protocol and its types of packets.  The document also explains the
  29. reasons behind some of the design decisions.
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41. Acknowledgements
  42.  
  43.  
  44.      The protocol was originally designed by Noel Chiappa, and was
  45.  
  46. redesigned by him, Bob Baldwin and Dave Clark, with comments from Steve
  47.  
  48. Szymanski.  The original version of this document was written by Bob
  49.  
  50. Baldwin.  The current version of the document includes modifications
  51.  
  52. suggested by Noel Chiappa, Dave Clark, Liza Martin and the author.  The
  53.  
  54. acknowledgement and retransmission scheme was inspired by TCP, and the
  55.  
  56. error mechanism was suggested by PARC's EFTP abort message.
  57.  
  58.  
  59.  
  60. 1: Purpose
  61.  
  62.      TFTP is a simple protocol to transfer files, and therefore was
  63.  
  64. named the Trivial File Transfer Protocol or TFTP.  It is built on top of
  65.  
  66. the Internet User Datagram protocol (UDP or Datagram) [2] so it may be
  67.  
  68. used to move files between machines on different networks.  It is
  69.  
  70. designed to be small and easy to implement.  Therefore, it lacks most of
  71.  
  72. the features of a regular FTP.  The only thing it can do is read and
  73.  
  74. write files (or mail) from/to a remote server.  It cannot list
  75.  
  76. directories, and currently has no provisions for user authentication.
  77.  
  78. In common with other Internet protocols, it passes 8 bit bytes of data.
  79.  
  80.      Three modes of transfer are currently supported: netascii (1);
  81.  
  82. binary, raw 8 bit bytes; mail, netascii characters sent to a user rather
  83.  
  84. than a file.  Additional modes can be defined by pairs of cooperating
  85.  
  86. hosts.
  87.  
  88.  
  89.  
  90.  
  91. 2: Overview of the Protocol
  92.  
  93.      Any transfer begins with a request to read or write a file, which
  94.  
  95. also serves to request a connection.  If the server grants the request,
  96.  
  97. the connection is opened and the file is sent in fixed length blocks of
  98.  
  99. 512 bytes.  Each data packet contains one block of data, and must be
  100.  
  101. _______________
  102. (1) This is ascii as defined in "USA Standard Code for Information
  103. Interchange" [1] with the modifications specified in "Telnet Protocol
  104. Specification" [3].  Note that it is 8 bit ascii.  The term "netascii"
  105. will be used throughout this document to mean this particular version of
  106. ascii.
  107.  
  108.                            - 2 -
  109.  
  110.  
  111.  
  112. acknowledged by an acknowledgment packet before the next packet can be
  113.  
  114. sent.  A packet of less than 512 bytes signals termination of a
  115.  
  116. transfer.  If a packet gets lost in the network, the intended recipient
  117.  
  118. will timeout and may retransmit his last packet (which may be data or an
  119.  
  120. acknowledgment), thus causing the sender of the lost packet to
  121.  
  122. retransmit that lost packet.  The sender has to keep just one packet on
  123.  
  124. hand for retransmission, since the lock step acknowledgment guarantees
  125.  
  126. that all older packets have been received.  Notice that both machines
  127.  
  128. involved in a transfer are considered senders and receivers.  One sends
  129.  
  130. data and receives acknowledgments, the other sends acknowledgments and
  131.  
  132. receives data.
  133.  
  134.      Most errors cause termination of the connection.  An error is
  135.  
  136. signalled by sending an error packet.  This packet is not acknowledged,
  137.  
  138. and not retransmitted (i.e., a TFTP server or user may terminate after
  139.  
  140. sending an error message), so the other end of the connection may not
  141.  
  142. get it.  Therefore timeouts are used to detect such a termination when
  143.  
  144. the error packet has been lost.  Errors are caused by three types of
  145.  
  146. events: not being able to satisfy the request (e.g., file not found, or
  147.  
  148. access violation), receiving a packet which cannot be explained by a
  149.  
  150. delay or duplication in the network (e.g. an incorrectly formed packet),
  151.  
  152. and losing access to a necessary resource (e.g., disc full, or source
  153.  
  154. file truncated during transfer).
  155.  
  156.      TFTP recognizes only one type of error that does not cause
  157.  
  158. termination, the source port of a received packet being incorrect.  In
  159.  
  160.                            - 3 -
  161.  
  162.  
  163.  
  164. this case an error packet is sent to the originating host.  See the
  165.  
  166. section on the Initial Connection Protocol for more details.
  167.  
  168.      This protocol is very restrictive, but that makes it easier to
  169.  
  170. implement.  For example, the fixed length blocks make allocation
  171.  
  172. straight forward, and the lock step acknowledgement provides flow
  173.  
  174. control and eliminates the need to reassemble files.
  175.  
  176.  
  177.  
  178.  
  179. 3: Relation to other Protocols
  180.  
  181.      As mentioned TFTP is designed to be implemented on top of the
  182.  
  183. Datagram protocol.  Since Datagram is implemented on the Internet
  184.  
  185. protocol, packets will have an Internet header, a Datagram header, and a
  186.  
  187. TFTP header.  Additionally, the packets may have a header (LNI, ARPA
  188.  
  189. header, etc.) to allow them through the local transport medium.  As
  190.  
  191. shown in Figure 1, the order of the contents of a packet will be local
  192.  
  193. medium header, if used, Internet header, Datagram header, TFTP header,
  194.  
  195. followed by the remainder of the TFTP packet.  (This may or may not be
  196.  
  197. data depending on the type of packet as specified in the TFTP header.)
  198.  
  199. TFTP does not specify any of the values in the Internet header.
  200.  
  201.      The source and destination port fields of the Datagram header (its
  202.  
  203. format is given in the appendix) are used by TFTP and the length field
  204.  
  205. reflects the size of the TFTP packet.  The transfer identifiers (TID's)
  206.  
  207. used by TFTP are passed to the Datagram layer to be used as ports.
  208.  
  209. Therefore for they must be between 0 and 65,535.  The initialization of
  210.  
  211. TID's is discussed in the section on initial connection protocol.
  212.  
  213.                            - 4 -
  214.  
  215.  
  216.  
  217.      The TFTP header consists of a 2 byte opcode field which indicates
  218.  
  219. the packet's type (e.g., DATA, ERROR, etc.)  These opcodes and the
  220.  
  221. formats of the various types of packets are discussed further in the
  222.  
  223. section on TFTP packets.
  224.  
  225.  
  226. Figure 1. Order of Headers
  227.  
  228.  ---------------------------------------------------
  229. |  Local Medium  |  Internet  |  Datagram  |  TFTP  |
  230.  ---------------------------------------------------
  231.  
  232.  
  233.  
  234.  
  235.  
  236. 4: Initial Connection Protocol
  237.  
  238.      A transfer is established by sending a request (WRQ to write onto a
  239.  
  240. foreign file system, or RRQ to read from it), and receiving a positive
  241.  
  242. reply, an acknowledgment packet for write, or the first data packet for
  243.  
  244. read.  In general an acknowledgment packet will contain the block number
  245.  
  246. of the data packet being acknowledged.  Each data packet has associated
  247.  
  248. with it a block number;  block numbers are consecutive and begin with
  249.  
  250. one.  Since the positive response to a write request is an
  251.  
  252. acknowledgment packet, in this special case the block number will be
  253.  
  254. zero.  (Normally, since an acknowledgment packet is acknowledging a data
  255.  
  256. packet, the acknowledgment packet will contain the block number of the
  257.  
  258. data packet being acknowledged.) If the reply is an error packet, then
  259.  
  260. the request is denied for the reason stated in the error packet.
  261.  
  262.      In order to create a connection, TID's to be used for the duration
  263.  
  264. of the connection are chosen by the two ends of that connection.  The
  265.  
  266. TID's chosen for a connection should be randomly chosen, so that the
  267.  
  268.                            - 5 -
  269.  
  270.  
  271.  
  272. probability that the same number is chosen twice in immediate succession
  273.  
  274. is very low.  Every packet has associated with it two TID's, the source
  275.  
  276. TID and the destination TID.  A requesting host chooses its source TID
  277.  
  278. as described above, and sends its initial request to the known TID 69
  279.  
  280. (105 octal) on the serving host.  The response to the request, under
  281.  
  282. normal operation, uses a TID chosen by the server as its source TID and
  283.  
  284. the TID chosen for the previous message by the requestor as its
  285.  
  286. destination TID.  The two chosen TID's are then used for the remainder
  287.  
  288. of the transfer.
  289.  
  290.      As an example, the following shows the steps used to establish a
  291.  
  292. connection to write a file.  Note that WRQ, ACK, and DATA are the names
  293.  
  294. of the write request, acknowledgment, and data types of packets
  295.  
  296. respectively.  The Appendix contains a similar example for reading a
  297.  
  298. file.
  299.  
  300.  
  301. 1.  Host A sends a "WRQ" to host B with
  302.  
  303.         source= A's TID,  destination= 69.
  304.  
  305. 2.  Host B sends a "ACK" (with block number= 0) to host A with
  306.  
  307.         source= B's TID,  destination= A's TID.
  308.  
  309. 3.  Host A sends a "DATA" (with block number= 1) to host B with
  310.  
  311.         source= A's TID,  destination= B's TID.
  312.  
  313. 4.  Host B sends a "ACK" (with block number= 1) to host A with
  314.  
  315.         source= B's TID,  destination= A's TID.
  316.  
  317.  
  318.      In step three, and in all succeeding steps, the hosts should make
  319.  
  320. sure that the source TID matches the value that was agreed on in step 2.
  321.  
  322.                            - 6 -
  323.  
  324.  
  325.  
  326. If it doesn't match, an error packet should be sent to the originator,
  327.  
  328. but the connection should not be aborted.  The following example
  329.  
  330. demonstates the problem this and the randomly chosen TID's are trying to
  331.  
  332. solve.
  333.  
  334.      Host A sends a request to host B.  Somewhere in the network, the
  335.  
  336. request packet is duplicated, and as a result two acknowledgments are
  337.  
  338. returned to host A, with different TID's chosen on host B in repsonse to
  339.  
  340. the two requests.  When the first response arrives, host A continues the
  341.  
  342. connection.  When the second response to the request arrives, it should
  343.  
  344. be rejected, but there is no reason to terminate the first connection.
  345.  
  346. Therefore, if different TID's are chosen on host B and host A checks the
  347.  
  348. source TID's of the messages it receives, the first connection can be
  349.  
  350. maintained while the second is rejected.
  351.  
  352.  
  353.  
  354.  
  355. 5: TFTP Packets
  356.  
  357.      TFTP supports five types of packets, all of which have been
  358.  
  359. mentioned above:
  360.  
  361.  
  362.           opcode  operation
  363.  
  364.             1     Read request (RRQ)
  365.  
  366.             2     Write request (WRQ)
  367.  
  368.             3     Acknowledgment (ACK)
  369.  
  370.             4     Data (DATA)
  371.  
  372.             5     Error (ERROR)
  373.  
  374.                            - 7 -
  375.  
  376.  
  377.  
  378. The TFTP header of a packet contains the opcode associated with that
  379.  
  380. packet.
  381.  
  382.  
  383. Figure 2. RRQ/WRQ
  384.  
  385.  2 bytes     string    1 byte     string   1 byte
  386.  ------------------------------------------------
  387. | Opcode |  Filename  |   0  |    Mode    |   0  |
  388.  ------------------------------------------------
  389.  
  390.  
  391.      RRQ and WRQ packets (opcodes 1 and 2 respectively) have the format
  392.  
  393. shown in Figure 2.  The file name is a sequence of bytes in netascii
  394.  
  395. terminated by a zero byte.  The mode field contains the string
  396.  
  397. "netascii", "binary", or "mail" in netascii indicating the three modes
  398.  
  399. defined in the protocol.  A host which receives netascii mode data must
  400.  
  401. translate the data to its own format.  Presumably, every host will
  402.  
  403. translate its character set to and from netascii.  Binary mode allows
  404.  
  405. the two communicating hosts to impose their own interpretation on the
  406.  
  407. data being transmitted;  between similar machines binary mode can be
  408.  
  409. used to avoid the conversion overhead.  If a host receives a binary file
  410.  
  411. and then returns it, the returned file must be identical to the file it
  412.  
  413. received.  Mail mode uses the name of a mail recipient in place of a
  414.  
  415. file and must begin with a WRQ.  Otherwise it is identical to netascii
  416.  
  417. mode.
  418.  
  419.  
  420. Figure 3. DATA
  421.  
  422.  2 bytes     2 bytes      n bytes
  423.  ----------------------------------
  424. | Opcode |   Block #  |   Data     |
  425.  ----------------------------------
  426.  
  427.                                  - 8 -
  428.  
  429.  
  430.  
  431. Data is actually transferred in DATA packets depicted in Figure 3.  DATA
  432.  
  433. packets (opcode = 4) have a block number and data field.  The block
  434.  
  435. numbers on data packets begin with one and increase by one for each new
  436.  
  437. block of data.  This restriction allows the program to use a single
  438.  
  439. number to discriminate between new packets and duplicates.  The data
  440.  
  441. field is from zero to 512 bytes long.  If it is 512 bytes long, the
  442.  
  443. block is not the last block of data; if it is from zero to 511 bytes
  444.  
  445. long, it signals the last data packet.  (See the section on Normal
  446.  
  447. Termination for details.)
  448.  
  449.  
  450. Figure 4. ACK packet
  451.  
  452.  2 bytes     2 bytes
  453.  ---------------------
  454. | Opcode |   Block #  |
  455.  ---------------------
  456.  
  457.  
  458.      All packets other than those used for termination are acknowledged
  459.  
  460. individually.  Sending a DATA packet is an acknowledgment for the ACK
  461.  
  462. packet of the previous DATA packet.  The WRQ and DATA packets are
  463.  
  464. acknowledged by ACK or ERROR packets, while RRQ and ACK packets are
  465.  
  466. acknowledged by DATA or ERROR packets.  Figure 4 depicts an ACK packet;
  467.  
  468. the opcode is 3.  The block number in an ACK echoes the block number of
  469.  
  470. the DATA packet being acknowledged.  A WRQ is acknowledged with an ACK
  471.  
  472. packet having a block number of zero.
  473.  
  474.                                  - 9 -
  475.  
  476.  
  477.  
  478. Figure 5. ERROR packet
  479.  
  480.  2 bytes     2 bytes      string    1 byte
  481.  -----------------------------------------
  482. | Opcode |  ErrorCode |   ErrMsg   |   0  |
  483.  -----------------------------------------
  484.  
  485.  
  486.      An ERROR packet (opcode 5) takes the form depicted in Figure 5.  An
  487.  
  488. ERROR packet can be the acknowledgment of any other type of packet.  The
  489.  
  490. error code is a small integer indicating the nature of the error.  A
  491.  
  492. table of its values and meanings is given in the appendix.  The error
  493.  
  494. message is intended for human consumption, and should be in netascii.
  495.  
  496. Like all other strings, it is terminated with a zero byte.
  497.  
  498.  
  499.  
  500.  
  501. 6: Normal Termination
  502.  
  503.      The end of a transfer is marked by a DATA packet that contains
  504.  
  505. between 0 and 511 bytes of data (i.e. Datagram length < 516).  This
  506.  
  507. packet is acknowledged by an ACK packet like all other DATA packets.
  508.  
  509. The final ACK packet is never retransmitted; the host acknowledging the
  510.  
  511. final DATA packet may terminate its side of the connection on sending
  512.  
  513. the final ACK.  On the other hand, the host sending the last DATA must
  514.  
  515. retransmit it until the packet is acknowledged or the sending host times
  516.  
  517. out.  If the response is an ACK, the transmission was completed
  518.  
  519. successfully.  If it is an ERROR (unknown transfer ID), or the sender of
  520.  
  521. the data times out and is not prepared to retransmit any more, the
  522.  
  523. transfer may still have been completed successfully, after which the
  524.  
  525. acknowledger may have experienced a problem.  It is also possible in
  526.  
  527.                            - 10 -
  528.  
  529.  
  530.  
  531. this case that the transfer was unsuccessful.  In any case, the
  532.  
  533. connection has been closed.
  534.  
  535.  
  536.  
  537.  
  538. 7: Premature Termination
  539.  
  540.      If a request can not be granted, or some error occurs during the
  541.  
  542. transfer, then an ERROR packet (opcode 5) is sent.  This is only a
  543.  
  544. courtesy since it will not be retransmitted or acknowledged, so it may
  545.  
  546. never be received.  Timeouts must also be used to detect errors.
  547.  
  548.                            - 11 -
  549.  
  550.  
  551.  
  552. APPENDIX
  553.  
  554.  
  555.  
  556.  
  557. Order of Headers
  558.  
  559.  
  560.                                                 2 bytes
  561.  ----------------------------------------------------------
  562. |  Local Medium  |  Internet  |  Datagram  |  TFTP Opcode  |
  563.  ----------------------------------------------------------
  564.  
  565.  
  566.  
  567. TFTP Formats
  568.  
  569.  
  570. Type  Op #     Format without header
  571. ____________________________________
  572.  
  573.  
  574.       2 bytes    string   1 byte     string   1 byte
  575.       -----------------------------------------------
  576. RRQ/ | 01/02 |  Filename  |   0  |    Mode    |   0  |
  577. WRQ   -----------------------------------------------
  578.  
  579.  
  580.  
  581.       2 bytes    2 bytes       n bytes
  582.       ---------------------------------
  583. DATA | 03    |   Block #  |    Data    |
  584.       ---------------------------------
  585.  
  586.  
  587.      2 bytes    2 bytes
  588.      -------------------
  589. ACK | 04    |   Block #  |
  590.      --------------------
  591.  
  592.  
  593.        2 bytes  2 bytes        string    1 byte
  594.        ----------------------------------------
  595. ERROR | 05    |  ErrorCode |   ErrMsg   |   0  |
  596.        ----------------------------------------
  597.  
  598.                            - 12 -
  599.  
  600.  
  601.  
  602. Initial Connection Protocol for reading a file
  603.  
  604.  
  605. 1.  Host A sends a "RRQ" to host B with
  606.  
  607.         source= A's TID, destination= 69.
  608.  
  609. 2.  Host B sends a "DATA" (with block number= 1) to host A with
  610.  
  611.         source= B's TID, destination= A's TID.
  612.  
  613. 3.  Host A sends an "ACK" (with block number= 1) to host B with
  614.  
  615.         source= A's TID, destination= B's TID.
  616.  
  617.                            - 13 -
  618.  
  619.  
  620.  
  621. Error Codes
  622.  
  623.  
  624.  
  625. Value   Meaning
  626.  
  627. _______________
  628.  
  629.  
  630. 0       Not defined, see error message (if any).
  631.  
  632. 1       File not found.
  633.  
  634. 2       Access violation.
  635.  
  636. 3       Disc full or allocation exceeded.
  637.  
  638. 4       Illegal TFTP operation.
  639.  
  640. 5       Unknown transfer ID.
  641.  
  642.                            - 14 -
  643.  
  644.  
  645.  
  646. Internet User Datagram Header
  647.  
  648.  
  649.  
  650. Format
  651.  
  652.  
  653.  
  654.  
  655.  
  656.  0                   1                   2                   3
  657.  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  658. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  659. |          Source Port          |       Destination Port        |
  660. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  661. |            Length             |           Checksum            |
  662. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  663.  
  664.  
  665.  
  666.  
  667. Values of Fields
  668.  
  669.  
  670. Source Port     Picked by originator of packet.
  671. Dest. Port      Picked by destination machine (69 for RRQ or WRQ).
  672. Length          Number of bytes in packet after Datagram header.
  673. Checksum        Reference 2 describes rules for computing checksum.
  674.                 Field contains zero if unused.
  675.  
  676.  
  677. Note: TFTP passes transfer identifiers (TID's) to the Internet User
  678. Datagram protocol to be used as the source and destination ports.
  679.  
  680.                            - 15 -
  681.  
  682.  
  683.  
  684.  
  685.  
  686.  
  687. References
  688.  
  689.  
  690. 1.      USA Standard Code for Information Interchange,
  691.         USASI X3.4-1968.
  692.  
  693. 2.      Postel, Jon., "User Datagram Protocol," IEN 88, May 2,
  694.         1979.
  695.  
  696. 3.      "Telnet Protocol Specification," RFC552, NIC 18639,
  697.         August, 1973.
  698.  
  699.  
  700.  
  701.  
  702.  
  703.  
  704.  
  705.  
  706.  
  707.  
  708.  
  709.  
  710.  
  711.  
  712.  
  713.  
  714.  
  715.  
  716.  
  717.  
  718.  
  719.  
  720.  
  721.  
  722.  
  723.  
  724.  
  725.  
  726.  
  727.  
  728.  
  729.  
  730.  
  731.  
  732.  
  733.  
  734.  
  735.  
  736.  
  737.  
  738.  
  739.  
  740.  
  741.