-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix : check wireguard kernel setup conditions
- Loading branch information
Showing
8 changed files
with
96 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
//go:build linux | ||
|
||
package wireguard | ||
|
||
import ( | ||
"os" | ||
"os/exec" | ||
"strings" | ||
|
||
"kernel.org/pub/linux/libs/security/libcap/cap" | ||
) | ||
|
||
func IsLinux() bool { | ||
return true | ||
} | ||
|
||
func CheckUnixKernelTunDeviceEnabled() bool { | ||
if _, err := os.Stat("/dev/net/tun"); err != nil { | ||
return false | ||
} | ||
return true | ||
} | ||
|
||
func CheckUnixKernelNetAdminCapEnabled() bool { | ||
orig := cap.GetProc() | ||
c, err := orig.Dup() | ||
if err != nil { | ||
return false | ||
} | ||
on, _ := c.GetFlag(cap.Effective, cap.NET_ADMIN) | ||
return on | ||
} | ||
|
||
func CheckUnixKernelIPv4SrcValidMarkEnabled() bool { | ||
buf, _ := os.ReadFile("/proc/sys/net/ipv4/conf/all/src_valid_mark") | ||
value := strings.TrimSpace(string(buf)) | ||
return value == "1" | ||
} | ||
|
||
func CheckUnixKernelIPv6IsEnabled() bool { | ||
buf, _ := os.ReadFile("/proc/sys/net/ipv6/conf/all/disable_ipv6") | ||
value := strings.TrimSpace(string(buf)) | ||
return value == "0" | ||
} | ||
|
||
// CheckUnixKernelTunSupported returns true if kernel tun is supported. | ||
// 1. check if the current process has CAP_NET_ADMIN capability | ||
// 2. check if /proc/sys/net/ipv4/conf/all/src_valid_mark exists and is set to 1 | ||
// 3. check if iptables is available | ||
func CheckUnixKernelTunSupported() bool { | ||
if !CheckUnixKernelTunDeviceEnabled() || !CheckUnixKernelNetAdminCapEnabled() { | ||
return false | ||
} | ||
outCmd := exec.Command("sh", "-c", "command -v iptables") | ||
outBuffer, err := outCmd.CombinedOutput() | ||
if err != nil { | ||
return false | ||
} | ||
iptablesPath := strings.TrimSpace(string(outBuffer)) | ||
return iptablesPath != "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
//go:build !linux | ||
|
||
package wireguard | ||
|
||
func IsLinux() bool { | ||
return false | ||
} | ||
|
||
func CheckUnixKernelTunDeviceEnabled() bool { | ||
return true | ||
} | ||
|
||
func CheckUnixKernelNetAdminCapEnabled() bool { | ||
return false | ||
} | ||
|
||
func CheckUnixKernelIPv6IsEnabled() bool { | ||
return false | ||
} | ||
|
||
func CheckUnixKernelIPv4SrcValidMarkEnabled() bool { | ||
return false | ||
} | ||
|
||
func CheckUnixKernelTunSupported() bool { | ||
return false | ||
} |