tailcfg_view.go 91 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692
  1. // Copyright (c) Tailscale Inc & AUTHORS
  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. // the client’s selected exit node, empty when unselected.
  512. func (v HostinfoView) ExitNodeID() StableNodeID { return v.ж.ExitNodeID }
  513. // Location represents geographical location data about a
  514. // Tailscale host. Location is optional and only set if
  515. // explicitly declared by a node.
  516. func (v HostinfoView) Location() LocationView { return v.ж.Location.View() }
  517. // TPM device metadata, if available
  518. func (v HostinfoView) TPM() views.ValuePointer[TPMInfo] { return views.ValuePointerOf(v.ж.TPM) }
  519. // StateEncrypted reports whether the node state is stored encrypted on
  520. // disk. The actual mechanism is platform-specific:
  521. // - Apple nodes use the Keychain
  522. // - Linux and Windows nodes use the TPM
  523. // - Android apps use EncryptedSharedPreferences
  524. func (v HostinfoView) StateEncrypted() opt.Bool { return v.ж.StateEncrypted }
  525. func (v HostinfoView) Equal(v2 HostinfoView) bool { return v.ж.Equal(v2.ж) }
  526. // A compilation failure here means this code must be regenerated, with the command at the top of this file.
  527. var _HostinfoViewNeedsRegeneration = Hostinfo(struct {
  528. IPNVersion string
  529. FrontendLogID string
  530. BackendLogID string
  531. OS string
  532. OSVersion string
  533. Container opt.Bool
  534. Env string
  535. Distro string
  536. DistroVersion string
  537. DistroCodeName string
  538. App string
  539. Desktop opt.Bool
  540. Package string
  541. DeviceModel string
  542. PushDeviceToken string
  543. Hostname string
  544. ShieldsUp bool
  545. ShareeNode bool
  546. NoLogsNoSupport bool
  547. WireIngress bool
  548. IngressEnabled bool
  549. AllowsUpdate bool
  550. Machine string
  551. GoArch string
  552. GoArchVar string
  553. GoVersion string
  554. RoutableIPs []netip.Prefix
  555. RequestTags []string
  556. WoLMACs []string
  557. Services []Service
  558. NetInfo *NetInfo
  559. SSH_HostKeys []string
  560. Cloud string
  561. Userspace opt.Bool
  562. UserspaceRouter opt.Bool
  563. AppConnector opt.Bool
  564. ServicesHash string
  565. ExitNodeID StableNodeID
  566. Location *Location
  567. TPM *TPMInfo
  568. StateEncrypted opt.Bool
  569. }{})
  570. // View returns a read-only view of NetInfo.
  571. func (p *NetInfo) View() NetInfoView {
  572. return NetInfoView{ж: p}
  573. }
  574. // NetInfoView provides a read-only view over NetInfo.
  575. //
  576. // Its methods should only be called if `Valid()` returns true.
  577. type NetInfoView struct {
  578. // ж is the underlying mutable value, named with a hard-to-type
  579. // character that looks pointy like a pointer.
  580. // It is named distinctively to make you think of how dangerous it is to escape
  581. // to callers. You must not let callers be able to mutate it.
  582. ж *NetInfo
  583. }
  584. // Valid reports whether v's underlying value is non-nil.
  585. func (v NetInfoView) Valid() bool { return v.ж != nil }
  586. // AsStruct returns a clone of the underlying value which aliases no memory with
  587. // the original.
  588. func (v NetInfoView) AsStruct() *NetInfo {
  589. if v.ж == nil {
  590. return nil
  591. }
  592. return v.ж.Clone()
  593. }
  594. // MarshalJSON implements [jsonv1.Marshaler].
  595. func (v NetInfoView) MarshalJSON() ([]byte, error) {
  596. return jsonv1.Marshal(v.ж)
  597. }
  598. // MarshalJSONTo implements [jsonv2.MarshalerTo].
  599. func (v NetInfoView) MarshalJSONTo(enc *jsontext.Encoder) error {
  600. return jsonv2.MarshalEncode(enc, v.ж)
  601. }
  602. // UnmarshalJSON implements [jsonv1.Unmarshaler].
  603. func (v *NetInfoView) UnmarshalJSON(b []byte) error {
  604. if v.ж != nil {
  605. return errors.New("already initialized")
  606. }
  607. if len(b) == 0 {
  608. return nil
  609. }
  610. var x NetInfo
  611. if err := jsonv1.Unmarshal(b, &x); err != nil {
  612. return err
  613. }
  614. v.ж = &x
  615. return nil
  616. }
  617. // UnmarshalJSONFrom implements [jsonv2.UnmarshalerFrom].
  618. func (v *NetInfoView) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
  619. if v.ж != nil {
  620. return errors.New("already initialized")
  621. }
  622. var x NetInfo
  623. if err := jsonv2.UnmarshalDecode(dec, &x); err != nil {
  624. return err
  625. }
  626. v.ж = &x
  627. return nil
  628. }
  629. // MappingVariesByDestIP says whether the host's NAT mappings
  630. // vary based on the destination IP.
  631. func (v NetInfoView) MappingVariesByDestIP() opt.Bool { return v.ж.MappingVariesByDestIP }
  632. // WorkingIPv6 is whether the host has IPv6 internet connectivity.
  633. func (v NetInfoView) WorkingIPv6() opt.Bool { return v.ж.WorkingIPv6 }
  634. // OSHasIPv6 is whether the OS supports IPv6 at all, regardless of
  635. // whether IPv6 internet connectivity is available.
  636. func (v NetInfoView) OSHasIPv6() opt.Bool { return v.ж.OSHasIPv6 }
  637. // WorkingUDP is whether the host has UDP internet connectivity.
  638. func (v NetInfoView) WorkingUDP() opt.Bool { return v.ж.WorkingUDP }
  639. // WorkingICMPv4 is whether ICMPv4 works.
  640. // Empty means not checked.
  641. func (v NetInfoView) WorkingICMPv4() opt.Bool { return v.ж.WorkingICMPv4 }
  642. // HavePortMap is whether we have an existing portmap open
  643. // (UPnP, PMP, or PCP).
  644. func (v NetInfoView) HavePortMap() bool { return v.ж.HavePortMap }
  645. // UPnP is whether UPnP appears present on the LAN.
  646. // Empty means not checked.
  647. func (v NetInfoView) UPnP() opt.Bool { return v.ж.UPnP }
  648. // PMP is whether NAT-PMP appears present on the LAN.
  649. // Empty means not checked.
  650. func (v NetInfoView) PMP() opt.Bool { return v.ж.PMP }
  651. // PCP is whether PCP appears present on the LAN.
  652. // Empty means not checked.
  653. func (v NetInfoView) PCP() opt.Bool { return v.ж.PCP }
  654. // PreferredDERP is this node's preferred (home) DERP region ID.
  655. // This is where the node expects to be contacted to begin a
  656. // peer-to-peer connection. The node might be be temporarily
  657. // connected to multiple DERP servers (to speak to other nodes
  658. // that are located elsewhere) but PreferredDERP is the region ID
  659. // that the node subscribes to traffic at.
  660. // Zero means disconnected or unknown.
  661. func (v NetInfoView) PreferredDERP() int { return v.ж.PreferredDERP }
  662. // LinkType is the current link type, if known.
  663. func (v NetInfoView) LinkType() string { return v.ж.LinkType }
  664. // DERPLatency is the fastest recent time to reach various
  665. // DERP STUN servers, in seconds. The map key is the
  666. // "regionID-v4" or "-v6"; it was previously the DERP server's
  667. // STUN host:port.
  668. //
  669. // This should only be updated rarely, or when there's a
  670. // material change, as any change here also gets uploaded to
  671. // the control plane.
  672. func (v NetInfoView) DERPLatency() views.Map[string, float64] { return views.MapOf(v.ж.DERPLatency) }
  673. // FirewallMode encodes both which firewall mode was selected and why.
  674. // It is Linux-specific (at least as of 2023-08-19) and is meant to help
  675. // debug iptables-vs-nftables issues. The string is of the form
  676. // "{nft,ift}-REASON", like "nft-forced" or "ipt-default". Empty means
  677. // either not Linux or a configuration in which the host firewall rules
  678. // are not managed by tailscaled.
  679. func (v NetInfoView) FirewallMode() string { return v.ж.FirewallMode }
  680. func (v NetInfoView) String() string { return v.ж.String() }
  681. // A compilation failure here means this code must be regenerated, with the command at the top of this file.
  682. var _NetInfoViewNeedsRegeneration = NetInfo(struct {
  683. MappingVariesByDestIP opt.Bool
  684. WorkingIPv6 opt.Bool
  685. OSHasIPv6 opt.Bool
  686. WorkingUDP opt.Bool
  687. WorkingICMPv4 opt.Bool
  688. HavePortMap bool
  689. UPnP opt.Bool
  690. PMP opt.Bool
  691. PCP opt.Bool
  692. PreferredDERP int
  693. LinkType string
  694. DERPLatency map[string]float64
  695. FirewallMode string
  696. }{})
  697. // View returns a read-only view of Login.
  698. func (p *Login) View() LoginView {
  699. return LoginView{ж: p}
  700. }
  701. // LoginView provides a read-only view over Login.
  702. //
  703. // Its methods should only be called if `Valid()` returns true.
  704. type LoginView struct {
  705. // ж is the underlying mutable value, named with a hard-to-type
  706. // character that looks pointy like a pointer.
  707. // It is named distinctively to make you think of how dangerous it is to escape
  708. // to callers. You must not let callers be able to mutate it.
  709. ж *Login
  710. }
  711. // Valid reports whether v's underlying value is non-nil.
  712. func (v LoginView) Valid() bool { return v.ж != nil }
  713. // AsStruct returns a clone of the underlying value which aliases no memory with
  714. // the original.
  715. func (v LoginView) AsStruct() *Login {
  716. if v.ж == nil {
  717. return nil
  718. }
  719. return v.ж.Clone()
  720. }
  721. // MarshalJSON implements [jsonv1.Marshaler].
  722. func (v LoginView) MarshalJSON() ([]byte, error) {
  723. return jsonv1.Marshal(v.ж)
  724. }
  725. // MarshalJSONTo implements [jsonv2.MarshalerTo].
  726. func (v LoginView) MarshalJSONTo(enc *jsontext.Encoder) error {
  727. return jsonv2.MarshalEncode(enc, v.ж)
  728. }
  729. // UnmarshalJSON implements [jsonv1.Unmarshaler].
  730. func (v *LoginView) UnmarshalJSON(b []byte) error {
  731. if v.ж != nil {
  732. return errors.New("already initialized")
  733. }
  734. if len(b) == 0 {
  735. return nil
  736. }
  737. var x Login
  738. if err := jsonv1.Unmarshal(b, &x); err != nil {
  739. return err
  740. }
  741. v.ж = &x
  742. return nil
  743. }
  744. // UnmarshalJSONFrom implements [jsonv2.UnmarshalerFrom].
  745. func (v *LoginView) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
  746. if v.ж != nil {
  747. return errors.New("already initialized")
  748. }
  749. var x Login
  750. if err := jsonv2.UnmarshalDecode(dec, &x); err != nil {
  751. return err
  752. }
  753. v.ж = &x
  754. return nil
  755. }
  756. // unused in the Tailscale client
  757. func (v LoginView) ID() LoginID { return v.ж.ID }
  758. // "google", "github", "okta_foo", etc.
  759. func (v LoginView) Provider() string { return v.ж.Provider }
  760. // an email address or "email-ish" string (like alice@github)
  761. func (v LoginView) LoginName() string { return v.ж.LoginName }
  762. // from the IdP
  763. func (v LoginView) DisplayName() string { return v.ж.DisplayName }
  764. // from the IdP
  765. func (v LoginView) ProfilePicURL() string { return v.ж.ProfilePicURL }
  766. // A compilation failure here means this code must be regenerated, with the command at the top of this file.
  767. var _LoginViewNeedsRegeneration = Login(struct {
  768. _ structs.Incomparable
  769. ID LoginID
  770. Provider string
  771. LoginName string
  772. DisplayName string
  773. ProfilePicURL string
  774. }{})
  775. // View returns a read-only view of DNSConfig.
  776. func (p *DNSConfig) View() DNSConfigView {
  777. return DNSConfigView{ж: p}
  778. }
  779. // DNSConfigView provides a read-only view over DNSConfig.
  780. //
  781. // Its methods should only be called if `Valid()` returns true.
  782. type DNSConfigView struct {
  783. // ж is the underlying mutable value, named with a hard-to-type
  784. // character that looks pointy like a pointer.
  785. // It is named distinctively to make you think of how dangerous it is to escape
  786. // to callers. You must not let callers be able to mutate it.
  787. ж *DNSConfig
  788. }
  789. // Valid reports whether v's underlying value is non-nil.
  790. func (v DNSConfigView) Valid() bool { return v.ж != nil }
  791. // AsStruct returns a clone of the underlying value which aliases no memory with
  792. // the original.
  793. func (v DNSConfigView) AsStruct() *DNSConfig {
  794. if v.ж == nil {
  795. return nil
  796. }
  797. return v.ж.Clone()
  798. }
  799. // MarshalJSON implements [jsonv1.Marshaler].
  800. func (v DNSConfigView) MarshalJSON() ([]byte, error) {
  801. return jsonv1.Marshal(v.ж)
  802. }
  803. // MarshalJSONTo implements [jsonv2.MarshalerTo].
  804. func (v DNSConfigView) MarshalJSONTo(enc *jsontext.Encoder) error {
  805. return jsonv2.MarshalEncode(enc, v.ж)
  806. }
  807. // UnmarshalJSON implements [jsonv1.Unmarshaler].
  808. func (v *DNSConfigView) UnmarshalJSON(b []byte) error {
  809. if v.ж != nil {
  810. return errors.New("already initialized")
  811. }
  812. if len(b) == 0 {
  813. return nil
  814. }
  815. var x DNSConfig
  816. if err := jsonv1.Unmarshal(b, &x); err != nil {
  817. return err
  818. }
  819. v.ж = &x
  820. return nil
  821. }
  822. // UnmarshalJSONFrom implements [jsonv2.UnmarshalerFrom].
  823. func (v *DNSConfigView) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
  824. if v.ж != nil {
  825. return errors.New("already initialized")
  826. }
  827. var x DNSConfig
  828. if err := jsonv2.UnmarshalDecode(dec, &x); err != nil {
  829. return err
  830. }
  831. v.ж = &x
  832. return nil
  833. }
  834. // Resolvers are the DNS resolvers to use, in order of preference.
  835. func (v DNSConfigView) Resolvers() views.SliceView[*dnstype.Resolver, dnstype.ResolverView] {
  836. return views.SliceOfViews[*dnstype.Resolver, dnstype.ResolverView](v.ж.Resolvers)
  837. }
  838. // Routes maps DNS name suffixes to a set of DNS resolvers to
  839. // use. It is used to implement "split DNS" and other advanced DNS
  840. // routing overlays.
  841. //
  842. // Map keys are fully-qualified DNS name suffixes; they may
  843. // optionally contain a trailing dot but no leading dot.
  844. //
  845. // If the value is an empty slice, that means the suffix should still
  846. // be handled by Tailscale's built-in resolver (100.100.100.100), such
  847. // as for the purpose of handling ExtraRecords.
  848. func (v DNSConfigView) Routes() views.MapFn[string, []*dnstype.Resolver, views.SliceView[*dnstype.Resolver, dnstype.ResolverView]] {
  849. return views.MapFnOf(v.ж.Routes, func(t []*dnstype.Resolver) views.SliceView[*dnstype.Resolver, dnstype.ResolverView] {
  850. return views.SliceOfViews[*dnstype.Resolver, dnstype.ResolverView](t)
  851. })
  852. }
  853. // FallbackResolvers is like Resolvers, but is only used if a
  854. // split DNS configuration is requested in a configuration that
  855. // doesn't work yet without explicit default resolvers.
  856. // https://github.com/tailscale/tailscale/issues/1743
  857. func (v DNSConfigView) FallbackResolvers() views.SliceView[*dnstype.Resolver, dnstype.ResolverView] {
  858. return views.SliceOfViews[*dnstype.Resolver, dnstype.ResolverView](v.ж.FallbackResolvers)
  859. }
  860. // Domains are the search domains to use.
  861. // Search domains must be FQDNs, but *without* the trailing dot.
  862. func (v DNSConfigView) Domains() views.Slice[string] { return views.SliceOf(v.ж.Domains) }
  863. // Proxied turns on automatic resolution of hostnames for devices
  864. // in the network map, aka MagicDNS.
  865. // Despite the (legacy) name, does not necessarily cause request
  866. // proxying to be enabled.
  867. func (v DNSConfigView) Proxied() bool { return v.ж.Proxied }
  868. // Nameservers are the IP addresses of the global nameservers to use.
  869. //
  870. // Deprecated: this is only set and used by MapRequest.Version >=9 and <14. Use Resolvers instead.
  871. func (v DNSConfigView) Nameservers() views.Slice[netip.Addr] { return views.SliceOf(v.ж.Nameservers) }
  872. // CertDomains are the set of DNS names for which the control
  873. // plane server will assist with provisioning TLS
  874. // certificates. See SetDNSRequest, which can be used to
  875. // answer dns-01 ACME challenges for e.g. LetsEncrypt.
  876. // These names are FQDNs without trailing periods, and without
  877. // any "_acme-challenge." prefix.
  878. func (v DNSConfigView) CertDomains() views.Slice[string] { return views.SliceOf(v.ж.CertDomains) }
  879. // ExtraRecords contains extra DNS records to add to the
  880. // MagicDNS config.
  881. func (v DNSConfigView) ExtraRecords() views.Slice[DNSRecord] { return views.SliceOf(v.ж.ExtraRecords) }
  882. // ExitNodeFilteredSuffixes are the DNS suffixes that the
  883. // node, when being an exit node DNS proxy, should not answer.
  884. //
  885. // The entries do not contain trailing periods and are always
  886. // all lowercase.
  887. //
  888. // If an entry starts with a period, it's a suffix match (but
  889. // suffix ".a.b" doesn't match "a.b"; a prefix is required).
  890. //
  891. // If an entry does not start with a period, it's an exact
  892. // match.
  893. //
  894. // Matches are case insensitive.
  895. func (v DNSConfigView) ExitNodeFilteredSet() views.Slice[string] {
  896. return views.SliceOf(v.ж.ExitNodeFilteredSet)
  897. }
  898. // TempCorpIssue13969 is a temporary (2023-08-16) field for an internal hack day prototype.
  899. // It contains a user inputed URL that should have a list of domains to be blocked.
  900. // See https://github.com/tailscale/corp/issues/13969.
  901. func (v DNSConfigView) TempCorpIssue13969() string { return v.ж.TempCorpIssue13969 }
  902. // A compilation failure here means this code must be regenerated, with the command at the top of this file.
  903. var _DNSConfigViewNeedsRegeneration = DNSConfig(struct {
  904. Resolvers []*dnstype.Resolver
  905. Routes map[string][]*dnstype.Resolver
  906. FallbackResolvers []*dnstype.Resolver
  907. Domains []string
  908. Proxied bool
  909. Nameservers []netip.Addr
  910. CertDomains []string
  911. ExtraRecords []DNSRecord
  912. ExitNodeFilteredSet []string
  913. TempCorpIssue13969 string
  914. }{})
  915. // View returns a read-only view of RegisterResponse.
  916. func (p *RegisterResponse) View() RegisterResponseView {
  917. return RegisterResponseView{ж: p}
  918. }
  919. // RegisterResponseView provides a read-only view over RegisterResponse.
  920. //
  921. // Its methods should only be called if `Valid()` returns true.
  922. type RegisterResponseView struct {
  923. // ж is the underlying mutable value, named with a hard-to-type
  924. // character that looks pointy like a pointer.
  925. // It is named distinctively to make you think of how dangerous it is to escape
  926. // to callers. You must not let callers be able to mutate it.
  927. ж *RegisterResponse
  928. }
  929. // Valid reports whether v's underlying value is non-nil.
  930. func (v RegisterResponseView) Valid() bool { return v.ж != nil }
  931. // AsStruct returns a clone of the underlying value which aliases no memory with
  932. // the original.
  933. func (v RegisterResponseView) AsStruct() *RegisterResponse {
  934. if v.ж == nil {
  935. return nil
  936. }
  937. return v.ж.Clone()
  938. }
  939. // MarshalJSON implements [jsonv1.Marshaler].
  940. func (v RegisterResponseView) MarshalJSON() ([]byte, error) {
  941. return jsonv1.Marshal(v.ж)
  942. }
  943. // MarshalJSONTo implements [jsonv2.MarshalerTo].
  944. func (v RegisterResponseView) MarshalJSONTo(enc *jsontext.Encoder) error {
  945. return jsonv2.MarshalEncode(enc, v.ж)
  946. }
  947. // UnmarshalJSON implements [jsonv1.Unmarshaler].
  948. func (v *RegisterResponseView) UnmarshalJSON(b []byte) error {
  949. if v.ж != nil {
  950. return errors.New("already initialized")
  951. }
  952. if len(b) == 0 {
  953. return nil
  954. }
  955. var x RegisterResponse
  956. if err := jsonv1.Unmarshal(b, &x); err != nil {
  957. return err
  958. }
  959. v.ж = &x
  960. return nil
  961. }
  962. // UnmarshalJSONFrom implements [jsonv2.UnmarshalerFrom].
  963. func (v *RegisterResponseView) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
  964. if v.ж != nil {
  965. return errors.New("already initialized")
  966. }
  967. var x RegisterResponse
  968. if err := jsonv2.UnmarshalDecode(dec, &x); err != nil {
  969. return err
  970. }
  971. v.ж = &x
  972. return nil
  973. }
  974. func (v RegisterResponseView) User() User { return v.ж.User }
  975. func (v RegisterResponseView) Login() Login { return v.ж.Login }
  976. // if true, the NodeKey needs to be replaced
  977. func (v RegisterResponseView) NodeKeyExpired() bool { return v.ж.NodeKeyExpired }
  978. // TODO(crawshaw): move to using MachineStatus
  979. func (v RegisterResponseView) MachineAuthorized() bool { return v.ж.MachineAuthorized }
  980. // if set, authorization pending
  981. func (v RegisterResponseView) AuthURL() string { return v.ж.AuthURL }
  982. // If set, this is the current node-key signature that needs to be
  983. // re-signed for the node's new node-key.
  984. func (v RegisterResponseView) NodeKeySignature() views.ByteSlice[tkatype.MarshaledSignature] {
  985. return views.ByteSliceOf(v.ж.NodeKeySignature)
  986. }
  987. // Error indicates that authorization failed. If this is non-empty,
  988. // other status fields should be ignored.
  989. func (v RegisterResponseView) Error() string { return v.ж.Error }
  990. // A compilation failure here means this code must be regenerated, with the command at the top of this file.
  991. var _RegisterResponseViewNeedsRegeneration = RegisterResponse(struct {
  992. User User
  993. Login Login
  994. NodeKeyExpired bool
  995. MachineAuthorized bool
  996. AuthURL string
  997. NodeKeySignature tkatype.MarshaledSignature
  998. Error string
  999. }{})
  1000. // View returns a read-only view of RegisterResponseAuth.
  1001. func (p *RegisterResponseAuth) View() RegisterResponseAuthView {
  1002. return RegisterResponseAuthView{ж: p}
  1003. }
  1004. // RegisterResponseAuthView provides a read-only view over RegisterResponseAuth.
  1005. //
  1006. // Its methods should only be called if `Valid()` returns true.
  1007. type RegisterResponseAuthView struct {
  1008. // ж is the underlying mutable value, named with a hard-to-type
  1009. // character that looks pointy like a pointer.
  1010. // It is named distinctively to make you think of how dangerous it is to escape
  1011. // to callers. You must not let callers be able to mutate it.
  1012. ж *RegisterResponseAuth
  1013. }
  1014. // Valid reports whether v's underlying value is non-nil.
  1015. func (v RegisterResponseAuthView) Valid() bool { return v.ж != nil }
  1016. // AsStruct returns a clone of the underlying value which aliases no memory with
  1017. // the original.
  1018. func (v RegisterResponseAuthView) AsStruct() *RegisterResponseAuth {
  1019. if v.ж == nil {
  1020. return nil
  1021. }
  1022. return v.ж.Clone()
  1023. }
  1024. // MarshalJSON implements [jsonv1.Marshaler].
  1025. func (v RegisterResponseAuthView) MarshalJSON() ([]byte, error) {
  1026. return jsonv1.Marshal(v.ж)
  1027. }
  1028. // MarshalJSONTo implements [jsonv2.MarshalerTo].
  1029. func (v RegisterResponseAuthView) MarshalJSONTo(enc *jsontext.Encoder) error {
  1030. return jsonv2.MarshalEncode(enc, v.ж)
  1031. }
  1032. // UnmarshalJSON implements [jsonv1.Unmarshaler].
  1033. func (v *RegisterResponseAuthView) UnmarshalJSON(b []byte) error {
  1034. if v.ж != nil {
  1035. return errors.New("already initialized")
  1036. }
  1037. if len(b) == 0 {
  1038. return nil
  1039. }
  1040. var x RegisterResponseAuth
  1041. if err := jsonv1.Unmarshal(b, &x); err != nil {
  1042. return err
  1043. }
  1044. v.ж = &x
  1045. return nil
  1046. }
  1047. // UnmarshalJSONFrom implements [jsonv2.UnmarshalerFrom].
  1048. func (v *RegisterResponseAuthView) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
  1049. if v.ж != nil {
  1050. return errors.New("already initialized")
  1051. }
  1052. var x RegisterResponseAuth
  1053. if err := jsonv2.UnmarshalDecode(dec, &x); err != nil {
  1054. return err
  1055. }
  1056. v.ж = &x
  1057. return nil
  1058. }
  1059. // used by pre-1.66 Android only
  1060. func (v RegisterResponseAuthView) Oauth2Token() views.ValuePointer[Oauth2Token] {
  1061. return views.ValuePointerOf(v.ж.Oauth2Token)
  1062. }
  1063. func (v RegisterResponseAuthView) AuthKey() string { return v.ж.AuthKey }
  1064. // A compilation failure here means this code must be regenerated, with the command at the top of this file.
  1065. var _RegisterResponseAuthViewNeedsRegeneration = RegisterResponseAuth(struct {
  1066. _ structs.Incomparable
  1067. Oauth2Token *Oauth2Token
  1068. AuthKey string
  1069. }{})
  1070. // View returns a read-only view of RegisterRequest.
  1071. func (p *RegisterRequest) View() RegisterRequestView {
  1072. return RegisterRequestView{ж: p}
  1073. }
  1074. // RegisterRequestView provides a read-only view over RegisterRequest.
  1075. //
  1076. // Its methods should only be called if `Valid()` returns true.
  1077. type RegisterRequestView struct {
  1078. // ж is the underlying mutable value, named with a hard-to-type
  1079. // character that looks pointy like a pointer.
  1080. // It is named distinctively to make you think of how dangerous it is to escape
  1081. // to callers. You must not let callers be able to mutate it.
  1082. ж *RegisterRequest
  1083. }
  1084. // Valid reports whether v's underlying value is non-nil.
  1085. func (v RegisterRequestView) Valid() bool { return v.ж != nil }
  1086. // AsStruct returns a clone of the underlying value which aliases no memory with
  1087. // the original.
  1088. func (v RegisterRequestView) AsStruct() *RegisterRequest {
  1089. if v.ж == nil {
  1090. return nil
  1091. }
  1092. return v.ж.Clone()
  1093. }
  1094. // MarshalJSON implements [jsonv1.Marshaler].
  1095. func (v RegisterRequestView) MarshalJSON() ([]byte, error) {
  1096. return jsonv1.Marshal(v.ж)
  1097. }
  1098. // MarshalJSONTo implements [jsonv2.MarshalerTo].
  1099. func (v RegisterRequestView) MarshalJSONTo(enc *jsontext.Encoder) error {
  1100. return jsonv2.MarshalEncode(enc, v.ж)
  1101. }
  1102. // UnmarshalJSON implements [jsonv1.Unmarshaler].
  1103. func (v *RegisterRequestView) UnmarshalJSON(b []byte) error {
  1104. if v.ж != nil {
  1105. return errors.New("already initialized")
  1106. }
  1107. if len(b) == 0 {
  1108. return nil
  1109. }
  1110. var x RegisterRequest
  1111. if err := jsonv1.Unmarshal(b, &x); err != nil {
  1112. return err
  1113. }
  1114. v.ж = &x
  1115. return nil
  1116. }
  1117. // UnmarshalJSONFrom implements [jsonv2.UnmarshalerFrom].
  1118. func (v *RegisterRequestView) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
  1119. if v.ж != nil {
  1120. return errors.New("already initialized")
  1121. }
  1122. var x RegisterRequest
  1123. if err := jsonv2.UnmarshalDecode(dec, &x); err != nil {
  1124. return err
  1125. }
  1126. v.ж = &x
  1127. return nil
  1128. }
  1129. // Version is the client's capabilities when using the Noise
  1130. // transport.
  1131. //
  1132. // When using the original nacl crypto_box transport, the
  1133. // value must be 1.
  1134. func (v RegisterRequestView) Version() CapabilityVersion { return v.ж.Version }
  1135. func (v RegisterRequestView) NodeKey() key.NodePublic { return v.ж.NodeKey }
  1136. func (v RegisterRequestView) OldNodeKey() key.NodePublic { return v.ж.OldNodeKey }
  1137. func (v RegisterRequestView) NLKey() key.NLPublic { return v.ж.NLKey }
  1138. func (v RegisterRequestView) Auth() RegisterResponseAuthView { return v.ж.Auth.View() }
  1139. // Expiry optionally specifies the requested key expiry.
  1140. // The server policy may override.
  1141. // As a special case, if Expiry is in the past and NodeKey is
  1142. // the node's current key, the key is expired.
  1143. func (v RegisterRequestView) Expiry() time.Time { return v.ж.Expiry }
  1144. // response waits until AuthURL is visited
  1145. func (v RegisterRequestView) Followup() string { return v.ж.Followup }
  1146. func (v RegisterRequestView) Hostinfo() HostinfoView { return v.ж.Hostinfo.View() }
  1147. // Ephemeral is whether the client is requesting that this
  1148. // node be considered ephemeral and be automatically deleted
  1149. // when it stops being active.
  1150. func (v RegisterRequestView) Ephemeral() bool { return v.ж.Ephemeral }
  1151. // NodeKeySignature is the node's own node-key signature, re-signed
  1152. // for its new node key using its network-lock key.
  1153. //
  1154. // This field is set when the client retries registration after learning
  1155. // its NodeKeySignature (which is in need of rotation).
  1156. func (v RegisterRequestView) NodeKeySignature() views.ByteSlice[tkatype.MarshaledSignature] {
  1157. return views.ByteSliceOf(v.ж.NodeKeySignature)
  1158. }
  1159. // The following fields are not used for SignatureNone and are required for
  1160. // SignatureV1:
  1161. func (v RegisterRequestView) SignatureType() SignatureType { return v.ж.SignatureType }
  1162. // creation time of request to prevent replay
  1163. func (v RegisterRequestView) Timestamp() views.ValuePointer[time.Time] {
  1164. return views.ValuePointerOf(v.ж.Timestamp)
  1165. }
  1166. // X.509 certificate for client device
  1167. func (v RegisterRequestView) DeviceCert() views.ByteSlice[[]byte] {
  1168. return views.ByteSliceOf(v.ж.DeviceCert)
  1169. }
  1170. // as described by SignatureType
  1171. func (v RegisterRequestView) Signature() views.ByteSlice[[]byte] {
  1172. return views.ByteSliceOf(v.ж.Signature)
  1173. }
  1174. // Tailnet is an optional identifier specifying the name of the recommended or required
  1175. // network that the node should join. Its exact form should not be depended on; new
  1176. // forms are coming later. The identifier is generally a domain name (for an organization)
  1177. // or e-mail address (for a personal account on a shared e-mail provider). It is the same name
  1178. // used by the API, as described in /api.md#tailnet.
  1179. // If Tailnet begins with the prefix "required:" then the server should prevent logging in to a different
  1180. // network than the one specified. Otherwise, the server should recommend the specified network
  1181. // but still permit logging in to other networks.
  1182. // If empty, no recommendation is offered to the server and the login page should show all options.
  1183. func (v RegisterRequestView) Tailnet() string { return v.ж.Tailnet }
  1184. // A compilation failure here means this code must be regenerated, with the command at the top of this file.
  1185. var _RegisterRequestViewNeedsRegeneration = RegisterRequest(struct {
  1186. _ structs.Incomparable
  1187. Version CapabilityVersion
  1188. NodeKey key.NodePublic
  1189. OldNodeKey key.NodePublic
  1190. NLKey key.NLPublic
  1191. Auth *RegisterResponseAuth
  1192. Expiry time.Time
  1193. Followup string
  1194. Hostinfo *Hostinfo
  1195. Ephemeral bool
  1196. NodeKeySignature tkatype.MarshaledSignature
  1197. SignatureType SignatureType
  1198. Timestamp *time.Time
  1199. DeviceCert []byte
  1200. Signature []byte
  1201. Tailnet string
  1202. }{})
  1203. // View returns a read-only view of DERPHomeParams.
  1204. func (p *DERPHomeParams) View() DERPHomeParamsView {
  1205. return DERPHomeParamsView{ж: p}
  1206. }
  1207. // DERPHomeParamsView provides a read-only view over DERPHomeParams.
  1208. //
  1209. // Its methods should only be called if `Valid()` returns true.
  1210. type DERPHomeParamsView struct {
  1211. // ж is the underlying mutable value, named with a hard-to-type
  1212. // character that looks pointy like a pointer.
  1213. // It is named distinctively to make you think of how dangerous it is to escape
  1214. // to callers. You must not let callers be able to mutate it.
  1215. ж *DERPHomeParams
  1216. }
  1217. // Valid reports whether v's underlying value is non-nil.
  1218. func (v DERPHomeParamsView) Valid() bool { return v.ж != nil }
  1219. // AsStruct returns a clone of the underlying value which aliases no memory with
  1220. // the original.
  1221. func (v DERPHomeParamsView) AsStruct() *DERPHomeParams {
  1222. if v.ж == nil {
  1223. return nil
  1224. }
  1225. return v.ж.Clone()
  1226. }
  1227. // MarshalJSON implements [jsonv1.Marshaler].
  1228. func (v DERPHomeParamsView) MarshalJSON() ([]byte, error) {
  1229. return jsonv1.Marshal(v.ж)
  1230. }
  1231. // MarshalJSONTo implements [jsonv2.MarshalerTo].
  1232. func (v DERPHomeParamsView) MarshalJSONTo(enc *jsontext.Encoder) error {
  1233. return jsonv2.MarshalEncode(enc, v.ж)
  1234. }
  1235. // UnmarshalJSON implements [jsonv1.Unmarshaler].
  1236. func (v *DERPHomeParamsView) UnmarshalJSON(b []byte) error {
  1237. if v.ж != nil {
  1238. return errors.New("already initialized")
  1239. }
  1240. if len(b) == 0 {
  1241. return nil
  1242. }
  1243. var x DERPHomeParams
  1244. if err := jsonv1.Unmarshal(b, &x); err != nil {
  1245. return err
  1246. }
  1247. v.ж = &x
  1248. return nil
  1249. }
  1250. // UnmarshalJSONFrom implements [jsonv2.UnmarshalerFrom].
  1251. func (v *DERPHomeParamsView) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
  1252. if v.ж != nil {
  1253. return errors.New("already initialized")
  1254. }
  1255. var x DERPHomeParams
  1256. if err := jsonv2.UnmarshalDecode(dec, &x); err != nil {
  1257. return err
  1258. }
  1259. v.ж = &x
  1260. return nil
  1261. }
  1262. // RegionScore scales latencies of DERP regions by a given scaling
  1263. // factor when determining which region to use as the home
  1264. // ("preferred") DERP. Scores in the range (0, 1) will cause this
  1265. // region to be proportionally more preferred, and scores in the range
  1266. // (1, ∞) will penalize a region.
  1267. //
  1268. // If a region is not present in this map, it is treated as having a
  1269. // score of 1.0.
  1270. //
  1271. // Scores should not be 0 or negative; such scores will be ignored.
  1272. //
  1273. // A nil map means no change from the previous value (if any); an empty
  1274. // non-nil map can be sent to reset all scores back to 1.0.
  1275. func (v DERPHomeParamsView) RegionScore() views.Map[int, float64] {
  1276. return views.MapOf(v.ж.RegionScore)
  1277. }
  1278. // A compilation failure here means this code must be regenerated, with the command at the top of this file.
  1279. var _DERPHomeParamsViewNeedsRegeneration = DERPHomeParams(struct {
  1280. RegionScore map[int]float64
  1281. }{})
  1282. // View returns a read-only view of DERPRegion.
  1283. func (p *DERPRegion) View() DERPRegionView {
  1284. return DERPRegionView{ж: p}
  1285. }
  1286. // DERPRegionView provides a read-only view over DERPRegion.
  1287. //
  1288. // Its methods should only be called if `Valid()` returns true.
  1289. type DERPRegionView struct {
  1290. // ж is the underlying mutable value, named with a hard-to-type
  1291. // character that looks pointy like a pointer.
  1292. // It is named distinctively to make you think of how dangerous it is to escape
  1293. // to callers. You must not let callers be able to mutate it.
  1294. ж *DERPRegion
  1295. }
  1296. // Valid reports whether v's underlying value is non-nil.
  1297. func (v DERPRegionView) Valid() bool { return v.ж != nil }
  1298. // AsStruct returns a clone of the underlying value which aliases no memory with
  1299. // the original.
  1300. func (v DERPRegionView) AsStruct() *DERPRegion {
  1301. if v.ж == nil {
  1302. return nil
  1303. }
  1304. return v.ж.Clone()
  1305. }
  1306. // MarshalJSON implements [jsonv1.Marshaler].
  1307. func (v DERPRegionView) MarshalJSON() ([]byte, error) {
  1308. return jsonv1.Marshal(v.ж)
  1309. }
  1310. // MarshalJSONTo implements [jsonv2.MarshalerTo].
  1311. func (v DERPRegionView) MarshalJSONTo(enc *jsontext.Encoder) error {
  1312. return jsonv2.MarshalEncode(enc, v.ж)
  1313. }
  1314. // UnmarshalJSON implements [jsonv1.Unmarshaler].
  1315. func (v *DERPRegionView) UnmarshalJSON(b []byte) error {
  1316. if v.ж != nil {
  1317. return errors.New("already initialized")
  1318. }
  1319. if len(b) == 0 {
  1320. return nil
  1321. }
  1322. var x DERPRegion
  1323. if err := jsonv1.Unmarshal(b, &x); err != nil {
  1324. return err
  1325. }
  1326. v.ж = &x
  1327. return nil
  1328. }
  1329. // UnmarshalJSONFrom implements [jsonv2.UnmarshalerFrom].
  1330. func (v *DERPRegionView) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
  1331. if v.ж != nil {
  1332. return errors.New("already initialized")
  1333. }
  1334. var x DERPRegion
  1335. if err := jsonv2.UnmarshalDecode(dec, &x); err != nil {
  1336. return err
  1337. }
  1338. v.ж = &x
  1339. return nil
  1340. }
  1341. // RegionID is a unique integer for a geographic region.
  1342. //
  1343. // It corresponds to the legacy derpN.tailscale.com hostnames
  1344. // used by older clients. (Older clients will continue to resolve
  1345. // derpN.tailscale.com when contacting peers, rather than use
  1346. // the server-provided DERPMap)
  1347. //
  1348. // RegionIDs must be non-zero, positive, and guaranteed to fit
  1349. // in a JavaScript number.
  1350. //
  1351. // RegionIDs in range 900-999 are reserved for end users to run their
  1352. // own DERP nodes.
  1353. func (v DERPRegionView) RegionID() int { return v.ж.RegionID }
  1354. // RegionCode is a short name for the region. It's usually a popular
  1355. // city or airport code in the region: "nyc", "sf", "sin",
  1356. // "fra", etc.
  1357. func (v DERPRegionView) RegionCode() string { return v.ж.RegionCode }
  1358. // RegionName is a long English name for the region: "New York City",
  1359. // "San Francisco", "Singapore", "Frankfurt", etc.
  1360. func (v DERPRegionView) RegionName() string { return v.ж.RegionName }
  1361. // Latitude, Longitude are optional geographical coordinates of the DERP region's city, in degrees.
  1362. func (v DERPRegionView) Latitude() float64 { return v.ж.Latitude }
  1363. func (v DERPRegionView) Longitude() float64 { return v.ж.Longitude }
  1364. // Avoid is whether the client should avoid picking this as its home region.
  1365. // The region should only be used if a peer is there. Clients already using
  1366. // this region as their home should migrate away to a new region without
  1367. // Avoid set.
  1368. //
  1369. // Deprecated: because of bugs in past implementations combined with unclear
  1370. // docs that caused people to think the bugs were intentional, this field is
  1371. // deprecated. It was never supposed to cause STUN/DERP measurement probes,
  1372. // but due to bugs, it sometimes did. And then some parts of the code began
  1373. // to rely on that property. But then we were unable to use this field for
  1374. // its original purpose, nor its later imagined purpose, because various
  1375. // parts of the codebase thought it meant one thing and others thought it
  1376. // meant another. But it did something in the middle instead. So we're retiring
  1377. // it. Use NoMeasureNoHome instead.
  1378. func (v DERPRegionView) Avoid() bool { return v.ж.Avoid }
  1379. // NoMeasureNoHome says that this regions should not be measured for its
  1380. // latency distance (STUN, HTTPS, etc) or availability (e.g. captive portal
  1381. // checks) and should never be selected as the node's home region. However,
  1382. // if a peer declares this region as its home, then this client is allowed
  1383. // to connect to it for the purpose of communicating with that peer.
  1384. //
  1385. // This is what the now deprecated Avoid bool was supposed to mean
  1386. // originally but had implementation bugs and documentation omissions.
  1387. func (v DERPRegionView) NoMeasureNoHome() bool { return v.ж.NoMeasureNoHome }
  1388. // Nodes are the DERP nodes running in this region, in
  1389. // priority order for the current client. Client TLS
  1390. // connections should ideally only go to the first entry
  1391. // (falling back to the second if necessary). STUN packets
  1392. // should go to the first 1 or 2.
  1393. //
  1394. // If nodes within a region route packets amongst themselves,
  1395. // but not to other regions. That said, each user/domain
  1396. // should get a the same preferred node order, so if all nodes
  1397. // for a user/network pick the first one (as they should, when
  1398. // things are healthy), the inter-cluster routing is minimal
  1399. // to zero.
  1400. func (v DERPRegionView) Nodes() views.SliceView[*DERPNode, DERPNodeView] {
  1401. return views.SliceOfViews[*DERPNode, DERPNodeView](v.ж.Nodes)
  1402. }
  1403. // A compilation failure here means this code must be regenerated, with the command at the top of this file.
  1404. var _DERPRegionViewNeedsRegeneration = DERPRegion(struct {
  1405. RegionID int
  1406. RegionCode string
  1407. RegionName string
  1408. Latitude float64
  1409. Longitude float64
  1410. Avoid bool
  1411. NoMeasureNoHome bool
  1412. Nodes []*DERPNode
  1413. }{})
  1414. // View returns a read-only view of DERPMap.
  1415. func (p *DERPMap) View() DERPMapView {
  1416. return DERPMapView{ж: p}
  1417. }
  1418. // DERPMapView provides a read-only view over DERPMap.
  1419. //
  1420. // Its methods should only be called if `Valid()` returns true.
  1421. type DERPMapView struct {
  1422. // ж is the underlying mutable value, named with a hard-to-type
  1423. // character that looks pointy like a pointer.
  1424. // It is named distinctively to make you think of how dangerous it is to escape
  1425. // to callers. You must not let callers be able to mutate it.
  1426. ж *DERPMap
  1427. }
  1428. // Valid reports whether v's underlying value is non-nil.
  1429. func (v DERPMapView) Valid() bool { return v.ж != nil }
  1430. // AsStruct returns a clone of the underlying value which aliases no memory with
  1431. // the original.
  1432. func (v DERPMapView) AsStruct() *DERPMap {
  1433. if v.ж == nil {
  1434. return nil
  1435. }
  1436. return v.ж.Clone()
  1437. }
  1438. // MarshalJSON implements [jsonv1.Marshaler].
  1439. func (v DERPMapView) MarshalJSON() ([]byte, error) {
  1440. return jsonv1.Marshal(v.ж)
  1441. }
  1442. // MarshalJSONTo implements [jsonv2.MarshalerTo].
  1443. func (v DERPMapView) MarshalJSONTo(enc *jsontext.Encoder) error {
  1444. return jsonv2.MarshalEncode(enc, v.ж)
  1445. }
  1446. // UnmarshalJSON implements [jsonv1.Unmarshaler].
  1447. func (v *DERPMapView) UnmarshalJSON(b []byte) error {
  1448. if v.ж != nil {
  1449. return errors.New("already initialized")
  1450. }
  1451. if len(b) == 0 {
  1452. return nil
  1453. }
  1454. var x DERPMap
  1455. if err := jsonv1.Unmarshal(b, &x); err != nil {
  1456. return err
  1457. }
  1458. v.ж = &x
  1459. return nil
  1460. }
  1461. // UnmarshalJSONFrom implements [jsonv2.UnmarshalerFrom].
  1462. func (v *DERPMapView) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
  1463. if v.ж != nil {
  1464. return errors.New("already initialized")
  1465. }
  1466. var x DERPMap
  1467. if err := jsonv2.UnmarshalDecode(dec, &x); err != nil {
  1468. return err
  1469. }
  1470. v.ж = &x
  1471. return nil
  1472. }
  1473. // HomeParams, if non-nil, is a change in home parameters.
  1474. //
  1475. // The rest of the DEPRMap fields, if zero, means unchanged.
  1476. func (v DERPMapView) HomeParams() DERPHomeParamsView { return v.ж.HomeParams.View() }
  1477. // Regions is the set of geographic regions running DERP node(s).
  1478. //
  1479. // It's keyed by the DERPRegion.RegionID.
  1480. //
  1481. // The numbers are not necessarily contiguous.
  1482. func (v DERPMapView) Regions() views.MapFn[int, *DERPRegion, DERPRegionView] {
  1483. return views.MapFnOf(v.ж.Regions, func(t *DERPRegion) DERPRegionView {
  1484. return t.View()
  1485. })
  1486. }
  1487. // OmitDefaultRegions specifies to not use Tailscale's DERP servers, and only use those
  1488. // specified in this DERPMap. If there are none set outside of the defaults, this is a noop.
  1489. //
  1490. // This field is only meaningful if the Regions map is non-nil (indicating a change).
  1491. func (v DERPMapView) OmitDefaultRegions() bool { return v.ж.OmitDefaultRegions }
  1492. // A compilation failure here means this code must be regenerated, with the command at the top of this file.
  1493. var _DERPMapViewNeedsRegeneration = DERPMap(struct {
  1494. HomeParams *DERPHomeParams
  1495. Regions map[int]*DERPRegion
  1496. OmitDefaultRegions bool
  1497. }{})
  1498. // View returns a read-only view of DERPNode.
  1499. func (p *DERPNode) View() DERPNodeView {
  1500. return DERPNodeView{ж: p}
  1501. }
  1502. // DERPNodeView provides a read-only view over DERPNode.
  1503. //
  1504. // Its methods should only be called if `Valid()` returns true.
  1505. type DERPNodeView struct {
  1506. // ж is the underlying mutable value, named with a hard-to-type
  1507. // character that looks pointy like a pointer.
  1508. // It is named distinctively to make you think of how dangerous it is to escape
  1509. // to callers. You must not let callers be able to mutate it.
  1510. ж *DERPNode
  1511. }
  1512. // Valid reports whether v's underlying value is non-nil.
  1513. func (v DERPNodeView) Valid() bool { return v.ж != nil }
  1514. // AsStruct returns a clone of the underlying value which aliases no memory with
  1515. // the original.
  1516. func (v DERPNodeView) AsStruct() *DERPNode {
  1517. if v.ж == nil {
  1518. return nil
  1519. }
  1520. return v.ж.Clone()
  1521. }
  1522. // MarshalJSON implements [jsonv1.Marshaler].
  1523. func (v DERPNodeView) MarshalJSON() ([]byte, error) {
  1524. return jsonv1.Marshal(v.ж)
  1525. }
  1526. // MarshalJSONTo implements [jsonv2.MarshalerTo].
  1527. func (v DERPNodeView) MarshalJSONTo(enc *jsontext.Encoder) error {
  1528. return jsonv2.MarshalEncode(enc, v.ж)
  1529. }
  1530. // UnmarshalJSON implements [jsonv1.Unmarshaler].
  1531. func (v *DERPNodeView) UnmarshalJSON(b []byte) error {
  1532. if v.ж != nil {
  1533. return errors.New("already initialized")
  1534. }
  1535. if len(b) == 0 {
  1536. return nil
  1537. }
  1538. var x DERPNode
  1539. if err := jsonv1.Unmarshal(b, &x); err != nil {
  1540. return err
  1541. }
  1542. v.ж = &x
  1543. return nil
  1544. }
  1545. // UnmarshalJSONFrom implements [jsonv2.UnmarshalerFrom].
  1546. func (v *DERPNodeView) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
  1547. if v.ж != nil {
  1548. return errors.New("already initialized")
  1549. }
  1550. var x DERPNode
  1551. if err := jsonv2.UnmarshalDecode(dec, &x); err != nil {
  1552. return err
  1553. }
  1554. v.ж = &x
  1555. return nil
  1556. }
  1557. // Name is a unique node name (across all regions).
  1558. // It is not a host name.
  1559. // It's typically of the form "1b", "2a", "3b", etc. (region
  1560. // ID + suffix within that region)
  1561. func (v DERPNodeView) Name() string { return v.ж.Name }
  1562. // RegionID is the RegionID of the DERPRegion that this node
  1563. // is running in.
  1564. func (v DERPNodeView) RegionID() int { return v.ж.RegionID }
  1565. // HostName is the DERP node's hostname.
  1566. //
  1567. // It is required but need not be unique; multiple nodes may
  1568. // have the same HostName but vary in configuration otherwise.
  1569. func (v DERPNodeView) HostName() string { return v.ж.HostName }
  1570. // CertName optionally specifies the expected TLS cert common
  1571. // name. If empty, HostName is used. If CertName is non-empty,
  1572. // HostName is only used for the TCP dial (if IPv4/IPv6 are
  1573. // not present) + TLS ClientHello.
  1574. //
  1575. // As a special case, if CertName starts with "sha256-raw:",
  1576. // then the rest of the string is a hex-encoded SHA256 of the
  1577. // cert to expect. This is used for self-signed certs.
  1578. // In this case, the HostName field will typically be an IP
  1579. // address literal.
  1580. func (v DERPNodeView) CertName() string { return v.ж.CertName }
  1581. // IPv4 optionally forces an IPv4 address to use, instead of using DNS.
  1582. // If empty, A record(s) from DNS lookups of HostName are used.
  1583. // If the string is not an IPv4 address, IPv4 is not used; the
  1584. // conventional string to disable IPv4 (and not use DNS) is
  1585. // "none".
  1586. func (v DERPNodeView) IPv4() string { return v.ж.IPv4 }
  1587. // IPv6 optionally forces an IPv6 address to use, instead of using DNS.
  1588. // If empty, AAAA record(s) from DNS lookups of HostName are used.
  1589. // If the string is not an IPv6 address, IPv6 is not used; the
  1590. // conventional string to disable IPv6 (and not use DNS) is
  1591. // "none".
  1592. func (v DERPNodeView) IPv6() string { return v.ж.IPv6 }
  1593. // Port optionally specifies a STUN port to use.
  1594. // Zero means 3478.
  1595. // To disable STUN on this node, use -1.
  1596. func (v DERPNodeView) STUNPort() int { return v.ж.STUNPort }
  1597. // STUNOnly marks a node as only a STUN server and not a DERP
  1598. // server.
  1599. func (v DERPNodeView) STUNOnly() bool { return v.ж.STUNOnly }
  1600. // DERPPort optionally provides an alternate TLS port number
  1601. // for the DERP HTTPS server.
  1602. //
  1603. // If zero, 443 is used.
  1604. func (v DERPNodeView) DERPPort() int { return v.ж.DERPPort }
  1605. // InsecureForTests is used by unit tests to disable TLS verification.
  1606. // It should not be set by users.
  1607. func (v DERPNodeView) InsecureForTests() bool { return v.ж.InsecureForTests }
  1608. // STUNTestIP is used in tests to override the STUN server's IP.
  1609. // If empty, it's assumed to be the same as the DERP server.
  1610. func (v DERPNodeView) STUNTestIP() string { return v.ж.STUNTestIP }
  1611. // CanPort80 specifies whether this DERP node is accessible over HTTP
  1612. // on port 80 specifically. This is used for captive portal checks.
  1613. func (v DERPNodeView) CanPort80() bool { return v.ж.CanPort80 }
  1614. // A compilation failure here means this code must be regenerated, with the command at the top of this file.
  1615. var _DERPNodeViewNeedsRegeneration = DERPNode(struct {
  1616. Name string
  1617. RegionID int
  1618. HostName string
  1619. CertName string
  1620. IPv4 string
  1621. IPv6 string
  1622. STUNPort int
  1623. STUNOnly bool
  1624. DERPPort int
  1625. InsecureForTests bool
  1626. STUNTestIP string
  1627. CanPort80 bool
  1628. }{})
  1629. // View returns a read-only view of SSHRule.
  1630. func (p *SSHRule) View() SSHRuleView {
  1631. return SSHRuleView{ж: p}
  1632. }
  1633. // SSHRuleView provides a read-only view over SSHRule.
  1634. //
  1635. // Its methods should only be called if `Valid()` returns true.
  1636. type SSHRuleView struct {
  1637. // ж is the underlying mutable value, named with a hard-to-type
  1638. // character that looks pointy like a pointer.
  1639. // It is named distinctively to make you think of how dangerous it is to escape
  1640. // to callers. You must not let callers be able to mutate it.
  1641. ж *SSHRule
  1642. }
  1643. // Valid reports whether v's underlying value is non-nil.
  1644. func (v SSHRuleView) Valid() bool { return v.ж != nil }
  1645. // AsStruct returns a clone of the underlying value which aliases no memory with
  1646. // the original.
  1647. func (v SSHRuleView) AsStruct() *SSHRule {
  1648. if v.ж == nil {
  1649. return nil
  1650. }
  1651. return v.ж.Clone()
  1652. }
  1653. // MarshalJSON implements [jsonv1.Marshaler].
  1654. func (v SSHRuleView) MarshalJSON() ([]byte, error) {
  1655. return jsonv1.Marshal(v.ж)
  1656. }
  1657. // MarshalJSONTo implements [jsonv2.MarshalerTo].
  1658. func (v SSHRuleView) MarshalJSONTo(enc *jsontext.Encoder) error {
  1659. return jsonv2.MarshalEncode(enc, v.ж)
  1660. }
  1661. // UnmarshalJSON implements [jsonv1.Unmarshaler].
  1662. func (v *SSHRuleView) UnmarshalJSON(b []byte) error {
  1663. if v.ж != nil {
  1664. return errors.New("already initialized")
  1665. }
  1666. if len(b) == 0 {
  1667. return nil
  1668. }
  1669. var x SSHRule
  1670. if err := jsonv1.Unmarshal(b, &x); err != nil {
  1671. return err
  1672. }
  1673. v.ж = &x
  1674. return nil
  1675. }
  1676. // UnmarshalJSONFrom implements [jsonv2.UnmarshalerFrom].
  1677. func (v *SSHRuleView) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
  1678. if v.ж != nil {
  1679. return errors.New("already initialized")
  1680. }
  1681. var x SSHRule
  1682. if err := jsonv2.UnmarshalDecode(dec, &x); err != nil {
  1683. return err
  1684. }
  1685. v.ж = &x
  1686. return nil
  1687. }
  1688. // RuleExpires, if non-nil, is when this rule expires.
  1689. //
  1690. // For example, a (principal,sshuser) tuple might be granted
  1691. // prompt-free SSH access for N minutes, so this rule would be
  1692. // before a expiration-free rule for the same principal that
  1693. // required an auth prompt. This permits the control plane to
  1694. // be out of the path for already-authorized SSH pairs.
  1695. //
  1696. // Once a rule matches, the lifetime of any accepting connection
  1697. // is subject to the SSHAction.SessionExpires time, if any.
  1698. func (v SSHRuleView) RuleExpires() views.ValuePointer[time.Time] {
  1699. return views.ValuePointerOf(v.ж.RuleExpires)
  1700. }
  1701. // Principals matches an incoming connection. If the connection
  1702. // matches anything in this list and also matches SSHUsers,
  1703. // then Action is applied.
  1704. func (v SSHRuleView) Principals() views.SliceView[*SSHPrincipal, SSHPrincipalView] {
  1705. return views.SliceOfViews[*SSHPrincipal, SSHPrincipalView](v.ж.Principals)
  1706. }
  1707. // SSHUsers are the SSH users that this rule matches. It is a
  1708. // map from either ssh-user|"*" => local-user. The map must
  1709. // contain a key for either ssh-user or, as a fallback, "*" to
  1710. // match anything. If it does, the map entry's value is the
  1711. // actual user that's logged in.
  1712. // If the map value is the empty string (for either the
  1713. // requested SSH user or "*"), the rule doesn't match.
  1714. // If the map value is "=", it means the ssh-user should map
  1715. // directly to the local-user.
  1716. // It may be nil if the Action is reject.
  1717. func (v SSHRuleView) SSHUsers() views.Map[string, string] { return views.MapOf(v.ж.SSHUsers) }
  1718. // Action is the outcome to task.
  1719. // A nil or invalid action means to deny.
  1720. func (v SSHRuleView) Action() SSHActionView { return v.ж.Action.View() }
  1721. // AcceptEnv is a slice of environment variable names that are allowlisted
  1722. // for the SSH rule in the policy file.
  1723. //
  1724. // AcceptEnv values may contain * and ? wildcard characters which match against
  1725. // an arbitrary number of characters or a single character respectively.
  1726. func (v SSHRuleView) AcceptEnv() views.Slice[string] { return views.SliceOf(v.ж.AcceptEnv) }
  1727. // A compilation failure here means this code must be regenerated, with the command at the top of this file.
  1728. var _SSHRuleViewNeedsRegeneration = SSHRule(struct {
  1729. RuleExpires *time.Time
  1730. Principals []*SSHPrincipal
  1731. SSHUsers map[string]string
  1732. Action *SSHAction
  1733. AcceptEnv []string
  1734. }{})
  1735. // View returns a read-only view of SSHAction.
  1736. func (p *SSHAction) View() SSHActionView {
  1737. return SSHActionView{ж: p}
  1738. }
  1739. // SSHActionView provides a read-only view over SSHAction.
  1740. //
  1741. // Its methods should only be called if `Valid()` returns true.
  1742. type SSHActionView struct {
  1743. // ж is the underlying mutable value, named with a hard-to-type
  1744. // character that looks pointy like a pointer.
  1745. // It is named distinctively to make you think of how dangerous it is to escape
  1746. // to callers. You must not let callers be able to mutate it.
  1747. ж *SSHAction
  1748. }
  1749. // Valid reports whether v's underlying value is non-nil.
  1750. func (v SSHActionView) Valid() bool { return v.ж != nil }
  1751. // AsStruct returns a clone of the underlying value which aliases no memory with
  1752. // the original.
  1753. func (v SSHActionView) AsStruct() *SSHAction {
  1754. if v.ж == nil {
  1755. return nil
  1756. }
  1757. return v.ж.Clone()
  1758. }
  1759. // MarshalJSON implements [jsonv1.Marshaler].
  1760. func (v SSHActionView) MarshalJSON() ([]byte, error) {
  1761. return jsonv1.Marshal(v.ж)
  1762. }
  1763. // MarshalJSONTo implements [jsonv2.MarshalerTo].
  1764. func (v SSHActionView) MarshalJSONTo(enc *jsontext.Encoder) error {
  1765. return jsonv2.MarshalEncode(enc, v.ж)
  1766. }
  1767. // UnmarshalJSON implements [jsonv1.Unmarshaler].
  1768. func (v *SSHActionView) UnmarshalJSON(b []byte) error {
  1769. if v.ж != nil {
  1770. return errors.New("already initialized")
  1771. }
  1772. if len(b) == 0 {
  1773. return nil
  1774. }
  1775. var x SSHAction
  1776. if err := jsonv1.Unmarshal(b, &x); err != nil {
  1777. return err
  1778. }
  1779. v.ж = &x
  1780. return nil
  1781. }
  1782. // UnmarshalJSONFrom implements [jsonv2.UnmarshalerFrom].
  1783. func (v *SSHActionView) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
  1784. if v.ж != nil {
  1785. return errors.New("already initialized")
  1786. }
  1787. var x SSHAction
  1788. if err := jsonv2.UnmarshalDecode(dec, &x); err != nil {
  1789. return err
  1790. }
  1791. v.ж = &x
  1792. return nil
  1793. }
  1794. // Message, if non-empty, is shown to the user before the
  1795. // action occurs.
  1796. func (v SSHActionView) Message() string { return v.ж.Message }
  1797. // Reject, if true, terminates the connection. This action
  1798. // has higher priority that Accept, if given.
  1799. // The reason this is exists is primarily so a response
  1800. // from HoldAndDelegate has a way to stop the poll.
  1801. func (v SSHActionView) Reject() bool { return v.ж.Reject }
  1802. // Accept, if true, accepts the connection immediately
  1803. // without further prompts.
  1804. func (v SSHActionView) Accept() bool { return v.ж.Accept }
  1805. // SessionDuration, if non-zero, is how long the session can stay open
  1806. // before being forcefully terminated.
  1807. func (v SSHActionView) SessionDuration() time.Duration { return v.ж.SessionDuration }
  1808. // AllowAgentForwarding, if true, allows accepted connections to forward
  1809. // the ssh agent if requested.
  1810. func (v SSHActionView) AllowAgentForwarding() bool { return v.ж.AllowAgentForwarding }
  1811. // HoldAndDelegate, if non-empty, is a URL that serves an
  1812. // outcome verdict. The connection will be accepted and will
  1813. // block until the provided long-polling URL serves a new
  1814. // SSHAction JSON value. The URL must be fetched using the
  1815. // Noise transport (in package control/control{base,http}).
  1816. // If the long poll breaks before returning a complete HTTP
  1817. // response, it should be re-fetched as long as the SSH
  1818. // session is open.
  1819. //
  1820. // The following variables in the URL are expanded by tailscaled:
  1821. //
  1822. // - $SRC_NODE_IP (URL escaped)
  1823. // - $SRC_NODE_ID (Node.ID as int64 string)
  1824. // - $DST_NODE_IP (URL escaped)
  1825. // - $DST_NODE_ID (Node.ID as int64 string)
  1826. // - $SSH_USER (URL escaped, ssh user requested)
  1827. // - $LOCAL_USER (URL escaped, local user mapped)
  1828. func (v SSHActionView) HoldAndDelegate() string { return v.ж.HoldAndDelegate }
  1829. // AllowLocalPortForwarding, if true, allows accepted connections
  1830. // to use local port forwarding if requested.
  1831. func (v SSHActionView) AllowLocalPortForwarding() bool { return v.ж.AllowLocalPortForwarding }
  1832. // AllowRemotePortForwarding, if true, allows accepted connections
  1833. // to use remote port forwarding if requested.
  1834. func (v SSHActionView) AllowRemotePortForwarding() bool { return v.ж.AllowRemotePortForwarding }
  1835. // Recorders defines the destinations of the SSH session recorders.
  1836. // The recording will be uploaded to http://addr:port/record.
  1837. func (v SSHActionView) Recorders() views.Slice[netip.AddrPort] { return views.SliceOf(v.ж.Recorders) }
  1838. // OnRecorderFailure is the action to take if recording fails.
  1839. // If nil, the default action is to fail open.
  1840. func (v SSHActionView) OnRecordingFailure() views.ValuePointer[SSHRecorderFailureAction] {
  1841. return views.ValuePointerOf(v.ж.OnRecordingFailure)
  1842. }
  1843. // A compilation failure here means this code must be regenerated, with the command at the top of this file.
  1844. var _SSHActionViewNeedsRegeneration = SSHAction(struct {
  1845. Message string
  1846. Reject bool
  1847. Accept bool
  1848. SessionDuration time.Duration
  1849. AllowAgentForwarding bool
  1850. HoldAndDelegate string
  1851. AllowLocalPortForwarding bool
  1852. AllowRemotePortForwarding bool
  1853. Recorders []netip.AddrPort
  1854. OnRecordingFailure *SSHRecorderFailureAction
  1855. }{})
  1856. // View returns a read-only view of SSHPrincipal.
  1857. func (p *SSHPrincipal) View() SSHPrincipalView {
  1858. return SSHPrincipalView{ж: p}
  1859. }
  1860. // SSHPrincipalView provides a read-only view over SSHPrincipal.
  1861. //
  1862. // Its methods should only be called if `Valid()` returns true.
  1863. type SSHPrincipalView struct {
  1864. // ж is the underlying mutable value, named with a hard-to-type
  1865. // character that looks pointy like a pointer.
  1866. // It is named distinctively to make you think of how dangerous it is to escape
  1867. // to callers. You must not let callers be able to mutate it.
  1868. ж *SSHPrincipal
  1869. }
  1870. // Valid reports whether v's underlying value is non-nil.
  1871. func (v SSHPrincipalView) Valid() bool { return v.ж != nil }
  1872. // AsStruct returns a clone of the underlying value which aliases no memory with
  1873. // the original.
  1874. func (v SSHPrincipalView) AsStruct() *SSHPrincipal {
  1875. if v.ж == nil {
  1876. return nil
  1877. }
  1878. return v.ж.Clone()
  1879. }
  1880. // MarshalJSON implements [jsonv1.Marshaler].
  1881. func (v SSHPrincipalView) MarshalJSON() ([]byte, error) {
  1882. return jsonv1.Marshal(v.ж)
  1883. }
  1884. // MarshalJSONTo implements [jsonv2.MarshalerTo].
  1885. func (v SSHPrincipalView) MarshalJSONTo(enc *jsontext.Encoder) error {
  1886. return jsonv2.MarshalEncode(enc, v.ж)
  1887. }
  1888. // UnmarshalJSON implements [jsonv1.Unmarshaler].
  1889. func (v *SSHPrincipalView) UnmarshalJSON(b []byte) error {
  1890. if v.ж != nil {
  1891. return errors.New("already initialized")
  1892. }
  1893. if len(b) == 0 {
  1894. return nil
  1895. }
  1896. var x SSHPrincipal
  1897. if err := jsonv1.Unmarshal(b, &x); err != nil {
  1898. return err
  1899. }
  1900. v.ж = &x
  1901. return nil
  1902. }
  1903. // UnmarshalJSONFrom implements [jsonv2.UnmarshalerFrom].
  1904. func (v *SSHPrincipalView) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
  1905. if v.ж != nil {
  1906. return errors.New("already initialized")
  1907. }
  1908. var x SSHPrincipal
  1909. if err := jsonv2.UnmarshalDecode(dec, &x); err != nil {
  1910. return err
  1911. }
  1912. v.ж = &x
  1913. return nil
  1914. }
  1915. func (v SSHPrincipalView) Node() StableNodeID { return v.ж.Node }
  1916. func (v SSHPrincipalView) NodeIP() string { return v.ж.NodeIP }
  1917. // email-ish: [email protected], bar@github
  1918. func (v SSHPrincipalView) UserLogin() string { return v.ж.UserLogin }
  1919. // if true, match any connection
  1920. func (v SSHPrincipalView) Any() bool { return v.ж.Any }
  1921. // UnusedPubKeys was public key support. It never became an official product
  1922. // feature and so as of 2024-12-12 is being removed.
  1923. // This stub exists to remind us not to re-use the JSON field name "pubKeys"
  1924. // in the future if we bring it back with different semantics.
  1925. //
  1926. // Deprecated: do not use. It does nothing.
  1927. func (v SSHPrincipalView) UnusedPubKeys() views.Slice[string] {
  1928. return views.SliceOf(v.ж.UnusedPubKeys)
  1929. }
  1930. // A compilation failure here means this code must be regenerated, with the command at the top of this file.
  1931. var _SSHPrincipalViewNeedsRegeneration = SSHPrincipal(struct {
  1932. Node StableNodeID
  1933. NodeIP string
  1934. UserLogin string
  1935. Any bool
  1936. UnusedPubKeys []string
  1937. }{})
  1938. // View returns a read-only view of ControlDialPlan.
  1939. func (p *ControlDialPlan) View() ControlDialPlanView {
  1940. return ControlDialPlanView{ж: p}
  1941. }
  1942. // ControlDialPlanView provides a read-only view over ControlDialPlan.
  1943. //
  1944. // Its methods should only be called if `Valid()` returns true.
  1945. type ControlDialPlanView struct {
  1946. // ж is the underlying mutable value, named with a hard-to-type
  1947. // character that looks pointy like a pointer.
  1948. // It is named distinctively to make you think of how dangerous it is to escape
  1949. // to callers. You must not let callers be able to mutate it.
  1950. ж *ControlDialPlan
  1951. }
  1952. // Valid reports whether v's underlying value is non-nil.
  1953. func (v ControlDialPlanView) Valid() bool { return v.ж != nil }
  1954. // AsStruct returns a clone of the underlying value which aliases no memory with
  1955. // the original.
  1956. func (v ControlDialPlanView) AsStruct() *ControlDialPlan {
  1957. if v.ж == nil {
  1958. return nil
  1959. }
  1960. return v.ж.Clone()
  1961. }
  1962. // MarshalJSON implements [jsonv1.Marshaler].
  1963. func (v ControlDialPlanView) MarshalJSON() ([]byte, error) {
  1964. return jsonv1.Marshal(v.ж)
  1965. }
  1966. // MarshalJSONTo implements [jsonv2.MarshalerTo].
  1967. func (v ControlDialPlanView) MarshalJSONTo(enc *jsontext.Encoder) error {
  1968. return jsonv2.MarshalEncode(enc, v.ж)
  1969. }
  1970. // UnmarshalJSON implements [jsonv1.Unmarshaler].
  1971. func (v *ControlDialPlanView) UnmarshalJSON(b []byte) error {
  1972. if v.ж != nil {
  1973. return errors.New("already initialized")
  1974. }
  1975. if len(b) == 0 {
  1976. return nil
  1977. }
  1978. var x ControlDialPlan
  1979. if err := jsonv1.Unmarshal(b, &x); err != nil {
  1980. return err
  1981. }
  1982. v.ж = &x
  1983. return nil
  1984. }
  1985. // UnmarshalJSONFrom implements [jsonv2.UnmarshalerFrom].
  1986. func (v *ControlDialPlanView) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
  1987. if v.ж != nil {
  1988. return errors.New("already initialized")
  1989. }
  1990. var x ControlDialPlan
  1991. if err := jsonv2.UnmarshalDecode(dec, &x); err != nil {
  1992. return err
  1993. }
  1994. v.ж = &x
  1995. return nil
  1996. }
  1997. // An empty list means the default: use DNS (unspecified which DNS).
  1998. func (v ControlDialPlanView) Candidates() views.Slice[ControlIPCandidate] {
  1999. return views.SliceOf(v.ж.Candidates)
  2000. }
  2001. // A compilation failure here means this code must be regenerated, with the command at the top of this file.
  2002. var _ControlDialPlanViewNeedsRegeneration = ControlDialPlan(struct {
  2003. Candidates []ControlIPCandidate
  2004. }{})
  2005. // View returns a read-only view of Location.
  2006. func (p *Location) View() LocationView {
  2007. return LocationView{ж: p}
  2008. }
  2009. // LocationView provides a read-only view over Location.
  2010. //
  2011. // Its methods should only be called if `Valid()` returns true.
  2012. type LocationView struct {
  2013. // ж is the underlying mutable value, named with a hard-to-type
  2014. // character that looks pointy like a pointer.
  2015. // It is named distinctively to make you think of how dangerous it is to escape
  2016. // to callers. You must not let callers be able to mutate it.
  2017. ж *Location
  2018. }
  2019. // Valid reports whether v's underlying value is non-nil.
  2020. func (v LocationView) Valid() bool { return v.ж != nil }
  2021. // AsStruct returns a clone of the underlying value which aliases no memory with
  2022. // the original.
  2023. func (v LocationView) AsStruct() *Location {
  2024. if v.ж == nil {
  2025. return nil
  2026. }
  2027. return v.ж.Clone()
  2028. }
  2029. // MarshalJSON implements [jsonv1.Marshaler].
  2030. func (v LocationView) MarshalJSON() ([]byte, error) {
  2031. return jsonv1.Marshal(v.ж)
  2032. }
  2033. // MarshalJSONTo implements [jsonv2.MarshalerTo].
  2034. func (v LocationView) MarshalJSONTo(enc *jsontext.Encoder) error {
  2035. return jsonv2.MarshalEncode(enc, v.ж)
  2036. }
  2037. // UnmarshalJSON implements [jsonv1.Unmarshaler].
  2038. func (v *LocationView) UnmarshalJSON(b []byte) error {
  2039. if v.ж != nil {
  2040. return errors.New("already initialized")
  2041. }
  2042. if len(b) == 0 {
  2043. return nil
  2044. }
  2045. var x Location
  2046. if err := jsonv1.Unmarshal(b, &x); err != nil {
  2047. return err
  2048. }
  2049. v.ж = &x
  2050. return nil
  2051. }
  2052. // UnmarshalJSONFrom implements [jsonv2.UnmarshalerFrom].
  2053. func (v *LocationView) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
  2054. if v.ж != nil {
  2055. return errors.New("already initialized")
  2056. }
  2057. var x Location
  2058. if err := jsonv2.UnmarshalDecode(dec, &x); err != nil {
  2059. return err
  2060. }
  2061. v.ж = &x
  2062. return nil
  2063. }
  2064. // User friendly country name, with proper capitalization ("Canada")
  2065. func (v LocationView) Country() string { return v.ж.Country }
  2066. // ISO 3166-1 alpha-2 in upper case ("CA")
  2067. func (v LocationView) CountryCode() string { return v.ж.CountryCode }
  2068. // User friendly city name, with proper capitalization ("Squamish")
  2069. func (v LocationView) City() string { return v.ж.City }
  2070. // CityCode is a short code representing the city in upper case.
  2071. // CityCode is used to disambiguate a city from another location
  2072. // with the same city name. It uniquely identifies a particular
  2073. // geographical location, within the tailnet.
  2074. // IATA, ICAO or ISO 3166-2 codes are recommended ("YSE")
  2075. func (v LocationView) CityCode() string { return v.ж.CityCode }
  2076. // Latitude, Longitude are optional geographical coordinates of the node, in degrees.
  2077. // No particular accuracy level is promised; the coordinates may simply be the center of the city or country.
  2078. func (v LocationView) Latitude() float64 { return v.ж.Latitude }
  2079. func (v LocationView) Longitude() float64 { return v.ж.Longitude }
  2080. // Priority determines the order of use of an exit node when a
  2081. // location based preference matches more than one exit node,
  2082. // the node with the highest priority wins. Nodes of equal
  2083. // probability may be selected arbitrarily.
  2084. //
  2085. // A value of 0 means the exit node does not have a priority
  2086. // preference. A negative int is not allowed.
  2087. func (v LocationView) Priority() int { return v.ж.Priority }
  2088. // A compilation failure here means this code must be regenerated, with the command at the top of this file.
  2089. var _LocationViewNeedsRegeneration = Location(struct {
  2090. Country string
  2091. CountryCode string
  2092. City string
  2093. CityCode string
  2094. Latitude float64
  2095. Longitude float64
  2096. Priority int
  2097. }{})
  2098. // View returns a read-only view of UserProfile.
  2099. func (p *UserProfile) View() UserProfileView {
  2100. return UserProfileView{ж: p}
  2101. }
  2102. // UserProfileView provides a read-only view over UserProfile.
  2103. //
  2104. // Its methods should only be called if `Valid()` returns true.
  2105. type UserProfileView struct {
  2106. // ж is the underlying mutable value, named with a hard-to-type
  2107. // character that looks pointy like a pointer.
  2108. // It is named distinctively to make you think of how dangerous it is to escape
  2109. // to callers. You must not let callers be able to mutate it.
  2110. ж *UserProfile
  2111. }
  2112. // Valid reports whether v's underlying value is non-nil.
  2113. func (v UserProfileView) Valid() bool { return v.ж != nil }
  2114. // AsStruct returns a clone of the underlying value which aliases no memory with
  2115. // the original.
  2116. func (v UserProfileView) AsStruct() *UserProfile {
  2117. if v.ж == nil {
  2118. return nil
  2119. }
  2120. return v.ж.Clone()
  2121. }
  2122. // MarshalJSON implements [jsonv1.Marshaler].
  2123. func (v UserProfileView) MarshalJSON() ([]byte, error) {
  2124. return jsonv1.Marshal(v.ж)
  2125. }
  2126. // MarshalJSONTo implements [jsonv2.MarshalerTo].
  2127. func (v UserProfileView) MarshalJSONTo(enc *jsontext.Encoder) error {
  2128. return jsonv2.MarshalEncode(enc, v.ж)
  2129. }
  2130. // UnmarshalJSON implements [jsonv1.Unmarshaler].
  2131. func (v *UserProfileView) UnmarshalJSON(b []byte) error {
  2132. if v.ж != nil {
  2133. return errors.New("already initialized")
  2134. }
  2135. if len(b) == 0 {
  2136. return nil
  2137. }
  2138. var x UserProfile
  2139. if err := jsonv1.Unmarshal(b, &x); err != nil {
  2140. return err
  2141. }
  2142. v.ж = &x
  2143. return nil
  2144. }
  2145. // UnmarshalJSONFrom implements [jsonv2.UnmarshalerFrom].
  2146. func (v *UserProfileView) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
  2147. if v.ж != nil {
  2148. return errors.New("already initialized")
  2149. }
  2150. var x UserProfile
  2151. if err := jsonv2.UnmarshalDecode(dec, &x); err != nil {
  2152. return err
  2153. }
  2154. v.ж = &x
  2155. return nil
  2156. }
  2157. func (v UserProfileView) ID() UserID { return v.ж.ID }
  2158. // "[email protected]"; for display purposes only (provider is not listed)
  2159. func (v UserProfileView) LoginName() string { return v.ж.LoginName }
  2160. // "Alice Smith"
  2161. func (v UserProfileView) DisplayName() string { return v.ж.DisplayName }
  2162. func (v UserProfileView) ProfilePicURL() string { return v.ж.ProfilePicURL }
  2163. func (v UserProfileView) Equal(v2 UserProfileView) bool { return v.ж.Equal(v2.ж) }
  2164. // A compilation failure here means this code must be regenerated, with the command at the top of this file.
  2165. var _UserProfileViewNeedsRegeneration = UserProfile(struct {
  2166. ID UserID
  2167. LoginName string
  2168. DisplayName string
  2169. ProfilePicURL string
  2170. }{})
  2171. // View returns a read-only view of VIPService.
  2172. func (p *VIPService) View() VIPServiceView {
  2173. return VIPServiceView{ж: p}
  2174. }
  2175. // VIPServiceView provides a read-only view over VIPService.
  2176. //
  2177. // Its methods should only be called if `Valid()` returns true.
  2178. type VIPServiceView struct {
  2179. // ж is the underlying mutable value, named with a hard-to-type
  2180. // character that looks pointy like a pointer.
  2181. // It is named distinctively to make you think of how dangerous it is to escape
  2182. // to callers. You must not let callers be able to mutate it.
  2183. ж *VIPService
  2184. }
  2185. // Valid reports whether v's underlying value is non-nil.
  2186. func (v VIPServiceView) Valid() bool { return v.ж != nil }
  2187. // AsStruct returns a clone of the underlying value which aliases no memory with
  2188. // the original.
  2189. func (v VIPServiceView) AsStruct() *VIPService {
  2190. if v.ж == nil {
  2191. return nil
  2192. }
  2193. return v.ж.Clone()
  2194. }
  2195. // MarshalJSON implements [jsonv1.Marshaler].
  2196. func (v VIPServiceView) MarshalJSON() ([]byte, error) {
  2197. return jsonv1.Marshal(v.ж)
  2198. }
  2199. // MarshalJSONTo implements [jsonv2.MarshalerTo].
  2200. func (v VIPServiceView) MarshalJSONTo(enc *jsontext.Encoder) error {
  2201. return jsonv2.MarshalEncode(enc, v.ж)
  2202. }
  2203. // UnmarshalJSON implements [jsonv1.Unmarshaler].
  2204. func (v *VIPServiceView) UnmarshalJSON(b []byte) error {
  2205. if v.ж != nil {
  2206. return errors.New("already initialized")
  2207. }
  2208. if len(b) == 0 {
  2209. return nil
  2210. }
  2211. var x VIPService
  2212. if err := jsonv1.Unmarshal(b, &x); err != nil {
  2213. return err
  2214. }
  2215. v.ж = &x
  2216. return nil
  2217. }
  2218. // UnmarshalJSONFrom implements [jsonv2.UnmarshalerFrom].
  2219. func (v *VIPServiceView) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
  2220. if v.ж != nil {
  2221. return errors.New("already initialized")
  2222. }
  2223. var x VIPService
  2224. if err := jsonv2.UnmarshalDecode(dec, &x); err != nil {
  2225. return err
  2226. }
  2227. v.ж = &x
  2228. return nil
  2229. }
  2230. // Name is the name of the service. The Name uniquely identifies a service
  2231. // on a particular tailnet, and so also corresponds uniquely to the pair of
  2232. // IP addresses belonging to the VIP service.
  2233. func (v VIPServiceView) Name() ServiceName { return v.ж.Name }
  2234. // Ports specify which ProtoPorts are made available by this node
  2235. // on the service's IPs.
  2236. func (v VIPServiceView) Ports() views.Slice[ProtoPortRange] { return views.SliceOf(v.ж.Ports) }
  2237. // Active specifies whether new requests for the service should be
  2238. // sent to this node by control.
  2239. func (v VIPServiceView) Active() bool { return v.ж.Active }
  2240. // A compilation failure here means this code must be regenerated, with the command at the top of this file.
  2241. var _VIPServiceViewNeedsRegeneration = VIPService(struct {
  2242. Name ServiceName
  2243. Ports []ProtoPortRange
  2244. Active bool
  2245. }{})
  2246. // View returns a read-only view of SSHPolicy.
  2247. func (p *SSHPolicy) View() SSHPolicyView {
  2248. return SSHPolicyView{ж: p}
  2249. }
  2250. // SSHPolicyView provides a read-only view over SSHPolicy.
  2251. //
  2252. // Its methods should only be called if `Valid()` returns true.
  2253. type SSHPolicyView struct {
  2254. // ж is the underlying mutable value, named with a hard-to-type
  2255. // character that looks pointy like a pointer.
  2256. // It is named distinctively to make you think of how dangerous it is to escape
  2257. // to callers. You must not let callers be able to mutate it.
  2258. ж *SSHPolicy
  2259. }
  2260. // Valid reports whether v's underlying value is non-nil.
  2261. func (v SSHPolicyView) Valid() bool { return v.ж != nil }
  2262. // AsStruct returns a clone of the underlying value which aliases no memory with
  2263. // the original.
  2264. func (v SSHPolicyView) AsStruct() *SSHPolicy {
  2265. if v.ж == nil {
  2266. return nil
  2267. }
  2268. return v.ж.Clone()
  2269. }
  2270. // MarshalJSON implements [jsonv1.Marshaler].
  2271. func (v SSHPolicyView) MarshalJSON() ([]byte, error) {
  2272. return jsonv1.Marshal(v.ж)
  2273. }
  2274. // MarshalJSONTo implements [jsonv2.MarshalerTo].
  2275. func (v SSHPolicyView) MarshalJSONTo(enc *jsontext.Encoder) error {
  2276. return jsonv2.MarshalEncode(enc, v.ж)
  2277. }
  2278. // UnmarshalJSON implements [jsonv1.Unmarshaler].
  2279. func (v *SSHPolicyView) UnmarshalJSON(b []byte) error {
  2280. if v.ж != nil {
  2281. return errors.New("already initialized")
  2282. }
  2283. if len(b) == 0 {
  2284. return nil
  2285. }
  2286. var x SSHPolicy
  2287. if err := jsonv1.Unmarshal(b, &x); err != nil {
  2288. return err
  2289. }
  2290. v.ж = &x
  2291. return nil
  2292. }
  2293. // UnmarshalJSONFrom implements [jsonv2.UnmarshalerFrom].
  2294. func (v *SSHPolicyView) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
  2295. if v.ж != nil {
  2296. return errors.New("already initialized")
  2297. }
  2298. var x SSHPolicy
  2299. if err := jsonv2.UnmarshalDecode(dec, &x); err != nil {
  2300. return err
  2301. }
  2302. v.ж = &x
  2303. return nil
  2304. }
  2305. // Rules are the rules to process for an incoming SSH connection. The first
  2306. // matching rule takes its action and stops processing further rules.
  2307. //
  2308. // When an incoming connection first starts, all rules are evaluated in
  2309. // "none" auth mode, where the client hasn't even been asked to send a
  2310. // public key. All SSHRule.Principals requiring a public key won't match. If
  2311. // a rule matches on the first pass and its Action is reject, the
  2312. // authentication fails with that action's rejection message, if any.
  2313. //
  2314. // If the first pass rule evaluation matches nothing without matching an
  2315. // Action with Reject set, the rules are considered to see whether public
  2316. // keys might still result in a match. If not, "none" auth is terminated
  2317. // before proceeding to public key mode. If so, the client is asked to try
  2318. // public key authentication and the rules are evaluated again for each of
  2319. // the client's present keys.
  2320. func (v SSHPolicyView) Rules() views.SliceView[*SSHRule, SSHRuleView] {
  2321. return views.SliceOfViews[*SSHRule, SSHRuleView](v.ж.Rules)
  2322. }
  2323. // A compilation failure here means this code must be regenerated, with the command at the top of this file.
  2324. var _SSHPolicyViewNeedsRegeneration = SSHPolicy(struct {
  2325. Rules []*SSHRule
  2326. }{})