-
Notifications
You must be signed in to change notification settings - Fork 261
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge: feat: 🎸 added bogus-nxdomain option
* commit 'baa099c4c650ec20f62fd25048a013ce0c9d7a5f': fix: 🐛 remove unnecessary len check fix: 🐛 typo feat: 🎸 added bogus-nxdomain option
- Loading branch information
Showing
14 changed files
with
1,071 additions
and
813 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package proxy | ||
|
||
import ( | ||
"github.com/AdguardTeam/dnsproxy/proxyutil" | ||
"github.com/miekg/dns" | ||
) | ||
|
||
// isBogusNXDomain - checks if the specified DNS message | ||
// contains ONLY ip addresses from the Proxy.BogusNXDomain list | ||
func (p *Proxy) isBogusNXDomain(reply *dns.Msg) bool { | ||
if reply == nil || | ||
len(p.BogusNXDomain) == 0 || | ||
len(reply.Answer) == 0 || | ||
(reply.Question[0].Qtype != dns.TypeA && | ||
reply.Question[0].Qtype != dns.TypeAAAA) { | ||
return false | ||
} | ||
|
||
for _, rr := range reply.Answer { | ||
ip := proxyutil.GetIPFromDNSRecord(rr) | ||
if !proxyutil.ContainsIP(p.BogusNXDomain, ip) { | ||
return false | ||
} | ||
} | ||
|
||
// All IPs are bogus if we got here | ||
return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package proxy | ||
|
||
import ( | ||
"net" | ||
"testing" | ||
|
||
"github.com/AdguardTeam/dnsproxy/upstream" | ||
"github.com/miekg/dns" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestBogusNXDomainTypeA(t *testing.T) { | ||
dnsProxy := createTestProxy(t, nil) | ||
dnsProxy.CacheEnabled = true | ||
dnsProxy.BogusNXDomain = []net.IP{net.ParseIP("4.3.2.1")} | ||
|
||
u := testUpstream{} | ||
dnsProxy.Upstreams = []upstream.Upstream{&u} | ||
err := dnsProxy.Start() | ||
assert.Nil(t, err) | ||
|
||
// first request | ||
// upstream answers with a bogus IP | ||
u.aResp = new(dns.A) | ||
u.aResp.Hdr.Rrtype = dns.TypeA | ||
u.aResp.Hdr.Name = "host." | ||
u.aResp.A = net.ParseIP("4.3.2.1") | ||
u.aResp.Hdr.Ttl = 10 | ||
|
||
clientIP := net.IP{1, 2, 3, 0} | ||
d := DNSContext{} | ||
d.Req = createHostTestMessage("host") | ||
d.Addr = &net.TCPAddr{ | ||
IP: clientIP, | ||
} | ||
|
||
err = dnsProxy.Resolve(&d) | ||
assert.Nil(t, err) | ||
|
||
// check response | ||
assert.NotNil(t, d.Res) | ||
assert.Equal(t, dns.RcodeNameError, d.Res.Rcode) | ||
|
||
// second request | ||
// upstream answers with a normal IP | ||
u.aResp = new(dns.A) | ||
u.aResp.Hdr.Rrtype = dns.TypeA | ||
u.aResp.Hdr.Name = "host." | ||
u.aResp.A = net.ParseIP("4.3.2.2") | ||
u.aResp.Hdr.Ttl = 10 | ||
|
||
err = dnsProxy.Resolve(&d) | ||
assert.Nil(t, err) | ||
|
||
// check response | ||
assert.NotNil(t, d.Res) | ||
assert.Equal(t, dns.RcodeSuccess, d.Res.Rcode) | ||
|
||
_ = dnsProxy.Stop() | ||
} |
Oops, something went wrong.