mirror of
https://github.com/yggdrasil-network/water.git
synced 2025-05-19 16:35:10 +03:00
Linux set interface underlying fd to non-blocking
This commit is contained in:
parent
8c63d7a3c7
commit
4d58427608
2 changed files with 47 additions and 2 deletions
|
@ -31,7 +31,7 @@ func ioctl(fd uintptr, request uintptr, argp uintptr) error {
|
|||
}
|
||||
|
||||
func newTAP(config Config) (ifce *Interface, err error) {
|
||||
file, err := os.OpenFile("/dev/net/tun", os.O_RDWR, 0)
|
||||
file, err := openTun()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ func newTAP(config Config) (ifce *Interface, err error) {
|
|||
}
|
||||
|
||||
func newTUN(config Config) (ifce *Interface, err error) {
|
||||
file, err := os.OpenFile("/dev/net/tun", os.O_RDWR, 0)
|
||||
file, err := openTun()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -107,5 +107,16 @@ func setDeviceOptions(fd uintptr, config Config) (err error) {
|
|||
if config.Persist {
|
||||
value = 1
|
||||
}
|
||||
|
||||
return ioctl(fd, syscall.TUNSETPERSIST, uintptr(value))
|
||||
}
|
||||
|
||||
func openTun() (*os.File, error) {
|
||||
tunFile := "/dev/net/tun"
|
||||
bfile, err := os.OpenFile(tunFile, os.O_RDWR, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return os.NewFile(bfile.Fd(), tunFile), nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue