示例#1
0
文件: zone.go 项目: valm0unt/fks
// ReadZoneFile reads a zone and adds it.
func (c *Config) ReadZoneFile(origin, file string) error {
	f, e := os.Open(file)
	if e != nil {
		return e
	}
	z := dns.NewZone(origin)
	for rr := range dns.ParseZone(f, origin, file) {
		if rr.Error == nil {
			if e := z.Insert(rr.RR); e != nil {
				logPrintf("failed to insert record: %s\n", e.Error())
			}
		} else {
			logPrintf("failed to parse: %s\n", rr.Error.Error())
		}
	}
	c.Zones[origin] = z
	dns.HandleFunc(origin, func(w dns.ResponseWriter, req *dns.Msg) { serve(w, req, c.Zones[origin]) })
	return nil
}
示例#2
0
文件: zone.go 项目: valm0unt/fks
// ReadZoneXfr reads a zone from an axfr.
func (c *Config) ReadZoneXfr(origin, master string) error {
	client := new(dns.Client)
	client.Net = "tcp"
	m := new(dns.Msg)
	m.SetAxfr(origin)

	z := dns.NewZone(origin)
	t, e := client.TransferIn(m, master)
	if e == nil {
		for r := range t {
			if r.Error == nil {
				// Loop answer section
				for _, rr := range r.RR {
					z.Insert(rr)
				}
			}
		}
		c.Zones[origin] = z
		dns.HandleFunc(origin, func(w dns.ResponseWriter, req *dns.Msg) { serve(w, req, c.Zones[origin]) })
		return nil
	}
	return e
}