1
0
Fork 0
bypass/ruleset.go

43 lines
1.1 KiB
Go
Raw Normal View History

2014-01-24 03:15:53 +08:00
package socks5
import (
"net"
)
// RuleSet is used to provide custom rules to allow or prohibit actions
type RuleSet interface {
// AllowConnect is used to filter connect requests
2014-01-24 03:42:09 +08:00
AllowConnect(dstIP net.IP, dstPort int, srcIP net.IP, srcPort int) bool
2014-01-24 03:15:53 +08:00
// AllowBind is used to filter bind requests
2014-01-24 03:42:09 +08:00
AllowBind(dstIP net.IP, dstPort int, srcIP net.IP, srcPort int) bool
2014-01-24 03:15:53 +08:00
// AllowAssociate is used to filter associate requests
2014-01-24 03:42:09 +08:00
AllowAssociate(dstIP net.IP, dstPort int, srcIP net.IP, srcPort int) bool
2014-01-24 03:15:53 +08:00
}
// PermitAll is an returns a RuleSet which allows all types of connections
func PermitAll() RuleSet {
return &PermitCommand{true, true, true}
}
// PermitCommand is an implementation of the RuleSet which
// enables filtering supported commands
type PermitCommand struct {
EnableConnect bool
EnableBind bool
EnableAssociate bool
}
2014-01-24 03:42:09 +08:00
func (p *PermitCommand) AllowConnect(net.IP, int, net.IP, int) bool {
2014-01-24 03:15:53 +08:00
return p.EnableConnect
}
2014-01-24 03:42:09 +08:00
func (p *PermitCommand) AllowBind(net.IP, int, net.IP, int) bool {
2014-01-24 03:15:53 +08:00
return p.EnableBind
}
2014-01-24 03:42:09 +08:00
func (p *PermitCommand) AllowAssociate(net.IP, int, net.IP, int) bool {
2014-01-24 03:15:53 +08:00
return p.EnableAssociate
}