1
0
mirror of https://github.com/bgp/stayrtr.git synced 2024-05-06 15:54:54 +00:00

Use netip.Prefix.Overlaps() and a check on the prefixlen to see if

fPrefix covers rPrefix. This works since we only work with CIDR prefixes.
This commit is contained in:
Claudio Jeker
2023-12-21 16:05:25 +01:00
parent b91a5a53e5
commit 76b583e106

View File

@ -10,8 +10,6 @@ import (
"net"
"net/netip"
"strings"
"go4.org/netipx"
)
type SlurmPrefixFilter struct {
@ -116,13 +114,6 @@ func (s *SlurmValidationOutputFilters) FilterOnVRPs(vrps []VRPJson) (added, remo
}
for _, vrp := range vrps {
rPrefix := vrp.GetPrefix()
var rIPStart netip.Addr
var rIPEnd netip.Addr
if rPrefix.IsValid() {
r := netipx.RangeOfPrefix(rPrefix)
rIPStart = r.From()
rIPEnd = r.To()
}
var wasRemoved bool
for _, filter := range s.PrefixFilters {
@ -131,7 +122,8 @@ func (s *SlurmValidationOutputFilters) FilterOnVRPs(vrps []VRPJson) (added, remo
match := true
if match && fPrefix.IsValid() && rPrefix.IsValid() {
if !(fPrefix.Contains(rIPStart) && fPrefix.Contains(rIPEnd)) {
if !(fPrefix.Overlaps(rPrefix) &&
fPrefix.Bits() <= rPrefix.Bits()) {
match = false
}
}