Skip to content

Commit

Permalink
Pull request: dnsforward: fix fqdn in some dns rewrites
Browse files Browse the repository at this point in the history
Updates #2498.
Updates #2533.

Squashed commit of the following:

commit 9eec20a
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Mon Mar 15 16:53:29 2021 +0300

    dnsforward: fix fqdn in some dns rewrites
  • Loading branch information
ainar-g committed Mar 15, 2021
1 parent 313fd71 commit 75ac1a5
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions internal/dnsforward/dnsrewrite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ func TestServer_FilterDNSRewrite(t *testing.T) {
}
svcbVal := &rules.DNSSVCB{
Params: map[string]string{"alpn": "h3"},
Target: domain,
Target: dns.Fqdn(domain),
Priority: 32,
}
srvVal := &rules.DNSSRV{
Priority: 32,
Weight: 60,
Port: 8080,
Target: domain,
Target: dns.Fqdn(domain),
}

// Helper functions and entities.
Expand Down Expand Up @@ -113,7 +113,7 @@ func TestServer_FilterDNSRewrite(t *testing.T) {
assert.Equal(t, dns.RcodeSuccess, d.Res.Rcode)

require.Len(t, d.Res.Answer, 1)
assert.Equal(t, domain, d.Res.Answer[0].(*dns.PTR).Ptr)
assert.Equal(t, dns.Fqdn(domain), d.Res.Answer[0].(*dns.PTR).Ptr)
})

t.Run("noerror_txt", func(t *testing.T) {
Expand Down Expand Up @@ -142,7 +142,7 @@ func TestServer_FilterDNSRewrite(t *testing.T) {
ans, ok := d.Res.Answer[0].(*dns.MX)

require.True(t, ok)
assert.Equal(t, mxVal.Exchange, ans.Mx)
assert.Equal(t, dns.Fqdn(mxVal.Exchange), ans.Mx)
assert.Equal(t, mxVal.Preference, ans.Preference)
})

Expand Down
6 changes: 3 additions & 3 deletions internal/dnsforward/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,14 @@ func (s *Server) genAnswerMX(req *dns.Msg, mx *rules.DNSMX) (ans *dns.MX) {
return &dns.MX{
Hdr: s.hdr(req, dns.TypeMX),
Preference: mx.Preference,
Mx: mx.Exchange,
Mx: dns.Fqdn(mx.Exchange),
}
}

func (s *Server) genAnswerPTR(req *dns.Msg, ptr string) (ans *dns.PTR) {
return &dns.PTR{
Hdr: s.hdr(req, dns.TypePTR),
Ptr: ptr,
Ptr: dns.Fqdn(ptr),
}
}

Expand All @@ -155,7 +155,7 @@ func (s *Server) genAnswerSRV(req *dns.Msg, srv *rules.DNSSRV) (ans *dns.SRV) {
Priority: srv.Priority,
Weight: srv.Weight,
Port: srv.Port,
Target: srv.Target,
Target: dns.Fqdn(srv.Target),
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/dnsforward/svcbmsg.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (s *Server) genAnswerSVCB(req *dns.Msg, svcb *rules.DNSSVCB) (ans *dns.SVCB
ans = &dns.SVCB{
Hdr: s.hdr(req, dns.TypeSVCB),
Priority: svcb.Priority,
Target: svcb.Target,
Target: dns.Fqdn(svcb.Target),
}
if len(svcb.Params) == 0 {
return ans
Expand Down
6 changes: 3 additions & 3 deletions internal/dnsforward/svcbmsg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestGenAnswerHTTPS_andSVCB(t *testing.T) {
want = &dns.SVCB{
Hdr: s.hdr(req, dns.TypeSVCB),
Priority: prio,
Target: host,
Target: dns.Fqdn(host),
}

if kv == nil {
Expand Down Expand Up @@ -122,15 +122,15 @@ func TestGenAnswerHTTPS_andSVCB(t *testing.T) {
}, {
svcb: dnssvcb("no-default-alpn", ""),
want: wantsvcb(&dns.SVCBNoDefaultAlpn{}),
name: "no-default-alpn",
name: "no_default_alpn",
}, {
svcb: dnssvcb("port", "8080"),
want: wantsvcb(&dns.SVCBPort{Port: 8080}),
name: "port",
}, {
svcb: dnssvcb("port", "1005008080"),
want: wantsvcb(nil),
name: "port",
name: "bad_port",
}}

for _, tc := range testCases {
Expand Down

0 comments on commit 75ac1a5

Please sign in to comment.