tailcfg,ipn/ipnlocal: add hostinfo field to replace service entry

Updates tailscale/corp#15437
Signed-off-by: James Tucker <james@tailscale.com>
pull/10203/head
James Tucker 1 year ago committed by James Tucker
parent 1f4a38ed49
commit 0b6636295e

@ -1544,6 +1544,7 @@ func (b *LocalBackend) Start(opts ipn.Options) error {
hostinfo.FrontendLogID = opts.FrontendLogID hostinfo.FrontendLogID = opts.FrontendLogID
hostinfo.Userspace.Set(b.sys.IsNetstack()) hostinfo.Userspace.Set(b.sys.IsNetstack())
hostinfo.UserspaceRouter.Set(b.sys.IsNetstackRouter()) hostinfo.UserspaceRouter.Set(b.sys.IsNetstackRouter())
hostinfo.AppConnector.Set(b.appConnector != nil)
b.logf.JSON(1, "Hostinfo", hostinfo) b.logf.JSON(1, "Hostinfo", hostinfo)
// TODO(apenwarr): avoid the need to reinit controlclient. // TODO(apenwarr): avoid the need to reinit controlclient.
@ -3270,6 +3271,11 @@ func (b *LocalBackend) blockEngineUpdates(block bool) {
// b.mu must be held. // b.mu must be held.
func (b *LocalBackend) reconfigAppConnectorLocked(nm *netmap.NetworkMap, prefs ipn.PrefsView) { func (b *LocalBackend) reconfigAppConnectorLocked(nm *netmap.NetworkMap, prefs ipn.PrefsView) {
const appConnectorCapName = "tailscale.com/app-connectors" const appConnectorCapName = "tailscale.com/app-connectors"
defer func() {
if b.hostinfo != nil {
b.hostinfo.AppConnector.Set(b.appConnector != nil)
}
}()
if !prefs.AppConnector().Advertise { if !prefs.AppConnector().Advertise {
var old *appc.AppConnector var old *appc.AppConnector

@ -1263,6 +1263,9 @@ func TestReconfigureAppConnector(t *testing.T) {
if !foundAppConnectorService { if !foundAppConnectorService {
t.Fatalf("expected app connector service") t.Fatalf("expected app connector service")
} }
if v, _ := b.hostinfo.AppConnector.Get(); !v {
t.Fatalf("expected app connector service")
}
// disable the connector in order to assert that the service is removed // disable the connector in order to assert that the service is removed
b.EditPrefs(&ipn.MaskedPrefs{ b.EditPrefs(&ipn.MaskedPrefs{
@ -1288,6 +1291,9 @@ func TestReconfigureAppConnector(t *testing.T) {
if foundAppConnectorService { if foundAppConnectorService {
t.Fatalf("expected no app connector service") t.Fatalf("expected no app connector service")
} }
if v, _ := b.hostinfo.AppConnector.Get(); v {
t.Fatalf("expected no app connector service")
}
} }
func hasAppConnectorService(b *LocalBackend) bool { func hasAppConnectorService(b *LocalBackend) bool {

@ -624,11 +624,12 @@ func (h *Hostinfo) CheckRequestTags() error {
type ServiceProto string type ServiceProto string
const ( const (
TCP = ServiceProto("tcp") TCP = ServiceProto("tcp")
UDP = ServiceProto("udp") UDP = ServiceProto("udp")
PeerAPI4 = ServiceProto("peerapi4") PeerAPI4 = ServiceProto("peerapi4")
PeerAPI6 = ServiceProto("peerapi6") PeerAPI6 = ServiceProto("peerapi6")
PeerAPIDNS = ServiceProto("peerapi-dns-proxy") PeerAPIDNS = ServiceProto("peerapi-dns-proxy")
// Deprecated: use the field on HostInfo instead.
AppConnector = ServiceProto("app-connector") AppConnector = ServiceProto("app-connector")
) )
@ -650,9 +651,9 @@ type Service struct {
// being a DNS proxy (when the node is an exit // being a DNS proxy (when the node is an exit
// node). For this service, the Port number is really // node). For this service, the Port number is really
// the version number of the service. // the version number of the service.
// * "app-connector": the local app-connector service is // * "app-connector": (deprecated) the local app-connector
// available. For this service, the Port number is // service is available. For this service, the Port number
// really the version number of the service. // is really the version number of the service.
Proto ServiceProto Proto ServiceProto
// Port is the port number. // Port is the port number.
@ -748,6 +749,7 @@ type Hostinfo struct {
Cloud string `json:",omitempty"` Cloud string `json:",omitempty"`
Userspace opt.Bool `json:",omitempty"` // if the client is running in userspace (netstack) mode Userspace opt.Bool `json:",omitempty"` // if the client is running in userspace (netstack) mode
UserspaceRouter opt.Bool `json:",omitempty"` // if the client's subnet router is running in userspace (netstack) mode UserspaceRouter opt.Bool `json:",omitempty"` // if the client's subnet router is running in userspace (netstack) mode
AppConnector opt.Bool `json:",omitempty"` // if the client is running the app-connector service
// Location represents geographical location data about a // Location represents geographical location data about a
// Tailscale host. Location is optional and only set if // Tailscale host. Location is optional and only set if

@ -177,6 +177,7 @@ var _HostinfoCloneNeedsRegeneration = Hostinfo(struct {
Cloud string Cloud string
Userspace opt.Bool Userspace opt.Bool
UserspaceRouter opt.Bool UserspaceRouter opt.Bool
AppConnector opt.Bool
Location *Location Location *Location
}{}) }{})

@ -17,6 +17,7 @@ import (
. "tailscale.com/tailcfg" . "tailscale.com/tailcfg"
"tailscale.com/types/key" "tailscale.com/types/key"
"tailscale.com/types/opt"
"tailscale.com/types/ptr" "tailscale.com/types/ptr"
"tailscale.com/util/must" "tailscale.com/util/must"
) )
@ -64,6 +65,7 @@ func TestHostinfoEqual(t *testing.T) {
"Cloud", "Cloud",
"Userspace", "Userspace",
"UserspaceRouter", "UserspaceRouter",
"AppConnector",
"Location", "Location",
} }
if have := fieldsOf(reflect.TypeOf(Hostinfo{})); !reflect.DeepEqual(have, hiHandles) { if have := fieldsOf(reflect.TypeOf(Hostinfo{})); !reflect.DeepEqual(have, hiHandles) {
@ -228,6 +230,16 @@ func TestHostinfoEqual(t *testing.T) {
&Hostinfo{App: "golink"}, &Hostinfo{App: "golink"},
true, true,
}, },
{
&Hostinfo{AppConnector: opt.Bool("true")},
&Hostinfo{AppConnector: opt.Bool("true")},
true,
},
{
&Hostinfo{AppConnector: opt.Bool("true")},
&Hostinfo{AppConnector: opt.Bool("false")},
false,
},
} }
for i, tt := range tests { for i, tt := range tests {
got := tt.a.Equal(tt.b) got := tt.a.Equal(tt.b)

@ -317,6 +317,7 @@ func (v HostinfoView) SSH_HostKeys() views.Slice[string] { return views.Sli
func (v HostinfoView) Cloud() string { return v.ж.Cloud } func (v HostinfoView) Cloud() string { return v.ж.Cloud }
func (v HostinfoView) Userspace() opt.Bool { return v.ж.Userspace } func (v HostinfoView) Userspace() opt.Bool { return v.ж.Userspace }
func (v HostinfoView) UserspaceRouter() opt.Bool { return v.ж.UserspaceRouter } func (v HostinfoView) UserspaceRouter() opt.Bool { return v.ж.UserspaceRouter }
func (v HostinfoView) AppConnector() opt.Bool { return v.ж.AppConnector }
func (v HostinfoView) Location() *Location { func (v HostinfoView) Location() *Location {
if v.ж.Location == nil { if v.ж.Location == nil {
return nil return nil
@ -363,6 +364,7 @@ var _HostinfoViewNeedsRegeneration = Hostinfo(struct {
Cloud string Cloud string
Userspace opt.Bool Userspace opt.Bool
UserspaceRouter opt.Bool UserspaceRouter opt.Bool
AppConnector opt.Bool
Location *Location Location *Location
}{}) }{})

Loading…
Cancel
Save