A: Summary overview

After the second article in this series, TCP(2) – the three-way handshake, it is clear how TCP establishes a connection. But the final operation is still to the data transmission, no matter how to design every step is to pave the way for data transmission and guarantee. When the client or server needs to send 100M data to each other, will it send it all at once? What is done to the packet if it is not sent once? What is the basis of these operations? Then you need to answer them one by one. The whole series of articles are read master Zhang gold digging brochure summary, interested friends can buy, really worth it

Two: Ethernet restrictions

Network transmission data through the application layer – transmission layer – network layer, the final landing point are in the link layer. Data transmission at the link layer will be carried out in the unit of frame transmission, and the Ethernet frame format is shown in the following figure: In the figure, it can be seen that the Ethernet frame range is 46-1500 bytes, that is to say, when the amount of data transmitted exceeds this range, it will be unbearable. As shown in the first example, buddy you have to hack it

Three: Network layer fragmentation

The network layer interacts directly with the link layer. Does the link layer operate on complete packets? The following practices are followed

// 217 server ping 74 On the server, set the packet bytes to 3000 ping-s3000 192.168.15.74 // 217 Server tcpdump captured packets are stored as mtu. PKT files for WireShark analysis tcpdump -i any-nn -vv -w /home/mtu. PKT host 192.168.15.74Copy the code

Ping -s adds an 8-byte ICMP header, so it will appear as 3008 when transmitting 3000 bytes of content

The first packet detail shows the total size of the packet is 1500 bytes. What happened?? Why does 3000 packets become 1500 packets, this is the MTU limit!! MTU Indicates the Maximum Transmission Unit (MTU). If the IP protocol detects that the size of a packet exceeds this value, the PACKET is fragmented and the complete packet is cut to a suitable size for Transmission

  • More fragment: Indicates whether there are More fragments
  • Fragment offset: indicates the Fragment displacement

Looking at the second packet makes this clear, you wonder why it’s 185. In fact, Wireshark is used to divide the data by 8, which means 185 * 8 = 1480. Doesn’t it say 1,500? Why is it 1480? Because 1500 contains a 20-byte header size, the actual data area is only 1480 bytes. See the Data area size value

Four: MTU value

Each server has its own MTU configuration. Run the following command to view the configuration: The MTU value is 1500, which corresponds to the experiment in Section 3

netstat -i
Copy the code

Barrel effect

Five: MSS restrictions

Under normal circumstances, the processing of the network layer can meet the requirements of data transmission, but if the transmission layer is TCP protocol, there will be no problem? Consider this question: when a packet sent by TCP to IP is fragmented by IP and a fragment is lost, does TCP retransmit the lost fragment or the entire packet? After careful consideration, it is clear that the operation of sharding must not be handed over to IP protocol by TCP, and must be kept controllable

// Max Segment Size (MSS) Specifies the maximum Segment Size. MSS = MTU-TCP header - IP headerCopy the code

To sum up, for TCP, when packets transmitted by the application layer exceed the size limit of MSS, they are segmented and delivered to the network layer after meeting the MTU requirements, avoiding packet fragmentation by IP protocol. During the three-way handshake, the TCP protocol tells each other its MSS through the options field