v0.1.0
ADDED: * Explicit subnet ordering option for VLSM
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user