Refine 4in6 processing

This commit is contained in:
世界
2022-09-25 22:16:24 +08:00
parent c6586f19fa
commit c90a77a185
12 changed files with 44 additions and 60 deletions

View File

@@ -59,13 +59,13 @@ func NewIPCIDRItem(isSource bool, prefixStrings []string) (*IPCIDRItem, error) {
func (r *IPCIDRItem) Match(metadata *adapter.InboundContext) bool {
if r.isSource {
return r.match(metadata.Source.Addr)
return r.ipSet.Contains(metadata.Source.Addr)
} else {
if metadata.Destination.IsIP() {
return r.match(metadata.Destination.Addr)
return r.ipSet.Contains(metadata.Destination.Addr)
} else {
for _, address := range metadata.DestinationAddresses {
if r.match(address) {
if r.ipSet.Contains(address) {
return true
}
}
@@ -74,14 +74,6 @@ func (r *IPCIDRItem) Match(metadata *adapter.InboundContext) bool {
return false
}
func (r *IPCIDRItem) match(address netip.Addr) bool {
if address.Is4In6() {
return r.ipSet.Contains(netip.AddrFrom4(address.As4()))
} else {
return r.ipSet.Contains(address)
}
}
func (r *IPCIDRItem) String() string {
return r.description
}