checking in- working on fix for numhost subnetting
This commit is contained in:
parent
3c239a4d09
commit
fd344f3b8e
@ -39,7 +39,7 @@ A tool to assist in design of segregate/segment/split/subnet networks.
|
||||
** For IPv4 addresses, it will be `true` if it is an APIPA (_Automatic Private IP Addressing_) address ({rfc}3927[RFC 3927^]) (in the `169.254.0.0/16` range).
|
||||
* `First` and `Last` refer to the first and last "usable" ("host"/assignable) addresses in a subnet/network.
|
||||
** Note that for IPv6, the first address (`x::`) in a subnet *may* or *may not* be assignable/"usable". If it is assigned to a device, that device *must* be a router for anycast. See {rfc}4291#section-2.6.1[RFC 4291 § 2.6.1^] for details. In the interest of convenience, `subnetter` will report this address as *not usable/addressable* in ranges for this reason as it is technically not a "host" address.
|
||||
** Note that for IPv6, some subnetting calculators erroneously report the last address for /64's (e.g. `x:ffff:ffff:ffff:ffff/64`) as usable. They are actually reserved in strictly RFC-compliant networks for EUI-64 reasons (per {rfc}2526[RFC 2526^]). For this reason, *if and only if* a prefix is a /64 *exactly*, `subnetter` will use `x:ffff:ffff:ffff:fffe` as the last host address.
|
||||
** Note that for IPv6, some subnetting calculators erroneously report the last address as usable. They are reserved in strictly RFC-compliant networks for anycast reasons (per {rfc}2526[RFC 2526^]). Subnetter follows RFC as closely as possible, and any deviation from RFC is considered a bug -- as such, the last address of IPv6 subnets is considered *not usable/addressable*.
|
||||
** There are additional restrictions for /64 subnets, but they fall earlier in the range. These are *not explicitly excluded* in the usable host range, nor are they excluded from the total host count.
|
||||
* Private networks ({rfc}1918[RFC 1918^]), ULA prefixes ({rfc}4193[RFC 4193^]), and documentation prefixes ({rfc}3849[RFC 3849^], {rfc}5737[RFC 5737^], {rfc}9637[RFC 9637^]) are treated as "normal" networks (in that it is allowed to subnet them).
|
||||
* Various other reserved IPv4 and IPv6 addresses/networks will print warnings with their corresponding RFC(s) (unless `-R`/`--allow-reserved` is specified) if they are specified as/included in the initial prefix/network. ({rfc}6890[RFC 6890^] and its update via {rfc}8190[RFC 8190^] are useful summaries.) Note that for checking to function, an Internet connection is required as it pulls it directly from IANA live to ensure the data is accurate to standards. This may be cached locally if `-c`/`--cache-reservations` is specified, in which case a locally-cached copy will be used if present and populated then used if not.
|
||||
|
@ -4,7 +4,8 @@ import (
|
||||
"encoding/json"
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
`math`
|
||||
"math"
|
||||
"math/big"
|
||||
"net"
|
||||
"net/netip"
|
||||
"strings"
|
||||
@ -151,19 +152,19 @@ func AddrInvert(ip netip.Addr) (inverted netip.Addr) {
|
||||
}
|
||||
|
||||
/*
|
||||
CheckReserved checks nets for any reserved prefixes; either directly/explicitly,
|
||||
included *within* a reserved prefix (revRecursive), or *including* a reserved prefix (recursive).
|
||||
excludePrivate indicates if LAN networks should be considered as "reserved" or not.
|
||||
If a network is found via revRecursive/recursive, the matching prefix - not the specified one - will be in reservations.
|
||||
CheckReserved checks nets for any reserved prefixes; either directly/explicitly,
|
||||
included *within* a reserved prefix (revRecursive), or *including* a reserved prefix (recursive).
|
||||
excludePrivate indicates if LAN networks should be considered as "reserved" or not.
|
||||
If a network is found via revRecursive/recursive, the matching prefix - not the specified one - will be in reservations.
|
||||
|
||||
Any found will be returned in reservations.
|
||||
Any found will be returned in reservations.
|
||||
|
||||
If no reserved networks are found, reservations will be nil.
|
||||
If no reserved networks are found, reservations will be nil.
|
||||
|
||||
Note that prefix-specific broadcasts (e.g. x.255.255.255/8, x.x.x.255/24, ::/64, x:ffff:ffff:ffff:ffff/64, etc.)
|
||||
will *not* be considered as "reserved" as they are considered normal addresses expected for functionality.
|
||||
This primarily focuses on prefixes/subnets for this reason.
|
||||
Additionally, all of nets will be aligned to their proper boundary range/CIDR/subnet.
|
||||
Note that prefix-specific broadcasts (e.g. x.255.255.255/8, x.x.x.255/24, ::/64, x:ffff:ffff:ffff:ffff/64, etc.)
|
||||
will *not* be considered as "reserved" as they are considered normal addresses expected for functionality.
|
||||
This primarily focuses on prefixes/subnets for this reason.
|
||||
Additionally, all of nets will be aligned to their proper boundary range/CIDR/subnet.
|
||||
*/
|
||||
func CheckReserved(nets []*netip.Prefix, revRecursive, recursive, excludePrivate bool) (reservations map[netip.Prefix]*IANAAddrNetResRecord, err error) {
|
||||
|
||||
@ -377,12 +378,34 @@ func MaskInvert(mask net.IPMask) (inverted net.IPMask) {
|
||||
}
|
||||
|
||||
/*
|
||||
NumNets returns the number of times prefix size subnet fits into prefix size network.
|
||||
NumAddrsNet returns the number of IP addresses in a net.IPNet.
|
||||
|
||||
It will error if network is larger than 128 or if subnet is smaller than network.
|
||||
# The network address is included in the count if inclNet is true, otherwise it is excluded
|
||||
|
||||
This is MUCH more performant than splitting out an actual network into explicit subnets,
|
||||
and does not require an actual network.
|
||||
Only assignable addresses ("hosts") are considered if hostsOnly is true,
|
||||
otherwise all addresses are counted (depending on inclNet).
|
||||
*/
|
||||
func NumAddrsNet(pfx *net.IPNet, inclNet, hostsOnly bool) (numAddrs *big.Int) {
|
||||
|
||||
if pfx == nil {
|
||||
return
|
||||
}
|
||||
|
||||
// TODO
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// NumAddrsPfx is the exact same as NumAddrsNet but for a net/netip.Prefix instead.
|
||||
// TODO
|
||||
|
||||
/*
|
||||
NumNets returns the number of times prefix size subnet fits into prefix size network.
|
||||
|
||||
It will error if network is larger than 128 or if subnet is smaller than network.
|
||||
|
||||
This is MUCH more performant than splitting out an actual network into explicit subnets,
|
||||
and does not require an actual network.
|
||||
*/
|
||||
func NumNets(subnet, network uint8) (numNets uint, ipv6Only bool, err error) {
|
||||
|
||||
@ -397,9 +420,7 @@ func NumNets(subnet, network uint8) (numNets uint, ipv6Only bool, err error) {
|
||||
err = ErrBigPrefix
|
||||
return
|
||||
}
|
||||
if network > maxBitsv4 {
|
||||
ipv6Only = true
|
||||
}
|
||||
ipv6Only = (network > maxBitsv4) || (subnet > maxBitsv4)
|
||||
|
||||
x = float64(subnet - network)
|
||||
|
||||
|
@ -1,21 +1,22 @@
|
||||
package netsplit
|
||||
|
||||
import (
|
||||
`math/big`
|
||||
`net`
|
||||
"fmt"
|
||||
"math/big"
|
||||
"net"
|
||||
"net/netip"
|
||||
|
||||
`github.com/projectdiscovery/mapcidr`
|
||||
"github.com/projectdiscovery/mapcidr"
|
||||
"go4.org/netipx"
|
||||
)
|
||||
|
||||
/*
|
||||
Split splits the network defined in a HostSplitter alongside its configuration and performs the subnetting.
|
||||
This strategy attempts to split the network into subnets of equal number of hosts.
|
||||
Split splits the network defined in a HostSplitter alongside its configuration and performs the subnetting.
|
||||
This strategy attempts to split the network into subnets of equal number of hosts.
|
||||
|
||||
remaining may or may not be nil depending on if the number of hosts can fit cleanly within equal network sizes on boundaries.
|
||||
remaining may or may not be nil depending on if the number of hosts can fit cleanly within equal network sizes on boundaries.
|
||||
|
||||
An ErrBadNumHosts will be returned if the number of hosts does not match the *addressable* range in a prefix.
|
||||
An ErrBadNumHosts will be returned if the number of hosts does not match the *addressable* range in a prefix.
|
||||
*/
|
||||
func (h *HostSplitter) Split() (nets []*netip.Prefix, remaining *netipx.IPSet, err error) {
|
||||
|
||||
@ -34,6 +35,8 @@ func (h *HostSplitter) Split() (nets []*netip.Prefix, remaining *netipx.IPSet, e
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println(split)
|
||||
|
||||
tgt = big.NewInt(0)
|
||||
tgt.SetUint64(uint64(h.NumberHosts))
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user