From 36ae14bccf9af1a940d262cb6945b67606876654 Mon Sep 17 00:00:00 2001 From: Juan Font Alonso Date: Sat, 2 Oct 2021 12:13:19 +0200 Subject: [PATCH] Send search domains --- api.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/api.go b/api.go index c7fbf8a1..be087eb1 100644 --- a/api.go +++ b/api.go @@ -241,11 +241,27 @@ func (h *Headscale) getMapResponse(mKey wgkey.Key, req tailcfg.MapRequest, m Mac DisplayName: m.Namespace.Name, } + var dnsConfig *tailcfg.DNSConfig + if h.cfg.DNSConfig.Proxied { // if MagicDNS is enabled + // TODO(juanfont): We should not be regenerating this all the time + // And we should only send the domains of the peers (this own namespace + those from the shared peers) + namespaces, err := h.ListNamespaces() + if err != nil { + return nil, err + } + dnsConfig := h.cfg.DNSConfig.Clone() + for _, ns := range *namespaces { + dnsConfig.Domains = append(dnsConfig.Domains, fmt.Sprintf("%s.%s", ns.Name, h.cfg.BaseDomain)) + } + } else { + dnsConfig = h.cfg.DNSConfig + } + resp := tailcfg.MapResponse{ KeepAlive: false, Node: node, Peers: *peers, - DNSConfig: h.cfg.DNSConfig, + DNSConfig: dnsConfig, Domain: h.cfg.BaseDomain, PacketFilter: *h.aclRules, DERPMap: h.cfg.DerpMap,