Tuesday, January 5, 2010

Transmission Control Protocol (TCP)





TCP Header

   Bit offset
 0
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
            0
                                       Source       port
                                           Destination     port


     32               Sequence number 
     64                Acknowledgment number 



96   Data offset
  Reserved 

C
W
R

E
C
E

U
R
G

A
C
K

P
S
H

R
S
T

S
Y
N

F
I
N


window Size
  128

Urgent pointer


  160             options(if data offset>5)
 









Tcp  is on of the core protocal for all protocal suite.


TCP operates at a higher level, concerned only with the two end systems.




TCP segment structure

  • Source port (16 bits) – identifies the sending port
  • Destination port (16 bits) – identifies the receiving port
  • Sequence number (32 bits) – has a dual role
  • If the SYN flag is set, then this is the initial sequence number. The sequence number of the actual first data byte (and the acknowledged number in the corresponding ACK) will then be this sequence number plus 1.
  • If the SYN flag is clear, then this is the sequence number of the first data byte
  • Acknowledgment number (32 bits) – if the ACK flag is set then the value of this field is the next sequence number that the receiver is expecting. This acknowledges receipt of all prior bytes (if any). The first ACK sent by each end acknowledges the other end's initial sequence number itself, but no data.
  • Data offset (4 bits) – specifies the size of the TCP header in 32-bit words. The minimum size header is 5 words and the maximum is 15 words thus giving the minimum size of 20 bytes and maximum of 60 bytes, allowing for up to 40 bytes of options in the header. This field gets its name from the fact that it is also the offset from the start of the TCP segment to the actual data.
  • Reserved (4 bits) – for future use and should be set to zero
  • Flags (8 bits) (aka Control bits) – contains 8 1-bit flags
CWR (1 bit) – Congestion Window Reduced (CWR) flag is set by the sending host to indicate that it received a TCP segment with the ECE flag set and had responded in congestion control mechanism
  • ECE (1 bit) – ECN-Echo indicates
  • If the SYN flag is set, that the TCP peer is ECN capable.
  • If the SYN flag is clear, that a packet with Congestion Experienced flag in IP header set is received during normal transmission
  • (1 bit) – indicates that the Urgent pointer field is significant
  • ACK (1 bit) – indicates that the Acknowledgment field is significant. All packets after the initial SYN packet sent by the client should have this flag set.
  • PSH (1 bit) – Push function
  • RST (1 bit) – Reset the connection
  • SYN (1 bit) – Synchronize sequence numbers. Only the first packet sent from each end should have this flag set. Some other flags change meaning based on this flag, and some are only valid for when it is set, and others when it is clear.
  • FIN (1 bit) – No more data from sender
Window (16 bits) – the size of the receive window, which specifies the number of bytes (beyond the sequence number in the acknowledgment field) that the receiver is currently willing to receive

 

  • Checksum (16 bits) – The 16-bit checksum field is used for error-checking of the header and data
  •  
  • Urgent pointer (16 bits) – if the URG flag is set, then this 16-bit field is an offset from the sequence number indicating the last urgent data byte
  •  
  • Options (Variable 0-320 bits, divisible by 32) – The length of this field is determined by the data offset field. Options 0 and 1 are a single byte (8 bits) in length. The remaining options indicate the total length of the option (expressed in bytes) in the second byte. Some options may only be sent when SYN is set; they are indicated below as .
  •  
  • 0 (8 bits) - End of options list
  •  
  • 1 (8 bits) - No operation (NOP, Padding) This may be used to align option fields on 32-bit boundaries for better performance.
  •  
  • 2,4,SS (32 bits) - Maximum segment size 

  • 3,3,S (24 bits) - Window scale
  •  
  • 4,2 (16 bits) - Selective Acknowledgement supported. 
  •  
  • 5,N,BBBB,EEEE,... (variable bits, N is either 10, 18, 26, or 34)- Selective ACKnowlegement (SACK) These first two bytes are followed by a list of 1-4 blocks being selectively acknowledged, specified as 32-bit begin/end pointers.
  •  
  • 8,10,TTTT,EEEE (80 bits)- Timestamp and echo of previous timestamp 

  • 14,3,S (24 bits) - TCP Alternate Checksum Request. 

  • 15,N,... (variable bits) - TCP Alternate Checksum Data. 

 


Protocol operation

 

  • LISTEN : In case of a server, waiting for a connection request from any remote client. 
  •  
  • SYN-SENT : waiting for the remote peer to send back a TCP segment with the SYN and ACK flags set. (usually set by TCP clients)
  •  
  • SYN-RECEIVED : waiting for the remote peer to send back an acknowledgment after having sent back a connection acknowledgment to the remote peer. (usually set by TCP servers)
  •  
  • ESTABLISHED : the port is ready to receive/send data from/to the remote peer.
  •  
  • FIN-WAIT-1
  •  
  • FIN-WAIT-2
  •  
  • CLOSE-WAIT
  •  
  • CLOSING
  •  
  • LAST-ACK
  • TIME-WAIT : represents waiting for enough time to pass to be sure the remote peer received the acknowledgment of its connection termination request. According to RFC 793 a connection can stay in TIME-WAIT for a maximum of four minutes.
  •  
  • CLOSED



No comments:

Post a Comment