mirror of
https://github.com/netbirdio/netbird.git
synced 2024-11-22 16:13:31 +01:00
64f2d295a8
* script to generate syso files * test wireguard-windows driver package * set int log * add windows test * add windows test * verbose bash * use cd * move checkout * exit 0 * removed tty flag * artifact path * fix tags and add cache * fix cache * fix cache * test dir * restore artifacts in the root * try dll file * try dll file * copy dll * typo in copy dll * compile test * checkout first * updated cicd * fix add address issue and gen GUID * psexec typo * accept eula * mod tidy before tests * regular test exec and verbose test with psexec * test all * return WGInterface Interface * use WgIfaceName and timeout after 30 seconds * different ports and validate connect 2 peers * Use time.After for timeout and close interface * Use time.After for testing connect peers * WG Interface struct * Update engine and parse address * refactor Linux create and assignAddress * NewWGIface and configuration methods * Update proxy with interface methods * update up command test * resolve lint warnings * remove psexec test * close copied files * add goos before build * run tests on mac,windows and linux * cache by testing os * run on push * fix indentation * adjust test timeouts * remove parallel flag * mod tidy before test * ignore syso files * removed functions and renamed vars * different IPs for connect peers test * Generate syso with DLL * Single Close method * use port from test constant * test: remove wireguard interfaces after finishing engine test * use load_wgnt_from_rsrc Co-authored-by: braginini <bangvalo@gmail.com>
48 lines
1.3 KiB
Go
48 lines
1.3 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.SetLogging(driver.AdapterLogOn)
|
|
if err != nil {
|
|
err = fmt.Errorf("Error enabling adapter logging: %w", err)
|
|
return err
|
|
}
|
|
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
|
|
}
|