mirror of
https://github.com/kubenetworks/kubevpn.git
synced 2025-12-24 11:51:13 +08:00
fix: add index number to tun device name on windows (#726)
This commit is contained in:
@@ -31,13 +31,26 @@ func createTun(cfg Config) (conn net.Conn, itf *net.Interface, err error) {
|
||||
if len(cfg.Name) != 0 {
|
||||
tunName = cfg.Name
|
||||
}
|
||||
var interfaces []net.Interface
|
||||
interfaces, err = net.Interfaces()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
maxIndex := -1
|
||||
for _, i := range interfaces {
|
||||
ifIndex := -1
|
||||
_, err := fmt.Sscanf(i.Name, "KubeVPN%d", &ifIndex)
|
||||
if err == nil && ifIndex >= 0 && maxIndex < ifIndex {
|
||||
maxIndex = ifIndex
|
||||
}
|
||||
}
|
||||
mtu := cfg.MTU
|
||||
if mtu <= 0 {
|
||||
mtu = config.DefaultMTU
|
||||
}
|
||||
|
||||
wireguardtun.WintunTunnelType = "KubeVPN"
|
||||
tunDevice, err := wireguardtun.CreateTUN(tunName, mtu)
|
||||
tunDevice, err := wireguardtun.CreateTUN(fmt.Sprintf("KubeVPN%d", maxIndex+1), mtu)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("failed to create TUN device: %w", err)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user