summaryrefslogtreecommitdiff
path: root/python/vyos/ifconfig.py
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2019-11-11 20:13:46 +0100
committerChristian Poessinger <christian@poessinger.com>2019-11-11 20:13:46 +0100
commit80375d2be96c53f2fa4a827f93105dc32931401f (patch)
tree0b805551a0d65cbec00857501e11e721fe0429ac /python/vyos/ifconfig.py
parent8abde544455dd158d080eb6ea7b7ed226b27965a (diff)
parentc9c8cd50f4165c7f86e71a6723f0ebb3a2cbdaf5 (diff)
downloadvyos-1x-80375d2be96c53f2fa4a827f93105dc32931401f.tar.gz
vyos-1x-80375d2be96c53f2fa4a827f93105dc32931401f.zip
Merge branch 'current' of github.com:vyos/vyos-1x into equuleus
* 'current' of github.com:vyos/vyos-1x: ifconfig: T1793: extend set_speed_duplex() delta check [OpenVPN]: T1704: Added uppercase entries of ncp-ciphers, since there seems to be a bug in OpenVPN client when comparing pushed cipher with local ncp cipher list [OpenVPN]: T1704: Moved ncp-ciphers out of encryption block in config template [OpenVPN]: T1704: Changed the description of ncp-ciphers in config [OpenVPN]: T1704: Added function for ncp-ciphers, and ability to disable it. [OpenVPN]: T1704: Changed config structure for OpenVPN encryption to support ncp-ciphers. [OpenVPN]: T1704: Added migration scripts for interface 2-to-3 Intel QAT: T1788: Intel QAT implementation ifconfig: T1793: add delta check on set_speed_duplex() ifconfig: T1793: add delta check on set_flow_control() Python/ifconfig: wireguard: remove trailing whitespaces l2tp: T1747: automatically calculate gw-ip-address QAT: T1788: Intel QAT implementation
Diffstat (limited to 'python/vyos/ifconfig.py')
-rw-r--r--python/vyos/ifconfig.py54
1 files changed, 49 insertions, 5 deletions
diff --git a/python/vyos/ifconfig.py b/python/vyos/ifconfig.py
index 66ccc85e9..279d948b7 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(
@@ -1120,6 +1139,31 @@ 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' 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
cmd = '/sbin/ethtool -s {}'.format(self._ifname)
if speed == 'auto' or duplex == 'auto':
@@ -1496,7 +1540,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 +1564,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 +1587,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))