1- //go:build linux && !android
1+ //go:build linux
22
33package wireguard
44
@@ -8,19 +8,14 @@ import (
88 "fmt"
99 "net"
1010 "net/netip"
11- "os"
12- "os/exec"
13- "strings"
1411
1512 "golang.org/x/sys/unix"
1613
1714 "github.com/sagernet/sing/common/control"
1815 "github.com/vishvananda/netlink"
19- wgtun "golang.zx2c4.com/wireguard/tun"
20- "kernel.org/pub/linux/libs/security/libcap/cap"
21-
2216 "github.com/xtls/xray-core/proxy/wireguard/iptables"
2317 iptexec "github.com/xtls/xray-core/proxy/wireguard/iptables/exec"
18+ wgtun "golang.zx2c4.com/wireguard/tun"
2419)
2520
2621type deviceNet struct {
@@ -92,7 +87,7 @@ func createKernelTun(localAddresses []netip.Addr, mtu int, handler promiscuousMo
9287 x := prefixes
9388 v4 = & x
9489 }
95- if v6 == nil && prefixes .Is6 () {
90+ if v6 == nil && prefixes .Is6 () && CheckUnixKernelIPv6IsEnabled () {
9691 x := prefixes
9792 v6 = & x
9893 }
@@ -244,33 +239,3 @@ func createKernelTun(localAddresses []netip.Addr, mtu int, handler promiscuousMo
244239 out .tun = wgt
245240 return out , nil
246241}
247-
248- // KernelTunSupported returns true if kernel tun is supported.
249- // 1. check if the current process has CAP_NET_ADMIN capability
250- // 2. check if /proc/sys/net/ipv4/conf/all/src_valid_mark exists and is set to 1
251- // 3. check if iptables is available
252- func KernelTunSupported () bool {
253- orig := cap .GetProc ()
254- c , err := orig .Dup ()
255- if err != nil {
256- return false
257- }
258- on , _ := c .GetFlag (cap .Effective , cap .NET_ADMIN )
259- if ! on {
260- return false
261- }
262-
263- buf , _ := os .ReadFile ("/proc/sys/net/ipv4/conf/all/src_valid_mark" )
264- value := strings .TrimSpace (string (buf ))
265- if value != "1" {
266- return false
267- }
268-
269- outCmd := exec .Command ("sh" , "-c" , "command -v iptables" )
270- outBuffer , err := outCmd .CombinedOutput ()
271- if err != nil {
272- return false
273- }
274- iptablesPath := strings .TrimSpace (string (outBuffer ))
275- return iptablesPath != ""
276- }
0 commit comments