let's see what i just fucked up.

This commit is contained in:
brent s. 2020-05-18 08:35:37 -04:00
parent e589e00100
commit cd422fc7d6
Signed by: bts
GPG Key ID: 8C004C2F93481F6B
2 changed files with 26 additions and 20 deletions

View File

@ -26,18 +26,19 @@ enable-ra
# {{ assignment.iface }} assignment
# Assignment blocks:
{%- for b in assignment.iface_blocks %}
# * {{ b|string }} {{ assignment.dhcp6_ranges[assign_loop.index0] }}
# * {{ b|string }}
{%- endfor %}
{%- if do_listen %}
listen-address = {{ assignment.iface_ll }}
{%- endif %}
ra-param = {{ assignment.iface }}, mtu:{{ common_opts.mtu }}, high, {{ common_opts.min_delay }}, {{ common_opts.lifetime }}
{%- if assignment.ra_dhcp %}
{%- for block in assignment.iface_blocks %}
{%- for block in assignment.assign_objs %}
{%- set dhcp_range = block.dhcp6_range|join(', ') -%}
{%- if loop.index0 == 0 %}
dhcp-range = {{ id_set }}, {{ assignment.dhcp6_ranges[assign_loop.index0]|join(', ') }}, {{ ra_opts|join(', ') }}, {{ common_opts.lease_life }}
dhcp-range = {{ id_set }}, {{ dhcp_range }}, {{ ra_opts|join(', ') }}, {{ common_opts.lease_life }}
{%- else %}
dhcp-range = {{ identifier }}, {{ assignment.dhcp6_ranges[assign_loop.index0]|join(', ') }}, {{ ra_opts|join(', ') }}, {{ common_opts.lease_life }}
dhcp-range = {{ identifier }}, {{ dhcp_range }}, {{ ra_opts|join(', ') }}, {{ common_opts.lease_life }}
{%- endif %}
{%- endfor %}
{%- else %}

View File

@ -84,7 +84,7 @@ class Assignment(object):
self.iface_ll = None
self.iface_idx = None
self.iface_blocks = []
self.dhcp6_ranges = []
self.assign_objs = []
self.alloc = None # This must be set externally to a mapped Allocation instance
self.alloc_id = None
self.prefix = None
@ -128,25 +128,30 @@ class Assignment(object):

def parse_alloc(self):
self.alloc_block = self.alloc.ip.alloc_block
self.iface_blocks = self.alloc_block.extract_subnet(self.prefix, count = 1)
for block in self.alloc_block.extract_subnet(self.prefix, count = 1):
self.iface_blocks.append(block)
self.assign_objs.append(AsssignmentBlock(block))
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.
# 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'', str(_base))
logger.debug('Base prefix for {0}: {1}'.format(str(i), _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))
return(None)


class AsssignmentBlock(object):
def __init__(self, net_net):
self.ip, self.prefix = str(net_net).split('/')
self.prefix = int(self.prefix)
self.ip = IP6(self.ip, self.prefix)
if self.prefix > 64:
raise ValueError('Allocation/Assignment block must be a /64 or larger (i.e. a smaller prefix)')
# DHCPv6 range.
# We need to do some funky things here.
_base = self.ip.ip
_base = ipaddress.IPv6Address(re.sub(r'(:0000){4}$', r':dead:beef:cafe::', str(_base.exploded)))
self.base = re.sub(r':0$', r'', str(_base))
start = '{0}:0'.format(self.base)
stop = '{0}:ffff'.format(self.base)
self.dhcp6_range = (start, stop)


class Allocation(object):
def __init__(self, alloc_net):
_ip, _prefix = alloc_net.split('/')