From 29b017f277e7dbcd56911b4bdf703b344f788b6b Mon Sep 17 00:00:00 2001
From: Marcus Wichelmann <mail@marcusw.de>
Date: Fri, 30 Sep 2022 10:22:14 +0200
Subject: [PATCH] Add MTU to client configs (#214)

---
 templates/global_settings.html | 4 ++--
 util/util.go                   | 5 +++++
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/templates/global_settings.html b/templates/global_settings.html
index 0288306..1c01438 100644
--- a/templates/global_settings.html
+++ b/templates/global_settings.html
@@ -91,9 +91,9 @@ Global Settings
                             <dt>2. DNS Servers</dt>
                             <dd>The DNS servers will be set to client config.</dd>
                             <dt>3. MTU</dt>
-                            <dd>The MTU will be set to server config. By default it is <code>1420</code>. You might want
+                            <dd>The MTU will be set to server and client config. By default it is <code>1420</code>. You might want
                                 to adjust the MTU size if your connection (e.g PPPoE, 3G, satellite network, etc) has a low MTU.</dd>
-                            <dd>Leave blank to omit this setting in the Server config.</dd>
+                            <dd>Leave blank to omit this setting in the configs.</dd>
                             <dt>4. Persistent Keepalive</dt>
                             <dd>By default, WireGuard peers remain silent while they do not need to communicate,
                                 so peers located behind a NAT and/or firewall may be unreachable from other peers
diff --git a/util/util.go b/util/util.go
index ea97fcc..6e9e144 100644
--- a/util/util.go
+++ b/util/util.go
@@ -28,6 +28,10 @@ func BuildClientConfig(client model.Client, server model.Server, setting model.G
 	if client.UseServerDNS {
 		clientDNS = fmt.Sprintf("DNS = %s\n", strings.Join(setting.DNSServers, ","))
 	}
+	clientMTU := ""
+	if setting.MTU > 0 {
+		clientMTU = fmt.Sprintf("MTU = %d\n", setting.MTU)
+	}
 
 	// Peer section
 	peerPublicKey := fmt.Sprintf("PublicKey = %s\n", server.KeyPair.PublicKey)
@@ -66,6 +70,7 @@ func BuildClientConfig(client model.Client, server model.Server, setting model.G
 		clientAddress +
 		clientPrivateKey +
 		clientDNS +
+		clientMTU +
 		forwardMark +
 		"\n[Peer]\n" +
 		peerPublicKey +