1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-12-31 22:45:39 -05:00

sub domain matcher

This commit is contained in:
Darien Raymond
2017-05-08 12:18:13 +02:00
parent a0ac334703
commit a0bde091d4
6 changed files with 146 additions and 60 deletions

View File

@@ -114,6 +114,31 @@ func (v *RegexpDomainMatcher) Apply(ctx context.Context) bool {
return v.pattern.MatchString(strings.ToLower(domain))
}
type SubDomainMatcher struct {
pattern string
}
func NewSubDomainMatcher(p string) *SubDomainMatcher {
return &SubDomainMatcher{
pattern: p,
}
}
func (m *SubDomainMatcher) Apply(ctx context.Context) bool {
dest, ok := proxy.TargetFromContext(ctx)
if !ok {
return false
}
if !dest.Address.Family().IsDomain() {
return false
}
domain := dest.Address.Domain()
if !strings.HasSuffix(domain, m.pattern) {
return false
}
return len(domain) == len(m.pattern) || domain[len(domain)-len(m.pattern)-1] == '.'
}
type CIDRMatcher struct {
cidr *net.IPNet
onSource bool