Jordan Whited 
							
						 
					 
					
						
						
							
						
						3bb8fec7e4 
					 
					
						
						
							
							conn, device, tun: implement vectorized I/O plumbing  
						
						... 
						
						
						
						Accept packet vectors for reading and writing in the tun.Device and
conn.Bind interfaces, so that the internal plumbing between these
interfaces now passes a vector of packets. Vectors move untouched
between these interfaces, i.e. if 128 packets are received from
conn.Bind.Read(), 128 packets are passed to tun.Device.Write(). There is
no internal buffering.
Currently, existing implementations are only adjusted to have vectors
of length one. Subsequent patches will improve that.
Also, as a related fixup, use the unix and windows packages rather than
the syscall package when possible.
Co-authored-by: James Tucker <james@tailscale.com >
Signed-off-by: James Tucker <james@tailscale.com >
Signed-off-by: Jordan Whited <jordan@tailscale.com >
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com > 
						
						
					 
					
						2023-03-10 14:52:13 +01:00 
						 
				 
			
				
					
						
							
							
								Jordan Whited 
							
						 
					 
					
						
						
							
						
						1e2c3e5a3c 
					 
					
						
						
							
							tun: guard Device.Events() against chan writes  
						
						... 
						
						
						
						Signed-off-by: Jordan Whited <jordan@tailscale.com >
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com > 
						
						
					 
					
						2023-02-09 12:35:58 -03:00 
						 
				 
			
				
					
						
							
							
								Jason A. Donenfeld 
							
						 
					 
					
						
						
							
						
						ebbd4a4330 
					 
					
						
						
							
							global: bump copyright year  
						
						... 
						
						
						
						Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com > 
						
						
					 
					
						2023-02-07 20:39:29 -03:00 
						 
				 
			
				
					
						
							
							
								Jason A. Donenfeld 
							
						 
					 
					
						
						
							
						
						bb719d3a6e 
					 
					
						
						
							
							global: bump copyright year  
						
						... 
						
						
						
						Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com > 
						
						
					 
					
						2022-09-20 17:21:32 +02:00 
						 
				 
			
				
					
						
							
							
								Brad Fitzpatrick 
							
						 
					 
					
						
						
							
						
						c31a7b1ab4 
					 
					
						
						
							
							conn, device, tun: set CLOEXEC on fds  
						
						... 
						
						
						
						Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com >
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com > 
						
						
					 
					
						2022-07-04 01:42:12 +02:00 
						 
				 
			
				
					
						
							
							
								Jason A. Donenfeld 
							
						 
					 
					
						
						
							
						
						9c9e7e2724 
					 
					
						
						
							
							global: apply gofumpt  
						
						... 
						
						
						
						Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com > 
						
						
					 
					
						2021-12-09 23:15:55 +01:00 
						 
				 
			
				
					
						
							
							
								Brad Fitzpatrick 
							
						 
					 
					
						
						
							
						
						0f4809f366 
					 
					
						
						
							
							tun: make NativeTun.Close well behaved, not crash on double close  
						
						... 
						
						
						
						Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com > 
						
						
					 
					
						2021-02-22 15:26:29 +01:00 
						 
				 
			
				
					
						
							
							
								Jason A. Donenfeld 
							
						 
					 
					
						
						
							
						
						8bf4204d2e 
					 
					
						
						
							
							global: stop using ioutil  
						
						... 
						
						
						
						Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com > 
						
						
					 
					
						2021-02-17 22:19:27 +01:00 
						 
				 
			
				
					
						
							
							
								Jason A. Donenfeld 
							
						 
					 
					
						
						
							
						
						c040dea798 
					 
					
						
						
							
							tun: use errors.Is for unwrapping  
						
						... 
						
						
						
						Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com > 
						
						
					 
					
						2021-02-09 19:50:31 +01:00 
						 
				 
			
				
					
						
							
							
								Jason A. Donenfeld 
							
						 
					 
					
						
						
							
						
						d4112d9096 
					 
					
						
						
							
							global: bump copyright  
						
						... 
						
						
						
						Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com > 
						
						
					 
					
						2021-01-28 17:52:15 +01:00 
						 
				 
			
				
					
						
							
							
								Josh Bleecher Snyder 
							
						 
					 
					
						
						
							
						
						1481e72107 
					 
					
						
						
							
							all: use ++ to increment  
						
						... 
						
						
						
						Make the code slightly more idiomatic. No functional changes.
Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com > 
						
						
					 
					
						2021-01-07 14:49:44 +01:00 
						 
				 
			
				
					
						
							
							
								Jason A. Donenfeld 
							
						 
					 
					
						
						
							
						
						db0aa39b76 
					 
					
						
						
							
							global: update header comments and modules  
						
						... 
						
						
						
						Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com > 
						
						
					 
					
						2020-05-02 02:08:26 -06:00 
						 
				 
			
				
					
						
							
							
								Jason A. Donenfeld 
							
						 
					 
					
						
						
							
						
						4cd06c0925 
					 
					
						
						
							
							tun: openbsd: check for interface already being up  
						
						... 
						
						
						
						In some cases, we operate on an already-up interface, or the user brings
