MTU and MSS are two important terms you should be familiar with when you jump into the networking world, and especially if you are working with GRE tunnels and IPSEC. If you are looking to use Incapsula Infrastructure Protection (now Imperva DDoS Protection) it will be helpful to know how they work.
(And if you’re looking for information on what application and data security threats keep IT leaders up at night, download the CyberThreat Defense Report 2019, which surveyed 1,200+ IT and security leaders and discovered exclusive findings such as one-third of businesses have suffered 6+ breaches in the past year. Get your copy at the link above.)
A maximum transmission unit (MTU) is the largest packet or frame size, specified in octets (eight-bit bytes) that can be sent in a packet- or frame-based network such as the internet. The internet’s transmission control protocol (TCP) uses the MTU to determine the maximum size of each packet in any transmission. MTU is usually associated with the Ethernet protocol, where a 1500-byte packet is the largest allowed in it (and hence over most of the internet).
One of the most common problems related to MTU is that sometimes higher-level protocols may create packets larger than a particular link supports, and you’ll need to make adjustments to make it work.
To get around this issue, IPv4 allows fragmentation which divides the datagram into pieces. Each piece is small enough to pass over the single link that it is being fragmented for, using the MTU parameter configured for that interface. This fragmentation process takes place at the IP layer (OSI layer 3) and marks the packets it fragments as such. This ensures the IP layer of the destination host knows it should reassemble the packets into the original datagram.
Fragmentation is sometimes not supported by applications, and is something we should avoid if possible. The best way to avoid fragmentation is to adjust the maximum segment size or TCP MSS so the segment will adjust its size before reaching the data link layer.
Before we look at TCP MSS, it helps to understand the build of the “unit” that’s being sent over the internet.
As mentioned, the common value of MTU in the internet is 1500 bytes.
As you can see in the figure above, the MTU is built from payload (also referred as data) and the TCP and the IP header, 20 bytes each. The total value of the IP and the TCP header is 40 bytes and mandatory for each packet, which leaves us 1460 bytes for our data.
Now, imagine that we are using the GRE protocol in our network, encapsulating the original packet and adding 24 bytes for the GRE header.
The total size of this kind of packet will be 1524 bytes, exceeding the 1500 bytes MTU value. The “data” size in this packet is 1460, but we can and should decrease it in order to make sure the total size will be 1500 bytes or less. And this is where TCP MSS comes into the picture.
TCP MSS, the maximum segment size, is a parameter of the options field of the TCP header that specifies the largest amount of data, specified in bytes, that a computer or communications device can receive in a single TCP segment. It does not include the TCP header or the IP header. This value will dictate the maximum size of the “data” part of the packet. In the following case for the GRE tunnel, we will set the tcp mss value to be 1436 or lower, while the default size is 1460.
The MSS announcement (often mistakenly called a negotiation) is sent during the three-way handshake by both sides, saying: “I can accept TCP segments up to size x”. The size (x) may be larger or smaller than the default. The MSS can be used completely independently in each direction of data flow.
Since the end device will not always know about high level protocols that will be added to this packet along the way, like GRE packets for example, it won’t usually adjust the TCP MSS value. As a result the network devices have the option to rewrite the value of TCP MSS packets that are processed through them. For example, in a Cisco Router the command “ip tcp mss-adjust 1436” in the interface level will rewrite the value of the TCP MSS of any SYN packet that will go via this interface.
Configuring TCP MSS for Incapsula Infrastructure Protection
In Incapsula Infrastructure Protection, we usually use GRE tunnels. Therefore, we need to address the possibility of fragmentation if we are not adjusting the TCP MSS. Our solution, which is asymmetric by definition (meaning in-bound traffic via Incapsula, outbound traffic via the original ISP) requires us to rewrite the TCP MSS value of SYN packets that are being sent by our protected customer to their end clients. We can achieve this in a Cisco Router, for example by configuring “ip tcp mss-adjust 1436” on the WAN interface or the interface that faces the provider.
Let’s look at the following diagram.
As you can see, the customer server sends the packet with the MSS value of 1460, but in the router’s interface we will adjust it to 1420. It’s important to understand that this value will affect the size of the traffic coming from the end client toward the customer’s server. This is the traffic that will go via the tunnel and therefore be encapsulated with 24 bytes of GRE. The outbound traffic, from the customer’s server toward the end client, goes directly via the original ISP, therefore we don’t need to adjust the SYN packets the end user sends as well.
The diagram above shows how the SYN packets in the three-way handshake travel. After the three-way handshake is completed and the connection established, the end user will send packets whose “data” won’t exceed the 1420 bytes size. In addition the customer’s server will send packets whose “data” won’t exceed the default 1460 bytes.
A common mistake is to configure the “ip tcp mss-adjust 1420” command on the tunnel interface of the customer. The reason it doesn’t work is because the SYN packets that are sent from the server toward the end user are not going via the GRE tunnel interface, but via the original ISP’s interface.
Do you have questions for the ops team or me? Please leave us a comment below.
Get the latest from imperva
The latest news from our experts in the fast-changing world of application, data, and edge security.