diff --git a/client/internal/engine_test.go b/client/internal/engine_test.go index e0f85d211..80b79a364 100644 --- a/client/internal/engine_test.go +++ b/client/internal/engine_test.go @@ -13,6 +13,7 @@ import ( "testing" "time" + "github.com/google/uuid" "github.com/pion/transport/v3/stdnet" log "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" @@ -845,6 +846,8 @@ func TestEngine_MultiplePeers(t *testing.T) { engine.dnsServer = &dns.MockServer{} mu.Lock() defer mu.Unlock() + guid := fmt.Sprintf("{%s}", uuid.New().String()) + iface.CustomWindowsGUIDString = strings.ToLower(guid) err = engine.Start() if err != nil { t.Errorf("unable to start engine for peer %d with error %v", j, err) diff --git a/iface/iface_test.go b/iface/iface_test.go index 43c44b770..6609c06f4 100644 --- a/iface/iface_test.go +++ b/iface/iface_test.go @@ -4,9 +4,11 @@ import ( "fmt" "net" "net/netip" + "strings" "testing" "time" + "github.com/google/uuid" "github.com/pion/transport/v3/stdnet" log "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" @@ -345,6 +347,9 @@ func Test_ConnectPeers(t *testing.T) { t.Fatal(err) } + guid := fmt.Sprintf("{%s}", uuid.New().String()) + CustomWindowsGUIDString = strings.ToLower(guid) + iface1, err := NewWGIFace(peer1ifaceName, peer1wgIP, peer1wgPort, peer1Key.String(), DefaultMTU, newNet, nil, nil) if err != nil { t.Fatal(err) @@ -364,6 +369,9 @@ func Test_ConnectPeers(t *testing.T) { t.Fatal(err) } + guid = fmt.Sprintf("{%s}", uuid.New().String()) + CustomWindowsGUIDString = strings.ToLower(guid) + newNet, err = stdnet.NewNet() if err != nil { t.Fatal(err) diff --git a/iface/tun.go b/iface/tun.go index b3c0f9d80..7d0a57ed6 100644 --- a/iface/tun.go +++ b/iface/tun.go @@ -7,6 +7,9 @@ import ( "github.com/netbirdio/netbird/iface/bind" ) +// CustomWindowsGUIDString is a custom GUID string for the interface +var CustomWindowsGUIDString string + type wgTunDevice interface { Create() (wgConfigurer, error) Up() (*bind.UniversalUDPMuxDefault, error) diff --git a/iface/tun_windows.go b/iface/tun_windows.go index 0d658059f..8c0a3c3b5 100644 --- a/iface/tun_windows.go +++ b/iface/tun_windows.go @@ -14,6 +14,8 @@ import ( "github.com/netbirdio/netbird/iface/bind" ) +const defaultWindowsGUIDSTring = "{f2f29e61-d91f-4d76-8151-119b20c4bdeb}" + type tunDevice struct { name string address WGAddress @@ -40,9 +42,22 @@ func newTunDevice(name string, address WGAddress, port int, key string, mtu int, } } +func getGUID() (windows.GUID, error) { + guidString := defaultWindowsGUIDSTring + if CustomWindowsGUIDString != "" { + guidString = CustomWindowsGUIDString + } + return windows.GUIDFromString(guidString) +} + func (t *tunDevice) Create() (wgConfigurer, error) { + guid, err := getGUID() + if err != nil { + log.Errorf("failed to get GUID: %s", err) + return nil, err + } log.Info("create tun interface") - tunDevice, err := tun.CreateTUN(t.name, t.mtu) + tunDevice, err := tun.CreateTUNWithRequestedGUID(t.name, &guid, t.mtu) if err != nil { return nil, err }