device: add priority message transmission around session establishment

Add SetPriorityMessageOnEstablishmentFunc, which registers a
PeerPriorityMessageFunc callback invoked when a peer's session keypair
is established or re-keyed for forward data transmission. The bytes it
returns are transmitted to the peer as a transport message.

The message is "priority" in two senses: it bypasses the staged packet
queue entirely, so it cannot be evicted by TUN-sourced packets, and it
is enqueued ahead of the keepalive/staged packets that follow keypair
establishment.

Updates tailscale/tailscale#20081

Signed-off-by: Jordan Whited <jordan@tailscale.com>
This commit is contained in:
Jordan Whited 2026-07-07 14:55:53 -07:00 committed by 世界
parent 15b912c1c0
commit 7a66fbee4a
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
3 changed files with 100 additions and 1 deletions

View file

@ -425,6 +425,7 @@ func (device *Device) RoutineHandshake(id int) {
peer.timersSessionDerived()
peer.timersHandshakeComplete()
peer.SendPriorityMessage()
peer.SendKeepalive()
}
skip:
@ -493,6 +494,7 @@ func (peer *Peer) processInboundContainer(elemsContainer *QueueInboundElementsCo
if peer.ReceivedWithKeypair(elem.keypair) {
peer.SetEndpointFromPacket(elem.endpoint)
peer.timersHandshakeComplete()
peer.SendPriorityMessage()
peer.SendStagedPackets()
}
if ep, ok := elem.endpoint.(conn.PeerAwareEndpoint); ok {