-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1287 from apernet/fix-tun-ipv6-disable
fix: tun failed on linux when ipv6.disable=1
- Loading branch information
Showing
4 changed files
with
58 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
//go:build !unix && !windows | ||
|
||
package tun | ||
|
||
import "net" | ||
|
||
func isIPv6Supported() bool { | ||
lis, err := net.ListenPacket("udp6", "[::1]:0") | ||
if err != nil { | ||
return false | ||
} | ||
_ = lis.Close() | ||
return true | ||
} |
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,16 @@ | ||
//go:build unix | ||
|
||
package tun | ||
|
||
import ( | ||
"golang.org/x/sys/unix" | ||
) | ||
|
||
func isIPv6Supported() bool { | ||
sock, err := unix.Socket(unix.AF_INET6, unix.SOCK_DGRAM, unix.IPPROTO_UDP) | ||
if err != nil { | ||
return false | ||
} | ||
_ = unix.Close(sock) | ||
return true | ||
} |
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,24 @@ | ||
//go:build windows | ||
|
||
package tun | ||
|
||
import ( | ||
"golang.org/x/sys/windows" | ||
) | ||
|
||
func isIPv6Supported() bool { | ||
var wsaData windows.WSAData | ||
err := windows.WSAStartup(uint32(0x202), &wsaData) | ||
if err != nil { | ||
// Failing silently: it is not our duty to report such errors | ||
return true | ||
} | ||
defer windows.WSACleanup() | ||
|
||
sock, err := windows.Socket(windows.AF_INET6, windows.SOCK_DGRAM, windows.IPPROTO_UDP) | ||
if err != nil { | ||
return false | ||
} | ||
_ = windows.Closesocket(sock) | ||
return true | ||
} |
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