ipn_view.go 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014
  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 ipn
  5. import (
  6. jsonv1 "encoding/json"
  7. "errors"
  8. "net/netip"
  9. jsonv2 "github.com/go-json-experiment/json"
  10. "github.com/go-json-experiment/json/jsontext"
  11. "tailscale.com/drive"
  12. "tailscale.com/tailcfg"
  13. "tailscale.com/types/opt"
  14. "tailscale.com/types/persist"
  15. "tailscale.com/types/preftype"
  16. "tailscale.com/types/views"
  17. )
  18. //go:generate go run tailscale.com/cmd/cloner -clonefunc=false -type=LoginProfile,Prefs,ServeConfig,ServiceConfig,TCPPortHandler,HTTPHandler,WebServerConfig
  19. // View returns a read-only view of LoginProfile.
  20. func (p *LoginProfile) View() LoginProfileView {
  21. return LoginProfileView{ж: p}
  22. }
  23. // LoginProfileView provides a read-only view over LoginProfile.
  24. //
  25. // Its methods should only be called if `Valid()` returns true.
  26. type LoginProfileView struct {
  27. // ж is the underlying mutable value, named with a hard-to-type
  28. // character that looks pointy like a pointer.
  29. // It is named distinctively to make you think of how dangerous it is to escape
  30. // to callers. You must not let callers be able to mutate it.
  31. ж *LoginProfile
  32. }
  33. // Valid reports whether v's underlying value is non-nil.
  34. func (v LoginProfileView) Valid() bool { return v.ж != nil }
  35. // AsStruct returns a clone of the underlying value which aliases no memory with
  36. // the original.
  37. func (v LoginProfileView) AsStruct() *LoginProfile {
  38. if v.ж == nil {
  39. return nil
  40. }
  41. return v.ж.Clone()
  42. }
  43. // MarshalJSON implements [jsonv1.Marshaler].
  44. func (v LoginProfileView) MarshalJSON() ([]byte, error) {
  45. return jsonv1.Marshal(v.ж)
  46. }
  47. // MarshalJSONTo implements [jsonv2.MarshalerTo].
  48. func (v LoginProfileView) MarshalJSONTo(enc *jsontext.Encoder) error {
  49. return jsonv2.MarshalEncode(enc, v.ж)
  50. }
  51. // UnmarshalJSON implements [jsonv1.Unmarshaler].
  52. func (v *LoginProfileView) UnmarshalJSON(b []byte) error {
  53. if v.ж != nil {
  54. return errors.New("already initialized")
  55. }
  56. if len(b) == 0 {
  57. return nil
  58. }
  59. var x LoginProfile
  60. if err := jsonv1.Unmarshal(b, &x); err != nil {
  61. return err
  62. }
  63. v.ж = &x
  64. return nil
  65. }
  66. // UnmarshalJSONFrom implements [jsonv2.UnmarshalerFrom].
  67. func (v *LoginProfileView) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
  68. if v.ж != nil {
  69. return errors.New("already initialized")
  70. }
  71. var x LoginProfile
  72. if err := jsonv2.UnmarshalDecode(dec, &x); err != nil {
  73. return err
  74. }
  75. v.ж = &x
  76. return nil
  77. }
  78. // ID is a unique identifier for this profile.
  79. // It is assigned on creation and never changes.
  80. // It may seem redundant to have both ID and UserProfile.ID
  81. // but they are different things. UserProfile.ID may change
  82. // over time (e.g. if a device is tagged).
  83. func (v LoginProfileView) ID() ProfileID { return v.ж.ID }
  84. // Name is the user-visible name of this profile.
  85. // It is filled in from the UserProfile.LoginName field.
  86. func (v LoginProfileView) Name() string { return v.ж.Name }
  87. // NetworkProfile is a subset of netmap.NetworkMap that we
  88. // store to remember information about the tailnet that this
  89. // profile was logged in with.
  90. //
  91. // This field was added on 2023-11-17.
  92. func (v LoginProfileView) NetworkProfile() NetworkProfile { return v.ж.NetworkProfile }
  93. // Key is the StateKey under which the profile is stored.
  94. // It is assigned once at profile creation time and never changes.
  95. func (v LoginProfileView) Key() StateKey { return v.ж.Key }
  96. // UserProfile is the server provided UserProfile for this profile.
  97. // This is updated whenever the server provides a new UserProfile.
  98. func (v LoginProfileView) UserProfile() tailcfg.UserProfile { return v.ж.UserProfile }
  99. // NodeID is the NodeID of the node that this profile is logged into.
  100. // This should be stable across tagging and untagging nodes.
  101. // It may seem redundant to check against both the UserProfile.UserID
  102. // and the NodeID. However the NodeID can change if the node is deleted
  103. // from the admin panel.
  104. func (v LoginProfileView) NodeID() tailcfg.StableNodeID { return v.ж.NodeID }
  105. // LocalUserID is the user ID of the user who created this profile.
  106. // It is only relevant on Windows where we have a multi-user system.
  107. // It is assigned once at profile creation time and never changes.
  108. func (v LoginProfileView) LocalUserID() WindowsUserID { return v.ж.LocalUserID }
  109. // ControlURL is the URL of the control server that this profile is logged
  110. // into.
  111. func (v LoginProfileView) ControlURL() string { return v.ж.ControlURL }
  112. // A compilation failure here means this code must be regenerated, with the command at the top of this file.
  113. var _LoginProfileViewNeedsRegeneration = LoginProfile(struct {
  114. ID ProfileID
  115. Name string
  116. NetworkProfile NetworkProfile
  117. Key StateKey
  118. UserProfile tailcfg.UserProfile
  119. NodeID tailcfg.StableNodeID
  120. LocalUserID WindowsUserID
  121. ControlURL string
  122. }{})
  123. // View returns a read-only view of Prefs.
  124. func (p *Prefs) View() PrefsView {
  125. return PrefsView{ж: p}
  126. }
  127. // PrefsView provides a read-only view over Prefs.
  128. //
  129. // Its methods should only be called if `Valid()` returns true.
  130. type PrefsView struct {
  131. // ж is the underlying mutable value, named with a hard-to-type
  132. // character that looks pointy like a pointer.
  133. // It is named distinctively to make you think of how dangerous it is to escape
  134. // to callers. You must not let callers be able to mutate it.
  135. ж *Prefs
  136. }
  137. // Valid reports whether v's underlying value is non-nil.
  138. func (v PrefsView) Valid() bool { return v.ж != nil }
  139. // AsStruct returns a clone of the underlying value which aliases no memory with
  140. // the original.
  141. func (v PrefsView) AsStruct() *Prefs {
  142. if v.ж == nil {
  143. return nil
  144. }
  145. return v.ж.Clone()
  146. }
  147. // MarshalJSON implements [jsonv1.Marshaler].
  148. func (v PrefsView) MarshalJSON() ([]byte, error) {
  149. return jsonv1.Marshal(v.ж)
  150. }
  151. // MarshalJSONTo implements [jsonv2.MarshalerTo].
  152. func (v PrefsView) MarshalJSONTo(enc *jsontext.Encoder) error {
  153. return jsonv2.MarshalEncode(enc, v.ж)
  154. }
  155. // UnmarshalJSON implements [jsonv1.Unmarshaler].
  156. func (v *PrefsView) UnmarshalJSON(b []byte) error {
  157. if v.ж != nil {
  158. return errors.New("already initialized")
  159. }
  160. if len(b) == 0 {
  161. return nil
  162. }
  163. var x Prefs
  164. if err := jsonv1.Unmarshal(b, &x); err != nil {
  165. return err
  166. }
  167. v.ж = &x
  168. return nil
  169. }
  170. // UnmarshalJSONFrom implements [jsonv2.UnmarshalerFrom].
  171. func (v *PrefsView) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
  172. if v.ж != nil {
  173. return errors.New("already initialized")
  174. }
  175. var x Prefs
  176. if err := jsonv2.UnmarshalDecode(dec, &x); err != nil {
  177. return err
  178. }
  179. v.ж = &x
  180. return nil
  181. }
  182. // ControlURL is the URL of the control server to use.
  183. //
  184. // If empty, the default for new installs, DefaultControlURL
  185. // is used. It's set non-empty once the daemon has been started
  186. // for the first time.
  187. //
  188. // TODO(apenwarr): Make it safe to update this with EditPrefs().
  189. // Right now, you have to pass it in the initial prefs in Start(),
  190. // which is the only code that actually uses the ControlURL value.
  191. // It would be more consistent to restart controlclient
  192. // automatically whenever this variable changes.
  193. //
  194. // Meanwhile, you have to provide this as part of
  195. // Options.LegacyMigrationPrefs or Options.UpdatePrefs when
  196. // calling Backend.Start().
  197. func (v PrefsView) ControlURL() string { return v.ж.ControlURL }
  198. // RouteAll specifies whether to accept subnets advertised by
  199. // other nodes on the Tailscale network. Note that this does not
  200. // include default routes (0.0.0.0/0 and ::/0), those are
  201. // controlled by ExitNodeID/IP below.
  202. func (v PrefsView) RouteAll() bool { return v.ж.RouteAll }
  203. // ExitNodeID and ExitNodeIP specify the node that should be used
  204. // as an exit node for internet traffic. At most one of these
  205. // should be non-zero.
  206. //
  207. // The preferred way to express the chosen node is ExitNodeID, but
  208. // in some cases it's not possible to use that ID (e.g. in the
  209. // linux CLI, before tailscaled has a netmap). For those
  210. // situations, we allow specifying the exit node by IP, and
  211. // ipnlocal.LocalBackend will translate the IP into an ID when the
  212. // node is found in the netmap.
  213. //
  214. // If the selected exit node doesn't exist (e.g. it's not part of
  215. // the current tailnet), or it doesn't offer exit node services, a
  216. // blackhole route will be installed on the local system to
  217. // prevent any traffic escaping to the local network.
  218. func (v PrefsView) ExitNodeID() tailcfg.StableNodeID { return v.ж.ExitNodeID }
  219. func (v PrefsView) ExitNodeIP() netip.Addr { return v.ж.ExitNodeIP }
  220. // AutoExitNode is an optional expression that specifies whether and how
  221. // tailscaled should pick an exit node automatically.
  222. //
  223. // If specified, tailscaled will use an exit node based on the expression,
  224. // and will re-evaluate the selection periodically as network conditions,
  225. // available exit nodes, or policy settings change. A blackhole route will
  226. // be installed to prevent traffic from escaping to the local network until
  227. // an exit node is selected. It takes precedence over ExitNodeID and ExitNodeIP.
  228. //
  229. // If empty, tailscaled will not automatically select an exit node.
  230. //
  231. // If the specified expression is invalid or unsupported by the client,
  232. // it falls back to the behavior of [AnyExitNode].
  233. //
  234. // As of 2025-07-02, the only supported value is [AnyExitNode].
  235. // It's a string rather than a boolean to allow future extensibility
  236. // (e.g., AutoExitNode = "mullvad" or AutoExitNode = "geo:us").
  237. func (v PrefsView) AutoExitNode() ExitNodeExpression { return v.ж.AutoExitNode }
  238. // InternalExitNodePrior is the most recently used ExitNodeID in string form. It is set by
  239. // the backend on transition from exit node on to off and used by the
  240. // backend.
  241. //
  242. // As an Internal field, it can't be set by LocalAPI clients, rather it is set indirectly
  243. // when the ExitNodeID value is zero'd and via the set-use-exit-node-enabled endpoint.
  244. func (v PrefsView) InternalExitNodePrior() tailcfg.StableNodeID { return v.ж.InternalExitNodePrior }
  245. // ExitNodeAllowLANAccess indicates whether locally accessible subnets should be
  246. // routed directly or via the exit node.
  247. func (v PrefsView) ExitNodeAllowLANAccess() bool { return v.ж.ExitNodeAllowLANAccess }
  248. // CorpDNS specifies whether to install the Tailscale network's
  249. // DNS configuration, if it exists.
  250. func (v PrefsView) CorpDNS() bool { return v.ж.CorpDNS }
  251. // RunSSH bool is whether this node should run an SSH
  252. // server, permitting access to peers according to the
  253. // policies as configured by the Tailnet's admin(s).
  254. func (v PrefsView) RunSSH() bool { return v.ж.RunSSH }
  255. // RunWebClient bool is whether this node should expose
  256. // its web client over Tailscale at port 5252,
  257. // permitting access to peers according to the
  258. // policies as configured by the Tailnet's admin(s).
  259. func (v PrefsView) RunWebClient() bool { return v.ж.RunWebClient }
  260. // WantRunning indicates whether networking should be active on
  261. // this node.
  262. func (v PrefsView) WantRunning() bool { return v.ж.WantRunning }
  263. // LoggedOut indicates whether the user intends to be logged out.
  264. // There are other reasons we may be logged out, including no valid
  265. // keys.
  266. // We need to remember this state so that, on next startup, we can
  267. // generate the "Login" vs "Connect" buttons correctly, without having
  268. // to contact the server to confirm our nodekey status first.
  269. func (v PrefsView) LoggedOut() bool { return v.ж.LoggedOut }
  270. // ShieldsUp indicates whether to block all incoming connections,
  271. // regardless of the control-provided packet filter. If false, we
  272. // use the packet filter as provided. If true, we block incoming
  273. // connections. This overrides tailcfg.Hostinfo's ShieldsUp.
  274. func (v PrefsView) ShieldsUp() bool { return v.ж.ShieldsUp }
  275. // AdvertiseTags specifies tags that should be applied to this node, for
  276. // purposes of ACL enforcement. These can be referenced from the ACL policy
  277. // document. Note that advertising a tag on the client doesn't guarantee
  278. // that the control server will allow the node to adopt that tag.
  279. func (v PrefsView) AdvertiseTags() views.Slice[string] { return views.SliceOf(v.ж.AdvertiseTags) }
  280. // Hostname is the hostname to use for identifying the node. If
  281. // not set, os.Hostname is used.
  282. func (v PrefsView) Hostname() string { return v.ж.Hostname }
  283. // NotepadURLs is a debugging setting that opens OAuth URLs in
  284. // notepad.exe on Windows, rather than loading them in a browser.
  285. //
  286. // apenwarr 2020-04-29: Unfortunately this is still needed sometimes.
  287. // Windows' default browser setting is sometimes screwy and this helps
  288. // users narrow it down a bit.
  289. func (v PrefsView) NotepadURLs() bool { return v.ж.NotepadURLs }
  290. // ForceDaemon specifies whether a platform that normally
  291. // operates in "client mode" (that is, requires an active user
  292. // logged in with the GUI app running) should keep running after the
  293. // GUI ends and/or the user logs out.
  294. //
  295. // The only current applicable platform is Windows. This
  296. // forced Windows to go into "server mode" where Tailscale is
  297. // running even with no users logged in. This might also be
  298. // used for macOS in the future. This setting has no effect
  299. // for Linux/etc, which always operate in daemon mode.
  300. func (v PrefsView) ForceDaemon() bool { return v.ж.ForceDaemon }
  301. // Egg is a optional debug flag.
  302. func (v PrefsView) Egg() bool { return v.ж.Egg }
  303. // AdvertiseRoutes specifies CIDR prefixes to advertise into the
  304. // Tailscale network as reachable through the current
  305. // node.
  306. func (v PrefsView) AdvertiseRoutes() views.Slice[netip.Prefix] {
  307. return views.SliceOf(v.ж.AdvertiseRoutes)
  308. }
  309. // AdvertiseServices specifies the list of services that this
  310. // node can serve as a destination for. Note that an advertised
  311. // service must still go through the approval process from the
  312. // control server.
  313. func (v PrefsView) AdvertiseServices() views.Slice[string] {
  314. return views.SliceOf(v.ж.AdvertiseServices)
  315. }
  316. // Sync is whether this node should sync its configuration from
  317. // the control plane. If unset, this defaults to true.
  318. // This exists primarily for testing, to verify that netmap caching
  319. // and offline operation work correctly.
  320. func (v PrefsView) Sync() opt.Bool { return v.ж.Sync }
  321. // NoSNAT specifies whether to source NAT traffic going to
  322. // destinations in AdvertiseRoutes. The default is to apply source
  323. // NAT, which makes the traffic appear to come from the router
  324. // machine rather than the peer's Tailscale IP.
  325. //
  326. // Disabling SNAT requires additional manual configuration in your
  327. // network to route Tailscale traffic back to the subnet relay
  328. // machine.
  329. //
  330. // Linux-only.
  331. func (v PrefsView) NoSNAT() bool { return v.ж.NoSNAT }
  332. // NoStatefulFiltering specifies whether to apply stateful filtering when
  333. // advertising routes in AdvertiseRoutes. The default is to not apply
  334. // stateful filtering.
  335. //
  336. // To allow inbound connections from advertised routes, both NoSNAT and
  337. // NoStatefulFiltering must be true.
  338. //
  339. // This is an opt.Bool because it was first added after NoSNAT, with a
  340. // backfill based on the value of that parameter. The backfill has been
  341. // removed since then, but the field remains an opt.Bool.
  342. //
  343. // Linux-only.
  344. func (v PrefsView) NoStatefulFiltering() opt.Bool { return v.ж.NoStatefulFiltering }
  345. // NetfilterMode specifies how much to manage netfilter rules for
  346. // Tailscale, if at all.
  347. func (v PrefsView) NetfilterMode() preftype.NetfilterMode { return v.ж.NetfilterMode }
  348. // OperatorUser is the local machine user name who is allowed to
  349. // operate tailscaled without being root or using sudo.
  350. func (v PrefsView) OperatorUser() string { return v.ж.OperatorUser }
  351. // ProfileName is the desired name of the profile. If empty, then the user's
  352. // LoginName is used. It is only used for display purposes in the client UI
  353. // and CLI.
  354. func (v PrefsView) ProfileName() string { return v.ж.ProfileName }
  355. // AutoUpdate sets the auto-update preferences for the node agent. See
  356. // AutoUpdatePrefs docs for more details.
  357. func (v PrefsView) AutoUpdate() AutoUpdatePrefs { return v.ж.AutoUpdate }
  358. // AppConnector sets the app connector preferences for the node agent. See
  359. // AppConnectorPrefs docs for more details.
  360. func (v PrefsView) AppConnector() AppConnectorPrefs { return v.ж.AppConnector }
  361. // PostureChecking enables the collection of information used for device
  362. // posture checks.
  363. //
  364. // Note: this should be named ReportPosture, but it was shipped as
  365. // PostureChecking in some early releases and this JSON field is written to
  366. // disk, so we just keep its old name. (akin to CorpDNS which is an internal
  367. // pref name that doesn't match the public interface)
  368. func (v PrefsView) PostureChecking() bool { return v.ж.PostureChecking }
  369. // NetfilterKind specifies what netfilter implementation to use.
  370. //
  371. // It can be "iptables", "nftables", or "" to auto-detect.
  372. //
  373. // Linux-only.
  374. func (v PrefsView) NetfilterKind() string { return v.ж.NetfilterKind }
  375. // DriveShares are the configured DriveShares, stored in increasing order
  376. // by name.
  377. func (v PrefsView) DriveShares() views.SliceView[*drive.Share, drive.ShareView] {
  378. return views.SliceOfViews[*drive.Share, drive.ShareView](v.ж.DriveShares)
  379. }
  380. // RelayServerPort is the UDP port number for the relay server to bind to,
  381. // on all interfaces. A non-nil zero value signifies a random unused port
  382. // should be used. A nil value signifies relay server functionality
  383. // should be disabled.
  384. func (v PrefsView) RelayServerPort() views.ValuePointer[uint16] {
  385. return views.ValuePointerOf(v.ж.RelayServerPort)
  386. }
  387. // RelayServerStaticEndpoints are static IP:port endpoints to advertise as
  388. // candidates for relay connections. Only relevant when RelayServerPort is
  389. // non-nil.
  390. func (v PrefsView) RelayServerStaticEndpoints() views.Slice[netip.AddrPort] {
  391. return views.SliceOf(v.ж.RelayServerStaticEndpoints)
  392. }
  393. // AllowSingleHosts was a legacy field that was always true
  394. // for the past 4.5 years. It controlled whether Tailscale
  395. // peers got /32 or /128 routes for each other.
  396. // As of 2024-05-17 we're starting to ignore it, but to let
  397. // people still downgrade Tailscale versions and not break
  398. // all peer-to-peer networking we still write it to disk (as JSON)
  399. // so it can be loaded back by old versions.
  400. // TODO(bradfitz): delete this in 2025 sometime. See #12058.
  401. func (v PrefsView) AllowSingleHosts() marshalAsTrueInJSON { return v.ж.AllowSingleHosts }
  402. // The Persist field is named 'Config' in the file for backward
  403. // compatibility with earlier versions.
  404. // TODO(apenwarr): We should move this out of here, it's not a pref.
  405. //
  406. // We can maybe do that once we're sure which module should persist
  407. // it (backend or frontend?)
  408. func (v PrefsView) Persist() persist.PersistView { return v.ж.Persist.View() }
  409. // A compilation failure here means this code must be regenerated, with the command at the top of this file.
  410. var _PrefsViewNeedsRegeneration = Prefs(struct {
  411. ControlURL string
  412. RouteAll bool
  413. ExitNodeID tailcfg.StableNodeID
  414. ExitNodeIP netip.Addr
  415. AutoExitNode ExitNodeExpression
  416. InternalExitNodePrior tailcfg.StableNodeID
  417. ExitNodeAllowLANAccess bool
  418. CorpDNS bool
  419. RunSSH bool
  420. RunWebClient bool
  421. WantRunning bool
  422. LoggedOut bool
  423. ShieldsUp bool
  424. AdvertiseTags []string
  425. Hostname string
  426. NotepadURLs bool
  427. ForceDaemon bool
  428. Egg bool
  429. AdvertiseRoutes []netip.Prefix
  430. AdvertiseServices []string
  431. Sync opt.Bool
  432. NoSNAT bool
  433. NoStatefulFiltering opt.Bool
  434. NetfilterMode preftype.NetfilterMode
  435. OperatorUser string
  436. ProfileName string
  437. AutoUpdate AutoUpdatePrefs
  438. AppConnector AppConnectorPrefs
  439. PostureChecking bool
  440. NetfilterKind string
  441. DriveShares []*drive.Share
  442. RelayServerPort *uint16
  443. RelayServerStaticEndpoints []netip.AddrPort
  444. AllowSingleHosts marshalAsTrueInJSON
  445. Persist *persist.Persist
  446. }{})
  447. // View returns a read-only view of ServeConfig.
  448. func (p *ServeConfig) View() ServeConfigView {
  449. return ServeConfigView{ж: p}
  450. }
  451. // ServeConfigView provides a read-only view over ServeConfig.
  452. //
  453. // Its methods should only be called if `Valid()` returns true.
  454. type ServeConfigView struct {
  455. // ж is the underlying mutable value, named with a hard-to-type
  456. // character that looks pointy like a pointer.
  457. // It is named distinctively to make you think of how dangerous it is to escape
  458. // to callers. You must not let callers be able to mutate it.
  459. ж *ServeConfig
  460. }
  461. // Valid reports whether v's underlying value is non-nil.
  462. func (v ServeConfigView) Valid() bool { return v.ж != nil }
  463. // AsStruct returns a clone of the underlying value which aliases no memory with
  464. // the original.
  465. func (v ServeConfigView) AsStruct() *ServeConfig {
  466. if v.ж == nil {
  467. return nil
  468. }
  469. return v.ж.Clone()
  470. }
  471. // MarshalJSON implements [jsonv1.Marshaler].
  472. func (v ServeConfigView) MarshalJSON() ([]byte, error) {
  473. return jsonv1.Marshal(v.ж)
  474. }
  475. // MarshalJSONTo implements [jsonv2.MarshalerTo].
  476. func (v ServeConfigView) MarshalJSONTo(enc *jsontext.Encoder) error {
  477. return jsonv2.MarshalEncode(enc, v.ж)
  478. }
  479. // UnmarshalJSON implements [jsonv1.Unmarshaler].
  480. func (v *ServeConfigView) UnmarshalJSON(b []byte) error {
  481. if v.ж != nil {
  482. return errors.New("already initialized")
  483. }
  484. if len(b) == 0 {
  485. return nil
  486. }
  487. var x ServeConfig
  488. if err := jsonv1.Unmarshal(b, &x); err != nil {
  489. return err
  490. }
  491. v.ж = &x
  492. return nil
  493. }
  494. // UnmarshalJSONFrom implements [jsonv2.UnmarshalerFrom].
  495. func (v *ServeConfigView) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
  496. if v.ж != nil {
  497. return errors.New("already initialized")
  498. }
  499. var x ServeConfig
  500. if err := jsonv2.UnmarshalDecode(dec, &x); err != nil {
  501. return err
  502. }
  503. v.ж = &x
  504. return nil
  505. }
  506. // TCP are the list of TCP port numbers that tailscaled should handle for
  507. // the Tailscale IP addresses. (not subnet routers, etc)
  508. func (v ServeConfigView) TCP() views.MapFn[uint16, *TCPPortHandler, TCPPortHandlerView] {
  509. return views.MapFnOf(v.ж.TCP, func(t *TCPPortHandler) TCPPortHandlerView {
  510. return t.View()
  511. })
  512. }
  513. // Web maps from "$SNI_NAME:$PORT" to a set of HTTP handlers
  514. // keyed by mount point ("/", "/foo", etc)
  515. func (v ServeConfigView) Web() views.MapFn[HostPort, *WebServerConfig, WebServerConfigView] {
  516. return views.MapFnOf(v.ж.Web, func(t *WebServerConfig) WebServerConfigView {
  517. return t.View()
  518. })
  519. }
  520. // Services maps from service name (in the form "svc:dns-label") to a ServiceConfig.
  521. // Which describes the L3, L4, and L7 forwarding information for the service.
  522. func (v ServeConfigView) Services() views.MapFn[tailcfg.ServiceName, *ServiceConfig, ServiceConfigView] {
  523. return views.MapFnOf(v.ж.Services, func(t *ServiceConfig) ServiceConfigView {
  524. return t.View()
  525. })
  526. }
  527. // AllowFunnel is the set of SNI:port values for which funnel
  528. // traffic is allowed, from trusted ingress peers.
  529. func (v ServeConfigView) AllowFunnel() views.Map[HostPort, bool] {
  530. return views.MapOf(v.ж.AllowFunnel)
  531. }
  532. // Foreground is a map of an IPN Bus session ID to an alternate foreground serve config that's valid for the
  533. // life of that WatchIPNBus session ID. This allows the config to specify ephemeral configs that are used
  534. // in the CLI's foreground mode to ensure ungraceful shutdowns of either the client or the LocalBackend does not
  535. // expose ports that users are not aware of. In practice this contains any serve config set via 'tailscale
  536. // serve' command run without the '--bg' flag. ServeConfig contained by Foreground is not expected itself to contain
  537. // another Foreground block.
  538. func (v ServeConfigView) Foreground() views.MapFn[string, *ServeConfig, ServeConfigView] {
  539. return views.MapFnOf(v.ж.Foreground, func(t *ServeConfig) ServeConfigView {
  540. return t.View()
  541. })
  542. }
  543. // ETag is the checksum of the serve config that's populated
  544. // by the LocalClient through the HTTP ETag header during a
  545. // GetServeConfig request and is translated to an If-Match header
  546. // during a SetServeConfig request.
  547. func (v ServeConfigView) ETag() string { return v.ж.ETag }
  548. // A compilation failure here means this code must be regenerated, with the command at the top of this file.
  549. var _ServeConfigViewNeedsRegeneration = ServeConfig(struct {
  550. TCP map[uint16]*TCPPortHandler
  551. Web map[HostPort]*WebServerConfig
  552. Services map[tailcfg.ServiceName]*ServiceConfig
  553. AllowFunnel map[HostPort]bool
  554. Foreground map[string]*ServeConfig
  555. ETag string
  556. }{})
  557. // View returns a read-only view of ServiceConfig.
  558. func (p *ServiceConfig) View() ServiceConfigView {
  559. return ServiceConfigView{ж: p}
  560. }
  561. // ServiceConfigView provides a read-only view over ServiceConfig.
  562. //
  563. // Its methods should only be called if `Valid()` returns true.
  564. type ServiceConfigView struct {
  565. // ж is the underlying mutable value, named with a hard-to-type
  566. // character that looks pointy like a pointer.
  567. // It is named distinctively to make you think of how dangerous it is to escape
  568. // to callers. You must not let callers be able to mutate it.
  569. ж *ServiceConfig
  570. }
  571. // Valid reports whether v's underlying value is non-nil.
  572. func (v ServiceConfigView) Valid() bool { return v.ж != nil }
  573. // AsStruct returns a clone of the underlying value which aliases no memory with
  574. // the original.
  575. func (v ServiceConfigView) AsStruct() *ServiceConfig {
  576. if v.ж == nil {
  577. return nil
  578. }
  579. return v.ж.Clone()
  580. }
  581. // MarshalJSON implements [jsonv1.Marshaler].
  582. func (v ServiceConfigView) MarshalJSON() ([]byte, error) {
  583. return jsonv1.Marshal(v.ж)
  584. }
  585. // MarshalJSONTo implements [jsonv2.MarshalerTo].
  586. func (v ServiceConfigView) MarshalJSONTo(enc *jsontext.Encoder) error {
  587. return jsonv2.MarshalEncode(enc, v.ж)
  588. }
  589. // UnmarshalJSON implements [jsonv1.Unmarshaler].
  590. func (v *ServiceConfigView) UnmarshalJSON(b []byte) error {
  591. if v.ж != nil {
  592. return errors.New("already initialized")
  593. }
  594. if len(b) == 0 {
  595. return nil
  596. }
  597. var x ServiceConfig
  598. if err := jsonv1.Unmarshal(b, &x); err != nil {
  599. return err
  600. }
  601. v.ж = &x
  602. return nil
  603. }
  604. // UnmarshalJSONFrom implements [jsonv2.UnmarshalerFrom].
  605. func (v *ServiceConfigView) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
  606. if v.ж != nil {
  607. return errors.New("already initialized")
  608. }
  609. var x ServiceConfig
  610. if err := jsonv2.UnmarshalDecode(dec, &x); err != nil {
  611. return err
  612. }
  613. v.ж = &x
  614. return nil
  615. }
  616. // TCP are the list of TCP port numbers that tailscaled should handle for
  617. // the Tailscale IP addresses. (not subnet routers, etc)
  618. func (v ServiceConfigView) TCP() views.MapFn[uint16, *TCPPortHandler, TCPPortHandlerView] {
  619. return views.MapFnOf(v.ж.TCP, func(t *TCPPortHandler) TCPPortHandlerView {
  620. return t.View()
  621. })
  622. }
  623. // Web maps from "$SNI_NAME:$PORT" to a set of HTTP handlers
  624. // keyed by mount point ("/", "/foo", etc)
  625. func (v ServiceConfigView) Web() views.MapFn[HostPort, *WebServerConfig, WebServerConfigView] {
  626. return views.MapFnOf(v.ж.Web, func(t *WebServerConfig) WebServerConfigView {
  627. return t.View()
  628. })
  629. }
  630. // Tun determines if the service should be using L3 forwarding (Tun mode).
  631. func (v ServiceConfigView) Tun() bool { return v.ж.Tun }
  632. // A compilation failure here means this code must be regenerated, with the command at the top of this file.
  633. var _ServiceConfigViewNeedsRegeneration = ServiceConfig(struct {
  634. TCP map[uint16]*TCPPortHandler
  635. Web map[HostPort]*WebServerConfig
  636. Tun bool
  637. }{})
  638. // View returns a read-only view of TCPPortHandler.
  639. func (p *TCPPortHandler) View() TCPPortHandlerView {
  640. return TCPPortHandlerView{ж: p}
  641. }
  642. // TCPPortHandlerView provides a read-only view over TCPPortHandler.
  643. //
  644. // Its methods should only be called if `Valid()` returns true.
  645. type TCPPortHandlerView struct {
  646. // ж is the underlying mutable value, named with a hard-to-type
  647. // character that looks pointy like a pointer.
  648. // It is named distinctively to make you think of how dangerous it is to escape
  649. // to callers. You must not let callers be able to mutate it.
  650. ж *TCPPortHandler
  651. }
  652. // Valid reports whether v's underlying value is non-nil.
  653. func (v TCPPortHandlerView) Valid() bool { return v.ж != nil }
  654. // AsStruct returns a clone of the underlying value which aliases no memory with
  655. // the original.
  656. func (v TCPPortHandlerView) AsStruct() *TCPPortHandler {
  657. if v.ж == nil {
  658. return nil
  659. }
  660. return v.ж.Clone()
  661. }
  662. // MarshalJSON implements [jsonv1.Marshaler].
  663. func (v TCPPortHandlerView) MarshalJSON() ([]byte, error) {
  664. return jsonv1.Marshal(v.ж)
  665. }
  666. // MarshalJSONTo implements [jsonv2.MarshalerTo].
  667. func (v TCPPortHandlerView) MarshalJSONTo(enc *jsontext.Encoder) error {
  668. return jsonv2.MarshalEncode(enc, v.ж)
  669. }
  670. // UnmarshalJSON implements [jsonv1.Unmarshaler].
  671. func (v *TCPPortHandlerView) UnmarshalJSON(b []byte) error {
  672. if v.ж != nil {
  673. return errors.New("already initialized")
  674. }
  675. if len(b) == 0 {
  676. return nil
  677. }
  678. var x TCPPortHandler
  679. if err := jsonv1.Unmarshal(b, &x); err != nil {
  680. return err
  681. }
  682. v.ж = &x
  683. return nil
  684. }
  685. // UnmarshalJSONFrom implements [jsonv2.UnmarshalerFrom].
  686. func (v *TCPPortHandlerView) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
  687. if v.ж != nil {
  688. return errors.New("already initialized")
  689. }
  690. var x TCPPortHandler
  691. if err := jsonv2.UnmarshalDecode(dec, &x); err != nil {
  692. return err
  693. }
  694. v.ж = &x
  695. return nil
  696. }
  697. // HTTPS, if true, means that tailscaled should handle this connection as an
  698. // HTTPS request as configured by ServeConfig.Web.
  699. //
  700. // It is mutually exclusive with TCPForward.
  701. func (v TCPPortHandlerView) HTTPS() bool { return v.ж.HTTPS }
  702. // HTTP, if true, means that tailscaled should handle this connection as an
  703. // HTTP request as configured by ServeConfig.Web.
  704. //
  705. // It is mutually exclusive with TCPForward.
  706. func (v TCPPortHandlerView) HTTP() bool { return v.ж.HTTP }
  707. // TCPForward is the IP:port to forward TCP connections to.
  708. // Whether or not TLS is terminated by tailscaled depends on
  709. // TerminateTLS.
  710. //
  711. // It is mutually exclusive with HTTPS.
  712. func (v TCPPortHandlerView) TCPForward() string { return v.ж.TCPForward }
  713. // TerminateTLS, if non-empty, means that tailscaled should terminate the
  714. // TLS connections before forwarding them to TCPForward, permitting only the
  715. // SNI name with this value. It is only used if TCPForward is non-empty.
  716. // (the HTTPS mode uses ServeConfig.Web)
  717. func (v TCPPortHandlerView) TerminateTLS() string { return v.ж.TerminateTLS }
  718. // ProxyProtocol indicates whether to send a PROXY protocol header
  719. // before forwarding the connection to TCPForward.
  720. //
  721. // This is only valid if TCPForward is non-empty.
  722. func (v TCPPortHandlerView) ProxyProtocol() int { return v.ж.ProxyProtocol }
  723. // A compilation failure here means this code must be regenerated, with the command at the top of this file.
  724. var _TCPPortHandlerViewNeedsRegeneration = TCPPortHandler(struct {
  725. HTTPS bool
  726. HTTP bool
  727. TCPForward string
  728. TerminateTLS string
  729. ProxyProtocol int
  730. }{})
  731. // View returns a read-only view of HTTPHandler.
  732. func (p *HTTPHandler) View() HTTPHandlerView {
  733. return HTTPHandlerView{ж: p}
  734. }
  735. // HTTPHandlerView provides a read-only view over HTTPHandler.
  736. //
  737. // Its methods should only be called if `Valid()` returns true.
  738. type HTTPHandlerView struct {
  739. // ж is the underlying mutable value, named with a hard-to-type
  740. // character that looks pointy like a pointer.
  741. // It is named distinctively to make you think of how dangerous it is to escape
  742. // to callers. You must not let callers be able to mutate it.
  743. ж *HTTPHandler
  744. }
  745. // Valid reports whether v's underlying value is non-nil.
  746. func (v HTTPHandlerView) Valid() bool { return v.ж != nil }
  747. // AsStruct returns a clone of the underlying value which aliases no memory with
  748. // the original.
  749. func (v HTTPHandlerView) AsStruct() *HTTPHandler {
  750. if v.ж == nil {
  751. return nil
  752. }
  753. return v.ж.Clone()
  754. }
  755. // MarshalJSON implements [jsonv1.Marshaler].
  756. func (v HTTPHandlerView) MarshalJSON() ([]byte, error) {
  757. return jsonv1.Marshal(v.ж)
  758. }
  759. // MarshalJSONTo implements [jsonv2.MarshalerTo].
  760. func (v HTTPHandlerView) MarshalJSONTo(enc *jsontext.Encoder) error {
  761. return jsonv2.MarshalEncode(enc, v.ж)
  762. }
  763. // UnmarshalJSON implements [jsonv1.Unmarshaler].
  764. func (v *HTTPHandlerView) UnmarshalJSON(b []byte) error {
  765. if v.ж != nil {
  766. return errors.New("already initialized")
  767. }
  768. if len(b) == 0 {
  769. return nil
  770. }
  771. var x HTTPHandler
  772. if err := jsonv1.Unmarshal(b, &x); err != nil {
  773. return err
  774. }
  775. v.ж = &x
  776. return nil
  777. }
  778. // UnmarshalJSONFrom implements [jsonv2.UnmarshalerFrom].
  779. func (v *HTTPHandlerView) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
  780. if v.ж != nil {
  781. return errors.New("already initialized")
  782. }
  783. var x HTTPHandler
  784. if err := jsonv2.UnmarshalDecode(dec, &x); err != nil {
  785. return err
  786. }
  787. v.ж = &x
  788. return nil
  789. }
  790. // absolute path to directory or file to serve
  791. func (v HTTPHandlerView) Path() string { return v.ж.Path }
  792. // http://localhost:3000/, localhost:3030, 3030
  793. func (v HTTPHandlerView) Proxy() string { return v.ж.Proxy }
  794. // plaintext to serve (primarily for testing)
  795. func (v HTTPHandlerView) Text() string { return v.ж.Text }
  796. // peer capabilities to forward in grant header, e.g. example.com/cap/mon
  797. func (v HTTPHandlerView) AcceptAppCaps() views.Slice[tailcfg.PeerCapability] {
  798. return views.SliceOf(v.ж.AcceptAppCaps)
  799. }
  800. // Redirect, if not empty, is the target URL to redirect requests to.
  801. // By default, we redirect with HTTP 302 (Found) status.
  802. // If Redirect starts with '<httpcode>:', then we use that status instead.
  803. //
  804. // The target URL supports the following expansion variables:
  805. // - ${HOST}: replaced with the request's Host header value
  806. // - ${REQUEST_URI}: replaced with the request's full URI (path and query string)
  807. func (v HTTPHandlerView) Redirect() string { return v.ж.Redirect }
  808. // A compilation failure here means this code must be regenerated, with the command at the top of this file.
  809. var _HTTPHandlerViewNeedsRegeneration = HTTPHandler(struct {
  810. Path string
  811. Proxy string
  812. Text string
  813. AcceptAppCaps []tailcfg.PeerCapability
  814. Redirect string
  815. }{})
  816. // View returns a read-only view of WebServerConfig.
  817. func (p *WebServerConfig) View() WebServerConfigView {
  818. return WebServerConfigView{ж: p}
  819. }
  820. // WebServerConfigView provides a read-only view over WebServerConfig.
  821. //
  822. // Its methods should only be called if `Valid()` returns true.
  823. type WebServerConfigView struct {
  824. // ж is the underlying mutable value, named with a hard-to-type
  825. // character that looks pointy like a pointer.
  826. // It is named distinctively to make you think of how dangerous it is to escape
  827. // to callers. You must not let callers be able to mutate it.
  828. ж *WebServerConfig
  829. }
  830. // Valid reports whether v's underlying value is non-nil.
  831. func (v WebServerConfigView) Valid() bool { return v.ж != nil }
  832. // AsStruct returns a clone of the underlying value which aliases no memory with
  833. // the original.
  834. func (v WebServerConfigView) AsStruct() *WebServerConfig {
  835. if v.ж == nil {
  836. return nil
  837. }
  838. return v.ж.Clone()
  839. }
  840. // MarshalJSON implements [jsonv1.Marshaler].
  841. func (v WebServerConfigView) MarshalJSON() ([]byte, error) {
  842. return jsonv1.Marshal(v.ж)
  843. }
  844. // MarshalJSONTo implements [jsonv2.MarshalerTo].
  845. func (v WebServerConfigView) MarshalJSONTo(enc *jsontext.Encoder) error {
  846. return jsonv2.MarshalEncode(enc, v.ж)
  847. }
  848. // UnmarshalJSON implements [jsonv1.Unmarshaler].
  849. func (v *WebServerConfigView) UnmarshalJSON(b []byte) error {
  850. if v.ж != nil {
  851. return errors.New("already initialized")
  852. }
  853. if len(b) == 0 {
  854. return nil
  855. }
  856. var x WebServerConfig
  857. if err := jsonv1.Unmarshal(b, &x); err != nil {
  858. return err
  859. }
  860. v.ж = &x
  861. return nil
  862. }
  863. // UnmarshalJSONFrom implements [jsonv2.UnmarshalerFrom].
  864. func (v *WebServerConfigView) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
  865. if v.ж != nil {
  866. return errors.New("already initialized")
  867. }
  868. var x WebServerConfig
  869. if err := jsonv2.UnmarshalDecode(dec, &x); err != nil {
  870. return err
  871. }
  872. v.ж = &x
  873. return nil
  874. }
  875. // mountPoint => handler
  876. func (v WebServerConfigView) Handlers() views.MapFn[string, *HTTPHandler, HTTPHandlerView] {
  877. return views.MapFnOf(v.ж.Handlers, func(t *HTTPHandler) HTTPHandlerView {
  878. return t.View()
  879. })
  880. }
  881. // A compilation failure here means this code must be regenerated, with the command at the top of this file.
  882. var _WebServerConfigViewNeedsRegeneration = WebServerConfig(struct {
  883. Handlers map[string]*HTTPHandler
  884. }{})