Feature: add source ipcidr condition for all rules
This commit is contained in:
@ -52,5 +52,5 @@ type Rule interface {
|
||||
Adapter() string
|
||||
Payload() string
|
||||
ShouldResolveIP() bool
|
||||
NetWork() NetWork
|
||||
RuleExtra() *RuleExtra
|
||||
}
|
||||
|
25
constant/rule_extra.go
Normal file
25
constant/rule_extra.go
Normal 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
|
||||
}
|
Reference in New Issue
Block a user