mirror of
https://github.com/netbirdio/netbird.git
synced 2024-11-07 16:54:16 +01:00
1cd1e84290
Updates test workflows with serial execution to avoid collision of ports and resource names. Also, used -exec sudo flag for UNIX tests and removed not-needed limits configuration on Linux and added a 5 minutes timeout. Updated the multi-peer tests in the client/internal/engine_test.go to provide proper validation when creating or starting a peer engine instance fails. As some operations of the tests running on windows are slow, we will experiment with disabling the Defender before restoring cache and checkout a repository, then we reenable it to run the tests. disabled extra logs for windows interface
43 lines
1.1 KiB
Go
43 lines
1.1 KiB
Go
package iface
|
|
|
|
import (
|
|
"fmt"
|
|
log "github.com/sirupsen/logrus"
|
|
"golang.org/x/sys/windows"
|
|
"golang.zx2c4.com/wireguard/windows/driver"
|
|
"golang.zx2c4.com/wireguard/windows/tunnel/winipcfg"
|
|
"net"
|
|
)
|
|
|
|
// Create Creates a new Wireguard interface, sets a given IP and brings it up.
|
|
func (w *WGIface) Create() error {
|
|
|
|
WintunStaticRequestedGUID, _ := windows.GenerateGUID()
|
|
adapter, err := driver.CreateAdapter(w.Name, "WireGuard", &WintunStaticRequestedGUID)
|
|
if err != nil {
|
|
err = fmt.Errorf("error creating adapter: %w", err)
|
|
return err
|
|
}
|
|
w.Interface = adapter
|
|
luid := adapter.LUID()
|
|
err = adapter.SetAdapterState(driver.AdapterStateUp)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
state, _ := luid.GUID()
|
|
log.Debugln("device guid: ", state.String())
|
|
return w.assignAddr(luid)
|
|
}
|
|
|
|
// assignAddr Adds IP address to the tunnel interface and network route based on the range provided
|
|
func (w *WGIface) assignAddr(luid winipcfg.LUID) error {
|
|
|
|
log.Debugf("adding address %s to interface: %s", w.Address.IP, w.Name)
|
|
err := luid.SetIPAddresses([]net.IPNet{{w.Address.IP, w.Address.Network.Mask}})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|