From 01acb18f5fa8b82fc0da252a43e15bb1d6b0c914 Mon Sep 17 00:00:00 2001 From: brent s Date: Mon, 18 May 2020 08:13:39 -0400 Subject: [PATCH] okay, i think i fixed the range allocation issue. --- utils/he_ipv6/tunnel.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/utils/he_ipv6/tunnel.py b/utils/he_ipv6/tunnel.py index cd134c2..3f47ad4 100644 --- a/utils/he_ipv6/tunnel.py +++ b/utils/he_ipv6/tunnel.py @@ -1,5 +1,6 @@ import ipaddress import logging +import re import socket ## import netaddr @@ -130,11 +131,16 @@ class Assignment(object): self.iface_blocks = self.alloc_block.extract_subnet(self.prefix, count = 1) logger.debug('Allocation blocks for {0}: {1}'.format(self.iface, ','.join([str(i) for i in self.iface_blocks]))) for idx, i in enumerate(self.iface_blocks): + if i.prefixlen > 64: + raise ValueError('Allocation block must be a /64 or larger') # DHCPv6 range. - _base = '{0}:{1}'.format(str(i.ip).rstrip(':'), idx) + # We need to do some funky things here. Netaddr doesn't have an .exploded(). + _base = ipaddress.IPv6Address(str(i.ip)) + _base = ipaddress.IPv6Address(re.sub(r'(:0000){4}$', r':dead:beef:cafe::', str(_base.exploded))) + _base = re.sub(r':0$', r'', _base) logger.debug('Base prefix for {0}: {1}'.format(str(i), _base)) - start = '{0}:dead:beef:cafe:0'.format(_base) - stop = '{0}:dead:beef:cafe:ffff'.format(_base) + start = '{0}:0'.format(_base) + stop = '{0}:ffff'.format(_base) d_range = (start, stop) self.dhcp6_ranges.append(d_range) logger.debug('Added range {0} to block {1} for iface {2}'.format(d_range, str(i.ip), self.iface))