Pull request 1966: 6050 upd urlfilter
Merge in DNS/adguard-home from upd-urlfilter to master Updates #6050. Squashed commit of the following: commit 80337ab02d616e25fa455e46c9535c088b5c5ea5 Merge: fb2cfd1a531f7aaeccAuthor: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Wed Aug 23 16:50:49 2023 +0300 Merge branch 'master' into upd-urlfilter commit fb2cfd1a5c94d92030fc8832615764f100d010e5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Wed Aug 23 16:22:43 2023 +0300 dnsforward: imp code, docs commit 2900333bb85d4e064db9de27bd5bfe7c3ef00747 Merge: 977ed35e42bfc9fcb1Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 22 18:06:05 2023 +0300 Merge branch 'master' into upd-urlfilter commit 977ed35e4ed377f1031721d58e0fcb58de1e74ac Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 22 17:06:30 2023 +0300 all: log changes commit 1228a0770485799bf50bbe68005dbb0ba9a96a9c Merge: 78305eb2e4b4036fa6Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 22 16:51:42 2023 +0300 Merge branch 'master' into upd-urlfilter commit 78305eb2ebc3854dd11ce35d6b4c7eecccd7cc78 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 22 15:55:05 2023 +0300 all: upd urlfilter commit 63a29e18d5034e5f9433121ff7e7c45aebfa1f0f Merge: 748c53430762e5be97Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Aug 21 20:12:49 2023 +0300 Merge branch 'master' into upd-urlfilter commit 748c5343020b0c6d4d4f16eb3d30b875c0a94e0f Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Aug 21 20:07:44 2023 +0300 all: imp code, docs commit 91975140f3305a6793e07142f7c9a75120a4ce8c Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Aug 17 16:16:19 2023 +0300 all: upd urlfilter
This commit is contained in:
@@ -2,7 +2,7 @@ package filtering
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"net/netip"
|
||||
"strings"
|
||||
|
||||
"github.com/AdguardTeam/golibs/errors"
|
||||
@@ -27,22 +27,12 @@ type LegacyRewrite struct {
|
||||
|
||||
// IP is the IP address that should be used in the response if Type is
|
||||
// dns.TypeA or dns.TypeAAAA.
|
||||
IP net.IP `yaml:"-"`
|
||||
IP netip.Addr `yaml:"-"`
|
||||
|
||||
// Type is the DNS record type: A, AAAA, or CNAME.
|
||||
Type uint16 `yaml:"-"`
|
||||
}
|
||||
|
||||
// clone returns a deep clone of rw.
|
||||
func (rw *LegacyRewrite) clone() (cloneRW *LegacyRewrite) {
|
||||
return &LegacyRewrite{
|
||||
Domain: rw.Domain,
|
||||
Answer: rw.Answer,
|
||||
IP: slices.Clone(rw.IP),
|
||||
Type: rw.Type,
|
||||
}
|
||||
}
|
||||
|
||||
// equal returns true if the rw is equal to the other.
|
||||
func (rw *LegacyRewrite) equal(other *LegacyRewrite) (ok bool) {
|
||||
return rw.Domain == other.Domain && rw.Answer == other.Answer
|
||||
@@ -62,11 +52,11 @@ func (rw *LegacyRewrite) matchesQType(qt uint16) (ok bool) {
|
||||
|
||||
// If the types match or the entry is set to allow only the other type,
|
||||
// include them.
|
||||
return rw.Type == qt || rw.IP == nil
|
||||
return rw.Type == qt || rw.IP == netip.Addr{}
|
||||
}
|
||||
|
||||
// normalize makes sure that the a new or decoded entry is normalized with
|
||||
// regards to domain name case, IP length, and so on.
|
||||
// normalize makes sure that the new or decoded entry is normalized with regards
|
||||
// to domain name case, IP length, and so on.
|
||||
//
|
||||
// If rw is nil, it returns an errors.
|
||||
func (rw *LegacyRewrite) normalize() (err error) {
|
||||
@@ -81,12 +71,12 @@ func (rw *LegacyRewrite) normalize() (err error) {
|
||||
|
||||
switch rw.Answer {
|
||||
case "AAAA":
|
||||
rw.IP = nil
|
||||
rw.IP = netip.Addr{}
|
||||
rw.Type = dns.TypeAAAA
|
||||
|
||||
return nil
|
||||
case "A":
|
||||
rw.IP = nil
|
||||
rw.IP = netip.Addr{}
|
||||
rw.Type = dns.TypeA
|
||||
|
||||
return nil
|
||||
@@ -94,19 +84,18 @@ func (rw *LegacyRewrite) normalize() (err error) {
|
||||
// Go on.
|
||||
}
|
||||
|
||||
ip := net.ParseIP(rw.Answer)
|
||||
if ip == nil {
|
||||
ip, err := netip.ParseAddr(rw.Answer)
|
||||
if err != nil {
|
||||
log.Debug("normalizing legacy rewrite: %s", err)
|
||||
rw.Type = dns.TypeCNAME
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
ip4 := ip.To4()
|
||||
if ip4 != nil {
|
||||
rw.IP = ip4
|
||||
rw.IP = ip
|
||||
if ip.Is4() {
|
||||
rw.Type = dns.TypeA
|
||||
} else {
|
||||
rw.IP = ip
|
||||
rw.Type = dns.TypeAAAA
|
||||
}
|
||||
|
||||
@@ -207,7 +196,7 @@ func findRewrites(
|
||||
func setRewriteResult(res *Result, host string, rewrites []*LegacyRewrite, qtype uint16) {
|
||||
for _, rw := range rewrites {
|
||||
if rw.Type == qtype && (qtype == dns.TypeA || qtype == dns.TypeAAAA) {
|
||||
if rw.IP == nil {
|
||||
if rw.IP == (netip.Addr{}) {
|
||||
// "A"/"AAAA" exception: allow getting from upstream.
|
||||
res.Reason = NotFilteredNotFound
|
||||
|
||||
@@ -225,7 +214,12 @@ func setRewriteResult(res *Result, host string, rewrites []*LegacyRewrite, qtype
|
||||
func cloneRewrites(entries []*LegacyRewrite) (clone []*LegacyRewrite) {
|
||||
clone = make([]*LegacyRewrite, len(entries))
|
||||
for i, rw := range entries {
|
||||
clone[i] = rw.clone()
|
||||
clone[i] = &LegacyRewrite{
|
||||
Domain: rw.Domain,
|
||||
Answer: rw.Answer,
|
||||
IP: rw.IP,
|
||||
Type: rw.Type,
|
||||
}
|
||||
}
|
||||
|
||||
return clone
|
||||
|
||||
Reference in New Issue
Block a user