summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2020-09-25 20:57:37 +0200
committerChristian Poessinger <christian@poessinger.com>2020-09-25 20:58:18 +0200
commit9b268012252a4fe6f253177830abde950e2773b5 (patch)
tree68d826e4f4cdd32593da24f3550dea57b0678992 /python
parent818a75c024e4b4c0403ccfe782fb55517f390bef (diff)
downloadvyos-1x-9b268012252a4fe6f253177830abde950e2773b5.tar.gz
vyos-1x-9b268012252a4fe6f253177830abde950e2773b5.zip
ifconfig: T2912: add helper to verify interface min/max supported MTU
Currently the MTU size of an interface is only checked when entered via CLI but if the interface supportes the configured MTU at all is not verified at all. New helper functions get_min_mtu(), get_max_mtu() and verify_mtu() have been added to provide a central API for validation.
Diffstat (limited to 'python')
-rw-r--r--python/vyos/configverify.py21
-rw-r--r--python/vyos/ifconfig/interface.py4
2 files changed, 23 insertions, 2 deletions
diff --git a/python/vyos/configverify.py b/python/vyos/configverify.py
index afa6c7f06..6e5ba1df0 100644
--- a/python/vyos/configverify.py
+++ b/python/vyos/configverify.py
@@ -23,6 +23,27 @@
from vyos import ConfigError
+def verify_mtu(config):
+ """
+ Common helper function used by interface implementations to perform
+ recurring validation if the specified MTU can be used by the underlaying
+ hardware.
+ """
+ from vyos.ifconfig import Interface
+ if 'mtu' in config:
+ mtu = int(config['mtu'])
+
+ tmp = Interface(config['ifname'])
+ min_mtu = tmp.get_min_mtu()
+ max_mtu = tmp.get_max_mtu()
+
+ if mtu < min_mtu:
+ raise ConfigError(f'Interface MTU too low, ' \
+ f'minimum supported MTU is {min_mtu}!')
+ if mtu > max_mtu:
+ raise ConfigError(f'Interface MTU too high, ' \
+ f'maximum supported MTU is {max_mtu}!')
+
def verify_vrf(config):
"""
Common helper function used by interface implementations to perform
diff --git a/python/vyos/ifconfig/interface.py b/python/vyos/ifconfig/interface.py
index a0f0ffe04..d200fc7a8 100644
--- a/python/vyos/ifconfig/interface.py
+++ b/python/vyos/ifconfig/interface.py
@@ -299,7 +299,7 @@ class Interface(Control):
>>> Interface('eth0').get_min_mtu()
'60'
"""
- return self.get_interface('min_mtu')
+ return int(self.get_interface('min_mtu'))
def get_max_mtu(self):
"""
@@ -310,7 +310,7 @@ class Interface(Control):
>>> Interface('eth0').get_max_mtu()
'9000'
"""
- return self.get_interface('max_mtu')
+ return int(self.get_interface('max_mtu'))
def get_mtu(self):
"""