TFTP Usage and Design � RFC 783, 1350 CSCE 515: Computer Network � Transfer files between processes. Programming ------ TFTP + Errors � Minimal overhead (no security). Wenyuan Xu � Designed for UDP, although could be used Department of Computer Science and Engineering with many transport protocols. University of South Carolina CSCE515 – Computer Network Programming Diskless Workstation Booting 1 TFTP Usage and Design (cont.) The call for help � Easy to implement Help! I don't know who I am! My Ethernet address is: � Small - possible to include in firmware 4C:23:17:77:A6:03 RARP � Used to bootstrap workstations and Diskless network devices. Workstation CSCE515 – Computer Network Programming CSCE515 – Computer Network Programming The answer from the all-knowing The request for instructions I need the file named boot-128.113.45.211 I know all! You are to be RARP know as: 128.113.45.211 Server Diskless Workstation Diskless TFTP Request (Broadcast) Workstation RARP REPLY CSCE515 – Computer Network Programming CSCE515 – Computer Network Programming
TFTP Protocol The dialog 5 message types: � Read request here is part 1 TFTP � Write request Server I got part 1 � Data � ACK (acknowledgment) here is part 2 Diskless � Error Workstation boot file TFTP File Transfer CSCE515 – Computer Network Programming CSCE515 – Computer Network Programming Messages Message Formats � Each is an independent UDP Datagram RRQ OPCODE FILENAME 0 MODE 0 WRQ � Each has a 2 byte opcode (1st 2 bytes) DATA OPCODE BLOCK# DATA � The structure of the rest of the datagram depends on the opcode. OPCODE BLOCK# ACK OPCODE BLOCK# ERROR MESSAGE 0 error IP UDP TFTP message header header 2 bytes 2 bytes CSCE515 – Computer Network Programming CSCE515 – Computer Network Programming Write Request Read Request filename mode filename mode 01 0 0 02 0 0 null terminated ascii null terminated ascii string string null terminated null terminated ascii ascii string string null terminated ascii null terminated ascii string string null terminated ascii null terminated ascii string string containing name of file containing transfer mode containing name of file containing transfer mode containing name of file containing transfer mode containing name of file containing transfer mode 2 byte opcode 2 byte opcode 2 byte opcode 2 byte opcode network byte order network byte order network byte order network byte order variable length fields! variable length fields! variable length fields! variable length fields! CSCE515 – Computer Network Programming CSCE515 – Computer Network Programming
TFTP Data Packet TFTP Acknowledgment block # data 0 to 512 bytes 03 block # 04 2 byte block number 2 byte block number 2 byte block number 2 byte block number network byte order network byte order 2 byte opcode 2 byte opcode network byte order network byte order network byte order network byte order 2 byte opcode opcode 2 byte all data packets have 512 bytes all data packets have 512 bytes network byte order network byte order except the last one. except the last one. CSCE515 – Computer Network Programming CSCE515 – Computer Network Programming TFTP Error Packet TFTP Error Codes (16 bit int) 0 - not defined errcode errstring 05 0 1 - File not found 2 - Access violation null terminated ascii ascii error string error string null terminated 3 - Disk full 2 byte opcode 2 byte opcode network byte order network byte order 4 - Illegal TFTP operation 2 byte error code 5 - Unknown port 2 byte error code network byte order network byte order 6 - File already exists 7 - No such user CSCE515 – Computer Network Programming CSCE515 – Computer Network Programming TFTP transfer modes NetAscii Transfer Mode Unix - end of line marker is just ' \n ' � “netascii” : for transferring text files. � all lines end with \r\n (CR,LF). � receiving a file � provides standard format for transferring text files. � you need to remove ' \r ' before storing data. � both ends responsible for converting to/from � sending a file netascii format. � you need to replace every ' \n ' with " \r\n " before sending � “octet” : for transferring binary files. � no translation done. CSCE515 – Computer Network Programming CSCE515 – Computer Network Programming
Concurrency UDP sockets � TFTP servers use a "well known address" (UDP port number). Server FIFO Client 2 � How would you implement a concurrent Client 1 Socket server? recv buf � forking (alone) may lead to problems! UDP UDP UDP � Can provide concurrency without forking, but it requires lots of bookkeeping. UDP datagram UDP datagram CSCE515 – Computer Network Programming CSCE515 – Computer Network Programming TCP sockets TFTP Concurrency � According to the protocol, the server may create a new udp port and send the initial fork response from this new port. Server fork Listen Server Client 1 Client 2 Child Child Server � The client should recognize this, and send TCP TCP all subsequent messages to the new port. TCP CSCE515 – Computer Network Programming CSCE515 – Computer Network Programming UDP sockets Connected UDP socket TFTP Server App1 App2 Client 2 Client 1 write read Store App2 IP address UDP UDP(9001) UDP(69) UDP(9000) and port # from UDP UDP UDP ??? connect connected UDP datagram UDP datagram UDP datagram UDP datagram from some UDP datagram other IP or port # CSCE515 – Computer Network Programming CSCE515 – Computer Network Programming
Who can call connect ? Questions � Can UDP socket connected to a broadcast address? Server FIFO Client 2 � A: yes, a connected UDP socket exchanges Client 1 Socket datagrams with only one IP address recv buf UDP UDP UDP � Server A is connected to a broadcast address, so…. UDP datagram UDP datagram � Can this UDP socket send? � Can this UDP socket Receive? CSCE515 – Computer Network Programming CSCE515 – Computer Network Programming RRQ (read request) WRQ (write request) � Client sends WRQ � Client sends RRQ � Server sends back ack #0 � Server sends back data chunk #1 � Client data chunk #1 (the first chunk!) � Client acks chunk #1 � Server acks data chunk #1 � … � Server sends data chunk #2 � ... there is no data chunk #0! � Stop and wait � What’s the advantage? � Disadvantage? CSCE515 – Computer Network Programming CSCE515 – Computer Network Programming Lost Data Packets - When is it over? Original Protocol Specification � There is no length of file field sent! � Sender uses a timeout with retransmission. � All data messages except the last one � sender could be client or server. contain 512 bytes of data. � Duplicate data packets must be recognized and ACK retransmitted. � The last data message might contain 0 � This original protocol suffers from the bytes of data! "sorcerer’s apprentice syndrome". � When to close the UDP socket? CSCE515 – Computer Network Programming CSCE515 – Computer Network Programming
Sorcerer’s Apprentice Syndrome The Fix send DATA[n] � Sender should not resend a data packet in receive DATA[n] send ACK[n] response to a duplicate ACK. (time out) retransmit DATA[n] receive DATA[n] (dup) receive ACK[n] � If sender receives ACK[n] - don’t send send ACK[n] (dup) send DATA[n+1] DATA[n+1] if the ACK was a duplicate. receive DATA[n+1] receive ACK[n] (dup) send ACK[n+1] send DATA[n+1](dup) receive DATA[n+1] (dup) ... send ACK[n+1] (dup) CSCE515 – Computer Network Programming CSCE515 – Computer Network Programming Security Issues � No username or password What if more than 65535 chunks are sent? � Obtain copies of Unix password file and then try to guess password � 65536 blocks x 512 bytes/block = 33,554,432 bytes. � Solution: � Only files in a specific directory can be accessed � The RFC does not address this issue! � Give lower access priority � Remember that the network can duplicate packets! CSCE515 – Computer Network Programming CSCE515 – Computer Network Programming System Calls and Errors � In general, systems calls return a negative number to indicate an error. � We often want to find out what error. Error Handling � Servers generally add this information to a log. � Clients generally provide some information to the user. CSCE515 – Computer Network Programming
Recommend
More recommend