ADDED:
* num-addrs subcommand, to get the number of hosts/addresses in a given
  prefix length
* get-net subcommand, to more easily get a single subnet from either the
  beginning or the end of a prefix. (MUCH FASTER than CIDR-splitting!)
This commit is contained in:
brent saner
2025-04-13 18:25:32 -04:00
parent c05f9c4d47
commit 860ad5842b
16 changed files with 334 additions and 78 deletions

View File

@@ -22,6 +22,10 @@ func (c *CIDRSplitter) Split() (nets []*netip.Prefix, remaining *netipx.IPSet, e
return
}
if err = validate.Struct(c); err != nil {
return
}
if base, ok = netipx.FromStdIPNet(c.network); !ok {
err = ErrBadBoundary
return
@@ -41,6 +45,15 @@ func (c *CIDRSplitter) Split() (nets []*netip.Prefix, remaining *netipx.IPSet, e
return
}
/*
TODO: This is *super* slow for tiny subnets in a large net.
For future optimzation, first off benchmark to make sure it makes a difference, but
chunk out the network (how to find appropriate length?) of n < x < y, where n is the network pfx len,
and goroutine each split into a channel.
Because this splits *on CIDR boundaries* and we aren't VLSM-ing, remaining never has to be considered-
it'll always be clean splitting.
See CIDRSplitter.LenSwitch.
*/
for {
if sub, remaining, ok = remaining.RemoveFreePrefix(c.PrefixLength); !ok {
if !sub.IsValid() {