diff options
| author | Christian Breunig <christian@breunig.cc> | 2025-11-20 21:24:32 +0100 |
|---|---|---|
| committer | Christian Breunig <christian@breunig.cc> | 2025-11-21 20:39:06 +0100 |
| commit | 6e9fbf809391b80b8f4c6257af26a8f53b66b53e (patch) | |
| tree | ae5f52bc7e3ce10b3b4421fc3d54f6a26d78d3a3 | |
| parent | 4f2d7c38ca2a0c35e81e0bf8e9a0e4abdf7fdfcc (diff) | |
| download | vyos-1x-6e9fbf809391b80b8f4c6257af26a8f53b66b53e.tar.gz vyos-1x-6e9fbf809391b80b8f4c6257af26a8f53b66b53e.zip | |
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.
| -rwxr-xr-x | smoketest/scripts/cli/test_interfaces_bonding.py | 24 | ||||
| -rwxr-xr-x | src/conf_mode/interfaces_bonding.py | 11 |
2 files changed, 35 insertions, 0 deletions
diff --git a/smoketest/scripts/cli/test_interfaces_bonding.py b/smoketest/scripts/cli/test_interfaces_bonding.py index 21918282d..b6eb5328d 100755 --- a/smoketest/scripts/cli/test_interfaces_bonding.py +++ b/smoketest/scripts/cli/test_interfaces_bonding.py @@ -334,5 +334,29 @@ class BondingInterfaceTest(BasicInterfaceTest.TestCase): id = int(id) + 1 + def test_bonding_member_mtu(self): + # This Smoketest only works on our CI platform where we force the NIC + # to virtio and an MTU of only 1500 bytes max + if not os.path.exists('/tmp/vyos.smoketests.hint'): + self.skipTest('Not running under VyOS CI/CD QEMU environment!') + + for interface in self._interfaces: + for option in self._options.get(interface, []): + self.cli_set(self._base_path + [interface] + option.split()) + + self.cli_set(self._base_path + [interface, 'mtu', '10000']) + + # check validate() - MTU of bond higher then virtio max MTU + with self.assertRaises(ConfigSessionError): + self.cli_commit() + + for interface in self._interfaces: + for option in self._options.get(interface, []): + self.cli_set(self._base_path + [interface] + option.split()) + + self.cli_delete(self._base_path + [interface, 'mtu']) + + self.cli_commit() + if __name__ == '__main__': unittest.main(verbosity=2, failfast=VyOSUnitTestSHIM.TestCase.debug_on()) diff --git a/src/conf_mode/interfaces_bonding.py b/src/conf_mode/interfaces_bonding.py index 68c2885bc..f844d0a21 100755 --- a/src/conf_mode/interfaces_bonding.py +++ b/src/conf_mode/interfaces_bonding.py @@ -248,6 +248,17 @@ def verify(bond): continue raise ConfigError(error_msg + f'it has a "{option_path.replace(".", " ")}" assigned!') + if mtu := bond.get('mtu'): + mtu = int(mtu) + max_mtu = int(EthernetIf(interface).get_max_mtu()) + min_mtu = int(EthernetIf(interface).get_min_mtu()) + if mtu > max_mtu: + raise ConfigError('Configured MTU is greater then member '\ + f'interface "{interface}" maximum of {max_mtu}!') + if mtu < min_mtu: + raise ConfigError('Configured MTU is less then member '\ + f'interface "{interface}" minimum of {min_mtu}!') + if 'primary' in bond: if bond['primary'] not in bond['member']['interface']: raise ConfigError(f'Primary interface of bond "{bond_name}" must be a member interface') |
