Uploaded on

 

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
1,383
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
9
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. TFTP Usage and Design RFC 783, 1350 CSCE 515: Computer Network Transfer files between processes. Programming ------ TFTP + Errors Minimal overhead (no security). Wenyuan Xu Department of Computer Science and Engineering Designed for UDP, although could be used University of South Carolina with many transport protocols. CSCE515 – Computer Network ProgrammingTFTP Usage and Design (cont.) Diskless Workstation Booting 1 Easy to implement The call for help Help! I dont 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 ProgrammingThe answer from the all-knowing The request for instructions I need the file named I know all! You are to be RARP boot-128.113.45.211 know as: 128.113.45.211 Server Diskless Diskless Workstation TFTP Request (Broadcast) Workstation RARP REPLY CSCE515 – Computer Network Programming CSCE515 – Computer Network Programming
  • 2. The dialog TFTP Protocol 5 message types: here is part 1 Read request TFTP Write request I got part 1 Server Data here is part 2 ACK (acknowledgment) 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 WRQ OPCODE FILENAME 0 MODE 0 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. ACK OPCODE BLOCK# error OPCODE BLOCK# ERROR MESSAGE 0 IP UDP TFTP message header header 2 bytes 2 bytes CSCE515 – Computer Network Programming CSCE515 – Computer Network Programming Write Request Read Request 01 filename 0 mode 0 02 filename 0 mode 0 null terminated ascii string null terminated ascii string null terminated ascii string null terminated ascii string containing name of file containing transfer mode containing name of file containing transfer mode2 byte opcode 2 byte opcodenetwork byte order network byte order variable length fields! variable length fields! CSCE515 – Computer Network Programming CSCE515 – Computer Network Programming
  • 3. TFTP Data Packet TFTP Acknowledgment 03 block # data 0 to 512 bytes 04 block # 2 byte block number network byte order 2 byte opcode 2 byte block number network byte order network byte order2 byte opcode all data packets have 512 bytesnetwork byte order except the last one. CSCE515 – Computer Network Programming CSCE515 – Computer Network Programming TFTP Error Packet TFTP Error Codes (16 bit int) 05 errcode errstring 0 0 - not defined 1 - File not found 2 - Access violation null terminated ascii error string 2 byte opcode 3 - Disk full network byte order 4 - Illegal TFTP operation 2 byte error code 5 - Unknown port 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 “netascii” : for transferring text files. Unix - end of line marker is just n all lines end with rn (CR,LF). provides standard format for transferring text receiving a file 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 "rn" “octet” : for transferring binary files. before sending no translation done. CSCE515 – Computer Network Programming CSCE515 – Computer Network Programming
  • 4. Concurrency UDP sockets TFTP servers use a "well known address" (UDP port number). Server FIFO Client 2 Client 1 How would you implement a concurrent 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 ProgrammingTCP sockets TFTP Concurrency According to the protocol, the server may create a new udp port and send the initial forkClient 1 Server Child fork Listen Server Server Child Client 2 response from this new port. TCP TCP The client should recognize this, and send TCP all subsequent messages to the new port. CSCE515 – Computer Network Programming CSCE515 – Computer Network ProgrammingUDP sockets Connected UDP socket TFTP Server App1 Client 2 App2 Client 1 read write Store App2 IP address UDP(9001) UDP(69) UDP(9000) UDP UDP and port # from UDP ??? connect UDP 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
  • 5. Who can call connect? Questions Can UDP socket connected to a broadcast Server address? FIFO Client 2 Client 1 A: yes, a connected UDP socket exchanges Socket recv buf datagrams with only one IP address UDP UDP UDP Server A is connected to a broadcast UDP datagram UDP datagram address, so…. Can this UDP socket send? Can this UDP socket Receive? CSCE515 – Computer Network Programming CSCE515 – Computer Network ProgrammingRRQ (read request) WRQ (write request) Client sends RRQ Client sends WRQ 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 ProgrammingWhen is it over? Lost Data Packets - There is no length of file field sent! Original Protocol Specification 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 bytes of data! This original protocol suffers from the "sorcerer’s apprentice syndrome". When to close the UDP socket? CSCE515 – Computer Network Programming CSCE515 – Computer Network Programming
  • 6. Sorcerer’s Apprentice Syndrome The Fix send DATA[n] receive DATA[n] Sender should not resend a data packet in (time out) send ACK[n] response to a duplicate ACK. retransmit DATA[n] receive ACK[n] receive DATA[n] (dup) If sender receives ACK[n] - don’t send send DATA[n+1] send ACK[n] (dup) DATA[n+1] if the ACK was a duplicate. receive ACK[n] (dup) receive DATA[n+1]send DATA[n+1](dup) send ACK[n+1] ... receive DATA[n+1] (dup) send ACK[n+1] (dup) CSCE515 – Computer Network Programming CSCE515 – Computer Network Programming Security Issues No username or password Obtain copies of Unix password file and What if more than 65535 chunks are sent? then try to guess password 65536 blocks x 512 bytes/block = 33,554,432 Solution: bytes. 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
  • 7. extern int errno; When is errno valid? Whenever an error occurs, system calls errno is valid only after a system call set the value of the global variable errno. has returned an error. You can check errno for specific errors. You can use support functions to print out or System calls dont clear errno on success. log an ASCII text error message. If you make another system call you may lose the previous value of errno. printf makes a call to write! CSCE515 – Computer Network Programming CSCE515 – Computer Network ProgrammingError codes Support Routines #include <errno.h> void perror(const char *string);Error codes are defined in errno.hEAGAIN EBADF EACCESS In stdio.hEBUSY EINTR EINVALEIO ENODEV EPIPE char *strerror(int errnum);… In string.h CSCE515 – Computer Network Programming CSCE515 – Computer Network ProgrammingGeneral Strategies Example wrapper Include code to check for errors after every system call. int Socket( int f,int t,int p) { int n; if ( (n=socket(f,t,p)) < 0 )) { Develop "wrapper functions" that do the checking for you. perror("Fatal Error"); exit(1); } Develop layers of functions, each hides some of the error-handling details. return(n); } CSCE515 – Computer Network Programming CSCE515 – Computer Network Programming
  • 8. What is fatal? Wrappers are great! How do you know what should be a fatal Wrappers like those used in the text can error (program exits)? make code much more readable. Common sense. If the program can continue – it should. There are always situations in which you cannot use the wrappers Example – if a server cant create a socket, or Sometimes system calls are "interrupted" cant bind to its port - there is no sense (EINTR) – this is not always a fatal error ! continuing… CSCE515 – Computer Network Programming CSCE515 – Computer Network ProgrammingWord of Caution Another approach Instead of simple wrapper functions, If you use the code from the book for your you might develop a layered system. projects, you must understand it! The idea is to "hide" the sockaddr and The library of code used in the text is extensive: error handling details behind a few Wrappers call custom error handing code. custom functions: Custom error handling code make assumptions about int tcp_client(char *server, int port); having other custom library functions. int tcp_server(int port); … CSCE515 – Computer Network Programming CSCE515 – Computer Network ProgrammingLayers and Code Re-use The Best Approach to Developing general functions that might be handling errors re-used in other programs is obviously "a good thing". There is no best approach. Layering is beneficial even if the code is Do what works for you. not intended to be re-used: Make sure you check all system calls for hide error-handling from "high-level" code. errors!!!! hide other details. Not checking can lead to security problems! often makes debugging easier. Not checking can lead to bad grades on homework projects! CSCE515 – Computer Network Programming CSCE515 – Computer Network Programming
  • 9. Assignment & Next time Reading: TI 15 ** RFC 1350 TFTP* Next Lecture: I/O Multiplexing and select() CSCE515 – Computer Network Programming