diff options
author | Nicolas Vollmar <nvollmar@gmail.com> | 2024-12-12 19:34:20 +0100 |
---|---|---|
committer | Nicolas Vollmar <nvo@scaling.ch> | 2024-12-24 13:44:20 +0100 |
commit | 3d5cc842ea651de68cfac299d6a8bd2849c9a1f8 (patch) | |
tree | b5342ba5384996859f58a6c72e9c70c434fbede5 /python | |
parent | b05cbfa71570bce1f4f470551e5c0217d14ba5a8 (diff) | |
download | vyos-1x-3d5cc842ea651de68cfac299d6a8bd2849c9a1f8.tar.gz vyos-1x-3d5cc842ea651de68cfac299d6a8bd2849c9a1f8.zip |
T6944: adds option to enable switchdev mode on ethernet interface
Diffstat (limited to 'python')
-rw-r--r-- | python/vyos/ifconfig/ethernet.py | 21 |
1 files changed, 21 insertions, 0 deletions
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) |