mirror of
https://github.com/qdm12/gluetun.git
synced 2026-07-30 17:03:22 +02:00
fix(wireguard): skip tun device checks when using kernelspace
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"net"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/netlink"
|
||||
gtun "github.com/qdm12/gluetun/internal/tun"
|
||||
"golang.org/x/sys/unix"
|
||||
"golang.zx2c4.com/wireguard/conn"
|
||||
"golang.zx2c4.com/wireguard/device"
|
||||
@@ -37,15 +38,18 @@ func (w *Wireguard) Run(ctx context.Context, waitError chan<- error, ready chan<
|
||||
kernelSupported := w.netlink.IsWireguardSupported()
|
||||
|
||||
setupFunction := setupUserSpace
|
||||
userspace := false
|
||||
switch w.settings.Implementation {
|
||||
case "auto": //nolint:goconst
|
||||
if !kernelSupported {
|
||||
w.logger.Info("Using userspace implementation since Kernel support does not exist")
|
||||
userspace = true
|
||||
break
|
||||
}
|
||||
w.logger.Info("Using available kernelspace implementation")
|
||||
setupFunction = setupKernelSpace
|
||||
case "userspace":
|
||||
userspace = true
|
||||
case "kernelspace":
|
||||
if !kernelSupported {
|
||||
waitError <- fmt.Errorf("%w", ErrKernelSupport)
|
||||
@@ -56,6 +60,14 @@ func (w *Wireguard) Run(ctx context.Context, waitError chan<- error, ready chan<
|
||||
panic(fmt.Sprintf("unknown implementation %q", w.settings.Implementation))
|
||||
}
|
||||
|
||||
if userspace {
|
||||
err := gtun.Setup()
|
||||
if err != nil {
|
||||
waitError <- fmt.Errorf("setting up userspace tun device: %w", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
client, err := wgctrl.New()
|
||||
if err != nil {
|
||||
waitError <- fmt.Errorf("%w: %s", ErrWgctrlOpen, err)
|
||||
|
||||
Reference in New Issue
Block a user