Send search domains

This commit is contained in:
Juan Font Alonso 2021-10-02 12:13:19 +02:00
parent 45e71ecba0
commit 36ae14bccf

18
api.go
View File

@ -241,11 +241,27 @@ func (h *Headscale) getMapResponse(mKey wgkey.Key, req tailcfg.MapRequest, m Mac
DisplayName: m.Namespace.Name, 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{ resp := tailcfg.MapResponse{
KeepAlive: false, KeepAlive: false,
Node: node, Node: node,
Peers: *peers, Peers: *peers,
DNSConfig: h.cfg.DNSConfig, DNSConfig: dnsConfig,
Domain: h.cfg.BaseDomain, Domain: h.cfg.BaseDomain,
PacketFilter: *h.aclRules, PacketFilter: *h.aclRules,
DERPMap: h.cfg.DerpMap, DERPMap: h.cfg.DerpMap,