summaryrefslogtreecommitdiff
path: root/python/vyos
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 19:04:15 +0200
commit2bfd809e9ae198d95b9fcb556440637fdcc4005c (patch)
treeb3ed201903dc0a649888e40a7521036b2d235105 /python/vyos
parent031817eecb14280e3f421cb9c391ab29dbc2fa60 (diff)
downloadvyos-1x-2bfd809e9ae198d95b9fcb556440637fdcc4005c.tar.gz
vyos-1x-2bfd809e9ae198d95b9fcb556440637fdcc4005c.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. (cherry picked from commit cc742d48579e4f76e5d3230d87e22f71f76f9301)
Diffstat (limited to 'python/vyos')
-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 55b7b776f..fb2e49c1d 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