aboutsummaryrefslogtreecommitdiff
path: root/tun/tun.go
diff options
context:
space:
mode:
authorJordan Whited <jordan@tailscale.com>2023-03-02 14:48:02 -0800
committerJason A. Donenfeld <Jason@zx2c4.com>2023-03-10 14:52:13 +0100
commit3bb8fec7e41fcc2138ddb4cba3f46100814fc523 (patch)
treee6c83a2ae0178ffee5dde657cbbdd17ee427dbbe /tun/tun.go
parent21636207a6756120f56f836b06c086b627f7b911 (diff)
downloadwireguard-go-3bb8fec7e41fcc2138ddb4cba3f46100814fc523.tar.gz
wireguard-go-3bb8fec7e41fcc2138ddb4cba3f46100814fc523.zip
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>
Diffstat (limited to 'tun/tun.go')
-rw-r--r--tun/tun.go40
1 files changed, 32 insertions, 8 deletions
diff --git a/tun/tun.go b/tun/tun.go
index 01051b9..e203ba8 100644
--- a/tun/tun.go
+++ b/tun/tun.go
@@ -18,12 +18,36 @@ const (
)
type Device interface {
- File() *os.File // returns the file descriptor of the device
- Read([]byte, int) (int, error) // read a packet from the device (without any additional headers)
- Write([]byte, int) (int, error) // writes a packet to the device (without any additional headers)
- Flush() error // flush all previous writes to the device
- MTU() (int, error) // returns the MTU of the device
- Name() (string, error) // fetches and returns the current name
- Events() <-chan Event // returns a constant channel of events related to the device
- Close() error // stops the device and closes the event channel
+ // File returns the file descriptor of the device.
+ File() *os.File
+
+ // Read one or more packets from the Device (without any additional headers).
+ // On a successful read it returns the number of packets read, and sets
+ // packet lengths within the sizes slice. len(sizes) must be >= len(buffs).
+ // A nonzero offset can be used to instruct the Device on where to begin
+ // reading into each element of the buffs slice.
+ Read(buffs [][]byte, sizes []int, offset int) (n int, err error)
+
+ // Write one or more packets to the device (without any additional headers).
+ // On a successful write it returns the number of packets written. A nonzero
+ // offset can be used to instruct the Device on where to begin writing from
+ // each packet contained within the buffs slice.
+ Write(buffs [][]byte, offset int) (int, error)
+
+ // MTU returns the MTU of the Device.
+ MTU() (int, error)
+
+ // Name returns the current name of the Device.
+ Name() (string, error)
+
+ // Events returns a channel of type Event, which is fed Device events.
+ Events() <-chan Event
+
+ // Close stops the Device and closes the Event channel.
+ Close() error
+
+ // BatchSize returns the preferred/max number of packets that can be read or
+ // written in a single read/write call. BatchSize must not change over the
+ // lifetime of a Device.
+ BatchSize() int
}