network: add auto-detection of optimal MTU for WireGuard interface, --wg-mtu flag, set max_mtu for Corrosion to 1232

This commit is contained in:
Pasha Sviderski
2026-06-16 21:36:12 +10:00
parent 2f76187bf5
commit 0c3b8b122f
18 changed files with 373 additions and 170 deletions
+10
View File
@@ -12,6 +12,16 @@ import (
const (
WireGuardInterfaceName = "uncloud"
DefaultWireGuardPort = 51820
// MinWireGuardMTU is the minimum MTU for the WireGuard interface. The management traffic inside the tunnel uses
// IPv6 whose minimum link MTU is 1280, so this is a safe floor that also keeps Corrosion's max_mtu (>= 1200) valid.
MinWireGuardMTU = 1280
// MaxWireGuardMTU is the conservative maximum MTU set by auto-detection and the fallback when detection fails.
// It's the standard WireGuard MTU for a 1500-byte underlay (1500 - 80) that matches the kernel's default
// for WireGuard links.
MaxWireGuardMTU = 1500 - wireGuardEncapOverhead
// wireGuardEncapOverhead is WireGuard's worst-case (IPv6 endpoint) encapsulation overhead: outer IPv6 (40) +
// UDP (8) + WireGuard message header and auth tag (32).
wireGuardEncapOverhead = 80
// WireGuardKeepaliveInterval is sensible interval that works with a wide variety of firewalls.
WireGuardKeepaliveInterval = 25 * time.Second
)