summaryrefslogtreecommitdiff
path: root/python/vyos/ethtool.py
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 /python/vyos/ethtool.py
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.
Diffstat (limited to 'python/vyos/ethtool.py')
-rw-r--r--python/vyos/ethtool.py15
1 files changed, 15 insertions, 0 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