aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/tunnel/defaultroutemonitor.go
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-06-17 13:08:13 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2019-06-18 12:08:51 +0200
commit6e48647318edad7540c4e99be5aed10ac898893f (patch)
tree13a2d97bcb3ad8e44f288d3220fd9030d9eb968c /tunnel/defaultroutemonitor.go
parentversion: bump (diff)
downloadwireguard-windows-6e48647318edad7540c4e99be5aed10ac898893f.tar.xz
wireguard-windows-6e48647318edad7540c4e99be5aed10ac898893f.zip
tunnel: wait for IP service to attach to wintun
This helps fix startup races without needing to poll, as well as reconfiguring interfaces after wintun destroys and re-adds. It also deals gracefully with IPv6 being disabled. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'tunnel/defaultroutemonitor.go')
-rw-r--r--tunnel/defaultroutemonitor.go56
1 files changed, 18 insertions, 38 deletions
diff --git a/tunnel/defaultroutemonitor.go b/tunnel/defaultroutemonitor.go
index e9440710..c1722c45 100644
--- a/tunnel/defaultroutemonitor.go
+++ b/tunnel/defaultroutemonitor.go
@@ -44,28 +44,28 @@ func bindSocketRoute(family winipcfg.AddressFamily, device *device.Device, ourLU
*lastLUID = luid
*lastIndex = index
if family == windows.AF_INET {
- log.Printf("Binding UDPv4 socket to interface %d", index)
+ log.Printf("Binding v4 socket to interface %d", index)
return device.BindSocketToInterface4(index)
} else if family == windows.AF_INET6 {
- log.Printf("Binding UDPv6 socket to interface %d", index)
+ log.Printf("Binding v6 socket to interface %d", index)
return device.BindSocketToInterface6(index)
}
return nil
}
-func monitorDefaultRoutes(device *device.Device, autoMTU bool, tun *tun.NativeTun) (*winipcfg.RouteChangeCallback, error) {
+func monitorDefaultRoutes(family winipcfg.AddressFamily, device *device.Device, autoMTU bool, tun *tun.NativeTun) (*winipcfg.RouteChangeCallback, error) {
+ var minMTU uint32
+ if family == windows.AF_INET {
+ minMTU = 576
+ } else if family == windows.AF_INET6 {
+ minMTU = 1280
+ }
ourLUID := winipcfg.LUID(tun.LUID())
- lastLUID4 := winipcfg.LUID(0)
- lastLUID6 := winipcfg.LUID(0)
- lastIndex4 := uint32(0)
- lastIndex6 := uint32(0)
+ lastLUID := winipcfg.LUID(0)
+ lastIndex := uint32(0)
lastMTU := uint32(0)
doIt := func() error {
- err := bindSocketRoute(windows.AF_INET, device, ourLUID, &lastLUID4, &lastIndex4)
- if err != nil {
- return err
- }
- err = bindSocketRoute(windows.AF_INET6, device, ourLUID, &lastLUID6, &lastIndex6)
+ err := bindSocketRoute(family, device, ourLUID, &lastLUID, &lastIndex)
if err != nil {
return err
}
@@ -73,8 +73,8 @@ func monitorDefaultRoutes(device *device.Device, autoMTU bool, tun *tun.NativeTu
return nil
}
mtu := uint32(0)
- if lastLUID4 != 0 {
- iface, err := lastLUID4.Interface()
+ if lastLUID != 0 {
+ iface, err := lastLUID.Interface()
if err != nil {
return err
}
@@ -82,40 +82,20 @@ func monitorDefaultRoutes(device *device.Device, autoMTU bool, tun *tun.NativeTu
mtu = iface.MTU
}
}
- if lastLUID6 != 0 {
- iface, err := lastLUID6.Interface()
- if err != nil {
- return err
- }
- if iface.MTU > 0 && iface.MTU < mtu {
- mtu = iface.MTU
- }
- }
if mtu > 0 && lastMTU != mtu {
- iface, err := ourLUID.IPInterface(windows.AF_INET)
+ iface, err := ourLUID.IPInterface(family)
if err != nil {
return err
}
iface.NLMTU = mtu - 80
- if iface.NLMTU < 576 {
- iface.NLMTU = 576
+ if iface.NLMTU < minMTU {
+ iface.NLMTU = minMTU
}
err = iface.Set()
if err != nil {
return err
}
- tun.ForceMTU(int(iface.NLMTU)) // TODO: it sort of breaks the model with v6 mtu and v4 mtu being different. Just set v4 one for now.
- iface, err = ourLUID.IPInterface(windows.AF_INET6)
- if err == nil { // People seem to like to disable IPv6, so we make this non-fatal.
- iface.NLMTU = mtu - 80
- if iface.NLMTU < 1280 {
- iface.NLMTU = 1280
- }
- err = iface.Set()
- if err != nil {
- return err
- }
- }
+ tun.ForceMTU(int(iface.NLMTU)) // TODO: having one MTU for both v4 and v6 kind of breaks the windows model, so right now this just gets the second one which is... bad.
lastMTU = mtu
}
return nil