Movatterモバイル変換


[0]ホーム

URL:


disco

package
v1.92.2Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 10, 2025 License:BSD-3-ClauseImports:10Imported by:9

Details

Repository

github.com/tailscale/tailscale

Links

Documentation

Overview

Package disco contains the discovery message types.

A discovery message is:

Header:

magic          [6]byte  // “TS💬” (0x54 53 f0 9f 92 ac)senderDiscoPub [32]byte // nacl public keynonce          [24]byte

The recipient then decrypts the bytes following (the nacl box)and then the inner payload structure is:

messageType     byte  (the MessageType constants below)messageVersion  byte  (0 for now; but always ignore bytes at the end)message-payload [...]byte

Index

Constants

View Source
const (TypePing                             =MessageType(0x01)TypePong                             =MessageType(0x02)TypeCallMeMaybe                      =MessageType(0x03)TypeBindUDPRelayEndpoint             =MessageType(0x04)TypeBindUDPRelayEndpointChallenge    =MessageType(0x05)TypeBindUDPRelayEndpointAnswer       =MessageType(0x06)TypeCallMeMaybeVia                   =MessageType(0x07)TypeAllocateUDPRelayEndpointRequest  =MessageType(0x08)TypeAllocateUDPRelayEndpointResponse =MessageType(0x09))
View Source
const BindUDPRelayChallengeLen = 32

BindUDPRelayChallengeLen is the length of the Challenge field carried inBindUDPRelayEndpointChallenge &BindUDPRelayEndpointAnswer messages.

View Source
const Magic = "TS💬"// 6 bytes: 0x54 53 f0 9f 92 ac

Magic is the 6 byte header of all discovery messages.

View Source
const MessageHeaderLen = 2

MessageHeaderLen is the length of a message header, 2 bytes for type and version.

View Source
const NonceLen = 24

NonceLen is the length of the nonces used by nacl box.

View Source
const PingLen = 12 +key.NodePublicRawLen

PingLen is the length of a marshalled ping message, without the messageheader or padding.

Variables

This section is empty.

Functions

funcLooksLikeDiscoWrapperadded inv1.0.0

func LooksLikeDiscoWrapper(p []byte)bool

LooksLikeDiscoWrapper reports whether p looks like it's a packetcontaining an encrypted disco message.

funcMessageSummary

func MessageSummary(mMessage)string

MessageSummary returns a short summary of m for logging purposes.

funcSourceadded inv1.14.6

func Source(p []byte) (src []byte, okbool)

Source returns the slice of p that represents thedisco public key source, and whether p looks likea disco message.

funcToPCAPFrameadded inv1.48.0

func ToPCAPFrame(srcnetip.AddrPort, derpNodeSrckey.NodePublic, payload []byte) []byte

ToPCAPFrame marshals the bytes for a pcap record that describe a disco frame.

Warning: Alloc garbage. Acceptable while capturing.

Types

typeAllocateUDPRelayEndpointRequestadded inv1.86.0

