Pull request 1966: 6050 upd urlfilter
Merge in DNS/adguard-home from upd-urlfilter to master Updates #6050. Squashed commit of the following: commit 80337ab02d616e25fa455e46c9535c088b5c5ea5 Merge: fb2cfd1a531f7aaeccAuthor: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Wed Aug 23 16:50:49 2023 +0300 Merge branch 'master' into upd-urlfilter commit fb2cfd1a5c94d92030fc8832615764f100d010e5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Wed Aug 23 16:22:43 2023 +0300 dnsforward: imp code, docs commit 2900333bb85d4e064db9de27bd5bfe7c3ef00747 Merge: 977ed35e42bfc9fcb1Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 22 18:06:05 2023 +0300 Merge branch 'master' into upd-urlfilter commit 977ed35e4ed377f1031721d58e0fcb58de1e74ac Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 22 17:06:30 2023 +0300 all: log changes commit 1228a0770485799bf50bbe68005dbb0ba9a96a9c Merge: 78305eb2e4b4036fa6Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 22 16:51:42 2023 +0300 Merge branch 'master' into upd-urlfilter commit 78305eb2ebc3854dd11ce35d6b4c7eecccd7cc78 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 22 15:55:05 2023 +0300 all: upd urlfilter commit 63a29e18d5034e5f9433121ff7e7c45aebfa1f0f Merge: 748c53430762e5be97Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Aug 21 20:12:49 2023 +0300 Merge branch 'master' into upd-urlfilter commit 748c5343020b0c6d4d4f16eb3d30b875c0a94e0f Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Aug 21 20:07:44 2023 +0300 all: imp code, docs commit 91975140f3305a6793e07142f7c9a75120a4ce8c Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Aug 17 16:16:19 2023 +0300 all: upd urlfilter
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"net/netip"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -183,7 +184,11 @@ func decodeResultRuleKey(key string, i int, dec *json.Decoder, ent *logEntry) {
|
||||
case "IP":
|
||||
ent.Result.Rules, vToken = decodeVTokenAndAddRule(key, i, dec, ent.Result.Rules)
|
||||
if ipStr, ok := vToken.(string); ok {
|
||||
ent.Result.Rules[i].IP = net.ParseIP(ipStr)
|
||||
if ip, err := netip.ParseAddr(ipStr); err == nil {
|
||||
ent.Result.Rules[i].IP = ip
|
||||
} else {
|
||||
log.Debug("querylog: decoding ipStr value: %s", err)
|
||||
}
|
||||
}
|
||||
case "Text":
|
||||
ent.Result.Rules, vToken = decodeVTokenAndAddRule(key, i, dec, ent.Result.Rules)
|
||||
@@ -362,8 +367,9 @@ func decodeResultIPList(dec *json.Decoder, ent *logEntry) {
|
||||
|
||||
return
|
||||
case string:
|
||||
ip := net.ParseIP(v)
|
||||
if ip != nil {
|
||||
var ip netip.Addr
|
||||
ip, err = netip.ParseAddr(v)
|
||||
if err == nil {
|
||||
ent.Result.IPList = append(ent.Result.IPList, ip)
|
||||
}
|
||||
default:
|
||||
@@ -462,7 +468,7 @@ func translateResult(ent *logEntry) {
|
||||
resp := res.DNSRewriteResult.Response
|
||||
for _, ip := range res.IPList {
|
||||
qType := dns.TypeAAAA
|
||||
if ip.To4() != nil {
|
||||
if ip.Is4() {
|
||||
qType = dns.TypeA
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"net"
|
||||
"net/netip"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -11,6 +12,7 @@ import (
|
||||
"github.com/AdguardTeam/AdGuardHome/internal/aghtest"
|
||||
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
|
||||
"github.com/AdguardTeam/golibs/log"
|
||||
"github.com/AdguardTeam/golibs/netutil"
|
||||
"github.com/AdguardTeam/urlfilter/rules"
|
||||
"github.com/miekg/dns"
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -71,15 +73,15 @@ func TestDecodeLogEntry(t *testing.T) {
|
||||
},
|
||||
CanonName: "example.com",
|
||||
ServiceName: "example.org",
|
||||
IPList: []net.IP{net.IPv4(127, 0, 0, 2)},
|
||||
IPList: []netip.Addr{netip.AddrFrom4([4]byte{127, 0, 0, 2})},
|
||||
Rules: []*filtering.ResultRule{{
|
||||
FilterListID: 42,
|
||||
Text: "||an.yandex.ru",
|
||||
IP: net.IPv4(127, 0, 0, 2),
|
||||
IP: netip.AddrFrom4([4]byte{127, 0, 0, 2}),
|
||||
}, {
|
||||
FilterListID: 43,
|
||||
Text: "||an2.yandex.ru",
|
||||
IP: net.IPv4(127, 0, 0, 3),
|
||||
IP: netip.AddrFrom4([4]byte{127, 0, 0, 3}),
|
||||
}},
|
||||
Reason: filtering.FilteredBlockList,
|
||||
IsFiltered: true,
|
||||
@@ -192,8 +194,10 @@ func TestDecodeLogEntry(t *testing.T) {
|
||||
|
||||
func TestDecodeLogEntry_backwardCompatability(t *testing.T) {
|
||||
var (
|
||||
a1, a2 = net.IP{127, 0, 0, 1}.To16(), net.IP{127, 0, 0, 2}.To16()
|
||||
aaaa1, aaaa2 = net.ParseIP("::1"), net.ParseIP("::2")
|
||||
a1 = netutil.IPv4Localhost()
|
||||
a2 = a1.Next()
|
||||
aaaa1 = netutil.IPv6Localhost()
|
||||
aaaa2 = aaaa1.Next()
|
||||
)
|
||||
|
||||
testCases := []struct {
|
||||
@@ -230,7 +234,7 @@ func TestDecodeLogEntry_backwardCompatability(t *testing.T) {
|
||||
entry: `{"Result":{"IPList":["127.0.0.1","127.0.0.2","::1","::2"],"Reason":9}}`,
|
||||
want: &logEntry{
|
||||
Result: filtering.Result{
|
||||
IPList: []net.IP{
|
||||
IPList: []netip.Addr{
|
||||
a1,
|
||||
a2,
|
||||
aaaa1,
|
||||
|
||||
Reference in New Issue
Block a user