当前位置:网站首页>Understand what MSS is

Understand what MSS is

2022-06-25 06:21:00 Programmer community

The article was first published in public - many - Number , Automotive network diagnostic communication

We know MTU Is the parameter of network card , It's data link layer versus network layer IP Package size limit . When the network layer IP package ( Include IP head ,VLAN tag) It's bigger than MTU when , You need to slice at the network layer first , Cut into smaller than MTU Of IP package , And then to the link layer

MSS

Think about the , Multiple under one host APP Need to pass through TCP agreement , Send a lot of data to communicate . To form such a situation : Multiple TCP message , When you get to the network layer , To encapsulate into many IP package , these IP The package is too big due to the data , Greater than MTU, It needs to be sliced , To the link layer . So many packets need to be sliced at the network layer , Does it reduce efficiency ?

Since from TCP The data is too big , And all of them are squeezed in the network layer for fragmentation , Why don't you think of a way , Give Way TCP Every piece of data that came , Just in line with the fact that there is no need for fragmentation in the network layer , How are you? How are you

MSS

Maximum Segment Size, Maximum message length ,TCP payload The maximum of ,TCP An option for protocol definition ,MSS yes TCP Used to limit the maximum number of bytes sent by the application layer

MSS Option is used in the TCP When the connection is established , The maximum data length that each message segment can carry when the sender and receiver negotiate communication

TCP When establishing a connection , According to MTU Calculate each of the MSS, By shaking hands three times MSS Tell the other person , Confirm each other's MSS size , Take the smaller one MSS Value as both sides in TCP The maximum number of layer segments payload

How to base on MTU Calculation MSS?

 Understand what is MSS illustrations

The default of Ethernet MTU = 1500 = IPHeader(20) +TCPHeader(20) + Data,TCP Valid data for Data The maximum value of is 1500-20-20 = 1460, This is it. MSS Value

The client is in SYN Carry your own in the message MSS, The server is replying to ACK+SYN Carry your own MSS

 Understand what is MSS illustrations 1

That's it TCP When communication , By determining the minimum... In the three handshake phase MSS, according to MSS, Transport layer will not exceed MSS Data encapsulation , Down to the network layer , The network layer avoids IP Package and slice , And the receiver will not have data frames exceeding MTU And can't receive it

PMTUD

The sender and receiver are TCP Protocol communication , Take smaller according to MSS Principles , Avoid the sender in the network layer fragmentation , The receiver in the network card due to more than MTU And can't receive it

however , Ethernet communication is not just two hosts , They also have routers and switches on the way to communicate , Routers and switches have their own MTU, If the data frames exceed their MTU What will happen ?

For routers , If the received data frame exceeds its own MTU, On the way out of the exit , It needs to be sliced , Network layer fragmentation IP package , What decisions need to be made ?

The answer is :IP The head of the DF Slice position

  • If DF = 0, It means that it can be sliced
  • If DF = 1, It means you can't slice

DF = 0

 Understand what is MSS illustrations 2

Two mainframes are TCP handshake phase , To determine the MSS = 1480 - 20 - 20 = 1440, So sent IP The bag is 1440 + 20 + 20 = 1480, In this way IP The bag doesn't split when it's sent out , And the receiver can also receive

When IP When the packet reaches the router , It needs to be issued from another interface , And interface MTU by 1450, It has to be fragmented to send , Then the router will check IP Bag DF position , To make sure that IP Whether the package supports fragmentation

Find out DF Is it 0, It means that it can be sliced , Put the IP The package is divided into two parts ,1450 and 30, Because of the first 1450 Yes, there is IP The head of the , It can be sent directly to the link layer , And the second one 30 It's not IP The head of the , Need to add IP head 20 Bytes , Form a new IP package , Size is 50 Bytes , It is also distributed to the link layer , issue

DF = 1

 Understand what is MSS illustrations 3

With the above DF = 0 The difference is , The router found IP The package needs to be sliced , But look at IP Bag DF position , The discovery value is 1, The display can't be sliced , At this time, the router can only discard this IP package , At the same time, reply a ICMP Message of unreachable purpose ,Type = 3,code = 4

code = 4 The meaning is :

 Understand what is MSS illustrations 4

meanwhile , stay ICMP There will be routers in the message MTU Size , Tell the source host the router's MTU How much is the , In this way, the source host can continue to adjust its own MSS value , If there are multiple routers , Multiple routers operate like this , Finally, determine a minimum on this path MTU, This is it. PMTUD

in addition ,ICMP Destination unreachable message , And throw away the IP The header of each layer of the package is also placed inside

 The picture is from https://zhuanlan.zhihu.com/p/139537936

PMUTD

Path MTU Discovery, No more explanation

Please also note

The router MTU Only for outgoing interfaces

PMTUD Only TCP Support ,UDP Does not support


原网站

版权声明
本文为[Programmer community]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202201245251297.html