mirror of
https://gitclone.com/github.com/MetaCubeX/Clash.Meta
synced 2024-11-15 13:41:23 +08:00
43 lines
624 B
Go
43 lines
624 B
Go
package rules
|
|
|
|
import (
|
|
"net"
|
|
|
|
C "github.com/Dreamacro/clash/constant"
|
|
)
|
|
|
|
type IPCIDR struct {
|
|
ipnet *net.IPNet
|
|
adapter string
|
|
}
|
|
|
|
func (i *IPCIDR) RuleType() C.RuleType {
|
|
return C.IPCIDR
|
|
}
|
|
|
|
func (i *IPCIDR) IsMatch(metadata *C.Metadata) bool {
|
|
if metadata.IP == nil {
|
|
return false
|
|
}
|
|
|
|
return i.ipnet.Contains(*metadata.IP)
|
|
}
|
|
|
|
func (i *IPCIDR) Adapter() string {
|
|
return i.adapter
|
|
}
|
|
|
|
func (i *IPCIDR) Payload() string {
|
|
return i.ipnet.String()
|
|
}
|
|
|
|
func NewIPCIDR(s string, adapter string) *IPCIDR {
|
|
_, ipnet, err := net.ParseCIDR(s)
|
|
if err != nil {
|
|
}
|
|
return &IPCIDR{
|
|
ipnet: ipnet,
|
|
adapter: adapter,
|
|
}
|
|
}
|