diff --git a/README.md b/README.md index 79bfca0..0c72e70 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ Simple socks5 server using go-socks5 with authentication, allowed ips list and d |PROXY_USER|String|EMPTY|Set proxy user (also required existed PROXY_PASS)| |PROXY_PASSWORD|String|EMPTY|Set proxy password for auth, used with PROXY_USER| |PROXY_PORT|String|1080|Set listen port for application inside docker container| -|ALLOWED_DEST_FQDN|String|EMPTY|Allowed destination address regular expression pattern. Default allows all.| +|ALLOWED_DEST_FQDN|String|EMPTY|Allowed destination address regular expression pattern. Default allows all. Examples "(192.168.0.1|go.dev)"| |ALLOWED_IPS|String|Empty|Set allowed IP's that can connect to proxy, separator `,`| diff --git a/ruleset.go b/ruleset.go index 4b9f6d6..b83c0fe 100644 --- a/ruleset.go +++ b/ruleset.go @@ -19,6 +19,13 @@ type PermitDestAddrPatternRuleSet struct { } func (p *PermitDestAddrPatternRuleSet) Allow(ctx context.Context, req *socks5.Request) (context.Context, bool) { - match, _ := regexp.MatchString(p.AllowedFqdnPattern, req.DestAddr.FQDN) - return ctx, match + var match bool + if req.DestAddr.FQDN != nil { + match, _ = regexp.MatchString(p.AllowedFqdnPattern, *req.DestAddr.FQDN) + } else if req.DestAddr.IP != nil { + match, _ = regexp.MatchString(p.AllowedFqdnPattern, *req.DestAddr.IP) + } else { + match = true + } + return ctx, match }