Commit graph

9 commits

Author SHA1 Message Date
Matt Layher 1f48971a80 tun: remove TUN prefix from types to reduce stutter elsewhere
Signed-off-by: Matt Layher <mdlayher@gmail.com>
2019-06-14 18:35:57 +02:00
Jason A. Donenfeld 6440f010ee receive: implement flush semantics 2019-03-21 14:45:41 -06:00
Simon Rozman 91b4e909bb wintun: Use native Win32 API for I/O
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-03-21 00:56:45 +01:00
Jason A. Donenfeld 967d1a0f3d tun: allow special methods in NativeTun 2019-03-01 00:05:57 +01:00
Jason A. Donenfeld 366cbd11a4 tun: use netpoll instead of rwcancel
The new sysconn function of Go 1.12 makes this possible:

package main

import "log"
import "os"
import "unsafe"
import "time"
import "syscall"
import "sync"
import "golang.org/x/sys/unix"

func main() {
	fd, err := os.OpenFile("/dev/net/tun", os.O_RDWR, 0)
	if err != nil {
		log.Fatal(err)
	}

	var ifr [unix.IFNAMSIZ + 64]byte
	copy(ifr[:], []byte("cheese"))
	*(*uint16)(unsafe.Pointer(&ifr[unix.IFNAMSIZ])) = unix.IFF_TUN

	var errno syscall.Errno
	s, _ := fd.SyscallConn()
	s.Control(func(fd uintptr) {
		_, _, errno = unix.Syscall(
			unix.SYS_IOCTL,
			fd,
			uintptr(unix.TUNSETIFF),
			uintptr(unsafe.Pointer(&ifr[0])),
		)
	})
	if errno != 0 {
		log.Fatal(errno)
	}

	b := [4]byte{}
	wait := sync.WaitGroup{}
	wait.Add(1)
	go func() {
		_, err := fd.Read(b[:])
		log.Print("Read errored: ", err)
		wait.Done()
	}()
	time.Sleep(time.Second)
	log.Print("Closing")
	err = fd.Close()
	if err != nil {
		log.Print("Close errored: " , err)
	}
	wait.Wait()
	log.Print("Exiting")
}
2019-02-27 01:52:55 +01:00
Jason A. Donenfeld ab0f442daf tun: use sysconn instead of .Fd with Go 1.12 2019-02-27 01:34:11 +01:00
Jason A. Donenfeld dff424baf8 Update copyright 2019-02-05 12:59:42 +01:00
Jason A. Donenfeld 5be541d147 global: fix up copyright headers 2018-09-16 18:49:19 +02:00
Jason A. Donenfeld 0a63188afa Move tun to subpackage 2018-05-23 03:58:27 +02:00