add special wildcard support for domain bypass

This commit is contained in:
ginuerzh 2018-06-30 13:18:58 +08:00
parent 9345a2dc2b
commit c11b5ddce8
2 changed files with 14 additions and 3 deletions

View File

@ -4,6 +4,7 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"net" "net"
"strings"
glob "github.com/gobwas/glob" glob "github.com/gobwas/glob"
) )
@ -83,11 +84,16 @@ type domainMatcher struct {
} }
// DomainMatcher creates a Matcher for a specific domain pattern, // DomainMatcher creates a Matcher for a specific domain pattern,
// the pattern can be a plain domain such as 'example.com' // the pattern can be a plain domain such as 'example.com',
// or a wildcard such as '*.exmaple.com'. // a wildcard such as '*.exmaple.com' or a special wildcard '.example.com'.
func DomainMatcher(pattern string) Matcher { func DomainMatcher(pattern string) Matcher {
p := pattern
if strings.HasPrefix(pattern, ".") {
p = pattern[1:] // trim the prefix '.'
pattern = "*" + pattern
}
return &domainMatcher{ return &domainMatcher{
pattern: pattern, pattern: p,
glob: glob.MustCompile(pattern), glob: glob.MustCompile(pattern),
} }
} }
@ -96,6 +102,10 @@ func (m *domainMatcher) Match(domain string) bool {
if m == nil || m.glob == nil { if m == nil || m.glob == nil {
return false return false
} }
if domain == m.pattern {
return true
}
return m.glob.Match(domain) return m.glob.Match(domain)
} }

View File

@ -317,6 +317,7 @@ func parseChainNode(ns string) (nodes []gost.Node, err error) {
node.Addr = ip node.Addr = ip
// override the default node address // override the default node address
node.HandshakeOptions = append(handshakeOptions, gost.AddrHandshakeOption(ip)) node.HandshakeOptions = append(handshakeOptions, gost.AddrHandshakeOption(ip))
// One node per IP
nodes = append(nodes, node) nodes = append(nodes, node)
} }
if len(ips) == 0 { if len(ips) == 0 {