Add MTU validation - sub cannot be higher than parent

This commit is contained in:
Pim van Pelt
2022-03-13 10:11:56 +00:00
parent 9250e07aed
commit b5d8f03e66
2 changed files with 11 additions and 2 deletions

View File

@ -7,14 +7,16 @@ bondethernet:
---
interface:
description: str(exclude='\'"',required=False)
lcp: str(max=8,matches='[a-z]+[a-z0-9-]{,7}',required=False)
mac: mac(required=False)
lcp: str(max=8,matches='[a-z]+[a-z0-9-]{,7}',required=False)
mtu: int(min=128,max=9216,required=False)
addresses: list(ip_interface(),min=1,max=6,required=False)
sub-interfaces: map(include('sub-interface'),key=int(min=1,max=4294967295),required=False)
---
sub-interface:
description: str(exclude='\'"',required=False)
lcp: str(max=8,matches='[a-z]+[a-z0-9-]{,7}',required=False)
mtu: int(min=128,max=9216,required=False)
addresses: list(ip_interface(),required=False)
encapsulation: include('encapsulation',required=False)
---
@ -23,4 +25,3 @@ encapsulation:
dot1ad: int(min=1,max=4095,required=False)
inner-dot1q: int(min=1,max=4095,required=False)
exact-match: bool(required=False)

View File

@ -121,6 +121,10 @@ def interface(args, yaml):
msgs.append("interface %s does not exist in bondethernets" % ifname)
result = False
if 'mtu' in iface:
iface_mtu = iface['mtu']
else:
iface_mtu = 1500
iface_lcp = has_lcp(yaml, ifname)
iface_address = has_address(yaml, ifname)
@ -132,6 +136,10 @@ def interface(args, yaml):
for sub_id, sub_iface in yaml['interfaces'][ifname]['sub-interfaces'].items():
sub_ifname = "%s.%d" % (ifname, sub_id)
logger.debug("sub-interface %s" % sub_iface)
if 'mtu' in sub_iface:
if sub_iface['mtu'] > iface_mtu:
msgs.append("sub-interface %s has MTU %d higher than parent MTU %d" % (sub_ifname, sub_iface['mtu'], iface_mtu))
result = False
if has_lcp(yaml, sub_ifname):
if not iface_lcp:
msgs.append("sub-interface %s has LCP but %s does not have LCP" % (sub_ifname, ifname))