Skip to content

Commit

Permalink
fix: fqdn error in NS and SOA
Browse files Browse the repository at this point in the history
  • Loading branch information
wintbiit committed Dec 11, 2023
1 parent 3550d74 commit 35886d9
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 7 deletions.
6 changes: 6 additions & 0 deletions model/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ type Domain struct {
Upstream string `json:"upstream,default=127.0.0.1:53"`
Providers map[string]string `json:"providers"`
TTL uint32 `json:"ttl,default=60"`
Tsig TSIG `json:"tsig"`
}

type TSIG struct {
KeyName string `json:"key_name"`
Key string `json:"key"`
}

type Rule struct {
Expand Down
6 changes: 5 additions & 1 deletion provider/lark.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ func (p *LarkProvider) Provide(ruleset string) ([]model.Record, error) {

var records []model.Record
for _, rec := range baseRec {
weight, err := strconv.ParseUint(rec.Fields["Weight"].(string), 10, 16)
weightStr, ok := rec.Fields["Weight"].(string)
if !ok {
weightStr = "0"
}
weight, err := strconv.ParseUint(weightStr, 10, 16)
if err != nil {
weight = 0
}
Expand Down
4 changes: 1 addition & 3 deletions server/CNAME.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ func (s *RuleSet) handleCNAME(r, m *dns.Msg, name string) error {
s.l.Infof("Response for question: %+v", name)

cname := record.Value.String()
if !strings.HasSuffix(cname, ".") {
cname = cname + "." + s.DomainName
}
cname = dns.Fqdn(cname)

m.Answer = append(m.Answer, &dns.CNAME{
Hdr: s.Header(record),
Expand Down
3 changes: 1 addition & 2 deletions server/NS.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package server

import (
"fmt"
"strings"

"github.com/miekg/dns"
)
Expand All @@ -29,7 +28,7 @@ func (s *RuleSet) handleNS(r, m *dns.Msg, name string) error {

m.Answer = append(m.Answer, &dns.NS{
Hdr: s.Header(record),
Ns: strings.TrimSuffix(record.Value.String(), "."),
Ns: dns.Fqdn(record.Value.String()),
})

return nil
Expand Down
2 changes: 1 addition & 1 deletion server/SOA.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (s *RuleSet) handleSOA(r, m *dns.Msg, name string) error {
}
m.Answer = append(m.Answer, &dns.SOA{
Hdr: s.Header(record),
Ns: soa.NS,
Ns: dns.Fqdn(soa.NS),
Mbox: soa.MBox,
Serial: soa.Serial,
Refresh: soa.Refresh,
Expand Down
7 changes: 7 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ func (s *Server) handle(w dns.ResponseWriter, r *dns.Msg) {
m.SetReply(r)
m.Authoritative = s.Authoritative
m.RecursionAvailable = s.Recursion
if r.IsTsig() != nil {
if w.TsigStatus() != nil {
m.SetTsig(s.Tsig.KeyName, dns.HmacSHA256, 300, time.Now().Unix())
}
}

handler := s.MatchHandler(w)

Expand All @@ -136,6 +141,8 @@ func (s *Server) Header(r *model.Record) dns.RR_Header {
if r.Host != "@" {
name = r.Host + "." + s.DomainName
}
name = dns.Fqdn(name)

return dns.RR_Header{
Name: name,
Rrtype: r.Type.DnsType(),
Expand Down

0 comments on commit 35886d9

Please sign in to comment.