Exemple #1
0
func findApex(m *dns.Msg, z *dns.Zone) {
	apex := z.Apex()
	if apex != nil {
		// What if we don't have this? TODO(mg)
		m.Ns = apex.RR[dns.TypeSOA]
	}
	return
}
Exemple #2
0
func findApex(m *dns.Msg, z *dns.Zone) {
	apex, exact := z.Find(z.Origin)
	if exact {
		// What if we don't have this? TODO(mg)
		m.Ns = apex.RR[dns.TypeSOA]
	}
	return
}
Exemple #3
0
func serve(w dns.ResponseWriter, req *dns.Msg, z *dns.Zone) {
	if z == nil {
		panic("fksd: no zone")
	}

	m := new(dns.Msg)
	// Just NACK ANYs
	if req.Question[0].Qtype == dns.TypeANY {
		m.SetRcode(req, dns.RcodeServerFailure)
		ednsFromRequest(req, m)
		w.WriteMsg(m)
		return
	}

	logPrintf("[zone %s] incoming %s %s %d from %s\n", z.Origin, req.Question[0].Name, dns.TypeToString[req.Question[0].Qtype], req.MsgHdr.Id, w.RemoteAddr())
	node, exact, ref := z.FindFunc(req.Question[0].Name, func(n interface{}) bool {
		return n.(*dns.ZoneData).NonAuth
	})
	if ref {
		logPrintf("[zone %s] referral due\n", z.Origin)
		m.SetReply(req)
		m.Ns = node.RR[dns.TypeNS]
		for _, n := range m.Ns {
			if dns.IsSubDomain(n.(*dns.NS).Ns, n.Header().Name) {
				findGlue(m, z, n.(*dns.NS).Ns)
			}
		}
		ednsFromRequest(req, m)
		w.WriteMsg(m)
		return
	}
	if exact {
		exactMatch(w, req, m, z, node)
		return
	}
	// Not an exact match nor an referral

	if z.Wildcard > 0 {
		lx := dns.SplitLabels(req.Question[0].Name)
		wc := "*." + strings.Join(lx[1:], ".")
		node, exact = z.Find(wc)
		if exact {
			logPrintf("[zone %s] wildcard answer\n", z.Origin)
			// as exact,but not complete -- only the last part
		}
	}
	nameerror(w, m, req)
	return
}
Exemple #4
0
func findGlue(m *dns.Msg, z *dns.Zone, nameserver string) {
	glue := z.Find(nameserver)
	if glue != nil {
		if a4, ok := glue.RR[dns.TypeAAAA]; ok {
			m.Extra = append(m.Extra, a4...)
			return
		}
		if a, ok := glue.RR[dns.TypeA]; ok {
			m.Extra = append(m.Extra, a...)
			return
		}
	}
	// length or the returned packet! TODO(mg)
	return
}