Feature: add source ipcidr condition for all rules

This commit is contained in:
yaling888
2021-08-31 21:46:04 +08:00
parent 83c9664c17
commit 4cc16e0136
14 changed files with 155 additions and 93 deletions

View File

@ -52,5 +52,5 @@ type Rule interface {
Adapter() string
Payload() string
ShouldResolveIP() bool
NetWork() NetWork
RuleExtra() *RuleExtra
}

25
constant/rule_extra.go Normal file
View File

@ -0,0 +1,25 @@
package constant
import "net"
type RuleExtra struct {
Network NetWork
SourceIPs []*net.IPNet
}
func (re *RuleExtra) NotMatchNetwork(network NetWork) bool {
return re.Network != ALLNet && re.Network != network
}
func (re *RuleExtra) NotMatchSourceIP(srcIP net.IP) bool {
if re.SourceIPs == nil {
return false
}
for _, ips := range re.SourceIPs {
if ips.Contains(srcIP) {
return false
}
}
return true
}