From 9e0be374dc0a6de73535b85bb1ac5c6904eb8a8c Mon Sep 17 00:00:00 2001 From: Julien Fortin Date: Fri, 29 Apr 2016 21:19:42 +0200 Subject: [PATCH] new ifupdown2.conf variable to adjust logical devices MTU Ticket: CM-8736 Reviewed By: Roopa Testing Done: Smoke tests + the ones from the ticket By default ifupdown2 will adjust logical devices MTU based on the physical interface they are running on top of. set this flag to 0 to disable this behaviour adjust_logical_dev_mtu=1 --- addons/addressvirtual.py | 15 +++++++++++++++ addons/bridge.py | 2 +- addons/vlan.py | 10 ++++++++-- config/ifupdown2.conf | 4 ++++ ifupdownaddons/bridgeutils.py | 5 ++--- ifupdownaddons/iproute2.py | 21 ++++++++++++++------- 6 files changed, 44 insertions(+), 13 deletions(-) diff --git a/addons/addressvirtual.py b/addons/addressvirtual.py index f95d694..55f01af 100644 --- a/addons/addressvirtual.py +++ b/addons/addressvirtual.py @@ -7,6 +7,8 @@ from ifupdown.iface import * from ifupdownaddons.modulebase import moduleBase from ifupdownaddons.iproute2 import iproute2 + +import ifupdown.ifupdownconfig as ifupdownConfig import ifupdown.statemanager as statemanager import ifupdown.rtnetlink_api as rtnetlink_api import ifupdown.ifupdownflags as ifupdownflags @@ -146,6 +148,11 @@ class addressvirtual(moduleBase): def _apply_address_config(self, ifaceobj, address_virtual_list): purge_existing = False if ifupdownflags.flags.PERFMODE else True + lower_iface_mtu = update_mtu = None + if ifupdownConfig.config.get('adjust_logical_dev_mtu', '1') != '0': + if ifaceobj.lowerifaces and address_virtual_list: + update_mtu = True + hwaddress = [] self.ipcmd.batch_start() av_idx = 0 @@ -177,10 +184,18 @@ class addressvirtual(moduleBase): hwaddress.append(mac) self.ipcmd.addr_add_multiple(macvlan_ifacename, ips, purge_existing) + # If link existed before, flap the link if not link_created: self._fix_connected_route(ifaceobj, macvlan_ifacename, ips[0]) + if update_mtu: + lower_iface_mtu = self.ipcmd.link_get_mtu(ifaceobj.lowerifaces[0], refresh=True) + update_mtu = False + + if lower_iface_mtu and lower_iface_mtu != self.ipcmd.link_get_mtu(macvlan_ifacename): + self.ipcmd.link_set_mtu(macvlan_ifacename, lower_iface_mtu) + av_idx += 1 self.ipcmd.batch_commit() diff --git a/addons/bridge.py b/addons/bridge.py index 8caa1e4..ac8ae67 100644 --- a/addons/bridge.py +++ b/addons/bridge.py @@ -1036,7 +1036,7 @@ class bridge(moduleBase): try: if ifaceobj.get_attr_value_first('bridge-vlan-aware') == 'yes': if (bridge_just_created or - not self.ipcmd.bridge_is_vlan_aware(ifaceobj.name)): + not self.ipcmd.bridge_is_vlan_aware(ifaceobj.name)): self.ipcmd.link_set(ifaceobj.name, 'vlan_filtering', '1', False, "bridge") if not bridge_just_created: diff --git a/addons/vlan.py b/addons/vlan.py index 866be26..e50fa81 100644 --- a/addons/vlan.py +++ b/addons/vlan.py @@ -7,6 +7,8 @@ from ifupdown.iface import * from ifupdownaddons.modulebase import moduleBase from ifupdownaddons.iproute2 import iproute2 +import ifupdown.ifupdownconfig as ifupdownConfig + import ifupdown.rtnetlink_api as rtnetlink_api import ifupdown.ifupdownflags as ifupdownflags import logging @@ -92,7 +94,7 @@ class vlan(moduleBase): if vlan_raw_device: return vlan_raw_device return self._get_vlan_raw_device_from_ifacename(ifaceobj.name) - + def get_dependent_ifacenames(self, ifaceobj, ifaceobjs_all=None): if not self._is_vlan_device(ifaceobj): return None @@ -136,6 +138,10 @@ class vlan(moduleBase): raise Exception('rawdevice %s not present' %vlanrawdevice) if self.ipcmd.link_exists(ifaceobj.name): self._bridge_vid_add_del(ifaceobj, vlanrawdevice, vlanid) + if ifupdownConfig.config.get('adjust_logical_dev_mtu', '1') != '0' and len(ifaceobj.lowerifaces): + lower_iface_mtu = self.ipcmd.link_get_mtu(ifaceobj.lowerifaces[0], refresh=True) + if not lower_iface_mtu == self.ipcmd.link_get_mtu(ifaceobj.name): + self.ipcmd.link_set_mtu(ifaceobj.name, lower_iface_mtu) return rtnetlink_api.rtnl_api.create_vlan(vlanrawdevice, ifaceobj.name, vlanid) @@ -204,7 +210,7 @@ class vlan(moduleBase): def _init_command_handlers(self): if not self.ipcmd: self.ipcmd = iproute2() - + def run(self, ifaceobj, operation, query_ifaceobj=None, **extra_args): """ run vlan configuration on the interface object passed as argument diff --git a/config/ifupdown2.conf b/config/ifupdown2.conf index d5b808a..13cbbdc 100644 --- a/config/ifupdown2.conf +++ b/config/ifupdown2.conf @@ -58,3 +58,7 @@ addr_config_squash=0 # ifaces stanzas for an interface ifaceobj_squash=0 +# By default ifupdown2 will adjust logical devices MTU +# based on the physical interface they are running on top of. +# set this flag to 0 to disable this behaviour +adjust_logical_dev_mtu=1 diff --git a/ifupdownaddons/bridgeutils.py b/ifupdownaddons/bridgeutils.py index 39640df..edffa71 100644 --- a/ifupdownaddons/bridgeutils.py +++ b/ifupdownaddons/bridgeutils.py @@ -96,7 +96,7 @@ class brctl(utilsBase): ##battrs['mcsnoop'] = broutlines[12].split('mc snooping')[1].strip() #battrs['mclmt'] = broutlines[13].split('mc last member timer')[1].split()[0].strip() except Exception, e: - self.logger.warn(str(e)) + self.logger.warn('%s: error while processing bridge attributes: %s' % (bridgename, str(e))) pass linkCache.update_attrdict([bridgename, 'linkinfo'], battrs) @@ -121,8 +121,7 @@ class brctl(utilsBase): #bportattrs['mcrouters'] = bplines[6].split('mc router')[1].split()[0].strip() #bportattrs['mc fast leave'] = bplines[6].split('mc fast leave')[1].strip() except Exception, e: - self.logger.warn(str(e)) - pass + self.logger.warn('%s: error while processing bridge attributes: %s' % (bridgename, str(e))) bports[pname] = bportattrs linkCache.update_attrdict([bridgename, 'linkinfo', 'ports'], bports) diff --git a/ifupdownaddons/iproute2.py b/ifupdownaddons/iproute2.py index 281f7da..cf15046 100644 --- a/ifupdownaddons/iproute2.py +++ b/ifupdownaddons/iproute2.py @@ -39,7 +39,7 @@ class iproute2(utilsBase): iproute2._cache_fill_done = True return True return False - + def _link_fill(self, ifacename=None, refresh=False): """ fills cache with link information @@ -141,7 +141,7 @@ class iproute2(utilsBase): try: # Check if ifacename is already full, in which case, return if ifacename and not refresh: - linkCache.get_attr([ifacename, 'addrs']) + linkCache.get_attr([ifacename, 'addrs']) return except: pass @@ -418,6 +418,13 @@ class iproute2(utilsBase): self.link_up(ifacename) self._cache_update([ifacename, 'hwaddress'], hwaddress) + def link_set_mtu(self, ifacename, mtu): + if not mtu or not ifacename: return + + with open('/sys/class/net/%s/mtu' % ifacename, 'w') as f: + f.write(mtu) + self._cache_update([ifacename, 'mtu'], mtu) + def link_set_alias(self, ifacename, alias): self.exec_commandl(['ip', 'link', 'set', 'dev', ifacename, 'alias', alias]) @@ -487,7 +494,7 @@ class iproute2(utilsBase): v = vlan_device_name.split('.') if len(v) != 2: self.logger.warn('invalid vlan device name %s' %vlan_device_name) - return + return self.link_create_vlan(vlan_device_name, v[0], v[1]) def link_create_macvlan(self, name, linkdev, mode='private'): @@ -622,8 +629,8 @@ class iproute2(utilsBase): def link_get_linkinfo_attrs(self, ifacename): return self._cache_get('link', [ifacename, 'linkinfo']) - def link_get_mtu(self, ifacename): - return self._cache_get('link', [ifacename, 'mtu']) + def link_get_mtu(self, ifacename, refresh=False): + return self._cache_get('link', [ifacename, 'mtu'], refresh=refresh) def link_get_kind(self, ifacename): return self._cache_get('link', [ifacename, 'kind']) @@ -767,7 +774,7 @@ class iproute2(utilsBase): vlan_str = '' if vlan: vlan_str = 'vlan %s ' % vlan - + dst_str = '' if remote: dst_str = 'dst %s ' % remote @@ -834,7 +841,7 @@ class iproute2(utilsBase): iflags = int(flags, 16) if (iflags & 0x0001): ret = True - except: + except: ret = False pass return ret