mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-18 16:26:38 +00:00
Fix windows tun GUID
This commit is contained in:
@@ -5,11 +5,9 @@ import (
|
|||||||
"github.com/netbirdio/netbird/iface/bind"
|
"github.com/netbirdio/netbird/iface/bind"
|
||||||
"github.com/pion/transport/v2"
|
"github.com/pion/transport/v2"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"golang.org/x/sys/windows"
|
|
||||||
"golang.zx2c4.com/wireguard/device"
|
"golang.zx2c4.com/wireguard/device"
|
||||||
"golang.zx2c4.com/wireguard/ipc"
|
"golang.zx2c4.com/wireguard/ipc"
|
||||||
"golang.zx2c4.com/wireguard/tun"
|
"golang.zx2c4.com/wireguard/tun"
|
||||||
"golang.zx2c4.com/wireguard/windows/driver"
|
|
||||||
"golang.zx2c4.com/wireguard/windows/tunnel/winipcfg"
|
"golang.zx2c4.com/wireguard/windows/tunnel/winipcfg"
|
||||||
"net"
|
"net"
|
||||||
)
|
)
|
||||||
@@ -95,8 +93,8 @@ func (c *tunDevice) getInterfaceGUIDString() (string, error) {
|
|||||||
if c.netInterface == nil {
|
if c.netInterface == nil {
|
||||||
return "", fmt.Errorf("interface has not been initialized yet")
|
return "", fmt.Errorf("interface has not been initialized yet")
|
||||||
}
|
}
|
||||||
windowsDevice := c.netInterface.(*driver.Adapter)
|
windowsDevice := c.netInterface.(*tun.NativeTun)
|
||||||
luid := windowsDevice.LUID()
|
luid := winipcfg.LUID(windowsDevice.LUID())
|
||||||
guid, err := luid.GUID()
|
guid, err := luid.GUID()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
@@ -104,22 +102,6 @@ func (c *tunDevice) getInterfaceGUIDString() (string, error) {
|
|||||||
return guid.String(), nil
|
return guid.String(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *tunDevice) createAdapter() (NetInterface, error) {
|
|
||||||
WintunStaticRequestedGUID, _ := windows.GenerateGUID()
|
|
||||||
adapter, err := driver.CreateAdapter(c.name, "WireGuard", &WintunStaticRequestedGUID)
|
|
||||||
if err != nil {
|
|
||||||
err = fmt.Errorf("error creating adapter: %w", err)
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
err = adapter.SetAdapterState(driver.AdapterStateUp)
|
|
||||||
if err != nil {
|
|
||||||
return adapter, err
|
|
||||||
}
|
|
||||||
state, _ := adapter.LUID().GUID()
|
|
||||||
log.Debugln("device guid: ", state.String())
|
|
||||||
return adapter, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// assignAddr Adds IP address to the tunnel interface and network route based on the range provided
|
// assignAddr Adds IP address to the tunnel interface and network route based on the range provided
|
||||||
func (c *tunDevice) assignAddr() error {
|
func (c *tunDevice) assignAddr() error {
|
||||||
tunDev := c.netInterface.(*tun.NativeTun)
|
tunDev := c.netInterface.(*tun.NativeTun)
|
||||||
|
|||||||
Reference in New Issue
Block a user