ADDED:
* Explicit subnet ordering option for VLSM
This commit is contained in:
brent saner
2025-04-03 18:35:35 -04:00
parent 166fb3be23
commit 0c8577f149
4 changed files with 25 additions and 14 deletions

View File

@@ -2,7 +2,7 @@ package netsplit
import (
"net/netip"
"sort"
`sort`
"go4.org/netipx"
)
@@ -42,17 +42,19 @@ func (v *VLSMSplitter) Split() (nets []*netip.Prefix, remaining *netipx.IPSet, e
return
}
sort.SliceStable(
v.PrefixLengths,
func(i, j int) (isBefore bool) { // We use a reverse sorting by default so we get larger prefixes at the beginning.
if v.Ascending {
isBefore = v.PrefixLengths[i] > v.PrefixLengths[j]
} else {
isBefore = v.PrefixLengths[i] < v.PrefixLengths[j]
}
return
},
)
if !v.Explicit {
sort.SliceStable(
v.PrefixLengths,
func(i, j int) (isBefore bool) { // We use a reverse sorting by default so we get larger prefixes at the beginning.
if v.Ascending {
isBefore = v.PrefixLengths[i] > v.PrefixLengths[j]
} else {
isBefore = v.PrefixLengths[i] < v.PrefixLengths[j]
}
return
},
)
}
pfxLen, _ = v.network.Mask.Size()
pfxLen8 = uint8(pfxLen)