up the interface before we start monitoring. For those situations, we
should first check if the interface is already up.
This still technically races between the initial check and the start of
the route loop, but fixing that is a bit ugly and probably not worth it
at the moment.
Reported-by: Theo Buehler <tb@theobuehler.org > 
						
						
					 
					
						2019-09-07 00:13:23 -05:00 
						 
				 
			
				
					
						
							
							
								Michael Zeltner 
							
						 
					 
					
						
						
							
						
						4d5819183e 
					 
					
						
						
							
							tun: openbsd: don't change MTU when it's already the expected size  
						
						... 
						
						
						
						Allows for running wireguard-go as non-root user.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com > 
						
						
					 
					
						2019-07-18 10:25:20 +02:00 
						 
				 
			
				
					
						
							
							
								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 
							
						 
					 
					
						
						
							
						
						eaf17becfa 
					 
					
						
						
							
							global: fixup TODO comment spacing  
						
						
						
						
					 
					
						2019-06-06 23:00:15 +02:00 
						 
				 
			
				
					
						
							
							
								Jason A. Donenfeld 
							
						 
					 
					
						
						
							
						
						3bf41b06ae 
					 
					
						
						
							
							global: regroup all imports  
						
						
						
						
					 
					
						2019-05-14 09:09:52 +02:00 
						 
				 
			
				
					
						
							
							
								Jason A. Donenfeld 
							
						 
					 
					
						
						
							
						
						6440f010ee 
					 
					
						
						
							
							receive: implement flush semantics  
						
						
						
						
					 
					
						2019-03-21 14:45:41 -06: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 
							
						 
					 
					
						
						
							
						
						42c6d0e261 
					 
					
						
						
							
							Change package path  
						
						
						
						
					 
					
						2019-02-18 05:11:39 +01:00 
						 
				 
			
				
					
						
							
							
								Jason A. Donenfeld 
							
						 
					 
					
						
						
							
						
						dff424baf8 
					 
					
						
						
							
							Update copyright  
						
						
						
						
					 
					
						2019-02-05 12:59:42 +01:00 
						 
				 
			
				
					
						
							
							
								Jason A. Donenfeld 
							
						 
					 
					
						
						
							
						
						2e772194cf 
					 
					
						
						
							
							tun: only call .Fd() once  
						
						... 
						
						
						
						Doing so tends to make the tunnel blocking, so we only retrieve it once
before we call SetNonblock, and then cache the result. 
						
						
					 
					
						2018-10-17 21:31:42 +02:00 
						 
				 
			
				
					
						
							
							
								Jason A. Donenfeld 
							
						 
					 
					
						
						
							
						
						5be541d147 
					 
					
						
						
							
							global: fix up copyright headers  
						
						
						
						
					 
					
						2018-09-16 18:49:19 +02:00 
						 
				 
			
				
					
						
							
							
								Jason A. Donenfeld 
							
						 
					 
					
						
						
							
						
						5079298ce2 
					 
					
						
						
							
							Disable broadcast mode on *BSD  
						
						... 
						
						
						
						Keeping it on makes IPv6 problematic and confuses routing daemons. 
						
						
					 
					
						2018-05-27 22:55:15 +02:00 
						 
				 
			
				
					
						
							
							
								Jason A. Donenfeld 
							
						 
					 
					
						
						
							
						
						2f2eca8947 
					 
					
						
						
							
							Catch EINTR  
						
						
						
						
					 
					
						2018-05-24 15:36:29 +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