aboutsummaryrefslogtreecommitdiffstats
path: root/tun/wintun/wintun_windows.go
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-04-01 12:00:33 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2019-04-01 12:04:44 +0200
commitac25702eaf13bb2243f02130ae271ff600f75209 (patch)
tree44f5518abce2ed2838888504d4c751e4957e9cb3 /tun/wintun/wintun_windows.go
parentwintun: add more retry loops (diff)
downloadwireguard-go-ac25702eaf13bb2243f02130ae271ff600f75209.tar.xz
wireguard-go-ac25702eaf13bb2243f02130ae271ff600f75209.zip
wintun: rename device using undocumented API that netsh.exe uses
Diffstat (limited to '')
-rw-r--r--tun/wintun/wintun_windows.go10
1 files changed, 9 insertions, 1 deletions
diff --git a/tun/wintun/wintun_windows.go b/tun/wintun/wintun_windows.go
index 77e83a0..8e09c41 100644
--- a/tun/wintun/wintun_windows.go
+++ b/tun/wintun/wintun_windows.go
@@ -8,6 +8,7 @@ package wintun
import (
"errors"
"fmt"
+ "golang.zx2c4.com/wireguard/tun/wintun/netshell"
"strings"
"syscall"
"time"
@@ -449,13 +450,20 @@ func (wintun *Wintun) GetInterfaceName() (string, error) {
// SetInterfaceName sets network interface name.
//
func (wintun *Wintun) SetInterfaceName(ifname string) error {
+ // We open the registry key before calling HrRename, because the registry open will wait until the key exists.
key, err := registryOpenKeyRetry(registry.LOCAL_MACHINE, wintun.GetNetRegKeyName(), registry.SET_VALUE)
if err != nil {
return errors.New("Network-specific registry key open failed: " + err.Error())
}
defer key.Close()
- // Set the interface name.
+ // We have to tell the various runtime COM services about the new name too. We ignore the
+ // error because netshell isn't available on servercore.
+ // TODO: netsh.exe falls back to NciSetConnection in this case. If somebody complains, maybe
+ // we should do the same.
+ _ = netshell.HrRenameConnection(&wintun.CfgInstanceID, windows.StringToUTF16Ptr(ifname))
+
+ // Set the interface name. The above line should have done this too, but in case it failed, we force it.
return key.SetStringValue("Name", ifname)
}