mirror of
https://github.com/juanfont/headscale.git
synced 2024-11-23 18:15:26 +00:00
Generated MagicDNS search domains (only in 100.64.0.0/10)
This commit is contained in:
parent
e432e98413
commit
45e71ecba0
12
app.go
12
app.go
@ -16,6 +16,7 @@ import (
|
||||
"gorm.io/gorm"
|
||||
"inet.af/netaddr"
|
||||
"tailscale.com/tailcfg"
|
||||
"tailscale.com/types/dnstype"
|
||||
"tailscale.com/types/wgkey"
|
||||
)
|
||||
|
||||
@ -104,6 +105,17 @@ func NewHeadscale(cfg Config) (*Headscale, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if h.cfg.DNSConfig != nil && h.cfg.DNSConfig.Proxied { // if MagicDNS
|
||||
magicDNSDomains, err := h.generateMagicDNSRootDomains()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
h.cfg.DNSConfig.Routes = make(map[string][]dnstype.Resolver)
|
||||
for _, d := range *magicDNSDomains {
|
||||
h.cfg.DNSConfig.Routes[d.WithoutTrailingDot()] = nil
|
||||
}
|
||||
}
|
||||
|
||||
return &h, nil
|
||||
}
|
||||
|
||||
|
30
dns.go
Normal file
30
dns.go
Normal file
@ -0,0 +1,30 @@
|
||||
package headscale
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"tailscale.com/util/dnsname"
|
||||
)
|
||||
|
||||
func (h *Headscale) generateMagicDNSRootDomains() (*[]dnsname.FQDN, error) {
|
||||
base, err := dnsname.ToFQDN(h.cfg.BaseDomain)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// TODO(juanfont): we are not handing over IPv6 addresses yet
|
||||
// and in fact this is Tailscale.com's range (not the fd7a:115c:a1e0: range in the fc00::/7 network)
|
||||
ipv6base := dnsname.FQDN("0.e.1.a.c.5.1.1.a.7.d.f.ip6.arpa.")
|
||||
fqdns := []dnsname.FQDN{base, ipv6base}
|
||||
|
||||
for i := 64; i <= 127; i++ {
|
||||
fqdn, err := dnsname.ToFQDN(fmt.Sprintf("%d.100.in-addr.arpa.", i))
|
||||
if err != nil {
|
||||
// TODO: propagate error
|
||||
continue
|
||||
}
|
||||
fqdns = append(fqdns, fqdn)
|
||||
}
|
||||
|
||||
return &fqdns, nil
|
||||
}
|
Loading…
Reference in New Issue
Block a user