type AllocateUDPRelayEndpointRequest struct {// ClientDisco are the Disco public keys of the clients that should be// permitted to handshake with the endpoint.ClientDisco [2]key.DiscoPublic// Generation represents the allocation request generation. The server must// echo it back in the [AllocateUDPRelayEndpointResponse] to enable request// and response alignment client-side.Generationuint32}

AllocateUDPRelayEndpointRequest is a message sent only over DERP to requestallocation of a relay endpoint on atailscale.com/net/udprelay.Server

func (*AllocateUDPRelayEndpointRequest)AppendMarshaladded inv1.86.0

func (m *AllocateUDPRelayEndpointRequest) AppendMarshal(b []byte) []byte

typeAllocateUDPRelayEndpointResponseadded inv1.86.0

type AllocateUDPRelayEndpointResponse struct {// Generation represents the allocation request generation. The server must// echo back the [AllocateUDPRelayEndpointRequest.Generation] here to enable// request and response alignment client-side.Generationuint32UDPRelayEndpoint}

AllocateUDPRelayEndpointResponse is a message sent only over DERP in responseto aAllocateUDPRelayEndpointRequest.

func (*AllocateUDPRelayEndpointResponse)AppendMarshaladded inv1.86.0

func (m *AllocateUDPRelayEndpointResponse) AppendMarshal(b []byte) []byte

typeBindUDPRelayEndpointadded inv1.84.0

type BindUDPRelayEndpoint struct {BindUDPRelayEndpointCommon}

BindUDPRelayEndpoint is the first messaged transmitted from UDP relay clienttowards UDP relay server as part of the 3-way bind handshake.

func (*BindUDPRelayEndpoint)AppendMarshaladded inv1.84.0

func (m *BindUDPRelayEndpoint) AppendMarshal(b []byte) []byte

typeBindUDPRelayEndpointAnsweradded inv1.84.0

type BindUDPRelayEndpointAnswer struct {BindUDPRelayEndpointCommon}

BindUDPRelayEndpointAnswer is transmitted from UDP relay client to UDP relayserver in response to a BindUDPRelayEndpointChallenge message.

func (*BindUDPRelayEndpointAnswer)AppendMarshaladded inv1.84.0

func (m *BindUDPRelayEndpointAnswer) AppendMarshal(b []byte) []byte

typeBindUDPRelayEndpointChallengeadded inv1.84.0

type BindUDPRelayEndpointChallenge struct {BindUDPRelayEndpointCommon}

BindUDPRelayEndpointChallenge is transmitted from UDP relay server towardsUDP relay client in response to a BindUDPRelayEndpoint message as part of the3-way bind handshake.

func (*BindUDPRelayEndpointChallenge)AppendMarshaladded inv1.84.0

func (m *BindUDPRelayEndpointChallenge) AppendMarshal(b []byte) []byte

typeBindUDPRelayEndpointCommonadded inv1.86.0

type BindUDPRelayEndpointCommon struct {// VNI is the Geneve header Virtual Network Identifier field value, which// must match this disco-sealed value upon reception. If they are// non-matching it indicates the cleartext Geneve header was tampered with// and/or mangled.VNIuint32// Generation represents the handshake generation. Clients must set a new,// nonzero value at the start of every handshake.Generationuint32// RemoteKey is the disco key of the remote peer participating over this// relay endpoint.RemoteKeykey.DiscoPublic// Challenge is set by the server in a [BindUDPRelayEndpointChallenge]// message, and expected to be echoed back by the client in a// [BindUDPRelayEndpointAnswer] message. Its value is irrelevant in a// [BindUDPRelayEndpoint] message, where it simply serves a padding purpose// ensuring all handshake messages are equal in size.Challenge [BindUDPRelayChallengeLen]byte}

BindUDPRelayEndpointCommon contains fields that are common across all 3UDP relay handshake message types. All 4 field values are expected to beconsistent for the lifetime of a handshake besides Challenge, which isirrelevant in aBindUDPRelayEndpoint message.

typeBindUDPRelayHandshakeStateadded inv1.84.0

type BindUDPRelayHandshakeStateint

BindUDPRelayHandshakeState represents the state of the 3-way bind handshakebetween UDP relay client and UDP relay server. Its potential values includethose for both participants, UDP relay client and UDP relay server. A UDPrelay server implementation can be found in net/udprelay. This is currentlyconsidered experimental.

const (// BindUDPRelayHandshakeStateInit represents the initial state prior to any// message being transmitted.BindUDPRelayHandshakeStateInitBindUDPRelayHandshakeState =iota// BindUDPRelayHandshakeStateBindSent is the first client state after// transmitting a BindUDPRelayEndpoint message to a UDP relay server.BindUDPRelayHandshakeStateBindSent// BindUDPRelayHandshakeStateChallengeSent is the first server state after// receiving a BindUDPRelayEndpoint message from a UDP relay client and// replying with a BindUDPRelayEndpointChallenge.BindUDPRelayHandshakeStateChallengeSent// BindUDPRelayHandshakeStateAnswerSent is a client state that is entered// after transmitting a BindUDPRelayEndpointAnswer message towards a UDP// relay server in response to a BindUDPRelayEndpointChallenge message.BindUDPRelayHandshakeStateAnswerSent// BindUDPRelayHandshakeStateAnswerReceived is a server state that is// entered after it has received a correct BindUDPRelayEndpointAnswer// message from a UDP relay client in response to a// BindUDPRelayEndpointChallenge message.BindUDPRelayHandshakeStateAnswerReceived)

typeCallMeMaybe

type CallMeMaybe struct {// MyNumber is what the peer believes its endpoints are.//// Prior to Tailscale 1.4, the endpoints were exchanged purely// between nodes and the control server.//// Starting with Tailscale 1.4, clients advertise their endpoints.// Older clients won't use this, but newer clients should// use any endpoints in here that aren't included from control.//// Control might have sent stale endpoints if the client was idle// before contacting us. In that case, the client likely did a STUN// request immediately before sending the CallMeMaybe to recreate// their NAT port mapping, and that new good endpoint is included// in this field, but might not yet be in control's endpoints.// (And in the future, control will stop distributing endpoints// when clients are suitably new.)MyNumber []netip.AddrPort}

CallMeMaybe is a message sent only over DERP to request that the recipient tryto open up a magicsock path back to the sender.

The sender should've already sent UDP packets to the peer to openup the stateful firewall mappings inbound.

The recipient may choose to not open a path back, if it's alreadyhappy with its path. But usually it will.

func (*CallMeMaybe)AppendMarshal

func (m *CallMeMaybe) AppendMarshal(b []byte) []byte

typeCallMeMaybeViaadded inv1.84.0

type CallMeMaybeVia struct {UDPRelayEndpoint}

CallMeMaybeVia is a message sent only over DERP to request that the recipienttry to open up a magicsock path back to the sender. The 'Via' inCallMeMaybeVia highlights that candidate paths are served through anintermediate relay, likely atailscale.com/net/udprelay.Server.

Usage of the candidate paths in magicsock requires a 3-way handshakeinvolvingBindUDPRelayEndpoint,BindUDPRelayEndpointChallenge, andBindUDPRelayEndpointAnswer.

CallMeMaybeVia mirrorstailscale.com/net/udprelay/endpoint.ServerEndpoint,which contains field documentation.

The recipient may choose to not open a path back if it's already happy withits path. Direct connections, e.g.CallMeMaybe-signaled, take priority overCallMeMaybeVia paths.

func (*CallMeMaybeVia)AppendMarshaladded inv1.84.0

func (m *CallMeMaybeVia) AppendMarshal(b []byte) []byte

typeMessage

type Message interface {// AppendMarshal appends the message's marshaled representation.// TODO(jwhited): consider using a signature matching encoding.BinaryAppenderAppendMarshal([]byte) []byte}

Message a discovery message.

funcParse

func Parse(p []byte) (Message,error)

Parse parses the encrypted part of the message from inside thenacl box.

typeMessageType

type MessageTypebyte

typePing

type Ping struct {// TxID is a random client-generated per-ping transaction ID.TxID [12]byte// NodeKey is allegedly the ping sender's wireguard public key.// Old clients (~1.16.0 and earlier) don't send this field.// It shouldn't be trusted by itself, but can be combined with// netmap data to reduce the discokey:nodekey relation from 1:N to// 1:1.NodeKeykey.NodePublic// Padding is the number of 0 bytes at the end of the// message. (It's used to probe path MTU.)Paddingint}

func (*Ping)AppendMarshal

func (m *Ping) AppendMarshal(b []byte) []byte

typePong

type Pong struct {TxID [12]byteSrcnetip.AddrPort// 18 bytes (16+2) on the wire; v4-mapped ipv6 for IPv4}

Pong is a response a Ping.

It includes the sender's source IP + port, so it's effectively aSTUN response.

func (*Pong)AppendMarshal

func (m *Pong) AppendMarshal(b []byte) []byte

typeUDPRelayEndpointadded inv1.86.0

type UDPRelayEndpoint struct {// ServerDisco is [tailscale.com/net/udprelay/endpoint.ServerEndpoint.ServerDisco]ServerDiscokey.DiscoPublic// ClientDisco is [tailscale.com/net/udprelay/endpoint.ServerEndpoint.ClientDisco]ClientDisco [2]key.DiscoPublic// LamportID is [tailscale.com/net/udprelay/endpoint.ServerEndpoint.LamportID]LamportIDuint64// VNI is [tailscale.com/net/udprelay/endpoint.ServerEndpoint.VNI]VNIuint32// BindLifetime is [tailscale.com/net/udprelay/endpoint.ServerEndpoint.BindLifetime]BindLifetimetime.Duration// SteadyStateLifetime is [tailscale.com/net/udprelay/endpoint.ServerEndpoint.SteadyStateLifetime]SteadyStateLifetimetime.Duration// AddrPorts is [tailscale.com/net/udprelay/endpoint.ServerEndpoint.AddrPorts]AddrPorts []netip.AddrPort}

UDPRelayEndpoint is a mirror oftailscale.com/net/udprelay/endpoint.ServerEndpoint,refer to it for field documentation.UDPRelayEndpoint is carried in bothCallMeMaybeVia andAllocateUDPRelayEndpointResponse messages.

Source Files

View all Source files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp