From 81054efa2c07598b2c0c131cc1cf0163e0a8a1be Mon Sep 17 00:00:00 2001 From: ernstjo Date: Fri, 13 Nov 2020 11:16:59 +0100 Subject: T3068: Automatic generation of IPv6 link local addresses for tunnel interfaces Tunnel interfaces hot having any IPv6 Link Local address because Linux Kernel does not assign address due to missing MAC. I have implemented a function to generate a linl local address and assign it to the interface. Link local address is required for OSPF and other protocols. --- python/vyos/ifconfig/tunnel.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'python/vyos/ifconfig') diff --git a/python/vyos/ifconfig/tunnel.py b/python/vyos/ifconfig/tunnel.py index 4122d1a2f..0c87ce3c5 100644 --- a/python/vyos/ifconfig/tunnel.py +++ b/python/vyos/ifconfig/tunnel.py @@ -22,6 +22,10 @@ from vyos.ifconfig.interface import Interface from vyos.ifconfig.afi import IP4, IP6 from vyos.validate import assert_list +import random +from random import seed, getrandbits +from ipaddress import IPv6Network, IPv6Address + def enable_to_on(value): if value == 'enable': return 'on' @@ -98,6 +102,16 @@ class _Tunnel(Interface): for k in self.options if k in self.config and self.config[k]]) self._cmd('{} {}'.format(self.create.format(**self.config), options)) self.set_admin_state('down') + + # Linux Kernel does not generate IPv6 Link Local address do to missing MAC + # We have to generate address manually and assign to interface + net = IPv6Network("FE80::/16") + rand_net = IPv6Network((net.network_address + (random.getrandbits(64 - net.prefixlen) << 64 ),64)) + network = IPv6Network(rand_net) + address = str(IPv6Address(network.network_address + getrandbits(network.max_prefixlen - network.prefixlen)))+'/'+str(network.prefixlen) + + # Assign generated IPv6 Link Local address to the interface + self.add_addr(address) def _delete(self): self.set_admin_state('down') -- cgit v1.2.3