docstring_tokens
stringlengths
18
16.9k
code_tokens
stringlengths
75
1.81M
html_url
stringlengths
74
116
file_name
stringlengths
3
311
keep keep keep keep replace replace keep keep keep keep keep
<mask> "sync/atomic" <mask> <mask> "github.com/AdguardTeam/AdGuardHome/internal/aghhttp" <mask> "github.com/AdguardTeam/AdGuardHome/internal/aghnet" <mask> "github.com/AdguardTeam/dnsproxy/upstream" <mask> "github.com/AdguardTeam/golibs/cache" <mask> "github.com/AdguardTeam/golibs/errors" <mask> "github.com/AdguardTeam/golibs/log" <mask> "github.com/AdguardTeam/golibs/mathutil" <mask> "github.com/AdguardTeam/golibs/stringutil" <mask> "github.com/AdguardTeam/urlfilter" </s> Pull request 1837: AG-21462-imp-safebrowsing-parental Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master Squashed commit of the following: commit 85016d4f1105e21a407efade0bd45b8362808061 Merge: 0e61edade 620b51e3e Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 16:36:30 2023 +0300 Merge branch 'master' into AG-21462-imp-safebrowsing-parental commit 0e61edadeff34f6305e941c1db94575c82f238d9 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 14:51:37 2023 +0300 filtering: imp tests commit 994255514cc0f67dfe33d5a0892432e8924d1e36 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:13:19 2023 +0300 filtering: fix typo commit 96d1069573171538333330d6af94ef0f4208a9c4 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:00:18 2023 +0300 filtering: imp code more commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 19:13:26 2023 +0300 all: add todo commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 14:36:08 2023 +0300 all: imp code more commit b6e734ccbeda82669023f6578481260b7c1f7161 Author: Stanislav Chzhen <[email protected]> Date: Tue Apr 25 15:01:56 2023 +0300 filtering: imp code commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 20:06:36 2023 +0300 all: imp code commit 49fa6e587052a40bb431fea457701ee860493527 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 14:57:19 2023 +0300 all: rm safe browsing ctx commit bbcb66cb03e18fa875e3c33cf16295892739e507 Author: Stanislav Chzhen <[email protected]> Date: Fri Apr 21 17:54:18 2023 +0300 filtering: add cache item commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 18:43:02 2023 +0300 filtering: fix hashes commit 153fec46270212af03f3631bfb42c5d680c4e142 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 16:15:15 2023 +0300 filtering: add test cases commit 09372f92bbb1fc082f1b1283594ee589100209c5 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 15:38:05 2023 +0300 filtering: imp code commit 466bc26d524ea6d1c3efb33692a7785d39e491ca Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 18:38:40 2023 +0300 filtering: add tests commit 24365ecf8c60512fdac65833ee603c80864ae018 Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 11:38:57 2023 +0300 filtering: add hashprefix </s> remove "github.com/AdguardTeam/dnsproxy/upstream" "github.com/AdguardTeam/golibs/cache" </s> add </s> remove "github.com/AdguardTeam/golibs/stringutil" "github.com/miekg/dns" "golang.org/x/exp/slices" "golang.org/x/net/publicsuffix" </s> add </s> remove "time" </s> add </s> add "github.com/AdguardTeam/dnsproxy/upstream" </s> remove "github.com/AdguardTeam/golibs/cache" </s> add "github.com/AdguardTeam/AdGuardHome/internal/filtering/hashprefix" </s> remove "strings" </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c
internal/filtering/filtering.go
keep add keep keep keep keep
<mask> // Config allows you to configure DNS filtering with New() or just change variables directly. <mask> type Config struct { <mask> // enabled is used to be returned within Settings. <mask> // <mask> // It is of type uint32 to be accessed by atomic. <mask> // </s> Pull request 1837: AG-21462-imp-safebrowsing-parental Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master Squashed commit of the following: commit 85016d4f1105e21a407efade0bd45b8362808061 Merge: 0e61edade 620b51e3e Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 16:36:30 2023 +0300 Merge branch 'master' into AG-21462-imp-safebrowsing-parental commit 0e61edadeff34f6305e941c1db94575c82f238d9 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 14:51:37 2023 +0300 filtering: imp tests commit 994255514cc0f67dfe33d5a0892432e8924d1e36 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:13:19 2023 +0300 filtering: fix typo commit 96d1069573171538333330d6af94ef0f4208a9c4 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:00:18 2023 +0300 filtering: imp code more commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 19:13:26 2023 +0300 all: add todo commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 14:36:08 2023 +0300 all: imp code more commit b6e734ccbeda82669023f6578481260b7c1f7161 Author: Stanislav Chzhen <[email protected]> Date: Tue Apr 25 15:01:56 2023 +0300 filtering: imp code commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 20:06:36 2023 +0300 all: imp code commit 49fa6e587052a40bb431fea457701ee860493527 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 14:57:19 2023 +0300 all: rm safe browsing ctx commit bbcb66cb03e18fa875e3c33cf16295892739e507 Author: Stanislav Chzhen <[email protected]> Date: Fri Apr 21 17:54:18 2023 +0300 filtering: add cache item commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 18:43:02 2023 +0300 filtering: fix hashes commit 153fec46270212af03f3631bfb42c5d680c4e142 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 16:15:15 2023 +0300 filtering: add test cases commit 09372f92bbb1fc082f1b1283594ee589100209c5 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 15:38:05 2023 +0300 filtering: imp code commit 466bc26d524ea6d1c3efb33692a7785d39e491ca Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 18:38:40 2023 +0300 filtering: add tests commit 24365ecf8c60512fdac65833ee603c80864ae018 Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 11:38:57 2023 +0300 filtering: add hashprefix </s> add // Checker is used for safe browsing or parental control hash-prefix filtering. type Checker interface { // Check returns true if request for the host should be blocked. Check(host string) (block bool, err error) } </s> remove refreshLock: &sync.Mutex{}, filterTitleRegexp: regexp.MustCompile(`^! Title: +(.*)$`), </s> add refreshLock: &sync.Mutex{}, filterTitleRegexp: regexp.MustCompile(`^! Title: +(.*)$`), safeBrowsingChecker: c.SafeBrowsingChecker, parentalControlChecker: c.ParentalControlChecker, </s> add safeSearch SafeSearch // safeBrowsingChecker is the safe browsing hash-prefix checker. safeBrowsingChecker Checker // parentalControl is the parental control hash-prefix checker. parentalControlChecker Checker </s> remove parentalServer string // access via methods safeBrowsingServer string // access via methods parentalUpstream upstream.Upstream safeBrowsingUpstream upstream.Upstream safebrowsingCache cache.Cache parentalCache cache.Cache </s> add </s> remove safeSearch SafeSearch </s> add </s> remove // TODO(a.garipov): Make configurable. const ( dnsTimeout = 3 * time.Second defaultSafebrowsingServer = `https://family.adguard-dns.com/dns-query` defaultParentalServer = `https://family.adguard-dns.com/dns-query` sbTXTSuffix = `sb.dns.adguard.com.` pcTXTSuffix = `pc.dns.adguard.com.` ) // SetParentalUpstream sets the parental upstream for *DNSFilter. // // TODO(e.burkov): Remove this in v1 API to forbid the direct access. func (d *DNSFilter) SetParentalUpstream(u upstream.Upstream) { d.parentalUpstream = u } // SetSafeBrowsingUpstream sets the safe browsing upstream for *DNSFilter. // // TODO(e.burkov): Remove this in v1 API to forbid the direct access. func (d *DNSFilter) SetSafeBrowsingUpstream(u upstream.Upstream) { d.safeBrowsingUpstream = u } func (d *DNSFilter) initSecurityServices() error { var err error d.safeBrowsingServer = defaultSafebrowsingServer d.parentalServer = defaultParentalServer opts := &upstream.Options{ Timeout: dnsTimeout, ServerIPAddrs: []net.IP{ {94, 140, 14, 15}, {94, 140, 15, 16}, net.ParseIP("2a10:50c0::bad1:ff"), net.ParseIP("2a10:50c0::bad2:ff"), }, } parUps, err := upstream.AddressToUpstream(d.parentalServer, opts) if err != nil { return fmt.Errorf("converting parental server: %w", err) } d.SetParentalUpstream(parUps) sbUps, err := upstream.AddressToUpstream(d.safeBrowsingServer, opts) if err != nil { return fmt.Errorf("converting safe browsing server: %w", err) } d.SetSafeBrowsingUpstream(sbUps) return nil } /* expire byte[4] hash byte[32] ... */ func (c *sbCtx) setCache(prefix, hashes []byte) { d := make([]byte, 4+len(hashes)) expire := uint(time.Now().Unix()) + c.cacheTime*60 binary.BigEndian.PutUint32(d[:4], uint32(expire)) copy(d[4:], hashes) c.cache.Set(prefix, d) log.Debug("%s: stored in cache: %v", c.svc, prefix) } // findInHash returns 32-byte hash if it's found in hashToHost. func (c *sbCtx) findInHash(val []byte) (hash32 [32]byte, found bool) { for i := 4; i < len(val); i += 32 { hash := val[i : i+32] copy(hash32[:], hash[0:32]) _, found = c.hashToHost[hash32] if found { return hash32, found } } return [32]byte{}, false } func (c *sbCtx) getCached() int { now := time.Now().Unix() hashesToRequest := map[[32]byte]string{} for k, v := range c.hashToHost { // nolint:looppointer // The subsilce is used for a safe cache lookup. val := c.cache.Get(k[0:2]) if val == nil || now >= int64(binary.BigEndian.Uint32(val)) { hashesToRequest[k] = v continue } if hash32, found := c.findInHash(val); found { log.Debug("%s: found in cache: %s: blocked by %v", c.svc, c.host, hash32) return 1 } } if len(hashesToRequest) == 0 { log.Debug("%s: found in cache: %s: not blocked", c.svc, c.host) return -1 } c.hashToHost = hashesToRequest return 0 } type sbCtx struct { host string svc string hashToHost map[[32]byte]string cache cache.Cache cacheTime uint } func hostnameToHashes(host string) map[[32]byte]string { hashes := map[[32]byte]string{} tld, icann := publicsuffix.PublicSuffix(host) if !icann { // private suffixes like cloudfront.net tld = "" } curhost := host nDots := 0 for i := len(curhost) - 1; i >= 0; i-- { if curhost[i] == '.' { nDots++ if nDots == 4 { curhost = curhost[i+1:] // "xxx.a.b.c.d" -> "a.b.c.d" break } } } for { if curhost == "" { // we've reached end of string break } if tld != "" && curhost == tld { // we've reached the TLD, don't hash it break } sum := sha256.Sum256([]byte(curhost)) hashes[sum] = curhost pos := strings.IndexByte(curhost, byte('.')) if pos < 0 { break } curhost = curhost[pos+1:] } return hashes } // convert hash array to string func (c *sbCtx) getQuestion() string { b := &strings.Builder{} for hash := range c.hashToHost { // nolint:looppointer // The subsilce is used for safe hex encoding. stringutil.WriteToBuilder(b, hex.EncodeToString(hash[0:2]), ".") } if c.svc == "SafeBrowsing" { stringutil.WriteToBuilder(b, sbTXTSuffix) return b.String() } stringutil.WriteToBuilder(b, pcTXTSuffix) return b.String() } // Find the target hash in TXT response func (c *sbCtx) processTXT(resp *dns.Msg) (bool, [][]byte) { matched := false hashes := [][]byte{} for _, a := range resp.Answer { txt, ok := a.(*dns.TXT) if !ok { continue } log.Debug("%s: received hashes for %s: %v", c.svc, c.host, txt.Txt) for _, t := range txt.Txt { if len(t) != 32*2 { continue } hash, err := hex.DecodeString(t) if err != nil { continue } hashes = append(hashes, hash) if !matched { var hash32 [32]byte copy(hash32[:], hash) var hashHost string hashHost, ok = c.hashToHost[hash32] if ok { log.Debug("%s: matched %s by %s/%s", c.svc, c.host, hashHost, t) matched = true } } } } return matched, hashes } func (c *sbCtx) storeCache(hashes [][]byte) { slices.SortFunc(hashes, func(a, b []byte) (sortsBefore bool) { return bytes.Compare(a, b) == -1 }) var curData []byte var prevPrefix []byte for i, hash := range hashes { // nolint:looppointer // The subsilce is used for a safe comparison. if !bytes.Equal(hash[0:2], prevPrefix) { if i != 0 { c.setCache(prevPrefix, curData) curData = nil } prevPrefix = hashes[i][0:2] } curData = append(curData, hash...) } if len(prevPrefix) != 0 { c.setCache(prevPrefix, curData) } for hash := range c.hashToHost { // nolint:looppointer // The subsilce is used for a safe cache lookup. prefix := hash[0:2] val := c.cache.Get(prefix) if val == nil { c.setCache(prefix, nil) } } } func check(c *sbCtx, r Result, u upstream.Upstream) (Result, error) { c.hashToHost = hostnameToHashes(c.host) switch c.getCached() { case -1: return Result{}, nil case 1: return r, nil } question := c.getQuestion() log.Tracef("%s: checking %s: %s", c.svc, c.host, question) req := (&dns.Msg{}).SetQuestion(question, dns.TypeTXT) resp, err := u.Exchange(req) if err != nil { return Result{}, err } matched, receivedHashes := c.processTXT(resp) c.storeCache(receivedHashes) if matched { return r, nil } return Result{}, nil } </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c
internal/filtering/filtering.go
keep keep keep add keep keep keep keep keep
<mask> check func(host string, qtype uint16, setts *Settings) (res Result, err error) <mask> name string <mask> } <mask> <mask> // DNSFilter matches hostnames and DNS requests against filtering rules. <mask> type DNSFilter struct { <mask> safeSearch SafeSearch <mask> <mask> // safeBrowsingChecker is the safe browsing hash-prefix checker. </s> Pull request 1837: AG-21462-imp-safebrowsing-parental Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master Squashed commit of the following: commit 85016d4f1105e21a407efade0bd45b8362808061 Merge: 0e61edade 620b51e3e Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 16:36:30 2023 +0300 Merge branch 'master' into AG-21462-imp-safebrowsing-parental commit 0e61edadeff34f6305e941c1db94575c82f238d9 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 14:51:37 2023 +0300 filtering: imp tests commit 994255514cc0f67dfe33d5a0892432e8924d1e36 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:13:19 2023 +0300 filtering: fix typo commit 96d1069573171538333330d6af94ef0f4208a9c4 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:00:18 2023 +0300 filtering: imp code more commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 19:13:26 2023 +0300 all: add todo commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 14:36:08 2023 +0300 all: imp code more commit b6e734ccbeda82669023f6578481260b7c1f7161 Author: Stanislav Chzhen <[email protected]> Date: Tue Apr 25 15:01:56 2023 +0300 filtering: imp code commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 20:06:36 2023 +0300 all: imp code commit 49fa6e587052a40bb431fea457701ee860493527 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 14:57:19 2023 +0300 all: rm safe browsing ctx commit bbcb66cb03e18fa875e3c33cf16295892739e507 Author: Stanislav Chzhen <[email protected]> Date: Fri Apr 21 17:54:18 2023 +0300 filtering: add cache item commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 18:43:02 2023 +0300 filtering: fix hashes commit 153fec46270212af03f3631bfb42c5d680c4e142 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 16:15:15 2023 +0300 filtering: add test cases commit 09372f92bbb1fc082f1b1283594ee589100209c5 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 15:38:05 2023 +0300 filtering: imp code commit 466bc26d524ea6d1c3efb33692a7785d39e491ca Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 18:38:40 2023 +0300 filtering: add tests commit 24365ecf8c60512fdac65833ee603c80864ae018 Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 11:38:57 2023 +0300 filtering: add hashprefix </s> add safeSearch SafeSearch // safeBrowsingChecker is the safe browsing hash-prefix checker. safeBrowsingChecker Checker // parentalControl is the parental control hash-prefix checker. parentalControlChecker Checker </s> add // SafeBrowsingChecker is the safe browsing hash-prefix checker. SafeBrowsingChecker Checker `yaml:"-"` // ParentControl is the parental control hash-prefix checker. ParentalControlChecker Checker `yaml:"-"` </s> remove safeSearch SafeSearch </s> add </s> remove d.SetParentalUpstream(aghtest.NewBlockUpstream(pcBlocked, true)) d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true)) </s> add </s> remove // TODO(a.garipov): Make configurable. const ( dnsTimeout = 3 * time.Second defaultSafebrowsingServer = `https://family.adguard-dns.com/dns-query` defaultParentalServer = `https://family.adguard-dns.com/dns-query` sbTXTSuffix = `sb.dns.adguard.com.` pcTXTSuffix = `pc.dns.adguard.com.` ) // SetParentalUpstream sets the parental upstream for *DNSFilter. // // TODO(e.burkov): Remove this in v1 API to forbid the direct access. func (d *DNSFilter) SetParentalUpstream(u upstream.Upstream) { d.parentalUpstream = u } // SetSafeBrowsingUpstream sets the safe browsing upstream for *DNSFilter. // // TODO(e.burkov): Remove this in v1 API to forbid the direct access. func (d *DNSFilter) SetSafeBrowsingUpstream(u upstream.Upstream) { d.safeBrowsingUpstream = u } func (d *DNSFilter) initSecurityServices() error { var err error d.safeBrowsingServer = defaultSafebrowsingServer d.parentalServer = defaultParentalServer opts := &upstream.Options{ Timeout: dnsTimeout, ServerIPAddrs: []net.IP{ {94, 140, 14, 15}, {94, 140, 15, 16}, net.ParseIP("2a10:50c0::bad1:ff"), net.ParseIP("2a10:50c0::bad2:ff"), }, } parUps, err := upstream.AddressToUpstream(d.parentalServer, opts) if err != nil { return fmt.Errorf("converting parental server: %w", err) } d.SetParentalUpstream(parUps) sbUps, err := upstream.AddressToUpstream(d.safeBrowsingServer, opts) if err != nil { return fmt.Errorf("converting safe browsing server: %w", err) } d.SetSafeBrowsingUpstream(sbUps) return nil } /* expire byte[4] hash byte[32] ... */ func (c *sbCtx) setCache(prefix, hashes []byte) { d := make([]byte, 4+len(hashes)) expire := uint(time.Now().Unix()) + c.cacheTime*60 binary.BigEndian.PutUint32(d[:4], uint32(expire)) copy(d[4:], hashes) c.cache.Set(prefix, d) log.Debug("%s: stored in cache: %v", c.svc, prefix) } // findInHash returns 32-byte hash if it's found in hashToHost. func (c *sbCtx) findInHash(val []byte) (hash32 [32]byte, found bool) { for i := 4; i < len(val); i += 32 { hash := val[i : i+32] copy(hash32[:], hash[0:32]) _, found = c.hashToHost[hash32] if found { return hash32, found } } return [32]byte{}, false } func (c *sbCtx) getCached() int { now := time.Now().Unix() hashesToRequest := map[[32]byte]string{} for k, v := range c.hashToHost { // nolint:looppointer // The subsilce is used for a safe cache lookup. val := c.cache.Get(k[0:2]) if val == nil || now >= int64(binary.BigEndian.Uint32(val)) { hashesToRequest[k] = v continue } if hash32, found := c.findInHash(val); found { log.Debug("%s: found in cache: %s: blocked by %v", c.svc, c.host, hash32) return 1 } } if len(hashesToRequest) == 0 { log.Debug("%s: found in cache: %s: not blocked", c.svc, c.host) return -1 } c.hashToHost = hashesToRequest return 0 } type sbCtx struct { host string svc string hashToHost map[[32]byte]string cache cache.Cache cacheTime uint } func hostnameToHashes(host string) map[[32]byte]string { hashes := map[[32]byte]string{} tld, icann := publicsuffix.PublicSuffix(host) if !icann { // private suffixes like cloudfront.net tld = "" } curhost := host nDots := 0 for i := len(curhost) - 1; i >= 0; i-- { if curhost[i] == '.' { nDots++ if nDots == 4 { curhost = curhost[i+1:] // "xxx.a.b.c.d" -> "a.b.c.d" break } } } for { if curhost == "" { // we've reached end of string break } if tld != "" && curhost == tld { // we've reached the TLD, don't hash it break } sum := sha256.Sum256([]byte(curhost)) hashes[sum] = curhost pos := strings.IndexByte(curhost, byte('.')) if pos < 0 { break } curhost = curhost[pos+1:] } return hashes } // convert hash array to string func (c *sbCtx) getQuestion() string { b := &strings.Builder{} for hash := range c.hashToHost { // nolint:looppointer // The subsilce is used for safe hex encoding. stringutil.WriteToBuilder(b, hex.EncodeToString(hash[0:2]), ".") } if c.svc == "SafeBrowsing" { stringutil.WriteToBuilder(b, sbTXTSuffix) return b.String() } stringutil.WriteToBuilder(b, pcTXTSuffix) return b.String() } // Find the target hash in TXT response func (c *sbCtx) processTXT(resp *dns.Msg) (bool, [][]byte) { matched := false hashes := [][]byte{} for _, a := range resp.Answer { txt, ok := a.(*dns.TXT) if !ok { continue } log.Debug("%s: received hashes for %s: %v", c.svc, c.host, txt.Txt) for _, t := range txt.Txt { if len(t) != 32*2 { continue } hash, err := hex.DecodeString(t) if err != nil { continue } hashes = append(hashes, hash) if !matched { var hash32 [32]byte copy(hash32[:], hash) var hashHost string hashHost, ok = c.hashToHost[hash32] if ok { log.Debug("%s: matched %s by %s/%s", c.svc, c.host, hashHost, t) matched = true } } } } return matched, hashes } func (c *sbCtx) storeCache(hashes [][]byte) { slices.SortFunc(hashes, func(a, b []byte) (sortsBefore bool) { return bytes.Compare(a, b) == -1 }) var curData []byte var prevPrefix []byte for i, hash := range hashes { // nolint:looppointer // The subsilce is used for a safe comparison. if !bytes.Equal(hash[0:2], prevPrefix) { if i != 0 { c.setCache(prevPrefix, curData) curData = nil } prevPrefix = hashes[i][0:2] } curData = append(curData, hash...) } if len(prevPrefix) != 0 { c.setCache(prevPrefix, curData) } for hash := range c.hashToHost { // nolint:looppointer // The subsilce is used for a safe cache lookup. prefix := hash[0:2] val := c.cache.Get(prefix) if val == nil { c.setCache(prefix, nil) } } } func check(c *sbCtx, r Result, u upstream.Upstream) (Result, error) { c.hashToHost = hostnameToHashes(c.host) switch c.getCached() { case -1: return Result{}, nil case 1: return r, nil } question := c.getQuestion() log.Tracef("%s: checking %s: %s", c.svc, c.host, question) req := (&dns.Msg{}).SetQuestion(question, dns.TypeTXT) resp, err := u.Exchange(req) if err != nil { return Result{}, err } matched, receivedHashes := c.processTXT(resp) c.storeCache(receivedHashes) if matched { return r, nil } return Result{}, nil } </s> add </s> remove refreshLock: &sync.Mutex{}, filterTitleRegexp: regexp.MustCompile(`^! Title: +(.*)$`), </s> add refreshLock: &sync.Mutex{}, filterTitleRegexp: regexp.MustCompile(`^! Title: +(.*)$`), safeBrowsingChecker: c.SafeBrowsingChecker, parentalControlChecker: c.ParentalControlChecker,
https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c
internal/filtering/filtering.go
keep keep keep add keep keep keep keep keep keep
<mask> } <mask> <mask> // DNSFilter matches hostnames and DNS requests against filtering rules. <mask> type DNSFilter struct { <mask> rulesStorage *filterlist.RuleStorage <mask> filteringEngine *urlfilter.DNSEngine <mask> <mask> rulesStorageAllow *filterlist.RuleStorage <mask> filteringEngineAllow *urlfilter.DNSEngine <mask> </s> Pull request 1837: AG-21462-imp-safebrowsing-parental Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master Squashed commit of the following: commit 85016d4f1105e21a407efade0bd45b8362808061 Merge: 0e61edade 620b51e3e Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 16:36:30 2023 +0300 Merge branch 'master' into AG-21462-imp-safebrowsing-parental commit 0e61edadeff34f6305e941c1db94575c82f238d9 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 14:51:37 2023 +0300 filtering: imp tests commit 994255514cc0f67dfe33d5a0892432e8924d1e36 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:13:19 2023 +0300 filtering: fix typo commit 96d1069573171538333330d6af94ef0f4208a9c4 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:00:18 2023 +0300 filtering: imp code more commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 19:13:26 2023 +0300 all: add todo commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 14:36:08 2023 +0300 all: imp code more commit b6e734ccbeda82669023f6578481260b7c1f7161 Author: Stanislav Chzhen <[email protected]> Date: Tue Apr 25 15:01:56 2023 +0300 filtering: imp code commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 20:06:36 2023 +0300 all: imp code commit 49fa6e587052a40bb431fea457701ee860493527 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 14:57:19 2023 +0300 all: rm safe browsing ctx commit bbcb66cb03e18fa875e3c33cf16295892739e507 Author: Stanislav Chzhen <[email protected]> Date: Fri Apr 21 17:54:18 2023 +0300 filtering: add cache item commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 18:43:02 2023 +0300 filtering: fix hashes commit 153fec46270212af03f3631bfb42c5d680c4e142 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 16:15:15 2023 +0300 filtering: add test cases commit 09372f92bbb1fc082f1b1283594ee589100209c5 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 15:38:05 2023 +0300 filtering: imp code commit 466bc26d524ea6d1c3efb33692a7785d39e491ca Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 18:38:40 2023 +0300 filtering: add tests commit 24365ecf8c60512fdac65833ee603c80864ae018 Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 11:38:57 2023 +0300 filtering: add hashprefix </s> add // Checker is used for safe browsing or parental control hash-prefix filtering. type Checker interface { // Check returns true if request for the host should be blocked. Check(host string) (block bool, err error) } </s> add // SafeBrowsingChecker is the safe browsing hash-prefix checker. SafeBrowsingChecker Checker `yaml:"-"` // ParentControl is the parental control hash-prefix checker. ParentalControlChecker Checker `yaml:"-"` </s> remove parentalServer string // access via methods safeBrowsingServer string // access via methods parentalUpstream upstream.Upstream safeBrowsingUpstream upstream.Upstream safebrowsingCache cache.Cache parentalCache cache.Cache </s> add </s> remove safeSearch SafeSearch </s> add </s> remove d.SetParentalUpstream(aghtest.NewBlockUpstream(pcBlocked, true)) d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true)) </s> add </s> remove refreshLock: &sync.Mutex{}, filterTitleRegexp: regexp.MustCompile(`^! Title: +(.*)$`), </s> add refreshLock: &sync.Mutex{}, filterTitleRegexp: regexp.MustCompile(`^! Title: +(.*)$`), safeBrowsingChecker: c.SafeBrowsingChecker, parentalControlChecker: c.ParentalControlChecker,
https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c
internal/filtering/filtering.go
keep keep keep keep replace replace replace replace replace replace replace replace keep keep keep keep keep
<mask> filteringEngineAllow *urlfilter.DNSEngine <mask> <mask> engineLock sync.RWMutex <mask> <mask> parentalServer string // access via methods <mask> safeBrowsingServer string // access via methods <mask> parentalUpstream upstream.Upstream <mask> safeBrowsingUpstream upstream.Upstream <mask> <mask> safebrowsingCache cache.Cache <mask> parentalCache cache.Cache <mask> <mask> Config // for direct access by library users, even a = assignment <mask> // confLock protects Config. <mask> confLock sync.RWMutex <mask> <mask> // Channel for passing data to filters-initializer goroutine </s> Pull request 1837: AG-21462-imp-safebrowsing-parental Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master Squashed commit of the following: commit 85016d4f1105e21a407efade0bd45b8362808061 Merge: 0e61edade 620b51e3e Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 16:36:30 2023 +0300 Merge branch 'master' into AG-21462-imp-safebrowsing-parental commit 0e61edadeff34f6305e941c1db94575c82f238d9 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 14:51:37 2023 +0300 filtering: imp tests commit 994255514cc0f67dfe33d5a0892432e8924d1e36 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:13:19 2023 +0300 filtering: fix typo commit 96d1069573171538333330d6af94ef0f4208a9c4 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:00:18 2023 +0300 filtering: imp code more commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 19:13:26 2023 +0300 all: add todo commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 14:36:08 2023 +0300 all: imp code more commit b6e734ccbeda82669023f6578481260b7c1f7161 Author: Stanislav Chzhen <[email protected]> Date: Tue Apr 25 15:01:56 2023 +0300 filtering: imp code commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 20:06:36 2023 +0300 all: imp code commit 49fa6e587052a40bb431fea457701ee860493527 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 14:57:19 2023 +0300 all: rm safe browsing ctx commit bbcb66cb03e18fa875e3c33cf16295892739e507 Author: Stanislav Chzhen <[email protected]> Date: Fri Apr 21 17:54:18 2023 +0300 filtering: add cache item commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 18:43:02 2023 +0300 filtering: fix hashes commit 153fec46270212af03f3631bfb42c5d680c4e142 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 16:15:15 2023 +0300 filtering: add test cases commit 09372f92bbb1fc082f1b1283594ee589100209c5 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 15:38:05 2023 +0300 filtering: imp code commit 466bc26d524ea6d1c3efb33692a7785d39e491ca Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 18:38:40 2023 +0300 filtering: add tests commit 24365ecf8c60512fdac65833ee603c80864ae018 Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 11:38:57 2023 +0300 filtering: add hashprefix </s> add // SafeBrowsingChecker is the safe browsing hash-prefix checker. SafeBrowsingChecker Checker `yaml:"-"` // ParentControl is the parental control hash-prefix checker. ParentalControlChecker Checker `yaml:"-"` </s> remove // TODO(a.garipov): Make configurable. const ( dnsTimeout = 3 * time.Second defaultSafebrowsingServer = `https://family.adguard-dns.com/dns-query` defaultParentalServer = `https://family.adguard-dns.com/dns-query` sbTXTSuffix = `sb.dns.adguard.com.` pcTXTSuffix = `pc.dns.adguard.com.` ) // SetParentalUpstream sets the parental upstream for *DNSFilter. // // TODO(e.burkov): Remove this in v1 API to forbid the direct access. func (d *DNSFilter) SetParentalUpstream(u upstream.Upstream) { d.parentalUpstream = u } // SetSafeBrowsingUpstream sets the safe browsing upstream for *DNSFilter. // // TODO(e.burkov): Remove this in v1 API to forbid the direct access. func (d *DNSFilter) SetSafeBrowsingUpstream(u upstream.Upstream) { d.safeBrowsingUpstream = u } func (d *DNSFilter) initSecurityServices() error { var err error d.safeBrowsingServer = defaultSafebrowsingServer d.parentalServer = defaultParentalServer opts := &upstream.Options{ Timeout: dnsTimeout, ServerIPAddrs: []net.IP{ {94, 140, 14, 15}, {94, 140, 15, 16}, net.ParseIP("2a10:50c0::bad1:ff"), net.ParseIP("2a10:50c0::bad2:ff"), }, } parUps, err := upstream.AddressToUpstream(d.parentalServer, opts) if err != nil { return fmt.Errorf("converting parental server: %w", err) } d.SetParentalUpstream(parUps) sbUps, err := upstream.AddressToUpstream(d.safeBrowsingServer, opts) if err != nil { return fmt.Errorf("converting safe browsing server: %w", err) } d.SetSafeBrowsingUpstream(sbUps) return nil } /* expire byte[4] hash byte[32] ... */ func (c *sbCtx) setCache(prefix, hashes []byte) { d := make([]byte, 4+len(hashes)) expire := uint(time.Now().Unix()) + c.cacheTime*60 binary.BigEndian.PutUint32(d[:4], uint32(expire)) copy(d[4:], hashes) c.cache.Set(prefix, d) log.Debug("%s: stored in cache: %v", c.svc, prefix) } // findInHash returns 32-byte hash if it's found in hashToHost. func (c *sbCtx) findInHash(val []byte) (hash32 [32]byte, found bool) { for i := 4; i < len(val); i += 32 { hash := val[i : i+32] copy(hash32[:], hash[0:32]) _, found = c.hashToHost[hash32] if found { return hash32, found } } return [32]byte{}, false } func (c *sbCtx) getCached() int { now := time.Now().Unix() hashesToRequest := map[[32]byte]string{} for k, v := range c.hashToHost { // nolint:looppointer // The subsilce is used for a safe cache lookup. val := c.cache.Get(k[0:2]) if val == nil || now >= int64(binary.BigEndian.Uint32(val)) { hashesToRequest[k] = v continue } if hash32, found := c.findInHash(val); found { log.Debug("%s: found in cache: %s: blocked by %v", c.svc, c.host, hash32) return 1 } } if len(hashesToRequest) == 0 { log.Debug("%s: found in cache: %s: not blocked", c.svc, c.host) return -1 } c.hashToHost = hashesToRequest return 0 } type sbCtx struct { host string svc string hashToHost map[[32]byte]string cache cache.Cache cacheTime uint } func hostnameToHashes(host string) map[[32]byte]string { hashes := map[[32]byte]string{} tld, icann := publicsuffix.PublicSuffix(host) if !icann { // private suffixes like cloudfront.net tld = "" } curhost := host nDots := 0 for i := len(curhost) - 1; i >= 0; i-- { if curhost[i] == '.' { nDots++ if nDots == 4 { curhost = curhost[i+1:] // "xxx.a.b.c.d" -> "a.b.c.d" break } } } for { if curhost == "" { // we've reached end of string break } if tld != "" && curhost == tld { // we've reached the TLD, don't hash it break } sum := sha256.Sum256([]byte(curhost)) hashes[sum] = curhost pos := strings.IndexByte(curhost, byte('.')) if pos < 0 { break } curhost = curhost[pos+1:] } return hashes } // convert hash array to string func (c *sbCtx) getQuestion() string { b := &strings.Builder{} for hash := range c.hashToHost { // nolint:looppointer // The subsilce is used for safe hex encoding. stringutil.WriteToBuilder(b, hex.EncodeToString(hash[0:2]), ".") } if c.svc == "SafeBrowsing" { stringutil.WriteToBuilder(b, sbTXTSuffix) return b.String() } stringutil.WriteToBuilder(b, pcTXTSuffix) return b.String() } // Find the target hash in TXT response func (c *sbCtx) processTXT(resp *dns.Msg) (bool, [][]byte) { matched := false hashes := [][]byte{} for _, a := range resp.Answer { txt, ok := a.(*dns.TXT) if !ok { continue } log.Debug("%s: received hashes for %s: %v", c.svc, c.host, txt.Txt) for _, t := range txt.Txt { if len(t) != 32*2 { continue } hash, err := hex.DecodeString(t) if err != nil { continue } hashes = append(hashes, hash) if !matched { var hash32 [32]byte copy(hash32[:], hash) var hashHost string hashHost, ok = c.hashToHost[hash32] if ok { log.Debug("%s: matched %s by %s/%s", c.svc, c.host, hashHost, t) matched = true } } } } return matched, hashes } func (c *sbCtx) storeCache(hashes [][]byte) { slices.SortFunc(hashes, func(a, b []byte) (sortsBefore bool) { return bytes.Compare(a, b) == -1 }) var curData []byte var prevPrefix []byte for i, hash := range hashes { // nolint:looppointer // The subsilce is used for a safe comparison. if !bytes.Equal(hash[0:2], prevPrefix) { if i != 0 { c.setCache(prevPrefix, curData) curData = nil } prevPrefix = hashes[i][0:2] } curData = append(curData, hash...) } if len(prevPrefix) != 0 { c.setCache(prevPrefix, curData) } for hash := range c.hashToHost { // nolint:looppointer // The subsilce is used for a safe cache lookup. prefix := hash[0:2] val := c.cache.Get(prefix) if val == nil { c.setCache(prefix, nil) } } } func check(c *sbCtx, r Result, u upstream.Upstream) (Result, error) { c.hashToHost = hostnameToHashes(c.host) switch c.getCached() { case -1: return Result{}, nil case 1: return r, nil } question := c.getQuestion() log.Tracef("%s: checking %s: %s", c.svc, c.host, question) req := (&dns.Msg{}).SetQuestion(question, dns.TypeTXT) resp, err := u.Exchange(req) if err != nil { return Result{}, err } matched, receivedHashes := c.processTXT(resp) c.storeCache(receivedHashes) if matched { return r, nil } return Result{}, nil } </s> add </s> add safeSearch SafeSearch // safeBrowsingChecker is the safe browsing hash-prefix checker. safeBrowsingChecker Checker // parentalControl is the parental control hash-prefix checker. parentalControlChecker Checker </s> remove safeSearch SafeSearch </s> add </s> add // Checker is used for safe browsing or parental control hash-prefix filtering. type Checker interface { // Check returns true if request for the host should be blocked. Check(host string) (block bool, err error) } </s> remove return check(sctx, res, d.parentalUpstream) </s> add block, err := d.parentalControlChecker.Check(host) if !block || err != nil { return Result{}, err } return res, nil
https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c
internal/filtering/filtering.go
keep keep keep keep replace keep keep keep keep keep
<mask> // <mask> // TODO(e.burkov): Don't use regexp for such a simple text processing task. <mask> filterTitleRegexp *regexp.Regexp <mask> <mask> safeSearch SafeSearch <mask> hostCheckers []hostChecker <mask> } <mask> <mask> // Filter represents a filter list <mask> type Filter struct { </s> Pull request 1837: AG-21462-imp-safebrowsing-parental Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master Squashed commit of the following: commit 85016d4f1105e21a407efade0bd45b8362808061 Merge: 0e61edade 620b51e3e Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 16:36:30 2023 +0300 Merge branch 'master' into AG-21462-imp-safebrowsing-parental commit 0e61edadeff34f6305e941c1db94575c82f238d9 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 14:51:37 2023 +0300 filtering: imp tests commit 994255514cc0f67dfe33d5a0892432e8924d1e36 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:13:19 2023 +0300 filtering: fix typo commit 96d1069573171538333330d6af94ef0f4208a9c4 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:00:18 2023 +0300 filtering: imp code more commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 19:13:26 2023 +0300 all: add todo commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 14:36:08 2023 +0300 all: imp code more commit b6e734ccbeda82669023f6578481260b7c1f7161 Author: Stanislav Chzhen <[email protected]> Date: Tue Apr 25 15:01:56 2023 +0300 filtering: imp code commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 20:06:36 2023 +0300 all: imp code commit 49fa6e587052a40bb431fea457701ee860493527 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 14:57:19 2023 +0300 all: rm safe browsing ctx commit bbcb66cb03e18fa875e3c33cf16295892739e507 Author: Stanislav Chzhen <[email protected]> Date: Fri Apr 21 17:54:18 2023 +0300 filtering: add cache item commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 18:43:02 2023 +0300 filtering: fix hashes commit 153fec46270212af03f3631bfb42c5d680c4e142 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 16:15:15 2023 +0300 filtering: add test cases commit 09372f92bbb1fc082f1b1283594ee589100209c5 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 15:38:05 2023 +0300 filtering: imp code commit 466bc26d524ea6d1c3efb33692a7785d39e491ca Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 18:38:40 2023 +0300 filtering: add tests commit 24365ecf8c60512fdac65833ee603c80864ae018 Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 11:38:57 2023 +0300 filtering: add hashprefix </s> add // Checker is used for safe browsing or parental control hash-prefix filtering. type Checker interface { // Check returns true if request for the host should be blocked. Check(host string) (block bool, err error) } </s> add safeSearch SafeSearch // safeBrowsingChecker is the safe browsing hash-prefix checker. safeBrowsingChecker Checker // parentalControl is the parental control hash-prefix checker. parentalControlChecker Checker </s> remove return check(sctx, res, d.parentalUpstream) </s> add block, err := d.parentalControlChecker.Check(host) if !block || err != nil { return Result{}, err } return res, nil </s> remove refreshLock: &sync.Mutex{}, filterTitleRegexp: regexp.MustCompile(`^! Title: +(.*)$`), </s> add refreshLock: &sync.Mutex{}, filterTitleRegexp: regexp.MustCompile(`^! Title: +(.*)$`), safeBrowsingChecker: c.SafeBrowsingChecker, parentalControlChecker: c.ParentalControlChecker, </s> remove // TODO(a.garipov): Make configurable. const ( dnsTimeout = 3 * time.Second defaultSafebrowsingServer = `https://family.adguard-dns.com/dns-query` defaultParentalServer = `https://family.adguard-dns.com/dns-query` sbTXTSuffix = `sb.dns.adguard.com.` pcTXTSuffix = `pc.dns.adguard.com.` ) // SetParentalUpstream sets the parental upstream for *DNSFilter. // // TODO(e.burkov): Remove this in v1 API to forbid the direct access. func (d *DNSFilter) SetParentalUpstream(u upstream.Upstream) { d.parentalUpstream = u } // SetSafeBrowsingUpstream sets the safe browsing upstream for *DNSFilter. // // TODO(e.burkov): Remove this in v1 API to forbid the direct access. func (d *DNSFilter) SetSafeBrowsingUpstream(u upstream.Upstream) { d.safeBrowsingUpstream = u } func (d *DNSFilter) initSecurityServices() error { var err error d.safeBrowsingServer = defaultSafebrowsingServer d.parentalServer = defaultParentalServer opts := &upstream.Options{ Timeout: dnsTimeout, ServerIPAddrs: []net.IP{ {94, 140, 14, 15}, {94, 140, 15, 16}, net.ParseIP("2a10:50c0::bad1:ff"), net.ParseIP("2a10:50c0::bad2:ff"), }, } parUps, err := upstream.AddressToUpstream(d.parentalServer, opts) if err != nil { return fmt.Errorf("converting parental server: %w", err) } d.SetParentalUpstream(parUps) sbUps, err := upstream.AddressToUpstream(d.safeBrowsingServer, opts) if err != nil { return fmt.Errorf("converting safe browsing server: %w", err) } d.SetSafeBrowsingUpstream(sbUps) return nil } /* expire byte[4] hash byte[32] ... */ func (c *sbCtx) setCache(prefix, hashes []byte) { d := make([]byte, 4+len(hashes)) expire := uint(time.Now().Unix()) + c.cacheTime*60 binary.BigEndian.PutUint32(d[:4], uint32(expire)) copy(d[4:], hashes) c.cache.Set(prefix, d) log.Debug("%s: stored in cache: %v", c.svc, prefix) } // findInHash returns 32-byte hash if it's found in hashToHost. func (c *sbCtx) findInHash(val []byte) (hash32 [32]byte, found bool) { for i := 4; i < len(val); i += 32 { hash := val[i : i+32] copy(hash32[:], hash[0:32]) _, found = c.hashToHost[hash32] if found { return hash32, found } } return [32]byte{}, false } func (c *sbCtx) getCached() int { now := time.Now().Unix() hashesToRequest := map[[32]byte]string{} for k, v := range c.hashToHost { // nolint:looppointer // The subsilce is used for a safe cache lookup. val := c.cache.Get(k[0:2]) if val == nil || now >= int64(binary.BigEndian.Uint32(val)) { hashesToRequest[k] = v continue } if hash32, found := c.findInHash(val); found { log.Debug("%s: found in cache: %s: blocked by %v", c.svc, c.host, hash32) return 1 } } if len(hashesToRequest) == 0 { log.Debug("%s: found in cache: %s: not blocked", c.svc, c.host) return -1 } c.hashToHost = hashesToRequest return 0 } type sbCtx struct { host string svc string hashToHost map[[32]byte]string cache cache.Cache cacheTime uint } func hostnameToHashes(host string) map[[32]byte]string { hashes := map[[32]byte]string{} tld, icann := publicsuffix.PublicSuffix(host) if !icann { // private suffixes like cloudfront.net tld = "" } curhost := host nDots := 0 for i := len(curhost) - 1; i >= 0; i-- { if curhost[i] == '.' { nDots++ if nDots == 4 { curhost = curhost[i+1:] // "xxx.a.b.c.d" -> "a.b.c.d" break } } } for { if curhost == "" { // we've reached end of string break } if tld != "" && curhost == tld { // we've reached the TLD, don't hash it break } sum := sha256.Sum256([]byte(curhost)) hashes[sum] = curhost pos := strings.IndexByte(curhost, byte('.')) if pos < 0 { break } curhost = curhost[pos+1:] } return hashes } // convert hash array to string func (c *sbCtx) getQuestion() string { b := &strings.Builder{} for hash := range c.hashToHost { // nolint:looppointer // The subsilce is used for safe hex encoding. stringutil.WriteToBuilder(b, hex.EncodeToString(hash[0:2]), ".") } if c.svc == "SafeBrowsing" { stringutil.WriteToBuilder(b, sbTXTSuffix) return b.String() } stringutil.WriteToBuilder(b, pcTXTSuffix) return b.String() } // Find the target hash in TXT response func (c *sbCtx) processTXT(resp *dns.Msg) (bool, [][]byte) { matched := false hashes := [][]byte{} for _, a := range resp.Answer { txt, ok := a.(*dns.TXT) if !ok { continue } log.Debug("%s: received hashes for %s: %v", c.svc, c.host, txt.Txt) for _, t := range txt.Txt { if len(t) != 32*2 { continue } hash, err := hex.DecodeString(t) if err != nil { continue } hashes = append(hashes, hash) if !matched { var hash32 [32]byte copy(hash32[:], hash) var hashHost string hashHost, ok = c.hashToHost[hash32] if ok { log.Debug("%s: matched %s by %s/%s", c.svc, c.host, hashHost, t) matched = true } } } } return matched, hashes } func (c *sbCtx) storeCache(hashes [][]byte) { slices.SortFunc(hashes, func(a, b []byte) (sortsBefore bool) { return bytes.Compare(a, b) == -1 }) var curData []byte var prevPrefix []byte for i, hash := range hashes { // nolint:looppointer // The subsilce is used for a safe comparison. if !bytes.Equal(hash[0:2], prevPrefix) { if i != 0 { c.setCache(prevPrefix, curData) curData = nil } prevPrefix = hashes[i][0:2] } curData = append(curData, hash...) } if len(prevPrefix) != 0 { c.setCache(prevPrefix, curData) } for hash := range c.hashToHost { // nolint:looppointer // The subsilce is used for a safe cache lookup. prefix := hash[0:2] val := c.cache.Get(prefix) if val == nil { c.setCache(prefix, nil) } } } func check(c *sbCtx, r Result, u upstream.Upstream) (Result, error) { c.hashToHost = hostnameToHashes(c.host) switch c.getCached() { case -1: return Result{}, nil case 1: return r, nil } question := c.getQuestion() log.Tracef("%s: checking %s: %s", c.svc, c.host, question) req := (&dns.Msg{}).SetQuestion(question, dns.TypeTXT) resp, err := u.Exchange(req) if err != nil { return Result{}, err } matched, receivedHashes := c.processTXT(resp) c.storeCache(receivedHashes) if matched { return r, nil } return Result{}, nil } </s> add </s> remove parentalServer string // access via methods safeBrowsingServer string // access via methods parentalUpstream upstream.Upstream safeBrowsingUpstream upstream.Upstream safebrowsingCache cache.Cache parentalCache cache.Cache </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c
internal/filtering/filtering.go
keep keep replace replace keep keep replace replace replace replace replace replace replace replace replace keep keep keep
<mask> func New(c *Config, blockFilters []Filter) (d *DNSFilter, err error) { <mask> d = &DNSFilter{ <mask> refreshLock: &sync.Mutex{}, <mask> filterTitleRegexp: regexp.MustCompile(`^! Title: +(.*)$`), <mask> } <mask> <mask> d.safebrowsingCache = cache.New(cache.Config{ <mask> EnableLRU: true, <mask> MaxSize: c.SafeBrowsingCacheSize, <mask> }) <mask> d.parentalCache = cache.New(cache.Config{ <mask> EnableLRU: true, <mask> MaxSize: c.ParentalCacheSize, <mask> }) <mask> <mask> d.safeSearch = c.SafeSearch <mask> <mask> d.hostCheckers = []hostChecker{{ </s> Pull request 1837: AG-21462-imp-safebrowsing-parental Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master Squashed commit of the following: commit 85016d4f1105e21a407efade0bd45b8362808061 Merge: 0e61edade 620b51e3e Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 16:36:30 2023 +0300 Merge branch 'master' into AG-21462-imp-safebrowsing-parental commit 0e61edadeff34f6305e941c1db94575c82f238d9 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 14:51:37 2023 +0300 filtering: imp tests commit 994255514cc0f67dfe33d5a0892432e8924d1e36 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:13:19 2023 +0300 filtering: fix typo commit 96d1069573171538333330d6af94ef0f4208a9c4 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:00:18 2023 +0300 filtering: imp code more commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 19:13:26 2023 +0300 all: add todo commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 14:36:08 2023 +0300 all: imp code more commit b6e734ccbeda82669023f6578481260b7c1f7161 Author: Stanislav Chzhen <[email protected]> Date: Tue Apr 25 15:01:56 2023 +0300 filtering: imp code commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 20:06:36 2023 +0300 all: imp code commit 49fa6e587052a40bb431fea457701ee860493527 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 14:57:19 2023 +0300 all: rm safe browsing ctx commit bbcb66cb03e18fa875e3c33cf16295892739e507 Author: Stanislav Chzhen <[email protected]> Date: Fri Apr 21 17:54:18 2023 +0300 filtering: add cache item commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 18:43:02 2023 +0300 filtering: fix hashes commit 153fec46270212af03f3631bfb42c5d680c4e142 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 16:15:15 2023 +0300 filtering: add test cases commit 09372f92bbb1fc082f1b1283594ee589100209c5 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 15:38:05 2023 +0300 filtering: imp code commit 466bc26d524ea6d1c3efb33692a7785d39e491ca Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 18:38:40 2023 +0300 filtering: add tests commit 24365ecf8c60512fdac65833ee603c80864ae018 Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 11:38:57 2023 +0300 filtering: add hashprefix </s> remove func purgeCaches(d *DNSFilter) { for _, c := range []cache.Cache{ d.safebrowsingCache, d.parentalCache, } { if c != nil { c.Clear() } } } </s> add </s> remove const hostname = "wmconvirus.narod.ru" </s> add const ( hostname = "wmconvirus.narod.ru" cacheTime = 10 * time.Minute cacheSize = 10000 ) sbChecker := hashprefix.New(&hashprefix.Config{ CacheTime: cacheTime, CacheSize: cacheSize, Upstream: aghtest.NewBlockUpstream(hostname, true), }) </s> remove err = d.initSecurityServices() if err != nil { return nil, fmt.Errorf("initializing services: %s", err) } </s> add </s> add func newChecker(host string) Checker { return hashprefix.New(&hashprefix.Config{ CacheTime: 10, CacheSize: 100000, Upstream: aghtest.NewBlockUpstream(host, true), }) } </s> remove // TODO(a.garipov): Make configurable. const ( dnsTimeout = 3 * time.Second defaultSafebrowsingServer = `https://family.adguard-dns.com/dns-query` defaultParentalServer = `https://family.adguard-dns.com/dns-query` sbTXTSuffix = `sb.dns.adguard.com.` pcTXTSuffix = `pc.dns.adguard.com.` ) // SetParentalUpstream sets the parental upstream for *DNSFilter. // // TODO(e.burkov): Remove this in v1 API to forbid the direct access. func (d *DNSFilter) SetParentalUpstream(u upstream.Upstream) { d.parentalUpstream = u } // SetSafeBrowsingUpstream sets the safe browsing upstream for *DNSFilter. // // TODO(e.burkov): Remove this in v1 API to forbid the direct access. func (d *DNSFilter) SetSafeBrowsingUpstream(u upstream.Upstream) { d.safeBrowsingUpstream = u } func (d *DNSFilter) initSecurityServices() error { var err error d.safeBrowsingServer = defaultSafebrowsingServer d.parentalServer = defaultParentalServer opts := &upstream.Options{ Timeout: dnsTimeout, ServerIPAddrs: []net.IP{ {94, 140, 14, 15}, {94, 140, 15, 16}, net.ParseIP("2a10:50c0::bad1:ff"), net.ParseIP("2a10:50c0::bad2:ff"), }, } parUps, err := upstream.AddressToUpstream(d.parentalServer, opts) if err != nil { return fmt.Errorf("converting parental server: %w", err) } d.SetParentalUpstream(parUps) sbUps, err := upstream.AddressToUpstream(d.safeBrowsingServer, opts) if err != nil { return fmt.Errorf("converting safe browsing server: %w", err) } d.SetSafeBrowsingUpstream(sbUps) return nil } /* expire byte[4] hash byte[32] ... */ func (c *sbCtx) setCache(prefix, hashes []byte) { d := make([]byte, 4+len(hashes)) expire := uint(time.Now().Unix()) + c.cacheTime*60 binary.BigEndian.PutUint32(d[:4], uint32(expire)) copy(d[4:], hashes) c.cache.Set(prefix, d) log.Debug("%s: stored in cache: %v", c.svc, prefix) } // findInHash returns 32-byte hash if it's found in hashToHost. func (c *sbCtx) findInHash(val []byte) (hash32 [32]byte, found bool) { for i := 4; i < len(val); i += 32 { hash := val[i : i+32] copy(hash32[:], hash[0:32]) _, found = c.hashToHost[hash32] if found { return hash32, found } } return [32]byte{}, false } func (c *sbCtx) getCached() int { now := time.Now().Unix() hashesToRequest := map[[32]byte]string{} for k, v := range c.hashToHost { // nolint:looppointer // The subsilce is used for a safe cache lookup. val := c.cache.Get(k[0:2]) if val == nil || now >= int64(binary.BigEndian.Uint32(val)) { hashesToRequest[k] = v continue } if hash32, found := c.findInHash(val); found { log.Debug("%s: found in cache: %s: blocked by %v", c.svc, c.host, hash32) return 1 } } if len(hashesToRequest) == 0 { log.Debug("%s: found in cache: %s: not blocked", c.svc, c.host) return -1 } c.hashToHost = hashesToRequest return 0 } type sbCtx struct { host string svc string hashToHost map[[32]byte]string cache cache.Cache cacheTime uint } func hostnameToHashes(host string) map[[32]byte]string { hashes := map[[32]byte]string{} tld, icann := publicsuffix.PublicSuffix(host) if !icann { // private suffixes like cloudfront.net tld = "" } curhost := host nDots := 0 for i := len(curhost) - 1; i >= 0; i-- { if curhost[i] == '.' { nDots++ if nDots == 4 { curhost = curhost[i+1:] // "xxx.a.b.c.d" -> "a.b.c.d" break } } } for { if curhost == "" { // we've reached end of string break } if tld != "" && curhost == tld { // we've reached the TLD, don't hash it break } sum := sha256.Sum256([]byte(curhost)) hashes[sum] = curhost pos := strings.IndexByte(curhost, byte('.')) if pos < 0 { break } curhost = curhost[pos+1:] } return hashes } // convert hash array to string func (c *sbCtx) getQuestion() string { b := &strings.Builder{} for hash := range c.hashToHost { // nolint:looppointer // The subsilce is used for safe hex encoding. stringutil.WriteToBuilder(b, hex.EncodeToString(hash[0:2]), ".") } if c.svc == "SafeBrowsing" { stringutil.WriteToBuilder(b, sbTXTSuffix) return b.String() } stringutil.WriteToBuilder(b, pcTXTSuffix) return b.String() } // Find the target hash in TXT response func (c *sbCtx) processTXT(resp *dns.Msg) (bool, [][]byte) { matched := false hashes := [][]byte{} for _, a := range resp.Answer { txt, ok := a.(*dns.TXT) if !ok { continue } log.Debug("%s: received hashes for %s: %v", c.svc, c.host, txt.Txt) for _, t := range txt.Txt { if len(t) != 32*2 { continue } hash, err := hex.DecodeString(t) if err != nil { continue } hashes = append(hashes, hash) if !matched { var hash32 [32]byte copy(hash32[:], hash) var hashHost string hashHost, ok = c.hashToHost[hash32] if ok { log.Debug("%s: matched %s by %s/%s", c.svc, c.host, hashHost, t) matched = true } } } } return matched, hashes } func (c *sbCtx) storeCache(hashes [][]byte) { slices.SortFunc(hashes, func(a, b []byte) (sortsBefore bool) { return bytes.Compare(a, b) == -1 }) var curData []byte var prevPrefix []byte for i, hash := range hashes { // nolint:looppointer // The subsilce is used for a safe comparison. if !bytes.Equal(hash[0:2], prevPrefix) { if i != 0 { c.setCache(prevPrefix, curData) curData = nil } prevPrefix = hashes[i][0:2] } curData = append(curData, hash...) } if len(prevPrefix) != 0 { c.setCache(prevPrefix, curData) } for hash := range c.hashToHost { // nolint:looppointer // The subsilce is used for a safe cache lookup. prefix := hash[0:2] val := c.cache.Get(prefix) if val == nil { c.setCache(prefix, nil) } } } func check(c *sbCtx, r Result, u upstream.Upstream) (Result, error) { c.hashToHost = hostnameToHashes(c.host) switch c.getCached() { case -1: return Result{}, nil case 1: return r, nil } question := c.getQuestion() log.Tracef("%s: checking %s: %s", c.svc, c.host, question) req := (&dns.Msg{}).SetQuestion(question, dns.TypeTXT) resp, err := u.Exchange(req) if err != nil { return Result{}, err } matched, receivedHashes := c.processTXT(resp) c.storeCache(receivedHashes) if matched { return r, nil } return Result{}, nil } </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c
internal/filtering/filtering.go
keep keep keep keep replace replace replace replace replace keep keep keep keep keep
<mask> }} <mask> <mask> defer func() { err = errors.Annotate(err, "filtering: %w") }() <mask> <mask> err = d.initSecurityServices() <mask> if err != nil { <mask> return nil, fmt.Errorf("initializing services: %s", err) <mask> } <mask> <mask> d.Config = *c <mask> d.filtersMu = &sync.RWMutex{} <mask> <mask> err = d.prepareRewrites() <mask> if err != nil { </s> Pull request 1837: AG-21462-imp-safebrowsing-parental Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master Squashed commit of the following: commit 85016d4f1105e21a407efade0bd45b8362808061 Merge: 0e61edade 620b51e3e Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 16:36:30 2023 +0300 Merge branch 'master' into AG-21462-imp-safebrowsing-parental commit 0e61edadeff34f6305e941c1db94575c82f238d9 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 14:51:37 2023 +0300 filtering: imp tests commit 994255514cc0f67dfe33d5a0892432e8924d1e36 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:13:19 2023 +0300 filtering: fix typo commit 96d1069573171538333330d6af94ef0f4208a9c4 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:00:18 2023 +0300 filtering: imp code more commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 19:13:26 2023 +0300 all: add todo commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 14:36:08 2023 +0300 all: imp code more commit b6e734ccbeda82669023f6578481260b7c1f7161 Author: Stanislav Chzhen <[email protected]> Date: Tue Apr 25 15:01:56 2023 +0300 filtering: imp code commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 20:06:36 2023 +0300 all: imp code commit 49fa6e587052a40bb431fea457701ee860493527 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 14:57:19 2023 +0300 all: rm safe browsing ctx commit bbcb66cb03e18fa875e3c33cf16295892739e507 Author: Stanislav Chzhen <[email protected]> Date: Fri Apr 21 17:54:18 2023 +0300 filtering: add cache item commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 18:43:02 2023 +0300 filtering: fix hashes commit 153fec46270212af03f3631bfb42c5d680c4e142 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 16:15:15 2023 +0300 filtering: add test cases commit 09372f92bbb1fc082f1b1283594ee589100209c5 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 15:38:05 2023 +0300 filtering: imp code commit 466bc26d524ea6d1c3efb33692a7785d39e491ca Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 18:38:40 2023 +0300 filtering: add tests commit 24365ecf8c60512fdac65833ee603c80864ae018 Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 11:38:57 2023 +0300 filtering: add hashprefix </s> remove return check(sctx, res, d.safeBrowsingUpstream) </s> add block, err := d.safeBrowsingChecker.Check(host) if !block || err != nil { return Result{}, err } return res, nil </s> remove // TODO(a.garipov): Make configurable. const ( dnsTimeout = 3 * time.Second defaultSafebrowsingServer = `https://family.adguard-dns.com/dns-query` defaultParentalServer = `https://family.adguard-dns.com/dns-query` sbTXTSuffix = `sb.dns.adguard.com.` pcTXTSuffix = `pc.dns.adguard.com.` ) // SetParentalUpstream sets the parental upstream for *DNSFilter. // // TODO(e.burkov): Remove this in v1 API to forbid the direct access. func (d *DNSFilter) SetParentalUpstream(u upstream.Upstream) { d.parentalUpstream = u } // SetSafeBrowsingUpstream sets the safe browsing upstream for *DNSFilter. // // TODO(e.burkov): Remove this in v1 API to forbid the direct access. func (d *DNSFilter) SetSafeBrowsingUpstream(u upstream.Upstream) { d.safeBrowsingUpstream = u } func (d *DNSFilter) initSecurityServices() error { var err error d.safeBrowsingServer = defaultSafebrowsingServer d.parentalServer = defaultParentalServer opts := &upstream.Options{ Timeout: dnsTimeout, ServerIPAddrs: []net.IP{ {94, 140, 14, 15}, {94, 140, 15, 16}, net.ParseIP("2a10:50c0::bad1:ff"), net.ParseIP("2a10:50c0::bad2:ff"), }, } parUps, err := upstream.AddressToUpstream(d.parentalServer, opts) if err != nil { return fmt.Errorf("converting parental server: %w", err) } d.SetParentalUpstream(parUps) sbUps, err := upstream.AddressToUpstream(d.safeBrowsingServer, opts) if err != nil { return fmt.Errorf("converting safe browsing server: %w", err) } d.SetSafeBrowsingUpstream(sbUps) return nil } /* expire byte[4] hash byte[32] ... */ func (c *sbCtx) setCache(prefix, hashes []byte) { d := make([]byte, 4+len(hashes)) expire := uint(time.Now().Unix()) + c.cacheTime*60 binary.BigEndian.PutUint32(d[:4], uint32(expire)) copy(d[4:], hashes) c.cache.Set(prefix, d) log.Debug("%s: stored in cache: %v", c.svc, prefix) } // findInHash returns 32-byte hash if it's found in hashToHost. func (c *sbCtx) findInHash(val []byte) (hash32 [32]byte, found bool) { for i := 4; i < len(val); i += 32 { hash := val[i : i+32] copy(hash32[:], hash[0:32]) _, found = c.hashToHost[hash32] if found { return hash32, found } } return [32]byte{}, false } func (c *sbCtx) getCached() int { now := time.Now().Unix() hashesToRequest := map[[32]byte]string{} for k, v := range c.hashToHost { // nolint:looppointer // The subsilce is used for a safe cache lookup. val := c.cache.Get(k[0:2]) if val == nil || now >= int64(binary.BigEndian.Uint32(val)) { hashesToRequest[k] = v continue } if hash32, found := c.findInHash(val); found { log.Debug("%s: found in cache: %s: blocked by %v", c.svc, c.host, hash32) return 1 } } if len(hashesToRequest) == 0 { log.Debug("%s: found in cache: %s: not blocked", c.svc, c.host) return -1 } c.hashToHost = hashesToRequest return 0 } type sbCtx struct { host string svc string hashToHost map[[32]byte]string cache cache.Cache cacheTime uint } func hostnameToHashes(host string) map[[32]byte]string { hashes := map[[32]byte]string{} tld, icann := publicsuffix.PublicSuffix(host) if !icann { // private suffixes like cloudfront.net tld = "" } curhost := host nDots := 0 for i := len(curhost) - 1; i >= 0; i-- { if curhost[i] == '.' { nDots++ if nDots == 4 { curhost = curhost[i+1:] // "xxx.a.b.c.d" -> "a.b.c.d" break } } } for { if curhost == "" { // we've reached end of string break } if tld != "" && curhost == tld { // we've reached the TLD, don't hash it break } sum := sha256.Sum256([]byte(curhost)) hashes[sum] = curhost pos := strings.IndexByte(curhost, byte('.')) if pos < 0 { break } curhost = curhost[pos+1:] } return hashes } // convert hash array to string func (c *sbCtx) getQuestion() string { b := &strings.Builder{} for hash := range c.hashToHost { // nolint:looppointer // The subsilce is used for safe hex encoding. stringutil.WriteToBuilder(b, hex.EncodeToString(hash[0:2]), ".") } if c.svc == "SafeBrowsing" { stringutil.WriteToBuilder(b, sbTXTSuffix) return b.String() } stringutil.WriteToBuilder(b, pcTXTSuffix) return b.String() } // Find the target hash in TXT response func (c *sbCtx) processTXT(resp *dns.Msg) (bool, [][]byte) { matched := false hashes := [][]byte{} for _, a := range resp.Answer { txt, ok := a.(*dns.TXT) if !ok { continue } log.Debug("%s: received hashes for %s: %v", c.svc, c.host, txt.Txt) for _, t := range txt.Txt { if len(t) != 32*2 { continue } hash, err := hex.DecodeString(t) if err != nil { continue } hashes = append(hashes, hash) if !matched { var hash32 [32]byte copy(hash32[:], hash) var hashHost string hashHost, ok = c.hashToHost[hash32] if ok { log.Debug("%s: matched %s by %s/%s", c.svc, c.host, hashHost, t) matched = true } } } } return matched, hashes } func (c *sbCtx) storeCache(hashes [][]byte) { slices.SortFunc(hashes, func(a, b []byte) (sortsBefore bool) { return bytes.Compare(a, b) == -1 }) var curData []byte var prevPrefix []byte for i, hash := range hashes { // nolint:looppointer // The subsilce is used for a safe comparison. if !bytes.Equal(hash[0:2], prevPrefix) { if i != 0 { c.setCache(prevPrefix, curData) curData = nil } prevPrefix = hashes[i][0:2] } curData = append(curData, hash...) } if len(prevPrefix) != 0 { c.setCache(prevPrefix, curData) } for hash := range c.hashToHost { // nolint:looppointer // The subsilce is used for a safe cache lookup. prefix := hash[0:2] val := c.cache.Get(prefix) if val == nil { c.setCache(prefix, nil) } } } func check(c *sbCtx, r Result, u upstream.Upstream) (Result, error) { c.hashToHost = hostnameToHashes(c.host) switch c.getCached() { case -1: return Result{}, nil case 1: return r, nil } question := c.getQuestion() log.Tracef("%s: checking %s: %s", c.svc, c.host, question) req := (&dns.Msg{}).SetQuestion(question, dns.TypeTXT) resp, err := u.Exchange(req) if err != nil { return Result{}, err } matched, receivedHashes := c.processTXT(resp) c.storeCache(receivedHashes) if matched { return r, nil } return Result{}, nil } </s> add </s> remove return check(sctx, res, d.parentalUpstream) </s> add block, err := d.parentalControlChecker.Check(host) if !block || err != nil { return Result{}, err } return res, nil </s> remove func purgeCaches(d *DNSFilter) { for _, c := range []cache.Cache{ d.safebrowsingCache, d.parentalCache, } { if c != nil { c.Clear() } } } </s> add </s> remove purgeCaches(f) </s> add </s> remove d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true)) </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c
internal/filtering/filtering.go
keep keep keep keep replace keep keep keep keep keep
<mask> "net" <mask> "testing" <mask> <mask> "github.com/AdguardTeam/AdGuardHome/internal/aghtest" <mask> "github.com/AdguardTeam/golibs/cache" <mask> "github.com/AdguardTeam/golibs/log" <mask> "github.com/AdguardTeam/golibs/testutil" <mask> "github.com/AdguardTeam/urlfilter/rules" <mask> "github.com/miekg/dns" <mask> "github.com/stretchr/testify/assert" </s> Pull request 1837: AG-21462-imp-safebrowsing-parental Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master Squashed commit of the following: commit 85016d4f1105e21a407efade0bd45b8362808061 Merge: 0e61edade 620b51e3e Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 16:36:30 2023 +0300 Merge branch 'master' into AG-21462-imp-safebrowsing-parental commit 0e61edadeff34f6305e941c1db94575c82f238d9 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 14:51:37 2023 +0300 filtering: imp tests commit 994255514cc0f67dfe33d5a0892432e8924d1e36 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:13:19 2023 +0300 filtering: fix typo commit 96d1069573171538333330d6af94ef0f4208a9c4 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:00:18 2023 +0300 filtering: imp code more commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 19:13:26 2023 +0300 all: add todo commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 14:36:08 2023 +0300 all: imp code more commit b6e734ccbeda82669023f6578481260b7c1f7161 Author: Stanislav Chzhen <[email protected]> Date: Tue Apr 25 15:01:56 2023 +0300 filtering: imp code commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 20:06:36 2023 +0300 all: imp code commit 49fa6e587052a40bb431fea457701ee860493527 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 14:57:19 2023 +0300 all: rm safe browsing ctx commit bbcb66cb03e18fa875e3c33cf16295892739e507 Author: Stanislav Chzhen <[email protected]> Date: Fri Apr 21 17:54:18 2023 +0300 filtering: add cache item commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 18:43:02 2023 +0300 filtering: fix hashes commit 153fec46270212af03f3631bfb42c5d680c4e142 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 16:15:15 2023 +0300 filtering: add test cases commit 09372f92bbb1fc082f1b1283594ee589100209c5 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 15:38:05 2023 +0300 filtering: imp code commit 466bc26d524ea6d1c3efb33692a7785d39e491ca Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 18:38:40 2023 +0300 filtering: add tests commit 24365ecf8c60512fdac65833ee603c80864ae018 Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 11:38:57 2023 +0300 filtering: add hashprefix </s> remove "github.com/AdguardTeam/dnsproxy/upstream" "github.com/AdguardTeam/golibs/cache" </s> add </s> remove "time" </s> add </s> remove "github.com/AdguardTeam/golibs/stringutil" "github.com/miekg/dns" "golang.org/x/exp/slices" "golang.org/x/net/publicsuffix" </s> add </s> remove "github.com/AdguardTeam/dnsproxy/upstream" "github.com/AdguardTeam/golibs/cache" </s> add </s> add "github.com/AdguardTeam/AdGuardHome/internal/filtering/hashprefix" </s> remove "strings" </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c
internal/filtering/filtering_test.go
keep keep keep keep replace replace replace replace replace replace replace replace replace replace replace keep keep keep keep keep
<mask> ) <mask> <mask> // Helpers. <mask> <mask> func purgeCaches(d *DNSFilter) { <mask> for _, c := range []cache.Cache{ <mask> d.safebrowsingCache, <mask> d.parentalCache, <mask> } { <mask> if c != nil { <mask> c.Clear() <mask> } <mask> } <mask> } <mask> <mask> func newForTest(t testing.TB, c *Config, filters []Filter) (f *DNSFilter, setts *Settings) { <mask> setts = &Settings{ <mask> ProtectionEnabled: true, <mask> FilteringEnabled: true, <mask> } </s> Pull request 1837: AG-21462-imp-safebrowsing-parental Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master Squashed commit of the following: commit 85016d4f1105e21a407efade0bd45b8362808061 Merge: 0e61edade 620b51e3e Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 16:36:30 2023 +0300 Merge branch 'master' into AG-21462-imp-safebrowsing-parental commit 0e61edadeff34f6305e941c1db94575c82f238d9 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 14:51:37 2023 +0300 filtering: imp tests commit 994255514cc0f67dfe33d5a0892432e8924d1e36 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:13:19 2023 +0300 filtering: fix typo commit 96d1069573171538333330d6af94ef0f4208a9c4 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:00:18 2023 +0300 filtering: imp code more commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 19:13:26 2023 +0300 all: add todo commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 14:36:08 2023 +0300 all: imp code more commit b6e734ccbeda82669023f6578481260b7c1f7161 Author: Stanislav Chzhen <[email protected]> Date: Tue Apr 25 15:01:56 2023 +0300 filtering: imp code commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 20:06:36 2023 +0300 all: imp code commit 49fa6e587052a40bb431fea457701ee860493527 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 14:57:19 2023 +0300 all: rm safe browsing ctx commit bbcb66cb03e18fa875e3c33cf16295892739e507 Author: Stanislav Chzhen <[email protected]> Date: Fri Apr 21 17:54:18 2023 +0300 filtering: add cache item commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 18:43:02 2023 +0300 filtering: fix hashes commit 153fec46270212af03f3631bfb42c5d680c4e142 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 16:15:15 2023 +0300 filtering: add test cases commit 09372f92bbb1fc082f1b1283594ee589100209c5 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 15:38:05 2023 +0300 filtering: imp code commit 466bc26d524ea6d1c3efb33692a7785d39e491ca Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 18:38:40 2023 +0300 filtering: add tests commit 24365ecf8c60512fdac65833ee603c80864ae018 Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 11:38:57 2023 +0300 filtering: add hashprefix </s> remove refreshLock: &sync.Mutex{}, filterTitleRegexp: regexp.MustCompile(`^! Title: +(.*)$`), </s> add refreshLock: &sync.Mutex{}, filterTitleRegexp: regexp.MustCompile(`^! Title: +(.*)$`), safeBrowsingChecker: c.SafeBrowsingChecker, parentalControlChecker: c.ParentalControlChecker, </s> remove // TODO(a.garipov): Make configurable. const ( dnsTimeout = 3 * time.Second defaultSafebrowsingServer = `https://family.adguard-dns.com/dns-query` defaultParentalServer = `https://family.adguard-dns.com/dns-query` sbTXTSuffix = `sb.dns.adguard.com.` pcTXTSuffix = `pc.dns.adguard.com.` ) // SetParentalUpstream sets the parental upstream for *DNSFilter. // // TODO(e.burkov): Remove this in v1 API to forbid the direct access. func (d *DNSFilter) SetParentalUpstream(u upstream.Upstream) { d.parentalUpstream = u } // SetSafeBrowsingUpstream sets the safe browsing upstream for *DNSFilter. // // TODO(e.burkov): Remove this in v1 API to forbid the direct access. func (d *DNSFilter) SetSafeBrowsingUpstream(u upstream.Upstream) { d.safeBrowsingUpstream = u } func (d *DNSFilter) initSecurityServices() error { var err error d.safeBrowsingServer = defaultSafebrowsingServer d.parentalServer = defaultParentalServer opts := &upstream.Options{ Timeout: dnsTimeout, ServerIPAddrs: []net.IP{ {94, 140, 14, 15}, {94, 140, 15, 16}, net.ParseIP("2a10:50c0::bad1:ff"), net.ParseIP("2a10:50c0::bad2:ff"), }, } parUps, err := upstream.AddressToUpstream(d.parentalServer, opts) if err != nil { return fmt.Errorf("converting parental server: %w", err) } d.SetParentalUpstream(parUps) sbUps, err := upstream.AddressToUpstream(d.safeBrowsingServer, opts) if err != nil { return fmt.Errorf("converting safe browsing server: %w", err) } d.SetSafeBrowsingUpstream(sbUps) return nil } /* expire byte[4] hash byte[32] ... */ func (c *sbCtx) setCache(prefix, hashes []byte) { d := make([]byte, 4+len(hashes)) expire := uint(time.Now().Unix()) + c.cacheTime*60 binary.BigEndian.PutUint32(d[:4], uint32(expire)) copy(d[4:], hashes) c.cache.Set(prefix, d) log.Debug("%s: stored in cache: %v", c.svc, prefix) } // findInHash returns 32-byte hash if it's found in hashToHost. func (c *sbCtx) findInHash(val []byte) (hash32 [32]byte, found bool) { for i := 4; i < len(val); i += 32 { hash := val[i : i+32] copy(hash32[:], hash[0:32]) _, found = c.hashToHost[hash32] if found { return hash32, found } } return [32]byte{}, false } func (c *sbCtx) getCached() int { now := time.Now().Unix() hashesToRequest := map[[32]byte]string{} for k, v := range c.hashToHost { // nolint:looppointer // The subsilce is used for a safe cache lookup. val := c.cache.Get(k[0:2]) if val == nil || now >= int64(binary.BigEndian.Uint32(val)) { hashesToRequest[k] = v continue } if hash32, found := c.findInHash(val); found { log.Debug("%s: found in cache: %s: blocked by %v", c.svc, c.host, hash32) return 1 } } if len(hashesToRequest) == 0 { log.Debug("%s: found in cache: %s: not blocked", c.svc, c.host) return -1 } c.hashToHost = hashesToRequest return 0 } type sbCtx struct { host string svc string hashToHost map[[32]byte]string cache cache.Cache cacheTime uint } func hostnameToHashes(host string) map[[32]byte]string { hashes := map[[32]byte]string{} tld, icann := publicsuffix.PublicSuffix(host) if !icann { // private suffixes like cloudfront.net tld = "" } curhost := host nDots := 0 for i := len(curhost) - 1; i >= 0; i-- { if curhost[i] == '.' { nDots++ if nDots == 4 { curhost = curhost[i+1:] // "xxx.a.b.c.d" -> "a.b.c.d" break } } } for { if curhost == "" { // we've reached end of string break } if tld != "" && curhost == tld { // we've reached the TLD, don't hash it break } sum := sha256.Sum256([]byte(curhost)) hashes[sum] = curhost pos := strings.IndexByte(curhost, byte('.')) if pos < 0 { break } curhost = curhost[pos+1:] } return hashes } // convert hash array to string func (c *sbCtx) getQuestion() string { b := &strings.Builder{} for hash := range c.hashToHost { // nolint:looppointer // The subsilce is used for safe hex encoding. stringutil.WriteToBuilder(b, hex.EncodeToString(hash[0:2]), ".") } if c.svc == "SafeBrowsing" { stringutil.WriteToBuilder(b, sbTXTSuffix) return b.String() } stringutil.WriteToBuilder(b, pcTXTSuffix) return b.String() } // Find the target hash in TXT response func (c *sbCtx) processTXT(resp *dns.Msg) (bool, [][]byte) { matched := false hashes := [][]byte{} for _, a := range resp.Answer { txt, ok := a.(*dns.TXT) if !ok { continue } log.Debug("%s: received hashes for %s: %v", c.svc, c.host, txt.Txt) for _, t := range txt.Txt { if len(t) != 32*2 { continue } hash, err := hex.DecodeString(t) if err != nil { continue } hashes = append(hashes, hash) if !matched { var hash32 [32]byte copy(hash32[:], hash) var hashHost string hashHost, ok = c.hashToHost[hash32] if ok { log.Debug("%s: matched %s by %s/%s", c.svc, c.host, hashHost, t) matched = true } } } } return matched, hashes } func (c *sbCtx) storeCache(hashes [][]byte) { slices.SortFunc(hashes, func(a, b []byte) (sortsBefore bool) { return bytes.Compare(a, b) == -1 }) var curData []byte var prevPrefix []byte for i, hash := range hashes { // nolint:looppointer // The subsilce is used for a safe comparison. if !bytes.Equal(hash[0:2], prevPrefix) { if i != 0 { c.setCache(prevPrefix, curData) curData = nil } prevPrefix = hashes[i][0:2] } curData = append(curData, hash...) } if len(prevPrefix) != 0 { c.setCache(prevPrefix, curData) } for hash := range c.hashToHost { // nolint:looppointer // The subsilce is used for a safe cache lookup. prefix := hash[0:2] val := c.cache.Get(prefix) if val == nil { c.setCache(prefix, nil) } } } func check(c *sbCtx, r Result, u upstream.Upstream) (Result, error) { c.hashToHost = hostnameToHashes(c.host) switch c.getCached() { case -1: return Result{}, nil case 1: return r, nil } question := c.getQuestion() log.Tracef("%s: checking %s: %s", c.svc, c.host, question) req := (&dns.Msg{}).SetQuestion(question, dns.TypeTXT) resp, err := u.Exchange(req) if err != nil { return Result{}, err } matched, receivedHashes := c.processTXT(resp) c.storeCache(receivedHashes) if matched { return r, nil } return Result{}, nil } </s> add </s> remove return check(sctx, res, d.safeBrowsingUpstream) </s> add block, err := d.safeBrowsingChecker.Check(host) if !block || err != nil { return Result{}, err } return res, nil </s> remove purgeCaches(f) </s> add </s> remove err = d.initSecurityServices() if err != nil { return nil, fmt.Errorf("initializing services: %s", err) } </s> add </s> add func newChecker(host string) Checker { return hashprefix.New(&hashprefix.Config{ CacheTime: 10, CacheSize: 100000, Upstream: aghtest.NewBlockUpstream(host, true), }) }
https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c
internal/filtering/filtering_test.go
keep keep keep keep replace replace keep keep keep keep keep
<mask> } <mask> f, err := New(c, filters) <mask> require.NoError(t, err) <mask> <mask> purgeCaches(f) <mask> <mask> return f, setts <mask> } <mask> <mask> func (d *DNSFilter) checkMatch(t *testing.T, hostname string, setts *Settings) { <mask> t.Helper() </s> Pull request 1837: AG-21462-imp-safebrowsing-parental Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master Squashed commit of the following: commit 85016d4f1105e21a407efade0bd45b8362808061 Merge: 0e61edade 620b51e3e Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 16:36:30 2023 +0300 Merge branch 'master' into AG-21462-imp-safebrowsing-parental commit 0e61edadeff34f6305e941c1db94575c82f238d9 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 14:51:37 2023 +0300 filtering: imp tests commit 994255514cc0f67dfe33d5a0892432e8924d1e36 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:13:19 2023 +0300 filtering: fix typo commit 96d1069573171538333330d6af94ef0f4208a9c4 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:00:18 2023 +0300 filtering: imp code more commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 19:13:26 2023 +0300 all: add todo commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 14:36:08 2023 +0300 all: imp code more commit b6e734ccbeda82669023f6578481260b7c1f7161 Author: Stanislav Chzhen <[email protected]> Date: Tue Apr 25 15:01:56 2023 +0300 filtering: imp code commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 20:06:36 2023 +0300 all: imp code commit 49fa6e587052a40bb431fea457701ee860493527 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 14:57:19 2023 +0300 all: rm safe browsing ctx commit bbcb66cb03e18fa875e3c33cf16295892739e507 Author: Stanislav Chzhen <[email protected]> Date: Fri Apr 21 17:54:18 2023 +0300 filtering: add cache item commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 18:43:02 2023 +0300 filtering: fix hashes commit 153fec46270212af03f3631bfb42c5d680c4e142 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 16:15:15 2023 +0300 filtering: add test cases commit 09372f92bbb1fc082f1b1283594ee589100209c5 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 15:38:05 2023 +0300 filtering: imp code commit 466bc26d524ea6d1c3efb33692a7785d39e491ca Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 18:38:40 2023 +0300 filtering: add tests commit 24365ecf8c60512fdac65833ee603c80864ae018 Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 11:38:57 2023 +0300 filtering: add hashprefix </s> add func newChecker(host string) Checker { return hashprefix.New(&hashprefix.Config{ CacheTime: 10, CacheSize: 100000, Upstream: aghtest.NewBlockUpstream(host, true), }) } </s> remove return check(sctx, res, d.safeBrowsingUpstream) </s> add block, err := d.safeBrowsingChecker.Check(host) if !block || err != nil { return Result{}, err } return res, nil </s> remove func purgeCaches(d *DNSFilter) { for _, c := range []cache.Cache{ d.safebrowsingCache, d.parentalCache, } { if c != nil { c.Clear() } } } </s> add </s> remove // TODO(a.garipov): Make configurable. const ( dnsTimeout = 3 * time.Second defaultSafebrowsingServer = `https://family.adguard-dns.com/dns-query` defaultParentalServer = `https://family.adguard-dns.com/dns-query` sbTXTSuffix = `sb.dns.adguard.com.` pcTXTSuffix = `pc.dns.adguard.com.` ) // SetParentalUpstream sets the parental upstream for *DNSFilter. // // TODO(e.burkov): Remove this in v1 API to forbid the direct access. func (d *DNSFilter) SetParentalUpstream(u upstream.Upstream) { d.parentalUpstream = u } // SetSafeBrowsingUpstream sets the safe browsing upstream for *DNSFilter. // // TODO(e.burkov): Remove this in v1 API to forbid the direct access. func (d *DNSFilter) SetSafeBrowsingUpstream(u upstream.Upstream) { d.safeBrowsingUpstream = u } func (d *DNSFilter) initSecurityServices() error { var err error d.safeBrowsingServer = defaultSafebrowsingServer d.parentalServer = defaultParentalServer opts := &upstream.Options{ Timeout: dnsTimeout, ServerIPAddrs: []net.IP{ {94, 140, 14, 15}, {94, 140, 15, 16}, net.ParseIP("2a10:50c0::bad1:ff"), net.ParseIP("2a10:50c0::bad2:ff"), }, } parUps, err := upstream.AddressToUpstream(d.parentalServer, opts) if err != nil { return fmt.Errorf("converting parental server: %w", err) } d.SetParentalUpstream(parUps) sbUps, err := upstream.AddressToUpstream(d.safeBrowsingServer, opts) if err != nil { return fmt.Errorf("converting safe browsing server: %w", err) } d.SetSafeBrowsingUpstream(sbUps) return nil } /* expire byte[4] hash byte[32] ... */ func (c *sbCtx) setCache(prefix, hashes []byte) { d := make([]byte, 4+len(hashes)) expire := uint(time.Now().Unix()) + c.cacheTime*60 binary.BigEndian.PutUint32(d[:4], uint32(expire)) copy(d[4:], hashes) c.cache.Set(prefix, d) log.Debug("%s: stored in cache: %v", c.svc, prefix) } // findInHash returns 32-byte hash if it's found in hashToHost. func (c *sbCtx) findInHash(val []byte) (hash32 [32]byte, found bool) { for i := 4; i < len(val); i += 32 { hash := val[i : i+32] copy(hash32[:], hash[0:32]) _, found = c.hashToHost[hash32] if found { return hash32, found } } return [32]byte{}, false } func (c *sbCtx) getCached() int { now := time.Now().Unix() hashesToRequest := map[[32]byte]string{} for k, v := range c.hashToHost { // nolint:looppointer // The subsilce is used for a safe cache lookup. val := c.cache.Get(k[0:2]) if val == nil || now >= int64(binary.BigEndian.Uint32(val)) { hashesToRequest[k] = v continue } if hash32, found := c.findInHash(val); found { log.Debug("%s: found in cache: %s: blocked by %v", c.svc, c.host, hash32) return 1 } } if len(hashesToRequest) == 0 { log.Debug("%s: found in cache: %s: not blocked", c.svc, c.host) return -1 } c.hashToHost = hashesToRequest return 0 } type sbCtx struct { host string svc string hashToHost map[[32]byte]string cache cache.Cache cacheTime uint } func hostnameToHashes(host string) map[[32]byte]string { hashes := map[[32]byte]string{} tld, icann := publicsuffix.PublicSuffix(host) if !icann { // private suffixes like cloudfront.net tld = "" } curhost := host nDots := 0 for i := len(curhost) - 1; i >= 0; i-- { if curhost[i] == '.' { nDots++ if nDots == 4 { curhost = curhost[i+1:] // "xxx.a.b.c.d" -> "a.b.c.d" break } } } for { if curhost == "" { // we've reached end of string break } if tld != "" && curhost == tld { // we've reached the TLD, don't hash it break } sum := sha256.Sum256([]byte(curhost)) hashes[sum] = curhost pos := strings.IndexByte(curhost, byte('.')) if pos < 0 { break } curhost = curhost[pos+1:] } return hashes } // convert hash array to string func (c *sbCtx) getQuestion() string { b := &strings.Builder{} for hash := range c.hashToHost { // nolint:looppointer // The subsilce is used for safe hex encoding. stringutil.WriteToBuilder(b, hex.EncodeToString(hash[0:2]), ".") } if c.svc == "SafeBrowsing" { stringutil.WriteToBuilder(b, sbTXTSuffix) return b.String() } stringutil.WriteToBuilder(b, pcTXTSuffix) return b.String() } // Find the target hash in TXT response func (c *sbCtx) processTXT(resp *dns.Msg) (bool, [][]byte) { matched := false hashes := [][]byte{} for _, a := range resp.Answer { txt, ok := a.(*dns.TXT) if !ok { continue } log.Debug("%s: received hashes for %s: %v", c.svc, c.host, txt.Txt) for _, t := range txt.Txt { if len(t) != 32*2 { continue } hash, err := hex.DecodeString(t) if err != nil { continue } hashes = append(hashes, hash) if !matched { var hash32 [32]byte copy(hash32[:], hash) var hashHost string hashHost, ok = c.hashToHost[hash32] if ok { log.Debug("%s: matched %s by %s/%s", c.svc, c.host, hashHost, t) matched = true } } } } return matched, hashes } func (c *sbCtx) storeCache(hashes [][]byte) { slices.SortFunc(hashes, func(a, b []byte) (sortsBefore bool) { return bytes.Compare(a, b) == -1 }) var curData []byte var prevPrefix []byte for i, hash := range hashes { // nolint:looppointer // The subsilce is used for a safe comparison. if !bytes.Equal(hash[0:2], prevPrefix) { if i != 0 { c.setCache(prevPrefix, curData) curData = nil } prevPrefix = hashes[i][0:2] } curData = append(curData, hash...) } if len(prevPrefix) != 0 { c.setCache(prevPrefix, curData) } for hash := range c.hashToHost { // nolint:looppointer // The subsilce is used for a safe cache lookup. prefix := hash[0:2] val := c.cache.Get(prefix) if val == nil { c.setCache(prefix, nil) } } } func check(c *sbCtx, r Result, u upstream.Upstream) (Result, error) { c.hashToHost = hostnameToHashes(c.host) switch c.getCached() { case -1: return Result{}, nil case 1: return r, nil } question := c.getQuestion() log.Tracef("%s: checking %s: %s", c.svc, c.host, question) req := (&dns.Msg{}).SetQuestion(question, dns.TypeTXT) resp, err := u.Exchange(req) if err != nil { return Result{}, err } matched, receivedHashes := c.processTXT(resp) c.storeCache(receivedHashes) if matched { return r, nil } return Result{}, nil } </s> add </s> remove d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true)) </s> add </s> remove err = d.initSecurityServices() if err != nil { return nil, fmt.Errorf("initializing services: %s", err) } </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c
internal/filtering/filtering_test.go
keep add keep keep keep keep
<mask> } <mask> <mask> func (d *DNSFilter) checkMatch(t *testing.T, hostname string, setts *Settings) { <mask> t.Helper() <mask> <mask> res, err := d.CheckHost(hostname, dns.TypeA, setts) </s> Pull request 1837: AG-21462-imp-safebrowsing-parental Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master Squashed commit of the following: commit 85016d4f1105e21a407efade0bd45b8362808061 Merge: 0e61edade 620b51e3e Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 16:36:30 2023 +0300 Merge branch 'master' into AG-21462-imp-safebrowsing-parental commit 0e61edadeff34f6305e941c1db94575c82f238d9 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 14:51:37 2023 +0300 filtering: imp tests commit 994255514cc0f67dfe33d5a0892432e8924d1e36 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:13:19 2023 +0300 filtering: fix typo commit 96d1069573171538333330d6af94ef0f4208a9c4 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:00:18 2023 +0300 filtering: imp code more commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 19:13:26 2023 +0300 all: add todo commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 14:36:08 2023 +0300 all: imp code more commit b6e734ccbeda82669023f6578481260b7c1f7161 Author: Stanislav Chzhen <[email protected]> Date: Tue Apr 25 15:01:56 2023 +0300 filtering: imp code commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 20:06:36 2023 +0300 all: imp code commit 49fa6e587052a40bb431fea457701ee860493527 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 14:57:19 2023 +0300 all: rm safe browsing ctx commit bbcb66cb03e18fa875e3c33cf16295892739e507 Author: Stanislav Chzhen <[email protected]> Date: Fri Apr 21 17:54:18 2023 +0300 filtering: add cache item commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 18:43:02 2023 +0300 filtering: fix hashes commit 153fec46270212af03f3631bfb42c5d680c4e142 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 16:15:15 2023 +0300 filtering: add test cases commit 09372f92bbb1fc082f1b1283594ee589100209c5 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 15:38:05 2023 +0300 filtering: imp code commit 466bc26d524ea6d1c3efb33692a7785d39e491ca Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 18:38:40 2023 +0300 filtering: add tests commit 24365ecf8c60512fdac65833ee603c80864ae018 Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 11:38:57 2023 +0300 filtering: add hashprefix </s> remove purgeCaches(f) </s> add </s> remove return check(sctx, res, d.safeBrowsingUpstream) </s> add block, err := d.safeBrowsingChecker.Check(host) if !block || err != nil { return Result{}, err } return res, nil </s> remove d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true)) </s> add </s> remove d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true)) </s> add </s> remove func purgeCaches(d *DNSFilter) { for _, c := range []cache.Cache{ d.safebrowsingCache, d.parentalCache, } { if c != nil { c.Clear() } } } </s> add </s> remove return check(sctx, res, d.parentalUpstream) </s> add block, err := d.parentalControlChecker.Check(host) if !block || err != nil { return Result{}, err } return res, nil
https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c
internal/filtering/filtering_test.go
keep keep replace keep keep keep keep keep keep keep keep replace keep keep
<mask> aghtest.ReplaceLogLevel(t, log.DEBUG) <mask> <mask> d, setts := newForTest(t, &Config{SafeBrowsingEnabled: true}, nil) <mask> t.Cleanup(d.Close) <mask> <mask> d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true)) <mask> d.checkMatch(t, sbBlocked, setts) <mask> <mask> d, setts := newForTest(t, &Config{SafeBrowsingEnabled: true}, nil) <mask> t.Cleanup(d.Close) <mask> <mask> d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true)) <mask> d.checkMatch(t, sbBlocked, setts) <mask> </s> Pull request 1837: AG-21462-imp-safebrowsing-parental Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master Squashed commit of the following: commit 85016d4f1105e21a407efade0bd45b8362808061 Merge: 0e61edade 620b51e3e Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 16:36:30 2023 +0300 Merge branch 'master' into AG-21462-imp-safebrowsing-parental commit 0e61edadeff34f6305e941c1db94575c82f238d9 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 14:51:37 2023 +0300 filtering: imp tests commit 994255514cc0f67dfe33d5a0892432e8924d1e36 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:13:19 2023 +0300 filtering: fix typo commit 96d1069573171538333330d6af94ef0f4208a9c4 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:00:18 2023 +0300 filtering: imp code more commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 19:13:26 2023 +0300 all: add todo commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 14:36:08 2023 +0300 all: imp code more commit b6e734ccbeda82669023f6578481260b7c1f7161 Author: Stanislav Chzhen <[email protected]> Date: Tue Apr 25 15:01:56 2023 +0300 filtering: imp code commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 20:06:36 2023 +0300 all: imp code commit 49fa6e587052a40bb431fea457701ee860493527 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 14:57:19 2023 +0300 all: rm safe browsing ctx commit bbcb66cb03e18fa875e3c33cf16295892739e507 Author: Stanislav Chzhen <[email protected]> Date: Fri Apr 21 17:54:18 2023 +0300 filtering: add cache item commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 18:43:02 2023 +0300 filtering: fix hashes commit 153fec46270212af03f3631bfb42c5d680c4e142 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 16:15:15 2023 +0300 filtering: add test cases commit 09372f92bbb1fc082f1b1283594ee589100209c5 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 15:38:05 2023 +0300 filtering: imp code commit 466bc26d524ea6d1c3efb33692a7785d39e491ca Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 18:38:40 2023 +0300 filtering: add tests commit 24365ecf8c60512fdac65833ee603c80864ae018 Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 11:38:57 2023 +0300 filtering: add hashprefix </s> remove d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true)) </s> add </s> remove d, setts := newForTest(t, &Config{ParentalEnabled: true}, nil) </s> add d, setts := newForTest(t, &Config{ ParentalEnabled: true, ParentalControlChecker: newChecker(pcBlocked), }, nil) </s> remove d.safeBrowsingServer = defaultSafebrowsingServer </s> add </s> remove d.SetParentalUpstream(aghtest.NewBlockUpstream(pcBlocked, true)) </s> add </s> remove d, setts := newForTest(t, &Config{SafeBrowsingEnabled: true}, nil) </s> add d, setts := newForTest(t, &Config{ SafeBrowsingEnabled: true, SafeBrowsingChecker: newChecker(sbBlocked), }, nil)
https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c
internal/filtering/filtering_test.go
keep keep keep keep replace keep keep replace keep
<mask> d.checkMatchEmpty(t, "yandex.ru", setts) <mask> d.checkMatchEmpty(t, pcBlocked, setts) <mask> <mask> // Cached result. <mask> d.safeBrowsingServer = "127.0.0.1" <mask> d.checkMatch(t, sbBlocked, setts) <mask> d.checkMatchEmpty(t, pcBlocked, setts) <mask> d.safeBrowsingServer = defaultSafebrowsingServer <mask> } </s> Pull request 1837: AG-21462-imp-safebrowsing-parental Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master Squashed commit of the following: commit 85016d4f1105e21a407efade0bd45b8362808061 Merge: 0e61edade 620b51e3e Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 16:36:30 2023 +0300 Merge branch 'master' into AG-21462-imp-safebrowsing-parental commit 0e61edadeff34f6305e941c1db94575c82f238d9 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 14:51:37 2023 +0300 filtering: imp tests commit 994255514cc0f67dfe33d5a0892432e8924d1e36 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:13:19 2023 +0300 filtering: fix typo commit 96d1069573171538333330d6af94ef0f4208a9c4 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:00:18 2023 +0300 filtering: imp code more commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 19:13:26 2023 +0300 all: add todo commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 14:36:08 2023 +0300 all: imp code more commit b6e734ccbeda82669023f6578481260b7c1f7161 Author: Stanislav Chzhen <[email protected]> Date: Tue Apr 25 15:01:56 2023 +0300 filtering: imp code commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 20:06:36 2023 +0300 all: imp code commit 49fa6e587052a40bb431fea457701ee860493527 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 14:57:19 2023 +0300 all: rm safe browsing ctx commit bbcb66cb03e18fa875e3c33cf16295892739e507 Author: Stanislav Chzhen <[email protected]> Date: Fri Apr 21 17:54:18 2023 +0300 filtering: add cache item commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 18:43:02 2023 +0300 filtering: fix hashes commit 153fec46270212af03f3631bfb42c5d680c4e142 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 16:15:15 2023 +0300 filtering: add test cases commit 09372f92bbb1fc082f1b1283594ee589100209c5 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 15:38:05 2023 +0300 filtering: imp code commit 466bc26d524ea6d1c3efb33692a7785d39e491ca Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 18:38:40 2023 +0300 filtering: add tests commit 24365ecf8c60512fdac65833ee603c80864ae018 Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 11:38:57 2023 +0300 filtering: add hashprefix </s> remove d.parentalServer = "127.0.0.1" </s> add </s> remove d.SetParentalUpstream(aghtest.NewBlockUpstream(pcBlocked, true)) </s> add </s> remove d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true)) </s> add </s> remove d, setts := newForTest(t, &Config{ParentalEnabled: true}, nil) </s> add d, setts := newForTest(t, &Config{ ParentalEnabled: true, ParentalControlChecker: newChecker(pcBlocked), }, nil) </s> remove d, setts := newForTest(t, &Config{SafeBrowsingEnabled: true}, nil) </s> add d, setts := newForTest(t, &Config{ SafeBrowsingEnabled: true, SafeBrowsingChecker: newChecker(sbBlocked), }, nil)
https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c
internal/filtering/filtering_test.go
keep replace keep keep replace replace keep keep
<mask> func TestParallelSB(t *testing.T) { <mask> d, setts := newForTest(t, &Config{SafeBrowsingEnabled: true}, nil) <mask> t.Cleanup(d.Close) <mask> <mask> d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true)) <mask> <mask> t.Run("group", func(t *testing.T) { <mask> for i := 0; i < 100; i++ { </s> Pull request 1837: AG-21462-imp-safebrowsing-parental Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master Squashed commit of the following: commit 85016d4f1105e21a407efade0bd45b8362808061 Merge: 0e61edade 620b51e3e Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 16:36:30 2023 +0300 Merge branch 'master' into AG-21462-imp-safebrowsing-parental commit 0e61edadeff34f6305e941c1db94575c82f238d9 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 14:51:37 2023 +0300 filtering: imp tests commit 994255514cc0f67dfe33d5a0892432e8924d1e36 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:13:19 2023 +0300 filtering: fix typo commit 96d1069573171538333330d6af94ef0f4208a9c4 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:00:18 2023 +0300 filtering: imp code more commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 19:13:26 2023 +0300 all: add todo commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 14:36:08 2023 +0300 all: imp code more commit b6e734ccbeda82669023f6578481260b7c1f7161 Author: Stanislav Chzhen <[email protected]> Date: Tue Apr 25 15:01:56 2023 +0300 filtering: imp code commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 20:06:36 2023 +0300 all: imp code commit 49fa6e587052a40bb431fea457701ee860493527 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 14:57:19 2023 +0300 all: rm safe browsing ctx commit bbcb66cb03e18fa875e3c33cf16295892739e507 Author: Stanislav Chzhen <[email protected]> Date: Fri Apr 21 17:54:18 2023 +0300 filtering: add cache item commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 18:43:02 2023 +0300 filtering: fix hashes commit 153fec46270212af03f3631bfb42c5d680c4e142 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 16:15:15 2023 +0300 filtering: add test cases commit 09372f92bbb1fc082f1b1283594ee589100209c5 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 15:38:05 2023 +0300 filtering: imp code commit 466bc26d524ea6d1c3efb33692a7785d39e491ca Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 18:38:40 2023 +0300 filtering: add tests commit 24365ecf8c60512fdac65833ee603c80864ae018 Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 11:38:57 2023 +0300 filtering: add hashprefix </s> remove d.safeBrowsingServer = defaultSafebrowsingServer </s> add </s> remove d, setts := newForTest(b, &Config{SafeBrowsingEnabled: true}, nil) </s> add d, setts := newForTest(b, &Config{ SafeBrowsingEnabled: true, SafeBrowsingChecker: newChecker(sbBlocked), }, nil) </s> remove d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true)) </s> add </s> remove d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true)) </s> add </s> remove d, setts := newForTest(b, &Config{SafeBrowsingEnabled: true}, nil) </s> add d, setts := newForTest(b, &Config{ SafeBrowsingEnabled: true, SafeBrowsingChecker: newChecker(sbBlocked), }, nil)
https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c
internal/filtering/filtering_test.go
keep keep keep keep replace keep keep keep keep keep
<mask> logOutput := &bytes.Buffer{} <mask> aghtest.ReplaceLogWriter(t, logOutput) <mask> aghtest.ReplaceLogLevel(t, log.DEBUG) <mask> <mask> d, setts := newForTest(t, &Config{ParentalEnabled: true}, nil) <mask> t.Cleanup(d.Close) <mask> <mask> d.SetParentalUpstream(aghtest.NewBlockUpstream(pcBlocked, true)) <mask> d.checkMatch(t, pcBlocked, setts) <mask> require.Contains(t, logOutput.String(), fmt.Sprintf("parental lookup for %q", pcBlocked)) </s> Pull request 1837: AG-21462-imp-safebrowsing-parental Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master Squashed commit of the following: commit 85016d4f1105e21a407efade0bd45b8362808061 Merge: 0e61edade 620b51e3e Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 16:36:30 2023 +0300 Merge branch 'master' into AG-21462-imp-safebrowsing-parental commit 0e61edadeff34f6305e941c1db94575c82f238d9 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 14:51:37 2023 +0300 filtering: imp tests commit 994255514cc0f67dfe33d5a0892432e8924d1e36 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:13:19 2023 +0300 filtering: fix typo commit 96d1069573171538333330d6af94ef0f4208a9c4 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:00:18 2023 +0300 filtering: imp code more commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 19:13:26 2023 +0300 all: add todo commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 14:36:08 2023 +0300 all: imp code more commit b6e734ccbeda82669023f6578481260b7c1f7161 Author: Stanislav Chzhen <[email protected]> Date: Tue Apr 25 15:01:56 2023 +0300 filtering: imp code commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 20:06:36 2023 +0300 all: imp code commit 49fa6e587052a40bb431fea457701ee860493527 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 14:57:19 2023 +0300 all: rm safe browsing ctx commit bbcb66cb03e18fa875e3c33cf16295892739e507 Author: Stanislav Chzhen <[email protected]> Date: Fri Apr 21 17:54:18 2023 +0300 filtering: add cache item commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 18:43:02 2023 +0300 filtering: fix hashes commit 153fec46270212af03f3631bfb42c5d680c4e142 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 16:15:15 2023 +0300 filtering: add test cases commit 09372f92bbb1fc082f1b1283594ee589100209c5 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 15:38:05 2023 +0300 filtering: imp code commit 466bc26d524ea6d1c3efb33692a7785d39e491ca Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 18:38:40 2023 +0300 filtering: add tests commit 24365ecf8c60512fdac65833ee603c80864ae018 Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 11:38:57 2023 +0300 filtering: add hashprefix </s> remove d.SetParentalUpstream(aghtest.NewBlockUpstream(pcBlocked, true)) </s> add </s> remove d, setts := newForTest(t, &Config{SafeBrowsingEnabled: true}, nil) </s> add sbChecker := newChecker(sbBlocked) d, setts := newForTest(t, &Config{ SafeBrowsingEnabled: true, SafeBrowsingChecker: sbChecker, }, nil) </s> remove d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true)) </s> add </s> remove d.safeBrowsingServer = defaultSafebrowsingServer </s> add </s> remove d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true)) </s> add </s> remove d, setts := newForTest(t, &Config{SafeBrowsingEnabled: true}, nil) </s> add d, setts := newForTest(t, &Config{ SafeBrowsingEnabled: true, SafeBrowsingChecker: newChecker(sbBlocked), }, nil)
https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c
internal/filtering/filtering_test.go
keep keep keep keep replace keep keep keep keep keep
<mask> <mask> d, setts := newForTest(t, &Config{ParentalEnabled: true}, nil) <mask> t.Cleanup(d.Close) <mask> <mask> d.SetParentalUpstream(aghtest.NewBlockUpstream(pcBlocked, true)) <mask> d.checkMatch(t, pcBlocked, setts) <mask> require.Contains(t, logOutput.String(), fmt.Sprintf("parental lookup for %q", pcBlocked)) <mask> <mask> d.checkMatch(t, "www."+pcBlocked, setts) <mask> d.checkMatchEmpty(t, "www.yandex.ru", setts) </s> Pull request 1837: AG-21462-imp-safebrowsing-parental Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master Squashed commit of the following: commit 85016d4f1105e21a407efade0bd45b8362808061 Merge: 0e61edade 620b51e3e Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 16:36:30 2023 +0300 Merge branch 'master' into AG-21462-imp-safebrowsing-parental commit 0e61edadeff34f6305e941c1db94575c82f238d9 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 14:51:37 2023 +0300 filtering: imp tests commit 994255514cc0f67dfe33d5a0892432e8924d1e36 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:13:19 2023 +0300 filtering: fix typo commit 96d1069573171538333330d6af94ef0f4208a9c4 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:00:18 2023 +0300 filtering: imp code more commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 19:13:26 2023 +0300 all: add todo commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 14:36:08 2023 +0300 all: imp code more commit b6e734ccbeda82669023f6578481260b7c1f7161 Author: Stanislav Chzhen <[email protected]> Date: Tue Apr 25 15:01:56 2023 +0300 filtering: imp code commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 20:06:36 2023 +0300 all: imp code commit 49fa6e587052a40bb431fea457701ee860493527 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 14:57:19 2023 +0300 all: rm safe browsing ctx commit bbcb66cb03e18fa875e3c33cf16295892739e507 Author: Stanislav Chzhen <[email protected]> Date: Fri Apr 21 17:54:18 2023 +0300 filtering: add cache item commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 18:43:02 2023 +0300 filtering: fix hashes commit 153fec46270212af03f3631bfb42c5d680c4e142 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 16:15:15 2023 +0300 filtering: add test cases commit 09372f92bbb1fc082f1b1283594ee589100209c5 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 15:38:05 2023 +0300 filtering: imp code commit 466bc26d524ea6d1c3efb33692a7785d39e491ca Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 18:38:40 2023 +0300 filtering: add tests commit 24365ecf8c60512fdac65833ee603c80864ae018 Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 11:38:57 2023 +0300 filtering: add hashprefix </s> remove d, setts := newForTest(t, &Config{ParentalEnabled: true}, nil) </s> add d, setts := newForTest(t, &Config{ ParentalEnabled: true, ParentalControlChecker: newChecker(pcBlocked), }, nil) </s> remove d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true)) </s> add </s> remove d.safeBrowsingServer = defaultSafebrowsingServer </s> add </s> remove d, setts := newForTest(t, &Config{SafeBrowsingEnabled: true}, nil) </s> add sbChecker := newChecker(sbBlocked) d, setts := newForTest(t, &Config{ SafeBrowsingEnabled: true, SafeBrowsingChecker: sbChecker, }, nil) </s> remove d.safeBrowsingServer = "127.0.0.1" </s> add </s> remove d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true)) </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c
internal/filtering/filtering_test.go
keep keep keep keep replace keep keep keep keep keep
<mask> d.checkMatchEmpty(t, "yandex.ru", setts) <mask> d.checkMatchEmpty(t, "api.jquery.com", setts) <mask> <mask> // Test cached result. <mask> d.parentalServer = "127.0.0.1" <mask> d.checkMatch(t, pcBlocked, setts) <mask> d.checkMatchEmpty(t, "yandex.ru", setts) <mask> } <mask> <mask> // Filtering. </s> Pull request 1837: AG-21462-imp-safebrowsing-parental Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master Squashed commit of the following: commit 85016d4f1105e21a407efade0bd45b8362808061 Merge: 0e61edade 620b51e3e Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 16:36:30 2023 +0300 Merge branch 'master' into AG-21462-imp-safebrowsing-parental commit 0e61edadeff34f6305e941c1db94575c82f238d9 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 14:51:37 2023 +0300 filtering: imp tests commit 994255514cc0f67dfe33d5a0892432e8924d1e36 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:13:19 2023 +0300 filtering: fix typo commit 96d1069573171538333330d6af94ef0f4208a9c4 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:00:18 2023 +0300 filtering: imp code more commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 19:13:26 2023 +0300 all: add todo commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 14:36:08 2023 +0300 all: imp code more commit b6e734ccbeda82669023f6578481260b7c1f7161 Author: Stanislav Chzhen <[email protected]> Date: Tue Apr 25 15:01:56 2023 +0300 filtering: imp code commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 20:06:36 2023 +0300 all: imp code commit 49fa6e587052a40bb431fea457701ee860493527 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 14:57:19 2023 +0300 all: rm safe browsing ctx commit bbcb66cb03e18fa875e3c33cf16295892739e507 Author: Stanislav Chzhen <[email protected]> Date: Fri Apr 21 17:54:18 2023 +0300 filtering: add cache item commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 18:43:02 2023 +0300 filtering: fix hashes commit 153fec46270212af03f3631bfb42c5d680c4e142 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 16:15:15 2023 +0300 filtering: add test cases commit 09372f92bbb1fc082f1b1283594ee589100209c5 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 15:38:05 2023 +0300 filtering: imp code commit 466bc26d524ea6d1c3efb33692a7785d39e491ca Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 18:38:40 2023 +0300 filtering: add tests commit 24365ecf8c60512fdac65833ee603c80864ae018 Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 11:38:57 2023 +0300 filtering: add hashprefix </s> remove d.safeBrowsingServer = "127.0.0.1" </s> add </s> remove d.safeBrowsingServer = defaultSafebrowsingServer </s> add </s> remove d.SetParentalUpstream(aghtest.NewBlockUpstream(pcBlocked, true)) </s> add </s> remove d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true)) </s> add </s> remove d, setts := newForTest(t, &Config{ParentalEnabled: true}, nil) </s> add d, setts := newForTest(t, &Config{ ParentalEnabled: true, ParentalControlChecker: newChecker(pcBlocked), }, nil) </s> remove d, setts := newForTest(t, &Config{SafeBrowsingEnabled: true}, nil) </s> add sbChecker := newChecker(sbBlocked) d, setts := newForTest(t, &Config{ SafeBrowsingEnabled: true, SafeBrowsingChecker: sbChecker, }, nil)
https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c
internal/filtering/filtering_test.go
keep keep keep keep replace replace keep keep keep keep keep
<mask> <mask> func TestClientSettings(t *testing.T) { <mask> d, setts := newForTest(t, <mask> &Config{ <mask> ParentalEnabled: true, <mask> SafeBrowsingEnabled: false, <mask> }, <mask> []Filter{{ <mask> ID: 0, Data: []byte("||example.org^\n"), <mask> }}, <mask> ) </s> Pull request 1837: AG-21462-imp-safebrowsing-parental Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master Squashed commit of the following: commit 85016d4f1105e21a407efade0bd45b8362808061 Merge: 0e61edade 620b51e3e Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 16:36:30 2023 +0300 Merge branch 'master' into AG-21462-imp-safebrowsing-parental commit 0e61edadeff34f6305e941c1db94575c82f238d9 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 14:51:37 2023 +0300 filtering: imp tests commit 994255514cc0f67dfe33d5a0892432e8924d1e36 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:13:19 2023 +0300 filtering: fix typo commit 96d1069573171538333330d6af94ef0f4208a9c4 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:00:18 2023 +0300 filtering: imp code more commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 19:13:26 2023 +0300 all: add todo commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 14:36:08 2023 +0300 all: imp code more commit b6e734ccbeda82669023f6578481260b7c1f7161 Author: Stanislav Chzhen <[email protected]> Date: Tue Apr 25 15:01:56 2023 +0300 filtering: imp code commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 20:06:36 2023 +0300 all: imp code commit 49fa6e587052a40bb431fea457701ee860493527 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 14:57:19 2023 +0300 all: rm safe browsing ctx commit bbcb66cb03e18fa875e3c33cf16295892739e507 Author: Stanislav Chzhen <[email protected]> Date: Fri Apr 21 17:54:18 2023 +0300 filtering: add cache item commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 18:43:02 2023 +0300 filtering: fix hashes commit 153fec46270212af03f3631bfb42c5d680c4e142 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 16:15:15 2023 +0300 filtering: add test cases commit 09372f92bbb1fc082f1b1283594ee589100209c5 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 15:38:05 2023 +0300 filtering: imp code commit 466bc26d524ea6d1c3efb33692a7785d39e491ca Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 18:38:40 2023 +0300 filtering: add tests commit 24365ecf8c60512fdac65833ee603c80864ae018 Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 11:38:57 2023 +0300 filtering: add hashprefix </s> remove d, setts := newForTest(t, &Config{SafeBrowsingEnabled: true}, nil) </s> add d, setts := newForTest(t, &Config{ SafeBrowsingEnabled: true, SafeBrowsingChecker: newChecker(sbBlocked), }, nil) </s> remove d, setts := newForTest(t, &Config{ParentalEnabled: true}, nil) </s> add d, setts := newForTest(t, &Config{ ParentalEnabled: true, ParentalControlChecker: newChecker(pcBlocked), }, nil) </s> remove d, setts := newForTest(t, &Config{SafeBrowsingEnabled: true}, nil) </s> add sbChecker := newChecker(sbBlocked) d, setts := newForTest(t, &Config{ SafeBrowsingEnabled: true, SafeBrowsingChecker: sbChecker, }, nil) </s> remove d, setts := newForTest(b, &Config{SafeBrowsingEnabled: true}, nil) </s> add d, setts := newForTest(b, &Config{ SafeBrowsingEnabled: true, SafeBrowsingChecker: newChecker(sbBlocked), }, nil) </s> remove d, setts := newForTest(b, &Config{SafeBrowsingEnabled: true}, nil) </s> add d, setts := newForTest(b, &Config{ SafeBrowsingEnabled: true, SafeBrowsingChecker: newChecker(sbBlocked), }, nil) </s> remove d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true)) </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c
internal/filtering/filtering_test.go
keep keep keep keep replace replace replace keep keep keep keep keep
<mask> }}, <mask> ) <mask> t.Cleanup(d.Close) <mask> <mask> d.SetParentalUpstream(aghtest.NewBlockUpstream(pcBlocked, true)) <mask> d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true)) <mask> <mask> type testCase struct { <mask> name string <mask> host string <mask> before bool <mask> wantReason Reason </s> Pull request 1837: AG-21462-imp-safebrowsing-parental Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master Squashed commit of the following: commit 85016d4f1105e21a407efade0bd45b8362808061 Merge: 0e61edade 620b51e3e Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 16:36:30 2023 +0300 Merge branch 'master' into AG-21462-imp-safebrowsing-parental commit 0e61edadeff34f6305e941c1db94575c82f238d9 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 14:51:37 2023 +0300 filtering: imp tests commit 994255514cc0f67dfe33d5a0892432e8924d1e36 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:13:19 2023 +0300 filtering: fix typo commit 96d1069573171538333330d6af94ef0f4208a9c4 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:00:18 2023 +0300 filtering: imp code more commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 19:13:26 2023 +0300 all: add todo commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 14:36:08 2023 +0300 all: imp code more commit b6e734ccbeda82669023f6578481260b7c1f7161 Author: Stanislav Chzhen <[email protected]> Date: Tue Apr 25 15:01:56 2023 +0300 filtering: imp code commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 20:06:36 2023 +0300 all: imp code commit 49fa6e587052a40bb431fea457701ee860493527 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 14:57:19 2023 +0300 all: rm safe browsing ctx commit bbcb66cb03e18fa875e3c33cf16295892739e507 Author: Stanislav Chzhen <[email protected]> Date: Fri Apr 21 17:54:18 2023 +0300 filtering: add cache item commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 18:43:02 2023 +0300 filtering: fix hashes commit 153fec46270212af03f3631bfb42c5d680c4e142 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 16:15:15 2023 +0300 filtering: add test cases commit 09372f92bbb1fc082f1b1283594ee589100209c5 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 15:38:05 2023 +0300 filtering: imp code commit 466bc26d524ea6d1c3efb33692a7785d39e491ca Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 18:38:40 2023 +0300 filtering: add tests commit 24365ecf8c60512fdac65833ee603c80864ae018 Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 11:38:57 2023 +0300 filtering: add hashprefix </s> add // Checker is used for safe browsing or parental control hash-prefix filtering. type Checker interface { // Check returns true if request for the host should be blocked. Check(host string) (block bool, err error) } </s> remove d.SetParentalUpstream(aghtest.NewBlockUpstream(pcBlocked, true)) </s> add </s> remove d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true)) </s> add </s> remove d, setts := newForTest(t, &Config{SafeBrowsingEnabled: true}, nil) </s> add d, setts := newForTest(t, &Config{ SafeBrowsingEnabled: true, SafeBrowsingChecker: newChecker(sbBlocked), }, nil) </s> remove d, setts := newForTest(t, &Config{ParentalEnabled: true}, nil) </s> add d, setts := newForTest(t, &Config{ ParentalEnabled: true, ParentalControlChecker: newChecker(pcBlocked), }, nil) </s> remove d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true)) </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c
internal/filtering/filtering_test.go
keep keep keep keep replace keep keep replace replace keep keep
<mask> <mask> // Benchmarks. <mask> <mask> func BenchmarkSafeBrowsing(b *testing.B) { <mask> d, setts := newForTest(b, &Config{SafeBrowsingEnabled: true}, nil) <mask> b.Cleanup(d.Close) <mask> <mask> d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true)) <mask> <mask> for n := 0; n < b.N; n++ { <mask> res, err := d.CheckHost(sbBlocked, dns.TypeA, setts) </s> Pull request 1837: AG-21462-imp-safebrowsing-parental Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master Squashed commit of the following: commit 85016d4f1105e21a407efade0bd45b8362808061 Merge: 0e61edade 620b51e3e Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 16:36:30 2023 +0300 Merge branch 'master' into AG-21462-imp-safebrowsing-parental commit 0e61edadeff34f6305e941c1db94575c82f238d9 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 14:51:37 2023 +0300 filtering: imp tests commit 994255514cc0f67dfe33d5a0892432e8924d1e36 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:13:19 2023 +0300 filtering: fix typo commit 96d1069573171538333330d6af94ef0f4208a9c4 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:00:18 2023 +0300 filtering: imp code more commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 19:13:26 2023 +0300 all: add todo commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 14:36:08 2023 +0300 all: imp code more commit b6e734ccbeda82669023f6578481260b7c1f7161 Author: Stanislav Chzhen <[email protected]> Date: Tue Apr 25 15:01:56 2023 +0300 filtering: imp code commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 20:06:36 2023 +0300 all: imp code commit 49fa6e587052a40bb431fea457701ee860493527 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 14:57:19 2023 +0300 all: rm safe browsing ctx commit bbcb66cb03e18fa875e3c33cf16295892739e507 Author: Stanislav Chzhen <[email protected]> Date: Fri Apr 21 17:54:18 2023 +0300 filtering: add cache item commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 18:43:02 2023 +0300 filtering: fix hashes commit 153fec46270212af03f3631bfb42c5d680c4e142 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 16:15:15 2023 +0300 filtering: add test cases commit 09372f92bbb1fc082f1b1283594ee589100209c5 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 15:38:05 2023 +0300 filtering: imp code commit 466bc26d524ea6d1c3efb33692a7785d39e491ca Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 18:38:40 2023 +0300 filtering: add tests commit 24365ecf8c60512fdac65833ee603c80864ae018 Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 11:38:57 2023 +0300 filtering: add hashprefix </s> remove d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true)) </s> add </s> remove d, setts := newForTest(b, &Config{SafeBrowsingEnabled: true}, nil) </s> add d, setts := newForTest(b, &Config{ SafeBrowsingEnabled: true, SafeBrowsingChecker: newChecker(sbBlocked), }, nil) </s> remove d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true)) </s> add </s> remove d, setts := newForTest(t, &Config{SafeBrowsingEnabled: true}, nil) </s> add d, setts := newForTest(t, &Config{ SafeBrowsingEnabled: true, SafeBrowsingChecker: newChecker(sbBlocked), }, nil) </s> remove d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true)) </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c
internal/filtering/filtering_test.go
keep replace keep keep replace replace keep keep keep keep
<mask> func BenchmarkSafeBrowsingParallel(b *testing.B) { <mask> d, setts := newForTest(b, &Config{SafeBrowsingEnabled: true}, nil) <mask> b.Cleanup(d.Close) <mask> <mask> d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true)) <mask> <mask> b.RunParallel(func(pb *testing.PB) { <mask> for pb.Next() { <mask> res, err := d.CheckHost(sbBlocked, dns.TypeA, setts) <mask> require.NoError(b, err) </s> Pull request 1837: AG-21462-imp-safebrowsing-parental Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master Squashed commit of the following: commit 85016d4f1105e21a407efade0bd45b8362808061 Merge: 0e61edade 620b51e3e Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 16:36:30 2023 +0300 Merge branch 'master' into AG-21462-imp-safebrowsing-parental commit 0e61edadeff34f6305e941c1db94575c82f238d9 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 14:51:37 2023 +0300 filtering: imp tests commit 994255514cc0f67dfe33d5a0892432e8924d1e36 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:13:19 2023 +0300 filtering: fix typo commit 96d1069573171538333330d6af94ef0f4208a9c4 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:00:18 2023 +0300 filtering: imp code more commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 19:13:26 2023 +0300 all: add todo commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 14:36:08 2023 +0300 all: imp code more commit b6e734ccbeda82669023f6578481260b7c1f7161 Author: Stanislav Chzhen <[email protected]> Date: Tue Apr 25 15:01:56 2023 +0300 filtering: imp code commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 20:06:36 2023 +0300 all: imp code commit 49fa6e587052a40bb431fea457701ee860493527 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 14:57:19 2023 +0300 all: rm safe browsing ctx commit bbcb66cb03e18fa875e3c33cf16295892739e507 Author: Stanislav Chzhen <[email protected]> Date: Fri Apr 21 17:54:18 2023 +0300 filtering: add cache item commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 18:43:02 2023 +0300 filtering: fix hashes commit 153fec46270212af03f3631bfb42c5d680c4e142 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 16:15:15 2023 +0300 filtering: add test cases commit 09372f92bbb1fc082f1b1283594ee589100209c5 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 15:38:05 2023 +0300 filtering: imp code commit 466bc26d524ea6d1c3efb33692a7785d39e491ca Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 18:38:40 2023 +0300 filtering: add tests commit 24365ecf8c60512fdac65833ee603c80864ae018 Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 11:38:57 2023 +0300 filtering: add hashprefix </s> remove d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true)) </s> add </s> remove d, setts := newForTest(b, &Config{SafeBrowsingEnabled: true}, nil) </s> add d, setts := newForTest(b, &Config{ SafeBrowsingEnabled: true, SafeBrowsingChecker: newChecker(sbBlocked), }, nil) </s> remove d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true)) </s> add </s> remove d, setts := newForTest(t, &Config{SafeBrowsingEnabled: true}, nil) </s> add d, setts := newForTest(t, &Config{ SafeBrowsingEnabled: true, SafeBrowsingChecker: newChecker(sbBlocked), }, nil) </s> add func newChecker(host string) Checker { return hashprefix.New(&hashprefix.Config{ CacheTime: 10, CacheSize: 100000, Upstream: aghtest.NewBlockUpstream(host, true), }) }
https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c
internal/filtering/filtering_test.go
keep replace replace replace replace replace replace keep replace keep keep
<mask> import ( <mask> "bytes" <mask> "crypto/sha256" <mask> "encoding/binary" <mask> "encoding/hex" <mask> "fmt" <mask> "net" <mask> "net/http" <mask> "strings" <mask> "sync" <mask> "time" </s> Pull request 1837: AG-21462-imp-safebrowsing-parental Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master Squashed commit of the following: commit 85016d4f1105e21a407efade0bd45b8362808061 Merge: 0e61edade 620b51e3e Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 16:36:30 2023 +0300 Merge branch 'master' into AG-21462-imp-safebrowsing-parental commit 0e61edadeff34f6305e941c1db94575c82f238d9 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 14:51:37 2023 +0300 filtering: imp tests commit 994255514cc0f67dfe33d5a0892432e8924d1e36 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:13:19 2023 +0300 filtering: fix typo commit 96d1069573171538333330d6af94ef0f4208a9c4 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:00:18 2023 +0300 filtering: imp code more commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 19:13:26 2023 +0300 all: add todo commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 14:36:08 2023 +0300 all: imp code more commit b6e734ccbeda82669023f6578481260b7c1f7161 Author: Stanislav Chzhen <[email protected]> Date: Tue Apr 25 15:01:56 2023 +0300 filtering: imp code commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 20:06:36 2023 +0300 all: imp code commit 49fa6e587052a40bb431fea457701ee860493527 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 14:57:19 2023 +0300 all: rm safe browsing ctx commit bbcb66cb03e18fa875e3c33cf16295892739e507 Author: Stanislav Chzhen <[email protected]> Date: Fri Apr 21 17:54:18 2023 +0300 filtering: add cache item commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 18:43:02 2023 +0300 filtering: fix hashes commit 153fec46270212af03f3631bfb42c5d680c4e142 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 16:15:15 2023 +0300 filtering: add test cases commit 09372f92bbb1fc082f1b1283594ee589100209c5 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 15:38:05 2023 +0300 filtering: imp code commit 466bc26d524ea6d1c3efb33692a7785d39e491ca Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 18:38:40 2023 +0300 filtering: add tests commit 24365ecf8c60512fdac65833ee603c80864ae018 Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 11:38:57 2023 +0300 filtering: add hashprefix </s> remove "time" </s> add </s> remove "github.com/AdguardTeam/dnsproxy/upstream" "github.com/AdguardTeam/golibs/cache" </s> add </s> remove "github.com/AdguardTeam/golibs/cache" </s> add "github.com/AdguardTeam/AdGuardHome/internal/filtering/hashprefix" </s> remove const hostname = "wmconvirus.narod.ru" </s> add const ( hostname = "wmconvirus.narod.ru" cacheTime = 10 * time.Minute cacheSize = 10000 ) sbChecker := hashprefix.New(&hashprefix.Config{ CacheTime: cacheTime, CacheSize: cacheSize, Upstream: aghtest.NewBlockUpstream(hostname, true), }) </s> remove // TODO(a.garipov): Make configurable. const ( dnsTimeout = 3 * time.Second defaultSafebrowsingServer = `https://family.adguard-dns.com/dns-query` defaultParentalServer = `https://family.adguard-dns.com/dns-query` sbTXTSuffix = `sb.dns.adguard.com.` pcTXTSuffix = `pc.dns.adguard.com.` ) // SetParentalUpstream sets the parental upstream for *DNSFilter. // // TODO(e.burkov): Remove this in v1 API to forbid the direct access. func (d *DNSFilter) SetParentalUpstream(u upstream.Upstream) { d.parentalUpstream = u } // SetSafeBrowsingUpstream sets the safe browsing upstream for *DNSFilter. // // TODO(e.burkov): Remove this in v1 API to forbid the direct access. func (d *DNSFilter) SetSafeBrowsingUpstream(u upstream.Upstream) { d.safeBrowsingUpstream = u } func (d *DNSFilter) initSecurityServices() error { var err error d.safeBrowsingServer = defaultSafebrowsingServer d.parentalServer = defaultParentalServer opts := &upstream.Options{ Timeout: dnsTimeout, ServerIPAddrs: []net.IP{ {94, 140, 14, 15}, {94, 140, 15, 16}, net.ParseIP("2a10:50c0::bad1:ff"), net.ParseIP("2a10:50c0::bad2:ff"), }, } parUps, err := upstream.AddressToUpstream(d.parentalServer, opts) if err != nil { return fmt.Errorf("converting parental server: %w", err) } d.SetParentalUpstream(parUps) sbUps, err := upstream.AddressToUpstream(d.safeBrowsingServer, opts) if err != nil { return fmt.Errorf("converting safe browsing server: %w", err) } d.SetSafeBrowsingUpstream(sbUps) return nil } /* expire byte[4] hash byte[32] ... */ func (c *sbCtx) setCache(prefix, hashes []byte) { d := make([]byte, 4+len(hashes)) expire := uint(time.Now().Unix()) + c.cacheTime*60 binary.BigEndian.PutUint32(d[:4], uint32(expire)) copy(d[4:], hashes) c.cache.Set(prefix, d) log.Debug("%s: stored in cache: %v", c.svc, prefix) } // findInHash returns 32-byte hash if it's found in hashToHost. func (c *sbCtx) findInHash(val []byte) (hash32 [32]byte, found bool) { for i := 4; i < len(val); i += 32 { hash := val[i : i+32] copy(hash32[:], hash[0:32]) _, found = c.hashToHost[hash32] if found { return hash32, found } } return [32]byte{}, false } func (c *sbCtx) getCached() int { now := time.Now().Unix() hashesToRequest := map[[32]byte]string{} for k, v := range c.hashToHost { // nolint:looppointer // The subsilce is used for a safe cache lookup. val := c.cache.Get(k[0:2]) if val == nil || now >= int64(binary.BigEndian.Uint32(val)) { hashesToRequest[k] = v continue } if hash32, found := c.findInHash(val); found { log.Debug("%s: found in cache: %s: blocked by %v", c.svc, c.host, hash32) return 1 } } if len(hashesToRequest) == 0 { log.Debug("%s: found in cache: %s: not blocked", c.svc, c.host) return -1 } c.hashToHost = hashesToRequest return 0 } type sbCtx struct { host string svc string hashToHost map[[32]byte]string cache cache.Cache cacheTime uint } func hostnameToHashes(host string) map[[32]byte]string { hashes := map[[32]byte]string{} tld, icann := publicsuffix.PublicSuffix(host) if !icann { // private suffixes like cloudfront.net tld = "" } curhost := host nDots := 0 for i := len(curhost) - 1; i >= 0; i-- { if curhost[i] == '.' { nDots++ if nDots == 4 { curhost = curhost[i+1:] // "xxx.a.b.c.d" -> "a.b.c.d" break } } } for { if curhost == "" { // we've reached end of string break } if tld != "" && curhost == tld { // we've reached the TLD, don't hash it break } sum := sha256.Sum256([]byte(curhost)) hashes[sum] = curhost pos := strings.IndexByte(curhost, byte('.')) if pos < 0 { break } curhost = curhost[pos+1:] } return hashes } // convert hash array to string func (c *sbCtx) getQuestion() string { b := &strings.Builder{} for hash := range c.hashToHost { // nolint:looppointer // The subsilce is used for safe hex encoding. stringutil.WriteToBuilder(b, hex.EncodeToString(hash[0:2]), ".") } if c.svc == "SafeBrowsing" { stringutil.WriteToBuilder(b, sbTXTSuffix) return b.String() } stringutil.WriteToBuilder(b, pcTXTSuffix) return b.String() } // Find the target hash in TXT response func (c *sbCtx) processTXT(resp *dns.Msg) (bool, [][]byte) { matched := false hashes := [][]byte{} for _, a := range resp.Answer { txt, ok := a.(*dns.TXT) if !ok { continue } log.Debug("%s: received hashes for %s: %v", c.svc, c.host, txt.Txt) for _, t := range txt.Txt { if len(t) != 32*2 { continue } hash, err := hex.DecodeString(t) if err != nil { continue } hashes = append(hashes, hash) if !matched { var hash32 [32]byte copy(hash32[:], hash) var hashHost string hashHost, ok = c.hashToHost[hash32] if ok { log.Debug("%s: matched %s by %s/%s", c.svc, c.host, hashHost, t) matched = true } } } } return matched, hashes } func (c *sbCtx) storeCache(hashes [][]byte) { slices.SortFunc(hashes, func(a, b []byte) (sortsBefore bool) { return bytes.Compare(a, b) == -1 }) var curData []byte var prevPrefix []byte for i, hash := range hashes { // nolint:looppointer // The subsilce is used for a safe comparison. if !bytes.Equal(hash[0:2], prevPrefix) { if i != 0 { c.setCache(prevPrefix, curData) curData = nil } prevPrefix = hashes[i][0:2] } curData = append(curData, hash...) } if len(prevPrefix) != 0 { c.setCache(prevPrefix, curData) } for hash := range c.hashToHost { // nolint:looppointer // The subsilce is used for a safe cache lookup. prefix := hash[0:2] val := c.cache.Get(prefix) if val == nil { c.setCache(prefix, nil) } } } func check(c *sbCtx, r Result, u upstream.Upstream) (Result, error) { c.hashToHost = hostnameToHashes(c.host) switch c.getCached() { case -1: return Result{}, nil case 1: return r, nil } question := c.getQuestion() log.Tracef("%s: checking %s: %s", c.svc, c.host, question) req := (&dns.Msg{}).SetQuestion(question, dns.TypeTXT) resp, err := u.Exchange(req) if err != nil { return Result{}, err } matched, receivedHashes := c.processTXT(resp) c.storeCache(receivedHashes) if matched { return r, nil } return Result{}, nil } </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c
internal/filtering/safebrowsing.go
keep replace keep keep replace replace
<mask> "sync" <mask> "time" <mask> <mask> "github.com/AdguardTeam/AdGuardHome/internal/aghhttp" <mask> "github.com/AdguardTeam/dnsproxy/upstream" <mask> "github.com/AdguardTeam/golibs/cache" </s> Pull request 1837: AG-21462-imp-safebrowsing-parental Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master Squashed commit of the following: commit 85016d4f1105e21a407efade0bd45b8362808061 Merge: 0e61edade 620b51e3e Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 16:36:30 2023 +0300 Merge branch 'master' into AG-21462-imp-safebrowsing-parental commit 0e61edadeff34f6305e941c1db94575c82f238d9 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 14:51:37 2023 +0300 filtering: imp tests commit 994255514cc0f67dfe33d5a0892432e8924d1e36 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:13:19 2023 +0300 filtering: fix typo commit 96d1069573171538333330d6af94ef0f4208a9c4 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:00:18 2023 +0300 filtering: imp code more commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 19:13:26 2023 +0300 all: add todo commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 14:36:08 2023 +0300 all: imp code more commit b6e734ccbeda82669023f6578481260b7c1f7161 Author: Stanislav Chzhen <[email protected]> Date: Tue Apr 25 15:01:56 2023 +0300 filtering: imp code commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 20:06:36 2023 +0300 all: imp code commit 49fa6e587052a40bb431fea457701ee860493527 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 14:57:19 2023 +0300 all: rm safe browsing ctx commit bbcb66cb03e18fa875e3c33cf16295892739e507 Author: Stanislav Chzhen <[email protected]> Date: Fri Apr 21 17:54:18 2023 +0300 filtering: add cache item commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 18:43:02 2023 +0300 filtering: fix hashes commit 153fec46270212af03f3631bfb42c5d680c4e142 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 16:15:15 2023 +0300 filtering: add test cases commit 09372f92bbb1fc082f1b1283594ee589100209c5 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 15:38:05 2023 +0300 filtering: imp code commit 466bc26d524ea6d1c3efb33692a7785d39e491ca Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 18:38:40 2023 +0300 filtering: add tests commit 24365ecf8c60512fdac65833ee603c80864ae018 Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 11:38:57 2023 +0300 filtering: add hashprefix </s> remove "strings" </s> add </s> remove "github.com/AdguardTeam/dnsproxy/upstream" "github.com/AdguardTeam/golibs/cache" </s> add </s> remove "github.com/AdguardTeam/golibs/stringutil" "github.com/miekg/dns" "golang.org/x/exp/slices" "golang.org/x/net/publicsuffix" </s> add </s> remove "bytes" "crypto/sha256" "encoding/binary" "encoding/hex" "fmt" "net" </s> add </s> remove "github.com/AdguardTeam/golibs/cache" </s> add "github.com/AdguardTeam/AdGuardHome/internal/filtering/hashprefix"
https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c
internal/filtering/safebrowsing.go
keep keep keep keep replace replace replace replace keep keep keep keep replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace keep keep
<mask> "github.com/AdguardTeam/AdGuardHome/internal/aghhttp" <mask> "github.com/AdguardTeam/dnsproxy/upstream" <mask> "github.com/AdguardTeam/golibs/cache" <mask> "github.com/AdguardTeam/golibs/log" <mask> "github.com/AdguardTeam/golibs/stringutil" <mask> "github.com/miekg/dns" <mask> "golang.org/x/exp/slices" <mask> "golang.org/x/net/publicsuffix" <mask> ) <mask> <mask> // Safe browsing and parental control methods. <mask> <mask> // TODO(a.garipov): Make configurable. <mask> const ( <mask> dnsTimeout = 3 * time.Second <mask> defaultSafebrowsingServer = `https://family.adguard-dns.com/dns-query` <mask> defaultParentalServer = `https://family.adguard-dns.com/dns-query` <mask> sbTXTSuffix = `sb.dns.adguard.com.` <mask> pcTXTSuffix = `pc.dns.adguard.com.` <mask> ) <mask> <mask> // SetParentalUpstream sets the parental upstream for *DNSFilter. <mask> // <mask> // TODO(e.burkov): Remove this in v1 API to forbid the direct access. <mask> func (d *DNSFilter) SetParentalUpstream(u upstream.Upstream) { <mask> d.parentalUpstream = u <mask> } <mask> <mask> // SetSafeBrowsingUpstream sets the safe browsing upstream for *DNSFilter. <mask> // <mask> // TODO(e.burkov): Remove this in v1 API to forbid the direct access. <mask> func (d *DNSFilter) SetSafeBrowsingUpstream(u upstream.Upstream) { <mask> d.safeBrowsingUpstream = u <mask> } <mask> <mask> func (d *DNSFilter) initSecurityServices() error { <mask> var err error <mask> d.safeBrowsingServer = defaultSafebrowsingServer <mask> d.parentalServer = defaultParentalServer <mask> opts := &upstream.Options{ <mask> Timeout: dnsTimeout, <mask> ServerIPAddrs: []net.IP{ <mask> {94, 140, 14, 15}, <mask> {94, 140, 15, 16}, <mask> net.ParseIP("2a10:50c0::bad1:ff"), <mask> net.ParseIP("2a10:50c0::bad2:ff"), <mask> }, <mask> } <mask> <mask> parUps, err := upstream.AddressToUpstream(d.parentalServer, opts) <mask> if err != nil { <mask> return fmt.Errorf("converting parental server: %w", err) <mask> } <mask> d.SetParentalUpstream(parUps) <mask> <mask> sbUps, err := upstream.AddressToUpstream(d.safeBrowsingServer, opts) <mask> if err != nil { <mask> return fmt.Errorf("converting safe browsing server: %w", err) <mask> } <mask> d.SetSafeBrowsingUpstream(sbUps) <mask> <mask> return nil <mask> } <mask> <mask> /* <mask> expire byte[4] <mask> hash byte[32] <mask> ... <mask> */ <mask> func (c *sbCtx) setCache(prefix, hashes []byte) { <mask> d := make([]byte, 4+len(hashes)) <mask> expire := uint(time.Now().Unix()) + c.cacheTime*60 <mask> binary.BigEndian.PutUint32(d[:4], uint32(expire)) <mask> copy(d[4:], hashes) <mask> c.cache.Set(prefix, d) <mask> log.Debug("%s: stored in cache: %v", c.svc, prefix) <mask> } <mask> <mask> // findInHash returns 32-byte hash if it's found in hashToHost. <mask> func (c *sbCtx) findInHash(val []byte) (hash32 [32]byte, found bool) { <mask> for i := 4; i < len(val); i += 32 { <mask> hash := val[i : i+32] <mask> <mask> copy(hash32[:], hash[0:32]) <mask> <mask> _, found = c.hashToHost[hash32] <mask> if found { <mask> return hash32, found <mask> } <mask> } <mask> <mask> return [32]byte{}, false <mask> } <mask> <mask> func (c *sbCtx) getCached() int { <mask> now := time.Now().Unix() <mask> hashesToRequest := map[[32]byte]string{} <mask> for k, v := range c.hashToHost { <mask> // nolint:looppointer // The subsilce is used for a safe cache lookup. <mask> val := c.cache.Get(k[0:2]) <mask> if val == nil || now >= int64(binary.BigEndian.Uint32(val)) { <mask> hashesToRequest[k] = v <mask> continue <mask> } <mask> if hash32, found := c.findInHash(val); found { <mask> log.Debug("%s: found in cache: %s: blocked by %v", c.svc, c.host, hash32) <mask> return 1 <mask> } <mask> } <mask> <mask> if len(hashesToRequest) == 0 { <mask> log.Debug("%s: found in cache: %s: not blocked", c.svc, c.host) <mask> return -1 <mask> } <mask> <mask> c.hashToHost = hashesToRequest <mask> return 0 <mask> } <mask> <mask> type sbCtx struct { <mask> host string <mask> svc string <mask> hashToHost map[[32]byte]string <mask> cache cache.Cache <mask> cacheTime uint <mask> } <mask> <mask> func hostnameToHashes(host string) map[[32]byte]string { <mask> hashes := map[[32]byte]string{} <mask> tld, icann := publicsuffix.PublicSuffix(host) <mask> if !icann { <mask> // private suffixes like cloudfront.net <mask> tld = "" <mask> } <mask> curhost := host <mask> <mask> nDots := 0 <mask> for i := len(curhost) - 1; i >= 0; i-- { <mask> if curhost[i] == '.' { <mask> nDots++ <mask> if nDots == 4 { <mask> curhost = curhost[i+1:] // "xxx.a.b.c.d" -> "a.b.c.d" <mask> break <mask> } <mask> } <mask> } <mask> <mask> for { <mask> if curhost == "" { <mask> // we've reached end of string <mask> break <mask> } <mask> if tld != "" && curhost == tld { <mask> // we've reached the TLD, don't hash it <mask> break <mask> } <mask> <mask> sum := sha256.Sum256([]byte(curhost)) <mask> hashes[sum] = curhost <mask> <mask> pos := strings.IndexByte(curhost, byte('.')) <mask> if pos < 0 { <mask> break <mask> } <mask> curhost = curhost[pos+1:] <mask> } <mask> return hashes <mask> } <mask> <mask> // convert hash array to string <mask> func (c *sbCtx) getQuestion() string { <mask> b := &strings.Builder{} <mask> <mask> for hash := range c.hashToHost { <mask> // nolint:looppointer // The subsilce is used for safe hex encoding. <mask> stringutil.WriteToBuilder(b, hex.EncodeToString(hash[0:2]), ".") <mask> } <mask> <mask> if c.svc == "SafeBrowsing" { <mask> stringutil.WriteToBuilder(b, sbTXTSuffix) <mask> <mask> return b.String() <mask> } <mask> <mask> stringutil.WriteToBuilder(b, pcTXTSuffix) <mask> <mask> return b.String() <mask> } <mask> <mask> // Find the target hash in TXT response <mask> func (c *sbCtx) processTXT(resp *dns.Msg) (bool, [][]byte) { <mask> matched := false <mask> hashes := [][]byte{} <mask> for _, a := range resp.Answer { <mask> txt, ok := a.(*dns.TXT) <mask> if !ok { <mask> continue <mask> } <mask> log.Debug("%s: received hashes for %s: %v", c.svc, c.host, txt.Txt) <mask> <mask> for _, t := range txt.Txt { <mask> if len(t) != 32*2 { <mask> continue <mask> } <mask> hash, err := hex.DecodeString(t) <mask> if err != nil { <mask> continue <mask> } <mask> <mask> hashes = append(hashes, hash) <mask> <mask> if !matched { <mask> var hash32 [32]byte <mask> copy(hash32[:], hash) <mask> <mask> var hashHost string <mask> hashHost, ok = c.hashToHost[hash32] <mask> if ok { <mask> log.Debug("%s: matched %s by %s/%s", c.svc, c.host, hashHost, t) <mask> matched = true <mask> } <mask> } <mask> } <mask> } <mask> <mask> return matched, hashes <mask> } <mask> <mask> func (c *sbCtx) storeCache(hashes [][]byte) { <mask> slices.SortFunc(hashes, func(a, b []byte) (sortsBefore bool) { <mask> return bytes.Compare(a, b) == -1 <mask> }) <mask> <mask> var curData []byte <mask> var prevPrefix []byte <mask> for i, hash := range hashes { <mask> // nolint:looppointer // The subsilce is used for a safe comparison. <mask> if !bytes.Equal(hash[0:2], prevPrefix) { <mask> if i != 0 { <mask> c.setCache(prevPrefix, curData) <mask> curData = nil <mask> } <mask> prevPrefix = hashes[i][0:2] <mask> } <mask> curData = append(curData, hash...) <mask> } <mask> <mask> if len(prevPrefix) != 0 { <mask> c.setCache(prevPrefix, curData) <mask> } <mask> <mask> for hash := range c.hashToHost { <mask> // nolint:looppointer // The subsilce is used for a safe cache lookup. <mask> prefix := hash[0:2] <mask> val := c.cache.Get(prefix) <mask> if val == nil { <mask> c.setCache(prefix, nil) <mask> } <mask> } <mask> } <mask> <mask> func check(c *sbCtx, r Result, u upstream.Upstream) (Result, error) { <mask> c.hashToHost = hostnameToHashes(c.host) <mask> switch c.getCached() { <mask> case -1: <mask> return Result{}, nil <mask> case 1: <mask> return r, nil <mask> } <mask> <mask> question := c.getQuestion() <mask> <mask> log.Tracef("%s: checking %s: %s", c.svc, c.host, question) <mask> req := (&dns.Msg{}).SetQuestion(question, dns.TypeTXT) <mask> <mask> resp, err := u.Exchange(req) <mask> if err != nil { <mask> return Result{}, err <mask> } <mask> <mask> matched, receivedHashes := c.processTXT(resp) <mask> <mask> c.storeCache(receivedHashes) <mask> if matched { <mask> return r, nil <mask> } <mask> <mask> return Result{}, nil <mask> } <mask> <mask> // TODO(a.garipov): Unify with checkParental. <mask> func (d *DNSFilter) checkSafeBrowsing( </s> Pull request 1837: AG-21462-imp-safebrowsing-parental Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master Squashed commit of the following: commit 85016d4f1105e21a407efade0bd45b8362808061 Merge: 0e61edade 620b51e3e Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 16:36:30 2023 +0300 Merge branch 'master' into AG-21462-imp-safebrowsing-parental commit 0e61edadeff34f6305e941c1db94575c82f238d9 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 14:51:37 2023 +0300 filtering: imp tests commit 994255514cc0f67dfe33d5a0892432e8924d1e36 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:13:19 2023 +0300 filtering: fix typo commit 96d1069573171538333330d6af94ef0f4208a9c4 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:00:18 2023 +0300 filtering: imp code more commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 19:13:26 2023 +0300 all: add todo commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 14:36:08 2023 +0300 all: imp code more commit b6e734ccbeda82669023f6578481260b7c1f7161 Author: Stanislav Chzhen <[email protected]> Date: Tue Apr 25 15:01:56 2023 +0300 filtering: imp code commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 20:06:36 2023 +0300 all: imp code commit 49fa6e587052a40bb431fea457701ee860493527 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 14:57:19 2023 +0300 all: rm safe browsing ctx commit bbcb66cb03e18fa875e3c33cf16295892739e507 Author: Stanislav Chzhen <[email protected]> Date: Fri Apr 21 17:54:18 2023 +0300 filtering: add cache item commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 18:43:02 2023 +0300 filtering: fix hashes commit 153fec46270212af03f3631bfb42c5d680c4e142 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 16:15:15 2023 +0300 filtering: add test cases commit 09372f92bbb1fc082f1b1283594ee589100209c5 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 15:38:05 2023 +0300 filtering: imp code commit 466bc26d524ea6d1c3efb33692a7785d39e491ca Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 18:38:40 2023 +0300 filtering: add tests commit 24365ecf8c60512fdac65833ee603c80864ae018 Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 11:38:57 2023 +0300 filtering: add hashprefix
https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c
internal/filtering/safebrowsing.go
keep keep keep keep replace replace replace replace replace replace replace keep keep keep keep keep
<mask> timer := log.StartTimer() <mask> defer timer.LogElapsed("safebrowsing lookup for %q", host) <mask> } <mask> <mask> sctx := &sbCtx{ <mask> host: host, <mask> svc: "SafeBrowsing", <mask> cache: d.safebrowsingCache, <mask> cacheTime: d.Config.CacheTime, <mask> } <mask> <mask> res = Result{ <mask> Rules: []*ResultRule{{ <mask> Text: "adguard-malware-shavar", <mask> FilterListID: SafeBrowsingListID, <mask> }}, </s> Pull request 1837: AG-21462-imp-safebrowsing-parental Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master Squashed commit of the following: commit 85016d4f1105e21a407efade0bd45b8362808061 Merge: 0e61edade 620b51e3e Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 16:36:30 2023 +0300 Merge branch 'master' into AG-21462-imp-safebrowsing-parental commit 0e61edadeff34f6305e941c1db94575c82f238d9 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 14:51:37 2023 +0300 filtering: imp tests commit 994255514cc0f67dfe33d5a0892432e8924d1e36 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:13:19 2023 +0300 filtering: fix typo commit 96d1069573171538333330d6af94ef0f4208a9c4 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:00:18 2023 +0300 filtering: imp code more commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 19:13:26 2023 +0300 all: add todo commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 14:36:08 2023 +0300 all: imp code more commit b6e734ccbeda82669023f6578481260b7c1f7161 Author: Stanislav Chzhen <[email protected]> Date: Tue Apr 25 15:01:56 2023 +0300 filtering: imp code commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 20:06:36 2023 +0300 all: imp code commit 49fa6e587052a40bb431fea457701ee860493527 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 14:57:19 2023 +0300 all: rm safe browsing ctx commit bbcb66cb03e18fa875e3c33cf16295892739e507 Author: Stanislav Chzhen <[email protected]> Date: Fri Apr 21 17:54:18 2023 +0300 filtering: add cache item commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 18:43:02 2023 +0300 filtering: fix hashes commit 153fec46270212af03f3631bfb42c5d680c4e142 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 16:15:15 2023 +0300 filtering: add test cases commit 09372f92bbb1fc082f1b1283594ee589100209c5 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 15:38:05 2023 +0300 filtering: imp code commit 466bc26d524ea6d1c3efb33692a7785d39e491ca Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 18:38:40 2023 +0300 filtering: add tests commit 24365ecf8c60512fdac65833ee603c80864ae018 Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 11:38:57 2023 +0300 filtering: add hashprefix </s> remove sctx := &sbCtx{ host: host, svc: "Parental", cache: d.parentalCache, cacheTime: d.Config.CacheTime, } </s> add </s> remove func purgeCaches(d *DNSFilter) { for _, c := range []cache.Cache{ d.safebrowsingCache, d.parentalCache, } { if c != nil { c.Clear() } } } </s> add </s> remove d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true)) </s> add </s> remove d, setts := newForTest(t, &Config{ParentalEnabled: true}, nil) </s> add d, setts := newForTest(t, &Config{ ParentalEnabled: true, ParentalControlChecker: newChecker(pcBlocked), }, nil) </s> remove d.SetParentalUpstream(aghtest.NewBlockUpstream(pcBlocked, true)) </s> add </s> remove // TODO(a.garipov): Make configurable. const ( dnsTimeout = 3 * time.Second defaultSafebrowsingServer = `https://family.adguard-dns.com/dns-query` defaultParentalServer = `https://family.adguard-dns.com/dns-query` sbTXTSuffix = `sb.dns.adguard.com.` pcTXTSuffix = `pc.dns.adguard.com.` ) // SetParentalUpstream sets the parental upstream for *DNSFilter. // // TODO(e.burkov): Remove this in v1 API to forbid the direct access. func (d *DNSFilter) SetParentalUpstream(u upstream.Upstream) { d.parentalUpstream = u } // SetSafeBrowsingUpstream sets the safe browsing upstream for *DNSFilter. // // TODO(e.burkov): Remove this in v1 API to forbid the direct access. func (d *DNSFilter) SetSafeBrowsingUpstream(u upstream.Upstream) { d.safeBrowsingUpstream = u } func (d *DNSFilter) initSecurityServices() error { var err error d.safeBrowsingServer = defaultSafebrowsingServer d.parentalServer = defaultParentalServer opts := &upstream.Options{ Timeout: dnsTimeout, ServerIPAddrs: []net.IP{ {94, 140, 14, 15}, {94, 140, 15, 16}, net.ParseIP("2a10:50c0::bad1:ff"), net.ParseIP("2a10:50c0::bad2:ff"), }, } parUps, err := upstream.AddressToUpstream(d.parentalServer, opts) if err != nil { return fmt.Errorf("converting parental server: %w", err) } d.SetParentalUpstream(parUps) sbUps, err := upstream.AddressToUpstream(d.safeBrowsingServer, opts) if err != nil { return fmt.Errorf("converting safe browsing server: %w", err) } d.SetSafeBrowsingUpstream(sbUps) return nil } /* expire byte[4] hash byte[32] ... */ func (c *sbCtx) setCache(prefix, hashes []byte) { d := make([]byte, 4+len(hashes)) expire := uint(time.Now().Unix()) + c.cacheTime*60 binary.BigEndian.PutUint32(d[:4], uint32(expire)) copy(d[4:], hashes) c.cache.Set(prefix, d) log.Debug("%s: stored in cache: %v", c.svc, prefix) } // findInHash returns 32-byte hash if it's found in hashToHost. func (c *sbCtx) findInHash(val []byte) (hash32 [32]byte, found bool) { for i := 4; i < len(val); i += 32 { hash := val[i : i+32] copy(hash32[:], hash[0:32]) _, found = c.hashToHost[hash32] if found { return hash32, found } } return [32]byte{}, false } func (c *sbCtx) getCached() int { now := time.Now().Unix() hashesToRequest := map[[32]byte]string{} for k, v := range c.hashToHost { // nolint:looppointer // The subsilce is used for a safe cache lookup. val := c.cache.Get(k[0:2]) if val == nil || now >= int64(binary.BigEndian.Uint32(val)) { hashesToRequest[k] = v continue } if hash32, found := c.findInHash(val); found { log.Debug("%s: found in cache: %s: blocked by %v", c.svc, c.host, hash32) return 1 } } if len(hashesToRequest) == 0 { log.Debug("%s: found in cache: %s: not blocked", c.svc, c.host) return -1 } c.hashToHost = hashesToRequest return 0 } type sbCtx struct { host string svc string hashToHost map[[32]byte]string cache cache.Cache cacheTime uint } func hostnameToHashes(host string) map[[32]byte]string { hashes := map[[32]byte]string{} tld, icann := publicsuffix.PublicSuffix(host) if !icann { // private suffixes like cloudfront.net tld = "" } curhost := host nDots := 0 for i := len(curhost) - 1; i >= 0; i-- { if curhost[i] == '.' { nDots++ if nDots == 4 { curhost = curhost[i+1:] // "xxx.a.b.c.d" -> "a.b.c.d" break } } } for { if curhost == "" { // we've reached end of string break } if tld != "" && curhost == tld { // we've reached the TLD, don't hash it break } sum := sha256.Sum256([]byte(curhost)) hashes[sum] = curhost pos := strings.IndexByte(curhost, byte('.')) if pos < 0 { break } curhost = curhost[pos+1:] } return hashes } // convert hash array to string func (c *sbCtx) getQuestion() string { b := &strings.Builder{} for hash := range c.hashToHost { // nolint:looppointer // The subsilce is used for safe hex encoding. stringutil.WriteToBuilder(b, hex.EncodeToString(hash[0:2]), ".") } if c.svc == "SafeBrowsing" { stringutil.WriteToBuilder(b, sbTXTSuffix) return b.String() } stringutil.WriteToBuilder(b, pcTXTSuffix) return b.String() } // Find the target hash in TXT response func (c *sbCtx) processTXT(resp *dns.Msg) (bool, [][]byte) { matched := false hashes := [][]byte{} for _, a := range resp.Answer { txt, ok := a.(*dns.TXT) if !ok { continue } log.Debug("%s: received hashes for %s: %v", c.svc, c.host, txt.Txt) for _, t := range txt.Txt { if len(t) != 32*2 { continue } hash, err := hex.DecodeString(t) if err != nil { continue } hashes = append(hashes, hash) if !matched { var hash32 [32]byte copy(hash32[:], hash) var hashHost string hashHost, ok = c.hashToHost[hash32] if ok { log.Debug("%s: matched %s by %s/%s", c.svc, c.host, hashHost, t) matched = true } } } } return matched, hashes } func (c *sbCtx) storeCache(hashes [][]byte) { slices.SortFunc(hashes, func(a, b []byte) (sortsBefore bool) { return bytes.Compare(a, b) == -1 }) var curData []byte var prevPrefix []byte for i, hash := range hashes { // nolint:looppointer // The subsilce is used for a safe comparison. if !bytes.Equal(hash[0:2], prevPrefix) { if i != 0 { c.setCache(prevPrefix, curData) curData = nil } prevPrefix = hashes[i][0:2] } curData = append(curData, hash...) } if len(prevPrefix) != 0 { c.setCache(prevPrefix, curData) } for hash := range c.hashToHost { // nolint:looppointer // The subsilce is used for a safe cache lookup. prefix := hash[0:2] val := c.cache.Get(prefix) if val == nil { c.setCache(prefix, nil) } } } func check(c *sbCtx, r Result, u upstream.Upstream) (Result, error) { c.hashToHost = hostnameToHashes(c.host) switch c.getCached() { case -1: return Result{}, nil case 1: return r, nil } question := c.getQuestion() log.Tracef("%s: checking %s: %s", c.svc, c.host, question) req := (&dns.Msg{}).SetQuestion(question, dns.TypeTXT) resp, err := u.Exchange(req) if err != nil { return Result{}, err } matched, receivedHashes := c.processTXT(resp) c.storeCache(receivedHashes) if matched { return r, nil } return Result{}, nil } </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c
internal/filtering/safebrowsing.go
keep keep keep keep replace keep keep keep keep keep
<mask> Reason: FilteredSafeBrowsing, <mask> IsFiltered: true, <mask> } <mask> <mask> return check(sctx, res, d.safeBrowsingUpstream) <mask> } <mask> <mask> // TODO(a.garipov): Unify with checkSafeBrowsing. <mask> func (d *DNSFilter) checkParental( <mask> host string, </s> Pull request 1837: AG-21462-imp-safebrowsing-parental Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master Squashed commit of the following: commit 85016d4f1105e21a407efade0bd45b8362808061 Merge: 0e61edade 620b51e3e Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 16:36:30 2023 +0300 Merge branch 'master' into AG-21462-imp-safebrowsing-parental commit 0e61edadeff34f6305e941c1db94575c82f238d9 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 14:51:37 2023 +0300 filtering: imp tests commit 994255514cc0f67dfe33d5a0892432e8924d1e36 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:13:19 2023 +0300 filtering: fix typo commit 96d1069573171538333330d6af94ef0f4208a9c4 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:00:18 2023 +0300 filtering: imp code more commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 19:13:26 2023 +0300 all: add todo commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 14:36:08 2023 +0300 all: imp code more commit b6e734ccbeda82669023f6578481260b7c1f7161 Author: Stanislav Chzhen <[email protected]> Date: Tue Apr 25 15:01:56 2023 +0300 filtering: imp code commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 20:06:36 2023 +0300 all: imp code commit 49fa6e587052a40bb431fea457701ee860493527 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 14:57:19 2023 +0300 all: rm safe browsing ctx commit bbcb66cb03e18fa875e3c33cf16295892739e507 Author: Stanislav Chzhen <[email protected]> Date: Fri Apr 21 17:54:18 2023 +0300 filtering: add cache item commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 18:43:02 2023 +0300 filtering: fix hashes commit 153fec46270212af03f3631bfb42c5d680c4e142 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 16:15:15 2023 +0300 filtering: add test cases commit 09372f92bbb1fc082f1b1283594ee589100209c5 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 15:38:05 2023 +0300 filtering: imp code commit 466bc26d524ea6d1c3efb33692a7785d39e491ca Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 18:38:40 2023 +0300 filtering: add tests commit 24365ecf8c60512fdac65833ee603c80864ae018 Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 11:38:57 2023 +0300 filtering: add hashprefix </s> remove return check(sctx, res, d.parentalUpstream) </s> add block, err := d.parentalControlChecker.Check(host) if !block || err != nil { return Result{}, err } return res, nil </s> add func newChecker(host string) Checker { return hashprefix.New(&hashprefix.Config{ CacheTime: 10, CacheSize: 100000, Upstream: aghtest.NewBlockUpstream(host, true), }) } </s> remove purgeCaches(f) </s> add </s> remove // TODO(a.garipov): Make configurable. const ( dnsTimeout = 3 * time.Second defaultSafebrowsingServer = `https://family.adguard-dns.com/dns-query` defaultParentalServer = `https://family.adguard-dns.com/dns-query` sbTXTSuffix = `sb.dns.adguard.com.` pcTXTSuffix = `pc.dns.adguard.com.` ) // SetParentalUpstream sets the parental upstream for *DNSFilter. // // TODO(e.burkov): Remove this in v1 API to forbid the direct access. func (d *DNSFilter) SetParentalUpstream(u upstream.Upstream) { d.parentalUpstream = u } // SetSafeBrowsingUpstream sets the safe browsing upstream for *DNSFilter. // // TODO(e.burkov): Remove this in v1 API to forbid the direct access. func (d *DNSFilter) SetSafeBrowsingUpstream(u upstream.Upstream) { d.safeBrowsingUpstream = u } func (d *DNSFilter) initSecurityServices() error { var err error d.safeBrowsingServer = defaultSafebrowsingServer d.parentalServer = defaultParentalServer opts := &upstream.Options{ Timeout: dnsTimeout, ServerIPAddrs: []net.IP{ {94, 140, 14, 15}, {94, 140, 15, 16}, net.ParseIP("2a10:50c0::bad1:ff"), net.ParseIP("2a10:50c0::bad2:ff"), }, } parUps, err := upstream.AddressToUpstream(d.parentalServer, opts) if err != nil { return fmt.Errorf("converting parental server: %w", err) } d.SetParentalUpstream(parUps) sbUps, err := upstream.AddressToUpstream(d.safeBrowsingServer, opts) if err != nil { return fmt.Errorf("converting safe browsing server: %w", err) } d.SetSafeBrowsingUpstream(sbUps) return nil } /* expire byte[4] hash byte[32] ... */ func (c *sbCtx) setCache(prefix, hashes []byte) { d := make([]byte, 4+len(hashes)) expire := uint(time.Now().Unix()) + c.cacheTime*60 binary.BigEndian.PutUint32(d[:4], uint32(expire)) copy(d[4:], hashes) c.cache.Set(prefix, d) log.Debug("%s: stored in cache: %v", c.svc, prefix) } // findInHash returns 32-byte hash if it's found in hashToHost. func (c *sbCtx) findInHash(val []byte) (hash32 [32]byte, found bool) { for i := 4; i < len(val); i += 32 { hash := val[i : i+32] copy(hash32[:], hash[0:32]) _, found = c.hashToHost[hash32] if found { return hash32, found } } return [32]byte{}, false } func (c *sbCtx) getCached() int { now := time.Now().Unix() hashesToRequest := map[[32]byte]string{} for k, v := range c.hashToHost { // nolint:looppointer // The subsilce is used for a safe cache lookup. val := c.cache.Get(k[0:2]) if val == nil || now >= int64(binary.BigEndian.Uint32(val)) { hashesToRequest[k] = v continue } if hash32, found := c.findInHash(val); found { log.Debug("%s: found in cache: %s: blocked by %v", c.svc, c.host, hash32) return 1 } } if len(hashesToRequest) == 0 { log.Debug("%s: found in cache: %s: not blocked", c.svc, c.host) return -1 } c.hashToHost = hashesToRequest return 0 } type sbCtx struct { host string svc string hashToHost map[[32]byte]string cache cache.Cache cacheTime uint } func hostnameToHashes(host string) map[[32]byte]string { hashes := map[[32]byte]string{} tld, icann := publicsuffix.PublicSuffix(host) if !icann { // private suffixes like cloudfront.net tld = "" } curhost := host nDots := 0 for i := len(curhost) - 1; i >= 0; i-- { if curhost[i] == '.' { nDots++ if nDots == 4 { curhost = curhost[i+1:] // "xxx.a.b.c.d" -> "a.b.c.d" break } } } for { if curhost == "" { // we've reached end of string break } if tld != "" && curhost == tld { // we've reached the TLD, don't hash it break } sum := sha256.Sum256([]byte(curhost)) hashes[sum] = curhost pos := strings.IndexByte(curhost, byte('.')) if pos < 0 { break } curhost = curhost[pos+1:] } return hashes } // convert hash array to string func (c *sbCtx) getQuestion() string { b := &strings.Builder{} for hash := range c.hashToHost { // nolint:looppointer // The subsilce is used for safe hex encoding. stringutil.WriteToBuilder(b, hex.EncodeToString(hash[0:2]), ".") } if c.svc == "SafeBrowsing" { stringutil.WriteToBuilder(b, sbTXTSuffix) return b.String() } stringutil.WriteToBuilder(b, pcTXTSuffix) return b.String() } // Find the target hash in TXT response func (c *sbCtx) processTXT(resp *dns.Msg) (bool, [][]byte) { matched := false hashes := [][]byte{} for _, a := range resp.Answer { txt, ok := a.(*dns.TXT) if !ok { continue } log.Debug("%s: received hashes for %s: %v", c.svc, c.host, txt.Txt) for _, t := range txt.Txt { if len(t) != 32*2 { continue } hash, err := hex.DecodeString(t) if err != nil { continue } hashes = append(hashes, hash) if !matched { var hash32 [32]byte copy(hash32[:], hash) var hashHost string hashHost, ok = c.hashToHost[hash32] if ok { log.Debug("%s: matched %s by %s/%s", c.svc, c.host, hashHost, t) matched = true } } } } return matched, hashes } func (c *sbCtx) storeCache(hashes [][]byte) { slices.SortFunc(hashes, func(a, b []byte) (sortsBefore bool) { return bytes.Compare(a, b) == -1 }) var curData []byte var prevPrefix []byte for i, hash := range hashes { // nolint:looppointer // The subsilce is used for a safe comparison. if !bytes.Equal(hash[0:2], prevPrefix) { if i != 0 { c.setCache(prevPrefix, curData) curData = nil } prevPrefix = hashes[i][0:2] } curData = append(curData, hash...) } if len(prevPrefix) != 0 { c.setCache(prevPrefix, curData) } for hash := range c.hashToHost { // nolint:looppointer // The subsilce is used for a safe cache lookup. prefix := hash[0:2] val := c.cache.Get(prefix) if val == nil { c.setCache(prefix, nil) } } } func check(c *sbCtx, r Result, u upstream.Upstream) (Result, error) { c.hashToHost = hostnameToHashes(c.host) switch c.getCached() { case -1: return Result{}, nil case 1: return r, nil } question := c.getQuestion() log.Tracef("%s: checking %s: %s", c.svc, c.host, question) req := (&dns.Msg{}).SetQuestion(question, dns.TypeTXT) resp, err := u.Exchange(req) if err != nil { return Result{}, err } matched, receivedHashes := c.processTXT(resp) c.storeCache(receivedHashes) if matched { return r, nil } return Result{}, nil } </s> add </s> remove func purgeCaches(d *DNSFilter) { for _, c := range []cache.Cache{ d.safebrowsingCache, d.parentalCache, } { if c != nil { c.Clear() } } } </s> add </s> add // Checker is used for safe browsing or parental control hash-prefix filtering. type Checker interface { // Check returns true if request for the host should be blocked. Check(host string) (block bool, err error) }
https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c
internal/filtering/safebrowsing.go
keep keep keep keep replace replace replace replace replace replace replace keep keep keep keep keep
<mask> timer := log.StartTimer() <mask> defer timer.LogElapsed("parental lookup for %q", host) <mask> } <mask> <mask> sctx := &sbCtx{ <mask> host: host, <mask> svc: "Parental", <mask> cache: d.parentalCache, <mask> cacheTime: d.Config.CacheTime, <mask> } <mask> <mask> res = Result{ <mask> Rules: []*ResultRule{{ <mask> Text: "parental CATEGORY_BLACKLISTED", <mask> FilterListID: ParentalListID, <mask> }}, </s> Pull request 1837: AG-21462-imp-safebrowsing-parental Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master Squashed commit of the following: commit 85016d4f1105e21a407efade0bd45b8362808061 Merge: 0e61edade 620b51e3e Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 16:36:30 2023 +0300 Merge branch 'master' into AG-21462-imp-safebrowsing-parental commit 0e61edadeff34f6305e941c1db94575c82f238d9 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 14:51:37 2023 +0300 filtering: imp tests commit 994255514cc0f67dfe33d5a0892432e8924d1e36 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:13:19 2023 +0300 filtering: fix typo commit 96d1069573171538333330d6af94ef0f4208a9c4 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:00:18 2023 +0300 filtering: imp code more commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 19:13:26 2023 +0300 all: add todo commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 14:36:08 2023 +0300 all: imp code more commit b6e734ccbeda82669023f6578481260b7c1f7161 Author: Stanislav Chzhen <[email protected]> Date: Tue Apr 25 15:01:56 2023 +0300 filtering: imp code commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 20:06:36 2023 +0300 all: imp code commit 49fa6e587052a40bb431fea457701ee860493527 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 14:57:19 2023 +0300 all: rm safe browsing ctx commit bbcb66cb03e18fa875e3c33cf16295892739e507 Author: Stanislav Chzhen <[email protected]> Date: Fri Apr 21 17:54:18 2023 +0300 filtering: add cache item commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 18:43:02 2023 +0300 filtering: fix hashes commit 153fec46270212af03f3631bfb42c5d680c4e142 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 16:15:15 2023 +0300 filtering: add test cases commit 09372f92bbb1fc082f1b1283594ee589100209c5 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 15:38:05 2023 +0300 filtering: imp code commit 466bc26d524ea6d1c3efb33692a7785d39e491ca Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 18:38:40 2023 +0300 filtering: add tests commit 24365ecf8c60512fdac65833ee603c80864ae018 Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 11:38:57 2023 +0300 filtering: add hashprefix </s> remove sctx := &sbCtx{ host: host, svc: "SafeBrowsing", cache: d.safebrowsingCache, cacheTime: d.Config.CacheTime, } </s> add </s> remove func purgeCaches(d *DNSFilter) { for _, c := range []cache.Cache{ d.safebrowsingCache, d.parentalCache, } { if c != nil { c.Clear() } } } </s> add </s> remove d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true)) </s> add </s> remove d, setts := newForTest(t, &Config{ParentalEnabled: true}, nil) </s> add d, setts := newForTest(t, &Config{ ParentalEnabled: true, ParentalControlChecker: newChecker(pcBlocked), }, nil) </s> remove d.SetParentalUpstream(aghtest.NewBlockUpstream(pcBlocked, true)) </s> add </s> remove // TODO(a.garipov): Make configurable. const ( dnsTimeout = 3 * time.Second defaultSafebrowsingServer = `https://family.adguard-dns.com/dns-query` defaultParentalServer = `https://family.adguard-dns.com/dns-query` sbTXTSuffix = `sb.dns.adguard.com.` pcTXTSuffix = `pc.dns.adguard.com.` ) // SetParentalUpstream sets the parental upstream for *DNSFilter. // // TODO(e.burkov): Remove this in v1 API to forbid the direct access. func (d *DNSFilter) SetParentalUpstream(u upstream.Upstream) { d.parentalUpstream = u } // SetSafeBrowsingUpstream sets the safe browsing upstream for *DNSFilter. // // TODO(e.burkov): Remove this in v1 API to forbid the direct access. func (d *DNSFilter) SetSafeBrowsingUpstream(u upstream.Upstream) { d.safeBrowsingUpstream = u } func (d *DNSFilter) initSecurityServices() error { var err error d.safeBrowsingServer = defaultSafebrowsingServer d.parentalServer = defaultParentalServer opts := &upstream.Options{ Timeout: dnsTimeout, ServerIPAddrs: []net.IP{ {94, 140, 14, 15}, {94, 140, 15, 16}, net.ParseIP("2a10:50c0::bad1:ff"), net.ParseIP("2a10:50c0::bad2:ff"), }, } parUps, err := upstream.AddressToUpstream(d.parentalServer, opts) if err != nil { return fmt.Errorf("converting parental server: %w", err) } d.SetParentalUpstream(parUps) sbUps, err := upstream.AddressToUpstream(d.safeBrowsingServer, opts) if err != nil { return fmt.Errorf("converting safe browsing server: %w", err) } d.SetSafeBrowsingUpstream(sbUps) return nil } /* expire byte[4] hash byte[32] ... */ func (c *sbCtx) setCache(prefix, hashes []byte) { d := make([]byte, 4+len(hashes)) expire := uint(time.Now().Unix()) + c.cacheTime*60 binary.BigEndian.PutUint32(d[:4], uint32(expire)) copy(d[4:], hashes) c.cache.Set(prefix, d) log.Debug("%s: stored in cache: %v", c.svc, prefix) } // findInHash returns 32-byte hash if it's found in hashToHost. func (c *sbCtx) findInHash(val []byte) (hash32 [32]byte, found bool) { for i := 4; i < len(val); i += 32 { hash := val[i : i+32] copy(hash32[:], hash[0:32]) _, found = c.hashToHost[hash32] if found { return hash32, found } } return [32]byte{}, false } func (c *sbCtx) getCached() int { now := time.Now().Unix() hashesToRequest := map[[32]byte]string{} for k, v := range c.hashToHost { // nolint:looppointer // The subsilce is used for a safe cache lookup. val := c.cache.Get(k[0:2]) if val == nil || now >= int64(binary.BigEndian.Uint32(val)) { hashesToRequest[k] = v continue } if hash32, found := c.findInHash(val); found { log.Debug("%s: found in cache: %s: blocked by %v", c.svc, c.host, hash32) return 1 } } if len(hashesToRequest) == 0 { log.Debug("%s: found in cache: %s: not blocked", c.svc, c.host) return -1 } c.hashToHost = hashesToRequest return 0 } type sbCtx struct { host string svc string hashToHost map[[32]byte]string cache cache.Cache cacheTime uint } func hostnameToHashes(host string) map[[32]byte]string { hashes := map[[32]byte]string{} tld, icann := publicsuffix.PublicSuffix(host) if !icann { // private suffixes like cloudfront.net tld = "" } curhost := host nDots := 0 for i := len(curhost) - 1; i >= 0; i-- { if curhost[i] == '.' { nDots++ if nDots == 4 { curhost = curhost[i+1:] // "xxx.a.b.c.d" -> "a.b.c.d" break } } } for { if curhost == "" { // we've reached end of string break } if tld != "" && curhost == tld { // we've reached the TLD, don't hash it break } sum := sha256.Sum256([]byte(curhost)) hashes[sum] = curhost pos := strings.IndexByte(curhost, byte('.')) if pos < 0 { break } curhost = curhost[pos+1:] } return hashes } // convert hash array to string func (c *sbCtx) getQuestion() string { b := &strings.Builder{} for hash := range c.hashToHost { // nolint:looppointer // The subsilce is used for safe hex encoding. stringutil.WriteToBuilder(b, hex.EncodeToString(hash[0:2]), ".") } if c.svc == "SafeBrowsing" { stringutil.WriteToBuilder(b, sbTXTSuffix) return b.String() } stringutil.WriteToBuilder(b, pcTXTSuffix) return b.String() } // Find the target hash in TXT response func (c *sbCtx) processTXT(resp *dns.Msg) (bool, [][]byte) { matched := false hashes := [][]byte{} for _, a := range resp.Answer { txt, ok := a.(*dns.TXT) if !ok { continue } log.Debug("%s: received hashes for %s: %v", c.svc, c.host, txt.Txt) for _, t := range txt.Txt { if len(t) != 32*2 { continue } hash, err := hex.DecodeString(t) if err != nil { continue } hashes = append(hashes, hash) if !matched { var hash32 [32]byte copy(hash32[:], hash) var hashHost string hashHost, ok = c.hashToHost[hash32] if ok { log.Debug("%s: matched %s by %s/%s", c.svc, c.host, hashHost, t) matched = true } } } } return matched, hashes } func (c *sbCtx) storeCache(hashes [][]byte) { slices.SortFunc(hashes, func(a, b []byte) (sortsBefore bool) { return bytes.Compare(a, b) == -1 }) var curData []byte var prevPrefix []byte for i, hash := range hashes { // nolint:looppointer // The subsilce is used for a safe comparison. if !bytes.Equal(hash[0:2], prevPrefix) { if i != 0 { c.setCache(prevPrefix, curData) curData = nil } prevPrefix = hashes[i][0:2] } curData = append(curData, hash...) } if len(prevPrefix) != 0 { c.setCache(prevPrefix, curData) } for hash := range c.hashToHost { // nolint:looppointer // The subsilce is used for a safe cache lookup. prefix := hash[0:2] val := c.cache.Get(prefix) if val == nil { c.setCache(prefix, nil) } } } func check(c *sbCtx, r Result, u upstream.Upstream) (Result, error) { c.hashToHost = hostnameToHashes(c.host) switch c.getCached() { case -1: return Result{}, nil case 1: return r, nil } question := c.getQuestion() log.Tracef("%s: checking %s: %s", c.svc, c.host, question) req := (&dns.Msg{}).SetQuestion(question, dns.TypeTXT) resp, err := u.Exchange(req) if err != nil { return Result{}, err } matched, receivedHashes := c.processTXT(resp) c.storeCache(receivedHashes) if matched { return r, nil } return Result{}, nil } </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c
internal/filtering/safebrowsing.go
keep keep keep keep replace keep keep keep keep keep
<mask> Reason: FilteredParental, <mask> IsFiltered: true, <mask> } <mask> <mask> return check(sctx, res, d.parentalUpstream) <mask> } <mask> <mask> // setProtectedBool sets the value of a boolean pointer under a lock. l must <mask> // protect the value under ptr. <mask> // </s> Pull request 1837: AG-21462-imp-safebrowsing-parental Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master Squashed commit of the following: commit 85016d4f1105e21a407efade0bd45b8362808061 Merge: 0e61edade 620b51e3e Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 16:36:30 2023 +0300 Merge branch 'master' into AG-21462-imp-safebrowsing-parental commit 0e61edadeff34f6305e941c1db94575c82f238d9 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 14:51:37 2023 +0300 filtering: imp tests commit 994255514cc0f67dfe33d5a0892432e8924d1e36 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:13:19 2023 +0300 filtering: fix typo commit 96d1069573171538333330d6af94ef0f4208a9c4 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:00:18 2023 +0300 filtering: imp code more commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 19:13:26 2023 +0300 all: add todo commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 14:36:08 2023 +0300 all: imp code more commit b6e734ccbeda82669023f6578481260b7c1f7161 Author: Stanislav Chzhen <[email protected]> Date: Tue Apr 25 15:01:56 2023 +0300 filtering: imp code commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 20:06:36 2023 +0300 all: imp code commit 49fa6e587052a40bb431fea457701ee860493527 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 14:57:19 2023 +0300 all: rm safe browsing ctx commit bbcb66cb03e18fa875e3c33cf16295892739e507 Author: Stanislav Chzhen <[email protected]> Date: Fri Apr 21 17:54:18 2023 +0300 filtering: add cache item commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 18:43:02 2023 +0300 filtering: fix hashes commit 153fec46270212af03f3631bfb42c5d680c4e142 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 16:15:15 2023 +0300 filtering: add test cases commit 09372f92bbb1fc082f1b1283594ee589100209c5 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 15:38:05 2023 +0300 filtering: imp code commit 466bc26d524ea6d1c3efb33692a7785d39e491ca Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 18:38:40 2023 +0300 filtering: add tests commit 24365ecf8c60512fdac65833ee603c80864ae018 Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 11:38:57 2023 +0300 filtering: add hashprefix </s> remove return check(sctx, res, d.safeBrowsingUpstream) </s> add block, err := d.safeBrowsingChecker.Check(host) if !block || err != nil { return Result{}, err } return res, nil </s> remove safeSearch SafeSearch </s> add </s> remove // TODO(a.garipov): Make configurable. const ( dnsTimeout = 3 * time.Second defaultSafebrowsingServer = `https://family.adguard-dns.com/dns-query` defaultParentalServer = `https://family.adguard-dns.com/dns-query` sbTXTSuffix = `sb.dns.adguard.com.` pcTXTSuffix = `pc.dns.adguard.com.` ) // SetParentalUpstream sets the parental upstream for *DNSFilter. // // TODO(e.burkov): Remove this in v1 API to forbid the direct access. func (d *DNSFilter) SetParentalUpstream(u upstream.Upstream) { d.parentalUpstream = u } // SetSafeBrowsingUpstream sets the safe browsing upstream for *DNSFilter. // // TODO(e.burkov): Remove this in v1 API to forbid the direct access. func (d *DNSFilter) SetSafeBrowsingUpstream(u upstream.Upstream) { d.safeBrowsingUpstream = u } func (d *DNSFilter) initSecurityServices() error { var err error d.safeBrowsingServer = defaultSafebrowsingServer d.parentalServer = defaultParentalServer opts := &upstream.Options{ Timeout: dnsTimeout, ServerIPAddrs: []net.IP{ {94, 140, 14, 15}, {94, 140, 15, 16}, net.ParseIP("2a10:50c0::bad1:ff"), net.ParseIP("2a10:50c0::bad2:ff"), }, } parUps, err := upstream.AddressToUpstream(d.parentalServer, opts) if err != nil { return fmt.Errorf("converting parental server: %w", err) } d.SetParentalUpstream(parUps) sbUps, err := upstream.AddressToUpstream(d.safeBrowsingServer, opts) if err != nil { return fmt.Errorf("converting safe browsing server: %w", err) } d.SetSafeBrowsingUpstream(sbUps) return nil } /* expire byte[4] hash byte[32] ... */ func (c *sbCtx) setCache(prefix, hashes []byte) { d := make([]byte, 4+len(hashes)) expire := uint(time.Now().Unix()) + c.cacheTime*60 binary.BigEndian.PutUint32(d[:4], uint32(expire)) copy(d[4:], hashes) c.cache.Set(prefix, d) log.Debug("%s: stored in cache: %v", c.svc, prefix) } // findInHash returns 32-byte hash if it's found in hashToHost. func (c *sbCtx) findInHash(val []byte) (hash32 [32]byte, found bool) { for i := 4; i < len(val); i += 32 { hash := val[i : i+32] copy(hash32[:], hash[0:32]) _, found = c.hashToHost[hash32] if found { return hash32, found } } return [32]byte{}, false } func (c *sbCtx) getCached() int { now := time.Now().Unix() hashesToRequest := map[[32]byte]string{} for k, v := range c.hashToHost { // nolint:looppointer // The subsilce is used for a safe cache lookup. val := c.cache.Get(k[0:2]) if val == nil || now >= int64(binary.BigEndian.Uint32(val)) { hashesToRequest[k] = v continue } if hash32, found := c.findInHash(val); found { log.Debug("%s: found in cache: %s: blocked by %v", c.svc, c.host, hash32) return 1 } } if len(hashesToRequest) == 0 { log.Debug("%s: found in cache: %s: not blocked", c.svc, c.host) return -1 } c.hashToHost = hashesToRequest return 0 } type sbCtx struct { host string svc string hashToHost map[[32]byte]string cache cache.Cache cacheTime uint } func hostnameToHashes(host string) map[[32]byte]string { hashes := map[[32]byte]string{} tld, icann := publicsuffix.PublicSuffix(host) if !icann { // private suffixes like cloudfront.net tld = "" } curhost := host nDots := 0 for i := len(curhost) - 1; i >= 0; i-- { if curhost[i] == '.' { nDots++ if nDots == 4 { curhost = curhost[i+1:] // "xxx.a.b.c.d" -> "a.b.c.d" break } } } for { if curhost == "" { // we've reached end of string break } if tld != "" && curhost == tld { // we've reached the TLD, don't hash it break } sum := sha256.Sum256([]byte(curhost)) hashes[sum] = curhost pos := strings.IndexByte(curhost, byte('.')) if pos < 0 { break } curhost = curhost[pos+1:] } return hashes } // convert hash array to string func (c *sbCtx) getQuestion() string { b := &strings.Builder{} for hash := range c.hashToHost { // nolint:looppointer // The subsilce is used for safe hex encoding. stringutil.WriteToBuilder(b, hex.EncodeToString(hash[0:2]), ".") } if c.svc == "SafeBrowsing" { stringutil.WriteToBuilder(b, sbTXTSuffix) return b.String() } stringutil.WriteToBuilder(b, pcTXTSuffix) return b.String() } // Find the target hash in TXT response func (c *sbCtx) processTXT(resp *dns.Msg) (bool, [][]byte) { matched := false hashes := [][]byte{} for _, a := range resp.Answer { txt, ok := a.(*dns.TXT) if !ok { continue } log.Debug("%s: received hashes for %s: %v", c.svc, c.host, txt.Txt) for _, t := range txt.Txt { if len(t) != 32*2 { continue } hash, err := hex.DecodeString(t) if err != nil { continue } hashes = append(hashes, hash) if !matched { var hash32 [32]byte copy(hash32[:], hash) var hashHost string hashHost, ok = c.hashToHost[hash32] if ok { log.Debug("%s: matched %s by %s/%s", c.svc, c.host, hashHost, t) matched = true } } } } return matched, hashes } func (c *sbCtx) storeCache(hashes [][]byte) { slices.SortFunc(hashes, func(a, b []byte) (sortsBefore bool) { return bytes.Compare(a, b) == -1 }) var curData []byte var prevPrefix []byte for i, hash := range hashes { // nolint:looppointer // The subsilce is used for a safe comparison. if !bytes.Equal(hash[0:2], prevPrefix) { if i != 0 { c.setCache(prevPrefix, curData) curData = nil } prevPrefix = hashes[i][0:2] } curData = append(curData, hash...) } if len(prevPrefix) != 0 { c.setCache(prevPrefix, curData) } for hash := range c.hashToHost { // nolint:looppointer // The subsilce is used for a safe cache lookup. prefix := hash[0:2] val := c.cache.Get(prefix) if val == nil { c.setCache(prefix, nil) } } } func check(c *sbCtx, r Result, u upstream.Upstream) (Result, error) { c.hashToHost = hostnameToHashes(c.host) switch c.getCached() { case -1: return Result{}, nil case 1: return r, nil } question := c.getQuestion() log.Tracef("%s: checking %s: %s", c.svc, c.host, question) req := (&dns.Msg{}).SetQuestion(question, dns.TypeTXT) resp, err := u.Exchange(req) if err != nil { return Result{}, err } matched, receivedHashes := c.processTXT(resp) c.storeCache(receivedHashes) if matched { return r, nil } return Result{}, nil } </s> add </s> add // SafeBrowsingChecker is the safe browsing hash-prefix checker. SafeBrowsingChecker Checker `yaml:"-"` // ParentControl is the parental control hash-prefix checker. ParentalControlChecker Checker `yaml:"-"` </s> add safeSearch SafeSearch // safeBrowsingChecker is the safe browsing hash-prefix checker. safeBrowsingChecker Checker // parentalControl is the parental control hash-prefix checker. parentalControlChecker Checker </s> add // Checker is used for safe browsing or parental control hash-prefix filtering. type Checker interface { // Check returns true if request for the host should be blocked. Check(host string) (block bool, err error) }
https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c
internal/filtering/safebrowsing.go
keep add keep keep keep keep keep
<mask> "github.com/AdguardTeam/AdGuardHome/internal/dnsforward" <mask> "github.com/AdguardTeam/AdGuardHome/internal/filtering" <mask> "github.com/AdguardTeam/AdGuardHome/internal/filtering/safesearch" <mask> "github.com/AdguardTeam/AdGuardHome/internal/querylog" <mask> "github.com/AdguardTeam/AdGuardHome/internal/stats" <mask> "github.com/AdguardTeam/AdGuardHome/internal/updater" <mask> "github.com/AdguardTeam/AdGuardHome/internal/version" </s> Pull request 1837: AG-21462-imp-safebrowsing-parental Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master Squashed commit of the following: commit 85016d4f1105e21a407efade0bd45b8362808061 Merge: 0e61edade 620b51e3e Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 16:36:30 2023 +0300 Merge branch 'master' into AG-21462-imp-safebrowsing-parental commit 0e61edadeff34f6305e941c1db94575c82f238d9 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 14:51:37 2023 +0300 filtering: imp tests commit 994255514cc0f67dfe33d5a0892432e8924d1e36 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:13:19 2023 +0300 filtering: fix typo commit 96d1069573171538333330d6af94ef0f4208a9c4 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:00:18 2023 +0300 filtering: imp code more commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 19:13:26 2023 +0300 all: add todo commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 14:36:08 2023 +0300 all: imp code more commit b6e734ccbeda82669023f6578481260b7c1f7161 Author: Stanislav Chzhen <[email protected]> Date: Tue Apr 25 15:01:56 2023 +0300 filtering: imp code commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 20:06:36 2023 +0300 all: imp code commit 49fa6e587052a40bb431fea457701ee860493527 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 14:57:19 2023 +0300 all: rm safe browsing ctx commit bbcb66cb03e18fa875e3c33cf16295892739e507 Author: Stanislav Chzhen <[email protected]> Date: Fri Apr 21 17:54:18 2023 +0300 filtering: add cache item commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 18:43:02 2023 +0300 filtering: fix hashes commit 153fec46270212af03f3631bfb42c5d680c4e142 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 16:15:15 2023 +0300 filtering: add test cases commit 09372f92bbb1fc082f1b1283594ee589100209c5 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 15:38:05 2023 +0300 filtering: imp code commit 466bc26d524ea6d1c3efb33692a7785d39e491ca Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 18:38:40 2023 +0300 filtering: add tests commit 24365ecf8c60512fdac65833ee603c80864ae018 Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 11:38:57 2023 +0300 filtering: add hashprefix </s> add "github.com/AdguardTeam/dnsproxy/upstream" </s> add "github.com/AdguardTeam/AdGuardHome/internal/filtering/hashprefix" </s> remove sctx := &sbCtx{ host: host, svc: "Parental", cache: d.parentalCache, cacheTime: d.Config.CacheTime, } </s> add </s> remove safeSearch SafeSearch </s> add </s> remove d, setts := newForTest(t, &Config{SafeBrowsingEnabled: true}, nil) </s> add sbChecker := newChecker(sbBlocked) d, setts := newForTest(t, &Config{ SafeBrowsingEnabled: true, SafeBrowsingChecker: sbChecker, }, nil) </s> add func newChecker(host string) Checker { return hashprefix.New(&hashprefix.Config{ CacheTime: 10, CacheSize: 100000, Upstream: aghtest.NewBlockUpstream(host, true), }) }
https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c
internal/home/home.go
keep keep add keep keep keep keep
<mask> "github.com/AdguardTeam/AdGuardHome/internal/stats" <mask> "github.com/AdguardTeam/AdGuardHome/internal/updater" <mask> "github.com/AdguardTeam/AdGuardHome/internal/version" <mask> "github.com/AdguardTeam/golibs/errors" <mask> "github.com/AdguardTeam/golibs/log" <mask> "github.com/AdguardTeam/golibs/netutil" <mask> "golang.org/x/exp/slices" </s> Pull request 1837: AG-21462-imp-safebrowsing-parental Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master Squashed commit of the following: commit 85016d4f1105e21a407efade0bd45b8362808061 Merge: 0e61edade 620b51e3e Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 16:36:30 2023 +0300 Merge branch 'master' into AG-21462-imp-safebrowsing-parental commit 0e61edadeff34f6305e941c1db94575c82f238d9 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 14:51:37 2023 +0300 filtering: imp tests commit 994255514cc0f67dfe33d5a0892432e8924d1e36 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:13:19 2023 +0300 filtering: fix typo commit 96d1069573171538333330d6af94ef0f4208a9c4 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 27 11:00:18 2023 +0300 filtering: imp code more commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 19:13:26 2023 +0300 all: add todo commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 26 14:36:08 2023 +0300 all: imp code more commit b6e734ccbeda82669023f6578481260b7c1f7161 Author: Stanislav Chzhen <[email protected]> Date: Tue Apr 25 15:01:56 2023 +0300 filtering: imp code commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 20:06:36 2023 +0300 all: imp code commit 49fa6e587052a40bb431fea457701ee860493527 Author: Stanislav Chzhen <[email protected]> Date: Mon Apr 24 14:57:19 2023 +0300 all: rm safe browsing ctx commit bbcb66cb03e18fa875e3c33cf16295892739e507 Author: Stanislav Chzhen <[email protected]> Date: Fri Apr 21 17:54:18 2023 +0300 filtering: add cache item commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 18:43:02 2023 +0300 filtering: fix hashes commit 153fec46270212af03f3631bfb42c5d680c4e142 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 16:15:15 2023 +0300 filtering: add test cases commit 09372f92bbb1fc082f1b1283594ee589100209c5 Author: Stanislav Chzhen <[email protected]> Date: Thu Apr 20 15:38:05 2023 +0300 filtering: imp code commit 466bc26d524ea6d1c3efb33692a7785d39e491ca Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 18:38:40 2023 +0300 filtering: add tests commit 24365ecf8c60512fdac65833ee603c80864ae018 Author: Stanislav Chzhen <[email protected]> Date: Wed Apr 19 11:38:57 2023 +0300 filtering: add hashprefix </s> add "github.com/AdguardTeam/AdGuardHome/internal/filtering/hashprefix" </s> remove "github.com/AdguardTeam/dnsproxy/upstream" "github.com/AdguardTeam/golibs/cache" </s> add </s> remove "github.com/AdguardTeam/dnsproxy/upstream" "github.com/AdguardTeam/golibs/cache" </s> add </s> remove "github.com/AdguardTeam/golibs/stringutil" "github.com/miekg/dns" "golang.org/x/exp/slices" "golang.org/x/net/publicsuffix" </s> add </s> add "github.com/AdguardTeam/AdGuardHome/internal/filtering/hashprefix" </s> remove "time" </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c
internal/home/home.go
keep keep keep add keep keep keep keep keep
<mask> "github.com/AdguardTeam/golibs/log" <mask> "github.com/AdguardTeam/golibs/stringutil" <mask> "github.com/AdguardTeam/urlfilter" <mask> "github.com/AdguardTeam/urlfilter/filterlist" <mask> ) <mask> <mask> // unit is a convenient alias for struct{} <mask> type unit = struct{} <mask> </s> Pull request 1750: 5468-disallowed-dnstype Updates #5468. Squashed commit of the following: commit ecb0c7cc53d43fe5aa75be0c5fc0f2a9179099ad Author: Ainar Garipov <[email protected]> Date: Mon Feb 27 13:57:40 2023 +0300 dnsforward: imp access test commit 3fdc2c4533d1fce8a01f6e636e326454ef96565b Author: Ainar Garipov <[email protected]> Date: Wed Feb 22 19:29:50 2023 +0300 dnsforward: allow dnstype rules in disallowed domains </s> remove func (a *accessManager) isBlockedHost(host string) (ok bool) { _, ok = a.blockedHostsEng.Match(strings.ToLower(host)) </s> add func (a *accessManager) isBlockedHost(host string, qt rules.RRType) (ok bool) { _, ok = a.blockedHostsEng.MatchRequest(&urlfilter.DNSRequest{ Hostname: host, ClientIP: "0.0.0.0", DNSType: qt, }) </s> add "github.com/AdguardTeam/urlfilter/rules" "github.com/miekg/dns" </s> remove host := strings.TrimSuffix(pctx.Req.Question[0].Name, ".") if s.access.isBlockedHost(host) { log.Debug("host %s is in access blocklist", host) </s> add q := pctx.Req.Question[0] qt := q.Qtype host := strings.TrimSuffix(q.Name, ".") if s.access.isBlockedHost(host, qt) { log.Debug("request %s %s is in access blocklist", dns.Type(qt), host) </s> remove ip: netip.MustParseAddr("9.6.7.100"), </s> add </s> remove assert.Equal(t, tc.want, a.isBlockedHost(tc.host)) </s> add tc.want(t, a.isBlockedHost(tc.host, tc.qt)) </s> remove want: false, </s> add qt: dns.TypeA, }, { want: assert.True, name: "by_qtype", host: "site-with-https-record.example", qt: dns.TypeHTTPS, }, { want: assert.False, name: "by_qtype_other", host: "site-with-https-record.example", qt: dns.TypeA,
https://github.com/AdguardTeam/AdGuardHome/commit/386add033b91e3110c822369fa91629d9006436c
internal/dnsforward/access.go
keep keep keep keep replace replace keep keep keep keep keep
<mask> return a.blockedClientIDs.Has(id) <mask> } <mask> <mask> // isBlockedHost returns true if host should be blocked. <mask> func (a *accessManager) isBlockedHost(host string) (ok bool) { <mask> _, ok = a.blockedHostsEng.Match(strings.ToLower(host)) <mask> <mask> return ok <mask> } <mask> <mask> // isBlockedIP returns the status of the IP address blocking as well as the rule </s> Pull request 1750: 5468-disallowed-dnstype Updates #5468. Squashed commit of the following: commit ecb0c7cc53d43fe5aa75be0c5fc0f2a9179099ad Author: Ainar Garipov <[email protected]> Date: Mon Feb 27 13:57:40 2023 +0300 dnsforward: imp access test commit 3fdc2c4533d1fce8a01f6e636e326454ef96565b Author: Ainar Garipov <[email protected]> Date: Wed Feb 22 19:29:50 2023 +0300 dnsforward: allow dnstype rules in disallowed domains </s> remove host := strings.TrimSuffix(pctx.Req.Question[0].Name, ".") if s.access.isBlockedHost(host) { log.Debug("host %s is in access blocklist", host) </s> add q := pctx.Req.Question[0] qt := q.Qtype host := strings.TrimSuffix(q.Name, ".") if s.access.isBlockedHost(host, qt) { log.Debug("request %s %s is in access blocklist", dns.Type(qt), host) </s> remove assert.Equal(t, tc.want, a.isBlockedHost(tc.host)) </s> add tc.want(t, a.isBlockedHost(tc.host, tc.qt)) </s> add "github.com/AdguardTeam/urlfilter/rules" </s> add "github.com/AdguardTeam/urlfilter/rules" "github.com/miekg/dns" </s> remove ip: netip.MustParseAddr("9.6.7.100"), </s> add </s> remove want bool </s> add qt rules.RRType
https://github.com/AdguardTeam/AdGuardHome/commit/386add033b91e3110c822369fa91629d9006436c
internal/dnsforward/access.go
keep add keep keep keep keep keep
<mask> "testing" <mask> <mask> "github.com/stretchr/testify/assert" <mask> "github.com/stretchr/testify/require" <mask> ) <mask> <mask> func TestIsBlockedClientID(t *testing.T) { </s> Pull request 1750: 5468-disallowed-dnstype Updates #5468. Squashed commit of the following: commit ecb0c7cc53d43fe5aa75be0c5fc0f2a9179099ad Author: Ainar Garipov <[email protected]> Date: Mon Feb 27 13:57:40 2023 +0300 dnsforward: imp access test commit 3fdc2c4533d1fce8a01f6e636e326454ef96565b Author: Ainar Garipov <[email protected]> Date: Wed Feb 22 19:29:50 2023 +0300 dnsforward: allow dnstype rules in disallowed domains </s> remove assert.Equal(t, tc.want, a.isBlockedHost(tc.host)) </s> add tc.want(t, a.isBlockedHost(tc.host, tc.qt)) </s> remove ip: netip.MustParseAddr("9.6.7.100"), </s> add </s> add "github.com/AdguardTeam/urlfilter/rules" </s> remove func (a *accessManager) isBlockedHost(host string) (ok bool) { _, ok = a.blockedHostsEng.Match(strings.ToLower(host)) </s> add func (a *accessManager) isBlockedHost(host string, qt rules.RRType) (ok bool) { _, ok = a.blockedHostsEng.MatchRequest(&urlfilter.DNSRequest{ Hostname: host, ClientIP: "0.0.0.0", DNSType: qt, }) </s> remove want: false, </s> add qt: dns.TypeA, }, { want: assert.True, name: "by_qtype", host: "site-with-https-record.example", qt: dns.TypeHTTPS, }, { want: assert.False, name: "by_qtype_other", host: "site-with-https-record.example", qt: dns.TypeA, </s> remove want: false, </s> add qt: dns.TypeA,
https://github.com/AdguardTeam/AdGuardHome/commit/386add033b91e3110c822369fa91629d9006436c
internal/dnsforward/access_test.go
keep add keep keep keep keep keep
<mask> "*.host.com", <mask> "||host3.com^", <mask> }) <mask> require.NoError(t, err) <mask> <mask> testCases := []struct { <mask> want assert.BoolAssertionFunc </s> Pull request 1750: 5468-disallowed-dnstype Updates #5468. Squashed commit of the following: commit ecb0c7cc53d43fe5aa75be0c5fc0f2a9179099ad Author: Ainar Garipov <[email protected]> Date: Mon Feb 27 13:57:40 2023 +0300 dnsforward: imp access test commit 3fdc2c4533d1fce8a01f6e636e326454ef96565b Author: Ainar Garipov <[email protected]> Date: Wed Feb 22 19:29:50 2023 +0300 dnsforward: allow dnstype rules in disallowed domains </s> add want assert.BoolAssertionFunc </s> add ip netip.Addr </s> remove want bool </s> add qt rules.RRType </s> remove assert.Equal(t, tc.want, a.isBlockedHost(tc.host)) </s> add tc.want(t, a.isBlockedHost(tc.host, tc.qt)) </s> remove ip netip.Addr </s> add </s> remove ip: netip.MustParseAddr("9.6.7.100"), </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/386add033b91e3110c822369fa91629d9006436c
internal/dnsforward/access_test.go
keep keep keep add keep keep keep keep keep
<mask> }) <mask> require.NoError(t, err) <mask> <mask> testCases := []struct { <mask> name string <mask> host string <mask> qt rules.RRType <mask> }{{ <mask> want: assert.True, </s> Pull request 1750: 5468-disallowed-dnstype Updates #5468. Squashed commit of the following: commit ecb0c7cc53d43fe5aa75be0c5fc0f2a9179099ad Author: Ainar Garipov <[email protected]> Date: Mon Feb 27 13:57:40 2023 +0300 dnsforward: imp access test commit 3fdc2c4533d1fce8a01f6e636e326454ef96565b Author: Ainar Garipov <[email protected]> Date: Wed Feb 22 19:29:50 2023 +0300 dnsforward: allow dnstype rules in disallowed domains </s> add ip netip.Addr </s> remove want bool </s> add qt rules.RRType </s> add want: assert.True, </s> add "||*^$dnstype=HTTPS", </s> remove ip netip.Addr </s> add </s> remove host := strings.TrimSuffix(pctx.Req.Question[0].Name, ".") if s.access.isBlockedHost(host) { log.Debug("host %s is in access blocklist", host) </s> add q := pctx.Req.Question[0] qt := q.Qtype host := strings.TrimSuffix(q.Name, ".") if s.access.isBlockedHost(host, qt) { log.Debug("request %s %s is in access blocklist", dns.Type(qt), host)
https://github.com/AdguardTeam/AdGuardHome/commit/386add033b91e3110c822369fa91629d9006436c
internal/dnsforward/access_test.go
keep keep keep keep replace keep keep keep keep keep
<mask> <mask> testCases := []struct { <mask> name string <mask> host string <mask> want bool <mask> }{{ <mask> name: "plain_match", <mask> host: "host1", <mask> want: true, <mask> }, { </s> Pull request 1750: 5468-disallowed-dnstype Updates #5468. Squashed commit of the following: commit ecb0c7cc53d43fe5aa75be0c5fc0f2a9179099ad Author: Ainar Garipov <[email protected]> Date: Mon Feb 27 13:57:40 2023 +0300 dnsforward: imp access test commit 3fdc2c4533d1fce8a01f6e636e326454ef96565b Author: Ainar Garipov <[email protected]> Date: Wed Feb 22 19:29:50 2023 +0300 dnsforward: allow dnstype rules in disallowed domains </s> add want assert.BoolAssertionFunc </s> add want: assert.True, </s> add ip netip.Addr </s> remove ip netip.Addr </s> add </s> remove want: true, </s> add qt: dns.TypeA, </s> add ip: netip.MustParseAddr("1.2.3.4"),
https://github.com/AdguardTeam/AdGuardHome/commit/386add033b91e3110c822369fa91629d9006436c
internal/dnsforward/access_test.go
keep keep keep add keep keep keep keep keep keep
<mask> name string <mask> host string <mask> qt rules.RRType <mask> }{{ <mask> name: "plain_match", <mask> host: "host1", <mask> qt: dns.TypeA, <mask> }, { <mask> want: assert.False, <mask> name: "plain_mismatch", </s> Pull request 1750: 5468-disallowed-dnstype Updates #5468. Squashed commit of the following: commit ecb0c7cc53d43fe5aa75be0c5fc0f2a9179099ad Author: Ainar Garipov <[email protected]> Date: Mon Feb 27 13:57:40 2023 +0300 dnsforward: imp access test commit 3fdc2c4533d1fce8a01f6e636e326454ef96565b Author: Ainar Garipov <[email protected]> Date: Wed Feb 22 19:29:50 2023 +0300 dnsforward: allow dnstype rules in disallowed domains </s> remove want bool </s> add qt rules.RRType </s> add want assert.BoolAssertionFunc </s> remove want: true, </s> add qt: dns.TypeA, </s> remove ip netip.Addr </s> add </s> add ip netip.Addr </s> add want: assert.False,
https://github.com/AdguardTeam/AdGuardHome/commit/386add033b91e3110c822369fa91629d9006436c
internal/dnsforward/access_test.go
keep keep keep keep replace keep keep keep keep keep
<mask> want bool <mask> }{{ <mask> name: "plain_match", <mask> host: "host1", <mask> want: true, <mask> }, { <mask> name: "plain_mismatch", <mask> host: "host2", <mask> want: false, <mask> }, { </s> Pull request 1750: 5468-disallowed-dnstype Updates #5468. Squashed commit of the following: commit ecb0c7cc53d43fe5aa75be0c5fc0f2a9179099ad Author: Ainar Garipov <[email protected]> Date: Mon Feb 27 13:57:40 2023 +0300 dnsforward: imp access test commit 3fdc2c4533d1fce8a01f6e636e326454ef96565b Author: Ainar Garipov <[email protected]> Date: Wed Feb 22 19:29:50 2023 +0300 dnsforward: allow dnstype rules in disallowed domains </s> remove want bool </s> add qt rules.RRType </s> add want: assert.True, </s> remove want: false, </s> add qt: dns.TypeA, </s> add want: assert.False, </s> add want: assert.True, </s> remove want: false, </s> add qt: dns.TypeA,
https://github.com/AdguardTeam/AdGuardHome/commit/386add033b91e3110c822369fa91629d9006436c
internal/dnsforward/access_test.go
keep add keep keep keep keep keep
<mask> qt: dns.TypeA, <mask> }, { <mask> name: "plain_mismatch", <mask> host: "host2", <mask> qt: dns.TypeA, <mask> }, { <mask> want: assert.True, </s> Pull request 1750: 5468-disallowed-dnstype Updates #5468. Squashed commit of the following: commit ecb0c7cc53d43fe5aa75be0c5fc0f2a9179099ad Author: Ainar Garipov <[email protected]> Date: Mon Feb 27 13:57:40 2023 +0300 dnsforward: imp access test commit 3fdc2c4533d1fce8a01f6e636e326454ef96565b Author: Ainar Garipov <[email protected]> Date: Wed Feb 22 19:29:50 2023 +0300 dnsforward: allow dnstype rules in disallowed domains </s> remove want: false, </s> add qt: dns.TypeA, </s> remove want: true, </s> add qt: dns.TypeA, </s> add want: assert.True, </s> add want: assert.True, </s> add want: assert.True, </s> add want: assert.False,
https://github.com/AdguardTeam/AdGuardHome/commit/386add033b91e3110c822369fa91629d9006436c
internal/dnsforward/access_test.go
keep keep keep keep replace keep keep keep keep keep
<mask> want: true, <mask> }, { <mask> name: "plain_mismatch", <mask> host: "host2", <mask> want: false, <mask> }, { <mask> name: "subdomain_match_short", <mask> host: "asdf.host.com", <mask> want: true, <mask> }, { </s> Pull request 1750: 5468-disallowed-dnstype Updates #5468. Squashed commit of the following: commit ecb0c7cc53d43fe5aa75be0c5fc0f2a9179099ad Author: Ainar Garipov <[email protected]> Date: Mon Feb 27 13:57:40 2023 +0300 dnsforward: imp access test commit 3fdc2c4533d1fce8a01f6e636e326454ef96565b Author: Ainar Garipov <[email protected]> Date: Wed Feb 22 19:29:50 2023 +0300 dnsforward: allow dnstype rules in disallowed domains </s> add want: assert.True, </s> remove want: true, </s> add qt: dns.TypeA, </s> remove want: true, </s> add qt: dns.TypeA, </s> add want: assert.False, </s> remove want: false, </s> add qt: dns.TypeA, </s> remove want: false, </s> add qt: dns.TypeA,
https://github.com/AdguardTeam/AdGuardHome/commit/386add033b91e3110c822369fa91629d9006436c
internal/dnsforward/access_test.go
keep keep add keep keep keep keep keep keep
<mask> host: "host2", <mask> qt: dns.TypeA, <mask> }, { <mask> name: "subdomain_match_short", <mask> host: "asdf.host.com", <mask> qt: dns.TypeA, <mask> }, { <mask> want: assert.True, <mask> name: "subdomain_match_long", </s> Pull request 1750: 5468-disallowed-dnstype Updates #5468. Squashed commit of the following: commit ecb0c7cc53d43fe5aa75be0c5fc0f2a9179099ad Author: Ainar Garipov <[email protected]> Date: Mon Feb 27 13:57:40 2023 +0300 dnsforward: imp access test commit 3fdc2c4533d1fce8a01f6e636e326454ef96565b Author: Ainar Garipov <[email protected]> Date: Wed Feb 22 19:29:50 2023 +0300 dnsforward: allow dnstype rules in disallowed domains </s> remove want: true, </s> add qt: dns.TypeA, </s> remove want: false, </s> add qt: dns.TypeA, </s> add want: assert.True, </s> add want: assert.False, </s> remove want: true, </s> add qt: dns.TypeA, </s> remove want: true, </s> add qt: dns.TypeA,
https://github.com/AdguardTeam/AdGuardHome/commit/386add033b91e3110c822369fa91629d9006436c
internal/dnsforward/access_test.go
keep keep keep keep replace keep keep keep keep keep
<mask> want: false, <mask> }, { <mask> name: "subdomain_match_short", <mask> host: "asdf.host.com", <mask> want: true, <mask> }, { <mask> name: "subdomain_match_long", <mask> host: "qwer.asdf.host.com", <mask> want: true, <mask> }, { </s> Pull request 1750: 5468-disallowed-dnstype Updates #5468. Squashed commit of the following: commit ecb0c7cc53d43fe5aa75be0c5fc0f2a9179099ad Author: Ainar Garipov <[email protected]> Date: Mon Feb 27 13:57:40 2023 +0300 dnsforward: imp access test commit 3fdc2c4533d1fce8a01f6e636e326454ef96565b Author: Ainar Garipov <[email protected]> Date: Wed Feb 22 19:29:50 2023 +0300 dnsforward: allow dnstype rules in disallowed domains </s> add want: assert.True, </s> add want: assert.True, </s> remove want: false, </s> add qt: dns.TypeA, </s> remove want: true, </s> add qt: dns.TypeA, </s> remove want: false, </s> add qt: dns.TypeA, </s> remove want: false, </s> add qt: dns.TypeA,
https://github.com/AdguardTeam/AdGuardHome/commit/386add033b91e3110c822369fa91629d9006436c
internal/dnsforward/access_test.go
keep keep add keep keep keep keep
<mask> host: "asdf.host.com", <mask> qt: dns.TypeA, <mask> }, { <mask> name: "subdomain_match_long", <mask> host: "qwer.asdf.host.com", <mask> qt: dns.TypeA, <mask> }, { </s> Pull request 1750: 5468-disallowed-dnstype Updates #5468. Squashed commit of the following: commit ecb0c7cc53d43fe5aa75be0c5fc0f2a9179099ad Author: Ainar Garipov <[email protected]> Date: Mon Feb 27 13:57:40 2023 +0300 dnsforward: imp access test commit 3fdc2c4533d1fce8a01f6e636e326454ef96565b Author: Ainar Garipov <[email protected]> Date: Wed Feb 22 19:29:50 2023 +0300 dnsforward: allow dnstype rules in disallowed domains </s> remove want: true, </s> add qt: dns.TypeA, </s> remove want: true, </s> add qt: dns.TypeA, </s> add want: assert.True, </s> remove want: false, </s> add qt: dns.TypeA, </s> remove want: false, </s> add qt: dns.TypeA, </s> remove want: true, </s> add qt: dns.TypeA,
https://github.com/AdguardTeam/AdGuardHome/commit/386add033b91e3110c822369fa91629d9006436c
internal/dnsforward/access_test.go
keep keep keep keep replace keep keep keep keep keep
<mask> want: true, <mask> }, { <mask> name: "subdomain_match_long", <mask> host: "qwer.asdf.host.com", <mask> want: true, <mask> }, { <mask> name: "subdomain_mismatch_no_lead", <mask> host: "host.com", <mask> want: false, <mask> }, { </s> Pull request 1750: 5468-disallowed-dnstype Updates #5468. Squashed commit of the following: commit ecb0c7cc53d43fe5aa75be0c5fc0f2a9179099ad Author: Ainar Garipov <[email protected]> Date: Mon Feb 27 13:57:40 2023 +0300 dnsforward: imp access test commit 3fdc2c4533d1fce8a01f6e636e326454ef96565b Author: Ainar Garipov <[email protected]> Date: Wed Feb 22 19:29:50 2023 +0300 dnsforward: allow dnstype rules in disallowed domains </s> remove want: false, </s> add qt: dns.TypeA, </s> remove want: true, </s> add qt: dns.TypeA, </s> add want: assert.False, </s> add want: assert.True, </s> remove want: false, </s> add qt: dns.TypeA, </s> remove want: false, </s> add qt: dns.TypeA,
https://github.com/AdguardTeam/AdGuardHome/commit/386add033b91e3110c822369fa91629d9006436c
internal/dnsforward/access_test.go
keep add keep keep keep keep keep keep
<mask> qt: dns.TypeA, <mask> }, { <mask> name: "subdomain_mismatch_no_lead", <mask> host: "host.com", <mask> qt: dns.TypeA, <mask> }, { <mask> want: assert.False, <mask> name: "subdomain_mismatch_bad_asterisk", </s> Pull request 1750: 5468-disallowed-dnstype Updates #5468. Squashed commit of the following: commit ecb0c7cc53d43fe5aa75be0c5fc0f2a9179099ad Author: Ainar Garipov <[email protected]> Date: Mon Feb 27 13:57:40 2023 +0300 dnsforward: imp access test commit 3fdc2c4533d1fce8a01f6e636e326454ef96565b Author: Ainar Garipov <[email protected]> Date: Wed Feb 22 19:29:50 2023 +0300 dnsforward: allow dnstype rules in disallowed domains </s> remove want: false, </s> add qt: dns.TypeA, </s> remove want: true, </s> add qt: dns.TypeA, </s> add want: assert.False, </s> remove want: false, </s> add qt: dns.TypeA, </s> add want: assert.True, </s> add want: assert.False,
https://github.com/AdguardTeam/AdGuardHome/commit/386add033b91e3110c822369fa91629d9006436c
internal/dnsforward/access_test.go
keep keep keep keep replace keep keep keep keep keep
<mask> want: true, <mask> }, { <mask> name: "subdomain_mismatch_no_lead", <mask> host: "host.com", <mask> want: false, <mask> }, { <mask> name: "subdomain_mismatch_bad_asterisk", <mask> host: "asdf.zhost.com", <mask> want: false, <mask> }, { </s> Pull request 1750: 5468-disallowed-dnstype Updates #5468. Squashed commit of the following: commit ecb0c7cc53d43fe5aa75be0c5fc0f2a9179099ad Author: Ainar Garipov <[email protected]> Date: Mon Feb 27 13:57:40 2023 +0300 dnsforward: imp access test commit 3fdc2c4533d1fce8a01f6e636e326454ef96565b Author: Ainar Garipov <[email protected]> Date: Wed Feb 22 19:29:50 2023 +0300 dnsforward: allow dnstype rules in disallowed domains </s> remove want: true, </s> add qt: dns.TypeA, </s> add want: assert.False, </s> remove want: false, </s> add qt: dns.TypeA, </s> add want: assert.False, </s> add want: assert.True, </s> remove want: false, </s> add qt: dns.TypeA,
https://github.com/AdguardTeam/AdGuardHome/commit/386add033b91e3110c822369fa91629d9006436c
internal/dnsforward/access_test.go
keep add keep keep keep keep keep
<mask> qt: dns.TypeA, <mask> }, { <mask> name: "subdomain_mismatch_bad_asterisk", <mask> host: "asdf.zhost.com", <mask> qt: dns.TypeA, <mask> }, { <mask> want: assert.True, </s> Pull request 1750: 5468-disallowed-dnstype Updates #5468. Squashed commit of the following: commit ecb0c7cc53d43fe5aa75be0c5fc0f2a9179099ad Author: Ainar Garipov <[email protected]> Date: Mon Feb 27 13:57:40 2023 +0300 dnsforward: imp access test commit 3fdc2c4533d1fce8a01f6e636e326454ef96565b Author: Ainar Garipov <[email protected]> Date: Wed Feb 22 19:29:50 2023 +0300 dnsforward: allow dnstype rules in disallowed domains </s> add want: assert.True, </s> remove want: false, </s> add qt: dns.TypeA, </s> remove want: false, </s> add qt: dns.TypeA, </s> add want: assert.False, </s> add want: assert.True, </s> add want: assert.False,
https://github.com/AdguardTeam/AdGuardHome/commit/386add033b91e3110c822369fa91629d9006436c
internal/dnsforward/access_test.go
keep keep keep keep replace keep keep keep keep keep
<mask> want: false, <mask> }, { <mask> name: "subdomain_mismatch_bad_asterisk", <mask> host: "asdf.zhost.com", <mask> want: false, <mask> }, { <mask> name: "rule_match_simple", <mask> host: "host3.com", <mask> want: true, <mask> }, { </s> Pull request 1750: 5468-disallowed-dnstype Updates #5468. Squashed commit of the following: commit ecb0c7cc53d43fe5aa75be0c5fc0f2a9179099ad Author: Ainar Garipov <[email protected]> Date: Mon Feb 27 13:57:40 2023 +0300 dnsforward: imp access test commit 3fdc2c4533d1fce8a01f6e636e326454ef96565b Author: Ainar Garipov <[email protected]> Date: Wed Feb 22 19:29:50 2023 +0300 dnsforward: allow dnstype rules in disallowed domains </s> add want: assert.True, </s> remove want: true, </s> add qt: dns.TypeA, </s> remove want: false, </s> add qt: dns.TypeA, </s> add want: assert.False, </s> remove want: false, </s> add qt: dns.TypeA, </s> remove want: true, </s> add qt: dns.TypeA,
https://github.com/AdguardTeam/AdGuardHome/commit/386add033b91e3110c822369fa91629d9006436c
internal/dnsforward/access_test.go
keep keep keep add keep keep keep keep keep keep
<mask> name: "subdomain_mismatch_bad_asterisk", <mask> host: "asdf.zhost.com", <mask> qt: dns.TypeA, <mask> }, { <mask> name: "rule_match_simple", <mask> host: "host3.com", <mask> qt: dns.TypeA, <mask> }, { <mask> want: assert.True, <mask> name: "rule_match_complex", </s> Pull request 1750: 5468-disallowed-dnstype Updates #5468. Squashed commit of the following: commit ecb0c7cc53d43fe5aa75be0c5fc0f2a9179099ad Author: Ainar Garipov <[email protected]> Date: Mon Feb 27 13:57:40 2023 +0300 dnsforward: imp access test commit 3fdc2c4533d1fce8a01f6e636e326454ef96565b Author: Ainar Garipov <[email protected]> Date: Wed Feb 22 19:29:50 2023 +0300 dnsforward: allow dnstype rules in disallowed domains </s> remove want: false, </s> add qt: dns.TypeA, </s> remove want: true, </s> add qt: dns.TypeA, </s> add want: assert.True, </s> add want: assert.False, </s> remove want: false, </s> add qt: dns.TypeA, </s> remove want: true, </s> add qt: dns.TypeA,
https://github.com/AdguardTeam/AdGuardHome/commit/386add033b91e3110c822369fa91629d9006436c
internal/dnsforward/access_test.go
keep keep keep keep replace keep keep keep keep keep
<mask> want: false, <mask> }, { <mask> name: "rule_match_simple", <mask> host: "host3.com", <mask> want: true, <mask> }, { <mask> name: "rule_match_complex", <mask> host: "asdf.host3.com", <mask> want: true, <mask> }, { </s> Pull request 1750: 5468-disallowed-dnstype Updates #5468. Squashed commit of the following: commit ecb0c7cc53d43fe5aa75be0c5fc0f2a9179099ad Author: Ainar Garipov <[email protected]> Date: Mon Feb 27 13:57:40 2023 +0300 dnsforward: imp access test commit 3fdc2c4533d1fce8a01f6e636e326454ef96565b Author: Ainar Garipov <[email protected]> Date: Wed Feb 22 19:29:50 2023 +0300 dnsforward: allow dnstype rules in disallowed domains </s> add want: assert.True, </s> remove want: false, </s> add qt: dns.TypeA, </s> add want: assert.True, </s> remove want: true, </s> add qt: dns.TypeA, </s> remove want: false, </s> add qt: dns.TypeA, </s> remove want: false, </s> add qt: dns.TypeA,
https://github.com/AdguardTeam/AdGuardHome/commit/386add033b91e3110c822369fa91629d9006436c
internal/dnsforward/access_test.go
keep keep add keep keep keep keep keep
<mask> host: "host3.com", <mask> qt: dns.TypeA, <mask> }, { <mask> name: "rule_match_complex", <mask> host: "asdf.host3.com", <mask> qt: dns.TypeA, <mask> }, { <mask> want: assert.False, </s> Pull request 1750: 5468-disallowed-dnstype Updates #5468. Squashed commit of the following: commit ecb0c7cc53d43fe5aa75be0c5fc0f2a9179099ad Author: Ainar Garipov <[email protected]> Date: Mon Feb 27 13:57:40 2023 +0300 dnsforward: imp access test commit 3fdc2c4533d1fce8a01f6e636e326454ef96565b Author: Ainar Garipov <[email protected]> Date: Wed Feb 22 19:29:50 2023 +0300 dnsforward: allow dnstype rules in disallowed domains </s> remove want: true, </s> add qt: dns.TypeA, </s> remove want: true, </s> add qt: dns.TypeA, </s> add want: assert.True, </s> remove want: false, </s> add qt: dns.TypeA, </s> add want: assert.False, </s> add want: assert.False,
https://github.com/AdguardTeam/AdGuardHome/commit/386add033b91e3110c822369fa91629d9006436c
internal/dnsforward/access_test.go
keep keep keep keep replace keep keep keep keep keep
<mask> want: true, <mask> }, { <mask> name: "rule_match_complex", <mask> host: "asdf.host3.com", <mask> want: true, <mask> }, { <mask> name: "rule_mismatch", <mask> host: ".host3.com", <mask> want: false, <mask> }} </s> Pull request 1750: 5468-disallowed-dnstype Updates #5468. Squashed commit of the following: commit ecb0c7cc53d43fe5aa75be0c5fc0f2a9179099ad Author: Ainar Garipov <[email protected]> Date: Mon Feb 27 13:57:40 2023 +0300 dnsforward: imp access test commit 3fdc2c4533d1fce8a01f6e636e326454ef96565b Author: Ainar Garipov <[email protected]> Date: Wed Feb 22 19:29:50 2023 +0300 dnsforward: allow dnstype rules in disallowed domains </s> remove want: true, </s> add qt: dns.TypeA, </s> add want: assert.False, </s> add want: assert.True, </s> remove want: false, </s> add qt: dns.TypeA, }, { want: assert.True, name: "by_qtype", host: "site-with-https-record.example", qt: dns.TypeHTTPS, }, { want: assert.False, name: "by_qtype_other", host: "site-with-https-record.example", qt: dns.TypeA, </s> add want: assert.True, </s> remove want: false, </s> add qt: dns.TypeA,
https://github.com/AdguardTeam/AdGuardHome/commit/386add033b91e3110c822369fa91629d9006436c
internal/dnsforward/access_test.go
keep add keep keep keep keep keep keep
<mask> qt: dns.TypeA, <mask> }, { <mask> name: "rule_mismatch", <mask> host: ".host3.com", <mask> qt: dns.TypeA, <mask> }, { <mask> want: assert.True, <mask> name: "by_qtype", </s> Pull request 1750: 5468-disallowed-dnstype Updates #5468. Squashed commit of the following: commit ecb0c7cc53d43fe5aa75be0c5fc0f2a9179099ad Author: Ainar Garipov <[email protected]> Date: Mon Feb 27 13:57:40 2023 +0300 dnsforward: imp access test commit 3fdc2c4533d1fce8a01f6e636e326454ef96565b Author: Ainar Garipov <[email protected]> Date: Wed Feb 22 19:29:50 2023 +0300 dnsforward: allow dnstype rules in disallowed domains </s> remove want: false, </s> add qt: dns.TypeA, }, { want: assert.True, name: "by_qtype", host: "site-with-https-record.example", qt: dns.TypeHTTPS, }, { want: assert.False, name: "by_qtype_other", host: "site-with-https-record.example", qt: dns.TypeA, </s> remove want: true, </s> add qt: dns.TypeA, </s> add want: assert.True, </s> add want: assert.True, </s> add want: assert.False, </s> add want: assert.True,
https://github.com/AdguardTeam/AdGuardHome/commit/386add033b91e3110c822369fa91629d9006436c
internal/dnsforward/access_test.go
keep replace keep keep keep keep replace keep keep
<mask> host: ".host3.com", <mask> want: false, <mask> }} <mask> <mask> for _, tc := range testCases { <mask> t.Run(tc.name, func(t *testing.T) { <mask> assert.Equal(t, tc.want, a.isBlockedHost(tc.host)) <mask> }) <mask> } </s> Pull request 1750: 5468-disallowed-dnstype Updates #5468. Squashed commit of the following: commit ecb0c7cc53d43fe5aa75be0c5fc0f2a9179099ad Author: Ainar Garipov <[email protected]> Date: Mon Feb 27 13:57:40 2023 +0300 dnsforward: imp access test commit 3fdc2c4533d1fce8a01f6e636e326454ef96565b Author: Ainar Garipov <[email protected]> Date: Wed Feb 22 19:29:50 2023 +0300 dnsforward: allow dnstype rules in disallowed domains </s> remove ip: netip.MustParseAddr("9.6.7.100"), </s> add </s> remove want: true, </s> add qt: dns.TypeA, </s> add "||*^$dnstype=HTTPS", </s> add want assert.BoolAssertionFunc </s> remove host := strings.TrimSuffix(pctx.Req.Question[0].Name, ".") if s.access.isBlockedHost(host) { log.Debug("host %s is in access blocklist", host) </s> add q := pctx.Req.Question[0] qt := q.Qtype host := strings.TrimSuffix(q.Name, ".") if s.access.isBlockedHost(host, qt) { log.Debug("request %s %s is in access blocklist", dns.Type(qt), host)
https://github.com/AdguardTeam/AdGuardHome/commit/386add033b91e3110c822369fa91629d9006436c
internal/dnsforward/access_test.go
keep keep add keep keep keep keep
<mask> require.NoError(t, err) <mask> <mask> testCases := []struct { <mask> name string <mask> wantRule string <mask> wantBlocked bool <mask> }{{ </s> Pull request 1750: 5468-disallowed-dnstype Updates #5468. Squashed commit of the following: commit ecb0c7cc53d43fe5aa75be0c5fc0f2a9179099ad Author: Ainar Garipov <[email protected]> Date: Mon Feb 27 13:57:40 2023 +0300 dnsforward: imp access test commit 3fdc2c4533d1fce8a01f6e636e326454ef96565b Author: Ainar Garipov <[email protected]> Date: Wed Feb 22 19:29:50 2023 +0300 dnsforward: allow dnstype rules in disallowed domains </s> remove ip netip.Addr </s> add </s> add want assert.BoolAssertionFunc </s> remove want bool </s> add qt rules.RRType </s> add "||*^$dnstype=HTTPS", </s> add ip: netip.MustParseAddr("1.2.3.4"), </s> add want: assert.True,
https://github.com/AdguardTeam/AdGuardHome/commit/386add033b91e3110c822369fa91629d9006436c
internal/dnsforward/access_test.go
keep keep keep keep replace keep keep keep keep keep
<mask> <mask> testCases := []struct { <mask> name string <mask> wantRule string <mask> ip netip.Addr <mask> wantBlocked bool <mask> }{{ <mask> name: "match_ip", <mask> wantRule: "1.2.3.4", <mask> ip: netip.MustParseAddr("1.2.3.4"), </s> Pull request 1750: 5468-disallowed-dnstype Updates #5468. Squashed commit of the following: commit ecb0c7cc53d43fe5aa75be0c5fc0f2a9179099ad Author: Ainar Garipov <[email protected]> Date: Mon Feb 27 13:57:40 2023 +0300 dnsforward: imp access test commit 3fdc2c4533d1fce8a01f6e636e326454ef96565b Author: Ainar Garipov <[email protected]> Date: Wed Feb 22 19:29:50 2023 +0300 dnsforward: allow dnstype rules in disallowed domains </s> add ip netip.Addr </s> add ip: netip.MustParseAddr("1.2.3.4"), </s> remove ip: netip.MustParseAddr("1.2.3.4"), </s> add </s> remove want bool </s> add qt rules.RRType </s> add want assert.BoolAssertionFunc </s> add want: assert.True,
https://github.com/AdguardTeam/AdGuardHome/commit/386add033b91e3110c822369fa91629d9006436c
internal/dnsforward/access_test.go
keep keep add keep keep keep keep keep keep
<mask> wantRule string <mask> wantBlocked bool <mask> }{{ <mask> name: "match_ip", <mask> wantRule: "1.2.3.4", <mask> wantBlocked: true, <mask> }, { <mask> ip: netip.MustParseAddr("5.6.7.100"), <mask> name: "match_cidr", </s> Pull request 1750: 5468-disallowed-dnstype Updates #5468. Squashed commit of the following: commit ecb0c7cc53d43fe5aa75be0c5fc0f2a9179099ad Author: Ainar Garipov <[email protected]> Date: Mon Feb 27 13:57:40 2023 +0300 dnsforward: imp access test commit 3fdc2c4533d1fce8a01f6e636e326454ef96565b Author: Ainar Garipov <[email protected]> Date: Wed Feb 22 19:29:50 2023 +0300 dnsforward: allow dnstype rules in disallowed domains </s> remove ip: netip.MustParseAddr("1.2.3.4"), </s> add </s> remove ip netip.Addr </s> add </s> add ip: netip.MustParseAddr("5.6.7.100"), </s> remove ip: netip.MustParseAddr("5.6.7.100"), </s> add </s> add ip netip.Addr </s> remove ip: netip.MustParseAddr("9.2.3.4"), </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/386add033b91e3110c822369fa91629d9006436c
internal/dnsforward/access_test.go
keep keep keep keep replace keep keep keep keep keep
<mask> wantBlocked bool <mask> }{{ <mask> name: "match_ip", <mask> wantRule: "1.2.3.4", <mask> ip: netip.MustParseAddr("1.2.3.4"), <mask> wantBlocked: true, <mask> }, { <mask> name: "match_cidr", <mask> wantRule: "5.6.7.8/24", <mask> ip: netip.MustParseAddr("5.6.7.100"), </s> Pull request 1750: 5468-disallowed-dnstype Updates #5468. Squashed commit of the following: commit ecb0c7cc53d43fe5aa75be0c5fc0f2a9179099ad Author: Ainar Garipov <[email protected]> Date: Mon Feb 27 13:57:40 2023 +0300 dnsforward: imp access test commit 3fdc2c4533d1fce8a01f6e636e326454ef96565b Author: Ainar Garipov <[email protected]> Date: Wed Feb 22 19:29:50 2023 +0300 dnsforward: allow dnstype rules in disallowed domains </s> add ip: netip.MustParseAddr("1.2.3.4"), </s> add ip: netip.MustParseAddr("5.6.7.100"), </s> remove ip: netip.MustParseAddr("5.6.7.100"), </s> add </s> remove ip netip.Addr </s> add </s> remove ip: netip.MustParseAddr("9.2.3.4"), </s> add </s> add ip: netip.MustParseAddr("9.2.3.4"),
https://github.com/AdguardTeam/AdGuardHome/commit/386add033b91e3110c822369fa91629d9006436c
internal/dnsforward/access_test.go
keep keep add keep keep keep keep
<mask> wantRule: "1.2.3.4", <mask> wantBlocked: true, <mask> }, { <mask> name: "match_cidr", <mask> wantRule: "5.6.7.8/24", <mask> wantBlocked: true, <mask> }, { </s> Pull request 1750: 5468-disallowed-dnstype Updates #5468. Squashed commit of the following: commit ecb0c7cc53d43fe5aa75be0c5fc0f2a9179099ad Author: Ainar Garipov <[email protected]> Date: Mon Feb 27 13:57:40 2023 +0300 dnsforward: imp access test commit 3fdc2c4533d1fce8a01f6e636e326454ef96565b Author: Ainar Garipov <[email protected]> Date: Wed Feb 22 19:29:50 2023 +0300 dnsforward: allow dnstype rules in disallowed domains </s> remove ip: netip.MustParseAddr("1.2.3.4"), </s> add </s> remove ip: netip.MustParseAddr("5.6.7.100"), </s> add </s> add ip: netip.MustParseAddr("1.2.3.4"), </s> remove ip: netip.MustParseAddr("9.2.3.4"), </s> add </s> add ip: netip.MustParseAddr("9.2.3.4"), </s> add ip: netip.MustParseAddr("9.6.7.100"),
https://github.com/AdguardTeam/AdGuardHome/commit/386add033b91e3110c822369fa91629d9006436c
internal/dnsforward/access_test.go
keep keep keep keep replace keep keep keep keep keep
<mask> wantBlocked: true, <mask> }, { <mask> name: "match_cidr", <mask> wantRule: "5.6.7.8/24", <mask> ip: netip.MustParseAddr("5.6.7.100"), <mask> wantBlocked: true, <mask> }, { <mask> name: "no_match_ip", <mask> wantRule: "", <mask> ip: netip.MustParseAddr("9.2.3.4"), </s> Pull request 1750: 5468-disallowed-dnstype Updates #5468. Squashed commit of the following: commit ecb0c7cc53d43fe5aa75be0c5fc0f2a9179099ad Author: Ainar Garipov <[email protected]> Date: Mon Feb 27 13:57:40 2023 +0300 dnsforward: imp access test commit 3fdc2c4533d1fce8a01f6e636e326454ef96565b Author: Ainar Garipov <[email protected]> Date: Wed Feb 22 19:29:50 2023 +0300 dnsforward: allow dnstype rules in disallowed domains </s> remove ip: netip.MustParseAddr("9.2.3.4"), </s> add </s> add ip: netip.MustParseAddr("5.6.7.100"), </s> add ip: netip.MustParseAddr("9.2.3.4"), </s> remove ip: netip.MustParseAddr("1.2.3.4"), </s> add </s> add ip: netip.MustParseAddr("1.2.3.4"), </s> add ip: netip.MustParseAddr("9.6.7.100"),
https://github.com/AdguardTeam/AdGuardHome/commit/386add033b91e3110c822369fa91629d9006436c
internal/dnsforward/access_test.go
keep add keep keep keep keep keep keep
<mask> wantBlocked: true, <mask> }, { <mask> name: "no_match_ip", <mask> wantRule: "", <mask> wantBlocked: false, <mask> }, { <mask> ip: netip.MustParseAddr("9.6.7.100"), <mask> name: "no_match_cidr", </s> Pull request 1750: 5468-disallowed-dnstype Updates #5468. Squashed commit of the following: commit ecb0c7cc53d43fe5aa75be0c5fc0f2a9179099ad Author: Ainar Garipov <[email protected]> Date: Mon Feb 27 13:57:40 2023 +0300 dnsforward: imp access test commit 3fdc2c4533d1fce8a01f6e636e326454ef96565b Author: Ainar Garipov <[email protected]> Date: Wed Feb 22 19:29:50 2023 +0300 dnsforward: allow dnstype rules in disallowed domains </s> remove ip: netip.MustParseAddr("9.2.3.4"), </s> add </s> add ip: netip.MustParseAddr("9.6.7.100"), </s> remove ip: netip.MustParseAddr("5.6.7.100"), </s> add </s> remove ip: netip.MustParseAddr("9.6.7.100"), </s> add </s> add ip: netip.MustParseAddr("5.6.7.100"), </s> remove ip: netip.MustParseAddr("1.2.3.4"), </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/386add033b91e3110c822369fa91629d9006436c
internal/dnsforward/access_test.go
keep keep keep keep replace keep keep keep keep keep
<mask> wantBlocked: true, <mask> }, { <mask> name: "no_match_ip", <mask> wantRule: "", <mask> ip: netip.MustParseAddr("9.2.3.4"), <mask> wantBlocked: false, <mask> }, { <mask> name: "no_match_cidr", <mask> wantRule: "", <mask> ip: netip.MustParseAddr("9.6.7.100"), </s> Pull request 1750: 5468-disallowed-dnstype Updates #5468. Squashed commit of the following: commit ecb0c7cc53d43fe5aa75be0c5fc0f2a9179099ad Author: Ainar Garipov <[email protected]> Date: Mon Feb 27 13:57:40 2023 +0300 dnsforward: imp access test commit 3fdc2c4533d1fce8a01f6e636e326454ef96565b Author: Ainar Garipov <[email protected]> Date: Wed Feb 22 19:29:50 2023 +0300 dnsforward: allow dnstype rules in disallowed domains </s> add ip: netip.MustParseAddr("9.2.3.4"), </s> remove ip: netip.MustParseAddr("5.6.7.100"), </s> add </s> add ip: netip.MustParseAddr("9.6.7.100"), </s> remove ip: netip.MustParseAddr("9.6.7.100"), </s> add </s> add ip: netip.MustParseAddr("5.6.7.100"), </s> remove ip: netip.MustParseAddr("1.2.3.4"), </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/386add033b91e3110c822369fa91629d9006436c
internal/dnsforward/access_test.go
keep add keep keep keep keep keep
<mask> wantBlocked: false, <mask> }, { <mask> name: "no_match_cidr", <mask> wantRule: "", <mask> wantBlocked: false, <mask> }} <mask> </s> Pull request 1750: 5468-disallowed-dnstype Updates #5468. Squashed commit of the following: commit ecb0c7cc53d43fe5aa75be0c5fc0f2a9179099ad Author: Ainar Garipov <[email protected]> Date: Mon Feb 27 13:57:40 2023 +0300 dnsforward: imp access test commit 3fdc2c4533d1fce8a01f6e636e326454ef96565b Author: Ainar Garipov <[email protected]> Date: Wed Feb 22 19:29:50 2023 +0300 dnsforward: allow dnstype rules in disallowed domains </s> remove ip: netip.MustParseAddr("9.2.3.4"), </s> add </s> remove ip: netip.MustParseAddr("9.6.7.100"), </s> add </s> add ip: netip.MustParseAddr("9.2.3.4"), </s> remove ip: netip.MustParseAddr("5.6.7.100"), </s> add </s> add ip: netip.MustParseAddr("5.6.7.100"), </s> remove ip: netip.MustParseAddr("1.2.3.4"), </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/386add033b91e3110c822369fa91629d9006436c
internal/dnsforward/access_test.go
keep keep keep keep replace keep keep keep keep keep
<mask> wantBlocked: false, <mask> }, { <mask> name: "no_match_cidr", <mask> wantRule: "", <mask> ip: netip.MustParseAddr("9.6.7.100"), <mask> wantBlocked: false, <mask> }} <mask> <mask> t.Run("allow", func(t *testing.T) { <mask> for _, tc := range testCases { </s> Pull request 1750: 5468-disallowed-dnstype Updates #5468. Squashed commit of the following: commit ecb0c7cc53d43fe5aa75be0c5fc0f2a9179099ad Author: Ainar Garipov <[email protected]> Date: Mon Feb 27 13:57:40 2023 +0300 dnsforward: imp access test commit 3fdc2c4533d1fce8a01f6e636e326454ef96565b Author: Ainar Garipov <[email protected]> Date: Wed Feb 22 19:29:50 2023 +0300 dnsforward: allow dnstype rules in disallowed domains </s> add ip: netip.MustParseAddr("9.6.7.100"), </s> remove assert.Equal(t, tc.want, a.isBlockedHost(tc.host)) </s> add tc.want(t, a.isBlockedHost(tc.host, tc.qt)) </s> remove ip: netip.MustParseAddr("9.2.3.4"), </s> add </s> add ip: netip.MustParseAddr("9.2.3.4"), </s> remove want: false, </s> add qt: dns.TypeA, }, { want: assert.True, name: "by_qtype", host: "site-with-https-record.example", qt: dns.TypeHTTPS, }, { want: assert.False, name: "by_qtype_other", host: "site-with-https-record.example", qt: dns.TypeA, </s> remove ip: netip.MustParseAddr("5.6.7.100"), </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/386add033b91e3110c822369fa91629d9006436c
internal/dnsforward/access_test.go
keep keep keep keep replace replace replace keep keep keep keep keep
<mask> return s.preBlockedResponse(pctx) <mask> } <mask> <mask> if len(pctx.Req.Question) == 1 { <mask> host := strings.TrimSuffix(pctx.Req.Question[0].Name, ".") <mask> if s.access.isBlockedHost(host) { <mask> log.Debug("host %s is in access blocklist", host) <mask> <mask> return s.preBlockedResponse(pctx) <mask> } <mask> } <mask> </s> Pull request 1750: 5468-disallowed-dnstype Updates #5468. Squashed commit of the following: commit ecb0c7cc53d43fe5aa75be0c5fc0f2a9179099ad Author: Ainar Garipov <[email protected]> Date: Mon Feb 27 13:57:40 2023 +0300 dnsforward: imp access test commit 3fdc2c4533d1fce8a01f6e636e326454ef96565b Author: Ainar Garipov <[email protected]> Date: Wed Feb 22 19:29:50 2023 +0300 dnsforward: allow dnstype rules in disallowed domains </s> remove func (a *accessManager) isBlockedHost(host string) (ok bool) { _, ok = a.blockedHostsEng.Match(strings.ToLower(host)) </s> add func (a *accessManager) isBlockedHost(host string, qt rules.RRType) (ok bool) { _, ok = a.blockedHostsEng.MatchRequest(&urlfilter.DNSRequest{ Hostname: host, ClientIP: "0.0.0.0", DNSType: qt, }) </s> remove assert.Equal(t, tc.want, a.isBlockedHost(tc.host)) </s> add tc.want(t, a.isBlockedHost(tc.host, tc.qt)) </s> remove want bool </s> add qt rules.RRType </s> add want assert.BoolAssertionFunc </s> add want: assert.True, </s> remove ip: netip.MustParseAddr("9.6.7.100"), </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/386add033b91e3110c822369fa91629d9006436c
internal/dnsforward/filter.go
keep keep keep add keep keep keep keep
<mask> <mask> await apiClient.setTlsConfig(values); <mask> dispatch(setTlsConfigSuccess(config)); <mask> dispatch(addSuccessToast('encryption_config_saved')); <mask> } catch (error) { <mask> dispatch(addErrorToast({ error })); <mask> dispatch(setTlsConfigFailure()); <mask> } </s> Request tls status after save </s> remove {encryption && !encryption.processing && </s> add {encryption && </s> add status_cert: '', status_key: '',
https://github.com/AdguardTeam/AdGuardHome/commit/38983097785c3d7f37c99cc2560512c4b342a201
client/src/actions/index.js
keep keep keep keep replace keep keep keep keep keep
<mask> } = encryption; <mask> <mask> return ( <mask> <div className="encryption"> <mask> {encryption && !encryption.processing && <mask> <Card <mask> title={t('encryption_title')} <mask> subtitle={t('encryption_desc')} <mask> bodyType="card-body box-body--settings" <mask> > </s> Request tls status after save </s> add dispatch(getTlsStatus()); </s> add status_cert: '', status_key: '',
https://github.com/AdguardTeam/AdGuardHome/commit/38983097785c3d7f37c99cc2560512c4b342a201
client/src/components/Settings/Encryption/index.js
keep add keep keep keep keep keep
<mask> processing: true, <mask> processingConfig: false, <mask> }); <mask> <mask> export default combineReducers({ <mask> settings, <mask> dashboard, </s> Request tls status after save </s> remove {encryption && !encryption.processing && </s> add {encryption && </s> add dispatch(getTlsStatus());
https://github.com/AdguardTeam/AdGuardHome/commit/38983097785c3d7f37c99cc2560512c4b342a201
client/src/reducers/index.js
keep add keep keep keep keep keep
<mask> <mask> import ( <mask> "encoding/binary" <mask> "fmt" <mask> "io/ioutil" <mask> "net" <mask> "strings" </s> * whois: use the upstream server to resolve whois server hostname Close #1535 Squashed commit of the following: commit 7755d7a50e48db5d341029e1c21da95a396d9090 Merge: e24e945f 5c2ca690 Author: Simon Zolin <[email protected]> Date: Wed May 27 14:41:24 2020 +0300 Merge remote-tracking branch 'origin/master' into 1535-whois-resolve commit e24e945f9b949e3cabcddb3a8a62962bb7a5b0b9 Merge: db764710 355e634f Author: Simon Zolin <[email protected]> Date: Wed May 27 14:29:44 2020 +0300 Merge remote-tracking branch 'origin/master' into 1535-whois-resolve commit db764710a0f0b60293f7bdf6b0d7b858d56819e0 Author: Simon Zolin <[email protected]> Date: Wed May 27 12:57:00 2020 +0300 fix commit dc38f668d5845cfd696b3107a8f02dda4f10298e Author: Simon Zolin <[email protected]> Date: Wed May 27 12:44:10 2020 +0300 * whois: use the upstream server to resolve whois server hostname </s> add "time" </s> add err := prepareTestDNSServer() assert.Nil(t, err) </s> add func prepareTestDNSServer() error { config.DNS.Port = 1234 Context.dnsServer = dnsforward.NewServer(nil, nil, nil) conf := &dnsforward.ServerConfig{} uc, err := proxy.ParseUpstreamsConfig([]string{"1.1.1.1"}, nil, time.Second*5) if err != nil { return err } conf.UpstreamConfig = &uc return Context.dnsServer.Prepare(conf) } </s> add "github.com/AdguardTeam/AdGuardHome/dnsforward" "github.com/AdguardTeam/dnsproxy/proxy" </s> remove conn, err := net.DialTimeout("tcp", serverAddr, time.Duration(w.timeoutMsec)*time.Millisecond) </s> add conn, err := customDialContext(context.TODO(), "tcp", serverAddr)
https://github.com/AdguardTeam/AdGuardHome/commit/391e619979e1849947d55eac78a6664745e4d288
home/whois.go
keep keep keep keep replace keep keep keep keep keep
<mask> addr, _, _ := net.SplitHostPort(serverAddr) <mask> if addr == "whois.arin.net" { <mask> target = "n + " + target <mask> } <mask> conn, err := net.DialTimeout("tcp", serverAddr, time.Duration(w.timeoutMsec)*time.Millisecond) <mask> if err != nil { <mask> return "", err <mask> } <mask> defer conn.Close() <mask> </s> * whois: use the upstream server to resolve whois server hostname Close #1535 Squashed commit of the following: commit 7755d7a50e48db5d341029e1c21da95a396d9090 Merge: e24e945f 5c2ca690 Author: Simon Zolin <[email protected]> Date: Wed May 27 14:41:24 2020 +0300 Merge remote-tracking branch 'origin/master' into 1535-whois-resolve commit e24e945f9b949e3cabcddb3a8a62962bb7a5b0b9 Merge: db764710 355e634f Author: Simon Zolin <[email protected]> Date: Wed May 27 14:29:44 2020 +0300 Merge remote-tracking branch 'origin/master' into 1535-whois-resolve commit db764710a0f0b60293f7bdf6b0d7b858d56819e0 Author: Simon Zolin <[email protected]> Date: Wed May 27 12:57:00 2020 +0300 fix commit dc38f668d5845cfd696b3107a8f02dda4f10298e Author: Simon Zolin <[email protected]> Date: Wed May 27 12:44:10 2020 +0300 * whois: use the upstream server to resolve whois server hostname </s> add func prepareTestDNSServer() error { config.DNS.Port = 1234 Context.dnsServer = dnsforward.NewServer(nil, nil, nil) conf := &dnsforward.ServerConfig{} uc, err := proxy.ParseUpstreamsConfig([]string{"1.1.1.1"}, nil, time.Second*5) if err != nil { return err } conf.UpstreamConfig = &uc return Context.dnsServer.Prepare(conf) } </s> add err := prepareTestDNSServer() assert.Nil(t, err) </s> add "github.com/AdguardTeam/AdGuardHome/dnsforward" "github.com/AdguardTeam/dnsproxy/proxy" </s> add "time" </s> add "context"
https://github.com/AdguardTeam/AdGuardHome/commit/391e619979e1849947d55eac78a6664745e4d288
home/whois.go
keep keep add keep keep keep keep
<mask> <mask> import ( <mask> "testing" <mask> <mask> "github.com/AdguardTeam/AdGuardHome/dnsforward" <mask> "github.com/AdguardTeam/dnsproxy/proxy" <mask> "github.com/stretchr/testify/assert" </s> * whois: use the upstream server to resolve whois server hostname Close #1535 Squashed commit of the following: commit 7755d7a50e48db5d341029e1c21da95a396d9090 Merge: e24e945f 5c2ca690 Author: Simon Zolin <[email protected]> Date: Wed May 27 14:41:24 2020 +0300 Merge remote-tracking branch 'origin/master' into 1535-whois-resolve commit e24e945f9b949e3cabcddb3a8a62962bb7a5b0b9 Merge: db764710 355e634f Author: Simon Zolin <[email protected]> Date: Wed May 27 14:29:44 2020 +0300 Merge remote-tracking branch 'origin/master' into 1535-whois-resolve commit db764710a0f0b60293f7bdf6b0d7b858d56819e0 Author: Simon Zolin <[email protected]> Date: Wed May 27 12:57:00 2020 +0300 fix commit dc38f668d5845cfd696b3107a8f02dda4f10298e Author: Simon Zolin <[email protected]> Date: Wed May 27 12:44:10 2020 +0300 * whois: use the upstream server to resolve whois server hostname </s> add "github.com/AdguardTeam/AdGuardHome/dnsforward" "github.com/AdguardTeam/dnsproxy/proxy" </s> add "context" </s> add err := prepareTestDNSServer() assert.Nil(t, err) </s> add func prepareTestDNSServer() error { config.DNS.Port = 1234 Context.dnsServer = dnsforward.NewServer(nil, nil, nil) conf := &dnsforward.ServerConfig{} uc, err := proxy.ParseUpstreamsConfig([]string{"1.1.1.1"}, nil, time.Second*5) if err != nil { return err } conf.UpstreamConfig = &uc return Context.dnsServer.Prepare(conf) } </s> remove conn, err := net.DialTimeout("tcp", serverAddr, time.Duration(w.timeoutMsec)*time.Millisecond) </s> add conn, err := customDialContext(context.TODO(), "tcp", serverAddr)
https://github.com/AdguardTeam/AdGuardHome/commit/391e619979e1849947d55eac78a6664745e4d288
home/whois_test.go
keep add keep keep keep keep keep
<mask> "time" <mask> <mask> "github.com/stretchr/testify/assert" <mask> ) <mask> <mask> func prepareTestDNSServer() error { <mask> config.DNS.Port = 1234 </s> * whois: use the upstream server to resolve whois server hostname Close #1535 Squashed commit of the following: commit 7755d7a50e48db5d341029e1c21da95a396d9090 Merge: e24e945f 5c2ca690 Author: Simon Zolin <[email protected]> Date: Wed May 27 14:41:24 2020 +0300 Merge remote-tracking branch 'origin/master' into 1535-whois-resolve commit e24e945f9b949e3cabcddb3a8a62962bb7a5b0b9 Merge: db764710 355e634f Author: Simon Zolin <[email protected]> Date: Wed May 27 14:29:44 2020 +0300 Merge remote-tracking branch 'origin/master' into 1535-whois-resolve commit db764710a0f0b60293f7bdf6b0d7b858d56819e0 Author: Simon Zolin <[email protected]> Date: Wed May 27 12:57:00 2020 +0300 fix commit dc38f668d5845cfd696b3107a8f02dda4f10298e Author: Simon Zolin <[email protected]> Date: Wed May 27 12:44:10 2020 +0300 * whois: use the upstream server to resolve whois server hostname </s> add func prepareTestDNSServer() error { config.DNS.Port = 1234 Context.dnsServer = dnsforward.NewServer(nil, nil, nil) conf := &dnsforward.ServerConfig{} uc, err := proxy.ParseUpstreamsConfig([]string{"1.1.1.1"}, nil, time.Second*5) if err != nil { return err } conf.UpstreamConfig = &uc return Context.dnsServer.Prepare(conf) } </s> add "time" </s> remove conn, err := net.DialTimeout("tcp", serverAddr, time.Duration(w.timeoutMsec)*time.Millisecond) </s> add conn, err := customDialContext(context.TODO(), "tcp", serverAddr) </s> add err := prepareTestDNSServer() assert.Nil(t, err) </s> add "context"
https://github.com/AdguardTeam/AdGuardHome/commit/391e619979e1849947d55eac78a6664745e4d288
home/whois_test.go
keep add keep keep keep keep keep keep
<mask> ) <mask> <mask> func TestWhois(t *testing.T) { <mask> err := prepareTestDNSServer() <mask> assert.Nil(t, err) <mask> <mask> w := Whois{timeoutMsec: 5000} <mask> resp, err := w.queryAll("8.8.8.8") </s> * whois: use the upstream server to resolve whois server hostname Close #1535 Squashed commit of the following: commit 7755d7a50e48db5d341029e1c21da95a396d9090 Merge: e24e945f 5c2ca690 Author: Simon Zolin <[email protected]> Date: Wed May 27 14:41:24 2020 +0300 Merge remote-tracking branch 'origin/master' into 1535-whois-resolve commit e24e945f9b949e3cabcddb3a8a62962bb7a5b0b9 Merge: db764710 355e634f Author: Simon Zolin <[email protected]> Date: Wed May 27 14:29:44 2020 +0300 Merge remote-tracking branch 'origin/master' into 1535-whois-resolve commit db764710a0f0b60293f7bdf6b0d7b858d56819e0 Author: Simon Zolin <[email protected]> Date: Wed May 27 12:57:00 2020 +0300 fix commit dc38f668d5845cfd696b3107a8f02dda4f10298e Author: Simon Zolin <[email protected]> Date: Wed May 27 12:44:10 2020 +0300 * whois: use the upstream server to resolve whois server hostname </s> add err := prepareTestDNSServer() assert.Nil(t, err) </s> add "github.com/AdguardTeam/AdGuardHome/dnsforward" "github.com/AdguardTeam/dnsproxy/proxy" </s> remove conn, err := net.DialTimeout("tcp", serverAddr, time.Duration(w.timeoutMsec)*time.Millisecond) </s> add conn, err := customDialContext(context.TODO(), "tcp", serverAddr) </s> add "time" </s> add "context"
https://github.com/AdguardTeam/AdGuardHome/commit/391e619979e1849947d55eac78a6664745e4d288
home/whois_test.go
keep add keep keep keep keep keep
<mask> <mask> func TestWhois(t *testing.T) { <mask> w := Whois{timeoutMsec: 5000} <mask> resp, err := w.queryAll("8.8.8.8") <mask> assert.True(t, err == nil) <mask> m := whoisParse(resp) <mask> assert.True(t, m["orgname"] == "Google LLC") </s> * whois: use the upstream server to resolve whois server hostname Close #1535 Squashed commit of the following: commit 7755d7a50e48db5d341029e1c21da95a396d9090 Merge: e24e945f 5c2ca690 Author: Simon Zolin <[email protected]> Date: Wed May 27 14:41:24 2020 +0300 Merge remote-tracking branch 'origin/master' into 1535-whois-resolve commit e24e945f9b949e3cabcddb3a8a62962bb7a5b0b9 Merge: db764710 355e634f Author: Simon Zolin <[email protected]> Date: Wed May 27 14:29:44 2020 +0300 Merge remote-tracking branch 'origin/master' into 1535-whois-resolve commit db764710a0f0b60293f7bdf6b0d7b858d56819e0 Author: Simon Zolin <[email protected]> Date: Wed May 27 12:57:00 2020 +0300 fix commit dc38f668d5845cfd696b3107a8f02dda4f10298e Author: Simon Zolin <[email protected]> Date: Wed May 27 12:44:10 2020 +0300 * whois: use the upstream server to resolve whois server hostname </s> add func prepareTestDNSServer() error { config.DNS.Port = 1234 Context.dnsServer = dnsforward.NewServer(nil, nil, nil) conf := &dnsforward.ServerConfig{} uc, err := proxy.ParseUpstreamsConfig([]string{"1.1.1.1"}, nil, time.Second*5) if err != nil { return err } conf.UpstreamConfig = &uc return Context.dnsServer.Prepare(conf) } </s> remove conn, err := net.DialTimeout("tcp", serverAddr, time.Duration(w.timeoutMsec)*time.Millisecond) </s> add conn, err := customDialContext(context.TODO(), "tcp", serverAddr) </s> add "github.com/AdguardTeam/AdGuardHome/dnsforward" "github.com/AdguardTeam/dnsproxy/proxy" </s> add "time" </s> add "context"
https://github.com/AdguardTeam/AdGuardHome/commit/391e619979e1849947d55eac78a6664745e4d288
home/whois_test.go
keep keep keep keep replace keep keep keep keep keep
<mask> } <mask> } <mask> <mask> // Set necessary properties <mask> f.ID = assignUniqueFilterID() <mask> f.Enabled = true <mask> <mask> // Download the filter contents <mask> ok, err := f.update(true) <mask> if err != nil { </s> - control: fix race in /control/version.json handler </s> add controlLock.Lock() </s> remove w.Write(versionCheckJSON) </s> add w.Write(data) </s> add controlLock.Unlock()
https://github.com/AdguardTeam/AdGuardHome/commit/392c7b6ee19ed38650fc9d7f4f3750d965e94da5
control.go
keep keep keep keep replace keep keep keep keep keep
<mask> now := time.Now() <mask> if now.Sub(versionCheckLastTime) <= versionCheckPeriod && len(versionCheckJSON) != 0 { <mask> // return cached copy <mask> w.Header().Set("Content-Type", "application/json") <mask> w.Write(versionCheckJSON) <mask> return <mask> } <mask> <mask> resp, err := client.Get(versionCheckURL) <mask> if err != nil { </s> - control: fix race in /control/version.json handler </s> remove f.ID = assignUniqueFilterID() </s> add controlLock.Lock() cached := now.Sub(versionCheckLastTime) <= versionCheckPeriod && len(versionCheckJSON) != 0 data := versionCheckJSON controlLock.Unlock() if cached { </s> add controlLock.Lock() </s> add controlLock.Unlock()
https://github.com/AdguardTeam/AdGuardHome/commit/392c7b6ee19ed38650fc9d7f4f3750d965e94da5
control.go
keep keep keep add keep keep keep keep keep
<mask> if err != nil { <mask> httpError(w, http.StatusInternalServerError, "Couldn't write body: %s", err) <mask> } <mask> <mask> versionCheckLastTime = now <mask> versionCheckJSON = body <mask> controlLock.Unlock() <mask> } <mask> </s> - control: fix race in /control/version.json handler </s> remove f.ID = assignUniqueFilterID() </s> add controlLock.Lock() cached := now.Sub(versionCheckLastTime) <= versionCheckPeriod && len(versionCheckJSON) != 0 data := versionCheckJSON controlLock.Unlock() if cached { </s> add controlLock.Unlock() </s> remove w.Write(versionCheckJSON) </s> add w.Write(data)
https://github.com/AdguardTeam/AdGuardHome/commit/392c7b6ee19ed38650fc9d7f4f3750d965e94da5
control.go
keep keep keep add keep keep keep keep keep keep
<mask> <mask> controlLock.Lock() <mask> versionCheckLastTime = now <mask> versionCheckJSON = body <mask> } <mask> <mask> // --------- <mask> // filtering <mask> // --------- <mask> </s> - control: fix race in /control/version.json handler </s> remove f.ID = assignUniqueFilterID() </s> add controlLock.Lock() cached := now.Sub(versionCheckLastTime) <= versionCheckPeriod && len(versionCheckJSON) != 0 data := versionCheckJSON controlLock.Unlock() if cached { </s> add controlLock.Lock() </s> remove w.Write(versionCheckJSON) </s> add w.Write(data)
https://github.com/AdguardTeam/AdGuardHome/commit/392c7b6ee19ed38650fc9d7f4f3750d965e94da5
control.go
keep keep keep add keep keep keep keep keep
<mask> NATIVE_GOARCH = $(shell unset GOARCH; go env GOARCH) <mask> GOPATH := $(shell go env GOPATH) <mask> JSFILES = $(shell find client -path client/node_modules -prune -o -type f -name '*.js') <mask> STATIC = build/static/index.html <mask> <mask> TARGET=AdGuardHome <mask> <mask> .PHONY: all build clean <mask> all: build </s> Fix #773 - preparing the new update channel </s> remove CGO_ENABLED=0 go build -ldflags="-s -w -X main.VersionString=$(GIT_VERSION)" -asmflags="-trimpath=$(PWD)" -gcflags="-trimpath=$(PWD)" </s> add CGO_ENABLED=0 go build -ldflags="-s -w -X main.VersionString=$(GIT_VERSION) -X main.updateChannel=$(CHANNEL)" -asmflags="-trimpath=$(PWD)" -gcflags="-trimpath=$(PWD)" </s> remove const versionCheckURL = "https://adguardteam.github.io/AdGuardHome/version.json" const versionCheckPeriod = time.Hour * 8 </s> add </s> add // updateChannel can be set via ldflags var updateChannel = "release" var versionCheckURL = "https://static.adguard.com/adguardhome/" + updateChannel + "/version.json" const versionCheckPeriod = time.Hour * 8 </s> remove log.Printf("AdGuard Home, version %s\n", VersionString) </s> add log.Printf("AdGuard Home, version %s, channel %s\n", VersionString, updateChannel) </s> add "time"
https://github.com/AdguardTeam/AdGuardHome/commit/395833056097fa44c1221da33319cd64e4a5ca62
Makefile
keep keep keep keep replace keep keep keep keep keep
<mask> <mask> $(TARGET): $(STATIC) *.go dhcpd/*.go dnsfilter/*.go dnsforward/*.go <mask> GOOS=$(NATIVE_GOOS) GOARCH=$(NATIVE_GOARCH) GO111MODULE=off go get -v github.com/gobuffalo/packr/... <mask> PATH=$(GOPATH)/bin:$(PATH) packr -z <mask> CGO_ENABLED=0 go build -ldflags="-s -w -X main.VersionString=$(GIT_VERSION)" -asmflags="-trimpath=$(PWD)" -gcflags="-trimpath=$(PWD)" <mask> PATH=$(GOPATH)/bin:$(PATH) packr clean <mask> <mask> clean: <mask> $(MAKE) cleanfast <mask> rm -rf build </s> Fix #773 - preparing the new update channel </s> add CHANNEL ?= release </s> remove const versionCheckURL = "https://adguardteam.github.io/AdGuardHome/version.json" const versionCheckPeriod = time.Hour * 8 </s> add </s> remove log.Printf("AdGuard Home, version %s\n", VersionString) </s> add log.Printf("AdGuard Home, version %s, channel %s\n", VersionString, updateChannel) </s> add // updateChannel can be set via ldflags var updateChannel = "release" var versionCheckURL = "https://static.adguard.com/adguardhome/" + updateChannel + "/version.json" const versionCheckPeriod = time.Hour * 8 </s> add "time"
https://github.com/AdguardTeam/AdGuardHome/commit/395833056097fa44c1221da33319cd64e4a5ca62
Makefile
keep keep add keep keep keep keep keep
<mask> "strings" <mask> "sync" <mask> "syscall" <mask> <mask> "github.com/AdguardTeam/golibs/log" <mask> "github.com/NYTimes/gziphandler" <mask> "github.com/gobuffalo/packr" <mask> ) </s> Fix #773 - preparing the new update channel </s> remove const versionCheckURL = "https://adguardteam.github.io/AdGuardHome/version.json" const versionCheckPeriod = time.Hour * 8 </s> add </s> remove log.Printf("AdGuard Home, version %s\n", VersionString) </s> add log.Printf("AdGuard Home, version %s, channel %s\n", VersionString, updateChannel) </s> add // updateChannel can be set via ldflags var updateChannel = "release" var versionCheckURL = "https://static.adguard.com/adguardhome/" + updateChannel + "/version.json" const versionCheckPeriod = time.Hour * 8 </s> remove CGO_ENABLED=0 go build -ldflags="-s -w -X main.VersionString=$(GIT_VERSION)" -asmflags="-trimpath=$(PWD)" -gcflags="-trimpath=$(PWD)" </s> add CGO_ENABLED=0 go build -ldflags="-s -w -X main.VersionString=$(GIT_VERSION) -X main.updateChannel=$(CHANNEL)" -asmflags="-trimpath=$(PWD)" -gcflags="-trimpath=$(PWD)" </s> add CHANNEL ?= release
https://github.com/AdguardTeam/AdGuardHome/commit/395833056097fa44c1221da33319cd64e4a5ca62
app.go
keep keep add keep keep keep keep keep keep
<mask> <mask> // VersionString will be set through ldflags, contains current version <mask> var VersionString = "undefined" <mask> var httpServer *http.Server <mask> var httpsServer struct { <mask> server *http.Server <mask> cond *sync.Cond // reacts to config.TLS.Enabled, PortHTTPS, CertificateChain and PrivateKey <mask> sync.Mutex // protects config.TLS <mask> shutdown bool // if TRUE, don't restart the server </s> Fix #773 - preparing the new update channel </s> remove log.Printf("AdGuard Home, version %s\n", VersionString) </s> add log.Printf("AdGuard Home, version %s, channel %s\n", VersionString, updateChannel) </s> remove const versionCheckURL = "https://adguardteam.github.io/AdGuardHome/version.json" const versionCheckPeriod = time.Hour * 8 </s> add </s> add CHANNEL ?= release </s> add "time" </s> remove CGO_ENABLED=0 go build -ldflags="-s -w -X main.VersionString=$(GIT_VERSION)" -asmflags="-trimpath=$(PWD)" -gcflags="-trimpath=$(PWD)" </s> add CGO_ENABLED=0 go build -ldflags="-s -w -X main.VersionString=$(GIT_VERSION) -X main.updateChannel=$(CHANNEL)" -asmflags="-trimpath=$(PWD)" -gcflags="-trimpath=$(PWD)"
https://github.com/AdguardTeam/AdGuardHome/commit/395833056097fa44c1221da33319cd64e4a5ca62
app.go
keep keep keep keep replace keep keep keep keep keep
<mask> // enable TLS 1.3 <mask> enableTLS13() <mask> <mask> // print the first message after logger is configured <mask> log.Printf("AdGuard Home, version %s\n", VersionString) <mask> log.Debug("Current working directory is %s", config.ourWorkingDir) <mask> if args.runningAsService { <mask> log.Info("AdGuard Home is running as a service") <mask> } <mask> config.runningAsService = args.runningAsService </s> Fix #773 - preparing the new update channel </s> add // updateChannel can be set via ldflags var updateChannel = "release" var versionCheckURL = "https://static.adguard.com/adguardhome/" + updateChannel + "/version.json" const versionCheckPeriod = time.Hour * 8 </s> remove const versionCheckURL = "https://adguardteam.github.io/AdGuardHome/version.json" const versionCheckPeriod = time.Hour * 8 </s> add </s> add CHANNEL ?= release </s> add "time" </s> remove CGO_ENABLED=0 go build -ldflags="-s -w -X main.VersionString=$(GIT_VERSION)" -asmflags="-trimpath=$(PWD)" -gcflags="-trimpath=$(PWD)" </s> add CGO_ENABLED=0 go build -ldflags="-s -w -X main.VersionString=$(GIT_VERSION) -X main.updateChannel=$(CHANNEL)" -asmflags="-trimpath=$(PWD)" -gcflags="-trimpath=$(PWD)"
https://github.com/AdguardTeam/AdGuardHome/commit/395833056097fa44c1221da33319cd64e4a5ca62
app.go
keep keep keep keep replace replace replace keep keep keep keep keep
<mask> var versionCheckLastTime time.Time <mask> <mask> var protocols = []string{"tls://", "https://", "tcp://", "sdns://"} <mask> <mask> const versionCheckURL = "https://adguardteam.github.io/AdGuardHome/version.json" <mask> const versionCheckPeriod = time.Hour * 8 <mask> <mask> var transport = &http.Transport{ <mask> DialContext: customDialContext, <mask> } <mask> <mask> var client = &http.Client{ </s> Fix #773 - preparing the new update channel </s> add // updateChannel can be set via ldflags var updateChannel = "release" var versionCheckURL = "https://static.adguard.com/adguardhome/" + updateChannel + "/version.json" const versionCheckPeriod = time.Hour * 8 </s> add CHANNEL ?= release </s> remove log.Printf("AdGuard Home, version %s\n", VersionString) </s> add log.Printf("AdGuard Home, version %s, channel %s\n", VersionString, updateChannel) </s> add "time" </s> remove CGO_ENABLED=0 go build -ldflags="-s -w -X main.VersionString=$(GIT_VERSION)" -asmflags="-trimpath=$(PWD)" -gcflags="-trimpath=$(PWD)" </s> add CGO_ENABLED=0 go build -ldflags="-s -w -X main.VersionString=$(GIT_VERSION) -X main.updateChannel=$(CHANNEL)" -asmflags="-trimpath=$(PWD)" -gcflags="-trimpath=$(PWD)"
https://github.com/AdguardTeam/AdGuardHome/commit/395833056097fa44c1221da33319cd64e4a5ca62
control.go
keep keep keep keep replace keep keep keep keep keep
<mask> // Initialize and run the admin Web interface <mask> box := packr.NewBox("build/static") <mask> // if not configured, redirect / to /install.html, otherwise redirect /install.html to / <mask> http.Handle("/", postInstallHandler(optionalAuthHandler(http.FileServer(box)))) <mask> http.Handle("/install.html", preInstallHandler(http.FileServer(box))) <mask> registerControlHandlers() <mask> <mask> // this loop is used as an ability to change listening host and/or port <mask> for { <mask> address := net.JoinHostPort(config.BindHost, strconv.Itoa(config.BindPort)) </s> Move installation of /install handlers into a separate optional function </s> add // add handlers for /install paths, we only need them when we're not configured yet if config.firstRun { http.Handle("/install.html", preInstallHandler(http.FileServer(box))) registerInstallHandlers() } </s> remove // TODO: move to registerInstallHandlers() http.HandleFunc("/control/install/get_addresses", preInstall(ensureGET(handleInstallGetAddresses))) http.HandleFunc("/control/install/configure", preInstall(ensurePOST(handleInstallConfigure))) </s> add </s> add func registerInstallHandlers() { http.HandleFunc("/control/install/get_addresses", preInstall(ensureGET(handleInstallGetAddresses))) http.HandleFunc("/control/install/configure", preInstall(ensurePOST(handleInstallConfigure))) }
https://github.com/AdguardTeam/AdGuardHome/commit/398312cd80537d49b3c8752425ab7fd8358c7bc0
app.go
keep keep add keep keep keep keep
<mask> http.Handle("/", postInstallHandler(optionalAuthHandler(http.FileServer(box)))) <mask> registerControlHandlers() <mask> <mask> // this loop is used as an ability to change listening host and/or port <mask> for { <mask> address := net.JoinHostPort(config.BindHost, strconv.Itoa(config.BindPort)) <mask> URL := fmt.Sprintf("http://%s", address) </s> Move installation of /install handlers into a separate optional function </s> remove http.Handle("/install.html", preInstallHandler(http.FileServer(box))) </s> add </s> add func registerInstallHandlers() { http.HandleFunc("/control/install/get_addresses", preInstall(ensureGET(handleInstallGetAddresses))) http.HandleFunc("/control/install/configure", preInstall(ensurePOST(handleInstallConfigure))) } </s> remove // TODO: move to registerInstallHandlers() http.HandleFunc("/control/install/get_addresses", preInstall(ensureGET(handleInstallGetAddresses))) http.HandleFunc("/control/install/configure", preInstall(ensurePOST(handleInstallConfigure))) </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/398312cd80537d49b3c8752425ab7fd8358c7bc0
app.go
keep add keep keep keep keep keep keep
<mask> } <mask> <mask> func registerControlHandlers() { <mask> http.HandleFunc("/control/status", postInstall(optionalAuth(ensureGET(handleStatus)))) <mask> http.HandleFunc("/control/enable_protection", postInstall(optionalAuth(ensurePOST(handleProtectionEnable)))) <mask> http.HandleFunc("/control/disable_protection", postInstall(optionalAuth(ensurePOST(handleProtectionDisable)))) <mask> http.HandleFunc("/control/querylog", postInstall(optionalAuth(ensureGET(dnsforward.HandleQueryLog)))) <mask> http.HandleFunc("/control/querylog_enable", postInstall(optionalAuth(ensurePOST(handleQueryLogEnable)))) </s> Move installation of /install handlers into a separate optional function </s> add // add handlers for /install paths, we only need them when we're not configured yet if config.firstRun { http.Handle("/install.html", preInstallHandler(http.FileServer(box))) registerInstallHandlers() } </s> remove http.Handle("/install.html", preInstallHandler(http.FileServer(box))) </s> add </s> remove // TODO: move to registerInstallHandlers() http.HandleFunc("/control/install/get_addresses", preInstall(ensureGET(handleInstallGetAddresses))) http.HandleFunc("/control/install/configure", preInstall(ensurePOST(handleInstallConfigure))) </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/398312cd80537d49b3c8752425ab7fd8358c7bc0
control.go
keep keep keep keep replace replace replace replace keep
<mask> http.HandleFunc("/control/dhcp/status", postInstall(optionalAuth(ensureGET(handleDHCPStatus)))) <mask> http.HandleFunc("/control/dhcp/interfaces", postInstall(optionalAuth(ensureGET(handleDHCPInterfaces)))) <mask> http.HandleFunc("/control/dhcp/set_config", postInstall(optionalAuth(ensurePOST(handleDHCPSetConfig)))) <mask> http.HandleFunc("/control/dhcp/find_active_dhcp", postInstall(optionalAuth(ensurePOST(handleDHCPFindActiveServer)))) <mask> <mask> // TODO: move to registerInstallHandlers() <mask> http.HandleFunc("/control/install/get_addresses", preInstall(ensureGET(handleInstallGetAddresses))) <mask> http.HandleFunc("/control/install/configure", preInstall(ensurePOST(handleInstallConfigure))) <mask> } </s> Move installation of /install handlers into a separate optional function </s> add // add handlers for /install paths, we only need them when we're not configured yet if config.firstRun { http.Handle("/install.html", preInstallHandler(http.FileServer(box))) registerInstallHandlers() } </s> remove http.Handle("/install.html", preInstallHandler(http.FileServer(box))) </s> add </s> add func registerInstallHandlers() { http.HandleFunc("/control/install/get_addresses", preInstall(ensureGET(handleInstallGetAddresses))) http.HandleFunc("/control/install/configure", preInstall(ensurePOST(handleInstallConfigure))) }
https://github.com/AdguardTeam/AdGuardHome/commit/398312cd80537d49b3c8752425ab7fd8358c7bc0
control.go
keep keep keep keep replace replace keep keep keep keep keep
<mask> "upstreams": "Upstreams", <mask> "apply_btn": "Apply", <mask> "disabled_filtering_toast": "Disabled filtering", <mask> "enabled_filtering_toast": "Enabled filtering", <mask> "disabled_safe_browsing_toast": "Disabled safebrowsing", <mask> "enabled_safe_browsing_toast": "Enabled safebrowsing", <mask> "disabled_parental_toast": "Disabled parental control", <mask> "enabled_parental_toast": "Enabled parental control", <mask> "disabled_safe_search_toast": "Disabled safe search", <mask> "enabled_save_search_toast": "Enabled safe search", <mask> "enabled_table_header": "Enabled", </s> Pull request: client: imp en i18n Merge in DNS/adguard-home from en-i18n-safe-browsing to master Squashed commit of the following: commit dd32a58c3761818a10386b4a1d9e6871da59c71e Author: Ainar Garipov <[email protected]> Date: Wed Dec 22 17:31:35 2021 +0300 client: imp en i18n </s> remove "blocked_safebrowsing": "Blocked by Safebrowsing", "blocked_adult_websites": "Blocked Adult Websites", </s> add "blocked_safebrowsing": "Blocked by Safe Browsing", "blocked_adult_websites": "Blocked by Parental Control", </s> remove "parental_control": "Parental control", "safe_browsing": "Safe browsing", </s> add "parental_control": "Parental Control", "safe_browsing": "Safe Browsing",
https://github.com/AdguardTeam/AdGuardHome/commit/39c4999d2d3d78eb6a1de4fc29d464767965043e
client/src/__locales/en.json
keep keep keep keep replace replace keep keep keep keep keep
<mask> "all_queries": "All queries", <mask> "show_blocked_responses": "Blocked", <mask> "show_whitelisted_responses": "Allowed", <mask> "show_processed_responses": "Processed", <mask> "blocked_safebrowsing": "Blocked by Safebrowsing", <mask> "blocked_adult_websites": "Blocked Adult Websites", <mask> "blocked_threats": "Blocked Threats", <mask> "allowed": "Allowed", <mask> "filtered": "Filtered", <mask> "rewritten": "Rewritten", <mask> "safe_search": "Safe search", </s> Pull request: client: imp en i18n Merge in DNS/adguard-home from en-i18n-safe-browsing to master Squashed commit of the following: commit dd32a58c3761818a10386b4a1d9e6871da59c71e Author: Ainar Garipov <[email protected]> Date: Wed Dec 22 17:31:35 2021 +0300 client: imp en i18n </s> remove "disabled_safe_browsing_toast": "Disabled safebrowsing", "enabled_safe_browsing_toast": "Enabled safebrowsing", </s> add "disabled_safe_browsing_toast": "Disabled Safe Browsing", "enabled_safe_browsing_toast": "Enabled Safe Browsing", </s> remove "parental_control": "Parental control", "safe_browsing": "Safe browsing", </s> add "parental_control": "Parental Control", "safe_browsing": "Safe Browsing",
https://github.com/AdguardTeam/AdGuardHome/commit/39c4999d2d3d78eb6a1de4fc29d464767965043e
client/src/__locales/en.json
keep keep keep keep replace replace keep keep
<mask> "filter_allowlist": "WARNING: This action also will exclude the rule \"{{disallowed_rule}}\" from the list of allowed clients.", <mask> "last_rule_in_allowlist": "Cannot disallow this client because excluding the rule \"{{disallowed_rule}}\" will DISABLE \"Allowed clients\" list.", <mask> "experimental": "Experimental", <mask> "use_saved_key": "Use the previously saved key", <mask> "parental_control": "Parental control", <mask> "safe_browsing": "Safe browsing", <mask> "served_from_cache": "{{value}} <i>(served from cache)</i>" <mask> } </s> Pull request: client: imp en i18n Merge in DNS/adguard-home from en-i18n-safe-browsing to master Squashed commit of the following: commit dd32a58c3761818a10386b4a1d9e6871da59c71e Author: Ainar Garipov <[email protected]> Date: Wed Dec 22 17:31:35 2021 +0300 client: imp en i18n </s> remove "disabled_safe_browsing_toast": "Disabled safebrowsing", "enabled_safe_browsing_toast": "Enabled safebrowsing", </s> add "disabled_safe_browsing_toast": "Disabled Safe Browsing", "enabled_safe_browsing_toast": "Enabled Safe Browsing", </s> remove "blocked_safebrowsing": "Blocked by Safebrowsing", "blocked_adult_websites": "Blocked Adult Websites", </s> add "blocked_safebrowsing": "Blocked by Safe Browsing", "blocked_adult_websites": "Blocked by Parental Control",
https://github.com/AdguardTeam/AdGuardHome/commit/39c4999d2d3d78eb6a1de4fc29d464767965043e
client/src/__locales/en.json
keep keep replace keep replace replace replace replace replace replace replace replace replace
<mask> # Don't consider the HTTPS hostname since the enforced HTTPS redirection should <mask> # work if the SSL check skipped. See file docker/healthcheck.sh. <mask> /^bind_host:/ { host = $2 } <mask> <mask> /^bind_port:/ { port = $2 } <mask> <mask> END { <mask> if (match(host, ":")) { <mask> print "http://[" host "]:" port <mask> } else { <mask> print "http://" host ":" port <mask> } <mask> } </s> Pull request: home: http conf Updates #2860. Squashed commit of the following: commit 0d55a99d5c0b9f1d8c9497775dd69929e5091eaa Merge: 73a203ac8 d4a4bda64 Author: Dimitry Kolyshev <[email protected]> Date: Thu Jun 29 16:25:36 2023 +0400 Merge remote-tracking branch 'origin/master' into http-yaml-conf commit 73a203ac8acf083fa289015e1f301d05bf320ea7 Author: Dimitry Kolyshev <[email protected]> Date: Thu Jun 29 16:21:48 2023 +0400 home: imp docs commit a4819ace94bfe4427f70f1b8341c9babc9234740 Author: Dimitry Kolyshev <[email protected]> Date: Thu Jun 29 11:45:30 2023 +0400 snap: imp script commit b0913c7ac5c6c46d6a73790fd57d8c5f9d7ace75 Author: Dimitry Kolyshev <[email protected]> Date: Wed Jun 28 17:34:03 2023 +0400 all: docs commit 14820d6d56f958081d9f236277fd34f356bdab33 Author: Dimitry Kolyshev <[email protected]> Date: Wed Jun 28 13:21:43 2023 +0400 home: imp tests commit 9db800d3ce39c36da7959e37b4a46736f4217e5c Author: Dimitry Kolyshev <[email protected]> Date: Wed Jun 28 13:17:34 2023 +0400 all: docs commit 9174a0ae710da51d85b4e1b1af79eda6a61dd3a2 Merge: ca8c4ae95 d88181343 Author: Dimitry Kolyshev <[email protected]> Date: Wed Jun 28 10:19:01 2023 +0400 Merge remote-tracking branch 'origin/master' into http-yaml-conf # Conflicts: # CHANGELOG.md # internal/home/upgrade.go # internal/home/upgrade_test.go commit ca8c4ae954ece25d78ef2f873bb3ba71fa4b8fa9 Author: Dimitry Kolyshev <[email protected]> Date: Wed Jun 28 10:07:15 2023 +0400 snap: imp script commit d84473f8e07b2c6e65023613eb4032fd01951521 Author: Dimitry Kolyshev <[email protected]> Date: Wed Jun 28 09:59:57 2023 +0400 snap: imp script commit 8a0808e42ddbff7d9d3345d758f91b14bb4453be Author: Dimitry Kolyshev <[email protected]> Date: Tue Jun 27 15:03:53 2023 +0400 home: http conf commit e8fbb89cc5748f9d8fa4be9e702756bd8b869de9 Author: Dimitry Kolyshev <[email protected]> Date: Tue Jun 27 14:59:37 2023 +0400 home: imp code commit 46541aabc421118562d564675dfd7e594d2056aa Author: Dimitry Kolyshev <[email protected]> Date: Tue Jun 27 12:36:14 2023 +0400 snap: bind port commit cecda5fcfd8c473db42f235b4f586b2193086997 Author: Dimitry Kolyshev <[email protected]> Date: Tue Jun 27 12:12:39 2023 +0400 docker: bind port commit 8d8945b70366c6b018616a32421c77eb281a6ea1 Author: Dimitry Kolyshev <[email protected]> Date: Tue Jun 27 11:06:32 2023 +0400 home: imp code commit ae5e8c1c4333d7b752c08605d80e41f55ee50e59 Author: Dimitry Kolyshev <[email protected]> Date: Tue Jun 27 11:02:09 2023 +0400 home: imp code commit c9ee460f37e32941b84ea5fa94d21b186d6dd82b Author: Dimitry Kolyshev <[email protected]> Date: Mon Jun 26 17:11:10 2023 +0400 home: imp code commit 44c72445112ef38d6ec9c25b197c119edd6c959f Author: Dimitry Kolyshev <[email protected]> Date: Mon Jun 26 11:52:19 2023 +0400 all: docs commit e3bf5faeb748f347b1202a496788739ff9219ed0 Merge: 38cc0f639 e7e638443 Author: Dimitry Kolyshev <[email protected]> Date: Mon Jun 26 11:39:12 2023 +0400 Merge remote-tracking branch 'origin/master' into http-yaml-conf commit 38cc0f6399040f1fa39d9da31ad6db65a6bdd4cc Author: Dimitry Kolyshev <[email protected]> Date: Mon Jun 26 11:38:17 2023 +0400 snap: bind port commit 3b9cb9e8cc89a67e55cecc7a2040c150f8675b4c Author: Dimitry Kolyshev <[email protected]> Date: Mon Jun 26 11:25:03 2023 +0400 docker: bind port ... and 4 more commits </s> remove port := config.BindPort </s> add port := int(config.HTTPConfig.Address.Port()) </s> remove err = checkPorts() if err != nil { // Don't wrap the error, because it's informative enough as is. return err </s> add if config.HTTPConfig.Address.Port() != 0 { err = checkPorts() if err != nil { // Don't wrap the error, because it's informative enough as is. return err } </s> remove } </s> add </s> remove switch portInt { case 0, config.BindPort: </s> add switch reqPort { case 0, config.HTTPConfig.Address.Port(): </s> remove return aghnet.CheckPort("tcp", netip.AddrPortFrom(config.BindHost, uint16(port))) == nil </s> add addrPort := netip.AddrPortFrom(config.HTTPConfig.Address.Addr(), uint16(port)) return aghnet.CheckPort("tcp", addrPort) == nil
https://github.com/AdguardTeam/AdGuardHome/commit/39f5c50acd9da08dca22a0a3170f3f47446210df
docker/web-bind.awk
keep keep keep keep replace replace keep keep keep keep keep
<mask> DHCP bool `yaml:"dhcp"` <mask> HostsFile bool `yaml:"hosts"` <mask> } <mask> <mask> // configuration is loaded from YAML <mask> // field ordering is important -- yaml fields will mirror ordering from here <mask> type configuration struct { <mask> // Raw file data to avoid re-reading of configuration file <mask> // It's reset after config is parsed <mask> fileData []byte <mask> </s> Pull request: home: http conf Updates #2860. Squashed commit of the following: commit 0d55a99d5c0b9f1d8c9497775dd69929e5091eaa Merge: 73a203ac8 d4a4bda64 Author: Dimitry Kolyshev <[email protected]> Date: Thu Jun 29 16:25:36 2023 +0400 Merge remote-tracking branch 'origin/master' into http-yaml-conf commit 73a203ac8acf083fa289015e1f301d05bf320ea7 Author: Dimitry Kolyshev <[email protected]> Date: Thu Jun 29 16:21:48 2023 +0400 home: imp docs commit a4819ace94bfe4427f70f1b8341c9babc9234740 Author: Dimitry Kolyshev <[email protected]> Date: Thu Jun 29 11:45:30 2023 +0400 snap: imp script commit b0913c7ac5c6c46d6a73790fd57d8c5f9d7ace75 Author: Dimitry Kolyshev <[email protected]> Date: Wed Jun 28 17:34:03 2023 +0400 all: docs commit 14820d6d56f958081d9f236277fd34f356bdab33 Author: Dimitry Kolyshev <[email protected]> Date: Wed Jun 28 13:21:43 2023 +0400 home: imp tests commit 9db800d3ce39c36da7959e37b4a46736f4217e5c Author: Dimitry Kolyshev <[email protected]> Date: Wed Jun 28 13:17:34 2023 +0400 all: docs commit 9174a0ae710da51d85b4e1b1af79eda6a61dd3a2 Merge: ca8c4ae95 d88181343 Author: Dimitry Kolyshev <[email protected]> Date: Wed Jun 28 10:19:01 2023 +0400 Merge remote-tracking branch 'origin/master' into http-yaml-conf # Conflicts: # CHANGELOG.md # internal/home/upgrade.go # internal/home/upgrade_test.go commit ca8c4ae954ece25d78ef2f873bb3ba71fa4b8fa9 Author: Dimitry Kolyshev <[email protected]> Date: Wed Jun 28 10:07:15 2023 +0400 snap: imp script commit d84473f8e07b2c6e65023613eb4032fd01951521 Author: Dimitry Kolyshev <[email protected]> Date: Wed Jun 28 09:59:57 2023 +0400 snap: imp script commit 8a0808e42ddbff7d9d3345d758f91b14bb4453be Author: Dimitry Kolyshev <[email protected]> Date: Tue Jun 27 15:03:53 2023 +0400 home: http conf commit e8fbb89cc5748f9d8fa4be9e702756bd8b869de9 Author: Dimitry Kolyshev <[email protected]> Date: Tue Jun 27 14:59:37 2023 +0400 home: imp code commit 46541aabc421118562d564675dfd7e594d2056aa Author: Dimitry Kolyshev <[email protected]> Date: Tue Jun 27 12:36:14 2023 +0400 snap: bind port commit cecda5fcfd8c473db42f235b4f586b2193086997 Author: Dimitry Kolyshev <[email protected]> Date: Tue Jun 27 12:12:39 2023 +0400 docker: bind port commit 8d8945b70366c6b018616a32421c77eb281a6ea1 Author: Dimitry Kolyshev <[email protected]> Date: Tue Jun 27 11:06:32 2023 +0400 home: imp code commit ae5e8c1c4333d7b752c08605d80e41f55ee50e59 Author: Dimitry Kolyshev <[email protected]> Date: Tue Jun 27 11:02:09 2023 +0400 home: imp code commit c9ee460f37e32941b84ea5fa94d21b186d6dd82b Author: Dimitry Kolyshev <[email protected]> Date: Mon Jun 26 17:11:10 2023 +0400 home: imp code commit 44c72445112ef38d6ec9c25b197c119edd6c959f Author: Dimitry Kolyshev <[email protected]> Date: Mon Jun 26 11:52:19 2023 +0400 all: docs commit e3bf5faeb748f347b1202a496788739ff9219ed0 Merge: 38cc0f639 e7e638443 Author: Dimitry Kolyshev <[email protected]> Date: Mon Jun 26 11:39:12 2023 +0400 Merge remote-tracking branch 'origin/master' into http-yaml-conf commit 38cc0f6399040f1fa39d9da31ad6db65a6bdd4cc Author: Dimitry Kolyshev <[email protected]> Date: Mon Jun 26 11:38:17 2023 +0400 snap: bind port commit 3b9cb9e8cc89a67e55cecc7a2040c150f8675b4c Author: Dimitry Kolyshev <[email protected]> Date: Mon Jun 26 11:25:03 2023 +0400 docker: bind port ... and 4 more commits </s> remove // field ordering is important -- yaml fields will mirror ordering from here </s> add // httpConfig is a block with HTTP configuration params. // // Field ordering is important, YAML fields better not to be reordered, if it's // not absolutely necessary. type httpConfig struct { // Address is the address to serve the web UI on. Address netip.AddrPort // SessionTTL for a web session. // An active session is automatically refreshed once a day. SessionTTL timeutil.Duration `yaml:"session_ttl"` } // dnsConfig is a block with DNS configuration params. // // Field ordering is important, YAML fields better not to be reordered, if it's // not absolutely necessary. </s> remove // BindHost is the address for the web interface server to listen on. BindHost netip.Addr `yaml:"bind_host"` // BindPort is the port for the web interface server to listen on. BindPort int `yaml:"bind_port"` </s> add // HTTPConfig is the block with http conf. HTTPConfig httpConfig `yaml:"http"` </s> remove if !conf.BindHost.IsValid() { return errors.Error("bind_host is not a valid ip address") </s> add if !conf.HTTPConfig.Address.IsValid() { return errors.Error("http.address is not a valid ip address") </s> remove return aghnet.CheckPort("tcp", netip.AddrPortFrom(req.Web.IP, uint16(portInt))) </s> add return aghnet.CheckPort("tcp", netip.AddrPortFrom(req.Web.IP, reqPort)) </s> remove // TTL for a web session (in hours) // An active session is automatically refreshed once a day. WebSessionTTLHours uint32 `yaml:"web_session_ttl"` </s> add </s> remove BindPort: 3000, BindHost: netip.IPv4Unspecified(), AuthAttempts: 5, AuthBlockMin: 15, WebSessionTTLHours: 30 * 24, </s> add AuthAttempts: 5, AuthBlockMin: 15, HTTPConfig: httpConfig{ Address: netip.AddrPortFrom(netip.IPv4Unspecified(), 3000), SessionTTL: timeutil.Duration{Duration: 30 * timeutil.Day}, },
https://github.com/AdguardTeam/AdGuardHome/commit/39f5c50acd9da08dca22a0a3170f3f47446210df
internal/home/config.go
keep keep keep keep replace replace replace replace replace keep keep keep keep keep
<mask> // Raw file data to avoid re-reading of configuration file <mask> // It's reset after config is parsed <mask> fileData []byte <mask> <mask> // BindHost is the address for the web interface server to listen on. <mask> BindHost netip.Addr `yaml:"bind_host"` <mask> // BindPort is the port for the web interface server to listen on. <mask> BindPort int `yaml:"bind_port"` <mask> <mask> // Users are the clients capable for accessing the web interface. <mask> Users []webUser `yaml:"users"` <mask> // AuthAttempts is the maximum number of failed login attempts a user <mask> // can do before being blocked. <mask> AuthAttempts uint `yaml:"auth_attempts"` </s> Pull request: home: http conf Updates #2860. Squashed commit of the following: commit 0d55a99d5c0b9f1d8c9497775dd69929e5091eaa Merge: 73a203ac8 d4a4bda64 Author: Dimitry Kolyshev <[email protected]> Date: Thu Jun 29 16:25:36 2023 +0400 Merge remote-tracking branch 'origin/master' into http-yaml-conf commit 73a203ac8acf083fa289015e1f301d05bf320ea7 Author: Dimitry Kolyshev <[email protected]> Date: Thu Jun 29 16:21:48 2023 +0400 home: imp docs commit a4819ace94bfe4427f70f1b8341c9babc9234740 Author: Dimitry Kolyshev <[email protected]> Date: Thu Jun 29 11:45:30 2023 +0400 snap: imp script commit b0913c7ac5c6c46d6a73790fd57d8c5f9d7ace75 Author: Dimitry Kolyshev <[email protected]> Date: Wed Jun 28 17:34:03 2023 +0400 all: docs commit 14820d6d56f958081d9f236277fd34f356bdab33 Author: Dimitry Kolyshev <[email protected]> Date: Wed Jun 28 13:21:43 2023 +0400 home: imp tests commit 9db800d3ce39c36da7959e37b4a46736f4217e5c Author: Dimitry Kolyshev <[email protected]> Date: Wed Jun 28 13:17:34 2023 +0400 all: docs commit 9174a0ae710da51d85b4e1b1af79eda6a61dd3a2 Merge: ca8c4ae95 d88181343 Author: Dimitry Kolyshev <[email protected]> Date: Wed Jun 28 10:19:01 2023 +0400 Merge remote-tracking branch 'origin/master' into http-yaml-conf # Conflicts: # CHANGELOG.md # internal/home/upgrade.go # internal/home/upgrade_test.go commit ca8c4ae954ece25d78ef2f873bb3ba71fa4b8fa9 Author: Dimitry Kolyshev <[email protected]> Date: Wed Jun 28 10:07:15 2023 +0400 snap: imp script commit d84473f8e07b2c6e65023613eb4032fd01951521 Author: Dimitry Kolyshev <[email protected]> Date: Wed Jun 28 09:59:57 2023 +0400 snap: imp script commit 8a0808e42ddbff7d9d3345d758f91b14bb4453be Author: Dimitry Kolyshev <[email protected]> Date: Tue Jun 27 15:03:53 2023 +0400 home: http conf commit e8fbb89cc5748f9d8fa4be9e702756bd8b869de9 Author: Dimitry Kolyshev <[email protected]> Date: Tue Jun 27 14:59:37 2023 +0400 home: imp code commit 46541aabc421118562d564675dfd7e594d2056aa Author: Dimitry Kolyshev <[email protected]> Date: Tue Jun 27 12:36:14 2023 +0400 snap: bind port commit cecda5fcfd8c473db42f235b4f586b2193086997 Author: Dimitry Kolyshev <[email protected]> Date: Tue Jun 27 12:12:39 2023 +0400 docker: bind port commit 8d8945b70366c6b018616a32421c77eb281a6ea1 Author: Dimitry Kolyshev <[email protected]> Date: Tue Jun 27 11:06:32 2023 +0400 home: imp code commit ae5e8c1c4333d7b752c08605d80e41f55ee50e59 Author: Dimitry Kolyshev <[email protected]> Date: Tue Jun 27 11:02:09 2023 +0400 home: imp code commit c9ee460f37e32941b84ea5fa94d21b186d6dd82b Author: Dimitry Kolyshev <[email protected]> Date: Mon Jun 26 17:11:10 2023 +0400 home: imp code commit 44c72445112ef38d6ec9c25b197c119edd6c959f Author: Dimitry Kolyshev <[email protected]> Date: Mon Jun 26 11:52:19 2023 +0400 all: docs commit e3bf5faeb748f347b1202a496788739ff9219ed0 Merge: 38cc0f639 e7e638443 Author: Dimitry Kolyshev <[email protected]> Date: Mon Jun 26 11:39:12 2023 +0400 Merge remote-tracking branch 'origin/master' into http-yaml-conf commit 38cc0f6399040f1fa39d9da31ad6db65a6bdd4cc Author: Dimitry Kolyshev <[email protected]> Date: Mon Jun 26 11:38:17 2023 +0400 snap: bind port commit 3b9cb9e8cc89a67e55cecc7a2040c150f8675b4c Author: Dimitry Kolyshev <[email protected]> Date: Mon Jun 26 11:25:03 2023 +0400 docker: bind port ... and 4 more commits </s> remove // configuration is loaded from YAML // field ordering is important -- yaml fields will mirror ordering from here </s> add // configuration is loaded from YAML. // // Field ordering is important, YAML fields better not to be reordered, if it's // not absolutely necessary. </s> remove // field ordering is important -- yaml fields will mirror ordering from here </s> add // httpConfig is a block with HTTP configuration params. // // Field ordering is important, YAML fields better not to be reordered, if it's // not absolutely necessary. type httpConfig struct { // Address is the address to serve the web UI on. Address netip.AddrPort // SessionTTL for a web session. // An active session is automatically refreshed once a day. SessionTTL timeutil.Duration `yaml:"session_ttl"` } // dnsConfig is a block with DNS configuration params. // // Field ordering is important, YAML fields better not to be reordered, if it's // not absolutely necessary. </s> remove case config.BindPort: </s> add case config.HTTPConfig.Address.Port(): </s> remove // TTL for a web session (in hours) // An active session is automatically refreshed once a day. WebSessionTTLHours uint32 `yaml:"web_session_ttl"` </s> add </s> remove return aghnet.CheckPort("tcp", netip.AddrPortFrom(req.Web.IP, uint16(portInt))) </s> add return aghnet.CheckPort("tcp", netip.AddrPortFrom(req.Web.IP, reqPort)) </s> remove portInt := req.Web.Port port := tcpPort(portInt) </s> add // TODO(a.garipov): Declare all port variables anywhere as uint16. reqPort := uint16(req.Web.Port) port := tcpPort(reqPort)
https://github.com/AdguardTeam/AdGuardHome/commit/39f5c50acd9da08dca22a0a3170f3f47446210df
internal/home/config.go
keep keep keep keep replace replace replace replace keep keep keep keep keep
<mask> Theme Theme `yaml:"theme"` <mask> // DebugPProf defines if the profiling HTTP handler will listen on :6060. <mask> DebugPProf bool `yaml:"debug_pprof"` <mask> <mask> // TTL for a web session (in hours) <mask> // An active session is automatically refreshed once a day. <mask> WebSessionTTLHours uint32 `yaml:"web_session_ttl"` <mask> <mask> DNS dnsConfig `yaml:"dns"` <mask> TLS tlsConfigSettings `yaml:"tls"` <mask> QueryLog queryLogConfig `yaml:"querylog"` <mask> Stats statsConfig `yaml:"statistics"` <mask> </s> Pull request: home: http conf Updates #2860. Squashed commit of the following: commit 0d55a99d5c0b9f1d8c9497775dd69929e5091eaa Merge: 73a203ac8 d4a4bda64 Author: Dimitry Kolyshev <[email protected]> Date: Thu Jun 29 16:25:36 2023 +0400 Merge remote-tracking branch 'origin/master' into http-yaml-conf commit 73a203ac8acf083fa289015e1f301d05bf320ea7 Author: Dimitry Kolyshev <[email protected]> Date: Thu Jun 29 16:21:48 2023 +0400 home: imp docs commit a4819ace94bfe4427f70f1b8341c9babc9234740 Author: Dimitry Kolyshev <[email protected]> Date: Thu Jun 29 11:45:30 2023 +0400 snap: imp script commit b0913c7ac5c6c46d6a73790fd57d8c5f9d7ace75 Author: Dimitry Kolyshev <[email protected]> Date: Wed Jun 28 17:34:03 2023 +0400 all: docs commit 14820d6d56f958081d9f236277fd34f356bdab33 Author: Dimitry Kolyshev <[email protected]> Date: Wed Jun 28 13:21:43 2023 +0400 home: imp tests commit 9db800d3ce39c36da7959e37b4a46736f4217e5c Author: Dimitry Kolyshev <[email protected]> Date: Wed Jun 28 13:17:34 2023 +0400 all: docs commit 9174a0ae710da51d85b4e1b1af79eda6a61dd3a2 Merge: ca8c4ae95 d88181343 Author: Dimitry Kolyshev <[email protected]> Date: Wed Jun 28 10:19:01 2023 +0400 Merge remote-tracking branch 'origin/master' into http-yaml-conf # Conflicts: # CHANGELOG.md # internal/home/upgrade.go # internal/home/upgrade_test.go commit ca8c4ae954ece25d78ef2f873bb3ba71fa4b8fa9 Author: Dimitry Kolyshev <[email protected]> Date: Wed Jun 28 10:07:15 2023 +0400 snap: imp script commit d84473f8e07b2c6e65023613eb4032fd01951521 Author: Dimitry Kolyshev <[email protected]> Date: Wed Jun 28 09:59:57 2023 +0400 snap: imp script commit 8a0808e42ddbff7d9d3345d758f91b14bb4453be Author: Dimitry Kolyshev <[email protected]> Date: Tue Jun 27 15:03:53 2023 +0400 home: http conf commit e8fbb89cc5748f9d8fa4be9e702756bd8b869de9 Author: Dimitry Kolyshev <[email protected]> Date: Tue Jun 27 14:59:37 2023 +0400 home: imp code commit 46541aabc421118562d564675dfd7e594d2056aa Author: Dimitry Kolyshev <[email protected]> Date: Tue Jun 27 12:36:14 2023 +0400 snap: bind port commit cecda5fcfd8c473db42f235b4f586b2193086997 Author: Dimitry Kolyshev <[email protected]> Date: Tue Jun 27 12:12:39 2023 +0400 docker: bind port commit 8d8945b70366c6b018616a32421c77eb281a6ea1 Author: Dimitry Kolyshev <[email protected]> Date: Tue Jun 27 11:06:32 2023 +0400 home: imp code commit ae5e8c1c4333d7b752c08605d80e41f55ee50e59 Author: Dimitry Kolyshev <[email protected]> Date: Tue Jun 27 11:02:09 2023 +0400 home: imp code commit c9ee460f37e32941b84ea5fa94d21b186d6dd82b Author: Dimitry Kolyshev <[email protected]> Date: Mon Jun 26 17:11:10 2023 +0400 home: imp code commit 44c72445112ef38d6ec9c25b197c119edd6c959f Author: Dimitry Kolyshev <[email protected]> Date: Mon Jun 26 11:52:19 2023 +0400 all: docs commit e3bf5faeb748f347b1202a496788739ff9219ed0 Merge: 38cc0f639 e7e638443 Author: Dimitry Kolyshev <[email protected]> Date: Mon Jun 26 11:39:12 2023 +0400 Merge remote-tracking branch 'origin/master' into http-yaml-conf commit 38cc0f6399040f1fa39d9da31ad6db65a6bdd4cc Author: Dimitry Kolyshev <[email protected]> Date: Mon Jun 26 11:38:17 2023 +0400 snap: bind port commit 3b9cb9e8cc89a67e55cecc7a2040c150f8675b4c Author: Dimitry Kolyshev <[email protected]> Date: Mon Jun 26 11:25:03 2023 +0400 docker: bind port ... and 4 more commits </s> remove // field ordering is important -- yaml fields will mirror ordering from here </s> add // httpConfig is a block with HTTP configuration params. // // Field ordering is important, YAML fields better not to be reordered, if it's // not absolutely necessary. type httpConfig struct { // Address is the address to serve the web UI on. Address netip.AddrPort // SessionTTL for a web session. // An active session is automatically refreshed once a day. SessionTTL timeutil.Duration `yaml:"session_ttl"` } // dnsConfig is a block with DNS configuration params. // // Field ordering is important, YAML fields better not to be reordered, if it's // not absolutely necessary. </s> remove // BindHost is the address for the web interface server to listen on. BindHost netip.Addr `yaml:"bind_host"` // BindPort is the port for the web interface server to listen on. BindPort int `yaml:"bind_port"` </s> add // HTTPConfig is the block with http conf. HTTPConfig httpConfig `yaml:"http"` </s> remove // configuration is loaded from YAML // field ordering is important -- yaml fields will mirror ordering from here </s> add // configuration is loaded from YAML. // // Field ordering is important, YAML fields better not to be reordered, if it's // not absolutely necessary. </s> remove if !conf.BindHost.IsValid() { return errors.Error("bind_host is not a valid ip address") </s> add if !conf.HTTPConfig.Address.IsValid() { return errors.Error("http.address is not a valid ip address") </s> remove return aghnet.CheckPort("tcp", netip.AddrPortFrom(req.Web.IP, uint16(portInt))) </s> add return aghnet.CheckPort("tcp", netip.AddrPortFrom(req.Web.IP, reqPort)) </s> remove case config.BindPort: </s> add case config.HTTPConfig.Address.Port():
https://github.com/AdguardTeam/AdGuardHome/commit/39f5c50acd9da08dca22a0a3170f3f47446210df
internal/home/config.go
keep keep keep keep replace keep keep keep keep keep
<mask> <mask> SchemaVersion int `yaml:"schema_version"` // keeping last so that users will be less tempted to change it -- used when upgrading between versions <mask> } <mask> <mask> // field ordering is important -- yaml fields will mirror ordering from here <mask> type dnsConfig struct { <mask> BindHosts []netip.Addr `yaml:"bind_hosts"` <mask> Port int `yaml:"port"` <mask> <mask> // AnonymizeClientIP defines if clients' IP addresses should be anonymized </s> Pull request: home: http conf Updates #2860. Squashed commit of the following: commit 0d55a99d5c0b9f1d8c9497775dd69929e5091eaa Merge: 73a203ac8 d4a4bda64 Author: Dimitry Kolyshev <[email protected]> Date: Thu Jun 29 16:25:36 2023 +0400 Merge remote-tracking branch 'origin/master' into http-yaml-conf commit 73a203ac8acf083fa289015e1f301d05bf320ea7 Author: Dimitry Kolyshev <[email protected]> Date: Thu Jun 29 16:21:48 2023 +0400 home: imp docs commit a4819ace94bfe4427f70f1b8341c9babc9234740 Author: Dimitry Kolyshev <[email protected]> Date: Thu Jun 29 11:45:30 2023 +0400 snap: imp script commit b0913c7ac5c6c46d6a73790fd57d8c5f9d7ace75 Author: Dimitry Kolyshev <[email protected]> Date: Wed Jun 28 17:34:03 2023 +0400 all: docs commit 14820d6d56f958081d9f236277fd34f356bdab33 Author: Dimitry Kolyshev <[email protected]> Date: Wed Jun 28 13:21:43 2023 +0400 home: imp tests commit 9db800d3ce39c36da7959e37b4a46736f4217e5c Author: Dimitry Kolyshev <[email protected]> Date: Wed Jun 28 13:17:34 2023 +0400 all: docs commit 9174a0ae710da51d85b4e1b1af79eda6a61dd3a2 Merge: ca8c4ae95 d88181343 Author: Dimitry Kolyshev <[email protected]> Date: Wed Jun 28 10:19:01 2023 +0400 Merge remote-tracking branch 'origin/master' into http-yaml-conf # Conflicts: # CHANGELOG.md # internal/home/upgrade.go # internal/home/upgrade_test.go commit ca8c4ae954ece25d78ef2f873bb3ba71fa4b8fa9 Author: Dimitry Kolyshev <[email protected]> Date: Wed Jun 28 10:07:15 2023 +0400 snap: imp script commit d84473f8e07b2c6e65023613eb4032fd01951521 Author: Dimitry Kolyshev <[email protected]> Date: Wed Jun 28 09:59:57 2023 +0400 snap: imp script commit 8a0808e42ddbff7d9d3345d758f91b14bb4453be Author: Dimitry Kolyshev <[email protected]> Date: Tue Jun 27 15:03:53 2023 +0400 home: http conf commit e8fbb89cc5748f9d8fa4be9e702756bd8b869de9 Author: Dimitry Kolyshev <[email protected]> Date: Tue Jun 27 14:59:37 2023 +0400 home: imp code commit 46541aabc421118562d564675dfd7e594d2056aa Author: Dimitry Kolyshev <[email protected]> Date: Tue Jun 27 12:36:14 2023 +0400 snap: bind port commit cecda5fcfd8c473db42f235b4f586b2193086997 Author: Dimitry Kolyshev <[email protected]> Date: Tue Jun 27 12:12:39 2023 +0400 docker: bind port commit 8d8945b70366c6b018616a32421c77eb281a6ea1 Author: Dimitry Kolyshev <[email protected]> Date: Tue Jun 27 11:06:32 2023 +0400 home: imp code commit ae5e8c1c4333d7b752c08605d80e41f55ee50e59 Author: Dimitry Kolyshev <[email protected]> Date: Tue Jun 27 11:02:09 2023 +0400 home: imp code commit c9ee460f37e32941b84ea5fa94d21b186d6dd82b Author: Dimitry Kolyshev <[email protected]> Date: Mon Jun 26 17:11:10 2023 +0400 home: imp code commit 44c72445112ef38d6ec9c25b197c119edd6c959f Author: Dimitry Kolyshev <[email protected]> Date: Mon Jun 26 11:52:19 2023 +0400 all: docs commit e3bf5faeb748f347b1202a496788739ff9219ed0 Merge: 38cc0f639 e7e638443 Author: Dimitry Kolyshev <[email protected]> Date: Mon Jun 26 11:39:12 2023 +0400 Merge remote-tracking branch 'origin/master' into http-yaml-conf commit 38cc0f6399040f1fa39d9da31ad6db65a6bdd4cc Author: Dimitry Kolyshev <[email protected]> Date: Mon Jun 26 11:38:17 2023 +0400 snap: bind port commit 3b9cb9e8cc89a67e55cecc7a2040c150f8675b4c Author: Dimitry Kolyshev <[email protected]> Date: Mon Jun 26 11:25:03 2023 +0400 docker: bind port ... and 4 more commits </s> remove // configuration is loaded from YAML // field ordering is important -- yaml fields will mirror ordering from here </s> add // configuration is loaded from YAML. // // Field ordering is important, YAML fields better not to be reordered, if it's // not absolutely necessary. </s> remove // TTL for a web session (in hours) // An active session is automatically refreshed once a day. WebSessionTTLHours uint32 `yaml:"web_session_ttl"` </s> add </s> remove portInt := req.Web.Port port := tcpPort(portInt) </s> add // TODO(a.garipov): Declare all port variables anywhere as uint16. reqPort := uint16(req.Web.Port) port := tcpPort(reqPort) </s> remove printWebAddrs(proto, bindhost.String(), port) </s> add printWebAddrs(proto, bindHost.String(), port) </s> remove HTTPPort int `json:"http_port"` </s> add HTTPPort uint16 `json:"http_port"` </s> remove return aghnet.CheckPort("tcp", netip.AddrPortFrom(req.Web.IP, uint16(portInt))) </s> add return aghnet.CheckPort("tcp", netip.AddrPortFrom(req.Web.IP, reqPort))
https://github.com/AdguardTeam/AdGuardHome/commit/39f5c50acd9da08dca22a0a3170f3f47446210df
internal/home/config.go
keep keep keep keep replace replace replace replace replace keep keep keep keep keep
<mask> // config is the global configuration structure. <mask> // <mask> // TODO(a.garipov, e.burkov): This global is awful and must be removed. <mask> var config = &configuration{ <mask> BindPort: 3000, <mask> BindHost: netip.IPv4Unspecified(), <mask> AuthAttempts: 5, <mask> AuthBlockMin: 15, <mask> WebSessionTTLHours: 30 * 24, <mask> DNS: dnsConfig{ <mask> BindHosts: []netip.Addr{netip.IPv4Unspecified()}, <mask> Port: defaultPortDNS, <mask> FilteringConfig: dnsforward.FilteringConfig{ <mask> ProtectionEnabled: true, // whether or not use any of filtering features </s> Pull request: home: http conf Updates #2860. Squashed commit of the following: commit 0d55a99d5c0b9f1d8c9497775dd69929e5091eaa Merge: 73a203ac8 d4a4bda64 Author: Dimitry Kolyshev <[email protected]> Date: Thu Jun 29 16:25:36 2023 +0400 Merge remote-tracking branch 'origin/master' into http-yaml-conf commit 73a203ac8acf083fa289015e1f301d05bf320ea7 Author: Dimitry Kolyshev <[email protected]> Date: Thu Jun 29 16:21:48 2023 +0400 home: imp docs commit a4819ace94bfe4427f70f1b8341c9babc9234740 Author: Dimitry Kolyshev <[email protected]> Date: Thu Jun 29 11:45:30 2023 +0400 snap: imp script commit b0913c7ac5c6c46d6a73790fd57d8c5f9d7ace75 Author: Dimitry Kolyshev <[email protected]> Date: Wed Jun 28 17:34:03 2023 +0400 all: docs commit 14820d6d56f958081d9f236277fd34f356bdab33 Author: Dimitry Kolyshev <[email protected]> Date: Wed Jun 28 13:21:43 2023 +0400 home: imp tests commit 9db800d3ce39c36da7959e37b4a46736f4217e5c Author: Dimitry Kolyshev <[email protected]> Date: Wed Jun 28 13:17:34 2023 +0400 all: docs commit 9174a0ae710da51d85b4e1b1af79eda6a61dd3a2 Merge: ca8c4ae95 d88181343 Author: Dimitry Kolyshev <[email protected]> Date: Wed Jun 28 10:19:01 2023 +0400 Merge remote-tracking branch 'origin/master' into http-yaml-conf # Conflicts: # CHANGELOG.md # internal/home/upgrade.go # internal/home/upgrade_test.go commit ca8c4ae954ece25d78ef2f873bb3ba71fa4b8fa9 Author: Dimitry Kolyshev <[email protected]> Date: Wed Jun 28 10:07:15 2023 +0400 snap: imp script commit d84473f8e07b2c6e65023613eb4032fd01951521 Author: Dimitry Kolyshev <[email protected]> Date: Wed Jun 28 09:59:57 2023 +0400 snap: imp script commit 8a0808e42ddbff7d9d3345d758f91b14bb4453be Author: Dimitry Kolyshev <[email protected]> Date: Tue Jun 27 15:03:53 2023 +0400 home: http conf commit e8fbb89cc5748f9d8fa4be9e702756bd8b869de9 Author: Dimitry Kolyshev <[email protected]> Date: Tue Jun 27 14:59:37 2023 +0400 home: imp code commit 46541aabc421118562d564675dfd7e594d2056aa Author: Dimitry Kolyshev <[email protected]> Date: Tue Jun 27 12:36:14 2023 +0400 snap: bind port commit cecda5fcfd8c473db42f235b4f586b2193086997 Author: Dimitry Kolyshev <[email protected]> Date: Tue Jun 27 12:12:39 2023 +0400 docker: bind port commit 8d8945b70366c6b018616a32421c77eb281a6ea1 Author: Dimitry Kolyshev <[email protected]> Date: Tue Jun 27 11:06:32 2023 +0400 home: imp code commit ae5e8c1c4333d7b752c08605d80e41f55ee50e59 Author: Dimitry Kolyshev <[email protected]> Date: Tue Jun 27 11:02:09 2023 +0400 home: imp code commit c9ee460f37e32941b84ea5fa94d21b186d6dd82b Author: Dimitry Kolyshev <[email protected]> Date: Mon Jun 26 17:11:10 2023 +0400 home: imp code commit 44c72445112ef38d6ec9c25b197c119edd6c959f Author: Dimitry Kolyshev <[email protected]> Date: Mon Jun 26 11:52:19 2023 +0400 all: docs commit e3bf5faeb748f347b1202a496788739ff9219ed0 Merge: 38cc0f639 e7e638443 Author: Dimitry Kolyshev <[email protected]> Date: Mon Jun 26 11:39:12 2023 +0400 Merge remote-tracking branch 'origin/master' into http-yaml-conf commit 38cc0f6399040f1fa39d9da31ad6db65a6bdd4cc Author: Dimitry Kolyshev <[email protected]> Date: Mon Jun 26 11:38:17 2023 +0400 snap: bind port commit 3b9cb9e8cc89a67e55cecc7a2040c150f8675b4c Author: Dimitry Kolyshev <[email protected]> Date: Mon Jun 26 11:25:03 2023 +0400 docker: bind port ... and 4 more commits </s> remove // configuration is loaded from YAML // field ordering is important -- yaml fields will mirror ordering from here </s> add // configuration is loaded from YAML. // // Field ordering is important, YAML fields better not to be reordered, if it's // not absolutely necessary. </s> remove return aghnet.CheckPort("tcp", netip.AddrPortFrom(req.Web.IP, uint16(portInt))) </s> add return aghnet.CheckPort("tcp", netip.AddrPortFrom(req.Web.IP, reqPort)) </s> remove // BindHost is the address for the web interface server to listen on. BindHost netip.Addr `yaml:"bind_host"` // BindPort is the port for the web interface server to listen on. BindPort int `yaml:"bind_port"` </s> add // HTTPConfig is the block with http conf. HTTPConfig httpConfig `yaml:"http"` </s> remove // field ordering is important -- yaml fields will mirror ordering from here </s> add // httpConfig is a block with HTTP configuration params. // // Field ordering is important, YAML fields better not to be reordered, if it's // not absolutely necessary. type httpConfig struct { // Address is the address to serve the web UI on. Address netip.AddrPort // SessionTTL for a web session. // An active session is automatically refreshed once a day. SessionTTL timeutil.Duration `yaml:"session_ttl"` } // dnsConfig is a block with DNS configuration params. // // Field ordering is important, YAML fields better not to be reordered, if it's // not absolutely necessary. </s> remove if !conf.BindHost.IsValid() { return errors.Error("bind_host is not a valid ip address") </s> add if !conf.HTTPConfig.Address.IsValid() { return errors.Error("http.address is not a valid ip address") </s> remove switch portInt { case 0, config.BindPort: </s> add switch reqPort { case 0, config.HTTPConfig.Address.Port():
https://github.com/AdguardTeam/AdGuardHome/commit/39f5c50acd9da08dca22a0a3170f3f47446210df
internal/home/config.go
keep keep keep keep replace replace keep keep keep keep keep
<mask> <mask> // validateBindHosts returns error if any of binding hosts from configuration is <mask> // not a valid IP address. <mask> func validateBindHosts(conf *configuration) (err error) { <mask> if !conf.BindHost.IsValid() { <mask> return errors.Error("bind_host is not a valid ip address") <mask> } <mask> <mask> for i, addr := range conf.DNS.BindHosts { <mask> if !addr.IsValid() { <mask> return fmt.Errorf("dns.bind_hosts at index %d is not a valid ip address", i) </s> Pull request: home: http conf Updates #2860. Squashed commit of the following: commit 0d55a99d5c0b9f1d8c9497775dd69929e5091eaa Merge: 73a203ac8 d4a4bda64 Author: Dimitry Kolyshev <[email protected]> Date: Thu Jun 29 16:25:36 2023 +0400 Merge remote-tracking branch 'origin/master' into http-yaml-conf commit 73a203ac8acf083fa289015e1f301d05bf320ea7 Author: Dimitry Kolyshev <[email protected]> Date: Thu Jun 29 16:21:48 2023 +0400 home: imp docs commit a4819ace94bfe4427f70f1b8341c9babc9234740 Author: Dimitry Kolyshev <[email protected]> Date: Thu Jun 29 11:45:30 2023 +0400 snap: imp script commit b0913c7ac5c6c46d6a73790fd57d8c5f9d7ace75 Author: Dimitry Kolyshev <[email protected]> Date: Wed Jun 28 17:34:03 2023 +0400 all: docs commit 14820d6d56f958081d9f236277fd34f356bdab33 Author: Dimitry Kolyshev <[email protected]> Date: Wed Jun 28 13:21:43 2023 +0400 home: imp tests commit 9db800d3ce39c36da7959e37b4a46736f4217e5c Author: Dimitry Kolyshev <[email protected]> Date: Wed Jun 28 13:17:34 2023 +0400 all: docs commit 9174a0ae710da51d85b4e1b1af79eda6a61dd3a2 Merge: ca8c4ae95 d88181343 Author: Dimitry Kolyshev <[email protected]> Date: Wed Jun 28 10:19:01 2023 +0400 Merge remote-tracking branch 'origin/master' into http-yaml-conf # Conflicts: # CHANGELOG.md # internal/home/upgrade.go # internal/home/upgrade_test.go commit ca8c4ae954ece25d78ef2f873bb3ba71fa4b8fa9 Author: Dimitry Kolyshev <[email protected]> Date: Wed Jun 28 10:07:15 2023 +0400 snap: imp script commit d84473f8e07b2c6e65023613eb4032fd01951521 Author: Dimitry Kolyshev <[email protected]> Date: Wed Jun 28 09:59:57 2023 +0400 snap: imp script commit 8a0808e42ddbff7d9d3345d758f91b14bb4453be Author: Dimitry Kolyshev <[email protected]> Date: Tue Jun 27 15:03:53 2023 +0400 home: http conf commit e8fbb89cc5748f9d8fa4be9e702756bd8b869de9 Author: Dimitry Kolyshev <[email protected]> Date: Tue Jun 27 14:59:37 2023 +0400 home: imp code commit 46541aabc421118562d564675dfd7e594d2056aa Author: Dimitry Kolyshev <[email protected]> Date: Tue Jun 27 12:36:14 2023 +0400 snap: bind port commit cecda5fcfd8c473db42f235b4f586b2193086997 Author: Dimitry Kolyshev <[email protected]> Date: Tue Jun 27 12:12:39 2023 +0400 docker: bind port commit 8d8945b70366c6b018616a32421c77eb281a6ea1 Author: Dimitry Kolyshev <[email protected]> Date: Tue Jun 27 11:06:32 2023 +0400 home: imp code commit ae5e8c1c4333d7b752c08605d80e41f55ee50e59 Author: Dimitry Kolyshev <[email protected]> Date: Tue Jun 27 11:02:09 2023 +0400 home: imp code commit c9ee460f37e32941b84ea5fa94d21b186d6dd82b Author: Dimitry Kolyshev <[email protected]> Date: Mon Jun 26 17:11:10 2023 +0400 home: imp code commit 44c72445112ef38d6ec9c25b197c119edd6c959f Author: Dimitry Kolyshev <[email protected]> Date: Mon Jun 26 11:52:19 2023 +0400 all: docs commit e3bf5faeb748f347b1202a496788739ff9219ed0 Merge: 38cc0f639 e7e638443 Author: Dimitry Kolyshev <[email protected]> Date: Mon Jun 26 11:39:12 2023 +0400 Merge remote-tracking branch 'origin/master' into http-yaml-conf commit 38cc0f6399040f1fa39d9da31ad6db65a6bdd4cc Author: Dimitry Kolyshev <[email protected]> Date: Mon Jun 26 11:38:17 2023 +0400 snap: bind port commit 3b9cb9e8cc89a67e55cecc7a2040c150f8675b4c Author: Dimitry Kolyshev <[email protected]> Date: Mon Jun 26 11:25:03 2023 +0400 docker: bind port ... and 4 more commits </s> remove // field ordering is important -- yaml fields will mirror ordering from here </s> add // httpConfig is a block with HTTP configuration params. // // Field ordering is important, YAML fields better not to be reordered, if it's // not absolutely necessary. type httpConfig struct { // Address is the address to serve the web UI on. Address netip.AddrPort // SessionTTL for a web session. // An active session is automatically refreshed once a day. SessionTTL timeutil.Duration `yaml:"session_ttl"` } // dnsConfig is a block with DNS configuration params. // // Field ordering is important, YAML fields better not to be reordered, if it's // not absolutely necessary. </s> remove addPorts(tcpPorts, tcpPort(config.BindPort)) </s> add addPorts(tcpPorts, tcpPort(config.HTTPConfig.Address.Port())) </s> remove return aghnet.CheckPort("tcp", netip.AddrPortFrom(req.Web.IP, uint16(portInt))) </s> add return aghnet.CheckPort("tcp", netip.AddrPortFrom(req.Web.IP, reqPort)) </s> remove // configuration is loaded from YAML // field ordering is important -- yaml fields will mirror ordering from here </s> add // configuration is loaded from YAML. // // Field ordering is important, YAML fields better not to be reordered, if it's // not absolutely necessary. </s> remove if opts.bindPort != 0 { config.BindPort = opts.bindPort </s> add bindAddr := opts.bindAddr if bindAddr != (netip.AddrPort{}) { config.HTTPConfig.Address = bindAddr </s> remove switch portInt { case 0, config.BindPort: </s> add switch reqPort { case 0, config.HTTPConfig.Address.Port():
https://github.com/AdguardTeam/AdGuardHome/commit/39f5c50acd9da08dca22a0a3170f3f47446210df
internal/home/config.go
keep keep keep keep replace keep keep keep keep keep
<mask> return err <mask> } <mask> <mask> tcpPorts := aghalg.UniqChecker[tcpPort]{} <mask> addPorts(tcpPorts, tcpPort(config.BindPort)) <mask> <mask> udpPorts := aghalg.UniqChecker[udpPort]{} <mask> addPorts(udpPorts, udpPort(config.DNS.Port)) <mask> <mask> if config.TLS.Enabled { </s> Pull request: home: http conf Updates #2860. Squashed commit of the following: commit 0d55a99d5c0b9f1d8c9497775dd69929e5091eaa Merge: 73a203ac8 d4a4bda64 Author: Dimitry Kolyshev <[email protected]> Date: Thu Jun 29 16:25:36 2023 +0400 Merge remote-tracking branch 'origin/master' into http-yaml-conf commit 73a203ac8acf083fa289015e1f301d05bf320ea7 Author: Dimitry Kolyshev <[email protected]> Date: Thu Jun 29 16:21:48 2023 +0400 home: imp docs commit a4819ace94bfe4427f70f1b8341c9babc9234740 Author: Dimitry Kolyshev <[email protected]> Date: Thu Jun 29 11:45:30 2023 +0400 snap: imp script commit b0913c7ac5c6c46d6a73790fd57d8c5f9d7ace75 Author: Dimitry Kolyshev <[email protected]> Date: Wed Jun 28 17:34:03 2023 +0400 all: docs commit 14820d6d56f958081d9f236277fd34f356bdab33 Author: Dimitry Kolyshev <[email protected]> Date: Wed Jun 28 13:21:43 2023 +0400 home: imp tests commit 9db800d3ce39c36da7959e37b4a46736f4217e5c Author: Dimitry Kolyshev <[email protected]> Date: Wed Jun 28 13:17:34 2023 +0400 all: docs commit 9174a0ae710da51d85b4e1b1af79eda6a61dd3a2 Merge: ca8c4ae95 d88181343 Author: Dimitry Kolyshev <[email protected]> Date: Wed Jun 28 10:19:01 2023 +0400 Merge remote-tracking branch 'origin/master' into http-yaml-conf # Conflicts: # CHANGELOG.md # internal/home/upgrade.go # internal/home/upgrade_test.go commit ca8c4ae954ece25d78ef2f873bb3ba71fa4b8fa9 Author: Dimitry Kolyshev <[email protected]> Date: Wed Jun 28 10:07:15 2023 +0400 snap: imp script commit d84473f8e07b2c6e65023613eb4032fd01951521 Author: Dimitry Kolyshev <[email protected]> Date: Wed Jun 28 09:59:57 2023 +0400 snap: imp script commit 8a0808e42ddbff7d9d3345d758f91b14bb4453be Author: Dimitry Kolyshev <[email protected]> Date: Tue Jun 27 15:03:53 2023 +0400 home: http conf commit e8fbb89cc5748f9d8fa4be9e702756bd8b869de9 Author: Dimitry Kolyshev <[email protected]> Date: Tue Jun 27 14:59:37 2023 +0400 home: imp code commit 46541aabc421118562d564675dfd7e594d2056aa Author: Dimitry Kolyshev <[email protected]> Date: Tue Jun 27 12:36:14 2023 +0400 snap: bind port commit cecda5fcfd8c473db42f235b4f586b2193086997 Author: Dimitry Kolyshev <[email protected]> Date: Tue Jun 27 12:12:39 2023 +0400 docker: bind port commit 8d8945b70366c6b018616a32421c77eb281a6ea1 Author: Dimitry Kolyshev <[email protected]> Date: Tue Jun 27 11:06:32 2023 +0400 home: imp code commit ae5e8c1c4333d7b752c08605d80e41f55ee50e59 Author: Dimitry Kolyshev <[email protected]> Date: Tue Jun 27 11:02:09 2023 +0400 home: imp code commit c9ee460f37e32941b84ea5fa94d21b186d6dd82b Author: Dimitry Kolyshev <[email protected]> Date: Mon Jun 26 17:11:10 2023 +0400 home: imp code commit 44c72445112ef38d6ec9c25b197c119edd6c959f Author: Dimitry Kolyshev <[email protected]> Date: Mon Jun 26 11:52:19 2023 +0400 all: docs commit e3bf5faeb748f347b1202a496788739ff9219ed0 Merge: 38cc0f639 e7e638443 Author: Dimitry Kolyshev <[email protected]> Date: Mon Jun 26 11:39:12 2023 +0400 Merge remote-tracking branch 'origin/master' into http-yaml-conf commit 38cc0f6399040f1fa39d9da31ad6db65a6bdd4cc Author: Dimitry Kolyshev <[email protected]> Date: Mon Jun 26 11:38:17 2023 +0400 snap: bind port commit 3b9cb9e8cc89a67e55cecc7a2040c150f8675b4c Author: Dimitry Kolyshev <[email protected]> Date: Mon Jun 26 11:25:03 2023 +0400 docker: bind port ... and 4 more commits </s> remove addPorts(tcpPorts, tcpPort(config.BindPort)) </s> add addPorts(tcpPorts, tcpPort(config.HTTPConfig.Address.Port())) </s> remove bindhost := config.BindHost if !bindhost.IsUnspecified() { printWebAddrs(proto, bindhost.String(), port) </s> add bindHost := config.HTTPConfig.Address.Addr() if !bindHost.IsUnspecified() { printWebAddrs(proto, bindHost.String(), port) </s> remove if opts.bindHost.IsValid() { config.BindHost = opts.bindHost </s> add return nil </s> remove port := req.DNS.Port </s> add port := uint16(req.DNS.Port) </s> remove if tlsConfUsesPrivilegedPorts(tlsConf) || config.BindPort < 1024 || config.DNS.Port < 1024 { </s> add if tlsConfUsesPrivilegedPorts(tlsConf) || config.HTTPConfig.Address.Port() < 1024 || config.DNS.Port < 1024 { </s> remove portInt := req.Web.Port port := tcpPort(portInt) </s> add // TODO(a.garipov): Declare all port variables anywhere as uint16. reqPort := uint16(req.Web.Port) port := tcpPort(reqPort)
https://github.com/AdguardTeam/AdGuardHome/commit/39f5c50acd9da08dca22a0a3170f3f47446210df
internal/home/config.go