summaryrefslogtreecommitdiffhomepage
path: root/tun/wintun/wintun_windows.go
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-08-19 09:20:23 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2019-08-19 10:12:50 +0200
commiteb786cd7c11335708133624eda678dfad54048d6 (patch)
treef1e81ac762d02957ab408f990eda6d63a284c249 /tun/wintun/wintun_windows.go
parent333de75370236c0109b15814a095f28d5484ec98 (diff)
wintun: also set friendly name after setting interface name
Diffstat (limited to 'tun/wintun/wintun_windows.go')
-rw-r--r--tun/wintun/wintun_windows.go31
1 files changed, 23 insertions, 8 deletions
diff --git a/tun/wintun/wintun_windows.go b/tun/wintun/wintun_windows.go
index 2f8fcc1..4bf17e6 100644
--- a/tun/wintun/wintun_windows.go
+++ b/tun/wintun/wintun_windows.go
@@ -563,19 +563,34 @@ func (wintun *Wintun) InterfaceName() (string, error) {
// SetInterfaceName sets name of the Wintun interface.
func (wintun *Wintun) SetInterfaceName(ifname string) error {
+ netRegKey, err := registry.OpenKey(registry.LOCAL_MACHINE, wintun.netRegKeyName(), registry.SET_VALUE)
+ if err != nil {
+ return fmt.Errorf("Network-specific registry key open failed: %v", err)
+ }
+ defer netRegKey.Close()
+ err = netRegKey.SetStringValue("Name", ifname)
+ if err != nil {
+ return err
+ }
+ deviceRegKey, err := registry.OpenKey(registry.LOCAL_MACHINE, wintun.deviceRegKeyName(), registry.SET_VALUE)
+ if err != nil {
+ return fmt.Errorf("Device-level registry key open failed: %v", err)
+ }
+ defer deviceRegKey.Close()
+ err = deviceRegKey.SetStringValue("DeviceDesc", deviceTypeName)
+ if err != nil {
+ return err
+ }
+ err = deviceRegKey.SetStringValue("FriendlyName", deviceTypeName)
+ if err != nil {
+ return err
+ }
// 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.
- key, err := registry.OpenKey(registry.LOCAL_MACHINE, wintun.netRegKeyName(), registry.SET_VALUE)
- if err != nil {
- return fmt.Errorf("Network-specific registry key open failed: %v", err)
- }
- defer key.Close()
- return key.SetStringValue("Name", ifname)
+ return nil
}
// netRegKeyName returns the interface-specific network registry key name.