summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorernstjo <mail@johannesernst.com>2020-11-13 11:16:59 +0100
committerernstjo <mail@johannesernst.com>2020-11-13 11:16:59 +0100
commit81054efa2c07598b2c0c131cc1cf0163e0a8a1be (patch)
tree932e83b717238dfd889712074a0d893640ea3f43
parent62320efc3866fa582852258846c15bfa09a92720 (diff)
downloadvyos-1x-81054efa2c07598b2c0c131cc1cf0163e0a8a1be.tar.gz
vyos-1x-81054efa2c07598b2c0c131cc1cf0163e0a8a1be.zip
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.
-rw-r--r--python/vyos/ifconfig/tunnel.py14
1 files changed, 14 insertions, 0 deletions
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')