Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[16.0] Enable automatic TCP MSS clamping for forwarded app traffic#5386

Merged
eriknordmark merged 1 commit into
lf-edge:16.0from
milan-zededa:16.0-mss-clamp
Nov 12, 2025
Merged

[16.0] Enable automatic TCP MSS clamping for forwarded app traffic#5386
eriknordmark merged 1 commit into
lf-edge:16.0from
milan-zededa:16.0-mss-clamp

Conversation

@milan-zededa

Copy link
Copy Markdown
Contributor

Description

Backport of #5319

How to test and validate this PR

Reproducing a scenario where TCP MSS clamping is required to prevent dropped or fragmented packets can be tricky.
The following procedure provides one possible way to validate the fix:

  1. Onboard the edge node.
  2. Deploy an application connected to a network instance with a device port attached (not air-gapped).
  3. Reduce the MTU on the port to, for example, 1400 bytes — either manually with ip link set mtu 1400 <port> or through the network configuration.
  4. Keep the application-side MTU at 1500.
    If the application virtio driver or DHCP client automatically adopted the 1400 MTU advertised by EVE, change it back manually to 1500.
    This simulates a case where MTU propagation does not occur properly.
  5. Disable PMTU discovery (if enabled), or drop incoming ICMP “Fragmentation Needed” messages on the application side.
    For example, on Linux:
sudo iptables -A INPUT -p icmp --icmp-type fragmentation-needed -j DROP
  1. Flush any cached PMTU values to ensure a clean test. On Linux: sudo ip route flush cache
  2. Then I recommend to use iperf3, which will try to use as large packets as allowed by the egress interface MTU to measure the maximum bandwidth.
    On another device reachable from the EVE node, start an iperf3 server: iperf3 -s
    Then, on the application side, run the client: iperf3 -c <the-server-IP>
  3. Verify that traffic is neither dropped (the reported bandwidth is non-zero) nor fragmented.
    To check that EVE is not fragmenting any packets, SSH into EVE (or use the console) and run:
eve enter debug
tcpdump -i any 'ip[6:2] & 0x1fff != 0 or ip[6] & 0x20 != 0' -vv -n

The packet capture during the iperf3 run should show no fragmented packets (i.e., output should be empty).

  1. Confirm that the MSS clamping rule is applied.
    After running the test, check that the iptables rule counter has incremented:
eve enter debug
iptables -L -v -t mangle | grep TCPMSS

Example output:

  20  1040 TCPMSS  tcp  --  any  any  anywhere  anywhere  tcp flags:SYN,RST/SYN  /* Clamp TCP MSS */ TCPMSS clamp to PMTU

A non-zero counter indicates that the MSS clamping rule was triggered as expected.

Changelog notes

Enable automatic TCP MSS clamping for forwarded app traffic using the path MTU to prevent fragmentation and dropped packets; can be disabled via the configuration property app.enable.tcp.mss.clamping.

Checklist

  • I've provided a proper description
  • I've added the proper documentation
  • I've tested my PR on amd64 device
  • I've tested my PR on arm64 device
  • I've written the test verification instructions
  • I've set the proper labels to this PR
  • I've added a reference link to the original PR
  • PR's title follows the template
  • I've checked the boxes above, or I've provided a good reason why I didn't check them.

TCP MSS clamping is now applied automatically to forwarded application
traffic in EVE. This ensures that TCP connections adjust their Maximum
Segment Size (MSS) to match the actual path MTU and avoid packet
fragmentation.

-> Why this is needed

In EVE, application workloads often run inside VMs (or containers within VMs).
In these environments, it is not always possible to propagate the underlying
interface MTU to the application:

- The app must request MTU via DHCP, or use a recent virtio driver that
  supports MTU propagation.
- When the network instance is rerouted to a different uplink, the new MTU
  only takes effect after the app’s DHCP lease expires.
- Containers running inside VMs may ignore the propagated MTU altogether.

As a result, applications might continue sending packets larger than the real
path MTU, causing fragmentation or even dropped packets if Don’t Fragment (DF)
flag is set. If ICMP “Fragmentation Needed” messages are filtered, the sender
cannot detect the issue, leading to retransmissions and connection stalls.

-> How it works

The kernel’s Netfilter subsystem automatically adjusts (clamps) the TCP MSS
in SYN and SYN-ACK packets to fit the path MTU.

The path MTU is determined from the output interface MTU and cached ICMP feedback
(if available). Even if ICMPs are blocked, the interface MTU still provides a safe
upper bound (especially when device is running at the network edge).

The MSS is determined by taking the minimum of the path MTUs in both directions
of the flow, ensuring packets in either direction fit the path.

The MSS in the packet is only ever reduced, never increased.

The calculated MSS is written into the TCP options of the packet, and the TCP
checksum is automatically recalculated to reflect the change.

The rule is implemented in the mangle table (FORWARD chain) using iptables:

- One rule for IPv4 (iptables)
- One rule for IPv6 (ip6tables)

-> Configuration

By default, MSS clamping is enabled for all forwarded application traffic.
If necessary, it can be disabled via the global configuration property:
`app.enable.tcp.mss.clamping`
This allows to disable clamping in case it causes some undesired
behaviour.

Signed-off-by: Milan Lenco <[email protected]>
(cherry picked from commit 10e402f)
@milan-zededa milan-zededa added enhancement New feature or request main-quest The fate of the project rests on this PR. Prioritise review to advance the storyline! labels Nov 11, 2025

@eriknordmark eriknordmark left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@eriknordmark eriknordmark merged commit 48cf740 into lf-edge:16.0 Nov 12, 2025
44 of 45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request main-quest The fate of the project rests on this PR. Prioritise review to advance the storyline!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants