tailcfg_view.go 92 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696
  1. // Copyright (c) Tailscale Inc & contributors
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. // Code generated by tailscale/cmd/viewer; DO NOT EDIT.
  4. package tailcfg
  5. import (
  6. jsonv1 "encoding/json"
  7. "errors"
  8. "net/netip"
  9. "time"
  10. jsonv2 "github.com/go-json-experiment/json"
  11. "github.com/go-json-experiment/json/jsontext"
  12. "tailscale.com/types/dnstype"
  13. "tailscale.com/types/key"
  14. "tailscale.com/types/opt"
  15. "tailscale.com/types/structs"
  16. "tailscale.com/types/tkatype"
  17. "tailscale.com/types/views"
  18. )
  19. //go:generate go run tailscale.com/cmd/cloner -clonefunc=true -type=User,Node,Hostinfo,NetInfo,Login,DNSConfig,RegisterResponse,RegisterResponseAuth,RegisterRequest,DERPHomeParams,DERPRegion,DERPMap,DERPNode,SSHRule,SSHAction,SSHPrincipal,ControlDialPlan,Location,UserProfile,VIPService,SSHPolicy
  20. // View returns a read-only view of User.
  21. func (p *User) View() UserView {
  22. return UserView{ж: p}
  23. }
  24. // UserView provides a read-only view over User.
  25. //
  26. // Its methods should only be called if `Valid()` returns true.
  27. type UserView struct {
  28. // ж is the underlying mutable value, named with a hard-to-type
  29. // character that looks pointy like a pointer.
  30. // It is named distinctively to make you think of how dangerous it is to escape
  31. // to callers. You must not let callers be able to mutate it.
  32. ж *User
  33. }
  34. // Valid reports whether v's underlying value is non-nil.
  35. func (v UserView) Valid() bool { return v.ж != nil }
  36. // AsStruct returns a clone of the underlying value which aliases no memory with
  37. // the original.
  38. func (v UserView) AsStruct() *User {
  39. if v.ж == nil {
  40. return nil
  41. }
  42. return v.ж.Clone()
  43. }
  44. // MarshalJSON implements [jsonv1.Marshaler].
  45. func (v UserView) MarshalJSON() ([]byte, error) {
  46. return jsonv1.Marshal(v.ж)
  47. }
  48. // MarshalJSONTo implements [jsonv2.MarshalerTo].
  49. func (v UserView) MarshalJSONTo(enc *jsontext.Encoder) error {
  50. return jsonv2.MarshalEncode(enc, v.ж)
  51. }
  52. // UnmarshalJSON implements [jsonv1.Unmarshaler].
  53. func (v *UserView) UnmarshalJSON(b []byte) error {
  54. if v.ж != nil {
  55. return errors.New("already initialized")
  56. }
  57. if len(b) == 0 {
  58. return nil
  59. }
  60. var x User
  61. if err := jsonv1.Unmarshal(b, &x); err != nil {
  62. return err
  63. }
  64. v.ж = &x
  65. return nil
  66. }
  67. // UnmarshalJSONFrom implements [jsonv2.UnmarshalerFrom].
  68. func (v *UserView) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
  69. if v.ж != nil {
  70. return errors.New("already initialized")
  71. }
  72. var x User
  73. if err := jsonv2.UnmarshalDecode(dec, &x); err != nil {
  74. return err
  75. }
  76. v.ж = &x
  77. return nil
  78. }
  79. func (v UserView) ID() UserID { return v.ж.ID }
  80. // if non-empty overrides Login field
  81. func (v UserView) DisplayName() string { return v.ж.DisplayName }
  82. // if non-empty overrides Login field
  83. func (v UserView) ProfilePicURL() string { return v.ж.ProfilePicURL }
  84. func (v UserView) Created() time.Time { return v.ж.Created }
  85. // A compilation failure here means this code must be regenerated, with the command at the top of this file.
  86. var _UserViewNeedsRegeneration = User(struct {
  87. ID UserID
  88. DisplayName string
  89. ProfilePicURL string
  90. Created time.Time
  91. }{})
  92. // View returns a read-only view of Node.
  93. func (p *Node) View() NodeView {
  94. return NodeView{ж: p}
  95. }
  96. // NodeView provides a read-only view over Node.
  97. //
  98. // Its methods should only be called if `Valid()` returns true.
  99. type NodeView struct {
  100. // ж is the underlying mutable value, named with a hard-to-type
  101. // character that looks pointy like a pointer.
  102. // It is named distinctively to make you think of how dangerous it is to escape
  103. // to callers. You must not let callers be able to mutate it.
  104. ж *Node
  105. }
  106. // Valid reports whether v's underlying value is non-nil.
  107. func (v NodeView) Valid() bool { return v.ж != nil }
  108. // AsStruct returns a clone of the underlying value which aliases no memory with
  109. // the original.
  110. func (v NodeView) AsStruct() *Node {
  111. if v.ж == nil {
  112. return nil
  113. }
  114. return v.ж.Clone()
  115. }
  116. // MarshalJSON implements [jsonv1.Marshaler].
  117. func (v NodeView) MarshalJSON() ([]byte, error) {
  118. return jsonv1.Marshal(v.ж)
  119. }
  120. // MarshalJSONTo implements [jsonv2.MarshalerTo].
  121. func (v NodeView) MarshalJSONTo(enc *jsontext.Encoder) error {
  122. return jsonv2.MarshalEncode(enc, v.ж)
  123. }
  124. // UnmarshalJSON implements [jsonv1.Unmarshaler].
  125. func (v *NodeView) UnmarshalJSON(b []byte) error {
  126. if v.ж != nil {
  127. return errors.New("already initialized")
  128. }
  129. if len(b) == 0 {
  130. return nil
  131. }
  132. var x Node
  133. if err := jsonv1.Unmarshal(b, &x); err != nil {
  134. return err
  135. }
  136. v.ж = &x
  137. return nil
  138. }
  139. // UnmarshalJSONFrom implements [jsonv2.UnmarshalerFrom].
  140. func (v *NodeView) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
  141. if v.ж != nil {
  142. return errors.New("already initialized")
  143. }
  144. var x Node
  145. if err := jsonv2.UnmarshalDecode(dec, &x); err != nil {
  146. return err
  147. }
  148. v.ж = &x
  149. return nil
  150. }
  151. func (v NodeView) ID() NodeID { return v.ж.ID }
  152. func (v NodeView) StableID() StableNodeID { return v.ж.StableID }
  153. // Name is the FQDN of the node.
  154. // It is also the MagicDNS name for the node.
  155. // It has a trailing dot.
  156. // e.g. "host.tail-scale.ts.net."
  157. func (v NodeView) Name() string { return v.ж.Name }
  158. // User is the user who created the node. If ACL tags are in use for the
  159. // node then it doesn't reflect the ACL identity that the node is running
  160. // as.
  161. func (v NodeView) User() UserID { return v.ж.User }
  162. // Sharer, if non-zero, is the user who shared this node, if different than User.
  163. func (v NodeView) Sharer() UserID { return v.ж.Sharer }
  164. func (v NodeView) Key() key.NodePublic { return v.ж.Key }
  165. // the zero value if this node does not expire
  166. func (v NodeView) KeyExpiry() time.Time { return v.ж.KeyExpiry }
  167. func (v NodeView) KeySignature() views.ByteSlice[tkatype.MarshaledSignature] {
  168. return views.ByteSliceOf(v.ж.KeySignature)
  169. }
  170. func (v NodeView) Machine() key.MachinePublic { return v.ж.Machine }
  171. func (v NodeView) DiscoKey() key.DiscoPublic { return v.ж.DiscoKey }
  172. // Addresses are the IP addresses of this Node directly.
  173. func (v NodeView) Addresses() views.Slice[netip.Prefix] { return views.SliceOf(v.ж.Addresses) }
  174. // AllowedIPs are the IP ranges to route to this node.
  175. //
  176. // As of CapabilityVersion 112, this may be nil (null or undefined) on the wire
  177. // to mean the same as Addresses. Internally, it is always filled in with
  178. // its possibly-implicit value.
  179. func (v NodeView) AllowedIPs() views.Slice[netip.Prefix] { return views.SliceOf(v.ж.AllowedIPs) }
  180. // IP+port (public via STUN, and local LANs)
  181. func (v NodeView) Endpoints() views.Slice[netip.AddrPort] { return views.SliceOf(v.ж.Endpoints) }
  182. // LegacyDERPString is this node's home LegacyDERPString region ID integer, but shoved into an
  183. // IP:port string for legacy reasons. The IP address is always "127.3.3.40"
  184. // (a loopback address (127) followed by the digits over the letters DERP on
  185. // a QWERTY keyboard (3.3.40)). The "port number" is the home LegacyDERPString region ID
  186. // integer.
  187. //
  188. // Deprecated: HomeDERP has replaced this, but old servers might still send
  189. // this field. See tailscale/tailscale#14636. Do not use this field in code
  190. // other than in the upgradeNode func, which canonicalizes it to HomeDERP
  191. // if it arrives as a LegacyDERPString string on the wire.
  192. func (v NodeView) LegacyDERPString() string { return v.ж.LegacyDERPString }
  193. // HomeDERP is the modern version of the DERP string field, with just an
  194. // integer. The client advertises support for this as of capver 111.
  195. //
  196. // HomeDERP may be zero if not (yet) known, but ideally always be non-zero
  197. // for magicsock connectivity to function normally.
  198. func (v NodeView) HomeDERP() int { return v.ж.HomeDERP }
  199. func (v NodeView) Hostinfo() HostinfoView { return v.ж.Hostinfo }
  200. func (v NodeView) Created() time.Time { return v.ж.Created }
  201. // if non-zero, the node's capability version; old servers might not send
  202. func (v NodeView) Cap() CapabilityVersion { return v.ж.Cap }
  203. // Tags are the list of ACL tags applied to this node.
  204. // Tags take the form of `tag:<value>` where value starts
  205. // with a letter and only contains alphanumerics and dashes `-`.
  206. // Some valid tag examples:
  207. //
  208. // `tag:prod`
  209. // `tag:database`
  210. // `tag:lab-1`
  211. func (v NodeView) Tags() views.Slice[string] { return views.SliceOf(v.ж.Tags) }
  212. // PrimaryRoutes are the routes from AllowedIPs that this node
  213. // is currently the primary subnet router for, as determined
  214. // by the control plane. It does not include the self address
  215. // values from Addresses that are in AllowedIPs.
  216. func (v NodeView) PrimaryRoutes() views.Slice[netip.Prefix] { return views.SliceOf(v.ж.PrimaryRoutes) }
  217. // LastSeen is when the node was last online. It is not
  218. // updated when Online is true. It is nil if the current
  219. // node doesn't have permission to know, or the node
  220. // has never been online.
  221. func (v NodeView) LastSeen() views.ValuePointer[time.Time] {
  222. return views.ValuePointerOf(v.ж.LastSeen)
  223. }
  224. // Online is whether the node is currently connected to the
  225. // coordination server. A value of nil means unknown, or the
  226. // current node doesn't have permission to know.
  227. func (v NodeView) Online() views.ValuePointer[bool] { return views.ValuePointerOf(v.ж.Online) }
  228. // TODO(crawshaw): replace with MachineStatus
  229. func (v NodeView) MachineAuthorized() bool { return v.ж.MachineAuthorized }
  230. // Capabilities are capabilities that the node has.
  231. // They're free-form strings, but should be in the form of URLs/URIs
  232. // such as:
  233. //
  234. // "https://tailscale.com/cap/is-admin"
  235. // "https://tailscale.com/cap/file-sharing"
  236. //
  237. // Deprecated: use CapMap instead. See https://github.com/tailscale/tailscale/issues/11508
  238. func (v NodeView) Capabilities() views.Slice[NodeCapability] { return views.SliceOf(v.ж.Capabilities) }
  239. // CapMap is a map of capabilities to their optional argument/data values.
  240. //
  241. // It is valid for a capability to not have any argument/data values; such
  242. // capabilities can be tested for using the HasCap method. These type of
  243. // capabilities are used to indicate that a node has a capability, but there
  244. // is no additional data associated with it. These were previously
  245. // represented by the Capabilities field, but can now be represented by
  246. // CapMap with an empty value.
  247. //
  248. // See NodeCapability for more information on keys.
  249. //
  250. // Metadata about nodes can be transmitted in 3 ways:
  251. // 1. MapResponse.Node.CapMap describes attributes that affect behavior for
  252. // this node, such as which features have been enabled through the admin
  253. // panel and any associated configuration details.
  254. // 2. MapResponse.PacketFilter(s) describes access (both IP and application
  255. // based) that should be granted to peers.
  256. // 3. MapResponse.Peers[].CapMap describes attributes regarding a peer node,
  257. // such as which features the peer supports or if that peer is preferred
  258. // for a particular task vs other peers that could also be chosen.
  259. func (v NodeView) CapMap() views.MapSlice[NodeCapability, RawMessage] {
  260. return views.MapSliceOf(v.ж.CapMap)
  261. }
  262. // UnsignedPeerAPIOnly means that this node is not signed nor subject to TKA
  263. // restrictions. However, in exchange for that privilege, it does not get
  264. // network access. It can only access this node's peerapi, which may not let
  265. // it do anything. It is the tailscaled client's job to double-check the
  266. // MapResponse's PacketFilter to verify that its AllowedIPs will not be
  267. // accepted by the packet filter.
  268. func (v NodeView) UnsignedPeerAPIOnly() bool { return v.ж.UnsignedPeerAPIOnly }
  269. // MagicDNS base name (for normal non-shared-in nodes), FQDN (without trailing dot, for shared-in nodes), or Hostname (if no MagicDNS)
  270. func (v NodeView) ComputedName() string { return v.ж.ComputedName }
  271. // either "ComputedName" or "ComputedName (computedHostIfDifferent)", if computedHostIfDifferent is set
  272. func (v NodeView) ComputedNameWithHost() string { return v.ж.ComputedNameWithHost }
  273. // DataPlaneAuditLogID is the per-node logtail ID used for data plane audit logging.
  274. func (v NodeView) DataPlaneAuditLogID() string { return v.ж.DataPlaneAuditLogID }
  275. // Expired is whether this node's key has expired. Control may send
  276. // this; clients are only allowed to set this from false to true. On
  277. // the client, this is calculated client-side based on a timestamp sent
  278. // from control, to avoid clock skew issues.
  279. func (v NodeView) Expired() bool { return v.ж.Expired }
  280. // SelfNodeV4MasqAddrForThisPeer is the IPv4 that this peer knows the current node as.
  281. // It may be empty if the peer knows the current node by its native
  282. // IPv4 address.
  283. // This field is only populated in a MapResponse for peers and not
  284. // for the current node.
  285. //
  286. // If set, it should be used to masquerade traffic originating from the
  287. // current node to this peer. The masquerade address is only relevant
  288. // for this peer and not for other peers.
  289. //
  290. // This only applies to traffic originating from the current node to the
  291. // peer or any of its subnets. Traffic originating from subnet routes will
  292. // not be masqueraded (e.g. in case of --snat-subnet-routes).
  293. func (v NodeView) SelfNodeV4MasqAddrForThisPeer() views.ValuePointer[netip.Addr] {
  294. return views.ValuePointerOf(v.ж.SelfNodeV4MasqAddrForThisPeer)
  295. }
  296. // SelfNodeV6MasqAddrForThisPeer is the IPv6 that this peer knows the current node as.
  297. // It may be empty if the peer knows the current node by its native
  298. // IPv6 address.
  299. // This field is only populated in a MapResponse for peers and not
  300. // for the current node.
  301. //
  302. // If set, it should be used to masquerade traffic originating from the
  303. // current node to this peer. The masquerade address is only relevant
  304. // for this peer and not for other peers.
  305. //
  306. // This only applies to traffic originating from the current node to the
  307. // peer or any of its subnets. Traffic originating from subnet routes will
  308. // not be masqueraded (e.g. in case of --snat-subnet-routes).
  309. func (v NodeView) SelfNodeV6MasqAddrForThisPeer() views.ValuePointer[netip.Addr] {
  310. return views.ValuePointerOf(v.ж.SelfNodeV6MasqAddrForThisPeer)
  311. }
  312. // IsWireGuardOnly indicates that this is a non-Tailscale WireGuard peer, it
  313. // is not expected to speak Disco or DERP, and it must have Endpoints in
  314. // order to be reachable.
  315. func (v NodeView) IsWireGuardOnly() bool { return v.ж.IsWireGuardOnly }
  316. // IsJailed indicates that this node is jailed and should not be allowed
  317. // initiate connections, however outbound connections to it should still be
  318. // allowed.
  319. func (v NodeView) IsJailed() bool { return v.ж.IsJailed }
  320. // ExitNodeDNSResolvers is the list of DNS servers that should be used when this
  321. // node is marked IsWireGuardOnly and being used as an exit node.
  322. func (v NodeView) ExitNodeDNSResolvers() views.SliceView[*dnstype.Resolver, dnstype.ResolverView] {
  323. return views.SliceOfViews[*dnstype.Resolver, dnstype.ResolverView](v.ж.ExitNodeDNSResolvers)
  324. }
  325. func (v NodeView) Equal(v2 NodeView) bool { return v.ж.Equal(v2.ж) }
  326. // A compilation failure here means this code must be regenerated, with the command at the top of this file.
  327. var _NodeViewNeedsRegeneration = Node(struct {
  328. ID NodeID
  329. StableID StableNodeID
  330. Name string
  331. User UserID
  332. Sharer UserID
  333. Key key.NodePublic
  334. KeyExpiry time.Time
  335. KeySignature tkatype.MarshaledSignature
  336. Machine key.MachinePublic
  337. DiscoKey key.DiscoPublic
  338. Addresses []netip.Prefix
  339. AllowedIPs []netip.Prefix
  340. Endpoints []netip.AddrPort
  341. LegacyDERPString string
  342. HomeDERP int
  343. Hostinfo HostinfoView
  344. Created time.Time
  345. Cap CapabilityVersion
  346. Tags []string
  347. PrimaryRoutes []netip.Prefix
  348. LastSeen *time.Time
  349. Online *bool
  350. MachineAuthorized bool
  351. Capabilities []NodeCapability
  352. CapMap NodeCapMap
  353. UnsignedPeerAPIOnly bool
  354. ComputedName string
  355. computedHostIfDifferent string
  356. ComputedNameWithHost string
  357. DataPlaneAuditLogID string
  358. Expired bool
  359. SelfNodeV4MasqAddrForThisPeer *netip.Addr
  360. SelfNodeV6MasqAddrForThisPeer *netip.Addr
  361. IsWireGuardOnly bool
  362. IsJailed bool
  363. ExitNodeDNSResolvers []*dnstype.Resolver
  364. }{})
  365. // View returns a read-only view of Hostinfo.
  366. func (p *Hostinfo) View() HostinfoView {
  367. return HostinfoView{ж: p}
  368. }
  369. // HostinfoView provides a read-only view over Hostinfo.
  370. //
  371. // Its methods should only be called if `Valid()` returns true.
  372. type HostinfoView struct {
  373. // ж is the underlying mutable value, named with a hard-to-type
  374. // character that looks pointy like a pointer.
  375. // It is named distinctively to make you think of how dangerous it is to escape
  376. // to callers. You must not let callers be able to mutate it.
  377. ж *Hostinfo
  378. }
  379. // Valid reports whether v's underlying value is non-nil.
  380. func (v HostinfoView) Valid() bool { return v.ж != nil }
  381. // AsStruct returns a clone of the underlying value which aliases no memory with
  382. // the original.
  383. func (v HostinfoView) AsStruct() *Hostinfo {
  384. if v.ж == nil {
  385. return nil
  386. }
  387. return v.ж.Clone()
  388. }
  389. // MarshalJSON implements [jsonv1.Marshaler].
  390. func (v HostinfoView) MarshalJSON() ([]byte, error) {
  391. return jsonv1.Marshal(v.ж)
  392. }
  393. // MarshalJSONTo implements [jsonv2.MarshalerTo].
  394. func (v HostinfoView) MarshalJSONTo(enc *jsontext.Encoder) error {
  395. return jsonv2.MarshalEncode(enc, v.ж)
  396. }
  397. // UnmarshalJSON implements [jsonv1.Unmarshaler].
  398. func (v *HostinfoView) UnmarshalJSON(b []byte) error {
  399. if v.ж != nil {
  400. return errors.New("already initialized")
  401. }
  402. if len(b) == 0 {
  403. return nil
  404. }
  405. var x Hostinfo
  406. if err := jsonv1.Unmarshal(b, &x); err != nil {
  407. return err
  408. }
  409. v.ж = &x
  410. return nil
  411. }
  412. // UnmarshalJSONFrom implements [jsonv2.UnmarshalerFrom].
  413. func (v *HostinfoView) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
  414. if v.ж != nil {
  415. return errors.New("already initialized")
  416. }
  417. var x Hostinfo
  418. if err := jsonv2.UnmarshalDecode(dec, &x); err != nil {
  419. return err
  420. }
  421. v.ж = &x
  422. return nil
  423. }
  424. // version of this code (in version.Long format)
  425. func (v HostinfoView) IPNVersion() string { return v.ж.IPNVersion }
  426. // logtail ID of frontend instance
  427. func (v HostinfoView) FrontendLogID() string { return v.ж.FrontendLogID }
  428. // logtail ID of backend instance
  429. func (v HostinfoView) BackendLogID() string { return v.ж.BackendLogID }
  430. // operating system the client runs on (a version.OS value)
  431. func (v HostinfoView) OS() string { return v.ж.OS }
  432. // OSVersion is the version of the OS, if available.
  433. //
  434. // For Android, it's like "10", "11", "12", etc. For iOS and macOS it's like
  435. // "15.6.1" or "12.4.0". For Windows it's like "10.0.19044.1889". For
  436. // FreeBSD it's like "12.3-STABLE".
  437. //
  438. // For Linux, prior to Tailscale 1.32, we jammed a bunch of fields into this
  439. // string on Linux, like "Debian 10.4; kernel=xxx; container; env=kn" and so
  440. // on. As of Tailscale 1.32, this is simply the kernel version on Linux, like
  441. // "5.10.0-17-amd64".
  442. func (v HostinfoView) OSVersion() string { return v.ж.OSVersion }
  443. // best-effort whether the client is running in a container
  444. func (v HostinfoView) Container() opt.Bool { return v.ж.Container }
  445. // a hostinfo.EnvType in string form
  446. func (v HostinfoView) Env() string { return v.ж.Env }
  447. // "debian", "ubuntu", "nixos", ...
  448. func (v HostinfoView) Distro() string { return v.ж.Distro }
  449. // "20.04", ...
  450. func (v HostinfoView) DistroVersion() string { return v.ж.DistroVersion }
  451. // "jammy", "bullseye", ...
  452. func (v HostinfoView) DistroCodeName() string { return v.ж.DistroCodeName }
  453. // App is used to disambiguate Tailscale clients that run using tsnet.
  454. func (v HostinfoView) App() string { return v.ж.App }
  455. // if a desktop was detected on Linux
  456. func (v HostinfoView) Desktop() opt.Bool { return v.ж.Desktop }
  457. // Tailscale package to disambiguate ("choco", "appstore", etc; "" for unknown)
  458. func (v HostinfoView) Package() string { return v.ж.Package }
  459. // mobile phone model ("Pixel 3a", "iPhone12,3")
  460. func (v HostinfoView) DeviceModel() string { return v.ж.DeviceModel }
  461. // macOS/iOS APNs device token for notifications (and Android in the future)
  462. func (v HostinfoView) PushDeviceToken() string { return v.ж.PushDeviceToken }
  463. // name of the host the client runs on
  464. func (v HostinfoView) Hostname() string { return v.ж.Hostname }
  465. // indicates whether the host is blocking incoming connections
  466. func (v HostinfoView) ShieldsUp() bool { return v.ж.ShieldsUp }
  467. // indicates this node exists in netmap because it's owned by a shared-to user
  468. func (v HostinfoView) ShareeNode() bool { return v.ж.ShareeNode }
  469. // indicates that the user has opted out of sending logs and support
  470. func (v HostinfoView) NoLogsNoSupport() bool { return v.ж.NoLogsNoSupport }
  471. // WireIngress indicates that the node would like to be wired up server-side
  472. // (DNS, etc) to be able to use Tailscale Funnel, even if it's not currently
  473. // enabled. For example, the user might only use it for intermittent
  474. // foreground CLI serve sessions, for which they'd like it to work right
  475. // away, even if it's disabled most of the time. As an optimization, this is
  476. // only sent if IngressEnabled is false, as IngressEnabled implies that this
  477. // option is true.
  478. func (v HostinfoView) WireIngress() bool { return v.ж.WireIngress }
  479. // if the node has any funnel endpoint enabled
  480. func (v HostinfoView) IngressEnabled() bool { return v.ж.IngressEnabled }
  481. // indicates that the node has opted-in to admin-console-drive remote updates
  482. func (v HostinfoView) AllowsUpdate() bool { return v.ж.AllowsUpdate }
  483. // the current host's machine type (uname -m)
  484. func (v HostinfoView) Machine() string { return v.ж.Machine }
  485. // GOARCH value (of the built binary)
  486. func (v HostinfoView) GoArch() string { return v.ж.GoArch }
  487. // GOARM, GOAMD64, etc (of the built binary)
  488. func (v HostinfoView) GoArchVar() string { return v.ж.GoArchVar }
  489. // Go version binary was built with
  490. func (v HostinfoView) GoVersion() string { return v.ж.GoVersion }
  491. // set of IP ranges this client can route
  492. func (v HostinfoView) RoutableIPs() views.Slice[netip.Prefix] { return views.SliceOf(v.ж.RoutableIPs) }
  493. // set of ACL tags this node wants to claim
  494. func (v HostinfoView) RequestTags() views.Slice[string] { return views.SliceOf(v.ж.RequestTags) }
  495. // MAC address(es) to send Wake-on-LAN packets to wake this node (lowercase hex w/ colons)
  496. func (v HostinfoView) WoLMACs() views.Slice[string] { return views.SliceOf(v.ж.WoLMACs) }
  497. // services advertised by this machine
  498. func (v HostinfoView) Services() views.Slice[Service] { return views.SliceOf(v.ж.Services) }
  499. func (v HostinfoView) NetInfo() NetInfoView { return v.ж.NetInfo.View() }
  500. // if advertised
  501. func (v HostinfoView) SSH_HostKeys() views.Slice[string] { return views.SliceOf(v.ж.SSH_HostKeys) }
  502. func (v HostinfoView) Cloud() string { return v.ж.Cloud }
  503. // if the client is running in userspace (netstack) mode
  504. func (v HostinfoView) Userspace() opt.Bool { return v.ж.Userspace }
  505. // if the client's subnet router is running in userspace (netstack) mode
  506. func (v HostinfoView) UserspaceRouter() opt.Bool { return v.ж.UserspaceRouter }
  507. // if the client is running the app-connector service
  508. func (v HostinfoView) AppConnector() opt.Bool { return v.ж.AppConnector }
  509. // opaque hash of the most recent list of tailnet services, change in hash indicates config should be fetched via c2n
  510. func (v HostinfoView) ServicesHash() string { return v.ж.ServicesHash }
  511. // if the client is willing to relay traffic for other peers
  512. func (v HostinfoView) PeerRelay() bool { return v.ж.PeerRelay }
  513. // the client’s selected exit node, empty when unselected.
  514. func (v HostinfoView) ExitNodeID() StableNodeID { return v.ж.ExitNodeID }
  515. // Location represents geographical location data about a
  516. // Tailscale host. Location is optional and only set if
  517. // explicitly declared by a node.
  518. func (v HostinfoView) Location() LocationView { return v.ж.Location.View() }
  519. // TPM device metadata, if available
  520. func (v HostinfoView) TPM() views.ValuePointer[TPMInfo] { return views.ValuePointerOf(v.ж.TPM) }
  521. // StateEncrypted reports whether the node state is stored encrypted on
  522. // disk. The actual mechanism is platform-specific:
  523. // - Apple nodes use the Keychain
  524. // - Linux and Windows nodes use the TPM
  525. // - Android apps use EncryptedSharedPreferences
  526. func (v HostinfoView) StateEncrypted() opt.Bool { return v.ж.StateEncrypted }
  527. func (v HostinfoView) Equal(v2 HostinfoView) bool { return v.ж.Equal(v2.ж) }
  528. // A compilation failure here means this code must be regenerated, with the command at the top of this file.
  529. var _HostinfoViewNeedsRegeneration = Hostinfo(struct {
  530. IPNVersion string
  531. FrontendLogID string
  532. BackendLogID string
  533. OS string
  534. OSVersion string
  535. Container opt.Bool
  536. Env string
  537. Distro string
  538. DistroVersion string
  539. DistroCodeName string
  540. App string
  541. Desktop opt.Bool
  542. Package string
  543. DeviceModel string
  544. PushDeviceToken string
  545. Hostname string
  546. ShieldsUp bool
  547. ShareeNode bool
  548. NoLogsNoSupport bool
  549. WireIngress bool
  550. IngressEnabled bool
  551. AllowsUpdate bool
  552. Machine string
  553. GoArch string
  554. GoArchVar string
  555. GoVersion string
  556. RoutableIPs []netip.Prefix
  557. RequestTags []string
  558. WoLMACs []string
  559. Services []Service
  560. NetInfo *NetInfo
  561. SSH_HostKeys []string
  562. Cloud string
  563. Userspace opt.Bool
  564. UserspaceRouter opt.Bool
  565. AppConnector opt.Bool
  566. ServicesHash string
  567. PeerRelay bool
  568. ExitNodeID StableNodeID
  569. Location *Location
  570. TPM *TPMInfo
  571. StateEncrypted opt.Bool
  572. }{})
  573. // View returns a read-only view of NetInfo.
  574. func (p *NetInfo) View() NetInfoView {
  575. return NetInfoView{ж: p}
  576. }
  577. // NetInfoView provides a read-only view over NetInfo.
  578. //
  579. // Its methods should only be called if `Valid()` returns true.
  580. type NetInfoView struct {
  581. // ж is the underlying mutable value, named with a hard-to-type
  582. // character that looks pointy like a pointer.
  583. // It is named distinctively to make you think of how dangerous it is to escape
  584. // to callers. You must not let callers be able to mutate it.
  585. ж *NetInfo
  586. }
  587. // Valid reports whether v's underlying value is non-nil.
  588. func (v NetInfoView) Valid() bool { return v.ж != nil }
  589. // AsStruct returns a clone of the underlying value which aliases no memory with
  590. // the original.
  591. func (v NetInfoView) AsStruct() *NetInfo {
  592. if v.ж == nil {
  593. return nil
  594. }
  595. return v.ж.Clone()
  596. }
  597. // MarshalJSON implements [jsonv1.Marshaler].
  598. func (v NetInfoView) MarshalJSON() ([]byte, error) {
  599. return jsonv1.Marshal(v.ж)
  600. }
  601. // MarshalJSONTo implements [jsonv2.MarshalerTo].
  602. func (v NetInfoView) MarshalJSONTo(enc *jsontext.Encoder) error {
  603. return jsonv2.MarshalEncode(enc, v.ж)
  604. }
  605. // UnmarshalJSON implements [jsonv1.Unmarshaler].
  606. func (v *NetInfoView) UnmarshalJSON(b []byte) error {
  607. if v.ж != nil {
  608. return errors.New("already initialized")
  609. }
  610. if len(b) == 0 {
  611. return nil
  612. }
  613. var x NetInfo
  614. if err := jsonv1.Unmarshal(b, &x); err != nil {
  615. return err
  616. }
  617. v.ж = &x
  618. return nil
  619. }
  620. // UnmarshalJSONFrom implements [jsonv2.UnmarshalerFrom].
  621. func (v *NetInfoView) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
  622. if v.ж != nil {
  623. return errors.New("already initialized")
  624. }
  625. var x NetInfo
  626. if err := jsonv2.UnmarshalDecode(dec, &x); err != nil {
  627. return err
  628. }
  629. v.ж = &x
  630. return nil
  631. }
  632. // MappingVariesByDestIP says whether the host's NAT mappings
  633. // vary based on the destination IP.
  634. func (v NetInfoView) MappingVariesByDestIP() opt.Bool { return v.ж.MappingVariesByDestIP }
  635. // WorkingIPv6 is whether the host has IPv6 internet connectivity.
  636. func (v NetInfoView) WorkingIPv6() opt.Bool { return v.ж.WorkingIPv6 }
  637. // OSHasIPv6 is whether the OS supports IPv6 at all, regardless of
  638. // whether IPv6 internet connectivity is available.
  639. func (v NetInfoView) OSHasIPv6() opt.Bool { return v.ж.OSHasIPv6 }
  640. // WorkingUDP is whether the host has UDP internet connectivity.
  641. func (v NetInfoView) WorkingUDP() opt.Bool { return v.ж.WorkingUDP }
  642. // WorkingICMPv4 is whether ICMPv4 works.
  643. // Empty means not checked.
  644. func (v NetInfoView) WorkingICMPv4() opt.Bool { return v.ж.WorkingICMPv4 }
  645. // HavePortMap is whether we have an existing portmap open
  646. // (UPnP, PMP, or PCP).
  647. func (v NetInfoView) HavePortMap() bool { return v.ж.HavePortMap }
  648. // UPnP is whether UPnP appears present on the LAN.
  649. // Empty means not checked.
  650. func (v NetInfoView) UPnP() opt.Bool { return v.ж.UPnP }
  651. // PMP is whether NAT-PMP appears present on the LAN.
  652. // Empty means not checked.
  653. func (v NetInfoView) PMP() opt.Bool { return v.ж.PMP }
  654. // PCP is whether PCP appears present on the LAN.
  655. // Empty means not checked.
  656. func (v NetInfoView) PCP() opt.Bool { return v.ж.PCP }
  657. // PreferredDERP is this node's preferred (home) DERP region ID.
  658. // This is where the node expects to be contacted to begin a
  659. // peer-to-peer connection. The node might be be temporarily
  660. // connected to multiple DERP servers (to speak to other nodes
  661. // that are located elsewhere) but PreferredDERP is the region ID
  662. // that the node subscribes to traffic at.
  663. // Zero means disconnected or unknown.
  664. func (v NetInfoView) PreferredDERP() int { return v.ж.PreferredDERP }
  665. // LinkType is the current link type, if known.
  666. func (v NetInfoView) LinkType() string { return v.ж.LinkType }
  667. // DERPLatency is the fastest recent time to reach various
  668. // DERP STUN servers, in seconds. The map key is the
  669. // "regionID-v4" or "-v6"; it was previously the DERP server's
  670. // STUN host:port.
  671. //
  672. // This should only be updated rarely, or when there's a
  673. // material change, as any change here also gets uploaded to
  674. // the control plane.
  675. func (v NetInfoView) DERPLatency() views.Map[string, float64] { return views.MapOf(v.ж.DERPLatency) }
  676. // FirewallMode encodes both which firewall mode was selected and why.
  677. // It is Linux-specific (at least as of 2023-08-19) and is meant to help
  678. // debug iptables-vs-nftables issues. The string is of the form
  679. // "{nft,ift}-REASON", like "nft-forced" or "ipt-default". Empty means
  680. // either not Linux or a configuration in which the host firewall rules
  681. // are not managed by tailscaled.
  682. func (v NetInfoView) FirewallMode() string { return v.ж.FirewallMode }
  683. func (v NetInfoView) String() string { return v.ж.String() }
  684. // A compilation failure here means this code must be regenerated, with the command at the top of this file.
  685. var _NetInfoViewNeedsRegeneration = NetInfo(struct {
  686. MappingVariesByDestIP opt.Bool
  687. WorkingIPv6 opt.Bool
  688. OSHasIPv6 opt.Bool
  689. WorkingUDP opt.Bool
  690. WorkingICMPv4 opt.Bool
  691. HavePortMap bool
  692. UPnP opt.Bool
  693. PMP opt.Bool
  694. PCP opt.Bool
  695. PreferredDERP int
  696. LinkType string
  697. DERPLatency map[string]float64
  698. FirewallMode string
  699. }{})
  700. // View returns a read-only view of Login.
  701. func (p *Login) View() LoginView {
  702. return LoginView{ж: p}
  703. }
  704. // LoginView provides a read-only view over Login.
  705. //
  706. // Its methods should only be called if `Valid()` returns true.
  707. type LoginView struct {
  708. // ж is the underlying mutable value, named with a hard-to-type
  709. // character that looks pointy like a pointer.
  710. // It is named distinctively to make you think of how dangerous it is to escape
  711. // to callers. You must not let callers be able to mutate it.
  712. ж *Login
  713. }
  714. // Valid reports whether v's underlying value is non-nil.
  715. func (v LoginView) Valid() bool { return v.ж != nil }
  716. // AsStruct returns a clone of the underlying value which aliases no memory with
  717. // the original.
  718. func (v LoginView) AsStruct() *Login {
  719. if v.ж == nil {
  720. return nil
  721. }
  722. return v.ж.Clone()
  723. }
  724. // MarshalJSON implements [jsonv1.Marshaler].
  725. func (v LoginView) MarshalJSON() ([]byte, error) {
  726. return jsonv1.Marshal(v.ж)
  727. }
  728. // MarshalJSONTo implements [jsonv2.MarshalerTo].
  729. func (v LoginView) MarshalJSONTo(enc *jsontext.Encoder) error {
  730. return jsonv2.MarshalEncode(enc, v.ж)
  731. }
  732. // UnmarshalJSON implements [jsonv1.Unmarshaler].
  733. func (v *LoginView) UnmarshalJSON(b []byte) error {
  734. if v.ж != nil {
  735. return errors.New("already initialized")
  736. }
  737. if len(b) == 0 {
  738. return nil
  739. }
  740. var x Login
  741. if err := jsonv1.Unmarshal(b, &x); err != nil {
  742. return err
  743. }
  744. v.ж = &x
  745. return nil
  746. }
  747. // UnmarshalJSONFrom implements [jsonv2.UnmarshalerFrom].
  748. func (v *LoginView) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
  749. if v.ж != nil {
  750. return errors.New("already initialized")
  751. }
  752. var x Login
  753. if err := jsonv2.UnmarshalDecode(dec, &x); err != nil {
  754. return err
  755. }
  756. v.ж = &x
  757. return nil
  758. }
  759. // unused in the Tailscale client
  760. func (v LoginView) ID() LoginID { return v.ж.ID }
  761. // "google", "github", "okta_foo", etc.
  762. func (v LoginView) Provider() string { return v.ж.Provider }
  763. // an email address or "email-ish" string (like alice@github)
  764. func (v LoginView) LoginName() string { return v.ж.LoginName }
  765. // from the IdP
  766. func (v LoginView) DisplayName() string { return v.ж.DisplayName }
  767. // from the IdP
  768. func (v LoginView) ProfilePicURL() string { return v.ж.ProfilePicURL }
  769. // A compilation failure here means this code must be regenerated, with the command at the top of this file.
  770. var _LoginViewNeedsRegeneration = Login(struct {
  771. _ structs.Incomparable
  772. ID LoginID
  773. Provider string
  774. LoginName string
  775. DisplayName string
  776. ProfilePicURL string
  777. }{})
  778. // View returns a read-only view of DNSConfig.
  779. func (p *DNSConfig) View() DNSConfigView {
  780. return DNSConfigView{ж: p}
  781. }
  782. // DNSConfigView provides a read-only view over DNSConfig.
  783. //
  784. // Its methods should only be called if `Valid()` returns true.
  785. type DNSConfigView struct {
  786. // ж is the underlying mutable value, named with a hard-to-type
  787. // character that looks pointy like a pointer.
  788. // It is named distinctively to make you think of how dangerous it is to escape
  789. // to callers. You must not let callers be able to mutate it.
  790. ж *DNSConfig
  791. }
  792. // Valid reports whether v's underlying value is non-nil.
  793. func (v DNSConfigView) Valid() bool { return v.ж != nil }
  794. // AsStruct returns a clone of the underlying value which aliases no memory with
  795. // the original.
  796. func (v DNSConfigView) AsStruct() *DNSConfig {
  797. if v.ж == nil {
  798. return nil
  799. }
  800. return v.ж.Clone()
  801. }
  802. // MarshalJSON implements [jsonv1.Marshaler].
  803. func (v DNSConfigView) MarshalJSON() ([]byte, error) {
  804. return jsonv1.Marshal(v.ж)
  805. }
  806. // MarshalJSONTo implements [jsonv2.MarshalerTo].
  807. func (v DNSConfigView) MarshalJSONTo(enc *jsontext.Encoder) error {
  808. return jsonv2.MarshalEncode(enc, v.ж)
  809. }
  810. // UnmarshalJSON implements [jsonv1.Unmarshaler].
  811. func (v *DNSConfigView) UnmarshalJSON(b []byte) error {
  812. if v.ж != nil {
  813. return errors.New("already initialized")
  814. }
  815. if len(b) == 0 {
  816. return nil
  817. }
  818. var x DNSConfig
  819. if err := jsonv1.Unmarshal(b, &x); err != nil {
  820. return err
  821. }
  822. v.ж = &x
  823. return nil
  824. }
  825. // UnmarshalJSONFrom implements [jsonv2.UnmarshalerFrom].
  826. func (v *DNSConfigView) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
  827. if v.ж != nil {
  828. return errors.New("already initialized")
  829. }
  830. var x DNSConfig
  831. if err := jsonv2.UnmarshalDecode(dec, &x); err != nil {
  832. return err
  833. }
  834. v.ж = &x
  835. return nil
  836. }
  837. // Resolvers are the DNS resolvers to use, in order of preference.
  838. func (v DNSConfigView) Resolvers() views.SliceView[*dnstype.Resolver, dnstype.ResolverView] {
  839. return views.SliceOfViews[*dnstype.Resolver, dnstype.ResolverView](v.ж.Resolvers)
  840. }
  841. // Routes maps DNS name suffixes to a set of DNS resolvers to
  842. // use. It is used to implement "split DNS" and other advanced DNS
  843. // routing overlays.
  844. //
  845. // Map keys are fully-qualified DNS name suffixes; they may
  846. // optionally contain a trailing dot but no leading dot.
  847. //
  848. // If the value is an empty slice, that means the suffix should still
  849. // be handled by Tailscale's built-in resolver (100.100.100.100), such
  850. // as for the purpose of handling ExtraRecords.
  851. func (v DNSConfigView) Routes() views.MapFn[string, []*dnstype.Resolver, views.SliceView[*dnstype.Resolver, dnstype.ResolverView]] {
  852. return views.MapFnOf(v.ж.Routes, func(t []*dnstype.Resolver) views.SliceView[*dnstype.Resolver, dnstype.ResolverView] {
  853. return views.SliceOfViews[*dnstype.Resolver, dnstype.ResolverView](t)
  854. })
  855. }
  856. // FallbackResolvers is like Resolvers, but is only used if a
  857. // split DNS configuration is requested in a configuration that
  858. // doesn't work yet without explicit default resolvers.
  859. // https://github.com/tailscale/tailscale/issues/1743
  860. func (v DNSConfigView) FallbackResolvers() views.SliceView[*dnstype.Resolver, dnstype.ResolverView] {
  861. return views.SliceOfViews[*dnstype.Resolver, dnstype.ResolverView](v.ж.FallbackResolvers)
  862. }
  863. // Domains are the search domains to use.
  864. // Search domains must be FQDNs, but *without* the trailing dot.
  865. func (v DNSConfigView) Domains() views.Slice[string] { return views.SliceOf(v.ж.Domains) }
  866. // Proxied turns on automatic resolution of hostnames for devices
  867. // in the network map, aka MagicDNS.
  868. // Despite the (legacy) name, does not necessarily cause request
  869. // proxying to be enabled.
  870. func (v DNSConfigView) Proxied() bool { return v.ж.Proxied }
  871. // Nameservers are the IP addresses of the global nameservers to use.
  872. //
  873. // Deprecated: this is only set and used by MapRequest.Version >=9 and <14. Use Resolvers instead.
  874. func (v DNSConfigView) Nameservers() views.Slice[netip.Addr] { return views.SliceOf(v.ж.Nameservers) }
  875. // CertDomains are the set of DNS names for which the control
  876. // plane server will assist with provisioning TLS
  877. // certificates. See SetDNSRequest, which can be used to
  878. // answer dns-01 ACME challenges for e.g. LetsEncrypt.
  879. // These names are FQDNs without trailing periods, and without
  880. // any "_acme-challenge." prefix.
  881. func (v DNSConfigView) CertDomains() views.Slice[string] { return views.SliceOf(v.ж.CertDomains) }
  882. // ExtraRecords contains extra DNS records to add to the
  883. // MagicDNS config.
  884. func (v DNSConfigView) ExtraRecords() views.Slice[DNSRecord] { return views.SliceOf(v.ж.ExtraRecords) }
  885. // ExitNodeFilteredSuffixes are the DNS suffixes that the
  886. // node, when being an exit node DNS proxy, should not answer.
  887. //
  888. // The entries do not contain trailing periods and are always
  889. // all lowercase.
  890. //
  891. // If an entry starts with a period, it's a suffix match (but
  892. // suffix ".a.b" doesn't match "a.b"; a prefix is required).
  893. //
  894. // If an entry does not start with a period, it's an exact
  895. // match.
  896. //
  897. // Matches are case insensitive.
  898. func (v DNSConfigView) ExitNodeFilteredSet() views.Slice[string] {
  899. return views.SliceOf(v.ж.ExitNodeFilteredSet)
  900. }
  901. // TempCorpIssue13969 is a temporary (2023-08-16) field for an internal hack day prototype.
  902. // It contains a user inputed URL that should have a list of domains to be blocked.
  903. // See https://github.com/tailscale/corp/issues/13969.
  904. func (v DNSConfigView) TempCorpIssue13969() string { return v.ж.TempCorpIssue13969 }
  905. // A compilation failure here means this code must be regenerated, with the command at the top of this file.
  906. var _DNSConfigViewNeedsRegeneration = DNSConfig(struct {
  907. Resolvers []*dnstype.Resolver
  908. Routes map[string][]*dnstype.Resolver
  909. FallbackResolvers []*dnstype.Resolver
  910. Domains []string
  911. Proxied bool
  912. Nameservers []netip.Addr
  913. CertDomains []string
  914. ExtraRecords []DNSRecord
  915. ExitNodeFilteredSet []string
  916. TempCorpIssue13969 string
  917. }{})
  918. // View returns a read-only view of RegisterResponse.
  919. func (p *RegisterResponse) View() RegisterResponseView {
  920. return RegisterResponseView{ж: p}
  921. }
  922. // RegisterResponseView provides a read-only view over RegisterResponse.
  923. //
  924. // Its methods should only be called if `Valid()` returns true.
  925. type RegisterResponseView struct {
  926. // ж is the underlying mutable value, named with a hard-to-type
  927. // character that looks pointy like a pointer.
  928. // It is named distinctively to make you think of how dangerous it is to escape
  929. // to callers. You must not let callers be able to mutate it.
  930. ж *RegisterResponse
  931. }
  932. // Valid reports whether v's underlying value is non-nil.
  933. func (v RegisterResponseView) Valid() bool { return v.ж != nil }
  934. // AsStruct returns a clone of the underlying value which aliases no memory with
  935. // the original.
  936. func (v RegisterResponseView) AsStruct() *RegisterResponse {
  937. if v.ж == nil {
  938. return nil
  939. }
  940. return v.ж.Clone()
  941. }
  942. // MarshalJSON implements [jsonv1.Marshaler].
  943. func (v RegisterResponseView) MarshalJSON() ([]byte, error) {
  944. return jsonv1.Marshal(v.ж)
  945. }
  946. // MarshalJSONTo implements [jsonv2.MarshalerTo].
  947. func (v RegisterResponseView) MarshalJSONTo(enc *jsontext.Encoder) error {
  948. return jsonv2.MarshalEncode(enc, v.ж)
  949. }
  950. // UnmarshalJSON implements [jsonv1.Unmarshaler].
  951. func (v *RegisterResponseView) UnmarshalJSON(b []byte) error {
  952. if v.ж != nil {
  953. return errors.New("already initialized")
  954. }
  955. if len(b) == 0 {
  956. return nil
  957. }
  958. var x RegisterResponse
  959. if err := jsonv1.Unmarshal(b, &x); err != nil {
  960. return err
  961. }
  962. v.ж = &x
  963. return nil
  964. }
  965. // UnmarshalJSONFrom implements [jsonv2.UnmarshalerFrom].
  966. func (v *RegisterResponseView) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
  967. if v.ж != nil {
  968. return errors.New("already initialized")
  969. }
  970. var x RegisterResponse
  971. if err := jsonv2.UnmarshalDecode(dec, &x); err != nil {
  972. return err
  973. }
  974. v.ж = &x
  975. return nil
  976. }
  977. func (v RegisterResponseView) User() User { return v.ж.User }
  978. func (v RegisterResponseView) Login() Login { return v.ж.Login }
  979. // if true, the NodeKey needs to be replaced
  980. func (v RegisterResponseView) NodeKeyExpired() bool { return v.ж.NodeKeyExpired }
  981. // TODO(crawshaw): move to using MachineStatus
  982. func (v RegisterResponseView) MachineAuthorized() bool { return v.ж.MachineAuthorized }
  983. // if set, authorization pending
  984. func (v RegisterResponseView) AuthURL() string { return v.ж.AuthURL }
  985. // If set, this is the current node-key signature that needs to be
  986. // re-signed for the node's new node-key.
  987. func (v RegisterResponseView) NodeKeySignature() views.ByteSlice[tkatype.MarshaledSignature] {
  988. return views.ByteSliceOf(v.ж.NodeKeySignature)
  989. }
  990. // Error indicates that authorization failed. If this is non-empty,
  991. // other status fields should be ignored.
  992. func (v RegisterResponseView) Error() string { return v.ж.Error }
  993. // A compilation failure here means this code must be regenerated, with the command at the top of this file.
  994. var _RegisterResponseViewNeedsRegeneration = RegisterResponse(struct {
  995. User User
  996. Login Login
  997. NodeKeyExpired bool
  998. MachineAuthorized bool
  999. AuthURL string
  1000. NodeKeySignature tkatype.MarshaledSignature
  1001. Error string
  1002. }{})
  1003. // View returns a read-only view of RegisterResponseAuth.
  1004. func (p *RegisterResponseAuth) View() RegisterResponseAuthView {
  1005. return RegisterResponseAuthView{ж: p}
  1006. }
  1007. // RegisterResponseAuthView provides a read-only view over RegisterResponseAuth.
  1008. //
  1009. // Its methods should only be called if `Valid()` returns true.
  1010. type RegisterResponseAuthView struct {
  1011. // ж is the underlying mutable value, named with a hard-to-type
  1012. // character that looks pointy like a pointer.
  1013. // It is named distinctively to make you think of how dangerous it is to escape
  1014. // to callers. You must not let callers be able to mutate it.
  1015. ж *RegisterResponseAuth
  1016. }
  1017. // Valid reports whether v's underlying value is non-nil.
  1018. func (v RegisterResponseAuthView) Valid() bool { return v.ж != nil }
  1019. // AsStruct returns a clone of the underlying value which aliases no memory with
  1020. // the original.
  1021. func (v RegisterResponseAuthView) AsStruct() *RegisterResponseAuth {
  1022. if v.ж == nil {
  1023. return nil
  1024. }
  1025. return v.ж.Clone()
  1026. }
  1027. // MarshalJSON implements [jsonv1.Marshaler].
  1028. func (v RegisterResponseAuthView) MarshalJSON() ([]byte, error) {
  1029. return jsonv1.Marshal(v.ж)
  1030. }
  1031. // MarshalJSONTo implements [jsonv2.MarshalerTo].
  1032. func (v RegisterResponseAuthView) MarshalJSONTo(enc *jsontext.Encoder) error {
  1033. return jsonv2.MarshalEncode(enc, v.ж)
  1034. }
  1035. // UnmarshalJSON implements [jsonv1.Unmarshaler].
  1036. func (v *RegisterResponseAuthView) UnmarshalJSON(b []byte) error {
  1037. if v.ж != nil {
  1038. return errors.New("already initialized")
  1039. }
  1040. if len(b) == 0 {
  1041. return nil
  1042. }
  1043. var x RegisterResponseAuth
  1044. if err := jsonv1.Unmarshal(b, &x); err != nil {
  1045. return err
  1046. }
  1047. v.ж = &x
  1048. return nil
  1049. }
  1050. // UnmarshalJSONFrom implements [jsonv2.UnmarshalerFrom].
  1051. func (v *RegisterResponseAuthView) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
  1052. if v.ж != nil {
  1053. return errors.New("already initialized")
  1054. }
  1055. var x RegisterResponseAuth
  1056. if err := jsonv2.UnmarshalDecode(dec, &x); err != nil {
  1057. return err
  1058. }
  1059. v.ж = &x
  1060. return nil
  1061. }
  1062. // used by pre-1.66 Android only
  1063. func (v RegisterResponseAuthView) Oauth2Token() views.ValuePointer[Oauth2Token] {
  1064. return views.ValuePointerOf(v.ж.Oauth2Token)
  1065. }
  1066. func (v RegisterResponseAuthView) AuthKey() string { return v.ж.AuthKey }
  1067. // A compilation failure here means this code must be regenerated, with the command at the top of this file.
  1068. var _RegisterResponseAuthViewNeedsRegeneration = RegisterResponseAuth(struct {
  1069. _ structs.Incomparable
  1070. Oauth2Token *Oauth2Token
  1071. AuthKey string
  1072. }{})
  1073. // View returns a read-only view of RegisterRequest.
  1074. func (p *RegisterRequest) View() RegisterRequestView {
  1075. return RegisterRequestView{ж: p}
  1076. }
  1077. // RegisterRequestView provides a read-only view over RegisterRequest.
  1078. //
  1079. // Its methods should only be called if `Valid()` returns true.
  1080. type RegisterRequestView struct {
  1081. // ж is the underlying mutable value, named with a hard-to-type
  1082. // character that looks pointy like a pointer.
  1083. // It is named distinctively to make you think of how dangerous it is to escape
  1084. // to callers. You must not let callers be able to mutate it.
  1085. ж *RegisterRequest
  1086. }
  1087. // Valid reports whether v's underlying value is non-nil.
  1088. func (v RegisterRequestView) Valid() bool { return v.ж != nil }
  1089. // AsStruct returns a clone of the underlying value which aliases no memory with
  1090. // the original.
  1091. func (v RegisterRequestView) AsStruct() *RegisterRequest {
  1092. if v.ж == nil {
  1093. return nil
  1094. }
  1095. return v.ж.Clone()
  1096. }
  1097. // MarshalJSON implements [jsonv1.Marshaler].
  1098. func (v RegisterRequestView) MarshalJSON() ([]byte, error) {
  1099. return jsonv1.Marshal(v.ж)
  1100. }
  1101. // MarshalJSONTo implements [jsonv2.MarshalerTo].
  1102. func (v RegisterRequestView) MarshalJSONTo(enc *jsontext.Encoder) error {
  1103. return jsonv2.MarshalEncode(enc, v.ж)
  1104. }
  1105. // UnmarshalJSON implements [jsonv1.Unmarshaler].
  1106. func (v *RegisterRequestView) UnmarshalJSON(b []byte) error {
  1107. if v.ж != nil {
  1108. return errors.New("already initialized")
  1109. }
  1110. if len(b) == 0 {
  1111. return nil
  1112. }
  1113. var x RegisterRequest
  1114. if err := jsonv1.Unmarshal(b, &x); err != nil {
  1115. return err
  1116. }
  1117. v.ж = &x
  1118. return nil
  1119. }
  1120. // UnmarshalJSONFrom implements [jsonv2.UnmarshalerFrom].
  1121. func (v *RegisterRequestView) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
  1122. if v.ж != nil {
  1123. return errors.New("already initialized")
  1124. }
  1125. var x RegisterRequest
  1126. if err := jsonv2.UnmarshalDecode(dec, &x); err != nil {
  1127. return err
  1128. }
  1129. v.ж = &x
  1130. return nil
  1131. }
  1132. // Version is the client's capabilities when using the Noise
  1133. // transport.
  1134. //
  1135. // When using the original nacl crypto_box transport, the
  1136. // value must be 1.
  1137. func (v RegisterRequestView) Version() CapabilityVersion { return v.ж.Version }
  1138. func (v RegisterRequestView) NodeKey() key.NodePublic { return v.ж.NodeKey }
  1139. func (v RegisterRequestView) OldNodeKey() key.NodePublic { return v.ж.OldNodeKey }
  1140. func (v RegisterRequestView) NLKey() key.NLPublic { return v.ж.NLKey }
  1141. func (v RegisterRequestView) Auth() RegisterResponseAuthView { return v.ж.Auth.View() }
  1142. // Expiry optionally specifies the requested key expiry.
  1143. // The server policy may override.
  1144. // As a special case, if Expiry is in the past and NodeKey is
  1145. // the node's current key, the key is expired.
  1146. func (v RegisterRequestView) Expiry() time.Time { return v.ж.Expiry }
  1147. // response waits until AuthURL is visited
  1148. func (v RegisterRequestView) Followup() string { return v.ж.Followup }
  1149. func (v RegisterRequestView) Hostinfo() HostinfoView { return v.ж.Hostinfo.View() }
  1150. // Ephemeral is whether the client is requesting that this
  1151. // node be considered ephemeral and be automatically deleted
  1152. // when it stops being active.
  1153. func (v RegisterRequestView) Ephemeral() bool { return v.ж.Ephemeral }
  1154. // NodeKeySignature is the node's own node-key signature, re-signed
  1155. // for its new node key using its network-lock key.
  1156. //
  1157. // This field is set when the client retries registration after learning
  1158. // its NodeKeySignature (which is in need of rotation).
  1159. func (v RegisterRequestView) NodeKeySignature() views.ByteSlice[tkatype.MarshaledSignature] {
  1160. return views.ByteSliceOf(v.ж.NodeKeySignature)
  1161. }
  1162. // The following fields are not used for SignatureNone and are required for
  1163. // SignatureV1:
  1164. func (v RegisterRequestView) SignatureType() SignatureType { return v.ж.SignatureType }
  1165. // creation time of request to prevent replay
  1166. func (v RegisterRequestView) Timestamp() views.ValuePointer[time.Time] {
  1167. return views.ValuePointerOf(v.ж.Timestamp)
  1168. }
  1169. // X.509 certificate for client device
  1170. func (v RegisterRequestView) DeviceCert() views.ByteSlice[[]byte] {
  1171. return views.ByteSliceOf(v.ж.DeviceCert)
  1172. }
  1173. // as described by SignatureType
  1174. func (v RegisterRequestView) Signature() views.ByteSlice[[]byte] {
  1175. return views.ByteSliceOf(v.ж.Signature)
  1176. }
  1177. // Tailnet is an optional identifier specifying the name of the recommended or required
  1178. // network that the node should join. Its exact form should not be depended on; new
  1179. // forms are coming later. The identifier is generally a domain name (for an organization)
  1180. // or e-mail address (for a personal account on a shared e-mail provider). It is the same name
  1181. // used by the API, as described in /api.md#tailnet.
  1182. // If Tailnet begins with the prefix "required:" then the server should prevent logging in to a different
  1183. // network than the one specified. Otherwise, the server should recommend the specified network
  1184. // but still permit logging in to other networks.
  1185. // If empty, no recommendation is offered to the server and the login page should show all options.
  1186. func (v RegisterRequestView) Tailnet() string { return v.ж.Tailnet }
  1187. // A compilation failure here means this code must be regenerated, with the command at the top of this file.
  1188. var _RegisterRequestViewNeedsRegeneration = RegisterRequest(struct {
  1189. _ structs.Incomparable
  1190. Version CapabilityVersion
  1191. NodeKey key.NodePublic
  1192. OldNodeKey key.NodePublic
  1193. NLKey key.NLPublic
  1194. Auth *RegisterResponseAuth
  1195. Expiry time.Time
  1196. Followup string
  1197. Hostinfo *Hostinfo
  1198. Ephemeral bool
  1199. NodeKeySignature tkatype.MarshaledSignature
  1200. SignatureType SignatureType
  1201. Timestamp *time.Time
  1202. DeviceCert []byte
  1203. Signature []byte
  1204. Tailnet string
  1205. }{})
  1206. // View returns a read-only view of DERPHomeParams.
  1207. func (p *DERPHomeParams) View() DERPHomeParamsView {
  1208. return DERPHomeParamsView{ж: p}
  1209. }
  1210. // DERPHomeParamsView provides a read-only view over DERPHomeParams.
  1211. //
  1212. // Its methods should only be called if `Valid()` returns true.
  1213. type DERPHomeParamsView struct {
  1214. // ж is the underlying mutable value, named with a hard-to-type
  1215. // character that looks pointy like a pointer.
  1216. // It is named distinctively to make you think of how dangerous it is to escape
  1217. // to callers. You must not let callers be able to mutate it.
  1218. ж *DERPHomeParams
  1219. }
  1220. // Valid reports whether v's underlying value is non-nil.
  1221. func (v DERPHomeParamsView) Valid() bool { return v.ж != nil }
  1222. // AsStruct returns a clone of the underlying value which aliases no memory with
  1223. // the original.
  1224. func (v DERPHomeParamsView) AsStruct() *DERPHomeParams {
  1225. if v.ж == nil {
  1226. return nil
  1227. }
  1228. return v.ж.Clone()
  1229. }
  1230. // MarshalJSON implements [jsonv1.Marshaler].
  1231. func (v DERPHomeParamsView) MarshalJSON() ([]byte, error) {
  1232. return jsonv1.Marshal(v.ж)
  1233. }
  1234. // MarshalJSONTo implements [jsonv2.MarshalerTo].
  1235. func (v DERPHomeParamsView) MarshalJSONTo(enc *jsontext.Encoder) error {
  1236. return jsonv2.MarshalEncode(enc, v.ж)
  1237. }
  1238. // UnmarshalJSON implements [jsonv1.Unmarshaler].
  1239. func (v *DERPHomeParamsView) UnmarshalJSON(b []byte) error {
  1240. if v.ж != nil {
  1241. return errors.New("already initialized")
  1242. }
  1243. if len(b) == 0 {
  1244. return nil
  1245. }
  1246. var x DERPHomeParams
  1247. if err := jsonv1.Unmarshal(b, &x); err != nil {
  1248. return err
  1249. }
  1250. v.ж = &x
  1251. return nil
  1252. }
  1253. // UnmarshalJSONFrom implements [jsonv2.UnmarshalerFrom].
  1254. func (v *DERPHomeParamsView) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
  1255. if v.ж != nil {
  1256. return errors.New("already initialized")
  1257. }
  1258. var x DERPHomeParams
  1259. if err := jsonv2.UnmarshalDecode(dec, &x); err != nil {
  1260. return err
  1261. }
  1262. v.ж = &x
  1263. return nil
  1264. }
  1265. // RegionScore scales latencies of DERP regions by a given scaling
  1266. // factor when determining which region to use as the home
  1267. // ("preferred") DERP. Scores in the range (0, 1) will cause this
  1268. // region to be proportionally more preferred, and scores in the range
  1269. // (1, ∞) will penalize a region.
  1270. //
  1271. // If a region is not present in this map, it is treated as having a
  1272. // score of 1.0.
  1273. //
  1274. // Scores should not be 0 or negative; such scores will be ignored.
  1275. //
  1276. // A nil map means no change from the previous value (if any); an empty
  1277. // non-nil map can be sent to reset all scores back to 1.0.
  1278. func (v DERPHomeParamsView) RegionScore() views.Map[int, float64] {
  1279. return views.MapOf(v.ж.RegionScore)
  1280. }
  1281. // A compilation failure here means this code must be regenerated, with the command at the top of this file.
  1282. var _DERPHomeParamsViewNeedsRegeneration = DERPHomeParams(struct {
  1283. RegionScore map[int]float64
  1284. }{})
  1285. // View returns a read-only view of DERPRegion.
  1286. func (p *DERPRegion) View() DERPRegionView {
  1287. return DERPRegionView{ж: p}
  1288. }
  1289. // DERPRegionView provides a read-only view over DERPRegion.
  1290. //
  1291. // Its methods should only be called if `Valid()` returns true.
  1292. type DERPRegionView struct {
  1293. // ж is the underlying mutable value, named with a hard-to-type
  1294. // character that looks pointy like a pointer.
  1295. // It is named distinctively to make you think of how dangerous it is to escape
  1296. // to callers. You must not let callers be able to mutate it.
  1297. ж *DERPRegion
  1298. }
  1299. // Valid reports whether v's underlying value is non-nil.
  1300. func (v DERPRegionView) Valid() bool { return v.ж != nil }
  1301. // AsStruct returns a clone of the underlying value which aliases no memory with
  1302. // the original.
  1303. func (v DERPRegionView) AsStruct() *DERPRegion {
  1304. if v.ж == nil {
  1305. return nil
  1306. }
  1307. return v.ж.Clone()
  1308. }
  1309. // MarshalJSON implements [jsonv1.Marshaler].
  1310. func (v DERPRegionView) MarshalJSON() ([]byte, error) {
  1311. return jsonv1.Marshal(v.ж)
  1312. }
  1313. // MarshalJSONTo implements [jsonv2.MarshalerTo].
  1314. func (v DERPRegionView) MarshalJSONTo(enc *jsontext.Encoder) error {
  1315. return jsonv2.MarshalEncode(enc, v.ж)
  1316. }
  1317. // UnmarshalJSON implements [jsonv1.Unmarshaler].
  1318. func (v *DERPRegionView) UnmarshalJSON(b []byte) error {
  1319. if v.ж != nil {
  1320. return errors.New("already initialized")
  1321. }
  1322. if len(b) == 0 {
  1323. return nil
  1324. }
  1325. var x DERPRegion
  1326. if err := jsonv1.Unmarshal(b, &x); err != nil {
  1327. return err
  1328. }
  1329. v.ж = &x
  1330. return nil
  1331. }
  1332. // UnmarshalJSONFrom implements [jsonv2.UnmarshalerFrom].
  1333. func (v *DERPRegionView) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
  1334. if v.ж != nil {
  1335. return errors.New("already initialized")
  1336. }
  1337. var x DERPRegion
  1338. if err := jsonv2.UnmarshalDecode(dec, &x); err != nil {
  1339. return err
  1340. }
  1341. v.ж = &x
  1342. return nil
  1343. }
  1344. // RegionID is a unique integer for a geographic region.
  1345. //
  1346. // It corresponds to the legacy derpN.tailscale.com hostnames
  1347. // used by older clients. (Older clients will continue to resolve
  1348. // derpN.tailscale.com when contacting peers, rather than use
  1349. // the server-provided DERPMap)
  1350. //
  1351. // RegionIDs must be non-zero, positive, and guaranteed to fit
  1352. // in a JavaScript number.
  1353. //
  1354. // RegionIDs in range 900-999 are reserved for end users to run their
  1355. // own DERP nodes.
  1356. func (v DERPRegionView) RegionID() int { return v.ж.RegionID }
  1357. // RegionCode is a short name for the region. It's usually a popular
  1358. // city or airport code in the region: "nyc", "sf", "sin",
  1359. // "fra", etc.
  1360. func (v DERPRegionView) RegionCode() string { return v.ж.RegionCode }
  1361. // RegionName is a long English name for the region: "New York City",
  1362. // "San Francisco", "Singapore", "Frankfurt", etc.
  1363. func (v DERPRegionView) RegionName() string { return v.ж.RegionName }
  1364. // Latitude, Longitude are optional geographical coordinates of the DERP region's city, in degrees.
  1365. func (v DERPRegionView) Latitude() float64 { return v.ж.Latitude }
  1366. func (v DERPRegionView) Longitude() float64 { return v.ж.Longitude }
  1367. // Avoid is whether the client should avoid picking this as its home region.
  1368. // The region should only be used if a peer is there. Clients already using
  1369. // this region as their home should migrate away to a new region without
  1370. // Avoid set.
  1371. //
  1372. // Deprecated: because of bugs in past implementations combined with unclear
  1373. // docs that caused people to think the bugs were intentional, this field is
  1374. // deprecated. It was never supposed to cause STUN/DERP measurement probes,
  1375. // but due to bugs, it sometimes did. And then some parts of the code began
  1376. // to rely on that property. But then we were unable to use this field for
  1377. // its original purpose, nor its later imagined purpose, because various
  1378. // parts of the codebase thought it meant one thing and others thought it
  1379. // meant another. But it did something in the middle instead. So we're retiring
  1380. // it. Use NoMeasureNoHome instead.
  1381. func (v DERPRegionView) Avoid() bool { return v.ж.Avoid }
  1382. // NoMeasureNoHome says that this regions should not be measured for its
  1383. // latency distance (STUN, HTTPS, etc) or availability (e.g. captive portal
  1384. // checks) and should never be selected as the node's home region. However,
  1385. // if a peer declares this region as its home, then this client is allowed
  1386. // to connect to it for the purpose of communicating with that peer.
  1387. //
  1388. // This is what the now deprecated Avoid bool was supposed to mean
  1389. // originally but had implementation bugs and documentation omissions.
  1390. func (v DERPRegionView) NoMeasureNoHome() bool { return v.ж.NoMeasureNoHome }
  1391. // Nodes are the DERP nodes running in this region, in
  1392. // priority order for the current client. Client TLS
  1393. // connections should ideally only go to the first entry
  1394. // (falling back to the second if necessary). STUN packets
  1395. // should go to the first 1 or 2.
  1396. //
  1397. // If nodes within a region route packets amongst themselves,
  1398. // but not to other regions. That said, each user/domain
  1399. // should get a the same preferred node order, so if all nodes
  1400. // for a user/network pick the first one (as they should, when
  1401. // things are healthy), the inter-cluster routing is minimal
  1402. // to zero.
  1403. func (v DERPRegionView) Nodes() views.SliceView[*DERPNode, DERPNodeView] {
  1404. return views.SliceOfViews[*DERPNode, DERPNodeView](v.ж.Nodes)
  1405. }
  1406. // A compilation failure here means this code must be regenerated, with the command at the top of this file.
  1407. var _DERPRegionViewNeedsRegeneration = DERPRegion(struct {
  1408. RegionID int
  1409. RegionCode string
  1410. RegionName string
  1411. Latitude float64
  1412. Longitude float64
  1413. Avoid bool
  1414. NoMeasureNoHome bool
  1415. Nodes []*DERPNode
  1416. }{})
  1417. // View returns a read-only view of DERPMap.
  1418. func (p *DERPMap) View() DERPMapView {
  1419. return DERPMapView{ж: p}
  1420. }
  1421. // DERPMapView provides a read-only view over DERPMap.
  1422. //
  1423. // Its methods should only be called if `Valid()` returns true.
  1424. type DERPMapView struct {
  1425. // ж is the underlying mutable value, named with a hard-to-type
  1426. // character that looks pointy like a pointer.
  1427. // It is named distinctively to make you think of how dangerous it is to escape
  1428. // to callers. You must not let callers be able to mutate it.
  1429. ж *DERPMap
  1430. }
  1431. // Valid reports whether v's underlying value is non-nil.
  1432. func (v DERPMapView) Valid() bool { return v.ж != nil }
  1433. // AsStruct returns a clone of the underlying value which aliases no memory with
  1434. // the original.
  1435. func (v DERPMapView) AsStruct() *DERPMap {
  1436. if v.ж == nil {
  1437. return nil
  1438. }
  1439. return v.ж.Clone()
  1440. }
  1441. // MarshalJSON implements [jsonv1.Marshaler].
  1442. func (v DERPMapView) MarshalJSON() ([]byte, error) {
  1443. return jsonv1.Marshal(v.ж)
  1444. }
  1445. // MarshalJSONTo implements [jsonv2.MarshalerTo].
  1446. func (v DERPMapView) MarshalJSONTo(enc *jsontext.Encoder) error {
  1447. return jsonv2.MarshalEncode(enc, v.ж)
  1448. }
  1449. // UnmarshalJSON implements [jsonv1.Unmarshaler].
  1450. func (v *DERPMapView) UnmarshalJSON(b []byte) error {
  1451. if v.ж != nil {
  1452. return errors.New("already initialized")
  1453. }
  1454. if len(b) == 0 {
  1455. return nil
  1456. }
  1457. var x DERPMap
  1458. if err := jsonv1.Unmarshal(b, &x); err != nil {
  1459. return err
  1460. }
  1461. v.ж = &x
  1462. return nil
  1463. }
  1464. // UnmarshalJSONFrom implements [jsonv2.UnmarshalerFrom].
  1465. func (v *DERPMapView) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
  1466. if v.ж != nil {
  1467. return errors.New("already initialized")
  1468. }
  1469. var x DERPMap
  1470. if err := jsonv2.UnmarshalDecode(dec, &x); err != nil {
  1471. return err
  1472. }
  1473. v.ж = &x
  1474. return nil
  1475. }
  1476. // HomeParams, if non-nil, is a change in home parameters.
  1477. //
  1478. // The rest of the DEPRMap fields, if zero, means unchanged.
  1479. func (v DERPMapView) HomeParams() DERPHomeParamsView { return v.ж.HomeParams.View() }
  1480. // Regions is the set of geographic regions running DERP node(s).
  1481. //
  1482. // It's keyed by the DERPRegion.RegionID.
  1483. //
  1484. // The numbers are not necessarily contiguous.
  1485. func (v DERPMapView) Regions() views.MapFn[int, *DERPRegion, DERPRegionView] {
  1486. return views.MapFnOf(v.ж.Regions, func(t *DERPRegion) DERPRegionView {
  1487. return t.View()
  1488. })
  1489. }
  1490. // OmitDefaultRegions specifies to not use Tailscale's DERP servers, and only use those
  1491. // specified in this DERPMap. If there are none set outside of the defaults, this is a noop.
  1492. //
  1493. // This field is only meaningful if the Regions map is non-nil (indicating a change).
  1494. func (v DERPMapView) OmitDefaultRegions() bool { return v.ж.OmitDefaultRegions }
  1495. // A compilation failure here means this code must be regenerated, with the command at the top of this file.
  1496. var _DERPMapViewNeedsRegeneration = DERPMap(struct {
  1497. HomeParams *DERPHomeParams
  1498. Regions map[int]*DERPRegion
  1499. OmitDefaultRegions bool
  1500. }{})
  1501. // View returns a read-only view of DERPNode.
  1502. func (p *DERPNode) View() DERPNodeView {
  1503. return DERPNodeView{ж: p}
  1504. }
  1505. // DERPNodeView provides a read-only view over DERPNode.
  1506. //
  1507. // Its methods should only be called if `Valid()` returns true.
  1508. type DERPNodeView struct {
  1509. // ж is the underlying mutable value, named with a hard-to-type
  1510. // character that looks pointy like a pointer.
  1511. // It is named distinctively to make you think of how dangerous it is to escape
  1512. // to callers. You must not let callers be able to mutate it.
  1513. ж *DERPNode
  1514. }
  1515. // Valid reports whether v's underlying value is non-nil.
  1516. func (v DERPNodeView) Valid() bool { return v.ж != nil }
  1517. // AsStruct returns a clone of the underlying value which aliases no memory with
  1518. // the original.
  1519. func (v DERPNodeView) AsStruct() *DERPNode {
  1520. if v.ж == nil {
  1521. return nil
  1522. }
  1523. return v.ж.Clone()
  1524. }
  1525. // MarshalJSON implements [jsonv1.Marshaler].
  1526. func (v DERPNodeView) MarshalJSON() ([]byte, error) {
  1527. return jsonv1.Marshal(v.ж)
  1528. }
  1529. // MarshalJSONTo implements [jsonv2.MarshalerTo].
  1530. func (v DERPNodeView) MarshalJSONTo(enc *jsontext.Encoder) error {
  1531. return jsonv2.MarshalEncode(enc, v.ж)
  1532. }
  1533. // UnmarshalJSON implements [jsonv1.Unmarshaler].
  1534. func (v *DERPNodeView) UnmarshalJSON(b []byte) error {
  1535. if v.ж != nil {
  1536. return errors.New("already initialized")
  1537. }
  1538. if len(b) == 0 {
  1539. return nil
  1540. }
  1541. var x DERPNode
  1542. if err := jsonv1.Unmarshal(b, &x); err != nil {
  1543. return err
  1544. }
  1545. v.ж = &x
  1546. return nil
  1547. }
  1548. // UnmarshalJSONFrom implements [jsonv2.UnmarshalerFrom].
  1549. func (v *DERPNodeView) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
  1550. if v.ж != nil {
  1551. return errors.New("already initialized")
  1552. }
  1553. var x DERPNode
  1554. if err := jsonv2.UnmarshalDecode(dec, &x); err != nil {
  1555. return err
  1556. }
  1557. v.ж = &x
  1558. return nil
  1559. }
  1560. // Name is a unique node name (across all regions).
  1561. // It is not a host name.
  1562. // It's typically of the form "1b", "2a", "3b", etc. (region
  1563. // ID + suffix within that region)
  1564. func (v DERPNodeView) Name() string { return v.ж.Name }
  1565. // RegionID is the RegionID of the DERPRegion that this node
  1566. // is running in.
  1567. func (v DERPNodeView) RegionID() int { return v.ж.RegionID }
  1568. // HostName is the DERP node's hostname.
  1569. //
  1570. // It is required but need not be unique; multiple nodes may
  1571. // have the same HostName but vary in configuration otherwise.
  1572. func (v DERPNodeView) HostName() string { return v.ж.HostName }
  1573. // CertName optionally specifies the expected TLS cert common
  1574. // name. If empty, HostName is used. If CertName is non-empty,
  1575. // HostName is only used for the TCP dial (if IPv4/IPv6 are
  1576. // not present) + TLS ClientHello.
  1577. //
  1578. // As a special case, if CertName starts with "sha256-raw:",
  1579. // then the rest of the string is a hex-encoded SHA256 of the
  1580. // cert to expect. This is used for self-signed certs.
  1581. // In this case, the HostName field will typically be an IP
  1582. // address literal.
  1583. func (v DERPNodeView) CertName() string { return v.ж.CertName }
  1584. // IPv4 optionally forces an IPv4 address to use, instead of using DNS.
  1585. // If empty, A record(s) from DNS lookups of HostName are used.
  1586. // If the string is not an IPv4 address, IPv4 is not used; the
  1587. // conventional string to disable IPv4 (and not use DNS) is
  1588. // "none".
  1589. func (v DERPNodeView) IPv4() string { return v.ж.IPv4 }
  1590. // IPv6 optionally forces an IPv6 address to use, instead of using DNS.
  1591. // If empty, AAAA record(s) from DNS lookups of HostName are used.
  1592. // If the string is not an IPv6 address, IPv6 is not used; the
  1593. // conventional string to disable IPv6 (and not use DNS) is
  1594. // "none".
  1595. func (v DERPNodeView) IPv6() string { return v.ж.IPv6 }
  1596. // Port optionally specifies a STUN port to use.
  1597. // Zero means 3478.
  1598. // To disable STUN on this node, use -1.
  1599. func (v DERPNodeView) STUNPort() int { return v.ж.STUNPort }
  1600. // STUNOnly marks a node as only a STUN server and not a DERP
  1601. // server.
  1602. func (v DERPNodeView) STUNOnly() bool { return v.ж.STUNOnly }
  1603. // DERPPort optionally provides an alternate TLS port number
  1604. // for the DERP HTTPS server.
  1605. //
  1606. // If zero, 443 is used.
  1607. func (v DERPNodeView) DERPPort() int { return v.ж.DERPPort }
  1608. // InsecureForTests is used by unit tests to disable TLS verification.
  1609. // It should not be set by users.
  1610. func (v DERPNodeView) InsecureForTests() bool { return v.ж.InsecureForTests }
  1611. // STUNTestIP is used in tests to override the STUN server's IP.
  1612. // If empty, it's assumed to be the same as the DERP server.
  1613. func (v DERPNodeView) STUNTestIP() string { return v.ж.STUNTestIP }
  1614. // CanPort80 specifies whether this DERP node is accessible over HTTP
  1615. // on port 80 specifically. This is used for captive portal checks.
  1616. func (v DERPNodeView) CanPort80() bool { return v.ж.CanPort80 }
  1617. // A compilation failure here means this code must be regenerated, with the command at the top of this file.
  1618. var _DERPNodeViewNeedsRegeneration = DERPNode(struct {
  1619. Name string
  1620. RegionID int
  1621. HostName string
  1622. CertName string
  1623. IPv4 string
  1624. IPv6 string
  1625. STUNPort int
  1626. STUNOnly bool
  1627. DERPPort int
  1628. InsecureForTests bool
  1629. STUNTestIP string
  1630. CanPort80 bool
  1631. }{})
  1632. // View returns a read-only view of SSHRule.
  1633. func (p *SSHRule) View() SSHRuleView {
  1634. return SSHRuleView{ж: p}
  1635. }
  1636. // SSHRuleView provides a read-only view over SSHRule.
  1637. //
  1638. // Its methods should only be called if `Valid()` returns true.
  1639. type SSHRuleView struct {
  1640. // ж is the underlying mutable value, named with a hard-to-type
  1641. // character that looks pointy like a pointer.
  1642. // It is named distinctively to make you think of how dangerous it is to escape
  1643. // to callers. You must not let callers be able to mutate it.
  1644. ж *SSHRule
  1645. }
  1646. // Valid reports whether v's underlying value is non-nil.
  1647. func (v SSHRuleView) Valid() bool { return v.ж != nil }
  1648. // AsStruct returns a clone of the underlying value which aliases no memory with
  1649. // the original.
  1650. func (v SSHRuleView) AsStruct() *SSHRule {
  1651. if v.ж == nil {
  1652. return nil
  1653. }
  1654. return v.ж.Clone()
  1655. }
  1656. // MarshalJSON implements [jsonv1.Marshaler].
  1657. func (v SSHRuleView) MarshalJSON() ([]byte, error) {
  1658. return jsonv1.Marshal(v.ж)
  1659. }
  1660. // MarshalJSONTo implements [jsonv2.MarshalerTo].
  1661. func (v SSHRuleView) MarshalJSONTo(enc *jsontext.Encoder) error {
  1662. return jsonv2.MarshalEncode(enc, v.ж)
  1663. }
  1664. // UnmarshalJSON implements [jsonv1.Unmarshaler].
  1665. func (v *SSHRuleView) UnmarshalJSON(b []byte) error {
  1666. if v.ж != nil {
  1667. return errors.New("already initialized")
  1668. }
  1669. if len(b) == 0 {
  1670. return nil
  1671. }
  1672. var x SSHRule
  1673. if err := jsonv1.Unmarshal(b, &x); err != nil {
  1674. return err
  1675. }
  1676. v.ж = &x
  1677. return nil
  1678. }
  1679. // UnmarshalJSONFrom implements [jsonv2.UnmarshalerFrom].
  1680. func (v *SSHRuleView) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
  1681. if v.ж != nil {
  1682. return errors.New("already initialized")
  1683. }
  1684. var x SSHRule
  1685. if err := jsonv2.UnmarshalDecode(dec, &x); err != nil {
  1686. return err
  1687. }
  1688. v.ж = &x
  1689. return nil
  1690. }
  1691. // RuleExpires, if non-nil, is when this rule expires.
  1692. //
  1693. // For example, a (principal,sshuser) tuple might be granted
  1694. // prompt-free SSH access for N minutes, so this rule would be
  1695. // before a expiration-free rule for the same principal that
  1696. // required an auth prompt. This permits the control plane to
  1697. // be out of the path for already-authorized SSH pairs.
  1698. //
  1699. // Once a rule matches, the lifetime of any accepting connection
  1700. // is subject to the SSHAction.SessionExpires time, if any.
  1701. func (v SSHRuleView) RuleExpires() views.ValuePointer[time.Time] {
  1702. return views.ValuePointerOf(v.ж.RuleExpires)
  1703. }
  1704. // Principals matches an incoming connection. If the connection
  1705. // matches anything in this list and also matches SSHUsers,
  1706. // then Action is applied.
  1707. func (v SSHRuleView) Principals() views.SliceView[*SSHPrincipal, SSHPrincipalView] {
  1708. return views.SliceOfViews[*SSHPrincipal, SSHPrincipalView](v.ж.Principals)
  1709. }
  1710. // SSHUsers are the SSH users that this rule matches. It is a
  1711. // map from either ssh-user|"*" => local-user. The map must
  1712. // contain a key for either ssh-user or, as a fallback, "*" to
  1713. // match anything. If it does, the map entry's value is the
  1714. // actual user that's logged in.
  1715. // If the map value is the empty string (for either the
  1716. // requested SSH user or "*"), the rule doesn't match.
  1717. // If the map value is "=", it means the ssh-user should map
  1718. // directly to the local-user.
  1719. // It may be nil if the Action is reject.
  1720. func (v SSHRuleView) SSHUsers() views.Map[string, string] { return views.MapOf(v.ж.SSHUsers) }
  1721. // Action is the outcome to task.
  1722. // A nil or invalid action means to deny.
  1723. func (v SSHRuleView) Action() SSHActionView { return v.ж.Action.View() }
  1724. // AcceptEnv is a slice of environment variable names that are allowlisted
  1725. // for the SSH rule in the policy file.
  1726. //
  1727. // AcceptEnv values may contain * and ? wildcard characters which match against
  1728. // an arbitrary number of characters or a single character respectively.
  1729. func (v SSHRuleView) AcceptEnv() views.Slice[string] { return views.SliceOf(v.ж.AcceptEnv) }
  1730. // A compilation failure here means this code must be regenerated, with the command at the top of this file.
  1731. var _SSHRuleViewNeedsRegeneration = SSHRule(struct {
  1732. RuleExpires *time.Time
  1733. Principals []*SSHPrincipal
  1734. SSHUsers map[string]string
  1735. Action *SSHAction
  1736. AcceptEnv []string
  1737. }{})
  1738. // View returns a read-only view of SSHAction.
  1739. func (p *SSHAction) View() SSHActionView {
  1740. return SSHActionView{ж: p}
  1741. }
  1742. // SSHActionView provides a read-only view over SSHAction.
  1743. //
  1744. // Its methods should only be called if `Valid()` returns true.
  1745. type SSHActionView struct {
  1746. // ж is the underlying mutable value, named with a hard-to-type
  1747. // character that looks pointy like a pointer.
  1748. // It is named distinctively to make you think of how dangerous it is to escape
  1749. // to callers. You must not let callers be able to mutate it.
  1750. ж *SSHAction
  1751. }
  1752. // Valid reports whether v's underlying value is non-nil.
  1753. func (v SSHActionView) Valid() bool { return v.ж != nil }
  1754. // AsStruct returns a clone of the underlying value which aliases no memory with
  1755. // the original.
  1756. func (v SSHActionView) AsStruct() *SSHAction {
  1757. if v.ж == nil {
  1758. return nil
  1759. }
  1760. return v.ж.Clone()
  1761. }
  1762. // MarshalJSON implements [jsonv1.Marshaler].
  1763. func (v SSHActionView) MarshalJSON() ([]byte, error) {
  1764. return jsonv1.Marshal(v.ж)
  1765. }
  1766. // MarshalJSONTo implements [jsonv2.MarshalerTo].
  1767. func (v SSHActionView) MarshalJSONTo(enc *jsontext.Encoder) error {
  1768. return jsonv2.MarshalEncode(enc, v.ж)
  1769. }
  1770. // UnmarshalJSON implements [jsonv1.Unmarshaler].
  1771. func (v *SSHActionView) UnmarshalJSON(b []byte) error {
  1772. if v.ж != nil {
  1773. return errors.New("already initialized")
  1774. }
  1775. if len(b) == 0 {
  1776. return nil
  1777. }
  1778. var x SSHAction
  1779. if err := jsonv1.Unmarshal(b, &x); err != nil {
  1780. return err
  1781. }
  1782. v.ж = &x
  1783. return nil
  1784. }
  1785. // UnmarshalJSONFrom implements [jsonv2.UnmarshalerFrom].
  1786. func (v *SSHActionView) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
  1787. if v.ж != nil {
  1788. return errors.New("already initialized")
  1789. }
  1790. var x SSHAction
  1791. if err := jsonv2.UnmarshalDecode(dec, &x); err != nil {
  1792. return err
  1793. }
  1794. v.ж = &x
  1795. return nil
  1796. }
  1797. // Message, if non-empty, is shown to the user before the
  1798. // action occurs.
  1799. func (v SSHActionView) Message() string { return v.ж.Message }
  1800. // Reject, if true, terminates the connection. This action
  1801. // has higher priority that Accept, if given.
  1802. // The reason this is exists is primarily so a response
  1803. // from HoldAndDelegate has a way to stop the poll.
  1804. func (v SSHActionView) Reject() bool { return v.ж.Reject }
  1805. // Accept, if true, accepts the connection immediately
  1806. // without further prompts.
  1807. func (v SSHActionView) Accept() bool { return v.ж.Accept }
  1808. // SessionDuration, if non-zero, is how long the session can stay open
  1809. // before being forcefully terminated.
  1810. func (v SSHActionView) SessionDuration() time.Duration { return v.ж.SessionDuration }
  1811. // AllowAgentForwarding, if true, allows accepted connections to forward
  1812. // the ssh agent if requested.
  1813. func (v SSHActionView) AllowAgentForwarding() bool { return v.ж.AllowAgentForwarding }
  1814. // HoldAndDelegate, if non-empty, is a URL that serves an
  1815. // outcome verdict. The connection will be accepted and will
  1816. // block until the provided long-polling URL serves a new
  1817. // SSHAction JSON value. The URL must be fetched using the
  1818. // Noise transport (in package control/control{base,http}).
  1819. // If the long poll breaks before returning a complete HTTP
  1820. // response, it should be re-fetched as long as the SSH
  1821. // session is open.
  1822. //
  1823. // The following variables in the URL are expanded by tailscaled:
  1824. //
  1825. // - $SRC_NODE_IP (URL escaped)
  1826. // - $SRC_NODE_ID (Node.ID as int64 string)
  1827. // - $DST_NODE_IP (URL escaped)
  1828. // - $DST_NODE_ID (Node.ID as int64 string)
  1829. // - $SSH_USER (URL escaped, ssh user requested)
  1830. // - $LOCAL_USER (URL escaped, local user mapped)
  1831. func (v SSHActionView) HoldAndDelegate() string { return v.ж.HoldAndDelegate }
  1832. // AllowLocalPortForwarding, if true, allows accepted connections
  1833. // to use local port forwarding if requested.
  1834. func (v SSHActionView) AllowLocalPortForwarding() bool { return v.ж.AllowLocalPortForwarding }
  1835. // AllowRemotePortForwarding, if true, allows accepted connections
  1836. // to use remote port forwarding if requested.
  1837. func (v SSHActionView) AllowRemotePortForwarding() bool { return v.ж.AllowRemotePortForwarding }
  1838. // Recorders defines the destinations of the SSH session recorders.
  1839. // The recording will be uploaded to http://addr:port/record.
  1840. func (v SSHActionView) Recorders() views.Slice[netip.AddrPort] { return views.SliceOf(v.ж.Recorders) }
  1841. // OnRecorderFailure is the action to take if recording fails.
  1842. // If nil, the default action is to fail open.
  1843. func (v SSHActionView) OnRecordingFailure() views.ValuePointer[SSHRecorderFailureAction] {
  1844. return views.ValuePointerOf(v.ж.OnRecordingFailure)
  1845. }
  1846. // A compilation failure here means this code must be regenerated, with the command at the top of this file.
  1847. var _SSHActionViewNeedsRegeneration = SSHAction(struct {
  1848. Message string
  1849. Reject bool
  1850. Accept bool
  1851. SessionDuration time.Duration
  1852. AllowAgentForwarding bool
  1853. HoldAndDelegate string
  1854. AllowLocalPortForwarding bool
  1855. AllowRemotePortForwarding bool
  1856. Recorders []netip.AddrPort
  1857. OnRecordingFailure *SSHRecorderFailureAction
  1858. }{})
  1859. // View returns a read-only view of SSHPrincipal.
  1860. func (p *SSHPrincipal) View() SSHPrincipalView {
  1861. return SSHPrincipalView{ж: p}
  1862. }
  1863. // SSHPrincipalView provides a read-only view over SSHPrincipal.
  1864. //
  1865. // Its methods should only be called if `Valid()` returns true.
  1866. type SSHPrincipalView struct {
  1867. // ж is the underlying mutable value, named with a hard-to-type
  1868. // character that looks pointy like a pointer.
  1869. // It is named distinctively to make you think of how dangerous it is to escape
  1870. // to callers. You must not let callers be able to mutate it.
  1871. ж *SSHPrincipal
  1872. }
  1873. // Valid reports whether v's underlying value is non-nil.
  1874. func (v SSHPrincipalView) Valid() bool { return v.ж != nil }
  1875. // AsStruct returns a clone of the underlying value which aliases no memory with
  1876. // the original.
  1877. func (v SSHPrincipalView) AsStruct() *SSHPrincipal {
  1878. if v.ж == nil {
  1879. return nil
  1880. }
  1881. return v.ж.Clone()
  1882. }
  1883. // MarshalJSON implements [jsonv1.Marshaler].
  1884. func (v SSHPrincipalView) MarshalJSON() ([]byte, error) {
  1885. return jsonv1.Marshal(v.ж)
  1886. }
  1887. // MarshalJSONTo implements [jsonv2.MarshalerTo].
  1888. func (v SSHPrincipalView) MarshalJSONTo(enc *jsontext.Encoder) error {
  1889. return jsonv2.MarshalEncode(enc, v.ж)
  1890. }
  1891. // UnmarshalJSON implements [jsonv1.Unmarshaler].
  1892. func (v *SSHPrincipalView) UnmarshalJSON(b []byte) error {
  1893. if v.ж != nil {
  1894. return errors.New("already initialized")
  1895. }
  1896. if len(b) == 0 {
  1897. return nil
  1898. }
  1899. var x SSHPrincipal
  1900. if err := jsonv1.Unmarshal(b, &x); err != nil {
  1901. return err
  1902. }
  1903. v.ж = &x
  1904. return nil
  1905. }
  1906. // UnmarshalJSONFrom implements [jsonv2.UnmarshalerFrom].
  1907. func (v *SSHPrincipalView) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
  1908. if v.ж != nil {
  1909. return errors.New("already initialized")
  1910. }
  1911. var x SSHPrincipal
  1912. if err := jsonv2.UnmarshalDecode(dec, &x); err != nil {
  1913. return err
  1914. }
  1915. v.ж = &x
  1916. return nil
  1917. }
  1918. func (v SSHPrincipalView) Node() StableNodeID { return v.ж.Node }
  1919. func (v SSHPrincipalView) NodeIP() string { return v.ж.NodeIP }
  1920. // email-ish: [email protected], bar@github
  1921. func (v SSHPrincipalView) UserLogin() string { return v.ж.UserLogin }
  1922. // if true, match any connection
  1923. func (v SSHPrincipalView) Any() bool { return v.ж.Any }
  1924. // UnusedPubKeys was public key support. It never became an official product
  1925. // feature and so as of 2024-12-12 is being removed.
  1926. // This stub exists to remind us not to re-use the JSON field name "pubKeys"
  1927. // in the future if we bring it back with different semantics.
  1928. //
  1929. // Deprecated: do not use. It does nothing.
  1930. func (v SSHPrincipalView) UnusedPubKeys() views.Slice[string] {
  1931. return views.SliceOf(v.ж.UnusedPubKeys)
  1932. }
  1933. // A compilation failure here means this code must be regenerated, with the command at the top of this file.
  1934. var _SSHPrincipalViewNeedsRegeneration = SSHPrincipal(struct {
  1935. Node StableNodeID
  1936. NodeIP string
  1937. UserLogin string
  1938. Any bool
  1939. UnusedPubKeys []string
  1940. }{})
  1941. // View returns a read-only view of ControlDialPlan.
  1942. func (p *ControlDialPlan) View() ControlDialPlanView {
  1943. return ControlDialPlanView{ж: p}
  1944. }
  1945. // ControlDialPlanView provides a read-only view over ControlDialPlan.
  1946. //
  1947. // Its methods should only be called if `Valid()` returns true.
  1948. type ControlDialPlanView struct {
  1949. // ж is the underlying mutable value, named with a hard-to-type
  1950. // character that looks pointy like a pointer.
  1951. // It is named distinctively to make you think of how dangerous it is to escape
  1952. // to callers. You must not let callers be able to mutate it.
  1953. ж *ControlDialPlan
  1954. }
  1955. // Valid reports whether v's underlying value is non-nil.
  1956. func (v ControlDialPlanView) Valid() bool { return v.ж != nil }
  1957. // AsStruct returns a clone of the underlying value which aliases no memory with
  1958. // the original.
  1959. func (v ControlDialPlanView) AsStruct() *ControlDialPlan {
  1960. if v.ж == nil {
  1961. return nil
  1962. }
  1963. return v.ж.Clone()
  1964. }
  1965. // MarshalJSON implements [jsonv1.Marshaler].
  1966. func (v ControlDialPlanView) MarshalJSON() ([]byte, error) {
  1967. return jsonv1.Marshal(v.ж)
  1968. }
  1969. // MarshalJSONTo implements [jsonv2.MarshalerTo].
  1970. func (v ControlDialPlanView) MarshalJSONTo(enc *jsontext.Encoder) error {
  1971. return jsonv2.MarshalEncode(enc, v.ж)
  1972. }
  1973. // UnmarshalJSON implements [jsonv1.Unmarshaler].
  1974. func (v *ControlDialPlanView) UnmarshalJSON(b []byte) error {
  1975. if v.ж != nil {
  1976. return errors.New("already initialized")
  1977. }
  1978. if len(b) == 0 {
  1979. return nil
  1980. }
  1981. var x ControlDialPlan
  1982. if err := jsonv1.Unmarshal(b, &x); err != nil {
  1983. return err
  1984. }
  1985. v.ж = &x
  1986. return nil
  1987. }
  1988. // UnmarshalJSONFrom implements [jsonv2.UnmarshalerFrom].
  1989. func (v *ControlDialPlanView) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
  1990. if v.ж != nil {
  1991. return errors.New("already initialized")
  1992. }
  1993. var x ControlDialPlan
  1994. if err := jsonv2.UnmarshalDecode(dec, &x); err != nil {
  1995. return err
  1996. }
  1997. v.ж = &x
  1998. return nil
  1999. }
  2000. // An empty list means the default: use DNS (unspecified which DNS).
  2001. func (v ControlDialPlanView) Candidates() views.Slice[ControlIPCandidate] {
  2002. return views.SliceOf(v.ж.Candidates)
  2003. }
  2004. // A compilation failure here means this code must be regenerated, with the command at the top of this file.
  2005. var _ControlDialPlanViewNeedsRegeneration = ControlDialPlan(struct {
  2006. Candidates []ControlIPCandidate
  2007. }{})
  2008. // View returns a read-only view of Location.
  2009. func (p *Location) View() LocationView {
  2010. return LocationView{ж: p}
  2011. }
  2012. // LocationView provides a read-only view over Location.
  2013. //
  2014. // Its methods should only be called if `Valid()` returns true.
  2015. type LocationView struct {
  2016. // ж is the underlying mutable value, named with a hard-to-type
  2017. // character that looks pointy like a pointer.
  2018. // It is named distinctively to make you think of how dangerous it is to escape
  2019. // to callers. You must not let callers be able to mutate it.
  2020. ж *Location
  2021. }
  2022. // Valid reports whether v's underlying value is non-nil.
  2023. func (v LocationView) Valid() bool { return v.ж != nil }
  2024. // AsStruct returns a clone of the underlying value which aliases no memory with
  2025. // the original.
  2026. func (v LocationView) AsStruct() *Location {
  2027. if v.ж == nil {
  2028. return nil
  2029. }
  2030. return v.ж.Clone()
  2031. }
  2032. // MarshalJSON implements [jsonv1.Marshaler].
  2033. func (v LocationView) MarshalJSON() ([]byte, error) {
  2034. return jsonv1.Marshal(v.ж)
  2035. }
  2036. // MarshalJSONTo implements [jsonv2.MarshalerTo].
  2037. func (v LocationView) MarshalJSONTo(enc *jsontext.Encoder) error {
  2038. return jsonv2.MarshalEncode(enc, v.ж)
  2039. }
  2040. // UnmarshalJSON implements [jsonv1.Unmarshaler].
  2041. func (v *LocationView) UnmarshalJSON(b []byte) error {
  2042. if v.ж != nil {
  2043. return errors.New("already initialized")
  2044. }
  2045. if len(b) == 0 {
  2046. return nil
  2047. }
  2048. var x Location
  2049. if err := jsonv1.Unmarshal(b, &x); err != nil {
  2050. return err
  2051. }
  2052. v.ж = &x
  2053. return nil
  2054. }
  2055. // UnmarshalJSONFrom implements [jsonv2.UnmarshalerFrom].
  2056. func (v *LocationView) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
  2057. if v.ж != nil {
  2058. return errors.New("already initialized")
  2059. }
  2060. var x Location
  2061. if err := jsonv2.UnmarshalDecode(dec, &x); err != nil {
  2062. return err
  2063. }
  2064. v.ж = &x
  2065. return nil
  2066. }
  2067. // User friendly country name, with proper capitalization ("Canada")
  2068. func (v LocationView) Country() string { return v.ж.Country }
  2069. // ISO 3166-1 alpha-2 in upper case ("CA")
  2070. func (v LocationView) CountryCode() string { return v.ж.CountryCode }
  2071. // User friendly city name, with proper capitalization ("Squamish")
  2072. func (v LocationView) City() string { return v.ж.City }
  2073. // CityCode is a short code representing the city in upper case.
  2074. // CityCode is used to disambiguate a city from another location
  2075. // with the same city name. It uniquely identifies a particular
  2076. // geographical location, within the tailnet.
  2077. // IATA, ICAO or ISO 3166-2 codes are recommended ("YSE")
  2078. func (v LocationView) CityCode() string { return v.ж.CityCode }
  2079. // Latitude, Longitude are optional geographical coordinates of the node, in degrees.
  2080. // No particular accuracy level is promised; the coordinates may simply be the center of the city or country.
  2081. func (v LocationView) Latitude() float64 { return v.ж.Latitude }
  2082. func (v LocationView) Longitude() float64 { return v.ж.Longitude }
  2083. // Priority determines the order of use of an exit node when a
  2084. // location based preference matches more than one exit node,
  2085. // the node with the highest priority wins. Nodes of equal
  2086. // probability may be selected arbitrarily.
  2087. //
  2088. // A value of 0 means the exit node does not have a priority
  2089. // preference. A negative int is not allowed.
  2090. func (v LocationView) Priority() int { return v.ж.Priority }
  2091. // A compilation failure here means this code must be regenerated, with the command at the top of this file.
  2092. var _LocationViewNeedsRegeneration = Location(struct {
  2093. Country string
  2094. CountryCode string
  2095. City string
  2096. CityCode string
  2097. Latitude float64
  2098. Longitude float64
  2099. Priority int
  2100. }{})
  2101. // View returns a read-only view of UserProfile.
  2102. func (p *UserProfile) View() UserProfileView {
  2103. return UserProfileView{ж: p}
  2104. }
  2105. // UserProfileView provides a read-only view over UserProfile.
  2106. //
  2107. // Its methods should only be called if `Valid()` returns true.
  2108. type UserProfileView struct {
  2109. // ж is the underlying mutable value, named with a hard-to-type
  2110. // character that looks pointy like a pointer.
  2111. // It is named distinctively to make you think of how dangerous it is to escape
  2112. // to callers. You must not let callers be able to mutate it.
  2113. ж *UserProfile
  2114. }
  2115. // Valid reports whether v's underlying value is non-nil.
  2116. func (v UserProfileView) Valid() bool { return v.ж != nil }
  2117. // AsStruct returns a clone of the underlying value which aliases no memory with
  2118. // the original.
  2119. func (v UserProfileView) AsStruct() *UserProfile {
  2120. if v.ж == nil {
  2121. return nil
  2122. }
  2123. return v.ж.Clone()
  2124. }
  2125. // MarshalJSON implements [jsonv1.Marshaler].
  2126. func (v UserProfileView) MarshalJSON() ([]byte, error) {
  2127. return jsonv1.Marshal(v.ж)
  2128. }
  2129. // MarshalJSONTo implements [jsonv2.MarshalerTo].
  2130. func (v UserProfileView) MarshalJSONTo(enc *jsontext.Encoder) error {
  2131. return jsonv2.MarshalEncode(enc, v.ж)
  2132. }
  2133. // UnmarshalJSON implements [jsonv1.Unmarshaler].
  2134. func (v *UserProfileView) UnmarshalJSON(b []byte) error {
  2135. if v.ж != nil {
  2136. return errors.New("already initialized")
  2137. }
  2138. if len(b) == 0 {
  2139. return nil
  2140. }
  2141. var x UserProfile
  2142. if err := jsonv1.Unmarshal(b, &x); err != nil {
  2143. return err
  2144. }
  2145. v.ж = &x
  2146. return nil
  2147. }
  2148. // UnmarshalJSONFrom implements [jsonv2.UnmarshalerFrom].
  2149. func (v *UserProfileView) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
  2150. if v.ж != nil {
  2151. return errors.New("already initialized")
  2152. }
  2153. var x UserProfile
  2154. if err := jsonv2.UnmarshalDecode(dec, &x); err != nil {
  2155. return err
  2156. }
  2157. v.ж = &x
  2158. return nil
  2159. }
  2160. func (v UserProfileView) ID() UserID { return v.ж.ID }
  2161. // "[email protected]"; for display purposes only (provider is not listed)
  2162. func (v UserProfileView) LoginName() string { return v.ж.LoginName }
  2163. // "Alice Smith"
  2164. func (v UserProfileView) DisplayName() string { return v.ж.DisplayName }
  2165. func (v UserProfileView) ProfilePicURL() string { return v.ж.ProfilePicURL }
  2166. func (v UserProfileView) Equal(v2 UserProfileView) bool { return v.ж.Equal(v2.ж) }
  2167. // A compilation failure here means this code must be regenerated, with the command at the top of this file.
  2168. var _UserProfileViewNeedsRegeneration = UserProfile(struct {
  2169. ID UserID
  2170. LoginName string
  2171. DisplayName string
  2172. ProfilePicURL string
  2173. }{})
  2174. // View returns a read-only view of VIPService.
  2175. func (p *VIPService) View() VIPServiceView {
  2176. return VIPServiceView{ж: p}
  2177. }
  2178. // VIPServiceView provides a read-only view over VIPService.
  2179. //
  2180. // Its methods should only be called if `Valid()` returns true.
  2181. type VIPServiceView struct {
  2182. // ж is the underlying mutable value, named with a hard-to-type
  2183. // character that looks pointy like a pointer.
  2184. // It is named distinctively to make you think of how dangerous it is to escape
  2185. // to callers. You must not let callers be able to mutate it.
  2186. ж *VIPService
  2187. }
  2188. // Valid reports whether v's underlying value is non-nil.
  2189. func (v VIPServiceView) Valid() bool { return v.ж != nil }
  2190. // AsStruct returns a clone of the underlying value which aliases no memory with
  2191. // the original.
  2192. func (v VIPServiceView) AsStruct() *VIPService {
  2193. if v.ж == nil {
  2194. return nil
  2195. }
  2196. return v.ж.Clone()
  2197. }
  2198. // MarshalJSON implements [jsonv1.Marshaler].
  2199. func (v VIPServiceView) MarshalJSON() ([]byte, error) {
  2200. return jsonv1.Marshal(v.ж)
  2201. }
  2202. // MarshalJSONTo implements [jsonv2.MarshalerTo].
  2203. func (v VIPServiceView) MarshalJSONTo(enc *jsontext.Encoder) error {
  2204. return jsonv2.MarshalEncode(enc, v.ж)
  2205. }
  2206. // UnmarshalJSON implements [jsonv1.Unmarshaler].
  2207. func (v *VIPServiceView) UnmarshalJSON(b []byte) error {
  2208. if v.ж != nil {
  2209. return errors.New("already initialized")
  2210. }
  2211. if len(b) == 0 {
  2212. return nil
  2213. }
  2214. var x VIPService
  2215. if err := jsonv1.Unmarshal(b, &x); err != nil {
  2216. return err
  2217. }
  2218. v.ж = &x
  2219. return nil
  2220. }
  2221. // UnmarshalJSONFrom implements [jsonv2.UnmarshalerFrom].
  2222. func (v *VIPServiceView) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
  2223. if v.ж != nil {
  2224. return errors.New("already initialized")
  2225. }
  2226. var x VIPService
  2227. if err := jsonv2.UnmarshalDecode(dec, &x); err != nil {
  2228. return err
  2229. }
  2230. v.ж = &x
  2231. return nil
  2232. }
  2233. // Name is the name of the service. The Name uniquely identifies a service
  2234. // on a particular tailnet, and so also corresponds uniquely to the pair of
  2235. // IP addresses belonging to the VIP service.
  2236. func (v VIPServiceView) Name() ServiceName { return v.ж.Name }
  2237. // Ports specify which ProtoPorts are made available by this node
  2238. // on the service's IPs.
  2239. func (v VIPServiceView) Ports() views.Slice[ProtoPortRange] { return views.SliceOf(v.ж.Ports) }
  2240. // Active specifies whether new requests for the service should be
  2241. // sent to this node by control.
  2242. func (v VIPServiceView) Active() bool { return v.ж.Active }
  2243. // A compilation failure here means this code must be regenerated, with the command at the top of this file.
  2244. var _VIPServiceViewNeedsRegeneration = VIPService(struct {
  2245. Name ServiceName
  2246. Ports []ProtoPortRange
  2247. Active bool
  2248. }{})
  2249. // View returns a read-only view of SSHPolicy.
  2250. func (p *SSHPolicy) View() SSHPolicyView {
  2251. return SSHPolicyView{ж: p}
  2252. }
  2253. // SSHPolicyView provides a read-only view over SSHPolicy.
  2254. //
  2255. // Its methods should only be called if `Valid()` returns true.
  2256. type SSHPolicyView struct {
  2257. // ж is the underlying mutable value, named with a hard-to-type
  2258. // character that looks pointy like a pointer.
  2259. // It is named distinctively to make you think of how dangerous it is to escape
  2260. // to callers. You must not let callers be able to mutate it.
  2261. ж *SSHPolicy
  2262. }
  2263. // Valid reports whether v's underlying value is non-nil.
  2264. func (v SSHPolicyView) Valid() bool { return v.ж != nil }
  2265. // AsStruct returns a clone of the underlying value which aliases no memory with
  2266. // the original.
  2267. func (v SSHPolicyView) AsStruct() *SSHPolicy {
  2268. if v.ж == nil {
  2269. return nil
  2270. }
  2271. return v.ж.Clone()
  2272. }
  2273. // MarshalJSON implements [jsonv1.Marshaler].
  2274. func (v SSHPolicyView) MarshalJSON() ([]byte, error) {
  2275. return jsonv1.Marshal(v.ж)
  2276. }
  2277. // MarshalJSONTo implements [jsonv2.MarshalerTo].
  2278. func (v SSHPolicyView) MarshalJSONTo(enc *jsontext.Encoder) error {
  2279. return jsonv2.MarshalEncode(enc, v.ж)
  2280. }
  2281. // UnmarshalJSON implements [jsonv1.Unmarshaler].
  2282. func (v *SSHPolicyView) UnmarshalJSON(b []byte) error {
  2283. if v.ж != nil {
  2284. return errors.New("already initialized")
  2285. }
  2286. if len(b) == 0 {
  2287. return nil
  2288. }
  2289. var x SSHPolicy
  2290. if err := jsonv1.Unmarshal(b, &x); err != nil {
  2291. return err
  2292. }
  2293. v.ж = &x
  2294. return nil
  2295. }
  2296. // UnmarshalJSONFrom implements [jsonv2.UnmarshalerFrom].
  2297. func (v *SSHPolicyView) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
  2298. if v.ж != nil {
  2299. return errors.New("already initialized")
  2300. }
  2301. var x SSHPolicy
  2302. if err := jsonv2.UnmarshalDecode(dec, &x); err != nil {
  2303. return err
  2304. }
  2305. v.ж = &x
  2306. return nil
  2307. }
  2308. // Rules are the rules to process for an incoming SSH connection. The first
  2309. // matching rule takes its action and stops processing further rules.
  2310. //
  2311. // When an incoming connection first starts, all rules are evaluated in
  2312. // "none" auth mode, where the client hasn't even been asked to send a
  2313. // public key. All SSHRule.Principals requiring a public key won't match. If
  2314. // a rule matches on the first pass and its Action is reject, the
  2315. // authentication fails with that action's rejection message, if any.
  2316. //
  2317. // If the first pass rule evaluation matches nothing without matching an
  2318. // Action with Reject set, the rules are considered to see whether public
  2319. // keys might still result in a match. If not, "none" auth is terminated
  2320. // before proceeding to public key mode. If so, the client is asked to try
  2321. // public key authentication and the rules are evaluated again for each of
  2322. // the client's present keys.
  2323. func (v SSHPolicyView) Rules() views.SliceView[*SSHRule, SSHRuleView] {
  2324. return views.SliceOfViews[*SSHRule, SSHRuleView](v.ж.Rules)
  2325. }
  2326. // A compilation failure here means this code must be regenerated, with the command at the top of this file.
  2327. var _SSHPolicyViewNeedsRegeneration = SSHPolicy(struct {
  2328. Rules []*SSHRule
  2329. }{})