From 687e8d12bec677f947d2f9d3162b622d3bb4c9a9 Mon Sep 17 00:00:00 2001 From: Juan Font Alonso Date: Sun, 17 Oct 2021 12:10:03 +0200 Subject: [PATCH] Do not use the full application for getMapResponseDNSConfig --- api.go | 2 +- dns.go | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/api.go b/api.go index 37090f16..427a5069 100644 --- a/api.go +++ b/api.go @@ -255,7 +255,7 @@ func (h *Headscale) getMapResponse(mKey wgkey.Key, req tailcfg.MapRequest, m *Ma return nil, err } - dnsConfig, err := h.getMapResponseDNSConfig(*m, peers) + dnsConfig, err := getMapResponseDNSConfig(h.cfg.DNSConfig, h.cfg.BaseDomain, *m, peers) if err != nil { log.Error(). Str("func", "getMapResponse"). diff --git a/dns.go b/dns.go index ae7d290c..e8c8a93c 100644 --- a/dns.go +++ b/dns.go @@ -69,12 +69,12 @@ func generateMagicDNSRootDomains(ipPrefix netaddr.IPPrefix, baseDomain string) ( return fqdns, nil } -func (h *Headscale) getMapResponseDNSConfig(m Machine, peers Machines) (*tailcfg.DNSConfig, error) { +func getMapResponseDNSConfig(dnsConfigOrig *tailcfg.DNSConfig, baseDomain string, m Machine, peers Machines) (*tailcfg.DNSConfig, error) { var dnsConfig *tailcfg.DNSConfig - if h.cfg.DNSConfig != nil && h.cfg.DNSConfig.Proxied { // if MagicDNS is enabled + if dnsConfigOrig != nil && dnsConfigOrig.Proxied { // if MagicDNS is enabled // Only inject the Search Domain of the current namespace - shared nodes should use their full FQDN - dnsConfig = h.cfg.DNSConfig.Clone() - dnsConfig.Domains = append(dnsConfig.Domains, fmt.Sprintf("%s.%s", m.Namespace.Name, h.cfg.BaseDomain)) + dnsConfig = dnsConfigOrig.Clone() + dnsConfig.Domains = append(dnsConfig.Domains, fmt.Sprintf("%s.%s", m.Namespace.Name, baseDomain)) namespaceSet := set.New(set.ThreadSafe) namespaceSet.Add(m.Namespace) @@ -82,11 +82,11 @@ func (h *Headscale) getMapResponseDNSConfig(m Machine, peers Machines) (*tailcfg namespaceSet.Add(p.Namespace) } for _, namespace := range namespaceSet.List() { - dnsRoute := dnsname.FQDN(fmt.Sprintf("%s.%s", namespace.(Namespace).Name, h.cfg.BaseDomain)) + dnsRoute := dnsname.FQDN(fmt.Sprintf("%s.%s", namespace.(Namespace).Name, baseDomain)) dnsConfig.Routes[dnsRoute.WithoutTrailingDot()] = nil } } else { - dnsConfig = h.cfg.DNSConfig + dnsConfig = dnsConfigOrig } return dnsConfig, nil }