From 1964144258b3bfd0bf2afac07fef26d535b95eba Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Mon, 4 Nov 2019 18:30:32 +0100 Subject: list_interfaces: add wifi interfaces to bridgeable interfaces --- python/vyos/interfaces.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'python') diff --git a/python/vyos/interfaces.py b/python/vyos/interfaces.py index ecf061d17..37c093aca 100644 --- a/python/vyos/interfaces.py +++ b/python/vyos/interfaces.py @@ -59,7 +59,7 @@ def wireguard_dump(): """Dump wireguard data in a python friendly way.""" last_device=None output = {} - + # Dump wireguard connection data _f = subprocess.check_output(["wg", "show", "all", "dump"]).decode() for line in _f.split('\n'): @@ -72,14 +72,14 @@ def wireguard_dump(): # We are currently entering a new node device, private_key, public_key, listen_port, fw_mark = items last_device = device - + output[device] = { 'private_key': None if private_key == '(none)' else private_key, 'public_key': None if public_key == '(none)' else public_key, 'listen_port': int(listen_port), 'fw_mark': None if fw_mark == 'off' else int(fw_mark), 'peers': {}, - } + } else: # We are entering a peer device, public_key, preshared_key, endpoint, allowed_ips, latest_handshake, transfer_rx, transfer_tx, persistent_keepalive = items @@ -95,5 +95,5 @@ def wireguard_dump(): 'transfer_rx': int(transfer_rx), 'transfer_tx': int(transfer_tx), 'persistent_keepalive': None if persistent_keepalive == 'off' else int(persistent_keepalive), - } + } return output -- cgit v1.2.3 From a5b4d854695524b0c20b70069e5151d052aa4c19 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Mon, 4 Nov 2019 20:17:12 +0100 Subject: Python/ifconfig: T1557: do not allow both IPv4 and dhcp address on interfaces --- python/vyos/ifconfig.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'python') diff --git a/python/vyos/ifconfig.py b/python/vyos/ifconfig.py index df86e3c93..66ccc85e9 100644 --- a/python/vyos/ifconfig.py +++ b/python/vyos/ifconfig.py @@ -23,6 +23,8 @@ import time import vyos.interfaces from vyos.validate import * from vyos.config import Config +from vyos import ConfigError + from ipaddress import IPv4Network, IPv6Address from netifaces import ifaddresses, AF_INET, AF_INET6 from subprocess import Popen, PIPE, STDOUT @@ -113,6 +115,9 @@ class Interface: 'dhcpv6_temporary' : False } + # list of assigned IP addresses + self._addr = [] + def _debug_msg(self, msg): if os.path.isfile('/tmp/vyos.ifconfig.debug'): print('DEBUG/{:<6} {}'.format(self._ifname, msg)) @@ -432,6 +437,18 @@ class Interface: >>> j.get_addr() ['192.0.2.1/24', '2001:db8::ffff/64'] """ + + # cache new IP address which is assigned to interface + self._addr.append(addr) + + # we can not have both DHCP and static IPv4 addresses assigned to an interface + if 'dhcp' in self._addr: + for addr in self._addr: + # do not change below 'if' ordering esle you will get an exception as: + # ValueError: 'dhcp' does not appear to be an IPv4 or IPv6 address + if addr != 'dhcp' and is_ipv4(addr): + raise ConfigError("Can't configure both static IPv4 and DHCP address on the same interface") + if addr == 'dhcp': self._set_dhcp() elif addr == 'dhcpv6': -- cgit v1.2.3