Skip to content

Commit

Permalink
Add PTR support
Browse files Browse the repository at this point in the history
  • Loading branch information
tianon committed Mar 7, 2024
1 parent 943c557 commit 2a27481
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions cmd/rawdns/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ type DomainConfig struct {
// "type": "static"
Addrs []string `json:"addrs"`
Cnames []string `json:"cnames"`
Ptrs []string `json:"ptrs"`
Txts [][]string `json:"txts"`
Srvs []DomainConfigSrv `json:"srvs"`
// pre-calculated/parsed
addrs []net.IP // net.ParseIP(Addrs)
cnames []string // dns.Fqdn(Cnames)
ptrs []string // dns.Fqdn(Ptrs)
txts [][]string // strings.Replace(Txts, `\`, `\\`, -1)
}

Expand Down Expand Up @@ -118,6 +120,11 @@ func main() {
cCopy.cnames[i] = dns.Fqdn(cname)
}

cCopy.ptrs = make([]string, len(cCopy.Ptrs))
for i, ptr := range cCopy.Ptrs {
cCopy.ptrs[i] = dns.Fqdn(ptr)
}

cCopy.txts = make([][]string, len(cCopy.Txts))
for i, txts := range cCopy.Txts {
cCopy.txts[i] = make([]string, len(txts))
Expand Down Expand Up @@ -169,6 +176,9 @@ func dnsAppend(q dns.Question, m *dns.Msg, rr dns.RR) {
} else if rrS, ok := rr.(*dns.CNAME); ok {
hdr.Rrtype = dns.TypeCNAME
rrS.Hdr = hdr
} else if rrS, ok := rr.(*dns.PTR); ok {
hdr.Rrtype = dns.TypePTR
rrS.Hdr = hdr
} else if rrS, ok := rr.(*dns.TXT); ok {
hdr.Rrtype = dns.TypeTXT
rrS.Hdr = hdr
Expand Down Expand Up @@ -271,6 +281,10 @@ func handleStaticRequest(config DomainConfig, w dns.ResponseWriter, r *dns.Msg)
}
}

for _, ptr := range config.ptrs {
dnsAppend(q, m, &dns.PTR{Ptr: ptr})
}

for _, txt := range config.txts {
dnsAppend(q, m, &dns.TXT{Txt: txt})
}
Expand Down

0 comments on commit 2a27481

Please sign in to comment.