Commit Graph

31 Commits

Author SHA1 Message Date
Jason A. Donenfeld
3bf41b06ae global: regroup all imports 2019-05-14 09:09:52 +02:00
Jason A. Donenfeld
d9078fe772 main: revise warnings 2019-04-19 07:48:09 +09:00
Jason A. Donenfeld
69f0fe67b6 global: begin modularization 2019-03-03 05:00:40 +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
42c6d0e261 Change package path 2019-02-18 05:11:39 +01:00
Jason A. Donenfeld
6f76edd045 Import windows scafolding 2019-02-05 12:59:42 +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
955e89839f Print version number in log 2018-05-30 01:09:18 +02:00
Jason A. Donenfeld
2f2eca8947 Catch EINTR 2018-05-24 15:36:29 +02:00
Jason A. Donenfeld
4a9de3218e Add undocumented --version flag 2018-05-24 02:25:36 +02:00
Jason A. Donenfeld
588b9f01ae Adopt GOPATH
GOPATH is annoying, but the Go community pushing me to adopt it is even
more annoying.
2018-05-23 05:18:13 +02:00
Jason A. Donenfeld
0a63188afa Move tun to subpackage 2018-05-23 03:58:27 +02:00
Filippo Valsorda
bc05eb1c3c Minor main.go signal fixes
* Buffer the signal channel as it's non-blocking on the sender side
* Notify on SIGTERM instead of the uncatchable SIGKILL

License: MIT
Signed-off-by: Filippo Valsorda <valsorda@google.com>
2018-05-21 20:22:12 +02:00
Mathias Hall-Andersen
38accea986 Add copyright headers 2018-05-19 02:40:22 +02:00
Jason A. Donenfeld
115a2e3946 Use /dev/null as place holder 2018-05-14 20:06:33 +02:00
Jason A. Donenfeld
a62c770a99 Ugly hack to suppress warning on backgrounded process 2018-05-14 16:01:58 +02:00
Jason A. Donenfeld
795f76cffa Netlink sockets can't be shutdown 2018-05-14 14:08:03 +02:00
Jason A. Donenfeld
355e9bd619 Clean more 2018-05-14 12:27:29 +02:00
Jason A. Donenfeld
c1e097d6d0 Optional logging even in background 2018-05-14 03:38:06 +02:00
Jason A. Donenfeld
233f079a94 Rewrite timers and related state machines 2018-05-10 16:08:03 +02:00
Mathias Hall-Andersen
abe2651ad5 Removed remaining signals from peer
1. Removed remaining signals from peer struct
2. Made needAnotherKeepalive local
3. Removed environment check from warning text (annoying when debugging)
2018-05-05 22:07:58 +02:00
Mathias Hall-Andersen
7a83f2565a Removed old signals 2018-05-05 04:15:07 +02:00
Jason A. Donenfeld
e1de0f229a uapi: use kqueue for sock deletion on darwin 2018-05-04 21:51:55 +02:00
Jason A. Donenfeld
de7ecc571b tun: allow darwin to auto assign names 2018-05-04 21:11:51 +02:00
Jason A. Donenfeld
0f322f83f5 warning: put into main 2018-05-04 19:50:08 +02:00
Jason A. Donenfeld
a040786645 global: Add SPDX tags and copyright header
Mathias should probably add his copyright headers to each file too.
2018-05-03 15:06:25 +02:00
Jason A. Donenfeld
209dd22ea0 Daemonize with environment variable 2018-05-03 14:55:10 +02:00
Jason A. Donenfeld
258a9223b9 Start to dust off Darwin 2018-05-03 14:55:10 +02:00
Jason A. Donenfeld
676bb91434 We can determine the interface name ourselves 2018-04-19 16:00:20 +02:00
Mathias Hall-Andersen
a0f54cbe5a Align with go library layout 2018-02-04 16:08:26 +01:00