Skip to content

Commit

Permalink
WireGuard config: Replace kernelMode with noKernelTun
Browse files Browse the repository at this point in the history
  • Loading branch information
RPRX authored Oct 17, 2024
1 parent b0272c1 commit 2655e7a
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 42 deletions.
27 changes: 8 additions & 19 deletions infra/conf/wireguard.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ func (c *WireGuardPeerConfig) Build() (proto.Message, error) {
type WireGuardConfig struct {
IsClient bool `json:""`

KernelTun *bool `json:"kernelTun"`
KernelMode *bool `json:"kernelMode"`
NoKernelTun bool `json:"noKernelTun"`
SecretKey string `json:"secretKey"`
Address []string `json:"address"`
Peers []*WireGuardPeerConfig `json:"peers"`
Expand Down Expand Up @@ -121,24 +120,14 @@ func (c *WireGuardConfig) Build() (proto.Message, error) {
}

config.IsClient = c.IsClient
kernelTunSupported, err := wireguard.KernelTunSupported()
if err != nil {
errors.LogWarning(context.Background(), fmt.Sprintf("Failed to check kernel TUN support: %v. This may indicate that your OS doesn't support kernel TUN or you lack the necessary permissions. Please ensure you have the required privileges.", err))
config.KernelMode = false
return config, nil
}
if c.KernelMode == nil {
c.KernelMode = c.KernelTun
}
if c.KernelMode != nil {
config.KernelMode = *c.KernelMode
if config.KernelMode && !kernelTunSupported {
config.NoKernelTun = c.NoKernelTun
if !config.NoKernelTun {
if kernelTunSupported, err := wireguard.KernelTunSupported(); err != nil {
errors.LogWarning(context.Background(), fmt.Sprintf("Failed to check kernel TUN support: %v. This may indicate that your OS doesn't support kernel TUN or you lack the necessary permissions. Please ensure you have the required privileges.", err))
config.NoKernelTun = true
} else if !kernelTunSupported {
errors.LogWarning(context.Background(), "kernel TUN is not supported on your OS or permission is insufficient")
}
} else {
config.KernelMode = kernelTunSupported
if config.KernelMode {
errors.LogDebug(context.Background(), "kernel TUN is enabled as it's supported and permission is sufficient")
config.NoKernelTun = true
}
}

Expand Down
4 changes: 2 additions & 2 deletions infra/conf/wireguard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestWireGuardConfig(t *testing.T) {
"mtu": 1300,
"workers": 2,
"domainStrategy": "ForceIPv6v4",
"kernelMode": false
"noKernelTun": false
}`,
Parser: loadJSON(creator),
Output: &wireguard.DeviceConfig{
Expand All @@ -45,7 +45,7 @@ func TestWireGuardConfig(t *testing.T) {
Mtu: 1300,
NumWorkers: 2,
DomainStrategy: wireguard.DeviceConfig_FORCE_IP64,
KernelMode: false,
NoKernelTun: false,
},
},
})
Expand Down
2 changes: 1 addition & 1 deletion proxy/wireguard/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (c *DeviceConfig) fallbackIP6() bool {
}

func (c *DeviceConfig) createTun() tunCreator {
if c.KernelMode {
if !c.NoKernelTun {
return createKernelTun
}
return createGVisorTun
Expand Down
38 changes: 19 additions & 19 deletions proxy/wireguard/config.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion proxy/wireguard/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ message DeviceConfig {
bytes reserved = 6;
DomainStrategy domain_strategy = 7;
bool is_client = 8;
bool kernel_mode = 9;
bool no_kernel_tun = 9;
}

0 comments on commit 2655e7a

Please sign in to comment.