mirror of
https://github.com/daeuniverse/dae.git
synced 2025-07-13 01:08:39 +07:00
fix: add _ to valid domain chars set (#365)
This commit is contained in:
@ -9,7 +9,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/daeuniverse/dae/common/consts"
|
"github.com/daeuniverse/dae/common/consts"
|
||||||
"github.com/daeuniverse/dae/component/routing"
|
"github.com/daeuniverse/dae/component/routing"
|
||||||
@ -225,7 +224,6 @@ func (m *ResponseMatcher) Match(
|
|||||||
if qName == "" {
|
if qName == "" {
|
||||||
return 0, fmt.Errorf("qName cannot be empty")
|
return 0, fmt.Errorf("qName cannot be empty")
|
||||||
}
|
}
|
||||||
qName = strings.TrimSuffix(strings.ToLower(qName), ".")
|
|
||||||
domainMatchBitmap := m.domainMatcher.MatchDomainBitmap(qName)
|
domainMatchBitmap := m.domainMatcher.MatchDomainBitmap(qName)
|
||||||
bin128 := make([]string, 0, len(ips))
|
bin128 := make([]string, 0, len(ips))
|
||||||
for _, ip := range ips {
|
for _, ip := range ips {
|
||||||
|
@ -7,15 +7,16 @@ package domain_matcher
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/daeuniverse/dae/common/consts"
|
"github.com/daeuniverse/dae/common/consts"
|
||||||
"github.com/daeuniverse/dae/pkg/trie"
|
"github.com/daeuniverse/dae/pkg/trie"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/v2rayA/ahocorasick-domain"
|
"github.com/v2rayA/ahocorasick-domain"
|
||||||
"regexp"
|
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var ValidDomainChars = trie.NewValidChars([]byte("0123456789abcdefghijklmnopqrstuvwxyz-.^"))
|
var ValidDomainChars = trie.NewValidChars([]byte("0123456789abcdefghijklmnopqrstuvwxyz-.^_"))
|
||||||
|
|
||||||
type AhocorasickSlimtrie struct {
|
type AhocorasickSlimtrie struct {
|
||||||
log *logrus.Logger
|
log *logrus.Logger
|
||||||
@ -52,7 +53,7 @@ nextPattern:
|
|||||||
case consts.RoutingDomainKey_Full:
|
case consts.RoutingDomainKey_Full:
|
||||||
for _, r := range []byte(d) {
|
for _, r := range []byte(d) {
|
||||||
if !ValidDomainChars.IsValidChar(r) {
|
if !ValidDomainChars.IsValidChar(r) {
|
||||||
n.log.Warnf("DomainMatcher: skip bad full domain: %v: unexpected chat: %v", d, r)
|
n.log.Warnf("DomainMatcher: skip bad full domain: %v: unexpected char: %v", d, string(r))
|
||||||
continue nextPattern
|
continue nextPattern
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -60,7 +61,7 @@ nextPattern:
|
|||||||
case consts.RoutingDomainKey_Suffix:
|
case consts.RoutingDomainKey_Suffix:
|
||||||
for _, r := range []byte(d) {
|
for _, r := range []byte(d) {
|
||||||
if !ValidDomainChars.IsValidChar(r) {
|
if !ValidDomainChars.IsValidChar(r) {
|
||||||
n.log.Warnf("DomainMatcher: skip bad suffix domain: %v: unexpected chat: %v", d, r)
|
n.log.Warnf("DomainMatcher: skip bad suffix domain: %v: unexpected char: %v", d, string(r))
|
||||||
continue nextPattern
|
continue nextPattern
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -94,7 +94,8 @@ func TestTrie(t *testing.T) {
|
|||||||
"zib.fmc^",
|
"zib.fmc^",
|
||||||
"zk.ytamlacbci.",
|
"zk.ytamlacbci.",
|
||||||
"zk.ytamlacbci^",
|
"zk.ytamlacbci^",
|
||||||
}, NewValidChars([]byte("0123456789abcdefghijklmnopqrstuvwxyz-.^")))
|
"nc.ude.ctsu.srorrim.pct_.sptth_", // https://github.com/daeuniverse/daed/issues/400
|
||||||
|
}, NewValidChars([]byte("0123456789abcdefghijklmnopqrstuvwxyz-.^_")))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user