From d77f68ef3198cff019e1e2d74dfe2290800a1ea6 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Tue, 24 Sep 2019 18:04:17 +0200 Subject: Python/ifconfig: T1557: refactor 'mtu' property to get_mtu()/set_mtu() --- src/conf_mode/interface-bonding.py | 6 ++---- src/conf_mode/interface-bridge.py | 2 -- src/conf_mode/interface-dummy.py | 7 +++---- src/conf_mode/interface-ethernet.py | 4 ++-- src/conf_mode/interface-loopback.py | 6 +++--- src/conf_mode/interface-openvpn.py | 6 ++---- src/conf_mode/interface-vxlan.py | 10 +++++----- src/conf_mode/interface-wireguard.py | 8 +++----- 8 files changed, 20 insertions(+), 29 deletions(-) (limited to 'src') diff --git a/src/conf_mode/interface-bonding.py b/src/conf_mode/interface-bonding.py index 9049913e6..4a91619f1 100755 --- a/src/conf_mode/interface-bonding.py +++ b/src/conf_mode/interface-bonding.py @@ -13,8 +13,6 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . -# -# import os @@ -90,7 +88,7 @@ def apply_vlan_config(vlan, config): # ignore link state changes vlan.link_detect = config['disable_link_detect'] # Maximum Transmission Unit (MTU) - vlan.mtu = config['mtu'] + vlan.set_mtu(config['mtu']) # Change VLAN interface MAC address if config['mac']: vlan.mac = config['mac'] @@ -395,7 +393,7 @@ def apply(bond): # Bonding policy b.mode = bond['mode'] # Maximum Transmission Unit (MTU) - b.mtu = bond['mtu'] + b.set_mtu(bond['mtu']) # Primary device interface if bond['primary']: diff --git a/src/conf_mode/interface-bridge.py b/src/conf_mode/interface-bridge.py index 62589c798..cb768e082 100755 --- a/src/conf_mode/interface-bridge.py +++ b/src/conf_mode/interface-bridge.py @@ -13,8 +13,6 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . -# -# import os diff --git a/src/conf_mode/interface-dummy.py b/src/conf_mode/interface-dummy.py index 614fe08db..1b3fbcc93 100755 --- a/src/conf_mode/interface-dummy.py +++ b/src/conf_mode/interface-dummy.py @@ -13,10 +13,9 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . -# -# -from os import environ +import os + from copy import deepcopy from sys import exit @@ -40,7 +39,7 @@ def get_config(): # determine tagNode instance try: - dummy['intf'] = environ['VYOS_TAGNODE_VALUE'] + dummy['intf'] = os.environ['VYOS_TAGNODE_VALUE'] except KeyError as E: print("Interface not specified") diff --git a/src/conf_mode/interface-ethernet.py b/src/conf_mode/interface-ethernet.py index 5d597fd0a..43e598618 100755 --- a/src/conf_mode/interface-ethernet.py +++ b/src/conf_mode/interface-ethernet.py @@ -71,7 +71,7 @@ def apply_vlan_config(vlan, config): # ignore link state changes vlan.link_detect = config['disable_link_detect'] # Maximum Transmission Unit (MTU) - vlan.mtu = config['mtu'] + vlan.set_mtu(config['mtu']) # Change VLAN interface MAC address if config['mac']: vlan.mac = config['mac'] @@ -296,7 +296,7 @@ def apply(eth): e.mac = eth['hw_id'] # Maximum Transmission Unit (MTU) - e.mtu = eth['mtu'] + e.set_mtu(eth['mtu']) # GRO (generic receive offload) e.set_gro(eth['offload_gro']) diff --git a/src/conf_mode/interface-loopback.py b/src/conf_mode/interface-loopback.py index a1a807868..aba682f31 100755 --- a/src/conf_mode/interface-loopback.py +++ b/src/conf_mode/interface-loopback.py @@ -13,9 +13,9 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . -# -from os import environ +import os + from sys import exit from copy import deepcopy @@ -38,7 +38,7 @@ def get_config(): # determine tagNode instance try: - loopback['intf'] = environ['VYOS_TAGNODE_VALUE'] + loopback['intf'] = os.environ['VYOS_TAGNODE_VALUE'] except KeyError as E: print("Interface not specified") diff --git a/src/conf_mode/interface-openvpn.py b/src/conf_mode/interface-openvpn.py index 35e7928c2..fa01f7fc5 100755 --- a/src/conf_mode/interface-openvpn.py +++ b/src/conf_mode/interface-openvpn.py @@ -13,8 +13,6 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . -# -# import os import re @@ -580,7 +578,7 @@ def get_config(): # Minimum required TLS version if conf.exists('tls tls-version-min'): openvpn['tls_version_min'] = conf.return_value('tls tls-version-min') - + if conf.exists('shared-secret-key-file'): openvpn['shared_secret_file'] = conf.return_value('shared-secret-key-file') @@ -736,7 +734,7 @@ def verify(openvpn): if openvpn['tls_auth']: if not checkCertHeader('-----BEGIN OpenVPN Static key V1-----', openvpn['tls_auth']): raise ConfigError('Specified auth-file "{}" is invalid'.format(openvpn['tls_auth'])) - + if openvpn['tls_cert']: if not checkCertHeader('-----BEGIN CERTIFICATE-----', openvpn['tls_cert']): raise ConfigError('Specified cert-file "{}" is invalid'.format(openvpn['tls_cert'])) diff --git a/src/conf_mode/interface-vxlan.py b/src/conf_mode/interface-vxlan.py index e97b4bf99..f0fa7596a 100755 --- a/src/conf_mode/interface-vxlan.py +++ b/src/conf_mode/interface-vxlan.py @@ -13,9 +13,9 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . -# -from os import environ +import os + from sys import exit from copy import deepcopy @@ -48,7 +48,7 @@ def get_config(): # determine tagNode instance try: - vxlan['intf'] = environ['VYOS_TAGNODE_VALUE'] + vxlan['intf'] = os.environ['VYOS_TAGNODE_VALUE'] except KeyError as E: print("Interface not specified") @@ -127,7 +127,7 @@ def verify(vxlan): if vxlan['link']: # VXLAN adds a 50 byte overhead - we need to check the underlaying MTU # if our configured MTU is at least 50 bytes less - underlay_mtu = int(Interface(vxlan['link']).mtu) + underlay_mtu = int(Interface(vxlan['link']).get_mtu()) if underlay_mtu < (vxlan['mtu'] + 50): raise ConfigError('VXLAN has a 50 byte overhead, underlaying device ' \ 'MTU is to small ({})'.format(underlay_mtu)) @@ -165,7 +165,7 @@ def apply(vxlan): # update interface description used e.g. by SNMP v.ifalias = vxlan['description'] # Maximum Transfer Unit (MTU) - v.mtu = vxlan['mtu'] + v.set_mtu(vxlan['mtu']) # configure ARP cache timeout in milliseconds v.arp_cache_tmp = vxlan['ip_arp_cache_tmo'] diff --git a/src/conf_mode/interface-wireguard.py b/src/conf_mode/interface-wireguard.py index 4ae3251fe..069298265 100755 --- a/src/conf_mode/interface-wireguard.py +++ b/src/conf_mode/interface-wireguard.py @@ -13,8 +13,6 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . -# -# import sys import os @@ -97,7 +95,7 @@ def get_config(): if c.exists(ifname + ' mtu'): config_data[ifname]['mtu'] = c.return_value(ifname + ' mtu') if c.exists(ifname + ' private-key'): - config_data[ifname]['pk'] = "{0}/{1}/private.key".format(kdir,c.return_value(ifname + ' private-key')) + config_data[ifname]['pk'] = "{0}/{1}/private.key".format(kdir,c.return_value(ifname + ' private-key')) if c.exists(ifname + ' peer'): for p in c.list_nodes(ifname + ' peer'): if not c.exists(ifname + ' peer ' + p + ' disable'): @@ -204,10 +202,10 @@ def apply(c): # interface MTU if c[ifname]['mtu'] != 1420: - intfc.mtu = int(c[ifname]['mtu']) + intfc.set_mtu(int(c[ifname]['mtu'])) else: # default is set to 1420 in config_data - intfc.mtu = int(c[ifname]['mtu']) + intfc.set_mtu(int(c[ifname]['mtu'])) # ifalias for snmp from description descr_eff = c_eff.return_effective_value(ifname + ' description') -- cgit v1.2.3 From d80398b6542b24042961ff6eae657c58c98d93c3 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Tue, 24 Sep 2019 18:10:39 +0200 Subject: Python/ifconfig: T1557: refactor 'mac' property to set_mac() --- python/vyos/ifconfig.py | 22 +++------------------- src/conf_mode/interface-bonding.py | 4 ++-- src/conf_mode/interface-bridge.py | 2 +- src/conf_mode/interface-ethernet.py | 6 +++--- 4 files changed, 9 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/python/vyos/ifconfig.py b/python/vyos/ifconfig.py index a128c3d54..afc7bbbf8 100644 --- a/python/vyos/ifconfig.py +++ b/python/vyos/ifconfig.py @@ -173,29 +173,13 @@ class Interface: return self._write_sysfs('/sys/class/net/{}/mtu' .format(self._ifname), mtu) - @property - def mac(self): - """ - Get/set interface mac address - - Example: - >>> from vyos.ifconfig import Interface - >>> Interface('eth0').mac - '00:0c:29:11:aa:cc' - """ - return self._read_sysfs('/sys/class/net/{}/address' - .format(self._ifname)) - - @mac.setter - def mac(self, mac): + def set_mac(self, mac): """ - Get/set interface mac address + Set interface MAC (Media Access Contrl) address to given value. Example: >>> from vyos.ifconfig import Interface - >>> Interface('eth0').mac = '00:90:43:fe:fe:1b' - >>> Interface('eth0').mac - '00:90:43:fe:fe:1b' + >>> Interface('eth0').set_mac('00:50:ab:cd:ef:01') """ # on interface removal (ethernet) an empty string is passed - ignore it if not mac: diff --git a/src/conf_mode/interface-bonding.py b/src/conf_mode/interface-bonding.py index 4a91619f1..fddc73b0f 100755 --- a/src/conf_mode/interface-bonding.py +++ b/src/conf_mode/interface-bonding.py @@ -91,7 +91,7 @@ def apply_vlan_config(vlan, config): vlan.set_mtu(config['mtu']) # Change VLAN interface MAC address if config['mac']: - vlan.mac = config['mac'] + vlan.set_mac(config['mac']) # enable/disable VLAN interface if config['disable']: @@ -388,7 +388,7 @@ def apply(bond): # Change interface MAC address if bond['mac']: - b.mac = bond['mac'] + b.set_mac(bond['mac']) # Bonding policy b.mode = bond['mode'] diff --git a/src/conf_mode/interface-bridge.py b/src/conf_mode/interface-bridge.py index cb768e082..6be7d6714 100755 --- a/src/conf_mode/interface-bridge.py +++ b/src/conf_mode/interface-bridge.py @@ -205,7 +205,7 @@ def apply(bridge): # Change interface MAC address if bridge['mac']: - br.mac = bridge['mac'] + br.set_mac(bridge['mac']) # remove interface from bridge for intf in bridge['member_remove']: diff --git a/src/conf_mode/interface-ethernet.py b/src/conf_mode/interface-ethernet.py index 43e598618..7708c0086 100755 --- a/src/conf_mode/interface-ethernet.py +++ b/src/conf_mode/interface-ethernet.py @@ -74,7 +74,7 @@ def apply_vlan_config(vlan, config): vlan.set_mtu(config['mtu']) # Change VLAN interface MAC address if config['mac']: - vlan.mac = config['mac'] + vlan.set_mac(config['mac']) # enable/disable VLAN interface if config['disable']: @@ -291,9 +291,9 @@ def apply(eth): # Change interface MAC address - re-set to real hardware address (hw-id) # if custom mac is removed if eth['mac']: - e.mac = eth['mac'] + e.set_mac(eth['mac']) else: - e.mac = eth['hw_id'] + e.set_mac(eth['hw_id']) # Maximum Transmission Unit (MTU) e.set_mtu(eth['mtu']) -- cgit v1.2.3 From 1e373c5ea5a8ac6a5a4f99376d6399b82df00efa Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Tue, 24 Sep 2019 18:15:01 +0200 Subject: Python/ifconfig: T1557: refactor BondIf 'primary' property to set_primary() --- python/vyos/ifconfig.py | 26 ++------------------------ src/conf_mode/interface-bonding.py | 2 +- 2 files changed, 3 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/python/vyos/ifconfig.py b/python/vyos/ifconfig.py index afc7bbbf8..f55c5fd5c 100644 --- a/python/vyos/ifconfig.py +++ b/python/vyos/ifconfig.py @@ -1516,28 +1516,8 @@ class BondIf(VLANIf): .format(self._ifname)) return list(map(str, slaves.split())) - @property - def primary(self): - """ - A string (eth0, eth2, etc) specifying which slave is the primary - device. The specified device will always be the active slave while it - is available. Only when the primary is off-line will alternate devices - be used. This is useful when one slave is preferred over another, e.g., - when one slave has higher throughput than another. - - The primary option is only valid for active-backup, balance-tlb and - balance-alb mode. - - Example: - >>> from vyos.ifconfig import BondIf - >>> BondIf('bond0').primary - 'eth1' - """ - return self._read_sysfs('/sys/class/net/{}/bonding/primary' - .format(self._ifname)) - @primary.setter - def primary(self, interface): + def set_primary(self, interface): """ A string (eth0, eth2, etc) specifying which slave is the primary device. The specified device will always be the active slave while it @@ -1550,9 +1530,7 @@ class BondIf(VLANIf): Example: >>> from vyos.ifconfig import BondIf - >>> BondIf('bond0').primary = 'eth2' - >>> BondIf('bond0').primary - 'eth2' + >>> BondIf('bond0').set_primary('eth2') """ if not interface: # reset primary interface diff --git a/src/conf_mode/interface-bonding.py b/src/conf_mode/interface-bonding.py index fddc73b0f..83cd2facc 100755 --- a/src/conf_mode/interface-bonding.py +++ b/src/conf_mode/interface-bonding.py @@ -397,7 +397,7 @@ def apply(bond): # Primary device interface if bond['primary']: - b.primary = bond['primary'] + b.set_primary(bond['primary']) # Add (enslave) interfaces to bond for intf in bond['member']: -- cgit v1.2.3 From 63dbedffa7c053e11d0ba5f538d12cbfc8b9e73f Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Tue, 24 Sep 2019 18:17:05 +0200 Subject: Python/ifconfig: T1557: refactor BridgeIf 'multicast_querier' property to set_multicast_querier() --- python/vyos/ifconfig.py | 18 +++--------------- src/conf_mode/interface-bridge.py | 2 +- 2 files changed, 4 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/python/vyos/ifconfig.py b/python/vyos/ifconfig.py index f55c5fd5c..0c3a3d0c8 100644 --- a/python/vyos/ifconfig.py +++ b/python/vyos/ifconfig.py @@ -909,21 +909,8 @@ class BridgeIf(Interface): else: raise ValueError("Value out of range") - @property - def multicast_querier(self): - """ - Get bridge multicast querier membership state. - Example: - >>> from vyos.ifconfig import Interface - >>> BridgeIf('br0').multicast_querier - '0' - """ - return self._read_sysfs('/sys/class/net/{}/bridge/multicast_querier' - .format(self._ifname)) - - @multicast_querier.setter - def multicast_querier(self, enable): + def set_multicast_querier(self, enable): """ Sets whether the bridge actively runs a multicast querier or not. When a bridge receives a 'multicast host membership' query from another network @@ -934,7 +921,7 @@ class BridgeIf(Interface): Example: >>> from vyos.ifconfig import Interface - >>> BridgeIf('br0').multicast_querier = 1 + >>> BridgeIf('br0').set_multicast_querier(1) """ if int(enable) >= 0 and int(enable) <= 1: return self._write_sysfs('/sys/class/net/{}/bridge/multicast_querier' @@ -942,6 +929,7 @@ class BridgeIf(Interface): else: raise ValueError("Value out of range") + def add_port(self, interface): """ Add physical interface to bridge (member port) diff --git a/src/conf_mode/interface-bridge.py b/src/conf_mode/interface-bridge.py index 6be7d6714..0adbb0617 100755 --- a/src/conf_mode/interface-bridge.py +++ b/src/conf_mode/interface-bridge.py @@ -199,7 +199,7 @@ def apply(bridge): # turn stp on/off br.stp_state = bridge['stp'] # enable or disable IGMP querier - br.multicast_querier = bridge['igmp_querier'] + br.set_multicast_querier(bridge['igmp_querier']) # update interface description used e.g. within SNMP br.ifalias = bridge['description'] -- cgit v1.2.3 From 1f5bfafc572a26b84c60a2e37d2dffa1e5fc0dfb Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Tue, 24 Sep 2019 18:19:37 +0200 Subject: Python/ifconfig: T1557: refactor BridgeIf 'max_age' property to set_max_age() --- python/vyos/ifconfig.py | 20 ++------------------ src/conf_mode/interface-bridge.py | 2 +- 2 files changed, 3 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/python/vyos/ifconfig.py b/python/vyos/ifconfig.py index 0c3a3d0c8..c3dcd86c5 100644 --- a/python/vyos/ifconfig.py +++ b/python/vyos/ifconfig.py @@ -823,30 +823,14 @@ class BridgeIf(Interface): return self._write_sysfs('/sys/class/net/{}/bridge/hello_time' .format(self._ifname), (int(time) * 100)) - @property - def max_age(self): - """ - Get bridge max max message age in seconds. Internal Kernel representation - is in centiseconds. - - Example: - >>> from vyos.ifconfig import Interface - >>> BridgeIf('br0').max_age - '20' - """ - - return (self._read_sysfs('/sys/class/net/{}/bridge/max_age' - .format(self._ifname)) / 100) - - @max_age.setter - def max_age(self, time): + def set_max_age(self, time): """ Set bridge max message age in seconds. Internal Kernel representation is in centiseconds. Example: >>> from vyos.ifconfig import Interface - >>> BridgeIf('br0').max_age = 30 + >>> BridgeIf('br0').set_max_age(30) """ return self._write_sysfs('/sys/class/net/{}/bridge/max_age' .format(self._ifname), (int(time) * 100)) diff --git a/src/conf_mode/interface-bridge.py b/src/conf_mode/interface-bridge.py index 0adbb0617..3690a144e 100755 --- a/src/conf_mode/interface-bridge.py +++ b/src/conf_mode/interface-bridge.py @@ -193,7 +193,7 @@ def apply(bridge): # set hello time br.hello_time = bridge['hello_time'] # set max message age - br.max_age = bridge['max_age'] + br.set_max_age(bridge['max_age']) # set bridge priority br.priority = bridge['priority'] # turn stp on/off -- cgit v1.2.3 From a9ef9748ce48e96b1c0be0237f77bd8e951ef69a Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Tue, 24 Sep 2019 18:21:05 +0200 Subject: Python/ifconfig: T1557: refactor BridgeIf 'forward_delay' property to set_forward_delay() --- python/vyos/ifconfig.py | 21 +++------------------ src/conf_mode/interface-bridge.py | 2 +- 2 files changed, 4 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/python/vyos/ifconfig.py b/python/vyos/ifconfig.py index c3dcd86c5..2a30857ab 100644 --- a/python/vyos/ifconfig.py +++ b/python/vyos/ifconfig.py @@ -769,29 +769,14 @@ class BridgeIf(Interface): return self._write_sysfs('/sys/class/net/{}/bridge/ageing_time' .format(self._ifname), time) - @property - def forward_delay(self): - """ - Get bridge forwarding delay in seconds. Internal Kernel representation - is in centiseconds. - - Example: - >>> from vyos.ifconfig import Interface - >>> BridgeIf('br0').ageing_time - '3' - """ - return (self._read_sysfs('/sys/class/net/{}/bridge/forward_delay' - .format(self._ifname)) / 100) - - @forward_delay.setter - def forward_delay(self, time): + def set_forward_delay(self, time): """ Set bridge forwarding delay in seconds. Internal Kernel representation is in centiseconds. Example: - >>> from vyos.ifconfig import Interface - >>> BridgeIf('br0').forward_delay = 15 + >>> from vyos.ifconfig import BridgeIf + >>> BridgeIf('br0').forward_delay(15) """ return self._write_sysfs('/sys/class/net/{}/bridge/forward_delay' .format(self._ifname), (int(time) * 100)) diff --git a/src/conf_mode/interface-bridge.py b/src/conf_mode/interface-bridge.py index 3690a144e..7380799ee 100755 --- a/src/conf_mode/interface-bridge.py +++ b/src/conf_mode/interface-bridge.py @@ -189,7 +189,7 @@ def apply(bridge): # set ageing time br.ageing_time = bridge['aging'] # set bridge forward delay - br.forward_delay = bridge['forwarding_delay'] + br.set_forward_delay(bridge['forwarding_delay']) # set hello time br.hello_time = bridge['hello_time'] # set max message age -- cgit v1.2.3 From e41213fd082603a7c70e518e52582b7600af8589 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Tue, 24 Sep 2019 18:22:25 +0200 Subject: Python/ifconfig: T1557: refactor BridgeIf 'hello_time' property to set_hello_time() --- python/vyos/ifconfig.py | 21 +++------------------ src/conf_mode/interface-bridge.py | 2 +- 2 files changed, 4 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/python/vyos/ifconfig.py b/python/vyos/ifconfig.py index 2a30857ab..e10e01e2f 100644 --- a/python/vyos/ifconfig.py +++ b/python/vyos/ifconfig.py @@ -781,29 +781,14 @@ class BridgeIf(Interface): return self._write_sysfs('/sys/class/net/{}/bridge/forward_delay' .format(self._ifname), (int(time) * 100)) - @property - def hello_time(self): - """ - Get bridge hello time in seconds. Internal Kernel representation - is in centiseconds. - - Example: - >>> from vyos.ifconfig import Interface - >>> BridgeIf('br0').hello_time - '2' - """ - return (self._read_sysfs('/sys/class/net/{}/bridge/hello_time' - .format(self._ifname)) / 100) - - @hello_time.setter - def hello_time(self, time): + def set_hello_time(self, time): """ Set bridge hello time in seconds. Internal Kernel representation is in centiseconds. Example: - >>> from vyos.ifconfig import Interface - >>> BridgeIf('br0').hello_time = 2 + >>> from vyos.ifconfig import BridgeIf + >>> BridgeIf('br0').set_hello_time(2) """ return self._write_sysfs('/sys/class/net/{}/bridge/hello_time' .format(self._ifname), (int(time) * 100)) diff --git a/src/conf_mode/interface-bridge.py b/src/conf_mode/interface-bridge.py index 7380799ee..5d97d49bc 100755 --- a/src/conf_mode/interface-bridge.py +++ b/src/conf_mode/interface-bridge.py @@ -191,7 +191,7 @@ def apply(bridge): # set bridge forward delay br.set_forward_delay(bridge['forwarding_delay']) # set hello time - br.hello_time = bridge['hello_time'] + br.set_hello_time(bridge['hello_time']) # set max message age br.set_max_age(bridge['max_age']) # set bridge priority -- cgit v1.2.3 From 839058e95311ed6ee08f96a943c271dbf77320ed Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Tue, 24 Sep 2019 18:24:39 +0200 Subject: Python/ifconfig: T1557: refactor BridgeIf 'ageing_time' property to set_ageing_time() --- python/vyos/ifconfig.py | 22 +++------------------- src/conf_mode/interface-bridge.py | 2 +- 2 files changed, 4 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/python/vyos/ifconfig.py b/python/vyos/ifconfig.py index e10e01e2f..4ffeaa729 100644 --- a/python/vyos/ifconfig.py +++ b/python/vyos/ifconfig.py @@ -740,30 +740,14 @@ class BridgeIf(Interface): def __init__(self, ifname): super().__init__(ifname, type='bridge') - @property - def ageing_time(self): - """ - Return configured bridge interface MAC address aging time in seconds. - Internal kernel representation is in centiseconds, thus its converted - in the end. Kernel default is 300 seconds. - - Example: - >>> from vyos.ifconfig import Interface - >>> BridgeIf('br0').aging_time - '300' - """ - return (self._read_sysfs('/sys/class/net/{}/bridge/ageing_time' - .format(self._ifname)) / 100) - - @ageing_time.setter - def ageing_time(self, time): + def set_ageing_time(self, time): """ Set bridge interface MAC address aging time in seconds. Internal kernel representation is in centiseconds. Kernel default is 300 seconds. Example: - >>> from vyos.ifconfig import Interface - >>> BridgeIf('br0').ageing_time = 2 + >>> from vyos.ifconfig import BridgeIf + >>> BridgeIf('br0').ageing_time(2) """ time = int(time) * 100 return self._write_sysfs('/sys/class/net/{}/bridge/ageing_time' diff --git a/src/conf_mode/interface-bridge.py b/src/conf_mode/interface-bridge.py index 5d97d49bc..3b18e24ab 100755 --- a/src/conf_mode/interface-bridge.py +++ b/src/conf_mode/interface-bridge.py @@ -187,7 +187,7 @@ def apply(bridge): # enable interface br.state = 'up' # set ageing time - br.ageing_time = bridge['aging'] + br.set_ageing_time(bridge['aging']) # set bridge forward delay br.set_forward_delay(bridge['forwarding_delay']) # set hello time -- cgit v1.2.3 From 2f458f5efbd95640780554cc83fb54ec790bd4cc Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Tue, 24 Sep 2019 18:26:28 +0200 Subject: Python/ifconfig: T1557: refactor BridgeIf 'priority' property to set_priority() --- python/vyos/ifconfig.py | 24 +++++------------------- src/conf_mode/interface-bridge.py | 10 +++++----- 2 files changed, 10 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/python/vyos/ifconfig.py b/python/vyos/ifconfig.py index 4ffeaa729..6b4d102fb 100644 --- a/python/vyos/ifconfig.py +++ b/python/vyos/ifconfig.py @@ -789,27 +789,13 @@ class BridgeIf(Interface): return self._write_sysfs('/sys/class/net/{}/bridge/max_age' .format(self._ifname), (int(time) * 100)) - @property - def priority(self): - """ - Get bridge max aging time in seconds. - - Example: - >>> from vyos.ifconfig import Interface - >>> BridgeIf('br0').priority - '32768' - """ - return self._read_sysfs('/sys/class/net/{}/bridge/priority' - .format(self._ifname)) - - @priority.setter - def priority(self, priority): + def set_priority(self, priority): """ Set bridge max aging time in seconds. Example: - >>> from vyos.ifconfig import Interface - >>> BridgeIf('br0').priority = 8192 + >>> from vyos.ifconfig import BridgeIf + >>> BridgeIf('br0').set_priority(8192) """ return self._write_sysfs('/sys/class/net/{}/bridge/priority' .format(self._ifname), priority) @@ -891,7 +877,7 @@ class BridgeIf(Interface): cmd = 'ip link set dev {} nomaster'.format(interface) self._cmd(cmd) - def set_cost(self, interface, cost): + def set_path_cost(self, interface, cost): """ Set interface path cost, only relevant for STP enabled interfaces @@ -903,7 +889,7 @@ class BridgeIf(Interface): return self._write_sysfs('/sys/class/net/{}/brif/{}/path_cost' .format(self._ifname, interface), cost) - def set_priority(self, interface, priority): + def set_path_priority(self, interface, priority): """ Set interface path priority, only relevant for STP enabled interfaces diff --git a/src/conf_mode/interface-bridge.py b/src/conf_mode/interface-bridge.py index 3b18e24ab..b120ac663 100755 --- a/src/conf_mode/interface-bridge.py +++ b/src/conf_mode/interface-bridge.py @@ -195,7 +195,7 @@ def apply(bridge): # set max message age br.set_max_age(bridge['max_age']) # set bridge priority - br.priority = bridge['priority'] + br.set_priority(bridge['priority']) # turn stp on/off br.stp_state = bridge['stp'] # enable or disable IGMP querier @@ -229,10 +229,10 @@ def apply(bridge): # configure additional bridge member options for member in bridge['member']: - # set bridge port cost - br.set_cost(member['name'], member['cost']) - # set bridge port priority - br.set_priority(member['name'], member['priority']) + # set bridge port path cost + br.set_path_cost(member['name'], member['cost']) + # set bridge port path priority + br.set_path_priority(member['name'], member['priority']) i = Interface(member['name']) # configure ARP cache timeout -- cgit v1.2.3 From 78badc8690cb06a0062694c21eb5329b830233d5 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Tue, 24 Sep 2019 18:29:02 +0200 Subject: Python/ifconfig: T1557: refactor BridgeIf 'stp_state' property to set_stp() --- python/vyos/ifconfig.py | 26 ++++---------------------- src/conf_mode/interface-bridge.py | 2 +- 2 files changed, 5 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/python/vyos/ifconfig.py b/python/vyos/ifconfig.py index 6b4d102fb..1f8612681 100644 --- a/python/vyos/ifconfig.py +++ b/python/vyos/ifconfig.py @@ -800,31 +800,13 @@ class BridgeIf(Interface): return self._write_sysfs('/sys/class/net/{}/bridge/priority' .format(self._ifname), priority) - @property - def stp_state(self): - """ - Get current bridge STP (Spanning Tree) state. - - Example: - >>> from vyos.ifconfig import Interface - >>> BridgeIf('br0').stp_state - '0' + def set_stp(self, state): """ - - state = 0 - with open('/sys/class/net/{}/bridge/stp_state'.format(self._ifname), 'r') as f: - state = int(f.read().rstrip('\n')) - - return state - - @stp_state.setter - def stp_state(self, state): - """ - Set bridge STP (Spannign Tree) state. 0 -> STP disabled, 1 -> STP enabled + Set bridge STP (Spanning Tree) state. 0 -> STP disabled, 1 -> STP enabled Example: - >>> from vyos.ifconfig import Interface - >>> BridgeIf('br0').stp_state = 1 + >>> from vyos.ifconfig import BridgeIf + >>> BridgeIf('br0').set_stp(1) """ if int(state) >= 0 and int(state) <= 1: diff --git a/src/conf_mode/interface-bridge.py b/src/conf_mode/interface-bridge.py index b120ac663..ef8680c5f 100755 --- a/src/conf_mode/interface-bridge.py +++ b/src/conf_mode/interface-bridge.py @@ -197,7 +197,7 @@ def apply(bridge): # set bridge priority br.set_priority(bridge['priority']) # turn stp on/off - br.stp_state = bridge['stp'] + br.set_stp(bridge['stp']) # enable or disable IGMP querier br.set_multicast_querier(bridge['igmp_querier']) # update interface description used e.g. within SNMP -- cgit v1.2.3 From 8138766884bb7fe301dc21d2cb0bd3556d169d2e Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Tue, 24 Sep 2019 18:33:30 +0200 Subject: Python/ifconfig: T1557: refactor Interface 'link_detect' property to set_link_detect() --- python/vyos/ifconfig.py | 22 ++++------------------ src/conf_mode/interface-bonding.py | 4 ++-- src/conf_mode/interface-bridge.py | 2 +- src/conf_mode/interface-ethernet.py | 4 ++-- 4 files changed, 9 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/python/vyos/ifconfig.py b/python/vyos/ifconfig.py index 1f8612681..749bc6a1a 100644 --- a/python/vyos/ifconfig.py +++ b/python/vyos/ifconfig.py @@ -235,23 +235,9 @@ class Interface: return self._write_sysfs('/proc/sys/net/ipv4/neigh/{0}/base_reachable_time_ms' .format(self._ifname), (int(tmo) * 1000)) - @property - def link_detect(self): - """ - How does the kernel act when receiving packets on 'down' interfaces - - Example: - >>> from vyos.ifconfig import Interface - >>> Interface('eth0').link_detect - '0' - """ - return self._read_sysfs('/proc/sys/net/ipv4/conf/{0}/link_filter' - .format(self._ifname)) - - @link_detect.setter - def link_detect(self, link_filter): + def set_link_detect(self, link_filter): """ - Konfigure kernel response in packets received on interfaces that are 'down' + Configure kernel response in packets received on interfaces that are 'down' 0 - Allow packets to be received for the address on this interface even if interface is disabled or no carrier. @@ -267,9 +253,9 @@ class Interface: Example: >>> from vyos.ifconfig import Interface - >>> Interface('eth0').link_detect = '1' + >>> Interface('eth0').set_link_detect(1) """ - if link_filter >= 0 and link_filter <= 2: + if int(link_filter) >= 0 and int(link_filter) <= 2: return self._write_sysfs('/proc/sys/net/ipv4/conf/{0}/link_filter' .format(self._ifname), link_filter) else: diff --git a/src/conf_mode/interface-bonding.py b/src/conf_mode/interface-bonding.py index 83cd2facc..dce4a8106 100755 --- a/src/conf_mode/interface-bonding.py +++ b/src/conf_mode/interface-bonding.py @@ -86,7 +86,7 @@ def apply_vlan_config(vlan, config): # update interface description used e.g. within SNMP vlan.ifalias = config['description'] # ignore link state changes - vlan.link_detect = config['disable_link_detect'] + vlan.set_link_detect(config['disable_link_detect']) # Maximum Transmission Unit (MTU) vlan.set_mtu(config['mtu']) # Change VLAN interface MAC address @@ -376,7 +376,7 @@ def apply(bond): # # ignore link state changes - b.link_detect = bond['disable_link_detect'] + b.set_link_detect(bond['disable_link_detect']) # Bonding transmit hash policy b.xmit_hash_policy = bond['hash_policy'] # configure ARP cache timeout in milliseconds diff --git a/src/conf_mode/interface-bridge.py b/src/conf_mode/interface-bridge.py index ef8680c5f..558ec3cc6 100755 --- a/src/conf_mode/interface-bridge.py +++ b/src/conf_mode/interface-bridge.py @@ -238,7 +238,7 @@ def apply(bridge): # configure ARP cache timeout i.arp_cache_tmo = bridge['arp_cache_tmo'] # ignore link state changes - i.link_detect = bridge['disable_link_detect'] + i.set_link_detect(bridge['disable_link_detect']) return None diff --git a/src/conf_mode/interface-ethernet.py b/src/conf_mode/interface-ethernet.py index 7708c0086..f4bc53a32 100755 --- a/src/conf_mode/interface-ethernet.py +++ b/src/conf_mode/interface-ethernet.py @@ -69,7 +69,7 @@ def apply_vlan_config(vlan, config): # update interface description used e.g. within SNMP vlan.ifalias = config['description'] # ignore link state changes - vlan.link_detect = config['disable_link_detect'] + vlan.set_link_detect(config['disable_link_detect']) # Maximum Transmission Unit (MTU) vlan.set_mtu(config['mtu']) # Change VLAN interface MAC address @@ -278,7 +278,7 @@ def apply(eth): # # ignore link state changes - e.link_detect = eth['disable_link_detect'] + e.set_link_detect(eth['disable_link_detect']) # disable ethernet flow control (pause frames) e.set_flow_control(eth['flow_control']) # configure ARP cache timeout in milliseconds -- cgit v1.2.3 From 12d0cdf69ba15dccb705e212ea605b692f825dbd Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Tue, 24 Sep 2019 18:40:07 +0200 Subject: Python/ifconfig: T1557: refactor Interface 'ifalias' property to set_alias() --- python/vyos/ifconfig.py | 29 +++++------------------------ src/conf_mode/interface-bonding.py | 4 ++-- src/conf_mode/interface-bridge.py | 2 +- src/conf_mode/interface-dummy.py | 14 +++++++------- src/conf_mode/interface-ethernet.py | 4 ++-- src/conf_mode/interface-loopback.py | 3 +-- src/conf_mode/interface-vxlan.py | 2 +- src/conf_mode/interface-wireguard.py | 2 +- 8 files changed, 20 insertions(+), 40 deletions(-) (limited to 'src') diff --git a/python/vyos/ifconfig.py b/python/vyos/ifconfig.py index 749bc6a1a..86e2084d3 100644 --- a/python/vyos/ifconfig.py +++ b/python/vyos/ifconfig.py @@ -261,36 +261,17 @@ class Interface: else: raise ValueError("Value out of range") - @property - def ifalias(self): - """ - Get/set interface alias name - - Example: - - >>> from vyos.ifconfig import Interface - >>> Interface('eth0').ifalias - '' - """ - return self._read_sysfs('/sys/class/net/{}/ifalias' - .format(self._ifname)) - - @ifalias.setter - def ifalias(self, ifalias=None): + def set_alias(self, ifalias=None): """ - Get/set interface alias name + Set interface alias name used by e.g. SNMP Example: >>> from vyos.ifconfig import Interface - >>> Interface('eth0').ifalias = 'VyOS upstream interface' - >>> Interface('eth0').ifalias - 'VyOS upstream interface' + >>> Interface('eth0').set_alias('VyOS upstream interface') - to clear interface alias e.g. delete it use: + to clear alias e.g. delete it use: - >>> Interface('eth0').ifalias = '' - >>> Interface('eth0').ifalias - '' + >>> Interface('eth0').set_ifalias('') """ if not ifalias: # clear interface alias diff --git a/src/conf_mode/interface-bonding.py b/src/conf_mode/interface-bonding.py index dce4a8106..8b4c8b625 100755 --- a/src/conf_mode/interface-bonding.py +++ b/src/conf_mode/interface-bonding.py @@ -84,7 +84,7 @@ def apply_vlan_config(vlan, config): raise TypeError() # update interface description used e.g. within SNMP - vlan.ifalias = config['description'] + vlan.set_alias(config['description']) # ignore link state changes vlan.set_link_detect(config['disable_link_detect']) # Maximum Transmission Unit (MTU) @@ -369,7 +369,7 @@ def apply(bond): b.arp_ip_target = '+' + addr # update interface description used e.g. within SNMP - b.ifalias = bond['description'] + b.set_alias(bond['description']) # # missing DHCP/DHCPv6 options go here diff --git a/src/conf_mode/interface-bridge.py b/src/conf_mode/interface-bridge.py index 558ec3cc6..cadd44feb 100755 --- a/src/conf_mode/interface-bridge.py +++ b/src/conf_mode/interface-bridge.py @@ -201,7 +201,7 @@ def apply(bridge): # enable or disable IGMP querier br.set_multicast_querier(bridge['igmp_querier']) # update interface description used e.g. within SNMP - br.ifalias = bridge['description'] + br.set_alias(bridge['description']) # Change interface MAC address if bridge['mac']: diff --git a/src/conf_mode/interface-dummy.py b/src/conf_mode/interface-dummy.py index 1b3fbcc93..2556722fa 100755 --- a/src/conf_mode/interface-dummy.py +++ b/src/conf_mode/interface-dummy.py @@ -78,28 +78,28 @@ def generate(dummy): return None def apply(dummy): - du = DummyIf(dummy['intf']) + d = DummyIf(dummy['intf']) # Remove dummy interface if dummy['deleted']: - du.remove() + d.remove() else: # enable interface - du.state = 'up' + d.state = 'up' # update interface description used e.g. within SNMP - du.ifalias = dummy['description'] + d.set_alias(dummy['description']) # Configure interface address(es) # - not longer required addresses get removed first # - newly addresses will be added second for addr in dummy['address_remove']: - du.del_addr(addr) + d.del_addr(addr) for addr in dummy['address']: - du.add_addr(addr) + d.add_addr(addr) # disable interface on demand if dummy['disable']: - du.state = 'down' + d.state = 'down' return None diff --git a/src/conf_mode/interface-ethernet.py b/src/conf_mode/interface-ethernet.py index f4bc53a32..5c8c76827 100755 --- a/src/conf_mode/interface-ethernet.py +++ b/src/conf_mode/interface-ethernet.py @@ -67,7 +67,7 @@ def apply_vlan_config(vlan, config): raise TypeError() # update interface description used e.g. within SNMP - vlan.ifalias = config['description'] + vlan.set_alias(config['description']) # ignore link state changes vlan.set_link_detect(config['disable_link_detect']) # Maximum Transmission Unit (MTU) @@ -271,7 +271,7 @@ def apply(eth): e.remove() else: # update interface description used e.g. within SNMP - e.ifalias = eth['description'] + e.set_alias(eth['description']) # # missing DHCP/DHCPv6 options go here diff --git a/src/conf_mode/interface-loopback.py b/src/conf_mode/interface-loopback.py index aba682f31..46fc6809b 100755 --- a/src/conf_mode/interface-loopback.py +++ b/src/conf_mode/interface-loopback.py @@ -75,8 +75,7 @@ def apply(loopback): lo = LoopbackIf(loopback['intf']) if not loopback['deleted']: # update interface description used e.g. within SNMP - # update interface description used e.g. within SNMP - lo.ifalias = loopback['description'] + lo.set_alias(loopback['description']) # Configure interface address(es) # - not longer required addresses get removed first diff --git a/src/conf_mode/interface-vxlan.py b/src/conf_mode/interface-vxlan.py index f0fa7596a..638efda31 100755 --- a/src/conf_mode/interface-vxlan.py +++ b/src/conf_mode/interface-vxlan.py @@ -163,7 +163,7 @@ def apply(vxlan): # Finally create the new interface v = VXLANIf(vxlan['intf'], config=conf) # update interface description used e.g. by SNMP - v.ifalias = vxlan['description'] + v.set_alias(vxlan['description']) # Maximum Transfer Unit (MTU) v.set_mtu(vxlan['mtu']) diff --git a/src/conf_mode/interface-wireguard.py b/src/conf_mode/interface-wireguard.py index 069298265..7254e153f 100755 --- a/src/conf_mode/interface-wireguard.py +++ b/src/conf_mode/interface-wireguard.py @@ -210,7 +210,7 @@ def apply(c): # ifalias for snmp from description descr_eff = c_eff.return_effective_value(ifname + ' description') if descr_eff != c[ifname]['descr']: - intfc.ifalias = str(c[ifname]['descr']) + intfc.set_alias(str(c[ifname]['descr'])) # peer deletion peer_eff = c_eff.list_effective_nodes(ifname + ' peer') -- cgit v1.2.3 From 3e108025a16a6d4db1bc08ea9161709b13295dfb Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Tue, 24 Sep 2019 18:48:49 +0200 Subject: Python/ifconfig: T1557: loopback: implement derived remove() --- python/vyos/ifconfig.py | 15 +++++++++++++++ src/conf_mode/interface-loopback.py | 16 ++++++++-------- 2 files changed, 23 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/python/vyos/ifconfig.py b/python/vyos/ifconfig.py index 86e2084d3..776fe1a23 100644 --- a/python/vyos/ifconfig.py +++ b/python/vyos/ifconfig.py @@ -680,6 +680,21 @@ class LoopbackIf(Interface): def __init__(self, ifname): super().__init__(ifname, type='loopback') + def remove(self): + """ + Loopback interface can not be deleted from operating system. We can + only remove all assigned IP addresses. + + Example: + >>> from vyos.ifconfig import Interface + >>> i = LoopbackIf('lo').remove() + """ + # remove all assigned IP addresses from interface + for addr in self.get_addr(): + self.del_addr(addr) + + # question: do we also delerte the loopback address? 127.0.0.1/8 + class DummyIf(Interface): diff --git a/src/conf_mode/interface-loopback.py b/src/conf_mode/interface-loopback.py index 46fc6809b..10722d137 100755 --- a/src/conf_mode/interface-loopback.py +++ b/src/conf_mode/interface-loopback.py @@ -72,20 +72,20 @@ def generate(loopback): return None def apply(loopback): - lo = LoopbackIf(loopback['intf']) - if not loopback['deleted']: + l = LoopbackIf(loopback['intf']) + if loopback['deleted']: + l.remove() + else: # update interface description used e.g. within SNMP - lo.set_alias(loopback['description']) + l.set_alias(loopback['description']) # Configure interface address(es) # - not longer required addresses get removed first # - newly addresses will be added second + for addr in loopback['address_remove']: + l.del_addr(addr) for addr in loopback['address']: - lo.add_addr(addr) - - # remove interface address(es) - for addr in loopback['address_remove']: - lo.del_addr(addr) + l.add_addr(addr) return None -- cgit v1.2.3 From 3cedc3358c6aeb9e6caad4251958fa1a05723ea3 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Tue, 24 Sep 2019 18:51:03 +0200 Subject: Python/ifconfig: T1557: refactor Interface 'proxy_arp' property to set_proxy_arp() --- python/vyos/ifconfig.py | 20 ++------------------ src/conf_mode/interface-bonding.py | 2 +- src/conf_mode/interface-ethernet.py | 2 +- src/conf_mode/interface-vxlan.py | 2 +- 4 files changed, 5 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/python/vyos/ifconfig.py b/python/vyos/ifconfig.py index 776fe1a23..86a080602 100644 --- a/python/vyos/ifconfig.py +++ b/python/vyos/ifconfig.py @@ -314,29 +314,13 @@ class Interface: cmd = 'ip link set dev {} {}'.format(self._ifname, state) self._cmd(cmd) - @property - def proxy_arp(self): - """ - Get current proxy ARP configuration from sysfs. Default: 0 - - Example: - >>> from vyos.ifconfig import Interface - >>> Interface('eth0').proxy_arp - '0' - """ - return self._read_sysfs('/proc/sys/net/ipv4/conf/{}/proxy_arp' - .format(self._ifname)) - - @proxy_arp.setter - def proxy_arp(self, enable): + def set_proxy_arp(self, enable): """ Set per interface proxy ARP configuration Example: >>> from vyos.ifconfig import Interface - >>> Interface('eth0').proxy_arp = 1 - >>> Interface('eth0').proxy_arp - '1' + >>> Interface('eth0').set_proxy_arp(1) """ if int(enable) >= 0 and int(enable) <= 1: return self._write_sysfs('/proc/sys/net/ipv4/conf/{}/proxy_arp' diff --git a/src/conf_mode/interface-bonding.py b/src/conf_mode/interface-bonding.py index 8b4c8b625..2058a3342 100755 --- a/src/conf_mode/interface-bonding.py +++ b/src/conf_mode/interface-bonding.py @@ -382,7 +382,7 @@ def apply(bond): # configure ARP cache timeout in milliseconds b.arp_cache_tmp = bond['ip_arp_cache_tmo'] # Enable proxy-arp on this interface - b.proxy_arp = bond['ip_proxy_arp'] + b.set_proxy_arp(bond['ip_proxy_arp']) # Enable private VLAN proxy ARP on this interface b.proxy_arp_pvlan = bond['ip_proxy_arp_pvlan'] diff --git a/src/conf_mode/interface-ethernet.py b/src/conf_mode/interface-ethernet.py index 5c8c76827..e15e89232 100755 --- a/src/conf_mode/interface-ethernet.py +++ b/src/conf_mode/interface-ethernet.py @@ -284,7 +284,7 @@ def apply(eth): # configure ARP cache timeout in milliseconds e.arp_cache_tmo = eth['ip_arp_cache_tmo'] # Enable proxy-arp on this interface - e.proxy_arp = eth['ip_proxy_arp'] + e.set_proxy_arp(eth['ip_proxy_arp']) # Enable private VLAN proxy ARP on this interface e.proxy_arp_pvlan = eth['ip_proxy_arp_pvlan'] diff --git a/src/conf_mode/interface-vxlan.py b/src/conf_mode/interface-vxlan.py index 638efda31..b7aa55b61 100755 --- a/src/conf_mode/interface-vxlan.py +++ b/src/conf_mode/interface-vxlan.py @@ -170,7 +170,7 @@ def apply(vxlan): # configure ARP cache timeout in milliseconds v.arp_cache_tmp = vxlan['ip_arp_cache_tmo'] # Enable proxy-arp on this interface - v.proxy_arp = vxlan['ip_proxy_arp'] + v.set_proxy_arp(vxlan['ip_proxy_arp']) # Configure interface address(es) - no need to implicitly delete the # old addresses as they have already been removed by deleting the -- cgit v1.2.3 From 48e5ad611bc63575eb1150024939d04eb62cf400 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Tue, 24 Sep 2019 18:53:05 +0200 Subject: Python/ifconfig: T1557: refactor Interface 'proxy_arp_pvlan' property to set_proxy_arp_pvlan() --- python/vyos/ifconfig.py | 36 ++---------------------------------- src/conf_mode/interface-bonding.py | 2 +- src/conf_mode/interface-ethernet.py | 2 +- 3 files changed, 4 insertions(+), 36 deletions(-) (limited to 'src') diff --git a/python/vyos/ifconfig.py b/python/vyos/ifconfig.py index 86a080602..d32b54199 100644 --- a/python/vyos/ifconfig.py +++ b/python/vyos/ifconfig.py @@ -328,8 +328,7 @@ class Interface: else: raise ValueError("Value out of range") - @property - def proxy_arp_pvlan(self): + def set_proxy_arp_pvlan(self, enable): """ Private VLAN proxy arp. Basically allow proxy arp replies back to the same interface @@ -351,38 +350,7 @@ class Interface: Example: >>> from vyos.ifconfig import Interface - >>> Interface('eth0').proxy_arp_pvlan - '0' - """ - return self._read_sysfs('/proc/sys/net/ipv4/conf/{}/proxy_arp_pvlan' - .format(self._ifname)) - - @proxy_arp_pvlan.setter - def proxy_arp_pvlan(self, enable): - """ - Private VLAN proxy arp. - Basically allow proxy arp replies back to the same interface - (from which the ARP request/solicitation was received). - - This is done to support (ethernet) switch features, like RFC - 3069, where the individual ports are NOT allowed to - communicate with each other, but they are allowed to talk to - the upstream router. As described in RFC 3069, it is possible - to allow these hosts to communicate through the upstream - router by proxy_arp'ing. Don't need to be used together with - proxy_arp. - - This technology is known by different names: - In RFC 3069 it is called VLAN Aggregation. - Cisco and Allied Telesyn call it Private VLAN. - Hewlett-Packard call it Source-Port filtering or port-isolation. - Ericsson call it MAC-Forced Forwarding (RFC Draft). - - Example: - >>> from vyos.ifconfig import Interface - >>> Interface('eth0').proxy_arp_pvlan = 1 - >>> Interface('eth0').proxy_arp_pvlan - '1' + >>> Interface('eth0').set_proxy_arp_pvlan(1) """ if int(enable) >= 0 and int(enable) <= 1: return self._write_sysfs('/proc/sys/net/ipv4/conf/{}/proxy_arp_pvlan' diff --git a/src/conf_mode/interface-bonding.py b/src/conf_mode/interface-bonding.py index 2058a3342..0b6ac14a6 100755 --- a/src/conf_mode/interface-bonding.py +++ b/src/conf_mode/interface-bonding.py @@ -384,7 +384,7 @@ def apply(bond): # Enable proxy-arp on this interface b.set_proxy_arp(bond['ip_proxy_arp']) # Enable private VLAN proxy ARP on this interface - b.proxy_arp_pvlan = bond['ip_proxy_arp_pvlan'] + b.set_proxy_arp_pvlan(bond['ip_proxy_arp_pvlan']) # Change interface MAC address if bond['mac']: diff --git a/src/conf_mode/interface-ethernet.py b/src/conf_mode/interface-ethernet.py index e15e89232..02a45408f 100755 --- a/src/conf_mode/interface-ethernet.py +++ b/src/conf_mode/interface-ethernet.py @@ -286,7 +286,7 @@ def apply(eth): # Enable proxy-arp on this interface e.set_proxy_arp(eth['ip_proxy_arp']) # Enable private VLAN proxy ARP on this interface - e.proxy_arp_pvlan = eth['ip_proxy_arp_pvlan'] + e.set_proxy_arp_pvlan(eth['ip_proxy_arp_pvlan']) # Change interface MAC address - re-set to real hardware address (hw-id) # if custom mac is removed -- cgit v1.2.3 From 09f4553ffdbf3c35696f08118d75793db33cb59b Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Tue, 24 Sep 2019 18:56:05 +0200 Subject: Python/ifconfig: T1557: refactor Interface 'arp_cache_tmo' property to set_set_arp_cache_tmo() --- python/vyos/ifconfig.py | 18 ++---------------- src/conf_mode/interface-bonding.py | 2 +- src/conf_mode/interface-bridge.py | 2 +- src/conf_mode/interface-ethernet.py | 2 +- src/conf_mode/interface-vxlan.py | 2 +- 5 files changed, 6 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/python/vyos/ifconfig.py b/python/vyos/ifconfig.py index d32b54199..5fa9f4f2b 100644 --- a/python/vyos/ifconfig.py +++ b/python/vyos/ifconfig.py @@ -208,29 +208,15 @@ class Interface: cmd = 'ip link set dev {} address {}'.format(self._ifname, mac) self._cmd(cmd) - @property - def arp_cache_tmo(self): - """ - Get configured ARP cache timeout value from interface in seconds. - Internal Kernel representation is in milliseconds. - - Example: - >>> from vyos.ifconfig import Interface - >>> Interface('eth0').arp_cache_tmo - '30' - """ - return (self._read_sysfs('/proc/sys/net/ipv4/neigh/{0}/base_reachable_time_ms' - .format(self._ifname)) / 1000) - @arp_cache_tmo.setter - def arp_cache_tmo(self, tmo): + def set_arp_cache_tmo(self, tmo): """ Set ARP cache timeout value in seconds. Internal Kernel representation is in milliseconds. Example: >>> from vyos.ifconfig import Interface - >>> Interface('eth0').arp_cache_tmo = '40' + >>> Interface('eth0').set_arp_cache_tmo(40) """ return self._write_sysfs('/proc/sys/net/ipv4/neigh/{0}/base_reachable_time_ms' .format(self._ifname), (int(tmo) * 1000)) diff --git a/src/conf_mode/interface-bonding.py b/src/conf_mode/interface-bonding.py index 0b6ac14a6..0fd19ce1e 100755 --- a/src/conf_mode/interface-bonding.py +++ b/src/conf_mode/interface-bonding.py @@ -380,7 +380,7 @@ def apply(bond): # Bonding transmit hash policy b.xmit_hash_policy = bond['hash_policy'] # configure ARP cache timeout in milliseconds - b.arp_cache_tmp = bond['ip_arp_cache_tmo'] + b.set_arp_cache_tmo(bond['ip_arp_cache_tmo']) # Enable proxy-arp on this interface b.set_proxy_arp(bond['ip_proxy_arp']) # Enable private VLAN proxy ARP on this interface diff --git a/src/conf_mode/interface-bridge.py b/src/conf_mode/interface-bridge.py index cadd44feb..cb053773a 100755 --- a/src/conf_mode/interface-bridge.py +++ b/src/conf_mode/interface-bridge.py @@ -236,7 +236,7 @@ def apply(bridge): i = Interface(member['name']) # configure ARP cache timeout - i.arp_cache_tmo = bridge['arp_cache_tmo'] + i.set_arp_cache_tmo(bridge['arp_cache_tmo']) # ignore link state changes i.set_link_detect(bridge['disable_link_detect']) diff --git a/src/conf_mode/interface-ethernet.py b/src/conf_mode/interface-ethernet.py index 02a45408f..cc9f44753 100755 --- a/src/conf_mode/interface-ethernet.py +++ b/src/conf_mode/interface-ethernet.py @@ -282,7 +282,7 @@ def apply(eth): # disable ethernet flow control (pause frames) e.set_flow_control(eth['flow_control']) # configure ARP cache timeout in milliseconds - e.arp_cache_tmo = eth['ip_arp_cache_tmo'] + e.set_arp_cache_tmo(eth['ip_arp_cache_tmo']) # Enable proxy-arp on this interface e.set_proxy_arp(eth['ip_proxy_arp']) # Enable private VLAN proxy ARP on this interface diff --git a/src/conf_mode/interface-vxlan.py b/src/conf_mode/interface-vxlan.py index b7aa55b61..c0c85e64c 100755 --- a/src/conf_mode/interface-vxlan.py +++ b/src/conf_mode/interface-vxlan.py @@ -168,7 +168,7 @@ def apply(vxlan): v.set_mtu(vxlan['mtu']) # configure ARP cache timeout in milliseconds - v.arp_cache_tmp = vxlan['ip_arp_cache_tmo'] + v.set_arp_cache_tmo(vxlan['ip_arp_cache_tmo']) # Enable proxy-arp on this interface v.set_proxy_arp(vxlan['ip_proxy_arp']) -- cgit v1.2.3 From 065adc3ab2ee6262b4a1a85762697ac81fc5b084 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Tue, 24 Sep 2019 19:03:57 +0200 Subject: Python/ifconfig: T1557: refactor Interface 'state' property to set_state()/get_state() --- python/vyos/ifconfig.py | 25 ++++++++++--------------- src/conf_mode/interface-bonding.py | 8 ++++---- src/conf_mode/interface-bridge.py | 4 ++-- src/conf_mode/interface-dummy.py | 6 +++--- src/conf_mode/interface-ethernet.py | 8 ++++---- src/conf_mode/interface-vxlan.py | 2 +- src/conf_mode/interface-wireguard.py | 6 +++--- 7 files changed, 27 insertions(+), 32 deletions(-) (limited to 'src') diff --git a/python/vyos/ifconfig.py b/python/vyos/ifconfig.py index 5fa9f4f2b..d10015e2d 100644 --- a/python/vyos/ifconfig.py +++ b/python/vyos/ifconfig.py @@ -60,7 +60,6 @@ class Interface: >>> i = Interface('eth0') """ self._ifname = str(ifname) - self._state = 'down' if not os.path.exists('/sys/class/net/{}'.format(ifname)) and not type: raise Exception('interface "{}" not found'.format(self._ifname)) @@ -266,35 +265,31 @@ class Interface: self._write_sysfs('/sys/class/net/{}/ifalias' .format(self._ifname), ifalias) - @property - def state(self): + def get_state(self): """ Enable (up) / Disable (down) an interface Example: >>> from vyos.ifconfig import Interface - >>> Interface('eth0').state + >>> Interface('eth0').get_state() 'up' """ return self._read_sysfs('/sys/class/net/{}/operstate' .format(self._ifname)) - @state.setter - def state(self, state): + def set_state(self, state): """ Enable (up) / Disable (down) an interface Example: >>> from vyos.ifconfig import Interface - >>> Interface('eth0').state = 'down' - >>> Interface('eth0').state + >>> Interface('eth0').set_state('down') + >>> Interface('eth0').get_state() 'down' """ if state not in ['up', 'down']: raise ValueError('state must be "up" or "down"') - self._state = state - # Assemble command executed on system. Unfortunately there is no way # to up/down an interface via sysfs cmd = 'ip link set dev {} {}'.format(self._ifname, state) @@ -468,7 +463,7 @@ class Interface: with open(self._dhcp_cfg_file, 'w') as f: f.write(dhcp_text) - if self._state == 'up': + if self.get_state() == 'up': cmd = 'start-stop-daemon --start --quiet --pidfile ' + \ self._dhcp_pid_file cmd += ' --exec /sbin/dhclient --' @@ -546,7 +541,7 @@ class Interface: with open(self._dhcpv6_cfg_file, 'w') as f: f.write(dhcpv6_text) - if self._state == 'up': + if self.get_state() == 'up': # https://bugs.launchpad.net/ubuntu/+source/ifupdown/+bug/1447715 # # wee need to wait for IPv6 DAD to finish once and interface is added @@ -1115,7 +1110,7 @@ class BondIf(VLANIf): for s in self.get_slaves(): slave = { 'ifname' : s, - 'state': Interface(s).state + 'state': Interface(s).get_state() } slave_list.append(slave) @@ -1126,7 +1121,7 @@ class BondIf(VLANIf): # physical interface for slave in slave_list: i = Interface(slave['ifname']) - i.state = slave['state'] + i.set_state(slave['state']) @property def xmit_hash_policy(self): @@ -1301,7 +1296,7 @@ class BondIf(VLANIf): # An interface can only be added to a bond if it is in 'down' state. If # interface is in 'up' state, the following Kernel error will be thrown: # bond0: eth1 is up - this may be due to an out of date ifenslave. - Interface(interface).state = 'down' + Interface(interface).set_state('down') return self._write_sysfs('/sys/class/net/{}/bonding/slaves' .format(self._ifname), '+' + interface) diff --git a/src/conf_mode/interface-bonding.py b/src/conf_mode/interface-bonding.py index 0fd19ce1e..c7adb0f9a 100755 --- a/src/conf_mode/interface-bonding.py +++ b/src/conf_mode/interface-bonding.py @@ -95,9 +95,9 @@ def apply_vlan_config(vlan, config): # enable/disable VLAN interface if config['disable']: - vlan.state = 'down' + vlan.set_state('down') else: - vlan.state = 'up' + vlan.set_state('up') # Configure interface address(es) # - not longer required addresses get removed first @@ -337,7 +337,7 @@ def apply(bond): else: # Some parameters can not be changed when the bond is up. # Always disable the bond prior changing anything - b.state = 'down' + b.set_state('down') # The bonding mode can not be changed when there are interfaces enslaved # to this bond, thus we will free all interfaces from the bond first! @@ -407,7 +407,7 @@ def apply(bond): # parameters we will only re-enable the interface if it is not # administratively disabled if not bond['disable']: - b.state = 'up' + b.set_state('up') # Configure interface address(es) # - not longer required addresses get removed first diff --git a/src/conf_mode/interface-bridge.py b/src/conf_mode/interface-bridge.py index cb053773a..b20e7f6ff 100755 --- a/src/conf_mode/interface-bridge.py +++ b/src/conf_mode/interface-bridge.py @@ -185,7 +185,7 @@ def apply(bridge): br.remove() else: # enable interface - br.state = 'up' + br.set_state('up') # set ageing time br.set_ageing_time(bridge['aging']) # set bridge forward delay @@ -217,7 +217,7 @@ def apply(bridge): # up/down interface if bridge['disable']: - br.state = 'down' + br.set_state('down') # Configure interface address(es) # - not longer required addresses get removed first diff --git a/src/conf_mode/interface-dummy.py b/src/conf_mode/interface-dummy.py index 2556722fa..16b716e61 100755 --- a/src/conf_mode/interface-dummy.py +++ b/src/conf_mode/interface-dummy.py @@ -84,8 +84,6 @@ def apply(dummy): if dummy['deleted']: d.remove() else: - # enable interface - d.state = 'up' # update interface description used e.g. within SNMP d.set_alias(dummy['description']) @@ -99,7 +97,9 @@ def apply(dummy): # disable interface on demand if dummy['disable']: - d.state = 'down' + d.set_state('down') + else + d.set_state('up') return None diff --git a/src/conf_mode/interface-ethernet.py b/src/conf_mode/interface-ethernet.py index cc9f44753..99450b19e 100755 --- a/src/conf_mode/interface-ethernet.py +++ b/src/conf_mode/interface-ethernet.py @@ -78,9 +78,9 @@ def apply_vlan_config(vlan, config): # enable/disable VLAN interface if config['disable']: - vlan.state = 'down' + vlan.set_state('down') else: - vlan.state = 'up' + vlan.set_state('up') # Configure interface address(es) # - not longer required addresses get removed first @@ -318,9 +318,9 @@ def apply(eth): # Enable/Disable interface if eth['disable']: - e.state = 'down' + e.set_state('down') else: - e.state = 'up' + e.set_state('up') # Configure interface address(es) # - not longer required addresses get removed first diff --git a/src/conf_mode/interface-vxlan.py b/src/conf_mode/interface-vxlan.py index c0c85e64c..1097ae4d0 100755 --- a/src/conf_mode/interface-vxlan.py +++ b/src/conf_mode/interface-vxlan.py @@ -182,7 +182,7 @@ def apply(vxlan): # parameters we will only re-enable the interface if it is not # administratively disabled if not vxlan['disable']: - v.state='up' + v.set_state('up') return None diff --git a/src/conf_mode/interface-wireguard.py b/src/conf_mode/interface-wireguard.py index 7254e153f..3fd29ad4d 100755 --- a/src/conf_mode/interface-wireguard.py +++ b/src/conf_mode/interface-wireguard.py @@ -173,11 +173,11 @@ def apply(c): # interface state if c[ifname]['state'] == 'disable': sl.syslog(sl.LOG_NOTICE, "disable interface " + ifname) - intfc.state = 'down' + intfc.set_state('down') else: - if not intfc.state == 'up': + if not intfc.get_state() == 'up': sl.syslog(sl.LOG_NOTICE, "enable interface " + ifname) - intfc.state = 'up' + intfc.set_state('up') # IP address if not c_eff.exists_effective(ifname + ' address'): -- cgit v1.2.3 From 19cae8e57885034002b3773b289d9f9086937ddc Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Tue, 24 Sep 2019 19:09:26 +0200 Subject: Python/ifconfig: T1557: refactor BondIf 'xmit_hash_policy' property to set_hash_policy() --- python/vyos/ifconfig.py | 25 ++----------------------- src/conf_mode/interface-bonding.py | 2 +- 2 files changed, 3 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/python/vyos/ifconfig.py b/python/vyos/ifconfig.py index a155ce572..2c627f0b0 100644 --- a/python/vyos/ifconfig.py +++ b/python/vyos/ifconfig.py @@ -1097,27 +1097,8 @@ class BondIf(VLANIf): i = Interface(slave['ifname']) i.set_state(slave['state']) - @property - def xmit_hash_policy(self): - """ - Selects the transmit hash policy to use for slave selection in - balance-xor, 802.3ad, and tlb modes. Possible values are: layer2, - layer2+3, layer3+4, encap2+3, encap3+4. - - The default value is layer2 - - Example: - >>> from vyos.ifconfig import BondIf - >>> BondIf('bond0').xmit_hash_policy - 'layer3+4' - """ - # Linux Kernel appends has policy value to string, e.g. 'layer3+4 1', - # so remove the later part and only return the mode as string. - return self._read_sysfs('/sys/class/net/{}/bonding/xmit_hash_policy' - .format(self._ifname)).split()[0] - @xmit_hash_policy.setter - def xmit_hash_policy(self, mode): + def set_hash_policy(self, mode): """ Selects the transmit hash policy to use for slave selection in balance-xor, 802.3ad, and tlb modes. Possible values are: layer2, @@ -1127,9 +1108,7 @@ class BondIf(VLANIf): Example: >>> from vyos.ifconfig import BondIf - >>> BondIf('bond0').xmit_hash_policy = 'layer2+3' - >>> BondIf('bond0').proxy_arp - '1' + >>> BondIf('bond0').set_hash_policy('layer2+3') """ if not mode in ['layer2', 'layer2+3', 'layer3+4', 'encap2+3', 'encap3+4']: raise ValueError("Value out of range") diff --git a/src/conf_mode/interface-bonding.py b/src/conf_mode/interface-bonding.py index c7adb0f9a..e8e22e305 100755 --- a/src/conf_mode/interface-bonding.py +++ b/src/conf_mode/interface-bonding.py @@ -378,7 +378,7 @@ def apply(bond): # ignore link state changes b.set_link_detect(bond['disable_link_detect']) # Bonding transmit hash policy - b.xmit_hash_policy = bond['hash_policy'] + b.set_hash_policy(bond['hash_policy']) # configure ARP cache timeout in milliseconds b.set_arp_cache_tmo(bond['ip_arp_cache_tmo']) # Enable proxy-arp on this interface -- cgit v1.2.3 From 8befa5b2aad043dca5d2ba293a7c762f55537c7e Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Tue, 24 Sep 2019 19:10:57 +0200 Subject: Python/ifconfig: T1557: refactor BondIf 'arp_interval' property to set_arp_interval() --- python/vyos/ifconfig.py | 28 ++-------------------------- src/conf_mode/interface-bonding.py | 2 +- 2 files changed, 3 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/python/vyos/ifconfig.py b/python/vyos/ifconfig.py index 2c627f0b0..e3404d3e1 100644 --- a/python/vyos/ifconfig.py +++ b/python/vyos/ifconfig.py @@ -1115,29 +1115,7 @@ class BondIf(VLANIf): return self._write_sysfs('/sys/class/net/{}/bonding/xmit_hash_policy' .format(self._ifname), mode) - @property - def arp_interval(self): - """ - Specifies the ARP link monitoring frequency in milliseconds. - - The ARP monitor works by periodically checking the slave devices to - determine whether they have sent or received traffic recently (the - precise criteria depends upon the bonding mode, and the state of the - slave). Regular traffic is generated via ARP probes issued for the - addresses specified by the arp_ip_target option. - - The default value is 0. - - Example: - >>> from vyos.ifconfig import BondIf - >>> BondIf('bond0').arp_interval - '0' - """ - return self._read_sysfs('/sys/class/net/{}/bonding/arp_interval' - .format(self._ifname)) - - @arp_interval.setter - def arp_interval(self, time): + def set_arp_interval(self, time): """ Specifies the IP addresses to use as ARP monitoring peers when arp_interval is > 0. These are the targets of the ARP request sent to @@ -1150,9 +1128,7 @@ class BondIf(VLANIf): Example: >>> from vyos.ifconfig import BondIf - >>> BondIf('bond0').arp_interval = '100' - >>> BondIf('bond0').arp_interval - '100' + >>> BondIf('bond0').set_arp_interval = '100' """ return self._write_sysfs('/sys/class/net/{}/bonding/arp_interval' .format(self._ifname), time) diff --git a/src/conf_mode/interface-bonding.py b/src/conf_mode/interface-bonding.py index e8e22e305..d1617cb1c 100755 --- a/src/conf_mode/interface-bonding.py +++ b/src/conf_mode/interface-bonding.py @@ -349,7 +349,7 @@ def apply(bond): # reset miimon to default b.miimon = 250 else: - b.arp_interval = bond['arp_mon_intvl'] + b.set_arp_interval(bond['arp_mon_intvl']) # ARP monitor targets need to be synchronized between sysfs and CLI. # Unfortunately an address can't be send twice to sysfs as this will -- cgit v1.2.3 From 7d747a6ad08d0ea726333bfa9917c7f05439f33b Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Tue, 24 Sep 2019 19:15:36 +0200 Subject: Python/ifconfig: T1557: refactor BondIf 'arp_ip_target' property to set_arp_ip_target()/get_arp_ip_target() --- python/vyos/ifconfig.py | 12 +++++------- src/conf_mode/interface-bonding.py | 6 +++--- 2 files changed, 8 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/python/vyos/ifconfig.py b/python/vyos/ifconfig.py index e3404d3e1..324f341da 100644 --- a/python/vyos/ifconfig.py +++ b/python/vyos/ifconfig.py @@ -1133,8 +1133,7 @@ class BondIf(VLANIf): return self._write_sysfs('/sys/class/net/{}/bonding/arp_interval' .format(self._ifname), time) - @property - def arp_ip_target(self): + def get_arp_ip_target(self): """ Specifies the IP addresses to use as ARP monitoring peers when arp_interval is > 0. These are the targets of the ARP request sent to @@ -1147,14 +1146,13 @@ class BondIf(VLANIf): Example: >>> from vyos.ifconfig import BondIf - >>> BondIf('bond0').arp_ip_target + >>> BondIf('bond0').get_arp_ip_target() '192.0.2.1' """ return self._read_sysfs('/sys/class/net/{}/bonding/arp_ip_target' .format(self._ifname)) - @arp_ip_target.setter - def arp_ip_target(self, target): + def set_arp_ip_target(self, target): """ Specifies the IP addresses to use as ARP monitoring peers when arp_interval is > 0. These are the targets of the ARP request sent to @@ -1167,8 +1165,8 @@ class BondIf(VLANIf): Example: >>> from vyos.ifconfig import BondIf - >>> BondIf('bond0').arp_ip_target = '192.0.2.1' - >>> BondIf('bond0').arp_ip_target + >>> BondIf('bond0').set_arp_ip_target('192.0.2.1') + >>> BondIf('bond0').get_arp_ip_target() '192.0.2.1' """ return self._write_sysfs('/sys/class/net/{}/bonding/arp_ip_target' diff --git a/src/conf_mode/interface-bonding.py b/src/conf_mode/interface-bonding.py index d1617cb1c..01df0e3d2 100755 --- a/src/conf_mode/interface-bonding.py +++ b/src/conf_mode/interface-bonding.py @@ -360,13 +360,13 @@ def apply(bond): # from the kernel side this looks valid to me. We won't run into an error # when a user added manual adresses which would result in having more # then 16 adresses in total. - arp_tgt_addr = list(map(str, b.arp_ip_target.split())) + arp_tgt_addr = list(map(str, b.get_arp_ip_target().split())) for addr in arp_tgt_addr: - b.arp_ip_target = '-' + addr + b.set_arp_ip_target('-' + addr) # Add configured ARP target addresses for addr in bond['arp_mon_tgt']: - b.arp_ip_target = '+' + addr + b.set_arp_ip_target('+' + addr) # update interface description used e.g. within SNMP b.set_alias(bond['description']) -- cgit v1.2.3 From bc9b28132ca7270f226968d0c1207adefe768049 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Tue, 24 Sep 2019 19:24:45 +0200 Subject: Python/ifconfig: T1557: refactor BondIf 'arp_interval' property to set_arp_interval() --- python/vyos/ifconfig.py | 81 ++++++++++++++------------------------ src/conf_mode/interface-bonding.py | 7 +--- 2 files changed, 32 insertions(+), 56 deletions(-) (limited to 'src') diff --git a/python/vyos/ifconfig.py b/python/vyos/ifconfig.py index 324f341da..8b333b81d 100644 --- a/python/vyos/ifconfig.py +++ b/python/vyos/ifconfig.py @@ -1115,23 +1115,41 @@ class BondIf(VLANIf): return self._write_sysfs('/sys/class/net/{}/bonding/xmit_hash_policy' .format(self._ifname), mode) - def set_arp_interval(self, time): + def set_arp_interval(self, interval): """ - Specifies the IP addresses to use as ARP monitoring peers when - arp_interval is > 0. These are the targets of the ARP request sent to - determine the health of the link to the targets. Specify these values - in ddd.ddd.ddd.ddd format. Multiple IP addresses must be separated by - a comma. At least one IP address must be given for ARP monitoring to - function. The maximum number of targets that can be specified is 16. + Specifies the ARP link monitoring frequency in milliseconds. - The default value is no IP addresses. + The ARP monitor works by periodically checking the slave devices + to determine whether they have sent or received traffic recently + (the precise criteria depends upon the bonding mode, and the + state of the slave). Regular traffic is generated via ARP probes + issued for the addresses specified by the arp_ip_target option. + + If ARP monitoring is used in an etherchannel compatible mode + (modes 0 and 2), the switch should be configured in a mode that + evenly distributes packets across all links. If the switch is + configured to distribute the packets in an XOR fashion, all + replies from the ARP targets will be received on the same link + which could cause the other team members to fail. + + value of 0 disables ARP monitoring. The default value is 0. Example: >>> from vyos.ifconfig import BondIf - >>> BondIf('bond0').set_arp_interval = '100' - """ - return self._write_sysfs('/sys/class/net/{}/bonding/arp_interval' - .format(self._ifname), time) + >>> BondIf('bond0').set_arp_interval('100') + """ + if int(interval) == 0: + """ + Specifies the MII link monitoring frequency in milliseconds. + This determines how often the link state of each slave is + inspected for link failures. A value of zero disables MII + link monitoring. A value of 100 is a good starting point. + """ + return self._write_sysfs('/sys/class/net/{}/bonding/miimon' + .format(self._ifname), interval) + else: + return self._write_sysfs('/sys/class/net/{}/bonding/arp_interval' + .format(self._ifname), interval) def get_arp_ip_target(self): """ @@ -1172,45 +1190,6 @@ class BondIf(VLANIf): return self._write_sysfs('/sys/class/net/{}/bonding/arp_ip_target' .format(self._ifname), target) - @property - def miimon(self): - """ - Specifies the MII link monitoring frequency in milliseconds. - This determines how often the link state of each slave is - inspected for link failures. A value of zero disables MII - link monitoring. A value of 100 is a good starting point. - - The default value is 0. - - Example: - >>> from vyos.ifconfig import BondIf - >>> BondIf('bond0').miimon - '250' - """ - return self._read_sysfs('/sys/class/net/{}/bonding/miimon' - .format(self._ifname)) - - - @miimon.setter - def miimon(self, time): - """ - Specifies the MII link monitoring frequency in milliseconds. - This determines how often the link state of each slave is - inspected for link failures. A value of zero disables MII - link monitoring. A value of 100 is a good starting point. - - The default value is 0. - - Example: - >>> from vyos.ifconfig import BondIf - >>> BondIf('bond0').miimon = 250 - >>> BondIf('bond0').miimon - '250' - """ - return self._write_sysfs('/sys/class/net/{}/bonding/miimon' - .format(self._ifname), time) - - def add_port(self, interface): """ Enslave physical interface to bond. diff --git a/src/conf_mode/interface-bonding.py b/src/conf_mode/interface-bonding.py index 01df0e3d2..6092d0732 100755 --- a/src/conf_mode/interface-bonding.py +++ b/src/conf_mode/interface-bonding.py @@ -345,11 +345,8 @@ def apply(bond): b.del_port(intf) # ARP link monitoring frequency, reset miimon when arp-montior is inactive - if bond['arp_mon_intvl'] == 0: - # reset miimon to default - b.miimon = 250 - else: - b.set_arp_interval(bond['arp_mon_intvl']) + # this is done inside BondIf automatically + b.set_arp_interval(bond['arp_mon_intvl']) # ARP monitor targets need to be synchronized between sysfs and CLI. # Unfortunately an address can't be send twice to sysfs as this will -- cgit v1.2.3 From f95659216b0816f53bdf5cb8ccc02afff970dd53 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Tue, 24 Sep 2019 19:27:54 +0200 Subject: Python/ifconfig: T1557: refactor BondIf 'mode' property to set_mode() --- python/vyos/ifconfig.py | 24 ++---------------------- src/conf_mode/interface-bonding.py | 2 +- 2 files changed, 3 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/python/vyos/ifconfig.py b/python/vyos/ifconfig.py index 8b333b81d..8f81bc9f6 100644 --- a/python/vyos/ifconfig.py +++ b/python/vyos/ifconfig.py @@ -1254,25 +1254,7 @@ class BondIf(VLANIf): return self._write_sysfs('/sys/class/net/{}/bonding/primary' .format(self._ifname), interface) - @property - def mode(self): - """ - Specifies one of the bonding policies. The default is balance-rr - (round robin). - - Possible values are: balance-rr (0), active-backup (1), balance-xor (2), - broadcast (3), 802.3ad (4), balance-tlb (5), balance-alb (6) - - Example: - >>> from vyos.ifconfig import BondIf - >>> BondIf('bond0').mode - 'balance-rr' - """ - return self._read_sysfs('/sys/class/net/{}/bonding/mode' - .format(self._ifname)).split()[0] - - @mode.setter - def mode(self, mode): + def set_mode(self, mode): """ Specifies one of the bonding policies. The default is balance-rr (round robin). @@ -1285,9 +1267,7 @@ class BondIf(VLANIf): Example: >>> from vyos.ifconfig import BondIf - >>> BondIf('bond0').mode = '802.3ad' - >>> BondIf('bond0').mode - '802.3ad' + >>> BondIf('bond0').set_mode('802.3ad') """ if not mode in [ 'balance-rr', 'active-backup', 'balance-xor', 'broadcast', diff --git a/src/conf_mode/interface-bonding.py b/src/conf_mode/interface-bonding.py index 6092d0732..4d5009c73 100755 --- a/src/conf_mode/interface-bonding.py +++ b/src/conf_mode/interface-bonding.py @@ -388,7 +388,7 @@ def apply(bond): b.set_mac(bond['mac']) # Bonding policy - b.mode = bond['mode'] + b.set_mode(bond['mode']) # Maximum Transmission Unit (MTU) b.set_mtu(bond['mtu']) -- cgit v1.2.3 From 3aed7f2dad9326ae094edc94b996db4fce2e0b18 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Tue, 24 Sep 2019 21:01:42 +0200 Subject: openvpn: T1548: setup interface alias --- src/conf_mode/interface-openvpn.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/conf_mode/interface-openvpn.py b/src/conf_mode/interface-openvpn.py index fa01f7fc5..57d565749 100755 --- a/src/conf_mode/interface-openvpn.py +++ b/src/conf_mode/interface-openvpn.py @@ -29,8 +29,9 @@ from pwd import getpwnam from subprocess import Popen, PIPE from time import sleep -from vyos.config import Config from vyos import ConfigError +from vyos.config import Config +from vyos.ifconfig import Interface from vyos.validate import is_addr_assigned user = 'openvpn' @@ -899,6 +900,13 @@ def apply(openvpn): # execute assembled command subprocess_cmd(cmd) + + # better late then sorry ... but we can only set interface alias after + # OpenVPN has been launched and created the interface + while openvpn['intf'] not in interfaces(): + sleep(0.250) # 250ms + Interface(openvpn['intf']).set_alias(openvpn['description']) + return None -- cgit v1.2.3 From 0588f5409f57a8d8577bc9bd23c393487fd2987b Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Tue, 24 Sep 2019 22:08:21 +0200 Subject: Python/ifconfig: T1557: add STPIf class (spanning tree) bridge member --- python/vyos/ifconfig.py | 66 ++++++++++++++++++++++++--------------- src/conf_mode/interface-bridge.py | 13 ++++---- 2 files changed, 47 insertions(+), 32 deletions(-) (limited to 'src') diff --git a/python/vyos/ifconfig.py b/python/vyos/ifconfig.py index a959e55d8..a77cde5e7 100644 --- a/python/vyos/ifconfig.py +++ b/python/vyos/ifconfig.py @@ -641,6 +641,47 @@ class DummyIf(Interface): super().__init__(ifname, type='dummy') +class STPIf(Interface): + """ + A spanning-tree capable interface. This applies only to bridge port member + interfaces! + """ + def __init__(self, ifname): + super().__init__(ifname) + + def set_path_cost(self, cost): + """ + Set interface path cost, only relevant for STP enabled interfaces + + Example: + + >>> from vyos.ifconfig import Interface + >>> Interface('eth0').set_path_cost(4) + """ + if not os.path.isfile('/sys/class/net/{}/brport/path_cost' + .format(self._ifname)): + raise TypeError('{} is not a bridge port member'.format(self._ifname)) + + return self._write_sysfs('/sys/class/net/{}/brport/path_cost' + .format(self._ifname), cost) + + def set_path_priority(self, priority): + """ + Set interface path priority, only relevant for STP enabled interfaces + + Example: + + >>> from vyos.ifconfig import Interface + >>> Interface('eth0').set_path_priority(4) + """ + if not os.path.isfile('/sys/class/net/{}/brport/priority' + .format(self._ifname)): + raise TypeError('{} is not a bridge port member'.format(self._ifname)) + + return self._write_sysfs('/sys/class/net/{}/brport/priority' + .format(self._ifname), priority) + + class BridgeIf(Interface): """ @@ -774,31 +815,6 @@ class BridgeIf(Interface): cmd = 'ip link set dev {} nomaster'.format(interface) self._cmd(cmd) - def set_path_cost(self, interface, cost): - """ - Set interface path cost, only relevant for STP enabled interfaces - - Example: - - >>> from vyos.ifconfig import Interface - >>> Interface('eth0').path_cost(4) - """ - return self._write_sysfs('/sys/class/net/{}/brif/{}/path_cost' - .format(self._ifname, interface), cost) - - def set_path_priority(self, interface, priority): - """ - Set interface path priority, only relevant for STP enabled interfaces - - Example: - - >>> from vyos.ifconfig import Interface - >>> Interface('eth0').priority(4) - """ - return self._write_sysfs('/sys/class/net/{}/brif/{}/priority' - .format(self._ifname, interface), priority) - - class VLANIf(Interface): """ This class handels the creation and removal of a VLAN interface. It serves diff --git a/src/conf_mode/interface-bridge.py b/src/conf_mode/interface-bridge.py index b20e7f6ff..37b5c4979 100755 --- a/src/conf_mode/interface-bridge.py +++ b/src/conf_mode/interface-bridge.py @@ -20,7 +20,7 @@ from copy import deepcopy from sys import exit from netifaces import interfaces -from vyos.ifconfig import BridgeIf, Interface +from vyos.ifconfig import BridgeIf, STPIf from vyos.configdict import list_diff from vyos.config import Config from vyos import ConfigError @@ -229,16 +229,15 @@ def apply(bridge): # configure additional bridge member options for member in bridge['member']: - # set bridge port path cost - br.set_path_cost(member['name'], member['cost']) - # set bridge port path priority - br.set_path_priority(member['name'], member['priority']) - - i = Interface(member['name']) + i = STPIf(member['name']) # configure ARP cache timeout i.set_arp_cache_tmo(bridge['arp_cache_tmo']) # ignore link state changes i.set_link_detect(bridge['disable_link_detect']) + # set bridge port path cost + i.set_path_cost(member['cost']) + # set bridge port path priority + i.set_path_priority(member['priority']) return None -- cgit v1.2.3