def __init__(self, network): if "/" not in network: logging.critical("No prefix length specified for network '%s'", network) try: self._net = ip_network(network) except ValueError: logging.critical("Invalid network '%s'", network) sys.exit(1) self._subnets = defaultdict(lambda: AddressGenerator()) self._allocations = defaultdict(list) # Initialise the allocations with the supplied network, making sure to # exclude 127.0.0.0/30 (for v4) and DEFAULT6_NETWORK_ADDR/126 (for v6) # if it's contained in the network. # - .0 is treated as a broadcast address by the kernel # - .1 is the normal loopback address # - .[23] are used for clients to bind to for testing purposes. if self._net.version == 4: exclude = ip_network("127.0.0.0/30") else: exclude = ip_network(DEFAULT6_NETWORK_ADDR + "/126") if self._net.overlaps(exclude): self._exclude_net(self._net, exclude) return self._allocations[self._net.prefixlen].append(self._net)
def __init__(self, network): self._net = ip_network(network) if "/" not in network: logging.critical("No prefix length specified for network '%s'", network) sys.exit(1) self._subnets = defaultdict(lambda: AddressGenerator()) self._allocations = defaultdict(list) # Initialise the allocations with the supplied network, making sure to # exclude 127.0.0.0/30 if it's contained in the network. # - 127.0.0.0 is treated as a broadcast address by the kernel # - 127.0.0.1 is the normal loopback address # - 127.0.0.[23] are used for clients to bind to for testing purposes. v4_lo = ip_network("127.0.0.0/30") if self._net.overlaps(v4_lo): self._exclude_net(self._net, v4_lo) else: self._allocations[self._net.prefixlen].append(self._net)