From 1a20fbccfccce7fa47c2028ccbb1403182739c3e Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Sun, 10 Nov 2019 21:24:17 +0100 Subject: Python/ifconfig: wireguard: remove trailing whitespaces --- python/vyos/ifconfig.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'python/vyos/ifconfig.py') diff --git a/python/vyos/ifconfig.py b/python/vyos/ifconfig.py index 66ccc85e9..8a4ad6ffc 100644 --- a/python/vyos/ifconfig.py +++ b/python/vyos/ifconfig.py @@ -1496,7 +1496,7 @@ class WireGuardIf(Interface): cmd = "wg set {0} peer {1} remove".format( self._ifname, str(peerkey)) return self._cmd(cmd) - + def op_show_interface(self): wgdump = vyos.interfaces.wireguard_dump().get(self._ifname,None) @@ -1520,7 +1520,7 @@ class WireGuardIf(Interface): if wgdump['peers']: pubkey = c.return_effective_value(["peer",peer,"pubkey"]) if pubkey in wgdump['peers']: - wgpeer = wgdump['peers'][pubkey] + wgpeer = wgdump['peers'][pubkey] print (" peer: {}".format(peer)) print (" public key: {}".format(pubkey)) @@ -1543,15 +1543,15 @@ class WireGuardIf(Interface): elif int(wgpeer['latest_handshake']) == 0: """ no handshake ever """ status = "inactive" - print (" status: {}".format(status)) + print (" status: {}".format(status)) if wgpeer['endpoint'] is not None: print (" endpoint: {}".format(wgpeer['endpoint'])) if wgpeer['allowed_ips'] is not None: print (" allowed ips: {}".format(",".join(wgpeer['allowed_ips']).replace(",",", "))) - - if wgpeer['transfer_rx'] > 0 or wgpeer['transfer_tx'] > 0: + + if wgpeer['transfer_rx'] > 0 or wgpeer['transfer_tx'] > 0: rx_size =size(wgpeer['transfer_rx'],system=alternative) tx_size =size(wgpeer['transfer_tx'],system=alternative) print (" transfer: {} received, {} sent".format(rx_size,tx_size)) -- cgit v1.2.3 From a1611eb01dd117d9dce6571cb27bac94481fa753 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Sun, 10 Nov 2019 22:35:45 +0100 Subject: ifconfig: T1793: add delta check on set_flow_control() The flow control settings should only be changed when they need to. If flow control is altered, the kernel will disable and re-enable the interface. This will not only let the switchport flap but it will also reset e.g. BGP sessions. In addition - this also reduces the config commit time. --- python/vyos/ifconfig.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'python/vyos/ifconfig.py') diff --git a/python/vyos/ifconfig.py b/python/vyos/ifconfig.py index 8a4ad6ffc..cc63482de 100644 --- a/python/vyos/ifconfig.py +++ b/python/vyos/ifconfig.py @@ -21,6 +21,7 @@ import glob import time import vyos.interfaces + from vyos.validate import * from vyos.config import Config from vyos import ConfigError @@ -1085,6 +1086,24 @@ class EthernetIf(VLANIf): .format(self.get_driver_name())) return + # Get current flow control settings: + cmd = '/sbin/ethtool --show-pause {0}'.format(self._ifname) + tmp = self._cmd(cmd) + + # The above command returns - with tabs: + # + # Pause parameters for eth0: + # Autonegotiate: on + # RX: off + # TX: off + if re.search("Autonegotiate:\ton", tmp): + if enable == "on": + # flowcontrol is already enabled - no need to re-enable it again + # this will prevent the interface from flapping as applying the + # flow-control settings will take the interface down and bring + # it back up every time. + return + # Assemble command executed on system. Unfortunately there is no way # to change this setting via sysfs cmd = '/sbin/ethtool --pause {0} autoneg {1} tx {1} rx {1}'.format( -- cgit v1.2.3 From 9e49477700647a390bebc18c02e6ce735d740e0c Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Sun, 10 Nov 2019 22:44:32 +0100 Subject: ifconfig: T1793: add delta check on set_speed_duplex() The speend and duplex settings should only be changed when they need to. Always configuring this setting will make the kernel disable and re-enable the physical interface. This will not only let the switchport flap but it will also reset e.g. BGP sessions. This is the first part of this fix for speed/duplex auto settings. In addition - this also reduces the config commit time. --- python/vyos/ifconfig.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'python/vyos/ifconfig.py') diff --git a/python/vyos/ifconfig.py b/python/vyos/ifconfig.py index cc63482de..24a718e73 100644 --- a/python/vyos/ifconfig.py +++ b/python/vyos/ifconfig.py @@ -1139,6 +1139,14 @@ class EthernetIf(VLANIf): .format(self.get_driver_name())) return + # Get current speed and duplex settings: + cmd = '/sbin/ethtool {0}'.format(self._ifname) + tmp = self._cmd(cmd) + + if re.search("\tAuto-negotiation: on", tmp): + if speed == 'auto' or duplex == 'auto': + # bail out early as nothing is to change + return cmd = '/sbin/ethtool -s {}'.format(self._ifname) if speed == 'auto' or duplex == 'auto': -- cgit v1.2.3 From c9c8cd50f4165c7f86e71a6723f0ebb3a2cbdaf5 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Mon, 11 Nov 2019 19:42:11 +0100 Subject: ifconfig: T1793: extend set_speed_duplex() delta check Commit 9e4947770064 ("ifconfig: T1793: add delta check on set_speed_duplex()") was wave1 of reducing the amount of switch-port flaps and BGP session resets. The delta check now also handles the case of fixed speed and duplex settings. --- python/vyos/ifconfig.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'python/vyos/ifconfig.py') diff --git a/python/vyos/ifconfig.py b/python/vyos/ifconfig.py index 24a718e73..279d948b7 100644 --- a/python/vyos/ifconfig.py +++ b/python/vyos/ifconfig.py @@ -1144,7 +1144,24 @@ class EthernetIf(VLANIf): tmp = self._cmd(cmd) if re.search("\tAuto-negotiation: on", tmp): - if speed == 'auto' or duplex == 'auto': + if speed == 'auto' and duplex == 'auto': + # bail out early as nothing is to change + return + else: + # read in current speed and duplex settings + cur_speed = 0 + cur_duplex = '' + for line in tmp.splitlines(): + if line.lstrip().startswith("Speed:"): + non_decimal = re.compile(r'[^\d.]+') + cur_speed = non_decimal.sub('', line) + continue + + if line.lstrip().startswith("Duplex:"): + cur_duplex = line.split()[-1].lower() + break + + if (cur_speed == speed) and (cur_duplex == duplex): # bail out early as nothing is to change return -- cgit v1.2.3