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
+8 -1
View File
@@ -53,7 +53,6 @@ func createOrGetLink(name string) (netlink.Link, error) {
return nil, fmt.Errorf("find WireGuard link %q: %v", name, err)
}
link = &netlink.GenericLink{
// TODO: figure out how to set the most appropriate MTU.
LinkAttrs: netlink.LinkAttrs{Name: name},
LinkType: "wireguard",
}
@@ -91,6 +90,14 @@ func (n *WireGuardNetwork) Configure(config Config) error {
}
slog.Info("Updated addresses of the WireGuard interface.", "name", n.link.Attrs().Name, "addrs", addrs)
// Set the MTU on the WireGuard interface if it differs from the configured value.
if mtu := config.EffectiveMTU(); n.link.Attrs().MTU != mtu {
if err = netlink.LinkSetMTU(n.link, mtu); err != nil {
return fmt.Errorf("set MTU %d on WireGuard link %q: %w", mtu, n.link.Attrs().Name, err)
}
slog.Info("Set MTU on the WireGuard interface.", "name", n.link.Attrs().Name, "mtu", mtu)
}
// Bring the WireGuard interface up if it's not already up.
if n.link.Attrs().Flags&unix.IFF_UP != unix.IFF_UP {
if err = netlink.LinkSetUp(n.link); err != nil {