From 1b284018d5eb2771888b02f8cebf84a82ed21c88 Mon Sep 17 00:00:00 2001 From: Roopa Prabhu Date: Sun, 17 Jul 2016 22:50:26 -0700 Subject: [PATCH] addons: addressvirtual: enslave macvlans on vrf slaves to the vrf master Ticket: CM-11803 Reviewed By: dsa, scotte, wkok, nikhil, julien Testing Done: tested config of address-virtual lines on vrf slaves This patch does the following: - addressvirtual: enslaves macvlans created on vrf slaves to the vrf master - vrf: when looking for stale slaves on vrf master, skip macvlan devices. This code does basic checking right now and can be improved to include more cases. Signed-off-by: Roopa Prabhu --- addons/addressvirtual.py | 13 +++++++++++-- addons/vrf.py | 20 ++++++++++++++++++++ ifupdownaddons/iproute2.py | 2 ++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/addons/addressvirtual.py b/addons/addressvirtual.py index 18bfa8e..a994a7f 100644 --- a/addons/addressvirtual.py +++ b/addons/addressvirtual.py @@ -125,6 +125,11 @@ class addressvirtual(moduleBase): %str(e)) pass + def _handle_vrf_slaves(self, macvlan_ifacename, ifaceobj): + vrfname = self.ipcmd.link_get_master(ifaceobj.name) + if vrfname: + self.ipcmd.link_set(macvlan_ifacename, 'master', vrfname) + def _get_macs_from_old_config(self, ifaceobj=None): """ This method returns a list of the mac addresses in the address-virtual attribute for the bridge. """ @@ -196,6 +201,10 @@ class addressvirtual(moduleBase): 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) + # handle vrf slaves + if (ifaceobj.link_privflags & ifaceLinkPrivFlags.VRF_SLAVE): + self._handle_vrf_slaves(macvlan_ifacename, ifaceobj) + # Disable IPv6 duplicate address detection on VRR interfaces for key, sysval in { 'accept_dad' : '0', 'dad_transmits' : '0' }.iteritems(): syskey = 'net.ipv6.conf.%s.%s' % (macvlan_ifacename, key) @@ -283,8 +292,8 @@ class addressvirtual(moduleBase): self._remove_address_config(ifaceobj, address_virtual_list) return - if ifaceobj.upperifaces and \ - not ifaceobj.link_privflags & ifaceLinkPrivFlags.VRF_SLAVE: + if (ifaceobj.upperifaces and + not ifaceobj.link_privflags & ifaceLinkPrivFlags.VRF_SLAVE): self.log_error('%s: invalid placement of address-virtual lines (must be configured under an interface with no upper interfaces or parent interfaces)' % (ifaceobj.name), ifaceobj) return diff --git a/addons/vrf.py b/addons/vrf.py index 0847052..fab769b 100644 --- a/addons/vrf.py +++ b/addons/vrf.py @@ -483,6 +483,23 @@ class vrf(moduleBase): vrf_dev_name) utils.exec_command(rule_cmd) + def _is_address_virtual_slaves(self, vrfobj, config_vrfslaves, + vrfslave): + # Address virtual lines on a vrf slave will create + # macvlan devices on the vrf slave and enslave them + # to the vrf master. This function checks if the + # vrf slave is such a macvlan interface. + # XXX: additional possible checks that can be done here + # are: + # - check if it is also a macvlan device of the + # format -v created by the + # address virtual module + vrfslave_lowers = self.ipcmd.link_get_lowers(vrfslave) + if vrfslave_lowers: + if vrfslave_lowers[0] in config_vrfslaves: + return True + return False + def _add_vrf_slaves(self, ifaceobj, ifaceobj_getfunc=None): running_slaves = self.ipcmd.link_get_lowers(ifaceobj.name) config_slaves = ifaceobj.lowerifaces @@ -510,6 +527,9 @@ class vrf(moduleBase): if del_slaves: for s in del_slaves: try: + if self._is_address_virtual_slaves(ifaceobj, + config_slaves, s): + continue sobj = None if ifaceobj_getfunc: sobj = ifaceobj_getfunc(s) diff --git a/ifupdownaddons/iproute2.py b/ifupdownaddons/iproute2.py index 43d4118..74af6e0 100644 --- a/ifupdownaddons/iproute2.py +++ b/ifupdownaddons/iproute2.py @@ -133,6 +133,8 @@ class iproute2(utilsBase): elif citems[i] == 'vrf_slave': linkattrs['kind'] = 'vrf_slave' break + elif citems[i] == 'macvlan' and citems[i + 1] == 'mode': + linkattrs['kind'] = 'macvlan' except Exception as e: if warn: self.logger.debug('%s: parsing error: id, mtu, state, link/ether, vlan, dummy, vxlan, local, remote, ageing, nolearning, vrf, table, vrf_slave are reserved keywords: %s' % (ifname, str(e)))