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 {
|
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."`
|
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"`
|
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
|
splitArgs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,6 +172,7 @@ func main() {
|
|||||||
cmnArgs = args.VLSM.common
|
cmnArgs = args.VLSM.common
|
||||||
splitter = &netsplit.VLSMSplitter{
|
splitter = &netsplit.VLSMSplitter{
|
||||||
Ascending: args.VLSM.Asc,
|
Ascending: args.VLSM.Asc,
|
||||||
|
Explicit: args.VLSM.Explicit,
|
||||||
PrefixLengths: args.VLSM.Sizes,
|
PrefixLengths: args.VLSM.Sizes,
|
||||||
BaseSplitter: new(netsplit.BaseSplitter),
|
BaseSplitter: new(netsplit.BaseSplitter),
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ package netsplit
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"sort"
|
`sort`
|
||||||
|
|
||||||
"go4.org/netipx"
|
"go4.org/netipx"
|
||||||
)
|
)
|
||||||
@ -42,17 +42,19 @@ func (v *VLSMSplitter) Split() (nets []*netip.Prefix, remaining *netipx.IPSet, e
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.SliceStable(
|
if !v.Explicit {
|
||||||
v.PrefixLengths,
|
sort.SliceStable(
|
||||||
func(i, j int) (isBefore bool) { // We use a reverse sorting by default so we get larger prefixes at the beginning.
|
v.PrefixLengths,
|
||||||
if v.Ascending {
|
func(i, j int) (isBefore bool) { // We use a reverse sorting by default so we get larger prefixes at the beginning.
|
||||||
isBefore = v.PrefixLengths[i] > v.PrefixLengths[j]
|
if v.Ascending {
|
||||||
} else {
|
isBefore = v.PrefixLengths[i] > v.PrefixLengths[j]
|
||||||
isBefore = v.PrefixLengths[i] < v.PrefixLengths[j]
|
} else {
|
||||||
}
|
isBefore = v.PrefixLengths[i] < v.PrefixLengths[j]
|
||||||
return
|
}
|
||||||
},
|
return
|
||||||
)
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
pfxLen, _ = v.network.Mask.Size()
|
pfxLen, _ = v.network.Mask.Size()
|
||||||
pfxLen8 = uint8(pfxLen)
|
pfxLen8 = uint8(pfxLen)
|
||||||
|
@ -79,6 +79,13 @@ type VLSMSplitter struct {
|
|||||||
You almost assuredly do not want to do this.
|
You almost assuredly do not want to do this.
|
||||||
*/
|
*/
|
||||||
Ascending bool
|
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 contains the prefix lengths of each subnet to split out from the network.
|
||||||
PrefixLengths []uint8 `json:"prefixes" xml:"prefixes>prefix" yaml:"Prefix Lengths"`
|
PrefixLengths []uint8 `json:"prefixes" xml:"prefixes>prefix" yaml:"Prefix Lengths"`
|
||||||
*BaseSplitter `json:"net" xml:"net,omitempty" yaml:"network,omitempty"`
|
*BaseSplitter `json:"net" xml:"net,omitempty" yaml:"network,omitempty"`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user