summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Vollmar <nvollmar@gmail.com>2024-12-12 19:34:20 +0100
committerNicolas Vollmar <nvo@scaling.ch>2024-12-24 13:44:20 +0100
commit3d5cc842ea651de68cfac299d6a8bd2849c9a1f8 (patch)
treeb5342ba5384996859f58a6c72e9c70c434fbede5
parentb05cbfa71570bce1f4f470551e5c0217d14ba5a8 (diff)
downloadvyos-1x-3d5cc842ea651de68cfac299d6a8bd2849c9a1f8.tar.gz
vyos-1x-3d5cc842ea651de68cfac299d6a8bd2849c9a1f8.zip
T6944: adds option to enable switchdev mode on ethernet interface
-rw-r--r--interface-definitions/interfaces_ethernet.xml.in6
-rw-r--r--python/vyos/ifconfig/ethernet.py21
-rwxr-xr-xsmoketest/scripts/cli/test_interfaces_ethernet.py9
3 files changed, 36 insertions, 0 deletions
diff --git a/interface-definitions/interfaces_ethernet.xml.in b/interface-definitions/interfaces_ethernet.xml.in
index 89f990d41..b3559a626 100644
--- a/interface-definitions/interfaces_ethernet.xml.in
+++ b/interface-definitions/interfaces_ethernet.xml.in
@@ -56,6 +56,12 @@
</properties>
<defaultValue>auto</defaultValue>
</leafNode>
+ <leafNode name="switchdev">
+ <properties>
+ <help>Enables switchdev mode on interface</help>
+ <valueless/>
+ </properties>
+ </leafNode>
#include <include/interface/eapol.xml.i>
<node name="evpn">
<properties>
diff --git a/python/vyos/ifconfig/ethernet.py b/python/vyos/ifconfig/ethernet.py
index 50dd0f396..a8b72cc9c 100644
--- a/python/vyos/ifconfig/ethernet.py
+++ b/python/vyos/ifconfig/ethernet.py
@@ -417,6 +417,25 @@ class EthernetIf(Interface):
print(f'could not set "{rx_tx}" ring-buffer for {ifname}')
return output
+ def set_switchdev(self, enable):
+ ifname = self.config['ifname']
+ addr, code = self._popen(f'ethtool -i {ifname} | grep bus-info | awk \'{{print $2}}\'')
+ if code != 0:
+ print(f'could not resolve PCIe address of {ifname}')
+ return
+
+ enabled = False
+ state, code = self._popen(f'/sbin/devlink dev eswitch show pci/{addr} | awk \'{{print $3}}\'')
+ if code == 0 and state == 'switchdev':
+ enabled = True
+
+ if enable and not enabled:
+ output, code = self._popen(f'/sbin/devlink dev eswitch set pci/{addr} mode switchdev')
+ if code != 0:
+ print(f'{ifname} does not support switchdev mode')
+ elif not enable and enabled:
+ self._cmd(f'/sbin/devlink dev eswitch set pci/{addr} mode legacy')
+
def update(self, config):
""" General helper function which works on a dictionary retrived by
get_config_dict(). It's main intention is to consolidate the scattered
@@ -463,6 +482,8 @@ class EthernetIf(Interface):
for rx_tx, size in config['ring_buffer'].items():
self.set_ring_buffer(rx_tx, size)
+ self.set_switchdev('switchdev' in config)
+
# call base class last
super().update(config)
diff --git a/smoketest/scripts/cli/test_interfaces_ethernet.py b/smoketest/scripts/cli/test_interfaces_ethernet.py
index c02ca613b..eeebaa4ca 100755
--- a/smoketest/scripts/cli/test_interfaces_ethernet.py
+++ b/smoketest/scripts/cli/test_interfaces_ethernet.py
@@ -223,5 +223,14 @@ class EthernetInterfaceTest(BasicInterfaceTest.TestCase):
frrconfig = self.getFRRconfig(f'interface {interface}', daemon=mgmt_daemon)
self.assertIn(f' evpn mh uplink', frrconfig)
+ def test_switchdev(self):
+ interface = self._interfaces[0]
+ self.cli_set(self._base_path + [interface, 'switchdev'])
+
+ # check validate() - virtual interfaces do not support switchdev
+ # should print out warning that enabling failed
+
+ self.cli_delete(self._base_path + [interface, 'switchdev'])
+
if __name__ == '__main__':
unittest.main(verbosity=2)