Skip to content

Commit

Permalink
fix: add _ to valid domain chars set (#365)
Browse files Browse the repository at this point in the history
  • Loading branch information
mzz2017 authored Dec 26, 2023
1 parent a794c4c commit aeaf2fc
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 0 additions & 2 deletions component/dns/response_routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"fmt"
"net/netip"
"strconv"
"strings"

"github.com/daeuniverse/dae/common/consts"
"github.com/daeuniverse/dae/component/routing"
Expand Down Expand Up @@ -225,7 +224,6 @@ func (m *ResponseMatcher) Match(
if qName == "" {
return 0, fmt.Errorf("qName cannot be empty")
}
qName = strings.TrimSuffix(strings.ToLower(qName), ".")
domainMatchBitmap := m.domainMatcher.MatchDomainBitmap(qName)
bin128 := make([]string, 0, len(ips))
for _, ip := range ips {
Expand Down
11 changes: 6 additions & 5 deletions component/routing/domain_matcher/ahocorasick_slimtrie.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ package domain_matcher

import (
"fmt"
"regexp"
"strings"

"github.com/daeuniverse/dae/common/consts"
"github.com/daeuniverse/dae/pkg/trie"
"github.com/sirupsen/logrus"
"github.com/v2rayA/ahocorasick-domain"
"regexp"
"strings"
)

var ValidDomainChars = trie.NewValidChars([]byte("0123456789abcdefghijklmnopqrstuvwxyz-.^"))
var ValidDomainChars = trie.NewValidChars([]byte("0123456789abcdefghijklmnopqrstuvwxyz-.^_"))

type AhocorasickSlimtrie struct {
log *logrus.Logger
Expand Down Expand Up @@ -52,15 +53,15 @@ nextPattern:
case consts.RoutingDomainKey_Full:
for _, r := range []byte(d) {
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
}
}
n.toBuildTrie[bitIndex] = append(n.toBuildTrie[bitIndex], "^"+d+"$")
case consts.RoutingDomainKey_Suffix:
for _, r := range []byte(d) {
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
}
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/trie/trie_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ func TestTrie(t *testing.T) {
"zib.fmc^",
"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 {
t.Fatal(err)
}
Expand Down

0 comments on commit aeaf2fc

Please sign in to comment.