@@ -10,7 +10,6 @@ import (
1010 "context"
1111 "crypto/sha256"
1212 "encoding/binary"
13- "encoding/hex"
1413 "encoding/json"
1514 "errors"
1615 "fmt"
@@ -5487,20 +5486,9 @@ func (b *LocalBackend) applyPrefsToHostinfoLocked(hi *tailcfg.Hostinfo, prefs ip
54875486 }
54885487 hi .SSH_HostKeys = sshHostKeys
54895488
5490- hi .ServicesHash = b .vipServiceHash (b .vipServicesFromPrefsLocked (prefs ))
5491-
5492- // The Hostinfo.IngressEnabled field is used to communicate to control whether
5493- // the node has funnel enabled.
5494- hi .IngressEnabled = b .hasIngressEnabledLocked ()
5495- // The Hostinfo.WantIngress field tells control whether the user intends
5496- // to use funnel with this node even though it is not currently enabled.
5497- // This is an optimization to control- Funnel requires creation of DNS
5498- // records and because DNS propagation can take time, we want to ensure
5499- // that the records exist for any node that intends to use funnel even
5500- // if it's not enabled. If hi.IngressEnabled is true, control knows that
5501- // DNS records are needed, so we can save bandwidth and not send
5502- // WireIngress.
5503- hi .WireIngress = b .shouldWireInactiveIngressLocked ()
5489+ for _ , f := range hookMaybeMutateHostinfoLocked {
5490+ f (b , hi , prefs )
5491+ }
55045492
55055493 if buildfeatures .HasAppConnectors {
55065494 hi .AppConnector .Set (prefs .AppConnector ().Advertise )
@@ -6284,36 +6272,34 @@ func (b *LocalBackend) setTCPPortsInterceptedFromNetmapAndPrefsLocked(prefs ipn.
62846272 }
62856273
62866274 // Update funnel and service hash info in hostinfo and kick off control update if needed.
6287- b .updateIngressAndServiceHashLocked (prefs )
6275+ b .maybeSentHostinfoIfChangedLocked (prefs )
62886276 b .setTCPPortsIntercepted (handlePorts )
62896277}
62906278
6291- // updateIngressAndServiceHashLocked updates the hostinfo.ServicesHash, hostinfo.WireIngress and
6279+ // hookMaybeMutateHostinfoLocked is a hook that allows conditional features
6280+ // to mutate the provided hostinfo before it is sent to control.
6281+ //
6282+ // The hook function should return true if it mutated the hostinfo.
6283+ //
6284+ // The LocalBackend's mutex is held while calling.
6285+ var hookMaybeMutateHostinfoLocked feature.Hooks [func (* LocalBackend , * tailcfg.Hostinfo , ipn.PrefsView ) bool ]
6286+
6287+ // maybeSentHostinfoIfChangedLocked updates the hostinfo.ServicesHash, hostinfo.WireIngress and
62926288// hostinfo.IngressEnabled fields and kicks off a Hostinfo update if the values have changed.
62936289//
62946290// b.mu must be held.
6295- func (b * LocalBackend ) updateIngressAndServiceHashLocked (prefs ipn.PrefsView ) {
6291+ func (b * LocalBackend ) maybeSentHostinfoIfChangedLocked (prefs ipn.PrefsView ) {
62966292 if b .hostinfo == nil {
62976293 return
62986294 }
6299- hostInfoChanged := false
6300- if ie := b .hasIngressEnabledLocked (); b .hostinfo .IngressEnabled != ie {
6301- b .logf ("Hostinfo.IngressEnabled changed to %v" , ie )
6302- b .hostinfo .IngressEnabled = ie
6303- hostInfoChanged = true
6304- }
6305- if wire := b .shouldWireInactiveIngressLocked (); b .hostinfo .WireIngress != wire {
6306- b .logf ("Hostinfo.WireIngress changed to %v" , wire )
6307- b .hostinfo .WireIngress = wire
6308- hostInfoChanged = true
6309- }
6310- latestHash := b .vipServiceHash (b .vipServicesFromPrefsLocked (prefs ))
6311- if b .hostinfo .ServicesHash != latestHash {
6312- b .hostinfo .ServicesHash = latestHash
6313- hostInfoChanged = true
6295+ changed := false
6296+ for _ , f := range hookMaybeMutateHostinfoLocked {
6297+ if f (b , b .hostinfo , prefs ) {
6298+ changed = true
6299+ }
63146300 }
63156301 // Kick off a Hostinfo update to control if ingress status has changed.
6316- if hostInfoChanged {
6302+ if changed {
63176303 b .goTracker .Go (b .doSetHostinfoFilterServices )
63186304 }
63196305}
@@ -7707,19 +7693,6 @@ func maybeUsernameOf(actor ipnauth.Actor) string {
77077693 return username
77087694}
77097695
7710- func (b * LocalBackend ) vipServiceHash (services []* tailcfg.VIPService ) string {
7711- if len (services ) == 0 {
7712- return ""
7713- }
7714- buf , err := json .Marshal (services )
7715- if err != nil {
7716- b .logf ("vipServiceHashLocked: %v" , err )
7717- return ""
7718- }
7719- hash := sha256 .Sum256 (buf )
7720- return hex .EncodeToString (hash [:])
7721- }
7722-
77237696var (
77247697 metricCurrentWatchIPNBus = clientmetric .NewGauge ("localbackend_current_watch_ipn_bus" )
77257698)
0 commit comments