mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-24 14:29:07 +02:00
Fix some iface issues
This commit is contained in:
@@ -2,6 +2,10 @@ package iface
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
"golang.zx2c4.com/wireguard/conn"
|
||||||
|
"golang.zx2c4.com/wireguard/device"
|
||||||
|
"golang.zx2c4.com/wireguard/tun"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
@@ -92,3 +96,49 @@ func (w *WGIface) Close() error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *WGIface) CreateNew(bind conn.Bind) error {
|
||||||
|
w.mu.Lock()
|
||||||
|
defer w.mu.Unlock()
|
||||||
|
|
||||||
|
return w.createWithUserspaceNew(bind)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *WGIface) createWithUserspaceNew(bind conn.Bind) error {
|
||||||
|
tunIface, err := tun.CreateTUN(w.Name, w.MTU)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Interface = tunIface
|
||||||
|
|
||||||
|
// We need to create a wireguard-go device and listen to configuration requests
|
||||||
|
tunDevice := device.NewDevice(tunIface, bind, device.NewLogger(device.LogLevelSilent, "[wiretrustee] "))
|
||||||
|
err = tunDevice.Up()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
uapi, err := getUAPI(w.Name)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
uapiConn, uapiErr := uapi.Accept()
|
||||||
|
if uapiErr != nil {
|
||||||
|
log.Traceln("uapi Accept failed with error: ", uapiErr)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
go tunDevice.IpcHandle(uapiConn)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
log.Debugln("UAPI listener started")
|
||||||
|
|
||||||
|
err = w.assignAddr()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package iface
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"golang.zx2c4.com/wireguard/conn"
|
|
||||||
"math"
|
"math"
|
||||||
"os"
|
"os"
|
||||||
"syscall"
|
"syscall"
|
||||||
@@ -33,12 +32,6 @@ func WireguardModExists() bool {
|
|||||||
|
|
||||||
return errors.Is(err, syscall.EINVAL)
|
return errors.Is(err, syscall.EINVAL)
|
||||||
}
|
}
|
||||||
func (w *WGIface) CreateNew(bind conn.Bind) error {
|
|
||||||
w.mu.Lock()
|
|
||||||
defer w.mu.Unlock()
|
|
||||||
|
|
||||||
return w.createWithUserspaceNew(bind)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create creates a new Wireguard interface, sets a given IP and brings it up.
|
// Create creates a new Wireguard interface, sets a given IP and brings it up.
|
||||||
// Will reuse an existing one.
|
// Will reuse an existing one.
|
||||||
|
|||||||
@@ -12,45 +12,6 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (w *WGIface) createWithUserspaceNew(bind conn.Bind) error {
|
|
||||||
tunIface, err := tun.CreateTUN(w.Name, w.MTU)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
w.Interface = tunIface
|
|
||||||
|
|
||||||
// We need to create a wireguard-go device and listen to configuration requests
|
|
||||||
tunDevice := device.NewDevice(tunIface, bind, device.NewLogger(device.LogLevelSilent, "[wiretrustee] "))
|
|
||||||
err = tunDevice.Up()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
uapi, err := getUAPI(w.Name)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
for {
|
|
||||||
uapiConn, uapiErr := uapi.Accept()
|
|
||||||
if uapiErr != nil {
|
|
||||||
log.Traceln("uapi Accept failed with error: ", uapiErr)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
go tunDevice.IpcHandle(uapiConn)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
log.Debugln("UAPI listener started")
|
|
||||||
|
|
||||||
err = w.assignAddr()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// createWithUserspace Creates a new Wireguard interface, using wireguard-go userspace implementation
|
// createWithUserspace Creates a new Wireguard interface, using wireguard-go userspace implementation
|
||||||
func (w *WGIface) createWithUserspace() error {
|
func (w *WGIface) createWithUserspace() error {
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"golang.org/x/sys/windows"
|
"golang.org/x/sys/windows"
|
||||||
|
"golang.zx2c4.com/wireguard/ipc"
|
||||||
"golang.zx2c4.com/wireguard/windows/driver"
|
"golang.zx2c4.com/wireguard/windows/driver"
|
||||||
"golang.zx2c4.com/wireguard/windows/tunnel/winipcfg"
|
"golang.zx2c4.com/wireguard/windows/tunnel/winipcfg"
|
||||||
"net"
|
"net"
|
||||||
@@ -62,3 +63,8 @@ func (w *WGIface) UpdateAddr(newAddr string) error {
|
|||||||
func WireguardModExists() bool {
|
func WireguardModExists() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// getUAPI returns a Listener
|
||||||
|
func getUAPI(iface string) (net.Listener, error) {
|
||||||
|
return ipc.UAPIListen(iface)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user