diff options
author | 2020-06-05 22:06:49 -0600 | |
---|---|---|
committer | 2020-06-05 22:08:08 -0600 | |
commit | 2a977979a1da0c5f61dc189b99bc866c4c92e2c3 (patch) | |
tree | 85bc0ab28754d317ef5afc003074c067d50fa31f | |
parent | syntax: update to latest from wireguard-tools, for dns search domains (diff) | |
download | wireguard-windows-2a977979a1da0c5f61dc189b99bc866c4c92e2c3.tar.xz wireguard-windows-2a977979a1da0c5f61dc189b99bc866c4c92e2c3.zip |
tunnel: support setting dns domain suffix
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r-- | tunnel/addressconfig.go | 9 | ||||
-rw-r--r-- | tunnel/winipcfg/luid.go | 27 |
2 files changed, 36 insertions, 0 deletions
diff --git a/tunnel/addressconfig.go b/tunnel/addressconfig.go index 777c96cd..462e1052 100644 --- a/tunnel/addressconfig.go +++ b/tunnel/addressconfig.go @@ -159,6 +159,15 @@ func configureInterface(family winipcfg.AddressFamily, conf *conf.Config, tun *t return err } + if len(conf.Interface.DNSSearch) > 0 { + err = luid.SetDNSDomain(conf.Interface.DNSSearch[0]) + if err != nil { + return nil + } + if len(conf.Interface.DNSSearch) > 1 { + log.Printf("Warning: %d DNS search domains were specified, but only one is supported, so the first one (%s) was used.", len(conf.Interface.DNSSearch), conf.Interface.DNSSearch[0]) + } + } err = luid.SetDNSForFamily(family, conf.Interface.DNS) if err != nil { return err diff --git a/tunnel/winipcfg/luid.go b/tunnel/winipcfg/luid.go index 396fbbb2..e1aafb61 100644 --- a/tunnel/winipcfg/luid.go +++ b/tunnel/winipcfg/luid.go @@ -6,10 +6,12 @@ package winipcfg import ( + "errors" "fmt" "net" "golang.org/x/sys/windows" + "golang.org/x/sys/windows/registry" ) // LUID represents a network interface. @@ -426,3 +428,28 @@ func (luid LUID) SetDNSForFamily(family AddressFamily, dnses []net.IP) error { } return runNetsh(cmds) } + +// SetDNSDomain method sets the interface-specific DNS domain. +func (luid LUID) SetDNSDomain(domain string) error { + guid, err := luid.GUID() + + key, err := registry.OpenKey(registry.LOCAL_MACHINE, fmt.Sprintf("SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Adapters\\%v", guid), registry.QUERY_VALUE) + if err != nil { + return fmt.Errorf("Error opening adapter-specific TCP/IP network registry key: %v", err) + } + paths, _, err := key.GetStringsValue("IpConfig") + key.Close() + if err != nil { + return fmt.Errorf("Error reading IpConfig registry key: %v", err) + } + if len(paths) == 0 { + return errors.New("No TCP/IP interfaces found on adapter") + } + key, err = registry.OpenKey(registry.LOCAL_MACHINE, fmt.Sprintf("SYSTEM\\CurrentControlSet\\Services\\%s", paths[0]), registry.SET_VALUE) + if err != nil { + return fmt.Errorf("Unable to open TCP/IP network registry key: %v", err) + } + err = key.SetStringValue("Domain", domain) + key.Close() + return err +} |