Refactor: metadata use netip.Addr
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package rules
|
||||
|
||||
import (
|
||||
"net"
|
||||
"net/netip"
|
||||
|
||||
C "github.com/Dreamacro/clash/constant"
|
||||
)
|
||||
@@ -22,7 +22,7 @@ func WithIPCIDRNoResolve(noResolve bool) IPCIDROption {
|
||||
|
||||
type IPCIDR struct {
|
||||
*Base
|
||||
ipnet *net.IPNet
|
||||
ipnet *netip.Prefix
|
||||
adapter string
|
||||
isSourceIP bool
|
||||
noResolveIP bool
|
||||
@@ -40,7 +40,7 @@ func (i *IPCIDR) Match(metadata *C.Metadata) bool {
|
||||
if i.isSourceIP {
|
||||
ip = metadata.SrcIP
|
||||
}
|
||||
return ip != nil && i.ipnet.Contains(ip)
|
||||
return ip.IsValid() && i.ipnet.Contains(ip)
|
||||
}
|
||||
|
||||
func (i *IPCIDR) Adapter() string {
|
||||
@@ -56,14 +56,14 @@ func (i *IPCIDR) ShouldResolveIP() bool {
|
||||
}
|
||||
|
||||
func NewIPCIDR(s string, adapter string, opts ...IPCIDROption) (*IPCIDR, error) {
|
||||
_, ipnet, err := net.ParseCIDR(s)
|
||||
ipnet, err := netip.ParsePrefix(s)
|
||||
if err != nil {
|
||||
return nil, errPayload
|
||||
}
|
||||
|
||||
ipcidr := &IPCIDR{
|
||||
Base: &Base{},
|
||||
ipnet: ipnet,
|
||||
ipnet: &ipnet,
|
||||
adapter: adapter,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user