Commit b1a9fec6 authored by Xavier Thompson's avatar Xavier Thompson

slapformat: WIP: Tap IPv6: default to last address of range

parent 756481fc
......@@ -474,7 +474,7 @@ class Tap(object):
"Options %r and %r for tap %s must either both be provided or neither",
'ipv4_gateway', 'ipv4_address', name
)
elif ipv4_address:
if ipv4_address:
self.ipv4_gateway = ipaddress.IPv4Interface(ipv4_gateway)
self.ipv4_address = ipaddress.IPv4Interface(ipv4_address)
elif interface.tap_ipv4_network:
......@@ -482,23 +482,27 @@ class Tap(object):
self.ipv4_address = interface.getTapIPv4Range(index)
# Tap IPv6: host-to-tap gateway and tap-to-host address
ipv6_gateway = options['ipv6_gateway']
ipv6_address = options['ipv6_address']
if not ipv6_gateway and ipv6_address:
conf.wrong(
"Options %r for tap %s must not be provided without option %r",
'ipv6_address', 'ipv6_gateway', name
)
if ipv6_gateway:
self.ipv6_gateway = ipaddress.IPv4Interface(ipv6_gateway)
ipv6_address = options['ipv6_address']
self.ipv6_gateway = ipv6_gateway = ipaddress.IPv6Interface(ipv6_gateway)
if ipv6_address:
self.ipv6_address = ipaddress.IPv6Interface(ipv6_address)
else:
self.ipv6_address = addressFromNetwork(ipv6_gateway.network, -1)
elif conf.tap_ipv6:
self.ipv6_gateway = interface.getTapIPv6Range(index)
# If needed, ipv6_address will be set to link-local in format
self.ipv6_gateway = ipv6_gateway = interface.getTapIPv6Range(index)
self.ipv6_address = addressFromNetwork(ipv6_gateway.network, -1)
def format(self, interface, user):
tap = self.name
conf = interface.conf
# Create/ensure TAP interface
self.ensureTap(user, conf)
# Find link local address if needed
if self.ipv6_gateway and not self.ipv6_address:
self.ipv6_address = interface.getIPv6LinkLocalAddress(tap)
# Create/ensure IPv4 routes
self.ensureIPv4Routes(conf)
# Create/ensure IPv6 routes
......@@ -663,22 +667,6 @@ class Interface(object):
result = network
return result
def getIPv6LinkLocalAddress(self, interface):
try:
addresses = netifaces.ifaddresses(interface)[AF_INET6]
except KeyError:
addresses = ()
for a in addresses:
address = a['addr'].split('%')[0]
netmask = a['netmask'].split('/')[-1]
ip = ipaddress.IPv6Interface('%s/%s' % (address, netmask))
if ip.is_link_local:
return ip
self.conf.abort(
"No link-local IPv6 address found on %s",
interface
)
def getComputerIPv6Addr(self):
return addressFromNetwork(self.ipv6_network, 1)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment