2026-01-07 23:05:08 +01:00
|
|
|
package tun
|
|
|
|
|
|
2026-10-12 05:05:12 +03:00
|
|
|
// packetRoom is what a tun may need in front of a packet in the buffer that it is read into
|
|
|
|
|
const packetRoom = 16
|
2026-04-13 21:38:10 +08:00
|
|
|
|
2026-01-07 23:05:08 +01:00
|
|
|
// Tun interface implements tun interface interaction
|
|
|
|
|
type Tun interface {
|
|
|
|
|
Start() error
|
|
|
|
|
Close() error
|
2026-04-13 21:38:10 +08:00
|
|
|
Name() (string, error)
|
|
|
|
|
Index() (int, error)
|
2026-10-12 05:05:12 +03:00
|
|
|
// ReadPacket waits for a packet, reads it into b and returns it
|
|
|
|
|
ReadPacket(b []byte) ([]byte, error)
|
|
|
|
|
// WritePacket writes a packet that is in two parts, the second of which may be empty
|
|
|
|
|
WritePacket(header, payload []byte) error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// segmenter is a tun whose other side takes TCP segments that are larger than the MTU,
|
2026-10-21 14:49:36 +03:00
|
|
|
// splits them only if it has to send them on, and completes their checksum then.
|
|
|
|
|
// What it sends comes as it is too, not split to the MTU
|
2026-10-12 05:05:12 +03:00
|
|
|
type segmenter interface {
|
2026-10-21 14:49:36 +03:00
|
|
|
// Segments reports whether ReadParts and WriteSegment can be used
|
2026-10-12 05:05:12 +03:00
|
|
|
Segments() bool
|
2026-10-21 14:49:36 +03:00
|
|
|
// ReadParts waits for a packet, reads it into parts, one after the other, and returns its size
|
|
|
|
|
ReadParts(parts [][]byte) (int, error)
|
2026-10-12 05:05:12 +03:00
|
|
|
// WriteSegment writes a packet with a TCP segment whose payload is in parts, to be sent on with mss bytes
|
|
|
|
|
// of it at most in one. Its checksum is that of the pseudo-header only, not inverted
|
|
|
|
|
WriteSegment(header []byte, payload [][]byte, mss int) error
|
2026-01-07 23:05:08 +01:00
|
|
|
}
|