From 228a82f178ec97f470a12ea9998e0c93f59b2458 Mon Sep 17 00:00:00 2001 From: James Tucker Date: Wed, 1 Nov 2023 11:38:44 -0700 Subject: [PATCH] ipn/ipnlocal,tailcfg: add AppConnector service to HostInfo when configured Updates tailscale/corp#15437 Signed-off-by: James Tucker --- ipn/ipnlocal/local.go | 6 ++++++ ipn/ipnlocal/local_test.go | 22 ++++++++++++++++++++++ ipn/ipnlocal/peerapi.go | 2 +- tailcfg/tailcfg.go | 16 ++++++++++------ 4 files changed, 39 insertions(+), 7 deletions(-) diff --git a/ipn/ipnlocal/local.go b/ipn/ipnlocal/local.go index 17f23e0f1..886f6ead0 100644 --- a/ipn/ipnlocal/local.go +++ b/ipn/ipnlocal/local.go @@ -3166,6 +3166,12 @@ func (b *LocalBackend) peerAPIServicesLocked() (ret []tailcfg.Service) { Port: 1, // version }) } + if b.appConnector != nil { + ret = append(ret, tailcfg.Service{ + Proto: tailcfg.AppConnector, + Port: 1, // version + }) + } return ret } diff --git a/ipn/ipnlocal/local_test.go b/ipn/ipnlocal/local_test.go index 1ac51ce58..c9e511cc0 100644 --- a/ipn/ipnlocal/local_test.go +++ b/ipn/ipnlocal/local_test.go @@ -1157,6 +1157,28 @@ func TestOfferingAppConnector(t *testing.T) { } } +func TestAppConnectorHostinfoService(t *testing.T) { + hasAppConnectorService := func(s []tailcfg.Service) bool { + for _, s := range s { + if s.Proto == tailcfg.AppConnector && s.Port == 1 { + return true + } + } + return false + } + + b := newTestBackend(t) + b.mu.Lock() + defer b.mu.Unlock() + if hasAppConnectorService(b.peerAPIServicesLocked()) { + t.Fatal("unexpected app connector service") + } + b.appConnector = appc.NewEmbeddedAppConnector(t.Logf, nil) + if !hasAppConnectorService(b.peerAPIServicesLocked()) { + t.Fatal("expected app connector service") + } +} + func TestRouteAdvertiser(t *testing.T) { b := newTestBackend(t) testPrefix := netip.MustParsePrefix("192.0.0.8/32") diff --git a/ipn/ipnlocal/peerapi.go b/ipn/ipnlocal/peerapi.go index 3f5b0beaf..0a7471f19 100644 --- a/ipn/ipnlocal/peerapi.go +++ b/ipn/ipnlocal/peerapi.go @@ -1003,7 +1003,7 @@ func dnsQueryForName(name, typStr string) []byte { b := dnsmessage.NewBuilder(nil, dnsmessage.Header{ OpCode: 0, // query RecursionDesired: true, - ID: 0, + ID: 1, // arbitrary, but 0 is rejected by some servers }) if !strings.HasSuffix(name, ".") { name += "." diff --git a/tailcfg/tailcfg.go b/tailcfg/tailcfg.go index 3fb7d70ab..54f3b24f7 100644 --- a/tailcfg/tailcfg.go +++ b/tailcfg/tailcfg.go @@ -624,11 +624,12 @@ func (h *Hostinfo) CheckRequestTags() error { type ServiceProto string const ( - TCP = ServiceProto("tcp") - UDP = ServiceProto("udp") - PeerAPI4 = ServiceProto("peerapi4") - PeerAPI6 = ServiceProto("peerapi6") - PeerAPIDNS = ServiceProto("peerapi-dns-proxy") + TCP = ServiceProto("tcp") + UDP = ServiceProto("udp") + PeerAPI4 = ServiceProto("peerapi4") + PeerAPI6 = ServiceProto("peerapi6") + PeerAPIDNS = ServiceProto("peerapi-dns-proxy") + AppConnector = ServiceProto("app-connector") ) // Service represents a service running on a node. @@ -645,10 +646,13 @@ type Service struct { // * "peerapi6": peerapi is available on IPv6; Port is the // port number that the peerapi is running on the // node's Tailscale IPv6 address. - // * "peerapi-dns": the local peerapi service supports + // * "peerapi-dns-proxy": the local peerapi service supports // being a DNS proxy (when the node is an exit // node). For this service, the Port number is really // the version number of the service. + // * "app-connector": the local app-connector service is + // available. For this service, the Port number is + // really the version number of the service. Proto ServiceProto // Port is the port number.