Documentation
¶
Index ¶
Constants ¶
const (
MaxMessageSize = math.MaxUint16
)
Variables ¶
var ( ErrTun = errors.New("tun device error") ErrInvalidNet = errors.New("invalid net IP") )
var ErrNoRoute = errors.New("tun: no route")
ErrNoRoute is what deliver reports when a destination names no peer, or a peer with no stream behind it. It is a routing miss and nothing worse: the packet is dropped, the hub keeps reading the device.
var ErrRegistrationRefused = errors.New("tun: registration refused")
ErrRegistrationRefused reports a spoke registration the hub's policy rejected — the authorizer, the passphrase, or the self-loop guard. It is returned — never echoed — so the stream is torn down: the spoke redials and re-registers (a fixed hub recovers on its own) instead of sitting "running" with zero traffic, and the failure surfaces in its counters. Nothing is answered, so a refused peer learns nothing except that the stream died. Malformed frames and bare echoes are not this: they never reach policy, and killing a stream over transport noise would turn one stray datagram into a reconnect storm.
Functions ¶
func NewP2PHandler ¶ added in v0.28.1
func NewP2PHandler(device net.Conn, authorizer PeerAuthorizer, opts ...handler.Option) handler.Handler
NewP2PHandler builds a hub over device — the tun conn the listener produced — for the peers that reach it over p2p. authorizer decides which addresses a peer's registration may claim, and may be nil when a peer is to be able to claim whatever it asks for.
There is no auther here, because a p2p peer has nothing to authenticate: the allowlist that routed its stream here already said who it is, and onKeepalive consults an auther with the *claimed address* as the user name — so a credential check could only ever ask "is this peer allowed the address it just claimed", which is the question authorizer answers, and which an operator could otherwise satisfy only by typing each spoke's own IP into the tunnel's username field.
The hub's device reader starts here and runs until Close, so a packet off the device is being routed before the first stream arrives.
Types ¶
type PeerAuthorizer ¶ added in v0.28.1
PeerAuthorizer decides whether the peer that sent a registration may claim the addresses in it.
It exists because an auth.Authenticator cannot answer the question: onKeepalive passes the claimed address as the user name and the frame's key as the password, so an auther never learns which peer is claiming and cannot bind a claim to one. The peer key is already authenticated by the transport — a p2p hub's allowlist is what routed the stream here — so this is authorization, not authentication: it decides which addresses a known peer may hold.
peer is the transport's name for the sender, verbatim: a "host:port" for a socket peer, a p2p peer key for a p2p one. ips is every address the frame claimed, and an implementation should require the whole set rather than a subset: peerTable.set is last-writer-wins per address, so a peer that also claims a neighbour's address takes that route over.
type PrefixRoute ¶ added in v0.28.1
PrefixRoute is a LAN route the hub holds: the member that reaches the prefix, and the members allowed to use it (empty = everyone).
It is exported because the hub that installs these routes lives in another module: the tun p2p handler is handed to it as a handler.Handler, so it names the map it passes by this type. Nothing else in x or outside it constructs one.