Make it work

This commit is contained in:
braginini
2023-03-27 19:09:01 +02:00
parent 2e7d199a6d
commit d6c2b46019
7 changed files with 34 additions and 49 deletions
+6
View File
@@ -1,6 +1,7 @@
package iface
import (
"github.com/netbirdio/netbird/iface/bind"
"net"
"sync"
"time"
@@ -21,6 +22,11 @@ type WGIface struct {
mu sync.Mutex
}
// GetBind returns a userspace implementation of WireGuard Bind interface
func (w *WGIface) GetBind() *bind.ICEBind {
return w.tun.iceBind
}
// Create creates a new Wireguard interface, sets a given IP and brings it up.
// Will reuse an existing one.
func (w *WGIface) Create() error {
+8 -6
View File
@@ -1,11 +1,11 @@
package iface
import (
"github.com/netbirdio/netbird/iface/bind"
"net"
log "github.com/sirupsen/logrus"
"golang.org/x/sys/unix"
"golang.zx2c4.com/wireguard/conn"
"golang.zx2c4.com/wireguard/device"
"golang.zx2c4.com/wireguard/ipc"
"golang.zx2c4.com/wireguard/tun"
@@ -16,10 +16,11 @@ type tunDevice struct {
mtu int
tunAdapter TunAdapter
fd int
name string
device *device.Device
uapi net.Listener
fd int
name string
device *device.Device
uapi net.Listener
iceBind *bind.ICEBind
}
func newTunDevice(address WGAddress, mtu int, tunAdapter TunAdapter) *tunDevice {
@@ -27,6 +28,7 @@ func newTunDevice(address WGAddress, mtu int, tunAdapter TunAdapter) *tunDevice
address: address,
mtu: mtu,
tunAdapter: tunAdapter,
iceBind: &bind.ICEBind{},
}
}
@@ -46,7 +48,7 @@ func (t *tunDevice) Create() error {
t.name = name
log.Debugf("attaching to interface %v", name)
t.device = device.NewDevice(tunDevice, conn.NewStdNetBind(), device.NewLogger(device.LogLevelSilent, "[wiretrustee] "))
t.device = device.NewDevice(tunDevice, t.iceBind, device.NewLogger(device.LogLevelSilent, "[wiretrustee] "))
t.device.DisableSomeRoamingForBrokenMobileSemantics()
log.Debugf("create uapi")
+2 -2
View File
@@ -11,10 +11,10 @@ import (
)
func (c *tunDevice) Create() error {
if WireguardModuleIsLoaded() {
/*if WireguardModuleIsLoaded() {
log.Info("using kernel WireGuard")
return c.createWithKernel()
}
}*/
if !tunModuleIsLoaded() {
return fmt.Errorf("couldn't check or load tun module")
+2 -2
View File
@@ -8,7 +8,6 @@ import (
"os"
log "github.com/sirupsen/logrus"
"golang.zx2c4.com/wireguard/conn"
"golang.zx2c4.com/wireguard/device"
"golang.zx2c4.com/wireguard/ipc"
"golang.zx2c4.com/wireguard/tun"
@@ -27,6 +26,7 @@ func newTunDevice(name string, address WGAddress, mtu int) *tunDevice {
name: name,
address: address,
mtu: mtu,
iceBind: &bind.ICEBind{},
}
}
@@ -71,7 +71,7 @@ func (c *tunDevice) createWithUserspace() (NetInterface, error) {
}
// We need to create a wireguard-go device and listen to configuration requests
tunDevice := device.NewDevice(tunIface, conn.NewDefaultBind(), device.NewLogger(device.LogLevelSilent, "[wiretrustee] "))
tunDevice := device.NewDevice(tunIface, c.iceBind, device.NewLogger(device.LogLevelSilent, "[wiretrustee] "))
err = tunDevice.Up()
if err != nil {
return tunIface, err
+2 -1
View File
@@ -13,10 +13,11 @@ type tunDevice struct {
name string
address WGAddress
netInterface NetInterface
iceBind *bind.ICEBind
}
func newTunDevice(name string, address WGAddress, mtu int) *tunDevice {
return &tunDevice{name: name, address: address}
return &tunDevice{name: name, address: address, iceBind: &bind.ICEBind{}}
}
func (c *tunDevice) Create() error {