-
Notifications
You must be signed in to change notification settings - Fork 0
/
bind.go
38 lines (33 loc) · 999 Bytes
/
bind.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
// This module handles the local zone file management.
import (
"fmt"
"github.com/miekg/dns"
"strings"
"time"
)
// lifted and modified from cli53 code for this
// parses out a slice of Records from the contents of a zone file
// zone: the full text of a bind file
func ParseZoneFile(zone string) ([]Response, error) {
z := dns.NewZoneParser(strings.NewReader(zone), ".", "")
responses := make([]Response, 0)
for rr, done := z.Next(); done; rr, done = z.Next() {
if err := z.Err(); err != nil {
return nil, fmt.Errorf("token error: %s\n", err)
}
// TODO the stuff we host sholdn't follow the same rules, check out the spec
cachedMsg := dns.Msg{
Answer: []dns.RR{rr},
}
response := Response{
Name: rr.Header().Name,
Entry: cachedMsg,
Ttl: time.Duration(rr.Header().Ttl) * time.Second,
CreationTime: time.Now(),
Qtype: rr.Header().Rrtype,
}
responses = append(responses, response)
}
return responses, nil
}