v0.1.0
ADDED: * Explicit subnet ordering option for VLSM
This commit is contained in:
parent
166fb3be23
commit
0c8577f149
@ -88,8 +88,9 @@ type XNetArgs struct {
|
||||
}
|
||||
|
||||
type VLSMArgs struct {
|
||||
Asc bool `short:"A" long:"ascending" description:"If specified, place smaller networks (larger prefixes) at the beginning. You almost assuredly do not want to do this."`
|
||||
Sizes []uint8 `short:"s" long:"size" required:"true" description:"Prefix lengths. May be specified multiple times." validate:"required"`
|
||||
Asc bool `short:"A" long:"ascending" description:"If specified, place smaller networks (larger prefixes) at the beginning. You almost assuredly do not want to do this."`
|
||||
Explicit bool `short:"O" long:"explicit-order" description:"If specified, ignore -A/--ascending and do no reordering of prefix sizes whatsoever, instead using the order given. This is EXTREMELY suboptimal and can lead to drastic addressing waste."`
|
||||
Sizes []uint8 `short:"s" long:"size" required:"true" description:"Prefix lengths. May be specified multiple times." validate:"required"`
|
||||
splitArgs
|
||||
}
|
||||
|
||||
|
@ -172,6 +172,7 @@ func main() {
|
||||
cmnArgs = args.VLSM.common
|
||||
splitter = &netsplit.VLSMSplitter{
|
||||
Ascending: args.VLSM.Asc,
|
||||
Explicit: args.VLSM.Explicit,
|
||||
PrefixLengths: args.VLSM.Sizes,
|
||||
BaseSplitter: new(netsplit.BaseSplitter),
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -79,6 +79,13 @@ type VLSMSplitter struct {
|
||||
You almost assuredly do not want to do this.
|
||||
*/
|
||||
Ascending bool
|
||||
/*
|
||||
Explicit, if true, will ignore Ascending completely and split in the explicit order of PrefixLengths.
|
||||
|
||||
This has the potential to be *extremely* wasteful of addressing space as the resulting blocks are
|
||||
VERY unoptimized.
|
||||
*/
|
||||
Explicit bool
|
||||
// PrefixLengths contains the prefix lengths of each subnet to split out from the network.
|
||||
PrefixLengths []uint8 `json:"prefixes" xml:"prefixes>prefix" yaml:"Prefix Lengths"`
|
||||
*BaseSplitter `json:"net" xml:"net,omitempty" yaml:"network,omitempty"`
|
||||
|
Loading…
x
Reference in New Issue
Block a user