Fix: set non block on TUN device

This commit is contained in:
Quentin McGaw (desktop)
2021-09-12 13:32:50 +00:00
parent 2ea00d149f
commit 19bf62c21f

View File

@@ -15,6 +15,8 @@ type Creator interface {
var (
ErrMknod = errors.New("cannot create TUN device file node")
ErrUnixOpen = errors.New("cannot Unix Open TUN device file")
ErrSetNonBlock = errors.New("cannot set non block to TUN device file descriptor")
)
// Create creates a TUN device at the path specified.
@@ -34,5 +36,16 @@ func (t *Tun) Create(path string) error {
return fmt.Errorf("%w: %s", ErrMknod, err)
}
fd, err := unix.Open(path, 0, 0)
if err != nil {
return fmt.Errorf("%w: %s", ErrUnixOpen, err)
}
const nonBlocking = true
err = unix.SetNonblock(fd, nonBlocking)
if err != nil {
return fmt.Errorf("%w: %s", ErrSetNonBlock, err)
}
return nil
}