ts_capabilityversion/lib.rs
1#![doc = include_str!("../README.md")]
2#![no_std]
3
4use core::fmt;
5
6/// Indicates the capability level of a Tailscale node. This must be kept in-sync with the
7/// CapabilityVersion constants in the Golang codebase (`tailcfg/tailcfg.go`).
8///
9/// It can be thought of as a node's simple version number; a single monotonically increasing
10/// integer, rather than the complex x.y.z-cccccc semver+hash(es) versioning scheme. Whenever a
11/// node gains a capability or wants to negotiate a change in semantics with the control plane,
12/// peers, or an official frontend (such as LocalAPI in the Golang codebase), bump this number and
13/// document what's changed.
14///
15/// The capability versions 0, 1, 2, and 35 are undefined; [`CapabilityVersion::new`] rejects them.
16/// The one exception is [`CapabilityVersion::ZERO`], the "not reported" reading of a peer's
17/// `Node.Cap`, which Go represents as the zero value.
18///
19/// Note: Prior to 2022-03-06, this value was known as the "`MapRequest` version", `mapVer`, or "map
20/// cap"; you'll still see that name used in comments throughout the Golang codebase.
21#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
22#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
23pub struct CapabilityVersion(u16);
24
25/// [`CapabilityVersion::ZERO`], Go's zero value, **not** [`CapabilityVersion::CURRENT`].
26///
27/// The default is what a struct that derives `Default` gets for a capability-version field it was
28/// not told about. For a *peer's* `Node.Cap` that must be "not reported", as in Go: defaulting to
29/// this node's own declaration would make a peer that reported nothing look relay-capable,
30/// DNS-proxy-capable and (once 152 is declared) hybrid-handshake capable.
31///
32/// It is kept, rather than removed, so the request structs that derive `Default` keep doing so.
33/// Their raw defaults therefore carry version 0: every sender in this tree sets
34/// [`CapabilityVersion::CURRENT`] when it builds a request, or stamps it before serializing one,
35/// and a new sender must do the same.
36impl Default for CapabilityVersion {
37 #[inline]
38 fn default() -> Self {
39 Self::ZERO
40 }
41}
42
43impl CapabilityVersion {
44 /// 2020-??-??: implicit compression, keep-alives
45 pub const V3: Self = Self(3);
46 /// 2020-??-??: opt-in keep-alives via KeepAlive field, opt-in compression via Compress
47 pub const V4: Self = Self(4);
48 /// 2020-10-19: implies IncludeIPv6; delta Peers/UserProfiles, supports MagicDNS
49 pub const V5: Self = Self(5);
50 /// 2020-12-07: means MapResponse.PacketFilter nil means unchanged
51 pub const V6: Self = Self(6);
52 /// 2020-12-15: FilterRule.SrcIPs accepts CIDRs+ranges, doesn't warn about 0.0.0.0/::
53 pub const V7: Self = Self(7);
54 /// 2020-12-19: client can buggily receive IPv6 addresses and routes if beta enabled server-side
55 pub const V8: Self = Self(8);
56 /// 2020-12-30: client doesn't auto-add implicit search domains from peers; only
57 /// DNSConfig.Domains
58 pub const V9: Self = Self(9);
59 /// 2021-01-17: client understands MapResponse.PeerSeenChange
60 pub const V10: Self = Self(10);
61 /// 2021-03-03: client understands IPv6; multiple default routes, and goroutine dumping
62 pub const V11: Self = Self(11);
63 /// 2021-03-04: client understands PingRequest
64 pub const V12: Self = Self(12);
65 /// 2021-03-19: client understands FilterRule.IPProto
66 pub const V13: Self = Self(13);
67 /// 2021-04-07: client understands DNSConfig.Routes and DNSConfig.Resolvers
68 pub const V14: Self = Self(14);
69 /// 2021-04-12: client treats nil MapResponse.DNSConfig as meaning unchanged
70 pub const V15: Self = Self(15);
71 /// 2021-04-15: client understands Node.Online, MapResponse.OnlineChange
72 pub const V16: Self = Self(16);
73 /// 2021-04-18: MapResponse.Domain empty means unchanged
74 pub const V17: Self = Self(17);
75 /// 2021-04-19: MapResponse.Node nil means unchanged (all fields now omitempty)
76 pub const V18: Self = Self(18);
77 /// 2021-04-21: MapResponse.Debug.SleepSeconds
78 pub const V19: Self = Self(19);
79 /// 2021-06-11: MapResponse.LastSeen used even less
80 /// (<https://github.com/tailscale/tailscale/issues/2107>)
81 pub const V20: Self = Self(20);
82 /// 2021-06-15: added MapResponse.DNSConfig.CertDomains
83 pub const V21: Self = Self(21);
84 /// 2021-06-16: added MapResponse.DNSConfig.ExtraRecords
85 pub const V22: Self = Self(22);
86 /// 2021-08-25: DNSConfig.Routes values may be empty (for ExtraRecords support in 1.14.1+)
87 pub const V23: Self = Self(23);
88 /// 2021-09-18: MapResponse.Health from control to node; node shows in "tailscale status"
89 pub const V24: Self = Self(24);
90 /// 2021-11-01: MapResponse.Debug.Exit
91 pub const V25: Self = Self(25);
92 /// 2022-01-12: (nothing, just bumping for 1.20.0)
93 pub const V26: Self = Self(26);
94 /// 2022-02-18: start of SSHPolicy being respected
95 pub const V27: Self = Self(27);
96 /// 2022-03-09: client can communicate over Noise.
97 pub const V28: Self = Self(28);
98 /// 2022-03-21: MapResponse.PopBrowserURL
99 pub const V29: Self = Self(29);
100 /// 2022-03-22: client can request id tokens.
101 pub const V30: Self = Self(30);
102 /// 2022-04-15: PingRequest & PingResponse TSMP & disco support
103 pub const V31: Self = Self(31);
104 /// 2022-04-17: client knows FilterRule.CapMatch
105 pub const V32: Self = Self(32);
106 /// 2022-07-20: added MapResponse.PeersChangedPatch (DERPRegion + Endpoints)
107 pub const V33: Self = Self(33);
108 /// 2022-08-02: client understands CapabilityFileSharingTarget
109 pub const V34: Self = Self(34);
110 /// 2022-08-02: added PeersChangedPatch.{Key,DiscoKey,Online,LastSeen,KeyExpiry,Capabilities}
111 pub const V36: Self = Self(36);
112 /// 2022-08-09: added Debug.{SetForceBackgroundSTUN,SetRandomizeClientPort}; Debug are sticky
113 pub const V37: Self = Self(37);
114 /// 2022-08-11: added PingRequest.URLIsNoise
115 pub const V38: Self = Self(38);
116 /// 2022-08-15: clients can talk Noise over arbitrary HTTPS port
117 pub const V39: Self = Self(39);
118 /// 2022-08-22: added Node.KeySignature, PeersChangedPatch.KeySignature
119 pub const V40: Self = Self(40);
120 /// 2022-08-30: uses 100.100.100.100 for route-less ExtraRecords if global nameservers is set
121 pub const V41: Self = Self(41);
122 /// 2022-09-06: NextDNS DoH support; see <https://github.com/tailscale/tailscale/pull/5556>
123 pub const V42: Self = Self(42);
124 /// 2022-09-21: clients can return usernames for SSH
125 pub const V43: Self = Self(43);
126 /// 2022-09-22: MapResponse.ControlDialPlan
127 pub const V44: Self = Self(44);
128 /// 2022-09-26: c2n /debug/{goroutines,prefs,metrics}
129 pub const V45: Self = Self(45);
130 /// 2022-10-04: c2n /debug/component-logging
131 pub const V46: Self = Self(46);
132 /// 2022-10-11: Register{Request,Response}.NodeKeySignature
133 pub const V47: Self = Self(47);
134 /// 2022-11-02: Node.UnsignedPeerAPIOnly
135 pub const V48: Self = Self(48);
136 /// 2022-11-03: Client understands EarlyNoise
137 pub const V49: Self = Self(49);
138 /// 2022-11-14: Client understands CapabilityIngress
139 pub const V50: Self = Self(50);
140 /// 2022-11-30: Client understands CapabilityTailnetLockAlpha
141 pub const V51: Self = Self(51);
142 /// 2023-01-05: client can handle c2n POST /logtail/flush
143 pub const V52: Self = Self(52);
144 /// 2023-01-18: client respects explicit Node.Expired + auto-sets based on Node.KeyExpiry
145 pub const V53: Self = Self(53);
146 /// 2023-01-19: Node.Cap added, PeersChangedPatch.Cap, uses Node.Cap for ExitDNS before
147 /// Hostinfo.Services fallback
148 pub const V54: Self = Self(54);
149 /// 2023-01-23: start of c2n GET+POST /update handler
150 pub const V55: Self = Self(55);
151 /// 2023-01-24: Client understands CapabilityDebugTSDNSResolution
152 pub const V56: Self = Self(56);
153 /// 2023-01-25: Client understands CapabilityBindToInterfaceByRoute
154 pub const V57: Self = Self(57);
155 /// 2023-03-10: Client retries lite map updates before restarting map poll.
156 pub const V58: Self = Self(58);
157 /// 2023-03-16: Client understands Peers[].SelfNodeV4MasqAddrForThisPeer
158 pub const V59: Self = Self(59);
159 /// 2023-04-06: Client understands IsWireGuardOnly
160 pub const V60: Self = Self(60);
161 /// 2023-04-18: Client understand SSHAction.SSHRecorderFailureAction
162 pub const V61: Self = Self(61);
163 /// 2023-05-05: Client can notify control over noise for SSHEventNotificationRequest recording
164 /// failure events
165 pub const V62: Self = Self(62);
166 /// 2023-06-08: Client understands SSHAction.AllowRemotePortForwarding.
167 pub const V63: Self = Self(63);
168 /// 2023-07-11: Client understands s/CapabilityTailnetLockAlpha/CapabilityTailnetLock
169 pub const V64: Self = Self(64);
170 /// 2023-07-12: Client understands DERPMap.HomeParams + incremental DERPMap updates with params
171 pub const V65: Self = Self(65);
172 /// 2023-07-23: UserProfile.Groups added (available via WhoIs) (removed in 87)
173 pub const V66: Self = Self(66);
174 /// 2023-07-25: Client understands PeerCapMap
175 pub const V67: Self = Self(67);
176 /// 2023-08-09: Client has dedicated updateRoutine; MapRequest.Stream true means ignore
177 /// Hostinfo+Endpoints
178 pub const V68: Self = Self(68);
179 /// 2023-08-16: removed Debug.LogHeap* + GoroutineDumpURL; added c2n /debug/logheap
180 pub const V69: Self = Self(69);
181 /// 2023-08-16: removed most Debug fields; added NodeAttrDisable*, NodeAttrDebug* instead
182 pub const V70: Self = Self(70);
183 /// 2023-08-17: added NodeAttrOneCGNATEnable, NodeAttrOneCGNATDisable
184 pub const V71: Self = Self(71);
185 /// 2023-08-23: TS-2023-006 UPnP issue fixed; UPnP can now be used again
186 pub const V72: Self = Self(72);
187 /// 2023-09-01: Non-Windows clients expect to receive ClientVersion
188 pub const V73: Self = Self(73);
189 /// 2023-09-18: Client understands NodeCapMap
190 pub const V74: Self = Self(74);
191 /// 2023-09-12: Client understands NodeAttrDNSForwarderDisableTCPRetries
192 pub const V75: Self = Self(75);
193 /// 2023-09-20: Client understands ExitNodeDNSResolvers for IsWireGuardOnly nodes
194 pub const V76: Self = Self(76);
195 /// 2023-10-03: Client understands Peers[].SelfNodeV6MasqAddrForThisPeer
196 pub const V77: Self = Self(77);
197 /// 2023-10-05: can handle c2n Wake-on-LAN sending
198 pub const V78: Self = Self(78);
199 /// 2023-10-05: Client understands UrgentSecurityUpdate in ClientVersion
200 pub const V79: Self = Self(79);
201 /// 2023-11-16: can handle c2n GET /tls-cert-status
202 pub const V80: Self = Self(80);
203 /// 2023-11-17: MapResponse.PacketFilters (incremental packet filter updates)
204 pub const V81: Self = Self(81);
205 /// 2023-12-01: Client understands NodeAttrLinuxMustUseIPTables, NodeAttrLinuxMustUseNfTables,
206 /// c2n /netfilter-kind
207 pub const V82: Self = Self(82);
208 /// 2023-12-18: Client understands DefaultAutoUpdate
209 pub const V83: Self = Self(83);
210 /// 2024-01-04: Client understands SeamlessKeyRenewal
211 pub const V84: Self = Self(84);
212 /// 2024-01-05: Client understands MaxKeyDuration
213 pub const V85: Self = Self(85);
214 /// 2024-01-23: Client understands NodeAttrProbeUDPLifetime
215 pub const V86: Self = Self(86);
216 /// 2024-02-11: UserProfile.Groups removed (added in 66)
217 pub const V87: Self = Self(87);
218 /// 2024-03-05: Client understands NodeAttrSuggestExitNode
219 pub const V88: Self = Self(88);
220 /// 2024-03-23: Client no longer respects deleted PeerChange.Capabilities (use CapMap)
221 pub const V89: Self = Self(89);
222 /// 2024-04-03: Client understands PeerCapabilityTaildrive.
223 pub const V90: Self = Self(90);
224 /// 2024-04-24: Client understands PeerCapabilityTaildriveSharer.
225 pub const V91: Self = Self(91);
226 /// 2024-05-06: Client understands NodeAttrUserDialUseRoutes.
227 pub const V92: Self = Self(92);
228 /// 2024-05-06: added support for stateful firewalling.
229 pub const V93: Self = Self(93);
230 /// 2024-05-06: Client understands Node.IsJailed.
231 pub const V94: Self = Self(94);
232 /// 2024-05-06: Client uses NodeAttrUserDialUseRoutes to change DNS dialing behavior.
233 pub const V95: Self = Self(95);
234 /// 2024-05-29: Client understands NodeAttrSSHBehaviorV1
235 pub const V96: Self = Self(96);
236 /// 2024-06-06: Client understands NodeAttrDisableSplitDNSWhenNoCustomResolvers
237 pub const V97: Self = Self(97);
238 /// 2024-06-13: iOS/tvOS clients may provide serial number as part of posture information
239 pub const V98: Self = Self(98);
240 /// 2024-06-14: Client understands NodeAttrDisableLocalDNSOverrideViaNRPT
241 pub const V99: Self = Self(99);
242 /// 2024-06-18: Initial support for filtertype.Match.SrcCaps - actually usable in capver 109
243 /// (issue #12542)
244 pub const V100: Self = Self(100);
245 /// 2024-07-01: Client supports SSH agent forwarding when handling connections with /bin/su
246 pub const V101: Self = Self(101);
247 /// 2024-07-12: NodeAttrDisableMagicSockCryptoRouting support
248 pub const V102: Self = Self(102);
249 /// 2024-07-24: Client supports NodeAttrDisableCaptivePortalDetection
250 pub const V103: Self = Self(103);
251 /// 2024-08-03: SelfNodeV6MasqAddrForThisPeer now works
252 pub const V104: Self = Self(104);
253 /// 2024-08-05: Fixed SSH behavior on systems that use busybox (issue #12849)
254 pub const V105: Self = Self(105);
255 /// 2024-09-03: fix panic regression from cryptokey routing change (65fe0ba7b5)
256 pub const V106: Self = Self(106);
257 /// 2024-10-30: add App Connector to conffile (PR #13942)
258 pub const V107: Self = Self(107);
259 /// 2024-11-08: Client sends ServicesHash in Hostinfo, understands c2n GET /vip-services.
260 pub const V108: Self = Self(108);
261 /// 2024-11-18: Client supports filtertype.Match.SrcCaps (issue #12542)
262 pub const V109: Self = Self(109);
263 /// 2024-12-12: removed never-before-used Tailscale SSH public key support (#14373)
264 pub const V110: Self = Self(110);
265 /// 2025-01-14: Client supports a peer having Node.HomeDERP (issue #14636)
266 pub const V111: Self = Self(111);
267 /// 2025-01-14: Client interprets AllowedIPs of nil as meaning same as Addresses
268 pub const V112: Self = Self(112);
269 /// 2025-01-20: Client communicates to control whether funnel is enabled by sending
270 /// Hostinfo.IngressEnabled (#14688)
271 pub const V113: Self = Self(113);
272 /// 2025-01-30: NodeAttrMaxKeyDuration CapMap defined, clients might use it (no tailscaled code
273 /// change) (#14829)
274 pub const V114: Self = Self(114);
275 /// 2025-03-07: Client understands DERPRegion.NoMeasureNoHome.
276 pub const V115: Self = Self(115);
277 /// 2025-05-05: Client serves MagicDNS "AAAA" if NodeAttrMagicDNSPeerAAAA set on self node
278 pub const V116: Self = Self(116);
279 /// 2025-05-28: Client understands DisplayMessages (structured health messages), but not
280 /// necessarily PrimaryAction.
281 pub const V117: Self = Self(117);
282 /// 2025-07-01: Client sends Hostinfo.StateEncrypted to report whether the state file is
283 /// encrypted at rest (#15830)
284 pub const V118: Self = Self(118);
285 /// 2025-07-10: Client uses Hostinfo.Location.Priority to prioritize one route over another.
286 pub const V119: Self = Self(119);
287 /// 2025-07-15: Client understands peer relay disco messages, and implements peer client and
288 /// relay server functions
289 pub const V120: Self = Self(120);
290 /// 2025-07-19: Client understands peer relay endpoint alloc with
291 /// `disco.AllocateUDPRelayEndpointRequest` & `disco.AllocateUDPRelayEndpointResponse`
292 pub const V121: Self = Self(121);
293 /// 2025-07-21: Client sends Hostinfo.ExitNodeID to report which exit node it has selected, if any.
294 pub const V122: Self = Self(122);
295 /// 2025-07-28: fix deadlock regression from cryptokey routing change (issue #16651)
296 pub const V123: Self = Self(123);
297 /// 2025-08-08: removed NodeAttrDisableMagicSockCryptoRouting support, crypto routing is now mandatory
298 pub const V124: Self = Self(124);
299 /// 2025-08-11: dnstype.Resolver adds UseWithExitNode field.
300 pub const V125: Self = Self(125);
301 /// 2025-09-17: Client uses seamless key renewal unless disabled by control
302 /// (tailscale/corp#31479)
303 pub const V126: Self = Self(126);
304 /// 2025-09-19: can handle C2N /debug/netmap.
305 pub const V127: Self = Self(127);
306 /// 2025-10-02: can handle C2N /debug/health.
307 pub const V128: Self = Self(128);
308 /// 2025-10-04: Fixed sleep/wake deadlock in magicsock when using peer relay (PR #17449)
309 pub const V129: Self = Self(129);
310 /// 2025-10-06: client can send key.HardwareAttestationPublic and
311 /// key.HardwareAttestationKeySignature in MapRequest
312 pub const V130: Self = Self(130);
313 /// 2025-11-25: client respects NodeAttrDefaultAutoUpdate
314 pub const V131: Self = Self(131);
315 /// 2026-02-13: client respects NodeAttrDisableHostsFileUpdates
316 pub const V132: Self = Self(132);
317 /// 2026-02-17: client understands NodeAttrForceRegisterMagicDNSIPv4Only; MagicDNS IPv6
318 /// registered w/ OS by default
319 pub const V133: Self = Self(133);
320 /// 2026-03-09: Client understands NodeAttrDisableAndroidBindToActiveNetwork
321 pub const V134: Self = Self(134);
322 /// 2026-03-30: Client understands NodeAttrCacheNetworkMaps
323 pub const V135: Self = Self(135);
324 /// 2026-04-09: Client understands NodeAttrDisableLinuxCGNATDropRule
325 pub const V136: Self = Self(136);
326 /// 2026-04-15: Client handles 429 responses to /machine/register.
327 pub const V137: Self = Self(137);
328 /// 2026-03-31: can handle C2N /debug/tka.
329 pub const V138: Self = Self(138);
330 /// 2026-05-22: Client understands NodeAttrEmitRuntimeMetrics
331 pub const V139: Self = Self(139);
332 /// 2026-05-27: Client understands NodeAttrDisableUDPGRO, NodeAttrDisableUDPGSO,
333 /// NodeAttrDisableTUNUDPGRO, NodeAttrDisableTUNTCPGRO
334 pub const V140: Self = Self(140);
335 /// 2026-05-28: Client understands NodeAttrNeverGSOEqualTail
336 pub const V141: Self = Self(141);
337 /// 2026-07-06: Client understands c2n /remoteapi/localapi/* proxy
338 pub const V142: Self = Self(142);
339 /// 2026-07-22: Client correctly ignores conn25 node attributes when not enabled by environment
340 /// variable
341 pub const V143: Self = Self(143);
342 /// 2026-07-31: Client sends packet.TSMPDiscoKeyAdvertisement around WireGuard handshakes
343 pub const V144: Self = Self(144);
344 /// 2026-08-04: Client understands NodeAttrScopeQuad100OnMacOS
345 pub const V145: Self = Self(145);
346 /// 2026-09-02: Client understands NodeAttrConnReject; can handle C2N /debug/rejects.
347 pub const V146: Self = Self(146);
348 /// 2026-09-09: Client handles 429/503 responses with retry-after headers to /machine/ endpoints
349 pub const V147: Self = Self(147);
350 /// 2026-09-15: Client understands Node.StableTailnetID
351 pub const V148: Self = Self(148);
352 /// 2026-10-07: Sentinel version to request the server send back NodeAttrCacheNetworkMaps set to
353 /// enabled
354 pub const V149: Self = Self(149);
355 /// 2026-10-13: Client handles app connectors with "mode": "magicip" as conn25.
356 pub const V150: Self = Self(150);
357 /// 2026-11-13: Client understands nodecap.LogUploadAuth for authenticated log uploads
358 pub const V151: Self = Self(151);
359 /// 2026-11-17: Client supports hybrid post-quantum handshakes
360 pub const V152: Self = Self(152);
361
362 /// Go's zero value: **no capability version reported**.
363 ///
364 /// A peer's `tailcfg.Node.Cap` is `omitzero` on the wire, so a node control sends without a
365 /// `Cap` — a WireGuard-only peer (e.g. a Mullvad exit node), or any node from an old control
366 /// server — reads as `0` in Go, and every capability gate (`capVerIsRelayCapable`,
367 /// `peerCanProxyDNS`, the hybrid-handshake predicate) is false for it. This is that value, so a
368 /// decoded peer gets exactly Go's answer from those gates.
369 ///
370 /// It is **not** a version a node can declare, which is why [`Self::new`] still rejects `0`:
371 /// it is only ever the "absent" reading of a peer's field. It sorts below every defined
372 /// version.
373 pub const ZERO: Self = Self(0);
374
375 /// The capability version this node declares to control.
376 ///
377 /// **This is a claim control and peers act on, so it is pinned to what this tree actually
378 /// implements — not to the newest constant defined above.** The constants above are a
379 /// transcription of upstream's list (they document what each version *means*); this one is a
380 /// promise. Declaring a version whose behaviour is missing does not gain a feature, it just
381 /// tells control to stop sending the compatibility path for it.
382 ///
383 /// The value is bracketed from **both** sides, and both bounds are load-bearing. See
384 /// [`Self::is_relay_capable`] for the lower one.
385 ///
386 /// # Upper bound: below 126
387 ///
388 /// The declaration is held at **125** because the next version names a behaviour this tree
389 /// does not have:
390 ///
391 /// - **126** — seamless key renewal. Go renews the node key ahead of expiry without breaking
392 /// connections (`controlknobs.Knobs.SeamlessKeyRenewal`). This tree's expiry recovery is a
393 /// node-key rotation plus a full re-register with the stored auth key
394 /// (`ts_control::Config::reauth_on_expiry`, Go `doLogin`) — that is upstream's *non*-seamless
395 /// path, so connections do break across a renewal.
396 ///
397 /// The c2n debug versions above it no longer hold the declaration down. **127** (c2n
398 /// `/debug/netmap`), **128** (`/debug/health`), **138** (`/debug/tka/log`) and **146** (`GET
399 /// /debug/rejects`) answer `400 unknown c2n path`, byte for byte as Go's `handleC2N` writes it
400 /// for an unregistered path (`ipn/ipnlocal/c2n.go:154`). Go's own `tsnet`, the Go component
401 /// this tree maps to, gives that answer for 138 and 146: their handlers are registered by
402 /// `feature/tailnetlock` and `feature/connreject`, which only `tailscaled` links (through
403 /// `feature/condregister`), and `tsnet/depaware.txt` lists neither. A `ts_omit_debug` build
404 /// gives it for 127 and 128, which are registered only under `buildfeatures.HasDebug`
405 /// (`c2n.go:50-65`). Both still declare 152, because the capability version is set by the
406 /// source tree, not by the build, so control already accepts this answer from a node that
407 /// declares these versions. This tree has no `netmap.NetworkMap` in Go's internal shape and no
408 /// health tracker, and a body of zero values would read as facts.
409 ///
410 /// 125 is also a version a real client shipped (Tailscale `v1.88.0` declares it), which keeps
411 /// this coherent with the `IPNVersion` advertised in `ts_control::hostinfo`.
412 ///
413 /// # Lower bound: at or above 121 — and the one exception it leaves standing
414 ///
415 /// A capability version is a single integer, so declaring 125 also asserts **120** ("Client
416 /// understands peer relay disco messages, and implements peer client and relay server
417 /// functions") and **121** ("Client understands peer relay endpoint alloc with
418 /// `disco.AllocateUDPRelayEndpointRequest` & `disco.AllocateUDPRelayEndpointResponse`").
419 /// Neither is *fully* implemented here: this tree ports the peer-relay **client** half only —
420 /// it answers an inbound `CallMeMaybeVia` and brings the relayed path up (`ts_magicsock`'s
421 /// relay module) — but it never serves as a relay (Go `net/udprelay.Server`,
422 /// `feature/relayserver`) and never originates an allocation request of its own.
423 ///
424 /// That is a real overclaim, and it is deliberately **not** resolved the way 126 is (by holding
425 /// the declaration below it), because here the two directions are not symmetric:
426 ///
427 /// - **Lowering would be unconditionally destructive.** An upstream peer decides whether we may
428 /// be offered a relay path from our declared version alone, with
429 /// `magicsock.capVerIsRelayCapable(n.Cap())` — ported here as [`Self::is_relay_capable`]. It
430 /// gates both `endpoint.wantUDPRelayPathDiscoveryLocked` (no discovery is started toward a
431 /// peer below the floor) and the inbound `CallMeMaybeVia` handler (the message is ignored
432 /// outright). Declaring 119 would mean no Go peer ever sends us a `CallMeMaybeVia`, making
433 /// the ported client half unreachable in production. 122–125 would go with it, including
434 /// 125's `dnstype.Resolver.UseWithExitNode`, which `ts_runtime::magic_dns` *does* implement.
435 /// - **The overclaim is inert unless an operator opts in.** The half we do not implement —
436 /// serving as a relay — is additionally gated on tailnet policy: a peer treats us as a
437 /// relay-server candidate only if it *also* holds `peercap.RelayTarget`
438 /// (`tailscale.com/cap/relay-target`) on us (`Conn.updateRelayServersSet`), a grant an
439 /// operator writes into the policy file. Absent it no peer ever asks us to allocate, and an
440 /// `AllocateUDPRelayEndpointRequest` that does arrive is decoded and dropped. Contrast 126,
441 /// which control acts on unilaterally the moment the version is declared — which is why
442 /// *that* is resolved by holding the declaration below it and this one is not.
443 ///
444 /// Closing it for real means porting the relay server, which was ruled out of scope for an
445 /// embedded client when the peer-relay client half landed. Until then it is a recorded,
446 /// bounded exception rather than an oversight.
447 ///
448 /// **Before raising this**, check that every version between the old value and the new one is
449 /// implemented here, not just the topmost one — capability versions are monotone, so declaring
450 /// `N` asserts everything at or below `N`. **Before lowering it**, check it against
451 /// [`Self::is_relay_capable`] first.
452 pub const CURRENT: Self = Self::V125;
453
454 /// The capability version at and above which an upstream Go peer will treat a node as
455 /// **peer-relay capable**: `121`.
456 ///
457 /// Faithful port of Go `magicsock.capVerIsRelayCapable` (`wgengine/magicsock/magicsock.go`,
458 /// pinned at `49e148c4a30b4f8098f69468fd27a7021d85ea02`), which is exactly
459 /// `version >= 121`. Go evaluates it over a peer's netmap `tailcfg.Node.Cap` and stores the
460 /// result as `endpoint.relayCapable`, which gates two things:
461 ///
462 /// - `endpoint.wantUDPRelayPathDiscoveryLocked` — a peer below the floor never has UDP relay
463 /// path discovery started toward it, so it is never sent a `CallMeMaybeVia`.
464 /// - the inbound `CallMeMaybeVia` path in `Conn.handleDiscoMessage` — a `CallMeMaybeVia`
465 /// *from* a peer below the floor is ignored ("is not known to be relay capable").
466 ///
467 /// So this is the floor [`Self::CURRENT`] must stay at or above for this tree's ported
468 /// peer-relay client half to be reachable at all by a real Tailscale peer; see that constant
469 /// for why the tree sits above the floor despite not implementing all of 120/121.
470 ///
471 /// The second of the two gates is applied here too: `ts_magicsock`'s inbound `CallMeMaybeVia`
472 /// handler runs this over the sending peer's netmap `Node.Cap` (supplied by the runtime, which
473 /// owns the netmap) and drops the message when it does not clear the floor. The first gate has
474 /// no counterpart yet — this tree never originates UDP relay path discovery.
475 #[must_use]
476 pub const fn is_relay_capable(self) -> bool {
477 self.0 >= Self::V121.0
478 }
479
480 /// Create a new [`CapabilityVersion`] instance from a `u16`. Note that the versions 0, 1, 2,
481 /// and 35 are undefined and will result in an error.
482 pub const fn new(value: u16) -> Option<Self> {
483 match value {
484 v if v < 3 || v == 35 => None,
485 _ => Some(Self(value)),
486 }
487 }
488}
489
490impl fmt::Display for CapabilityVersion {
491 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
492 write!(f, "{}", self.0)
493 }
494}
495
496/// Convert [`CapabilityVersion`] into a native-endian [`u16`]; little-endian on `x86_64`.
497impl From<CapabilityVersion> for u16 {
498 fn from(value: CapabilityVersion) -> Self {
499 value.0
500 }
501}
502
503impl TryFrom<u16> for CapabilityVersion {
504 type Error = ();
505
506 fn try_from(value: u16) -> Result<Self, Self::Error> {
507 Self::new(value).ok_or(())
508 }
509}
510
511#[cfg(test)]
512mod tests {
513 use super::CapabilityVersion;
514
515 /// Upper bound. 126 (seamless key renewal) is unimplemented, so 125 is the ceiling; see
516 /// [`CapabilityVersion::CURRENT`] for the evidence, and for why 127, 128, 138 and 146 (the c2n
517 /// debug versions) no longer are. This test exists so raising the
518 /// constant without doing the port fails here rather than silently on the wire.
519 #[test]
520 fn current_is_not_declared_above_what_is_implemented() {
521 assert_eq!(CapabilityVersion::CURRENT, CapabilityVersion::V125);
522 assert!(CapabilityVersion::CURRENT < CapabilityVersion::V126);
523 }
524
525 /// Lower bound, and the reason 125 is not lowered to 119 even though 120 and 121 are only
526 /// half-implemented (peer-relay client, no relay server, no allocation request of our own).
527 ///
528 /// Go decides whether a node may be offered a peer-relay path from its declared capability
529 /// version alone — `magicsock.capVerIsRelayCapable(n.Cap())`, `>= 121`, ported as
530 /// [`CapabilityVersion::is_relay_capable`]. Below that floor no Go peer starts UDP relay path
531 /// discovery toward us and any `CallMeMaybeVia` we did receive would have been dropped by the
532 /// sender's own gate, so the ported client half in `ts_magicsock` would be dead code against
533 /// every real peer. Dropping under the floor is therefore a functional regression, not a
534 /// tightening of an honest claim, and this test is what makes that visible to whoever tries it.
535 #[test]
536 fn current_stays_at_or_above_the_relay_capable_floor() {
537 assert!(
538 CapabilityVersion::CURRENT.is_relay_capable(),
539 "declaring below {} makes upstream peers stop offering peer-relay paths, which would \
540 leave this tree's ported peer-relay client half unreachable in production",
541 CapabilityVersion::V121,
542 );
543 }
544
545 /// A peer that reported no `Cap` reads as Go's zero value, and the default is that value, not
546 /// this node's own declaration. Go evaluates `capVerIsRelayCapable(0)` and
547 /// `peerCanProxyDNS` (`Cap >= 26`) as false for such a peer; with the default at `CURRENT`
548 /// (125) both said yes, and from 152 the hybrid predicate would have too.
549 #[test]
550 fn default_is_go_zero_value_not_current() {
551 assert_eq!(CapabilityVersion::default(), CapabilityVersion::ZERO);
552 assert_ne!(CapabilityVersion::default(), CapabilityVersion::CURRENT);
553 assert_eq!(u16::from(CapabilityVersion::ZERO), 0);
554 assert!(!CapabilityVersion::ZERO.is_relay_capable());
555 assert!(CapabilityVersion::ZERO < CapabilityVersion::V3);
556 assert!(CapabilityVersion::ZERO < CapabilityVersion::V26);
557 assert!(CapabilityVersion::ZERO < CapabilityVersion::V152);
558 // Still not a version a node can construct or declare.
559 assert_eq!(CapabilityVersion::new(0), None);
560 }
561
562 /// The 134-152 constants are a transcription of upstream's `tailcfg.go` list at v1.106.0
563 /// (where `CurrentCapabilityVersion = 152`). Each constant must carry its own number. Declaring
564 /// any of them is a separate decision, guarded by
565 /// `current_is_not_declared_above_what_is_implemented`.
566 #[test]
567 fn transcribed_constants_carry_their_numbers() {
568 let transcribed = [
569 (CapabilityVersion::V134, 134u16),
570 (CapabilityVersion::V135, 135),
571 (CapabilityVersion::V136, 136),
572 (CapabilityVersion::V137, 137),
573 (CapabilityVersion::V138, 138),
574 (CapabilityVersion::V139, 139),
575 (CapabilityVersion::V140, 140),
576 (CapabilityVersion::V141, 141),
577 (CapabilityVersion::V142, 142),
578 (CapabilityVersion::V143, 143),
579 (CapabilityVersion::V144, 144),
580 (CapabilityVersion::V145, 145),
581 (CapabilityVersion::V146, 146),
582 (CapabilityVersion::V147, 147),
583 (CapabilityVersion::V148, 148),
584 (CapabilityVersion::V149, 149),
585 (CapabilityVersion::V150, 150),
586 (CapabilityVersion::V151, 151),
587 (CapabilityVersion::V152, 152),
588 ];
589 for (constant, number) in transcribed {
590 assert_eq!(u16::from(constant), number);
591 assert_eq!(CapabilityVersion::new(number), Some(constant));
592 }
593 }
594
595 /// The floor itself is upstream's, not a local guess: Go `capVerIsRelayCapable` is
596 /// `version >= 121`, so 120 is out and 121 is in, exactly.
597 #[test]
598 fn relay_capable_floor_matches_upstream() {
599 for below in [3u16, 119, 120] {
600 let v = CapabilityVersion::new(below).expect("valid capability version");
601 assert!(!v.is_relay_capable(), "{v} is below Go's 121 relay floor");
602 }
603 for at_or_above in [121u16, 122, 125, 145, u16::MAX] {
604 let v = CapabilityVersion::new(at_or_above).expect("valid capability version");
605 assert!(
606 v.is_relay_capable(),
607 "{v} is at or above Go's 121 relay floor"
608 );
609 }
610 }
611}