Skip to content

Commit

Permalink
Fix match 4in6 address in ip_cidr
Browse files Browse the repository at this point in the history
  • Loading branch information
nekohasekai committed Sep 9, 2022
1 parent 7aa97a3 commit ef7f2d8
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions route/rule_cidr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.ipSet.Contains(metadata.Source.Addr)
return r.match(metadata.Source.Addr)
} else {
if metadata.Destination.IsIP() {
return r.ipSet.Contains(metadata.Destination.Addr)
return r.match(metadata.Destination.Addr)
} else {
for _, address := range metadata.DestinationAddresses {
if r.ipSet.Contains(address) {
if r.match(address) {
return true
}
}
Expand All @@ -74,6 +74,14 @@ 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
}

0 comments on commit ef7f2d8

Please sign in to comment.