summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2021-08-31 18:15:47 +0200
committerChristian Poessinger <christian@poessinger.com>2021-08-31 18:55:44 +0200
commitcc742d48579e4f76e5d3230d87e22f71f76f9301 (patch)
tree97ae925890fa13b3a2b87b88d17793719c40f375
parenta086dc2c429aea9614ac7a9c735c6475c2d6da59 (diff)
downloadvyos-1x-cc742d48579e4f76e5d3230d87e22f71f76f9301.tar.gz
vyos-1x-cc742d48579e4f76e5d3230d87e22f71f76f9301.zip
ethernet: T2241: check if interface supports changing speed/duplex settings
Not all interface drivers have the ability to change the speed and duplex settings. Known drivers with this limitation are vmxnet3, virtio_net and xen_netfront. If this driver is detected, an error will be presented to the user.
-rw-r--r--python/vyos/ethtool.py15
-rwxr-xr-xsrc/conf_mode/interfaces-ethernet.py3
-rwxr-xr-xsrc/migration-scripts/interfaces/20-to-2115
3 files changed, 32 insertions, 1 deletions
diff --git a/python/vyos/ethtool.py b/python/vyos/ethtool.py
index 7dcb68346..968e2e2a3 100644
--- a/python/vyos/ethtool.py
+++ b/python/vyos/ethtool.py
@@ -13,7 +13,9 @@
# You should have received a copy of the GNU Lesser General Public
# License along with this library. If not, see <http://www.gnu.org/licenses/>.
+import os
import re
+
from vyos.util import popen
class Ethtool:
@@ -41,8 +43,18 @@ class Ethtool:
# }
_speed_duplex = { }
_ring_buffers = { }
+ _driver_name = None
def __init__(self, ifname):
+ # Get driver used for interface
+ sysfs_file = f'/sys/class/net/{ifname}/device/driver/module'
+ if os.path.exists(sysfs_file):
+ link = os.readlink(sysfs_file)
+ self._driver_name = os.path.basename(link)
+
+ if not self._driver_name:
+ raise ValueError(f'Could not determine driver for interface {ifname}!')
+
# Build a dictinary of supported link-speed and dupley settings.
out, err = popen(f'ethtool {ifname}')
reading = False
@@ -142,6 +154,9 @@ class Ethtool:
if duplex not in ['full', 'half']:
raise ValueError(f'Value "{duplex}" for duplex is invalid!')
+ if self._driver_name in ['vmxnet3', 'virtio_net', 'xen_netfront']:
+ return False
+
if speed in self._speed_duplex:
if duplex in self._speed_duplex[speed]:
return True
diff --git a/src/conf_mode/interfaces-ethernet.py b/src/conf_mode/interfaces-ethernet.py
index 27c4a7c38..889f4856f 100755
--- a/src/conf_mode/interfaces-ethernet.py
+++ b/src/conf_mode/interfaces-ethernet.py
@@ -85,7 +85,8 @@ def verify(ethernet):
speed = ethernet['speed']
duplex = ethernet['duplex']
if not ethtool.check_speed_duplex(speed, duplex):
- raise ConfigError(f'Adapter does not support speed "{speed}" and duplex "{duplex}"!')
+ raise ConfigError(f'Adapter does not support changing speed and duplex '\
+ f'settings to: {speed}/{duplex}!')
if 'ring_buffer' in ethernet:
max_rx = ethtool.get_rx_buffer()
diff --git a/src/migration-scripts/interfaces/20-to-21 b/src/migration-scripts/interfaces/20-to-21
index 4b0e70d35..bd89dcdb4 100755
--- a/src/migration-scripts/interfaces/20-to-21
+++ b/src/migration-scripts/interfaces/20-to-21
@@ -89,6 +89,21 @@ for ifname in config.list_nodes(base):
if config.exists(base + [ifname, 'offload', 'ufo']):
config.delete(base + [ifname, 'offload', 'ufo'])
+ # Also while processing the interface configuration, not all adapters support
+ # changing the speed and duplex settings. If the desired speed and duplex
+ # values do not work for the NIC driver, we change them back to the default
+ # value of "auto" - which will be applied if the CLI node is deleted.
+ speed_path = base + [ifname, 'speed']
+ duplex_path = base + [ifname, 'duplex']
+ # speed and duplex must always be set at the same time if not set to "auto"
+ if config.exists(speed_path) and config.exists(duplex_path):
+ speed = config.return_value(speed_path)
+ duplex = config.return_value(duplex_path)
+ if speed != 'auto' and duplex != 'auto':
+ if not eth.check_speed_duplex(speed, duplex):
+ config.delete(speed_path)
+ config.delete(duplex_path)
+
try:
with open(file_name, 'w') as f:
f.write(config.to_string())