Skip to content

Commit

Permalink
Fix ipv6 dns entries
Browse files Browse the repository at this point in the history
Signed-off-by: Artem Glazychev <[email protected]>
  • Loading branch information
glazychev-art committed Oct 13, 2022
1 parent 9ae27f8 commit 2c613cc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ import (
"github.com/networkservicemesh/sdk/pkg/networkservice/utils/metadata"
"github.com/networkservicemesh/sdk/pkg/tools/dnsconfig"
"github.com/networkservicemesh/sdk/pkg/tools/dnsutils"
dnschain "github.com/networkservicemesh/sdk/pkg/tools/dnsutils/chain"
"github.com/networkservicemesh/sdk/pkg/tools/dnsutils/dnsconfigs"
"github.com/networkservicemesh/sdk/pkg/tools/dnsutils/fanout"
"github.com/networkservicemesh/sdk/pkg/tools/dnsutils/memory"
dnsnext "github.com/networkservicemesh/sdk/pkg/tools/dnsutils/next"
"github.com/networkservicemesh/sdk/pkg/tools/dnsutils/noloop"
"github.com/networkservicemesh/sdk/pkg/tools/dnsutils/norecursion"
"github.com/networkservicemesh/sdk/pkg/tools/ippool"
Expand Down Expand Up @@ -70,7 +70,7 @@ func NewServer(chanCtx context.Context, getDNSServerIP func() net.IP, opts ...Op
}

if result.dnsServer == nil {
result.dnsServer = dnsnext.NewDNSHandler(
result.dnsServer = dnschain.NewDNSHandler(
dnsconfigs.NewDNSHandler(result.dnsConfigs),
noloop.NewDNSHandler(),
norecursion.NewDNSHandler(),
Expand Down
22 changes: 13 additions & 9 deletions pkg/tools/dnsutils/memory/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ func (f *memoryHandler) ServeDNS(ctx context.Context, rw dns.ResponseWriter, msg
if !ok {
next.Handler(ctx).ServeDNS(ctx, rwWrapper, msg)
if !rwWrapper.passed {
dns.HandleFailed(rw, msg)
// Send NXDomain because we didn't find anything
m := new(dns.Msg)
_ = rw.WriteMsg(m.SetRcode(msg, dns.RcodeNameError))
}
return
}
Expand All @@ -81,7 +83,9 @@ func (f *memoryHandler) ServeDNS(ctx context.Context, rw dns.ResponseWriter, msg
if len(resp.Answer) == 0 {
next.Handler(ctx).ServeDNS(ctx, rwWrapper, msg)
if !rwWrapper.passed {
dns.HandleFailed(rw, msg)
// Send NXDomain because we didn't find anything
m := new(dns.Msg)
_ = rw.WriteMsg(m.SetRcode(msg, dns.RcodeNameError))
}
return
}
Expand All @@ -99,29 +103,29 @@ func NewDNSHandler(records *Map) dnsutils.Handler {
return &memoryHandler{records: records}
}
func a(domain string, ips []net.IP) []dns.RR {
answers := make([]dns.RR, len(ips))
for i, ip := range ips {
var answers []dns.RR
for _, ip := range ips {
if ip.To4() == nil {
continue
}
r := new(dns.A)
r.Hdr = dns.RR_Header{Name: domain, Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: defaultTTL}
r.A = ip
answers[i] = r
answers = append(answers, r)
}
return answers
}

func aaaa(domain string, ips []net.IP) []dns.RR {
answers := make([]dns.RR, len(ips))
for i, ip := range ips {
if ip.To16() == nil {
var answers []dns.RR
for _, ip := range ips {
if ip.To4() != nil {
continue
}
r := new(dns.AAAA)
r.Hdr = dns.RR_Header{Name: domain, Rrtype: dns.TypeAAAA, Class: dns.ClassINET, Ttl: defaultTTL}
r.AAAA = ip
answers[i] = r
answers = append(answers, r)
}
return answers
}

0 comments on commit 2c613cc

Please sign in to comment.