Added Regex destination matching

This commit is contained in:
Peter Huang
2021-07-24 21:22:03 +10:00
parent 76cd1a28e6
commit ca40be5600
3 changed files with 43 additions and 7 deletions
+24
View File
@@ -0,0 +1,24 @@
package main
import (
"regexp"
"github.com/armon/go-socks5"
"golang.org/x/net/context"
)
// PermitDestAddrPattern returns a RuleSet which selectively allows addresses
func PermitDestAddrPattern(pattern string) socks5.RuleSet {
return &PermitDestAddrPatternRuleSet{pattern}
}
// PermitDestAddrPatternRuleSet is an implementation of the RuleSet which
// enables filtering supported destination address
type PermitDestAddrPatternRuleSet struct {
AllowedFqdnPattern string
}
func (p *PermitDestAddrPatternRuleSet) Allow(ctx context.Context, req *socks5.Request) (context.Context, bool) {
match, _ := regexp.MatchString(p.AllowedFqdnPattern, req.DestAddr.FQDN)
return ctx, match
}