mirror of
https://github.com/CumulusNetworks/ifupdown2.git
synced 2024-05-06 15:54:50 +00:00
addons: bridge: set bridge mtu on device creation
Signed-off-by: Julien Fortin <julien@cumulusnetworks.com>
This commit is contained in:
@@ -2043,6 +2043,24 @@ class bridge(moduleBase):
|
||||
self.logger.debug('(cache %s)' % cached_ifla_brport_group_fwd_maskhi)
|
||||
brports_ifla_info_slave_data[brport_name][Link.IFLA_BRPORT_GROUP_FWD_MASKHI] = ifla_brport_group_fwd_maskhi
|
||||
|
||||
def get_bridge_mtu(self, ifaceobj):
|
||||
user_config_mtu = ifaceobj.get_attr_value_first("mtu")
|
||||
|
||||
if not user_config_mtu:
|
||||
user_config_mtu = policymanager.policymanager_api.get_attr_default(
|
||||
module_name=self.__class__.__name__,
|
||||
attr="mtu"
|
||||
)
|
||||
|
||||
try:
|
||||
if user_config_mtu:
|
||||
mtu = int(user_config_mtu)
|
||||
self.logger.info("%s: set bridge mtu %s" % (ifaceobj.name, mtu))
|
||||
return mtu
|
||||
except Exception as e:
|
||||
self.logger.warning("%s: invalid bridge mtu %s: %s" % (ifaceobj.name, user_config_mtu, str(e)))
|
||||
return 0
|
||||
|
||||
def up_bridge(self, ifaceobj, ifaceobj_getfunc):
|
||||
ifname = ifaceobj.name
|
||||
|
||||
@@ -2054,7 +2072,7 @@ class bridge(moduleBase):
|
||||
link_just_created = not link_exists
|
||||
|
||||
if not link_exists:
|
||||
netlink.link_add_bridge(ifname)
|
||||
netlink.link_add_bridge(ifname, self.get_bridge_mtu(ifaceobj))
|
||||
else:
|
||||
self.logger.info('%s: bridge already exists' % ifname)
|
||||
|
||||
|
@@ -242,11 +242,11 @@ class Netlink(utilsBase):
|
||||
raise Exception('netlink: cannot set link %s protodown %s: %s'
|
||||
% (ifacename, state, str(e)))
|
||||
|
||||
def link_add_bridge(self, ifname):
|
||||
def link_add_bridge(self, ifname, mtu=None):
|
||||
self.logger.info('%s: netlink: ip link add %s type bridge' % (ifname, ifname))
|
||||
if ifupdownflags.flags.DRYRUN: return
|
||||
try:
|
||||
return self._nlmanager_api.link_add_bridge(ifname)
|
||||
return self._nlmanager_api.link_add_bridge(ifname, mtu=mtu)
|
||||
except Exception as e:
|
||||
raise Exception('netlink: cannot create bridge %s: %s' % (ifname, str(e)))
|
||||
|
||||
|
@@ -637,7 +637,7 @@ class NetlinkManager(object):
|
||||
link.build_message(self.sequence.next(), self.pid)
|
||||
return self.tx_nlpacket_get_response(link)
|
||||
|
||||
def _link_add(self, ifindex, ifname, kind, ifla_info_data):
|
||||
def _link_add(self, ifindex, ifname, kind, ifla_info_data, mtu=None):
|
||||
"""
|
||||
Build and TX a RTM_NEWLINK message to add the desired interface
|
||||
"""
|
||||
@@ -651,6 +651,9 @@ class NetlinkManager(object):
|
||||
if ifindex:
|
||||
link.add_attribute(Link.IFLA_LINK, ifindex)
|
||||
|
||||
if mtu:
|
||||
link.add_attribute(Link.IFLA_MTU, mtu)
|
||||
|
||||
link.add_attribute(Link.IFLA_LINKINFO, {
|
||||
Link.IFLA_INFO_KIND: kind,
|
||||
Link.IFLA_INFO_DATA: ifla_info_data
|
||||
@@ -658,8 +661,8 @@ class NetlinkManager(object):
|
||||
link.build_message(self.sequence.next(), self.pid)
|
||||
return self.tx_nlpacket_get_response(link)
|
||||
|
||||
def link_add_bridge(self, ifname, ifla_info_data={}):
|
||||
return self._link_add(ifindex=None, ifname=ifname, kind='bridge', ifla_info_data=ifla_info_data)
|
||||
def link_add_bridge(self, ifname, ifla_info_data={}, mtu=None):
|
||||
return self._link_add(ifindex=None, ifname=ifname, kind='bridge', ifla_info_data=ifla_info_data, mtu=mtu)
|
||||
|
||||
def link_add_vlan(self, ifindex, ifname, vlanid, vlan_protocol=None):
|
||||
"""
|
||||
|
Reference in New Issue
Block a user