Detailed explanation of TCP packet fragmentation mechanism

Original address: http://www.cnitblog.com/donne/archive/2010/12/23/72500.aspx

IP fragmentation is on Ethernet. Due to electrical limitations, a frame cannot exceed 1518 bytes. Excluding the 14-byte Ethernet frame header (mac address, etc.) and the 4-byte check at the end of the frame, there are still 1500 bytes left. This size is called is MTU (Maximum Transmission Unit). 

If your IP packet is larger than 1500 bytes, the IP layer will be fragmented. The source of the MTU value of 1492 is because of the PPPoE protocol. The PPP protocol is used by broadband operators to authenticate and charge users (TCP/IP Ethernet does not have this function). The PPPoE header and tail have a total of 8 bytes, so the payload MTU has become smaller. It used to be 1500 bytes, and now there are only 1492. 

The 1492 also contains a 20-byte IP header, an 8-byte UDP header, or a 20-byte TCP header. So the real unsharded data,

UDP is 1492-28=1464,

TCP is 1492-40=1452 bytes. 

TCP is indeed a stream, so the data size that a TCP packet can contain is 65536 (the length of the packet header is defined as 2 bytes) . A continuously sends data to b, and after b receives a data size larger than its low water level each time, your recv will return (assuming blocking mode) and get the data length. Of course you will continue to receive and process data. 

If the actual data is larger than 1452 bytes, the IP will be fragmented, but the IP will also reassemble the fragments, so it can still be received in one recv (not necessarily all, but it has nothing to do with the fragmentation). If a fragment is lost, the entire TCP packet will be resent, because the IP layer will not hand over the confiscated fragment to the transport layer. The timing of ACK confirmation is to confirm the TCP sequence number of the last complete packet when it is received. If it is not complete, of course, it will wait for it to be received completely, and it will not interact with the application layer, nor will ACK confirmation be sent (it can be confirmed by 3 times). the last complete serial number for the sender to quickly transmit). Handshake negotiation and ACK TCP will negotiate MSS (maximum segment size) when it initiates 3 handshakes. This value is generally the minimum MTU-IP header-TCP header of the path. If the MTU is 1500, then 1500-20-20=1460 words Festival. In this way, each packet does not need to be fragmented by the IP layer. So you send 2000 bytes, you call send once, and if the send buffer moving window is large enough, it should all succeed. Otherwise, the actual bytes sent are returned. Assuming that all 2000 bytes are successful, tcp will actually divide it into two packets of 1460 and 540 and send it. The receiving end will return an ACK when it receives a 1460 packet, and an ACK when it receives a 540-sized packet. Each section has an IP header and a TCP header. Only the first IP fragment has a transport layer header, and the rest of the fragments only have an IP header.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326356660&siteId=291194637