Skip to content

Commit e9e11e3

Browse files
committed
bond: T8023: validate member interface min/max MTU
It is impossible to set the bond interface MTU to be larger or lower then the limits of the underlaying interface MTU. Add proper commit validation and smoketest.
1 parent 4f2d7c3 commit e9e11e3

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

smoketest/scripts/cli/test_interfaces_bonding.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from base_interfaces_test import BasicInterfaceTest
2121
from base_vyostest_shim import VyOSUnitTestSHIM
2222

23+
from vyos.ethtool import Ethtool
2324
from vyos.ifconfig import Section
2425
from vyos.ifconfig.interface import Interface
2526
from vyos.configsession import ConfigSessionError
@@ -334,5 +335,35 @@ def test_bonding_evpn_multihoming(self):
334335

335336
id = int(id) + 1
336337

338+
def test_bonding_member_mtu(self):
339+
# This Smoketest only works on systems running virtio drivers
340+
for interface in self._interfaces:
341+
for option in self._options.get(interface, []):
342+
self.cli_set(self._base_path + [interface] + option.split())
343+
344+
self.cli_set(self._base_path + [interface, 'mtu', '10000'])
345+
346+
is_virtio = False
347+
for member in self._members:
348+
if Ethtool(member).get_driver_name() == 'virtio_net':
349+
is_virtio = True
350+
break
351+
352+
if not is_virtio:
353+
self.cli_discard()
354+
self.skipTest('Test requires virtio NIC drivers')
355+
356+
# check validate() - MTU of bond higher then virtio max MTU
357+
with self.assertRaises(ConfigSessionError):
358+
self.cli_commit()
359+
360+
for interface in self._interfaces:
361+
for option in self._options.get(interface, []):
362+
self.cli_set(self._base_path + [interface] + option.split())
363+
364+
self.cli_delete(self._base_path + [interface, 'mtu'])
365+
366+
self.cli_commit()
367+
337368
if __name__ == '__main__':
338369
unittest.main(verbosity=2, failfast=VyOSUnitTestSHIM.TestCase.debug_on())

src/conf_mode/interfaces_bonding.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,17 @@ def verify(bond):
248248
continue
249249
raise ConfigError(error_msg + f'it has a "{option_path.replace(".", " ")}" assigned!')
250250

251+
if mtu := bond.get('mtu'):
252+
mtu = int(mtu)
253+
max_mtu = int(EthernetIf(interface).get_max_mtu())
254+
min_mtu = int(EthernetIf(interface).get_min_mtu())
255+
if mtu > max_mtu:
256+
raise ConfigError('Configured MTU is greater then member '\
257+
f'interface "{interface}" maximum of {max_mtu}!')
258+
if mtu < min_mtu:
259+
raise ConfigError('Configured MTU is less then member '\
260+
f'interface "{interface}" minimum of {min_mtu}!')
261+
251262
if 'primary' in bond:
252263
if bond['primary'] not in bond['member']['interface']:
253264
raise ConfigError(f'Primary interface of bond "{bond_name}" must be a member interface')

0 commit comments

Comments
 (0)