summaryrefslogtreecommitdiff
path: root/python/vyos/ifconfig/wireguard.py
diff options
context:
space:
mode:
authorernstjo <mail@johannesernst.com>2020-11-13 22:14:15 +0100
committerernstjo <mail@johannesernst.com>2020-11-13 22:14:15 +0100
commitb90ff025992451e9bc23cfe84328447ee7495093 (patch)
tree6910bb44d8c0425bc819675f37971d584b670aec /python/vyos/ifconfig/wireguard.py
parentc9661f01df8e22c9b462785f992e422d9587e4cc (diff)
downloadvyos-1x-b90ff025992451e9bc23cfe84328447ee7495093.tar.gz
vyos-1x-b90ff025992451e9bc23cfe84328447ee7495093.zip
T2802: Tunnel interface does not apply EUI-64 IPv6 Address
Generate an IPv6 Link Local address for wireguard interfaces.
Diffstat (limited to 'python/vyos/ifconfig/wireguard.py')
-rw-r--r--python/vyos/ifconfig/wireguard.py22
1 files changed, 21 insertions, 1 deletions
diff --git a/python/vyos/ifconfig/wireguard.py b/python/vyos/ifconfig/wireguard.py
index da3bd4e89..5e9173349 100644
--- a/python/vyos/ifconfig/wireguard.py
+++ b/python/vyos/ifconfig/wireguard.py
@@ -26,6 +26,10 @@ from vyos.ifconfig import Interface
from vyos.ifconfig import Operational
from vyos.template import is_ipv6
+import random
+from random import seed, getrandbits
+from ipaddress import IPv6Network, IPv6Address
+
class WireGuardOperational(Operational):
def _dump(self):
"""Dump wireguard data in a python friendly way."""
@@ -168,7 +172,23 @@ class WireGuardIf(Interface):
options = Interface.options + \
['port', 'private_key', 'pubkey', 'psk',
'allowed_ips', 'fwmark', 'endpoint', 'keepalive']
-
+
+
+ def generate_link_local():
+ # 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)
+
+ return address
+
+ def _create(self):
+ super()._create(self)
+ # Assign generated IPv6 Link Local address to the interface
+ self.add_addr(self.generate_link_local())
+
def update(self, config):
""" General helper function which works on a dictionary retrived by
get_config_dict(). It's main intention is to consolidate the scattered