2021-08-31 21:46:04 +08:00
|
|
|
package constant
|
|
|
|
|
2022-02-23 02:38:50 +08:00
|
|
|
import (
|
2022-04-20 01:52:51 +08:00
|
|
|
"net/netip"
|
2022-02-23 14:01:53 +08:00
|
|
|
"strings"
|
2022-02-23 02:38:50 +08:00
|
|
|
|
|
|
|
"github.com/Dreamacro/clash/component/geodata/router"
|
|
|
|
)
|
|
|
|
|
2021-08-31 21:46:04 +08:00
|
|
|
type RuleExtra struct {
|
2022-02-23 14:01:53 +08:00
|
|
|
Network NetWork
|
2022-04-20 01:52:51 +08:00
|
|
|
SourceIPs []*netip.Prefix
|
2022-02-23 14:01:53 +08:00
|
|
|
ProcessNames []string
|
2021-08-31 21:46:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (re *RuleExtra) NotMatchNetwork(network NetWork) bool {
|
|
|
|
return re.Network != ALLNet && re.Network != network
|
|
|
|
}
|
|
|
|
|
2022-04-20 01:52:51 +08:00
|
|
|
func (re *RuleExtra) NotMatchSourceIP(srcIP netip.Addr) bool {
|
2021-08-31 21:46:04 +08:00
|
|
|
if re.SourceIPs == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, ips := range re.SourceIPs {
|
|
|
|
if ips.Contains(srcIP) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
2022-02-23 02:38:50 +08:00
|
|
|
|
2022-02-23 14:01:53 +08:00
|
|
|
func (re *RuleExtra) NotMatchProcessName(processName string) bool {
|
|
|
|
if re.ProcessNames == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, pn := range re.ProcessNames {
|
|
|
|
if strings.EqualFold(pn, processName) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2022-02-23 02:38:50 +08:00
|
|
|
type RuleGeoSite interface {
|
|
|
|
GetDomainMatcher() *router.DomainMatcher
|
|
|
|
}
|