mirror of
https://github.com/slackhq/nebula.git
synced 2026-08-15 09:36:58 +02:00
913a37cfee
Device loses io.ReadWriteCloser + NewMultiQueueReader in favor of Queues(n), which returns up to n tio.Queue objects; platforms without multiqueue hand back their single queue and the interface sizes its reader routines to what it actually got. Queue.Read returns a batch of borrowed packets (single-element for every current backend) so a future backend can deliver more than one packet per syscall without another interface change. The Linux poll/eventfd machinery moves out of tun_linux.go into the new overlay/tio package: nonblocking fds, a shared shutdown eventfd owned by the queue set, and pollfd arrays built on the stack so concurrent writers parked in blockOnWrite no longer share Revents storage. Other platforms wrap their existing one-datagram Read/Write in a singleQueue adapter that owns a private scratch buffer, so multiqueue-by-sharing devices (user, disabled) no longer race concurrent readers on one buffer. This is the tun-interface subset of better-tun-interface-ordering, extracted at 18dc13b with none of the GSO/GRO offload mechanics and no udp/sendmmsg changes. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
29 lines
870 B
Go
29 lines
870 B
Go
package overlay
|
|
|
|
import (
|
|
"io"
|
|
"net/netip"
|
|
|
|
"github.com/slackhq/nebula/overlay/tio"
|
|
"github.com/slackhq/nebula/routing"
|
|
)
|
|
|
|
// defaultBatchBufSize is the per-Queue scratch size for Read. 65535 covers
|
|
// any single IP packet.
|
|
const defaultBatchBufSize = 65535
|
|
|
|
type Device interface {
|
|
io.Closer
|
|
Activate() error
|
|
Networks() []netip.Prefix
|
|
Name() string
|
|
RoutesFor(netip.Addr) routing.Gateways
|
|
// Queues returns the device's packet queues, opening additional ones as
|
|
// needed until there are n. Platforms without multiqueue support return
|
|
// their single queue regardless of n, so callers must size reader loops
|
|
// to len(result), not n; implementations never return more than n. An
|
|
// error means a queue that should have opened could not; the caller owns
|
|
// cleanup via Close. Called once, during interface activation.
|
|
Queues(n int) ([]tio.Queue, error)
|
|
}
|