From e1e47628d7a34bcd94f21c93cff60f0a210dd28a Mon Sep 17 00:00:00 2001 From: Callan Bryant Date: Sun, 11 May 2025 09:47:11 +0100 Subject: [PATCH] wiring to set MTU Yet to figure out: 1. the right place to set it 2. How to set it to change it on sync https://github.com/WireGuard/wireguard-go/blob/master/main.go reference --- cmd/cli/config.go | 2 ++ cmd/root.go | 1 + lib/link.go | 2 ++ 3 files changed, 5 insertions(+) diff --git a/cmd/cli/config.go b/cmd/cli/config.go index 17cfe25..f04ea31 100644 --- a/cmd/cli/config.go +++ b/cmd/cli/config.go @@ -67,6 +67,7 @@ type DsnetConfig struct { Peers []PeerConfig `validate:"dive"` // used for server and client PersistentKeepalive int `validate:"gte=0,lte=255"` + MTU int `validate:"gte=0,lte=65535"` } // LoadConfigFile parses the json config file, validates and stuffs @@ -88,6 +89,7 @@ func LoadConfigFile() (*DsnetConfig, error) { // used _even if value is zero!_ // Effectively, this is a migration PersistentKeepalive: 25, + MTU: 1420, } err = json.Unmarshal(raw, &conf) diff --git a/cmd/root.go b/cmd/root.go index 3ae3508..4cb60b2 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -206,6 +206,7 @@ func init() { viper.SetDefault("config_file", "/etc/dsnetconfig.json") viper.SetDefault("fallback_wg_bing", "wireguard-go") viper.SetDefault("listen_port", 51820) + viper.SetDefault("MTU", 1420) viper.SetDefault("interface_name", "dsnet") // if last handshake (different from keepalive, see https://www.wireguard.com/protocol/) diff --git a/lib/link.go b/lib/link.go index 1e2c257..d77648c 100644 --- a/lib/link.go +++ b/lib/link.go @@ -65,6 +65,8 @@ func (s *Server) CreateLink() error { if err != nil { return fmt.Errorf("could not add ipv4 addr %s to interface %s: %v", addr.IP, s.InterfaceName, err) } + // set MTU + err = netlink.LinkSetMTU(link, s.MTU) } }