]> git.ipfire.org Git - thirdparty/wireguard-apple.git/commitdiff
macOS: Use tunnelOverheadBytes for automatic MTU in macOS
authorRoopesh Chander <roop@roopc.net>
Tue, 15 Jan 2019 20:21:50 +0000 (01:51 +0530)
committerRoopesh Chander <roop@roopc.net>
Tue, 15 Jan 2019 20:21:56 +0000 (01:51 +0530)
Signed-off-by: Roopesh Chander <roop@roopc.net>
WireGuard/WireGuardNetworkExtension/PacketTunnelSettingsGenerator.swift

index f6eb722337b78fde96461486668d796932eb6827..a1f90f1d3bb81411a330df5f1820de9e83704845 100644 (file)
@@ -70,7 +70,7 @@ class PacketTunnelSettingsGenerator {
         dnsSettings.matchDomains = [""] // All DNS queries must first go through the tunnel's DNS
         networkSettings.dnsSettings = dnsSettings
 
-        var mtu = tunnelConfiguration.interface.mtu ?? 0
+        let mtu = tunnelConfiguration.interface.mtu ?? 0
 
         /* 0 means automatic MTU. In theory, we should just do
          * `networkSettings.tunnelOverheadBytes = 80` but in
@@ -79,11 +79,15 @@ class PacketTunnelSettingsGenerator {
          * add a nob, maybe, or iOS will do probing for us.
          */
         if mtu == 0 {
-            mtu = 1280
+            #if os(iOS)
+            networkSettings.mtu = NSNumber(value: 1280)
+            #elseif os(OSX)
+            networkSettings.tunnelOverheadBytes = 80
+            #endif
+        } else {
+            networkSettings.mtu = NSNumber(value: mtu)
         }
 
-        networkSettings.mtu = NSNumber(value: mtu)
-
         let (ipv4Routes, ipv6Routes) = routes()
         let (ipv4IncludedRoutes, ipv6IncludedRoutes) = includedRoutes()