wintun: try multiple names until one isn't a duplicate
This commit is contained in:
parent
68fea631d8
commit
3cedc22d7b
|
@ -522,10 +522,18 @@ func (wintun *Wintun) InterfaceName() (string, error) {
|
||||||
|
|
||||||
// SetInterfaceName sets name of the Wintun interface.
|
// SetInterfaceName sets name of the Wintun interface.
|
||||||
func (wintun *Wintun) SetInterfaceName(ifname string) error {
|
func (wintun *Wintun) SetInterfaceName(ifname string) error {
|
||||||
err := nci.SetConnectionName(&wintun.cfgInstanceID, ifname)
|
const maxSuffix = 1000
|
||||||
if err != nil {
|
availableIfname := ifname
|
||||||
|
for i := 0; ; i++ {
|
||||||
|
err := nci.SetConnectionName(&wintun.cfgInstanceID, availableIfname)
|
||||||
|
if err == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if i > maxSuffix || err != windows.ERROR_DUP_NAME {
|
||||||
return fmt.Errorf("NciSetConnectionName failed: %v", err)
|
return fmt.Errorf("NciSetConnectionName failed: %v", err)
|
||||||
}
|
}
|
||||||
|
availableIfname = fmt.Sprintf("%s %d", ifname, i+1)
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: This should use NetSetup2 so that it doesn't get unset.
|
// TODO: This should use NetSetup2 so that it doesn't get unset.
|
||||||
deviceRegKey, err := registry.OpenKey(registry.LOCAL_MACHINE, wintun.deviceRegKeyName(), registry.SET_VALUE)
|
deviceRegKey, err := registry.OpenKey(registry.LOCAL_MACHINE, wintun.deviceRegKeyName(), registry.SET_VALUE)
|
||||||
|
|
Loading…
Reference in a new issue