mirror of
https://github.com/netbirdio/netbird.git
synced 2025-06-20 01:38:41 +02:00
refactort: extract method to create Wireguard interface using kernel module
This commit is contained in:
parent
729b16e599
commit
f2ca2fc7c1
@ -5,5 +5,5 @@ package iface
|
|||||||
// 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.
|
||||||
func Create(iface string, address string) error {
|
func Create(iface string, address string) error {
|
||||||
return CreateInUserspace(iface, address)
|
return CreateWithUserspace(iface, address)
|
||||||
}
|
}
|
||||||
|
@ -26,8 +26,8 @@ func ConfigureWithKeyGen(iface string) (*wgtypes.Key, error) {
|
|||||||
return &key, Configure(iface, key.String())
|
return &key, Configure(iface, key.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateInUserspace Creates a new Wireguard interface, using wireguard-go userspace implementation
|
// CreateWithUserspace Creates a new Wireguard interface, using wireguard-go userspace implementation
|
||||||
func CreateInUserspace(iface string, address string) error {
|
func CreateWithUserspace(iface string, address string) error {
|
||||||
var err error
|
var err error
|
||||||
tunIface, err := tun.CreateTUN(iface, defaultMTU)
|
tunIface, err := tun.CreateTUN(iface, defaultMTU)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -11,6 +11,16 @@ import (
|
|||||||
func Create(iface string, address string) error {
|
func Create(iface string, address string) error {
|
||||||
|
|
||||||
if WireguardModExists() {
|
if WireguardModExists() {
|
||||||
|
return CreateWithKernel(iface, address)
|
||||||
|
} else {
|
||||||
|
return CreateWithUserspace(iface, address)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateWithKernel Creates a new Wireguard interface using kernel Wireguard module.
|
||||||
|
// Works for Linux and offers much better network performance
|
||||||
|
func CreateWithKernel(iface string, address string) error {
|
||||||
attrs := netlink.NewLinkAttrs()
|
attrs := netlink.NewLinkAttrs()
|
||||||
attrs.Name = iface
|
attrs.Name = iface
|
||||||
|
|
||||||
@ -55,10 +65,6 @@ func Create(iface string, address string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
} else {
|
|
||||||
return CreateInUserspace(iface, address)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// assignAddr Adds IP address to the tunnel interface
|
// assignAddr Adds IP address to the tunnel interface
|
||||||
|
Loading…
x
Reference in New Issue
Block a user