@ -20,7 +20,6 @@ import (
winipcfg "github.com/tailscale/winipcfg-go"
winipcfg "github.com/tailscale/winipcfg-go"
"github.com/tailscale/wireguard-go/device"
"github.com/tailscale/wireguard-go/device"
"github.com/tailscale/wireguard-go/tun"
"github.com/tailscale/wireguard-go/tun"
"github.com/tailscale/wireguard-go/wgcfg"
"golang.org/x/sys/windows"
"golang.org/x/sys/windows"
"golang.org/x/sys/windows/registry"
"golang.org/x/sys/windows/registry"
"tailscale.com/wgengine/winnet"
"tailscale.com/wgengine/winnet"
@ -237,7 +236,7 @@ func setFirewall(ifcGUID *windows.GUID) (bool, error) {
return false , nil
return false , nil
}
}
func configureInterface ( m * wgcfg . Config , tun * tun . NativeTun , dns [ ] wgcfg . IP , dnsDomains [ ] string ) error {
func configureInterface ( rs Settings , tun * tun . NativeTun ) error {
const mtu = 0
const mtu = 0
guid := tun . GUID ( )
guid := tun . GUID ( )
log . Printf ( "wintun GUID is %v\n" , guid )
log . Printf ( "wintun GUID is %v\n" , guid )
@ -263,13 +262,13 @@ func configureInterface(m *wgcfg.Config, tun *tun.NativeTun, dns []wgcfg.IP, dns
}
}
} ( )
} ( )
setDNSDomains ( guid , dns Domains)
setDNSDomains ( guid , rs. DNS Domains)
routes := [ ] winipcfg . RouteData { }
routes := [ ] winipcfg . RouteData { }
var firstGateway4 * net . IP
var firstGateway4 * net . IP
var firstGateway6 * net . IP
var firstGateway6 * net . IP
addresses := make ( [ ] * net . IPNet , len ( m. Addresse s) )
addresses := make ( [ ] * net . IPNet , len ( rs. LocalAddr s) )
for i , addr := range m. Addresse s {
for i , addr := range rs. LocalAddr s {
ipnet := addr . IPNet ( )
ipnet := addr . IPNet ( )
addresses [ i ] = ipnet
addresses [ i ] = ipnet
gateway := ipnet . IP
gateway := ipnet . IP
@ -282,17 +281,16 @@ func configureInterface(m *wgcfg.Config, tun *tun.NativeTun, dns []wgcfg.IP, dns
foundDefault4 := false
foundDefault4 := false
foundDefault6 := false
foundDefault6 := false
for _ , peer := range m . Peers {
for _ , route := range rs . Routes {
for _ , allowedip := range peer . AllowedIPs {
if ( route . IP . Is4 ( ) && firstGateway4 == nil ) || ( route . IP . Is6 ( ) && firstGateway6 == nil ) {
if ( allowedip . IP . Is4 ( ) && firstGateway4 == nil ) || ( allowedip . IP . Is6 ( ) && firstGateway6 == nil ) {
return errors . New ( "Due to a Windows limitation, one cannot have interface routes without an interface address" )
return errors . New ( "Due to a Windows limitation, one cannot have interface routes without an interface address" )
}
}
ipn := allowedip . IPNet ( )
ipn := route . IPNet ( )
var gateway net . IP
var gateway net . IP
if allowedip . IP . Is4 ( ) {
if route . IP . Is4 ( ) {
gateway = * firstGateway4
gateway = * firstGateway4
} else if allowedip . IP . Is6 ( ) {
} else if route . IP . Is6 ( ) {
gateway = * firstGateway6
gateway = * firstGateway6
}
}
r := winipcfg . RouteData {
r := winipcfg . RouteData {
@ -311,20 +309,19 @@ func configureInterface(m *wgcfg.Config, tun *tun.NativeTun, dns []wgcfg.IP, dns
// then the interface's IP won't be pingable.
// then the interface's IP won't be pingable.
continue
continue
}
}
if allowedip . IP . Is4 ( ) {
if route . IP . Is4 ( ) {
if allowedip . Mask == 0 {
if route . Mask == 0 {
foundDefault4 = true
foundDefault4 = true
}
}
r . NextHop = * firstGateway4
r . NextHop = * firstGateway4
} else if allowedip . IP . Is6 ( ) {
} else if route . IP . Is6 ( ) {
if allowedip . Mask == 0 {
if route . Mask == 0 {
foundDefault6 = true
foundDefault6 = true
}
}
r . NextHop = * firstGateway6
r . NextHop = * firstGateway6
}
}
routes = append ( routes , r )
routes = append ( routes , r )
}
}
}
err = iface . SyncAddresses ( addresses )
err = iface . SyncAddresses ( addresses )
if err != nil {
if err != nil {
@ -362,7 +359,7 @@ func configureInterface(m *wgcfg.Config, tun *tun.NativeTun, dns []wgcfg.IP, dns
}
}
var dnsIPs [ ] net . IP
var dnsIPs [ ] net . IP
for _ , ip := range dns {
for _ , ip := range rs. DNS {
dnsIPs = append ( dnsIPs , ip . IP ( ) )
dnsIPs = append ( dnsIPs , ip . IP ( ) )
}
}
err = iface . SetDNS ( dnsIPs )
err = iface . SetDNS ( dnsIPs )