This commit is contained in:
bluepython508 committed 2026-10-22 12:27:19 +01:00
1 parent 3530afb854
commit 6903fcff27
2146 files changed
+112256 -190703

No files matched your search

+22 -8
View File
@@ -1,4 +1,4 @@
// Copyright (c) Tailscale Inc & AUTHORS
// Copyright (c) Tailscale Inc & contributors
// SPDX-License-Identifier: BSD-3-Clause
// TSMP is our ICMP-like "Tailscale Message Protocol" for signaling
@@ -29,7 +29,7 @@ const minTSMPSize = 7 // the rejected body is 7 bytes
// On the wire, after the IP header, it's currently 7 or 8 bytes:
// - '!'
// - IPProto byte (IANA protocol number: TCP or UDP)
// - 'A' or 'S' (RejectedDueToACLs, RejectedDueToShieldsUp)
// - byte stating rejection reason (see [TailscaleRejectReason] for valid values)
// - srcPort big endian uint16
// - dstPort big endian uint16
// - [optional] byte of flag bits:
@@ -63,19 +63,20 @@ func (rh TailscaleRejectedHeader) String() string {
return fmt.Sprintf("TSMP-reject-flow{%s %s > %s}: %s", rh.Proto, rh.Src, rh.Dst, rh.Reason)
}
// TSMPType is the type byte of a TSMP message. It follows the IPv4 or IPv6 header.
type TSMPType uint8
const (
// TSMPTypeRejectedConn is the type byte for a TailscaleRejectedHeader.
// TSMPTypeRejectedConn is the type byte for a [TailscaleRejectedHeader].
TSMPTypeRejectedConn TSMPType = '!'
// TSMPTypePing is the type byte for a TailscalePingRequest.
// TSMPTypePing is the type byte for a [TSMPPingRequest].
TSMPTypePing TSMPType = 'p'
// TSMPTypePong is the type byte for a TailscalePongResponse.
// TSMPTypePong is the type byte for a [TSMPPongReply].
TSMPTypePong TSMPType = 'o'
// TSPMTypeDiscoAdvertisement is the type byte for sending disco keys
// TSMPTypeDiscoAdvertisement is the type byte for a [TSMPDiscoKeyAdvertisement].
TSMPTypeDiscoAdvertisement TSMPType = 'a'
)
@@ -101,6 +102,11 @@ const (
// RejectedDueToHostFirewall means that the target host's
// firewall is blocking the traffic.
RejectedDueToHostFirewall TailscaleRejectReason = 'W'
// RejectedDueToUnknownAppConnectorTransitIP means that the connector host has no real IP
// mapping that matches the provided transit IP for this client, so the
// connector has no destination to forward the connection to.
RejectedDueToUnknownAppConnectorTransitIP TailscaleRejectReason = 'T'
)
func (r TailscaleRejectReason) String() string {
@@ -113,6 +119,8 @@ func (r TailscaleRejectReason) String() string {
return "host-ip-forwarding-unavailable"
case RejectedDueToHostFirewall:
return "host-firewall"
case RejectedDueToUnknownAppConnectorTransitIP:
return "app-connector-transit-ip-unknown"
}
return fmt.Sprintf("0x%02x", byte(r))
}
@@ -265,7 +273,9 @@ func (h TSMPPongReply) Marshal(buf []byte) error {
return nil
}
// TSMPDiscoKeyAdvertisement is a TSMP message that's used for distributing Disco Keys.
// TSMPDiscoKeyAdvertisement is a TSMP message that's used for distributing
// [key.DiscoPublic]. It is sent immediately following eligible WireGuard
// session establishment starting at [tailscale.com/tailcfg.CapabilityVersion] 144.
//
// On the wire, after the IP header, it's currently 33 bytes:
// - 'a' (TSMPTypeDiscoAdvertisement)
@@ -275,6 +285,10 @@ type TSMPDiscoKeyAdvertisement struct {
Key key.DiscoPublic
}
// Marshal marshals ka to a wire representation appropriate for transmission
// over WireGuard to a remote client. A marshaled [TSMPDiscoKeyAdvertisement]
// must not exceed [github.com/tailscale/wireguard-go/device.MaxPriorityMessageContentSize],
// or wireguard-go will reject and discard the payload.
func (ka *TSMPDiscoKeyAdvertisement) Marshal() ([]byte, error) {
var iph Header
if ka.Src.Is4() {
@@ -290,7 +304,7 @@ func (ka *TSMPDiscoKeyAdvertisement) Marshal() ([]byte, error) {
Dst: ka.Dst,
}
}
payload := make([]byte, 0, 33)
payload := make([]byte, 0, 1+key.DiscoPublicRawLen)
payload = append(payload, byte(TSMPTypeDiscoAdvertisement))
payload = ka.Key.AppendTo(payload)
if len(payload) != 33 {