Skip to content

Commit

Permalink
Add darwin and win support
Browse files Browse the repository at this point in the history
  • Loading branch information
pappz committed Dec 21, 2023
1 parent ad6f5fc commit 41397b0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
15 changes: 12 additions & 3 deletions iface/iface_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"fmt"

"github.com/pion/transport/v2"

"github.com/netbirdio/netbird/iface/netstack"
)

// NewWGIFace Creates a new WireGuard interface instance
Expand All @@ -16,10 +18,17 @@ func NewWGIFace(iFaceName string, address string, mtu int, transportNet transpor
return nil, err
}

wgIFace := &WGIface{
tun: newTunDevice(iFaceName, wgAddress, mtu, transportNet),
userspaceBind: false,
wgIFace := &WGIface{}

if netstack.IsEnabled() {
wgIFace.tun = newTunNetstackDevice(iFaceName, wgAddress, mtu, transportNet, netstack.ListenAddr())
wgIFace.userspaceBind = true
return wgIFace, nil
}

wgIFace.tun = newTunDevice(iFaceName, wgAddress, mtu, transportNet)
wgIFace.userspaceBind = false

return wgIFace, nil
}

Expand Down
15 changes: 12 additions & 3 deletions iface/iface_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"

"github.com/pion/transport/v2"

"github.com/netbirdio/netbird/iface/netstack"
)

// NewWGIFace Creates a new WireGuard interface instance
Expand All @@ -13,10 +15,17 @@ func NewWGIFace(iFaceName string, address string, mtu int, transportNet transpor
return nil, err
}

wgIFace := &WGIface{
tun: newTunDevice(iFaceName, wgAddress, mtu, transportNet),
userspaceBind: false,
wgIFace := &WGIface{}

if netstack.IsEnabled() {
wgIFace.tun = newTunNetstackDevice(iFaceName, wgAddress, mtu, transportNet, netstack.ListenAddr())
wgIFace.userspaceBind = true
return wgIFace, nil
}

wgIFace.tun = newTunDevice(iFaceName, wgAddress, mtu, transportNet)
wgIFace.userspaceBind = false

return wgIFace, nil
}

Expand Down
4 changes: 1 addition & 3 deletions iface/tun_netstack_linux.go → iface/tun_netstack.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//go:build linux && !android

package iface

import (
Expand Down Expand Up @@ -34,7 +32,7 @@ func newTunNetstackDevice(name string, address WGAddress, mtu int, transportNet
}

func (t *tunNetstackDevice) Create() (wgConfigurer, error) {
log.Info("create tun interface")
log.Info("create netstack tun interface")
t.nsTun = netstack.NewNetStackTun(t.listenAddress, t.address.IP.String(), t.mtu)
tunIface, err := t.nsTun.Create()
if err != nil {
Expand Down

0 comments on commit 41397b0

Please sign in to comment.