mirror of
https://github.com/netbirdio/netbird.git
synced 2025-02-23 13:41:19 +01:00
[client] Use static requested GUID when creating Windows interface (#2479)
RequestedGUID is the GUID of the created network adapter, which then influences NLA generation deterministically. With this change, NetBird should not generate multiple interfaces in every restart on Windows.
This commit is contained in:
parent
63a75d72fc
commit
7efaf7eadb
@ -13,6 +13,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
"github.com/pion/transport/v3/stdnet"
|
"github.com/pion/transport/v3/stdnet"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
@ -845,6 +846,8 @@ func TestEngine_MultiplePeers(t *testing.T) {
|
|||||||
engine.dnsServer = &dns.MockServer{}
|
engine.dnsServer = &dns.MockServer{}
|
||||||
mu.Lock()
|
mu.Lock()
|
||||||
defer mu.Unlock()
|
defer mu.Unlock()
|
||||||
|
guid := fmt.Sprintf("{%s}", uuid.New().String())
|
||||||
|
iface.CustomWindowsGUIDString = strings.ToLower(guid)
|
||||||
err = engine.Start()
|
err = engine.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unable to start engine for peer %d with error %v", j, err)
|
t.Errorf("unable to start engine for peer %d with error %v", j, err)
|
||||||
|
@ -4,9 +4,11 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
"github.com/pion/transport/v3/stdnet"
|
"github.com/pion/transport/v3/stdnet"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
@ -345,6 +347,9 @@ func Test_ConnectPeers(t *testing.T) {
|
|||||||
t.Fatal(err)
|
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)
|
iface1, err := NewWGIFace(peer1ifaceName, peer1wgIP, peer1wgPort, peer1Key.String(), DefaultMTU, newNet, nil, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@ -364,6 +369,9 @@ func Test_ConnectPeers(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
guid = fmt.Sprintf("{%s}", uuid.New().String())
|
||||||
|
CustomWindowsGUIDString = strings.ToLower(guid)
|
||||||
|
|
||||||
newNet, err = stdnet.NewNet()
|
newNet, err = stdnet.NewNet()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -7,6 +7,9 @@ import (
|
|||||||
"github.com/netbirdio/netbird/iface/bind"
|
"github.com/netbirdio/netbird/iface/bind"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// CustomWindowsGUIDString is a custom GUID string for the interface
|
||||||
|
var CustomWindowsGUIDString string
|
||||||
|
|
||||||
type wgTunDevice interface {
|
type wgTunDevice interface {
|
||||||
Create() (wgConfigurer, error)
|
Create() (wgConfigurer, error)
|
||||||
Up() (*bind.UniversalUDPMuxDefault, error)
|
Up() (*bind.UniversalUDPMuxDefault, error)
|
||||||
|
@ -14,6 +14,8 @@ import (
|
|||||||
"github.com/netbirdio/netbird/iface/bind"
|
"github.com/netbirdio/netbird/iface/bind"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const defaultWindowsGUIDSTring = "{f2f29e61-d91f-4d76-8151-119b20c4bdeb}"
|
||||||
|
|
||||||
type tunDevice struct {
|
type tunDevice struct {
|
||||||
name string
|
name string
|
||||||
address WGAddress
|
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) {
|
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")
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user