aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/service/ifaceconfig.go
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-03-05 01:00:06 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2019-03-05 05:36:21 +0100
commit9633126b286d28e3bcffc41600cb671aa0a4fd1d (patch)
tree777ff3840f07c2463d9ad12e143074dbd09ec029 /service/ifaceconfig.go
parentifaceconfig: trim filtered list (diff)
downloadwireguard-windows-9633126b286d28e3bcffc41600cb671aa0a4fd1d.tar.xz
wireguard-windows-9633126b286d28e3bcffc41600cb671aa0a4fd1d.zip
ifaceconfig: set MTU and monitor for auto mtu changes
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'service/ifaceconfig.go')
-rw-r--r--service/ifaceconfig.go53
1 files changed, 52 insertions, 1 deletions
diff --git a/service/ifaceconfig.go b/service/ifaceconfig.go
index 4569b0ab..b2f93b70 100644
--- a/service/ifaceconfig.go
+++ b/service/ifaceconfig.go
@@ -59,10 +59,11 @@ func bindSocketRoute(family winipcfg.AddressFamily, device *device.Device, ourLu
return nil
}
-func monitorDefaultRoutes(device *device.Device, guid *windows.GUID) (*winipcfg.RouteChangeCallback, error) {
+func monitorDefaultRoutes(device *device.Device, autoMTU bool, guid *windows.GUID) (*winipcfg.RouteChangeCallback, error) {
ourLuid, err := winipcfg.InterfaceGuidToLuid(guid)
lastLuid4 := uint64(0)
lastLuid6 := uint64(0)
+ lastMtu := uint32(0)
if err != nil {
return nil, err
}
@@ -75,6 +76,50 @@ func monitorDefaultRoutes(device *device.Device, guid *windows.GUID) (*winipcfg.
if err != nil {
return err
}
+ if !autoMTU {
+ return nil
+ }
+ mtu := uint32(0)
+ if lastLuid4 != 0 {
+ iface, err := winipcfg.InterfaceFromLUID(lastLuid4)
+ if err != nil {
+ return err
+ }
+ if iface.Mtu > 0 {
+ mtu = iface.Mtu
+ }
+ }
+ if lastLuid6 != 0 {
+ iface, err := winipcfg.InterfaceFromLUID(lastLuid6)
+ if err != nil {
+ return err
+ }
+ if iface.Mtu > 0 && iface.Mtu < mtu {
+ mtu = iface.Mtu
+ }
+ }
+ if mtu > 0 && (lastMtu == 0 || lastMtu != mtu) {
+ //TODO: makesure wireguard-go knows about all MTU changes
+ iface, err := winipcfg.GetIpInterface(ourLuid, winipcfg.AF_INET)
+ if err != nil {
+ return err
+ }
+ iface.NlMtu = mtu - 80
+ err = iface.Set()
+ if err != nil {
+ return err
+ }
+ iface, err = winipcfg.GetIpInterface(ourLuid, winipcfg.AF_INET6)
+ if err != nil {
+ return err
+ }
+ iface.NlMtu = mtu - 80
+ err = iface.Set()
+ if err != nil {
+ return err
+ }
+ lastMtu = mtu
+ }
return nil
}
err = doIt()
@@ -204,6 +249,9 @@ func configureInterface(conf *conf.Config, guid *windows.GUID) error {
ipif.UseAutomaticMetric = false
ipif.Metric = 0
}
+ if conf.Interface.Mtu > 0 {
+ ipif.NlMtu = uint32(conf.Interface.Mtu)
+ }
err = ipif.Set()
if err != nil {
return err
@@ -217,6 +265,9 @@ func configureInterface(conf *conf.Config, guid *windows.GUID) error {
ipif.UseAutomaticMetric = false
ipif.Metric = 0
}
+ if conf.Interface.Mtu > 0 {
+ ipif.NlMtu = uint32(conf.Interface.Mtu)
+ }
ipif.DadTransmits = 0
ipif.RouterDiscoveryBehavior = winipcfg.RouterDiscoveryDisabled
err = ipif.Set()