Fix the IsSubDomain issue
This commit is contained in:
parent
1dffbeeee1
commit
939fd83e83
|
@ -20,13 +20,16 @@ func serve(w dns.ResponseWriter, req *dns.Msg, z *dns.Zone) {
|
||||||
if z == nil {
|
if z == nil {
|
||||||
panic("fksd: no zone")
|
panic("fksd: no zone")
|
||||||
}
|
}
|
||||||
//logPrintf("[zone %s] incoming %s %s %d from %s\n", z.Origin, req.Question[0].Name, dns.Rr_str[req.Question[0].Qtype], req.MsgHdr.Id, w.RemoteAddr())
|
logPrintf("[zone %s] incoming %s %s %d from %s\n", z.Origin, req.Question[0].Name, dns.Rr_str[req.Question[0].Qtype], req.MsgHdr.Id, w.RemoteAddr())
|
||||||
// Ds Handling
|
// Ds Handling
|
||||||
// Referral
|
// Referral
|
||||||
// if we find something with NonAuth = true, it means
|
// if we find something with NonAuth = true, it means
|
||||||
// we need to return referral
|
// we need to return referral
|
||||||
nss := z.Predecessor(req.Question[0].Name)
|
nss := z.Predecessor(req.Question[0].Name)
|
||||||
m := new(dns.Msg)
|
m := new(dns.Msg)
|
||||||
|
if nss != nil {
|
||||||
|
println("found", nss.RR[dns.TypeNS][0].String())
|
||||||
|
}
|
||||||
if nss != nil && nss.NonAuth {
|
if nss != nil && nss.NonAuth {
|
||||||
m.SetReply(req)
|
m.SetReply(req)
|
||||||
m.Ns = nss.RR[dns.TypeNS]
|
m.Ns = nss.RR[dns.TypeNS]
|
||||||
|
@ -98,6 +101,9 @@ func serve(w dns.ResponseWriter, req *dns.Msg, z *dns.Zone) {
|
||||||
return
|
return
|
||||||
} else { // NoData reply or CNAME
|
} else { // NoData reply or CNAME
|
||||||
m.SetReply(req)
|
m.SetReply(req)
|
||||||
|
if cname, ok := node.RR[dns.TypeCNAME]; ok {
|
||||||
|
m.Answer = cname // tODO
|
||||||
|
}
|
||||||
m.Ns = apex.RR[dns.TypeSOA]
|
m.Ns = apex.RR[dns.TypeSOA]
|
||||||
ednsFromRequest(req, m)
|
ednsFromRequest(req, m)
|
||||||
w.Write(m)
|
w.Write(m)
|
||||||
|
|
|
@ -14,7 +14,9 @@ func (c *Config) ReadZoneFile(origin, file string) error {
|
||||||
z := dns.NewZone(origin)
|
z := dns.NewZone(origin)
|
||||||
for rr := range dns.ParseZone(f, origin, file) {
|
for rr := range dns.ParseZone(f, origin, file) {
|
||||||
if rr.Error == nil {
|
if rr.Error == nil {
|
||||||
z.Insert(rr.RR)
|
if e := z.Insert(rr.RR); e != nil {
|
||||||
|
logPrintf("failed to insert record: %s\n", e.Error())
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
logPrintf("failed to parse: %s\n", rr.Error.Error())
|
logPrintf("failed to parse: %s\n", rr.Error.Error())
|
||||||
}
|
}
|
||||||
|
|
2
zone.go
2
zone.go
|
@ -52,7 +52,7 @@ func NewZone(origin string) *Zone {
|
||||||
|
|
||||||
// Insert inserts an RR into the zone. Duplicate data overwrites the old data.
|
// Insert inserts an RR into the zone. Duplicate data overwrites the old data.
|
||||||
func (z *Zone) Insert(r RR) error {
|
func (z *Zone) Insert(r RR) error {
|
||||||
if !IsSubDomain(r.Header().Name, z.Origin) {
|
if !IsSubDomain(z.Origin, r.Header().Name) {
|
||||||
return &Error{Err: "out of zone data", Name: r.Header().Name}
|
return &Error{Err: "out of zone data", Name: r.Header().Name}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue