2019-01-02 01:55:51 +01:00
|
|
|
/* SPDX-License-Identifier: MIT
|
2018-05-23 02:10:54 +02:00
|
|
|
*
|
2022-09-20 17:21:32 +02:00
|
|
|
* Copyright (C) 2017-2023 WireGuard LLC. All Rights Reserved.
|
2018-05-23 02:10:54 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
package tun
|
|
|
|
|
2019-02-27 01:06:43 +01:00
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
)
|
2018-05-23 02:10:54 +02:00
|
|
|
|
2019-06-10 23:33:40 +02:00
|
|
|
type Event int
|
2018-05-23 02:10:54 +02:00
|
|
|
|
|
|
|
const (
|
2019-06-10 23:33:40 +02:00
|
|
|
EventUp = 1 << iota
|
|
|
|
EventDown
|
|
|
|
EventMTUUpdate
|
2018-05-23 02:10:54 +02:00
|
|
|
)
|
|
|
|
|
2019-06-10 23:33:40 +02:00
|
|
|
type Device interface {
|
2023-03-02 23:48:02 +01:00
|
|
|
// 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
|
2018-05-23 02:10:54 +02:00
|
|
|
}
|