diff --git a/backend.go b/backend.go index 90366da..fa8c952 100644 --- a/backend.go +++ b/backend.go @@ -172,7 +172,7 @@ func (tx *Btx) Do() (rrs []dns.RR, err error) { return tx.doRootDomain() } - if tx.basename == "x--nmc" { + if tx.basename == "x--nmc" && tx.b.s.cfg.SelfName == "" { return tx.doMetaDomain() } @@ -180,6 +180,11 @@ func (tx *Btx) Do() (rrs []dns.RR, err error) { } func (tx *Btx) doRootDomain() (rrs []dns.RR, err error) { + nsname := tx.b.s.cfg.SelfName + if nsname == "" { + nsname = "this.x--nmc." + tx.rootname + } + soa := &dns.SOA { Hdr: dns.RR_Header { Name: absname(tx.rootname), @@ -187,7 +192,7 @@ func (tx *Btx) doRootDomain() (rrs []dns.RR, err error) { Class: dns.ClassINET, Rrtype: dns.TypeSOA, }, - Ns: absname("this.x--nmc." + tx.rootname), + Ns: absname(nsname), Mbox: ".", Serial: 1, Refresh: 600, @@ -203,7 +208,7 @@ func (tx *Btx) doRootDomain() (rrs []dns.RR, err error) { Class: dns.ClassINET, Rrtype: dns.TypeNS, }, - Ns: absname("this.x--nmc." + tx.rootname), + Ns: absname(nsname), } rrs = []dns.RR{ soa, ns, } diff --git a/ncdns.go b/ncdns.go index 3cd12fb..f6b6b0e 100644 --- a/ncdns.go +++ b/ncdns.go @@ -121,6 +121,7 @@ type ServerConfig struct { NamecoinRPCAddress string `default:"localhost:8336" usage:"Namecoin RPC server address"` CacheMaxEntries int `default:"1000" usage:"Maximum name cache entries"` SelfIP string `default:"127.127.127.127" usage:"The canonical IP address for this service"` + SelfName string `default:"" usage:"Canonical name for this nameserver (default: autogenerated psuedo-hostname resolving to SelfIP; SelfIP is not used if this is set)"` } func (s *Server) doRunListener(ds *dns.Server) { @@ -182,7 +183,11 @@ func (s *Server) handle(rw dns.ResponseWriter, reqMsg *dns.Msg) { err := tx.addAnswers() if err != nil { - if tx.rcode == 0 { + if err == ErrNoResults { + tx.rcode = 0 + } else if err == ErrNoSuchDomain { + tx.rcode = dns.RcodeNameError + } else if tx.rcode == 0 { log.Infoe(err, "Handler error, doing SERVFAIL") tx.rcode = dns.RcodeServerFailure } @@ -337,13 +342,13 @@ func (tx *Tx) addAnswersAuthoritative(rrs []dns.RR, origerr error) error { // appropriate zone, fail with REFUSED // ErrNoSuchDomain -- there are no records at this name of ANY type, nor are there at any // direct or indirect descendant domain; fail with NXDOMAIN - // ErrNoResult -- There are no records of the given type of class. However, there are + // ErrNoResults -- There are no records of the given type of class. However, there are // other records at the given domain and/or records at a direct or // indirect descendant domain; NOERROR // any other error -- SERVFAIL // // If it succeeds: - // If there are zero records, treat the response as ErrNoResult above. Otherwise, each record + // If there are zero records, treat the response as ErrNoResults above. Otherwise, each record // can be classified into one of the following categories: // // - A NS record not at the zone apex and thus not authoritative (handled in addAnswersDelegation)