mirror of
https://github.com/tailscale/tailscale.git
synced 2025-05-01 05:01:01 +00:00
wgengine/router: tolerate disabled IPv6 on Windows
Fixes #412 Updates #524 (maybe fixes?) Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
parent
9ab2b32569
commit
31c13013ae
@ -91,6 +91,7 @@ func monitorDefaultRoutes(device *device.Device, autoMTU bool, tun *tun.NativeTu
|
|||||||
}
|
}
|
||||||
err = bindSocketRoute(winipcfg.AF_INET6, device, ourLuid, &lastLuid6)
|
err = bindSocketRoute(winipcfg.AF_INET6, device, ourLuid, &lastLuid6)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Printf("bindSocketRoute(AF_INET6): %v", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if !autoMTU {
|
if !autoMTU {
|
||||||
@ -138,15 +139,18 @@ func monitorDefaultRoutes(device *device.Device, autoMTU bool, tun *tun.NativeTu
|
|||||||
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.
|
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 = winipcfg.GetIpInterface(ourLuid, winipcfg.AF_INET6)
|
iface, err = winipcfg.GetIpInterface(ourLuid, winipcfg.AF_INET6)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
if !isMissingIPv6Err(err) {
|
||||||
}
|
return err
|
||||||
iface.NlMtu = mtu - 80
|
}
|
||||||
if iface.NlMtu < 1280 {
|
} else {
|
||||||
iface.NlMtu = 1280
|
iface.NlMtu = mtu - 80
|
||||||
}
|
if iface.NlMtu < 1280 {
|
||||||
err = iface.Set()
|
iface.NlMtu = 1280
|
||||||
if err != nil {
|
}
|
||||||
return err
|
err = iface.Set()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
lastMtu = mtu
|
lastMtu = mtu
|
||||||
}
|
}
|
||||||
@ -358,28 +362,39 @@ func configureInterface(cfg *Config, tun *tun.NativeTun) error {
|
|||||||
|
|
||||||
ipif, err = iface.GetIpInterface(winipcfg.AF_INET6)
|
ipif, err = iface.GetIpInterface(winipcfg.AF_INET6)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
if !isMissingIPv6Err(err) {
|
||||||
}
|
return err
|
||||||
if err != nil && errAcc == nil {
|
}
|
||||||
errAcc = err
|
} else {
|
||||||
}
|
if foundDefault6 {
|
||||||
if foundDefault6 {
|
ipif.UseAutomaticMetric = false
|
||||||
ipif.UseAutomaticMetric = false
|
ipif.Metric = 0
|
||||||
ipif.Metric = 0
|
}
|
||||||
}
|
if mtu > 0 {
|
||||||
if mtu > 0 {
|
ipif.NlMtu = uint32(mtu)
|
||||||
ipif.NlMtu = uint32(mtu)
|
}
|
||||||
}
|
ipif.DadTransmits = 0
|
||||||
ipif.DadTransmits = 0
|
ipif.RouterDiscoveryBehavior = winipcfg.RouterDiscoveryDisabled
|
||||||
ipif.RouterDiscoveryBehavior = winipcfg.RouterDiscoveryDisabled
|
err = ipif.Set()
|
||||||
err = ipif.Set()
|
if err != nil && errAcc == nil {
|
||||||
if err != nil && errAcc == nil {
|
errAcc = err
|
||||||
errAcc = err
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return errAcc
|
return errAcc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// isMissingIPv6Err reports whether err is due to IPv6 not being enabled on the machine.
|
||||||
|
//
|
||||||
|
// It's intended for use on errors returned by the winipcfg.Interface.GetIpInterface
|
||||||
|
// method, which ultimately calls:
|
||||||
|
// https://docs.microsoft.com/en-us/windows/win32/api/netioapi/nf-netioapi-getipinterfaceentry
|
||||||
|
func isMissingIPv6Err(err error) bool {
|
||||||
|
// ERROR_NOT_FOUND from means the address family (IPv6) is not found.
|
||||||
|
// (ERROR_FILE_NOT_FOUND means that the interface doesn't exist.)
|
||||||
|
return errors.Is(err, windows.ERROR_NOT_FOUND)
|
||||||
|
}
|
||||||
|
|
||||||
// routeLess reports whether ri should sort before rj.
|
// routeLess reports whether ri should sort before rj.
|
||||||
// The actual sort order doesn't appear to matter. The caller just
|
// The actual sort order doesn't appear to matter. The caller just
|
||||||
// wants them sorted to be able to de-dup.
|
// wants them sorted to be able to de-dup.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user