mirror of
https://github.com/slackhq/nebula.git
synced 2026-05-16 04:47:38 +02:00
flatten tio.Capabilities
This commit is contained in:
@@ -15,6 +15,10 @@ import (
|
||||
// exercise the datapath.
|
||||
type NoopTun struct{}
|
||||
|
||||
func (NoopTun) Capabilities() tio.Capabilities {
|
||||
return tio.Capabilities{}
|
||||
}
|
||||
|
||||
func (NoopTun) RoutesFor(addr netip.Addr) routing.Gateways {
|
||||
return routing.Gateways{}
|
||||
}
|
||||
|
||||
@@ -34,15 +34,16 @@ type Queue interface {
|
||||
// Read returns one or more packets. The returned Packet.Bytes slices
|
||||
// are borrowed from the Queue's internal buffer and are only valid
|
||||
// until the next Read or Close on this Queue - callers must encrypt
|
||||
// or copy each slice before the next call. A Packet may carry a
|
||||
// GSO/USO superpacket (see GSOInfo); when GSO.IsSuperpacket() is
|
||||
// true the caller must segment Bytes before treating it as a single
|
||||
// IP datagram. Not safe for concurrent Reads.
|
||||
// or copy each slice before the next call.
|
||||
Read() ([]Packet, error)
|
||||
|
||||
// Write emits a single packet on the plaintext (outside→inside)
|
||||
// delivery path. Not safe for concurrent Writes.
|
||||
Write(p []byte) (int, error)
|
||||
|
||||
// Capabilities returns the Queue's negotiated offload capabilities,
|
||||
// or the zero value when q does not advertise any.
|
||||
Capabilities() Capabilities
|
||||
}
|
||||
|
||||
// Packet is the unit Queue.Read returns. Bytes points into the queue's
|
||||
@@ -79,38 +80,6 @@ type GSOInfo struct {
|
||||
// and sent on the wire.
|
||||
func (g GSOInfo) IsSuperpacket() bool { return g.Size > 0 }
|
||||
|
||||
// Clone returns a Packet whose Bytes is a freshly allocated copy of p.Bytes,
|
||||
// safe to retain past the next Read or Close on the originating Queue.
|
||||
// GSO metadata is copied verbatim. Use this only when a caller genuinely
|
||||
// needs to outlive the borrowed-slice contract — the hot path reads should
|
||||
// continue to consume the borrow synchronously to avoid the allocation.
|
||||
func (p Packet) Clone() Packet {
|
||||
if p.Bytes == nil {
|
||||
return p
|
||||
}
|
||||
cp := make([]byte, len(p.Bytes))
|
||||
copy(cp, p.Bytes)
|
||||
return Packet{Bytes: cp, GSO: p.GSO}
|
||||
}
|
||||
|
||||
// CapsProvider is an optional interface implemented by Queues that
|
||||
// successfully negotiated kernel offload features at open time. Callers
|
||||
// pick a write-path coalescer based on the result. Queues that don't
|
||||
// implement it are treated as having no offload capability — callers must
|
||||
// fall back to plain per-packet writes.
|
||||
type CapsProvider interface {
|
||||
Capabilities() Capabilities
|
||||
}
|
||||
|
||||
// QueueCapabilities returns q's negotiated offload capabilities, or the
|
||||
// zero value when q does not advertise any.
|
||||
func QueueCapabilities(q Queue) Capabilities {
|
||||
if cp, ok := q.(CapsProvider); ok {
|
||||
return cp.Capabilities()
|
||||
}
|
||||
return Capabilities{}
|
||||
}
|
||||
|
||||
// GSOProto selects the L4 protocol for a GSO superpacket. Determines which
|
||||
// VIRTIO_NET_HDR_GSO_* type the writer stamps and which checksum offset
|
||||
// inside the transport header virtio NEEDS_CSUM expects.
|
||||
|
||||
@@ -128,3 +128,7 @@ func (t *tun) NewMultiQueueReader() error {
|
||||
func (t *tun) Readers() []tio.Queue {
|
||||
return []tio.Queue{t}
|
||||
}
|
||||
|
||||
func (t *tun) Capabilities() tio.Capabilities {
|
||||
return tio.Capabilities{}
|
||||
}
|
||||
|
||||
@@ -573,3 +573,7 @@ func (t *tun) NewMultiQueueReader() error {
|
||||
func (t *tun) Readers() []tio.Queue {
|
||||
return []tio.Queue{t}
|
||||
}
|
||||
|
||||
func (t *tun) Capabilities() tio.Capabilities {
|
||||
return tio.Capabilities{}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,10 @@ type disabledQueue struct {
|
||||
batchRet [1]tio.Packet
|
||||
}
|
||||
|
||||
func (q *disabledQueue) Capabilities() tio.Capabilities {
|
||||
return tio.Capabilities{}
|
||||
}
|
||||
|
||||
func (q *disabledQueue) Read() ([]tio.Packet, error) {
|
||||
r, ok := <-q.parent.read
|
||||
if !ok {
|
||||
|
||||
@@ -609,6 +609,10 @@ func (t *tun) Readers() []tio.Queue {
|
||||
return []tio.Queue{t}
|
||||
}
|
||||
|
||||
func (t *tun) Capabilities() tio.Capabilities {
|
||||
return tio.Capabilities{}
|
||||
}
|
||||
|
||||
func (t *tun) removeRoutes(routes []Route) error {
|
||||
for _, r := range routes {
|
||||
if !r.Install {
|
||||
|
||||
@@ -184,3 +184,7 @@ func (t *tun) NewMultiQueueReader() error {
|
||||
func (t *tun) Readers() []tio.Queue {
|
||||
return []tio.Queue{t}
|
||||
}
|
||||
|
||||
func (t *tun) Capabilities() tio.Capabilities {
|
||||
return tio.Capabilities{}
|
||||
}
|
||||
|
||||
@@ -84,6 +84,10 @@ func (t *tun) Readers() []tio.Queue {
|
||||
return []tio.Queue{t}
|
||||
}
|
||||
|
||||
func (t *tun) Capabilities() tio.Capabilities {
|
||||
return tio.Capabilities{}
|
||||
}
|
||||
|
||||
var deviceNameRE = regexp.MustCompile(`^tun[0-9]+$`)
|
||||
|
||||
func newTunFromFd(_ *config.C, _ *slog.Logger, _ int, _ []netip.Prefix) (*tun, error) {
|
||||
|
||||
@@ -383,6 +383,10 @@ func (t *tun) Readers() []tio.Queue {
|
||||
return []tio.Queue{t}
|
||||
}
|
||||
|
||||
func (t *tun) Capabilities() tio.Capabilities {
|
||||
return tio.Capabilities{}
|
||||
}
|
||||
|
||||
func addRoute(prefix netip.Prefix, gateways []netip.Prefix) error {
|
||||
sock, err := unix.Socket(unix.AF_ROUTE, unix.SOCK_RAW, unix.AF_UNSPEC)
|
||||
if err != nil {
|
||||
|
||||
@@ -197,6 +197,10 @@ func (t *TestTun) Readers() []tio.Queue {
|
||||
return []tio.Queue{t}
|
||||
}
|
||||
|
||||
func (t *TestTun) Capabilities() tio.Capabilities {
|
||||
return tio.Capabilities{}
|
||||
}
|
||||
|
||||
func (t *TestTun) SupportsMultiqueue() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -284,6 +284,10 @@ func (t *winTun) Readers() []tio.Queue {
|
||||
return []tio.Queue{t}
|
||||
}
|
||||
|
||||
func (t *winTun) Capabilities() tio.Capabilities {
|
||||
return tio.Capabilities{}
|
||||
}
|
||||
|
||||
func (t *winTun) Close() error {
|
||||
// It seems that the Windows networking stack doesn't like it when we destroy interfaces that have active routes,
|
||||
// so to be certain, just remove everything before destroying.
|
||||
|
||||
@@ -42,6 +42,10 @@ type UserDevice struct {
|
||||
batchRet [1]tio.Packet
|
||||
}
|
||||
|
||||
func (d *UserDevice) Capabilities() tio.Capabilities {
|
||||
return tio.Capabilities{}
|
||||
}
|
||||
|
||||
func (d *UserDevice) Read() ([]tio.Packet, error) {
|
||||
if d.readBuf == nil {
|
||||
d.readBuf = make([]byte, defaultBatchBufSize)
|
||||
|
||||
Reference in New Issue
Block a user