2014-10-09 16:02:46 -07:00
|
|
|
#!/usr/bin/python
|
|
|
|
#
|
2018-12-13 11:43:32 -08:00
|
|
|
# Copyright 2014-2017 Cumulus Networks, Inc. All rights reserved.
|
2014-10-09 16:02:46 -07:00
|
|
|
# Author: Roopa Prabhu, roopa@cumulusnetworks.com
|
|
|
|
#
|
|
|
|
|
|
|
|
import os
|
|
|
|
import glob
|
|
|
|
|
2019-01-25 09:58:25 +08:00
|
|
|
from string import maketrans
|
|
|
|
from collections import deque
|
2018-12-13 11:43:32 -08:00
|
|
|
from ipaddr import IPNetwork, IPv6Network
|
|
|
|
|
|
|
|
try:
|
|
|
|
from ifupdown2.ifupdown.iface import *
|
2018-06-18 16:51:51 +02:00
|
|
|
from ifupdown2.ifupdown.utils import utils
|
2018-12-13 11:43:32 -08:00
|
|
|
from ifupdown2.ifupdown.netlink import netlink
|
|
|
|
|
|
|
|
from ifupdown2.ifupdownaddons.LinkUtils import LinkUtils
|
|
|
|
from ifupdown2.ifupdownaddons.modulebase import moduleBase
|
|
|
|
|
|
|
|
import ifupdown2.ifupdown.statemanager as statemanager
|
2018-06-25 16:36:26 +02:00
|
|
|
import ifupdown2.ifupdown.policymanager as policymanager
|
2018-12-13 11:43:32 -08:00
|
|
|
import ifupdown2.ifupdown.ifupdownflags as ifupdownflags
|
|
|
|
import ifupdown2.ifupdown.ifupdownconfig as ifupdownconfig
|
|
|
|
except ImportError:
|
|
|
|
from ifupdown.iface import *
|
2018-06-18 16:51:51 +02:00
|
|
|
from ifupdown.utils import utils
|
2018-12-13 11:43:32 -08:00
|
|
|
from ifupdown.netlink import netlink
|
|
|
|
|
|
|
|
from ifupdownaddons.LinkUtils import LinkUtils
|
|
|
|
from ifupdownaddons.modulebase import moduleBase
|
|
|
|
|
|
|
|
import ifupdown.statemanager as statemanager
|
2018-06-25 16:36:26 +02:00
|
|
|
import ifupdown.policymanager as policymanager
|
2018-12-13 11:43:32 -08:00
|
|
|
import ifupdown.ifupdownflags as ifupdownflags
|
|
|
|
import ifupdown.ifupdownconfig as ifupdownconfig
|
|
|
|
|
|
|
|
|
2014-10-09 16:02:46 -07:00
|
|
|
class addressvirtual(moduleBase):
|
|
|
|
""" ifupdown2 addon module to configure virtual addresses """
|
|
|
|
|
|
|
|
_modinfo = {'mhelp' : 'address module configures virtual addresses for ' +
|
|
|
|
'interfaces. It creates a macvlan interface for ' +
|
|
|
|
'every mac ip address-virtual line',
|
|
|
|
'attrs' : {
|
|
|
|
'address-virtual' :
|
2016-08-01 09:19:31 +02:00
|
|
|
{ 'help' : 'bridge router virtual mac and ips',
|
2016-12-29 16:29:20 +00:00
|
|
|
'multivalue' : True,
|
2016-08-01 17:20:44 +02:00
|
|
|
'validvals' : ['<mac-ip/prefixlen-list>',],
|
2018-06-18 16:51:51 +02:00
|
|
|
'example': ['address-virtual 00:11:22:33:44:01 11.0.1.1/24 11.0.1.2/24']
|
|
|
|
},
|
|
|
|
'address-virtual-ipv6-addrgen': {
|
|
|
|
'help': 'enable disable ipv6 link addrgenmode',
|
|
|
|
'validvals': ['on', 'off'],
|
|
|
|
'default': 'on',
|
|
|
|
'example': [
|
2018-06-18 19:28:32 +02:00
|
|
|
'address-virtual-ipv6-addrgen on',
|
|
|
|
'address-virtual-ipv6-addrgen off'
|
2018-06-18 16:51:51 +02:00
|
|
|
]
|
2019-01-25 09:58:25 +08:00
|
|
|
},
|
|
|
|
"vrrp": {
|
|
|
|
"help": "VRRP support",
|
|
|
|
"multivalue": True,
|
|
|
|
"example": [
|
|
|
|
"vrrp 1 10.0.0.15/24 2001:0db8::0370:7334/64",
|
|
|
|
"vrrp 42 10.0.0.42/24"
|
|
|
|
]
|
2018-06-18 16:51:51 +02:00
|
|
|
}
|
|
|
|
}}
|
2014-10-09 16:02:46 -07:00
|
|
|
|
2014-11-03 17:55:51 -08:00
|
|
|
|
2014-10-09 16:02:46 -07:00
|
|
|
def __init__(self, *args, **kargs):
|
|
|
|
moduleBase.__init__(self, *args, **kargs)
|
|
|
|
self.ipcmd = None
|
2014-11-03 17:55:51 -08:00
|
|
|
self._bridge_fdb_query_cache = {}
|
2018-06-25 16:36:26 +02:00
|
|
|
self.addressvirtual_with_route_metric = utils.get_boolean_from_string(
|
|
|
|
policymanager.policymanager_api.get_module_globals(
|
|
|
|
module_name=self.__class__.__name__,
|
|
|
|
attr='addressvirtual_with_route_metric'
|
|
|
|
),
|
|
|
|
default=True
|
|
|
|
)
|
2014-10-09 16:02:46 -07:00
|
|
|
|
2018-07-23 10:38:29 +02:00
|
|
|
self.address_virtual_ipv6_addrgen_value_dict = {'on': 0, 'yes': 0, '0': 0, 'off': 1, 'no': 1, '1': 1}
|
2019-01-25 09:58:25 +08:00
|
|
|
self.mac_translate_tab = maketrans(":.-,", " ")
|
2018-07-23 10:38:29 +02:00
|
|
|
|
[PATCH ifupdown2] addons: addressvirtual: fixup macvlan device enslavements for vrfs
Ticket: CM-12988
Reviewed By: julien, nikhil, dsa
Testing Done: tested ifup and ifdown of vrf devices with address virtual
slaves
This patch fixes up macvlan device enslavements when vrf device
or vrf slave is brought down and up. address virtual macvlan
devices on vrf slaves need to enslaved to the vrf. This
patch checks and fixes up those vrf enslavements for the following
cases:
ifdown <vrf_device> && ifup <vrf_device>
ifdown <vrf_slave> && ifup <vrf_slave>
starting state:
------------
$ip -br link show
myvrf UP 46:c6:44:db:37:60 <NOARP,MASTER,UP,LOWER_UP>
bridge.901@bridge UP 44:38:39:00:77:88 <UP,BROADCAST,MULTICAST,UP>
bridge-901-v0@bridge.901 UP 00:00:5e:00:01:81 <UP,BROADCAST,MULTICAST,UP>
$ifdown myvrf
$ip -br link show
bridge.901@bridge DOWN 44:38:39:00:77:88 <BROADCAST,MULTICAST>
bridge-901-v0@bridge.901 DOWN 00:00:5e:00:01:81 <BROADCAST,MULTICAST,M-DOWN>
before patch (macvlan device bridge-901-v0 did not come up:
----------------------------------------
$ifup myvrf
$ip -br link show
bridge.901@bridge UP 44:38:39:00:77:88 <UP,BROADCAST,MULTICAST,UP>
bridge-901-v0@bridge.901 DOWN 00:00:5e:00:01:81 <BROADCAST,MULTICAST>
myvrf UP ce:a6:e1:85:75:73 <NOARP,MASTER,UP,LOWER_UP>
after patch:
------------
$ifup myvrf
$ip -br link show
bridge.901@bridge UP 44:38:39:00:77:88 <UP,BROADCAST,MULTICAST,UP>
bridge-901-v0@bridge.901 UP 00:00:5e:00:01:81 <UP,BROADCAST,MULTICAST,UP>
myvrf UP ce:a6:e1:85:75:73 <NOARP,MASTER,UP,LOWER_UP>
Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
2016-10-19 10:43:45 -07:00
|
|
|
def get_dependent_ifacenames(self, ifaceobj, ifacenames_all=None):
|
2019-01-25 09:58:25 +08:00
|
|
|
if ifaceobj.get_attr_value('address-virtual') or ifaceobj.get_attr_value("vrrp"):
|
[PATCH ifupdown2] addons: addressvirtual: fixup macvlan device enslavements for vrfs
Ticket: CM-12988
Reviewed By: julien, nikhil, dsa
Testing Done: tested ifup and ifdown of vrf devices with address virtual
slaves
This patch fixes up macvlan device enslavements when vrf device
or vrf slave is brought down and up. address virtual macvlan
devices on vrf slaves need to enslaved to the vrf. This
patch checks and fixes up those vrf enslavements for the following
cases:
ifdown <vrf_device> && ifup <vrf_device>
ifdown <vrf_slave> && ifup <vrf_slave>
starting state:
------------
$ip -br link show
myvrf UP 46:c6:44:db:37:60 <NOARP,MASTER,UP,LOWER_UP>
bridge.901@bridge UP 44:38:39:00:77:88 <UP,BROADCAST,MULTICAST,UP>
bridge-901-v0@bridge.901 UP 00:00:5e:00:01:81 <UP,BROADCAST,MULTICAST,UP>
$ifdown myvrf
$ip -br link show
bridge.901@bridge DOWN 44:38:39:00:77:88 <BROADCAST,MULTICAST>
bridge-901-v0@bridge.901 DOWN 00:00:5e:00:01:81 <BROADCAST,MULTICAST,M-DOWN>
before patch (macvlan device bridge-901-v0 did not come up:
----------------------------------------
$ifup myvrf
$ip -br link show
bridge.901@bridge UP 44:38:39:00:77:88 <UP,BROADCAST,MULTICAST,UP>
bridge-901-v0@bridge.901 DOWN 00:00:5e:00:01:81 <BROADCAST,MULTICAST>
myvrf UP ce:a6:e1:85:75:73 <NOARP,MASTER,UP,LOWER_UP>
after patch:
------------
$ifup myvrf
$ip -br link show
bridge.901@bridge UP 44:38:39:00:77:88 <UP,BROADCAST,MULTICAST,UP>
bridge-901-v0@bridge.901 UP 00:00:5e:00:01:81 <UP,BROADCAST,MULTICAST,UP>
myvrf UP ce:a6:e1:85:75:73 <NOARP,MASTER,UP,LOWER_UP>
Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
2016-10-19 10:43:45 -07:00
|
|
|
ifaceobj.link_privflags |= ifaceLinkPrivFlags.ADDRESS_VIRTUAL_SLAVE
|
2014-10-09 16:02:46 -07:00
|
|
|
|
2014-11-08 06:29:26 -08:00
|
|
|
def _get_macvlan_prefix(self, ifaceobj):
|
|
|
|
return '%s-v' %ifaceobj.name[0:13].replace('.', '-')
|
|
|
|
|
2019-02-19 23:14:03 +01:00
|
|
|
@staticmethod
|
|
|
|
def get_vrr_prefix(ifname, family):
|
|
|
|
return "%s-%sv" % (ifname[0:10].replace(".", "-"), family)
|
|
|
|
|
2014-10-28 16:10:00 -07:00
|
|
|
def _add_addresses_to_bridge(self, ifaceobj, hwaddress):
|
2014-11-03 17:55:51 -08:00
|
|
|
# XXX: batch the addresses
|
2018-12-13 11:43:32 -08:00
|
|
|
if ifaceobj.link_kind & ifaceLinkKind.VLAN:
|
|
|
|
bridgename = ifaceobj.lowerifaces[0]
|
|
|
|
vlan = self._get_vlan_id(ifaceobj)
|
2014-10-28 16:10:00 -07:00
|
|
|
if self.ipcmd.bridge_is_vlan_aware(bridgename):
|
|
|
|
[self.ipcmd.bridge_fdb_add(bridgename, addr,
|
|
|
|
vlan) for addr in hwaddress]
|
2014-11-03 17:55:51 -08:00
|
|
|
elif self.ipcmd.is_bridge(ifaceobj.name):
|
|
|
|
[self.ipcmd.bridge_fdb_add(ifaceobj.name, addr)
|
|
|
|
for addr in hwaddress]
|
2014-10-28 16:10:00 -07:00
|
|
|
|
|
|
|
def _remove_addresses_from_bridge(self, ifaceobj, hwaddress):
|
2014-11-03 17:55:51 -08:00
|
|
|
# XXX: batch the addresses
|
2018-12-13 11:43:32 -08:00
|
|
|
if ifaceobj.link_kind & ifaceLinkKind.VLAN:
|
|
|
|
bridgename = ifaceobj.lowerifaces[0]
|
|
|
|
vlan = self._get_vlan_id(ifaceobj)
|
2014-10-28 16:10:00 -07:00
|
|
|
if self.ipcmd.bridge_is_vlan_aware(bridgename):
|
2015-07-23 15:43:45 -04:00
|
|
|
for addr in hwaddress:
|
|
|
|
try:
|
|
|
|
self.ipcmd.bridge_fdb_del(bridgename, addr, vlan)
|
|
|
|
except Exception, e:
|
|
|
|
self.logger.debug("%s: %s" %(ifaceobj.name, str(e)))
|
|
|
|
pass
|
2014-11-03 17:55:51 -08:00
|
|
|
elif self.ipcmd.is_bridge(ifaceobj.name):
|
2015-07-23 15:43:45 -04:00
|
|
|
for addr in hwaddress:
|
|
|
|
try:
|
|
|
|
self.ipcmd.bridge_fdb_del(ifaceobj.name, addr)
|
|
|
|
except Exception, e:
|
|
|
|
self.logger.debug("%s: %s" %(ifaceobj.name, str(e)))
|
|
|
|
pass
|
2014-11-03 17:55:51 -08:00
|
|
|
|
|
|
|
def _get_bridge_fdbs(self, bridgename, vlan):
|
|
|
|
fdbs = self._bridge_fdb_query_cache.get(bridgename)
|
|
|
|
if not fdbs:
|
|
|
|
fdbs = self.ipcmd.bridge_fdb_show_dev(bridgename)
|
|
|
|
if not fdbs:
|
|
|
|
return
|
|
|
|
self._bridge_fdb_query_cache[bridgename] = fdbs
|
|
|
|
return fdbs.get(vlan)
|
|
|
|
|
|
|
|
def _check_addresses_in_bridge(self, ifaceobj, hwaddress):
|
|
|
|
""" If the device is a bridge, make sure the addresses
|
|
|
|
are in the bridge """
|
2018-12-13 11:43:32 -08:00
|
|
|
if ifaceobj.link_kind & ifaceLinkKind.VLAN:
|
|
|
|
bridgename = ifaceobj.lowerifaces[0]
|
|
|
|
vlan = self._get_vlan_id(ifaceobj)
|
2014-11-03 17:55:51 -08:00
|
|
|
if self.ipcmd.bridge_is_vlan_aware(bridgename):
|
2018-12-13 11:43:32 -08:00
|
|
|
fdb_addrs = self._get_bridge_fdbs(bridgename, str(vlan))
|
2019-01-25 09:58:25 +08:00
|
|
|
if not fdb_addrs:
|
2014-11-03 17:55:51 -08:00
|
|
|
return False
|
2019-01-25 09:58:25 +08:00
|
|
|
hwaddress_int = self.mac_str_to_int(hwaddress)
|
|
|
|
for mac in fdb_addrs:
|
|
|
|
if self.mac_str_to_int(mac) == hwaddress_int:
|
|
|
|
return True
|
|
|
|
return False
|
2014-11-03 17:55:51 -08:00
|
|
|
return True
|
2014-10-28 16:10:00 -07:00
|
|
|
|
2014-12-31 23:43:27 -08:00
|
|
|
def _fix_connected_route(self, ifaceobj, vifacename, addr):
|
|
|
|
#
|
2018-12-13 11:43:32 -08:00
|
|
|
# XXX: Hack to make sure the primary address
|
2014-12-31 23:43:27 -08:00
|
|
|
# is the first in the routing table.
|
|
|
|
#
|
|
|
|
# We use `ip route get` on the vrr network to see which
|
|
|
|
# device the kernel returns. if it is the mac vlan device,
|
|
|
|
# flap the macvlan device to adjust the routing table entry.
|
2018-12-13 11:43:32 -08:00
|
|
|
#
|
2014-12-31 23:43:27 -08:00
|
|
|
# flapping the macvlan device makes sure the macvlan
|
|
|
|
# connected route goes through delete + add, hence adjusting
|
|
|
|
# the order in the routing table.
|
|
|
|
#
|
|
|
|
try:
|
|
|
|
self.logger.info('%s: checking route entry ...' %ifaceobj.name)
|
|
|
|
ip = IPNetwork(addr)
|
2018-12-13 11:43:32 -08:00
|
|
|
|
|
|
|
# we don't support ip6 route fix yet
|
|
|
|
if type(ip) == IPv6Network:
|
|
|
|
return
|
|
|
|
|
2014-12-31 23:43:27 -08:00
|
|
|
route_prefix = '%s/%d' %(ip.network, ip.prefixlen)
|
|
|
|
|
2018-06-15 17:59:19 +02:00
|
|
|
if ifaceobj.link_privflags & ifaceLinkPrivFlags.VRF_SLAVE:
|
|
|
|
vrf_master = self.ipcmd.link_get_master(ifaceobj.name)
|
|
|
|
else:
|
|
|
|
vrf_master = None
|
|
|
|
|
|
|
|
dev = self.ipcmd.ip_route_get_dev(route_prefix, vrf_master=vrf_master)
|
|
|
|
|
2018-12-13 11:43:32 -08:00
|
|
|
if dev and dev != ifaceobj.name:
|
2014-12-31 23:43:27 -08:00
|
|
|
self.logger.info('%s: preferred routing entry ' %ifaceobj.name +
|
|
|
|
'seems to be of the macvlan dev %s'
|
|
|
|
%vifacename +
|
|
|
|
' .. flapping macvlan dev to fix entry.')
|
|
|
|
self.ipcmd.link_down(vifacename)
|
|
|
|
self.ipcmd.link_up(vifacename)
|
|
|
|
except Exception, e:
|
|
|
|
self.logger.debug('%s: fixing route entry failed (%s)'
|
2018-12-13 11:43:32 -08:00
|
|
|
% (ifaceobj.name, str(e)))
|
2014-12-31 23:43:27 -08:00
|
|
|
pass
|
|
|
|
|
2016-07-17 22:50:26 -07:00
|
|
|
def _handle_vrf_slaves(self, macvlan_ifacename, ifaceobj):
|
|
|
|
vrfname = self.ipcmd.link_get_master(ifaceobj.name)
|
|
|
|
if vrfname:
|
2018-12-13 11:43:32 -08:00
|
|
|
self.ipcmd.link_set(macvlan_ifacename, 'master', vrfname)
|
2016-07-17 22:50:26 -07:00
|
|
|
|
2015-07-23 15:43:45 -04:00
|
|
|
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. """
|
|
|
|
maclist = []
|
|
|
|
saved_ifaceobjs = statemanager.statemanager_api.get_ifaceobjs(ifaceobj.name)
|
|
|
|
if not saved_ifaceobjs:
|
|
|
|
return maclist
|
|
|
|
# we need the old saved configs from the statemanager
|
|
|
|
for oldifaceobj in saved_ifaceobjs:
|
|
|
|
if not oldifaceobj.get_attr_value('address-virtual'):
|
|
|
|
continue
|
|
|
|
for av in oldifaceobj.get_attr_value('address-virtual'):
|
|
|
|
macip = av.split()
|
|
|
|
if len(macip) < 2:
|
|
|
|
self.logger.debug("%s: incorrect old address-virtual attrs '%s'"
|
|
|
|
%(oldifaceobj.name, av))
|
|
|
|
continue
|
|
|
|
maclist.append(macip[0])
|
|
|
|
return maclist
|
|
|
|
|
2018-06-18 16:51:51 +02:00
|
|
|
def get_addressvirtual_ipv6_addrgen_user_conf(self, ifaceobj):
|
|
|
|
ipv6_addrgen = ifaceobj.get_attr_value_first('address-virtual-ipv6-addrgen')
|
|
|
|
|
|
|
|
if ipv6_addrgen:
|
2018-07-10 00:18:39 +02:00
|
|
|
# IFLA_INET6_ADDR_GEN_MODE values:
|
|
|
|
# 0 = eui64
|
|
|
|
# 1 = none
|
2018-07-23 10:38:29 +02:00
|
|
|
ipv6_addrgen_nl = self.address_virtual_ipv6_addrgen_value_dict.get(ipv6_addrgen.lower(), None)
|
2018-07-10 00:18:39 +02:00
|
|
|
|
|
|
|
if ipv6_addrgen_nl is None:
|
|
|
|
self.logger.warning('%s: invalid value "%s" for attribute address-virtual-ipv6-addrgen' % (ifaceobj.name, ipv6_addrgen))
|
|
|
|
else:
|
|
|
|
return True, ipv6_addrgen_nl
|
2018-06-18 16:51:51 +02:00
|
|
|
|
2018-07-23 10:38:29 +02:00
|
|
|
else:
|
|
|
|
# if user didn't configure ipv6-addrgen, should we reset to default?
|
|
|
|
ipv6_addrgen_nl = self.address_virtual_ipv6_addrgen_value_dict.get(
|
|
|
|
self.get_attr_default_value('address-virtual-ipv6-addrgen'),
|
|
|
|
None
|
|
|
|
)
|
|
|
|
if ipv6_addrgen_nl is not None:
|
|
|
|
return True, ipv6_addrgen_nl
|
|
|
|
|
2018-06-18 16:51:51 +02:00
|
|
|
return False, None
|
|
|
|
|
2014-10-28 16:10:00 -07:00
|
|
|
def _remove_running_address_config(self, ifaceobj):
|
|
|
|
if not self.ipcmd.link_exists(ifaceobj.name):
|
2014-10-09 16:02:46 -07:00
|
|
|
return
|
2014-10-28 16:10:00 -07:00
|
|
|
hwaddress = []
|
2014-10-09 16:02:46 -07:00
|
|
|
self.ipcmd.batch_start()
|
2019-02-15 11:29:43 +01:00
|
|
|
for macvlan_prefix in [
|
|
|
|
self._get_macvlan_prefix(ifaceobj),
|
|
|
|
self.get_vrr_prefix(ifaceobj.name, "4"),
|
|
|
|
self.get_vrr_prefix(ifaceobj.name, "6")
|
|
|
|
]:
|
|
|
|
for macvlan_ifacename in glob.glob("/sys/class/net/%s*" % macvlan_prefix):
|
|
|
|
macvlan_ifacename = os.path.basename(macvlan_ifacename)
|
|
|
|
if not self.ipcmd.link_exists(macvlan_ifacename):
|
|
|
|
continue
|
|
|
|
hwaddress.append(self.ipcmd.link_get_hwaddress(macvlan_ifacename))
|
|
|
|
self.ipcmd.link_delete(os.path.basename(macvlan_ifacename))
|
|
|
|
# XXX: Also delete any fdb addresses. This requires, checking mac address
|
|
|
|
# on individual macvlan interfaces and deleting the vlan from that.
|
2014-10-09 16:02:46 -07:00
|
|
|
self.ipcmd.batch_commit()
|
2014-10-28 16:10:00 -07:00
|
|
|
if any(hwaddress):
|
|
|
|
self._remove_addresses_from_bridge(ifaceobj, hwaddress)
|
2014-10-09 16:02:46 -07:00
|
|
|
|
2014-10-28 16:10:00 -07:00
|
|
|
def _remove_address_config(self, ifaceobj, address_virtual_list=None):
|
|
|
|
if not address_virtual_list:
|
|
|
|
self._remove_running_address_config(ifaceobj)
|
|
|
|
return
|
|
|
|
|
|
|
|
if not self.ipcmd.link_exists(ifaceobj.name):
|
|
|
|
return
|
|
|
|
hwaddress = []
|
|
|
|
self.ipcmd.batch_start()
|
|
|
|
av_idx = 0
|
2014-11-08 06:29:26 -08:00
|
|
|
macvlan_prefix = self._get_macvlan_prefix(ifaceobj)
|
2014-10-28 16:10:00 -07:00
|
|
|
for av in address_virtual_list:
|
|
|
|
av_attrs = av.split()
|
|
|
|
if len(av_attrs) < 2:
|
2016-05-15 13:28:10 -07:00
|
|
|
self.log_error("%s: incorrect address-virtual attrs '%s'"
|
|
|
|
%(ifaceobj.name, av), ifaceobj,
|
|
|
|
raise_error=False)
|
2014-10-28 16:10:00 -07:00
|
|
|
av_idx += 1
|
|
|
|
continue
|
|
|
|
|
|
|
|
# Delete the macvlan device on this device
|
2014-10-28 23:04:40 -07:00
|
|
|
macvlan_ifacename = '%s%d' %(macvlan_prefix, av_idx)
|
2014-10-28 16:10:00 -07:00
|
|
|
self.ipcmd.link_delete(os.path.basename(macvlan_ifacename))
|
|
|
|
if av_attrs[0] != 'None':
|
|
|
|
hwaddress.append(av_attrs[0])
|
|
|
|
av_idx += 1
|
|
|
|
self.ipcmd.batch_commit()
|
|
|
|
self._remove_addresses_from_bridge(ifaceobj, hwaddress)
|
2014-10-09 16:02:46 -07:00
|
|
|
|
2016-03-17 13:01:26 -07:00
|
|
|
def check_mac_address(self, ifaceobj, mac):
|
2019-01-25 09:58:25 +08:00
|
|
|
if mac == 'none':
|
2018-12-13 11:43:32 -08:00
|
|
|
return True
|
2016-03-17 13:01:26 -07:00
|
|
|
try:
|
2016-03-30 16:56:37 -07:00
|
|
|
if int(mac.split(":")[0], 16) & 1 :
|
2018-07-02 12:20:07 +02:00
|
|
|
self.log_error("%s: Multicast bit is set in the virtual mac address '%s'"
|
|
|
|
% (ifaceobj.name, mac), ifaceobj=ifaceobj)
|
2016-03-17 13:01:26 -07:00
|
|
|
return False
|
|
|
|
return True
|
2018-07-02 12:20:07 +02:00
|
|
|
except ValueError:
|
2016-03-17 13:01:26 -07:00
|
|
|
return False
|
|
|
|
|
[PATCH ifupdown2] addons: addressvirtual: fixup macvlan device enslavements for vrfs
Ticket: CM-12988
Reviewed By: julien, nikhil, dsa
Testing Done: tested ifup and ifdown of vrf devices with address virtual
slaves
This patch fixes up macvlan device enslavements when vrf device
or vrf slave is brought down and up. address virtual macvlan
devices on vrf slaves need to enslaved to the vrf. This
patch checks and fixes up those vrf enslavements for the following
cases:
ifdown <vrf_device> && ifup <vrf_device>
ifdown <vrf_slave> && ifup <vrf_slave>
starting state:
------------
$ip -br link show
myvrf UP 46:c6:44:db:37:60 <NOARP,MASTER,UP,LOWER_UP>
bridge.901@bridge UP 44:38:39:00:77:88 <UP,BROADCAST,MULTICAST,UP>
bridge-901-v0@bridge.901 UP 00:00:5e:00:01:81 <UP,BROADCAST,MULTICAST,UP>
$ifdown myvrf
$ip -br link show
bridge.901@bridge DOWN 44:38:39:00:77:88 <BROADCAST,MULTICAST>
bridge-901-v0@bridge.901 DOWN 00:00:5e:00:01:81 <BROADCAST,MULTICAST,M-DOWN>
before patch (macvlan device bridge-901-v0 did not come up:
----------------------------------------
$ifup myvrf
$ip -br link show
bridge.901@bridge UP 44:38:39:00:77:88 <UP,BROADCAST,MULTICAST,UP>
bridge-901-v0@bridge.901 DOWN 00:00:5e:00:01:81 <BROADCAST,MULTICAST>
myvrf UP ce:a6:e1:85:75:73 <NOARP,MASTER,UP,LOWER_UP>
after patch:
------------
$ifup myvrf
$ip -br link show
bridge.901@bridge UP 44:38:39:00:77:88 <UP,BROADCAST,MULTICAST,UP>
bridge-901-v0@bridge.901 UP 00:00:5e:00:01:81 <UP,BROADCAST,MULTICAST,UP>
myvrf UP ce:a6:e1:85:75:73 <NOARP,MASTER,UP,LOWER_UP>
Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
2016-10-19 10:43:45 -07:00
|
|
|
def _fixup_vrf_enslavements(self, ifaceobj, ifaceobj_getfunc=None):
|
|
|
|
""" This function fixes up address virtual interfaces
|
|
|
|
(macvlans) on vrf slaves. Since this fixup is an overhead,
|
|
|
|
this must be called only in cases when ifupdown2 is
|
|
|
|
called on the vrf device or its slave and not when
|
|
|
|
ifupdown2 is called for all devices. When all
|
|
|
|
interfaces are brought up, the expectation is that
|
|
|
|
the normal path will fix up a vrf device or its slaves"""
|
|
|
|
|
|
|
|
if not ifaceobj_getfunc:
|
|
|
|
return
|
|
|
|
if ((ifaceobj.link_kind & ifaceLinkKind.VRF) and
|
|
|
|
self.ipcmd.link_exists(ifaceobj.name)):
|
|
|
|
# if I am a vrf device and I have slaves
|
|
|
|
# that have address virtual config,
|
|
|
|
# enslave the slaves 'address virtual
|
|
|
|
# interfaces (macvlans)' to myself:
|
|
|
|
running_slaves = self.ipcmd.link_get_lowers(ifaceobj.name)
|
|
|
|
if running_slaves:
|
|
|
|
# pick up any existing slaves of a vrf device and
|
|
|
|
# look for their upperdevices and enslave them to the
|
|
|
|
# vrf device:
|
|
|
|
for s in running_slaves:
|
|
|
|
sobjs = ifaceobj_getfunc(s)
|
|
|
|
if (sobjs and
|
|
|
|
(sobjs[0].link_privflags & ifaceLinkPrivFlags.ADDRESS_VIRTUAL_SLAVE)):
|
|
|
|
# enslave all its upper devices to
|
|
|
|
# the vrf device
|
|
|
|
upperdevs = self.ipcmd.link_get_uppers(sobjs[0].name)
|
|
|
|
if not upperdevs:
|
|
|
|
continue
|
|
|
|
for u in upperdevs:
|
|
|
|
# skip vrf device which
|
|
|
|
# will also show up in the
|
|
|
|
# upper device list
|
|
|
|
if u == ifaceobj.name:
|
|
|
|
continue
|
2018-12-13 11:43:32 -08:00
|
|
|
self.ipcmd.link_set(u, 'master', ifaceobj.name,
|
|
|
|
state='up')
|
[PATCH ifupdown2] addons: addressvirtual: fixup macvlan device enslavements for vrfs
Ticket: CM-12988
Reviewed By: julien, nikhil, dsa
Testing Done: tested ifup and ifdown of vrf devices with address virtual
slaves
This patch fixes up macvlan device enslavements when vrf device
or vrf slave is brought down and up. address virtual macvlan
devices on vrf slaves need to enslaved to the vrf. This
patch checks and fixes up those vrf enslavements for the following
cases:
ifdown <vrf_device> && ifup <vrf_device>
ifdown <vrf_slave> && ifup <vrf_slave>
starting state:
------------
$ip -br link show
myvrf UP 46:c6:44:db:37:60 <NOARP,MASTER,UP,LOWER_UP>
bridge.901@bridge UP 44:38:39:00:77:88 <UP,BROADCAST,MULTICAST,UP>
bridge-901-v0@bridge.901 UP 00:00:5e:00:01:81 <UP,BROADCAST,MULTICAST,UP>
$ifdown myvrf
$ip -br link show
bridge.901@bridge DOWN 44:38:39:00:77:88 <BROADCAST,MULTICAST>
bridge-901-v0@bridge.901 DOWN 00:00:5e:00:01:81 <BROADCAST,MULTICAST,M-DOWN>
before patch (macvlan device bridge-901-v0 did not come up:
----------------------------------------
$ifup myvrf
$ip -br link show
bridge.901@bridge UP 44:38:39:00:77:88 <UP,BROADCAST,MULTICAST,UP>
bridge-901-v0@bridge.901 DOWN 00:00:5e:00:01:81 <BROADCAST,MULTICAST>
myvrf UP ce:a6:e1:85:75:73 <NOARP,MASTER,UP,LOWER_UP>
after patch:
------------
$ifup myvrf
$ip -br link show
bridge.901@bridge UP 44:38:39:00:77:88 <UP,BROADCAST,MULTICAST,UP>
bridge-901-v0@bridge.901 UP 00:00:5e:00:01:81 <UP,BROADCAST,MULTICAST,UP>
myvrf UP ce:a6:e1:85:75:73 <NOARP,MASTER,UP,LOWER_UP>
Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
2016-10-19 10:43:45 -07:00
|
|
|
elif ((ifaceobj.link_privflags & ifaceLinkPrivFlags.ADDRESS_VIRTUAL_SLAVE) and
|
|
|
|
(ifaceobj.link_privflags & ifaceLinkPrivFlags.VRF_SLAVE) and
|
|
|
|
self.ipcmd.link_exists(ifaceobj.name)):
|
|
|
|
# If I am a vrf slave and I have 'address virtual'
|
|
|
|
# config, make sure my addrress virtual interfaces
|
|
|
|
# (macvlans) are also enslaved to the vrf device
|
|
|
|
vrfname = ifaceobj.get_attr_value_first('vrf')
|
|
|
|
if not vrfname or not self.ipcmd.link_exists(vrfname):
|
|
|
|
return
|
|
|
|
running_uppers = self.ipcmd.link_get_uppers(ifaceobj.name)
|
|
|
|
if not running_uppers:
|
|
|
|
return
|
|
|
|
macvlan_prefix = self._get_macvlan_prefix(ifaceobj)
|
|
|
|
if not macvlan_prefix:
|
|
|
|
return
|
|
|
|
for u in running_uppers:
|
|
|
|
if u == vrfname:
|
|
|
|
continue
|
|
|
|
if u.startswith(macvlan_prefix):
|
2018-12-13 11:43:32 -08:00
|
|
|
self.ipcmd.link_set(u, 'master', vrfname,
|
|
|
|
state='up')
|
[PATCH ifupdown2] addons: addressvirtual: fixup macvlan device enslavements for vrfs
Ticket: CM-12988
Reviewed By: julien, nikhil, dsa
Testing Done: tested ifup and ifdown of vrf devices with address virtual
slaves
This patch fixes up macvlan device enslavements when vrf device
or vrf slave is brought down and up. address virtual macvlan
devices on vrf slaves need to enslaved to the vrf. This
patch checks and fixes up those vrf enslavements for the following
cases:
ifdown <vrf_device> && ifup <vrf_device>
ifdown <vrf_slave> && ifup <vrf_slave>
starting state:
------------
$ip -br link show
myvrf UP 46:c6:44:db:37:60 <NOARP,MASTER,UP,LOWER_UP>
bridge.901@bridge UP 44:38:39:00:77:88 <UP,BROADCAST,MULTICAST,UP>
bridge-901-v0@bridge.901 UP 00:00:5e:00:01:81 <UP,BROADCAST,MULTICAST,UP>
$ifdown myvrf
$ip -br link show
bridge.901@bridge DOWN 44:38:39:00:77:88 <BROADCAST,MULTICAST>
bridge-901-v0@bridge.901 DOWN 00:00:5e:00:01:81 <BROADCAST,MULTICAST,M-DOWN>
before patch (macvlan device bridge-901-v0 did not come up:
----------------------------------------
$ifup myvrf
$ip -br link show
bridge.901@bridge UP 44:38:39:00:77:88 <UP,BROADCAST,MULTICAST,UP>
bridge-901-v0@bridge.901 DOWN 00:00:5e:00:01:81 <BROADCAST,MULTICAST>
myvrf UP ce:a6:e1:85:75:73 <NOARP,MASTER,UP,LOWER_UP>
after patch:
------------
$ifup myvrf
$ip -br link show
bridge.901@bridge UP 44:38:39:00:77:88 <UP,BROADCAST,MULTICAST,UP>
bridge-901-v0@bridge.901 UP 00:00:5e:00:01:81 <UP,BROADCAST,MULTICAST,UP>
myvrf UP ce:a6:e1:85:75:73 <NOARP,MASTER,UP,LOWER_UP>
Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
2016-10-19 10:43:45 -07:00
|
|
|
|
2019-01-25 09:58:25 +08:00
|
|
|
def mac_str_to_int(self, mac):
|
|
|
|
mac_int = 0
|
|
|
|
for n in mac.translate(self.mac_translate_tab).split():
|
|
|
|
mac_int += int(n, 16)
|
|
|
|
return mac_int
|
|
|
|
|
|
|
|
def create_macvlan_and_apply_config(self, ifaceobj, intf_config_list):
|
|
|
|
"""
|
|
|
|
intf_config_list = [
|
|
|
|
{
|
|
|
|
"ifname": "macvlan_ifname",
|
|
|
|
"hwaddress": "macvlan_hwaddress",
|
|
|
|
"ips": [str(IPNetwork), ]
|
|
|
|
},
|
|
|
|
]
|
|
|
|
"""
|
|
|
|
user_configured_ipv6_addrgenmode, ipv6_addrgen_user_value = self.get_addressvirtual_ipv6_addrgen_user_conf(ifaceobj)
|
|
|
|
purge_existing = False if ifupdownflags.flags.PERFMODE else True
|
|
|
|
hw_address_list = []
|
|
|
|
ifname = ifaceobj.name
|
|
|
|
|
|
|
|
lower_iface_mtu = update_mtu = None
|
|
|
|
if ifupdownconfig.config.get("adjust_logical_dev_mtu", "1") != "0":
|
|
|
|
if ifaceobj.lowerifaces and intf_config_list:
|
|
|
|
update_mtu = True
|
|
|
|
|
|
|
|
self.ipcmd.batch_start()
|
|
|
|
|
|
|
|
for intf_config_dict in intf_config_list:
|
|
|
|
link_created = False
|
|
|
|
macvlan_ifname = intf_config_dict.get("ifname")
|
|
|
|
macvlan_hwaddr = intf_config_dict.get("hwaddress")
|
|
|
|
ips = intf_config_dict.get("ips")
|
|
|
|
|
|
|
|
if not self.ipcmd.link_exists(macvlan_ifname):
|
|
|
|
self.ipcmd.link_add_macvlan(ifname, macvlan_ifname)
|
|
|
|
link_created = True
|
|
|
|
|
|
|
|
# first thing we need to handle vrf enslavement
|
|
|
|
if ifaceobj.link_privflags & ifaceLinkPrivFlags.VRF_SLAVE:
|
|
|
|
self._handle_vrf_slaves(macvlan_ifname, ifaceobj)
|
|
|
|
|
|
|
|
if user_configured_ipv6_addrgenmode:
|
|
|
|
self.ipcmd.ipv6_addrgen(macvlan_ifname, ipv6_addrgen_user_value, link_created)
|
|
|
|
|
|
|
|
if macvlan_hwaddr:
|
|
|
|
self.ipcmd.link_set_hwaddress(macvlan_ifname, macvlan_hwaddr)
|
|
|
|
hw_address_list.append(macvlan_hwaddr)
|
|
|
|
|
|
|
|
if self.addressvirtual_with_route_metric and self.ipcmd.addr_metric_support():
|
|
|
|
metric = self.ipcmd.get_default_ip_metric()
|
|
|
|
else:
|
|
|
|
metric = None
|
|
|
|
|
|
|
|
self.ipcmd.addr_add_multiple(
|
|
|
|
ifaceobj,
|
|
|
|
macvlan_ifname,
|
|
|
|
ips,
|
|
|
|
purge_existing,
|
|
|
|
metric=metric
|
|
|
|
)
|
|
|
|
|
|
|
|
# If link existed before, flap the link
|
|
|
|
if not link_created:
|
|
|
|
|
|
|
|
if not self.addressvirtual_with_route_metric or not self.ipcmd.addr_metric_support():
|
|
|
|
# if the system doesn't support ip addr set METRIC
|
|
|
|
# we need to do manually check the ordering of the ip4 routes
|
|
|
|
self._fix_connected_route(ifaceobj, macvlan_ifname, ips[0])
|
|
|
|
|
|
|
|
if update_mtu:
|
|
|
|
lower_iface_mtu = self.ipcmd.link_get_mtu(ifname, refresh=True)
|
|
|
|
update_mtu = False
|
|
|
|
|
|
|
|
if lower_iface_mtu and lower_iface_mtu != self.ipcmd.link_get_mtu(macvlan_ifname, refresh=True):
|
|
|
|
try:
|
|
|
|
self.ipcmd.link_set_mtu(macvlan_ifname,
|
|
|
|
lower_iface_mtu)
|
|
|
|
except Exception as e:
|
|
|
|
self.logger.info('%s: failed to set mtu %s: %s' %
|
|
|
|
(macvlan_ifname, lower_iface_mtu, e))
|
|
|
|
|
|
|
|
# set macvlan device to up in anycase.
|
|
|
|
# since we auto create them here..we are responsible
|
|
|
|
# to bring them up here in the case they were brought down
|
|
|
|
# by some other entity in the system.
|
|
|
|
netlink.link_set_updown(macvlan_ifname, "up")
|
|
|
|
else:
|
|
|
|
try:
|
|
|
|
if not self.addressvirtual_with_route_metric or not self.ipcmd.addr_metric_support():
|
|
|
|
# if the system doesn't support ip addr set METRIC
|
|
|
|
# we need to do manually check the ordering of the ip6 routes
|
|
|
|
self.ipcmd.fix_ipv6_route_metric(ifaceobj, macvlan_ifname, ips)
|
|
|
|
except Exception as e:
|
|
|
|
self.logger.debug('fix_vrf_slave_ipv6_route_metric: failed: %s' % e)
|
|
|
|
|
|
|
|
# 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_ifname, key)
|
|
|
|
if self.sysctl_get(syskey) != sysval:
|
|
|
|
self.sysctl_set(syskey, sysval)
|
|
|
|
|
|
|
|
self.ipcmd.batch_commit()
|
|
|
|
return hw_address_list
|
|
|
|
|
[PATCH ifupdown2] addons: addressvirtual: fixup macvlan device enslavements for vrfs
Ticket: CM-12988
Reviewed By: julien, nikhil, dsa
Testing Done: tested ifup and ifdown of vrf devices with address virtual
slaves
This patch fixes up macvlan device enslavements when vrf device
or vrf slave is brought down and up. address virtual macvlan
devices on vrf slaves need to enslaved to the vrf. This
patch checks and fixes up those vrf enslavements for the following
cases:
ifdown <vrf_device> && ifup <vrf_device>
ifdown <vrf_slave> && ifup <vrf_slave>
starting state:
------------
$ip -br link show
myvrf UP 46:c6:44:db:37:60 <NOARP,MASTER,UP,LOWER_UP>
bridge.901@bridge UP 44:38:39:00:77:88 <UP,BROADCAST,MULTICAST,UP>
bridge-901-v0@bridge.901 UP 00:00:5e:00:01:81 <UP,BROADCAST,MULTICAST,UP>
$ifdown myvrf
$ip -br link show
bridge.901@bridge DOWN 44:38:39:00:77:88 <BROADCAST,MULTICAST>
bridge-901-v0@bridge.901 DOWN 00:00:5e:00:01:81 <BROADCAST,MULTICAST,M-DOWN>
before patch (macvlan device bridge-901-v0 did not come up:
----------------------------------------
$ifup myvrf
$ip -br link show
bridge.901@bridge UP 44:38:39:00:77:88 <UP,BROADCAST,MULTICAST,UP>
bridge-901-v0@bridge.901 DOWN 00:00:5e:00:01:81 <BROADCAST,MULTICAST>
myvrf UP ce:a6:e1:85:75:73 <NOARP,MASTER,UP,LOWER_UP>
after patch:
------------
$ifup myvrf
$ip -br link show
bridge.901@bridge UP 44:38:39:00:77:88 <UP,BROADCAST,MULTICAST,UP>
bridge-901-v0@bridge.901 UP 00:00:5e:00:01:81 <UP,BROADCAST,MULTICAST,UP>
myvrf UP ce:a6:e1:85:75:73 <NOARP,MASTER,UP,LOWER_UP>
Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
2016-10-19 10:43:45 -07:00
|
|
|
def _up(self, ifaceobj, ifaceobj_getfunc=None):
|
|
|
|
if not ifupdownflags.flags.ALL:
|
|
|
|
self._fixup_vrf_enslavements(ifaceobj, ifaceobj_getfunc)
|
2019-01-25 09:58:25 +08:00
|
|
|
|
2014-10-09 16:02:46 -07:00
|
|
|
address_virtual_list = ifaceobj.get_attr_value('address-virtual')
|
2019-01-25 09:58:25 +08:00
|
|
|
vrr_config_list = ifaceobj.get_attr_value("vrrp")
|
|
|
|
|
|
|
|
if not address_virtual_list and not vrr_config_list:
|
2014-10-09 16:02:46 -07:00
|
|
|
# XXX: address virtual is not present. In which case,
|
2014-12-31 23:43:27 -08:00
|
|
|
# delete stale macvlan devices.
|
2019-01-25 09:58:25 +08:00
|
|
|
self._remove_running_address_config(ifaceobj)
|
2014-10-09 16:02:46 -07:00
|
|
|
return
|
|
|
|
|
2019-01-25 09:58:25 +08:00
|
|
|
if ifaceobj.upperifaces and not ifaceobj.link_privflags & ifaceLinkPrivFlags.VRF_SLAVE:
|
|
|
|
self.log_error("%s: invalid placement of address-virtual/vrrp lines "
|
|
|
|
"(must be configured under an interface "
|
|
|
|
"with no upper interfaces or parent interfaces)"
|
|
|
|
% ifaceobj.name, ifaceobj)
|
2016-04-25 17:39:57 +02:00
|
|
|
|
2014-10-28 16:10:00 -07:00
|
|
|
if not self.ipcmd.link_exists(ifaceobj.name):
|
2014-10-09 16:02:46 -07:00
|
|
|
return
|
2019-01-25 09:58:25 +08:00
|
|
|
|
|
|
|
addr_virtual_macs = self.create_macvlan_and_apply_config(
|
|
|
|
ifaceobj,
|
|
|
|
self.translate_addrvirtual_user_config_to_list(
|
|
|
|
ifaceobj,
|
|
|
|
address_virtual_list
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
vrr_macs = self.create_macvlan_and_apply_config(
|
|
|
|
ifaceobj,
|
|
|
|
self.translate_vrr_user_config_to_list(
|
|
|
|
ifaceobj,
|
|
|
|
vrr_config_list
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
hw_address_list = addr_virtual_macs + vrr_macs
|
|
|
|
|
|
|
|
# check the statemanager for old configs.
|
|
|
|
# We need to remove only the previously configured FDB entries
|
|
|
|
oldmacs = self._get_macs_from_old_config(ifaceobj)
|
|
|
|
# get a list of fdbs in old that are not in new config meaning they should
|
|
|
|
# be removed since they are gone from the config
|
|
|
|
removed_macs = [mac for mac in oldmacs if mac.lower() not in hw_address_list]
|
|
|
|
self._remove_addresses_from_bridge(ifaceobj, removed_macs)
|
|
|
|
# if ifaceobj is a bridge and bridge is a vlan aware bridge
|
|
|
|
# add the vid to the bridge
|
|
|
|
self._add_addresses_to_bridge(ifaceobj, hw_address_list)
|
|
|
|
|
|
|
|
def translate_vrr_user_config_to_list(self, ifaceobj, vrr_config_list, ifquery=False):
|
|
|
|
"""
|
|
|
|
If (IPv4 addresses provided):
|
|
|
|
00:00:5e:00:01:<V>
|
|
|
|
else if (IPv6 addresses provided):
|
|
|
|
00:00:5e:00:02:<V>
|
|
|
|
|
|
|
|
vrrp 1 10.0.0.15/24
|
|
|
|
vrrp 1 2001:0db8::0370:7334/64
|
|
|
|
|
|
|
|
# Translate:
|
|
|
|
# vrrp 255 10.0.0.15/24 10.0.0.2/1
|
|
|
|
# To:
|
|
|
|
# [
|
|
|
|
# {
|
|
|
|
# "ifname": "macvlan_ifname",
|
|
|
|
# "hwaddress": "macvlan_hwaddress",
|
|
|
|
# "ips": [str(IPNetwork), ]
|
|
|
|
# },
|
|
|
|
# ]
|
|
|
|
"""
|
|
|
|
ifname = ifaceobj.name
|
|
|
|
user_config_list = []
|
|
|
|
|
2019-02-19 23:14:03 +01:00
|
|
|
for index, config in enumerate(vrr_config_list or []):
|
2019-01-25 09:58:25 +08:00
|
|
|
vrrp_id, ip_addrs = config.split(" ", 1)
|
|
|
|
hex_id = '%02x' % int(vrrp_id)
|
|
|
|
ip4 = []
|
|
|
|
ip6 = []
|
|
|
|
|
|
|
|
for ip_addr in ip_addrs.split():
|
|
|
|
ip_network_obj = IPNetwork(ip_addr)
|
|
|
|
is_ip6 = isinstance(ip_network_obj, IPv6Network)
|
|
|
|
|
|
|
|
if is_ip6:
|
|
|
|
ip6.append(ip_addr)
|
|
|
|
else:
|
|
|
|
ip4.append(ip_addr)
|
|
|
|
|
2019-02-19 23:14:03 +01:00
|
|
|
macvlan_ip4_ifname = "%s%s" % (self.get_vrr_prefix(ifname, "4"), index)
|
|
|
|
macvlan_ip6_ifname = "%s%s" % (self.get_vrr_prefix(ifname, "6"), index)
|
2019-01-25 09:58:25 +08:00
|
|
|
|
|
|
|
merged_with_existing_obj = False
|
|
|
|
# if the vrr config is defined in different lines for the same ID
|
|
|
|
# we need to save the ip4 and ip6 in the objects we previously
|
|
|
|
# created, example:
|
|
|
|
# vrrp 255 10.0.0.15/24 10.0.0.2/15
|
|
|
|
# vrrp 255 fe80::a00:27ff:fe04:42/64
|
|
|
|
for obj in user_config_list:
|
|
|
|
if obj.get("ifname") == macvlan_ip4_ifname:
|
|
|
|
obj["ips"] += ip4
|
|
|
|
merged_with_existing_obj = True
|
|
|
|
elif obj.get("ifname") == macvlan_ip6_ifname:
|
|
|
|
obj["ips"] += ip6
|
|
|
|
merged_with_existing_obj = True
|
|
|
|
|
|
|
|
if merged_with_existing_obj:
|
|
|
|
continue
|
|
|
|
|
|
|
|
if ip4 or ifquery:
|
|
|
|
# config_ip4
|
|
|
|
macvlan_ip4_mac = "00:00:5e:00:01:%s" % hex_id
|
|
|
|
user_config_list.append({
|
|
|
|
"ifname": macvlan_ip4_ifname,
|
|
|
|
"hwaddress": macvlan_ip4_mac,
|
|
|
|
"hwaddress_int": self.mac_str_to_int(macvlan_ip4_mac),
|
|
|
|
"ips": ip4,
|
|
|
|
"id": vrrp_id
|
|
|
|
})
|
|
|
|
|
|
|
|
if ip6 or ifquery:
|
|
|
|
# config_ip6
|
|
|
|
macvlan_ip6_mac = "00:00:5e:00:02:%s" % hex_id
|
|
|
|
user_config_list.append({
|
|
|
|
"ifname": macvlan_ip6_ifname,
|
|
|
|
"hwaddress": macvlan_ip6_mac,
|
|
|
|
"hwaddress_int": self.mac_str_to_int(macvlan_ip6_mac),
|
|
|
|
"ips": ip6,
|
|
|
|
"id": vrrp_id
|
|
|
|
})
|
|
|
|
|
|
|
|
return user_config_list
|
|
|
|
|
|
|
|
def translate_addrvirtual_user_config_to_list(self, ifaceobj, address_virtual_list):
|
|
|
|
"""
|
|
|
|
# Translate:
|
|
|
|
# address-virtual 00:11:22:33:44:01 2001:0db8::0370:7334/64 11.0.1.1/24 11.0.1.2/24
|
|
|
|
# To:
|
|
|
|
# [
|
|
|
|
# {
|
|
|
|
# "ifname": "macvlan_ifname",
|
|
|
|
# "hwaddress": "macvlan_hwaddress",
|
|
|
|
# "ips": [str(IPNetwork), ]
|
|
|
|
# },
|
|
|
|
# ]
|
|
|
|
"""
|
|
|
|
user_config_list = []
|
|
|
|
|
|
|
|
if not address_virtual_list:
|
|
|
|
return user_config_list
|
|
|
|
|
|
|
|
macvlan_prefix = self._get_macvlan_prefix(ifaceobj)
|
|
|
|
|
|
|
|
for index, addr_virtual in enumerate(address_virtual_list):
|
|
|
|
av_attrs = addr_virtual.split()
|
|
|
|
|
|
|
|
if len(av_attrs) < 2:
|
|
|
|
self.log_error("%s: incorrect address-virtual attrs '%s'"
|
|
|
|
% (ifaceobj.name, addr_virtual), ifaceobj,
|
|
|
|
raise_error=False)
|
|
|
|
continue
|
|
|
|
|
|
|
|
mac = av_attrs[0]
|
|
|
|
if mac:
|
|
|
|
mac = mac.lower()
|
|
|
|
|
|
|
|
if not self.check_mac_address(ifaceobj, mac):
|
|
|
|
continue
|
|
|
|
|
|
|
|
config = {"ifname": "%s%d" % (macvlan_prefix, index)}
|
|
|
|
|
|
|
|
if mac != "none":
|
|
|
|
config["hwaddress"] = mac
|
|
|
|
config["hwaddress_int"] = self.mac_str_to_int(mac)
|
|
|
|
|
|
|
|
ip_network_obj_list = []
|
|
|
|
for ip in av_attrs[1:]:
|
|
|
|
ip_network_obj_list.append(str(IPNetwork(ip)))
|
|
|
|
|
|
|
|
config["ips"] = ip_network_obj_list
|
|
|
|
user_config_list.append(config)
|
|
|
|
|
|
|
|
return user_config_list
|
|
|
|
|
|
|
|
def process_macvlans_config(self, ifaceobj, attr_name, virtual_addr_list_raw, macvlan_config_list):
|
|
|
|
return self.create_macvlan_and_apply_config(ifaceobj, macvlan_config_list)
|
2014-10-09 16:02:46 -07:00
|
|
|
|
[PATCH ifupdown2] addons: addressvirtual: fixup macvlan device enslavements for vrfs
Ticket: CM-12988
Reviewed By: julien, nikhil, dsa
Testing Done: tested ifup and ifdown of vrf devices with address virtual
slaves
This patch fixes up macvlan device enslavements when vrf device
or vrf slave is brought down and up. address virtual macvlan
devices on vrf slaves need to enslaved to the vrf. This
patch checks and fixes up those vrf enslavements for the following
cases:
ifdown <vrf_device> && ifup <vrf_device>
ifdown <vrf_slave> && ifup <vrf_slave>
starting state:
------------
$ip -br link show
myvrf UP 46:c6:44:db:37:60 <NOARP,MASTER,UP,LOWER_UP>
bridge.901@bridge UP 44:38:39:00:77:88 <UP,BROADCAST,MULTICAST,UP>
bridge-901-v0@bridge.901 UP 00:00:5e:00:01:81 <UP,BROADCAST,MULTICAST,UP>
$ifdown myvrf
$ip -br link show
bridge.901@bridge DOWN 44:38:39:00:77:88 <BROADCAST,MULTICAST>
bridge-901-v0@bridge.901 DOWN 00:00:5e:00:01:81 <BROADCAST,MULTICAST,M-DOWN>
before patch (macvlan device bridge-901-v0 did not come up:
----------------------------------------
$ifup myvrf
$ip -br link show
bridge.901@bridge UP 44:38:39:00:77:88 <UP,BROADCAST,MULTICAST,UP>
bridge-901-v0@bridge.901 DOWN 00:00:5e:00:01:81 <BROADCAST,MULTICAST>
myvrf UP ce:a6:e1:85:75:73 <NOARP,MASTER,UP,LOWER_UP>
after patch:
------------
$ifup myvrf
$ip -br link show
bridge.901@bridge UP 44:38:39:00:77:88 <UP,BROADCAST,MULTICAST,UP>
bridge-901-v0@bridge.901 UP 00:00:5e:00:01:81 <UP,BROADCAST,MULTICAST,UP>
myvrf UP ce:a6:e1:85:75:73 <NOARP,MASTER,UP,LOWER_UP>
Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
2016-10-19 10:43:45 -07:00
|
|
|
def _down(self, ifaceobj, ifaceobj_getfunc=None):
|
2014-10-09 16:02:46 -07:00
|
|
|
try:
|
2014-10-28 23:04:40 -07:00
|
|
|
self._remove_address_config(ifaceobj,
|
|
|
|
ifaceobj.get_attr_value('address-virtual'))
|
2019-01-25 09:58:25 +08:00
|
|
|
|
|
|
|
#### VRR
|
|
|
|
hwaddress = []
|
|
|
|
self.ipcmd.batch_start()
|
|
|
|
for vrr_prefix in [self.get_vrr_prefix(ifaceobj.name, "4"), self.get_vrr_prefix(ifaceobj.name, "6")]:
|
|
|
|
for macvlan_ifacename in glob.glob("/sys/class/net/%s*" % vrr_prefix):
|
|
|
|
macvlan_ifacename = os.path.basename(macvlan_ifacename)
|
|
|
|
if not self.ipcmd.link_exists(macvlan_ifacename):
|
|
|
|
continue
|
|
|
|
hwaddress.append(self.ipcmd.link_get_hwaddress(macvlan_ifacename))
|
|
|
|
self.ipcmd.link_delete(os.path.basename(macvlan_ifacename))
|
|
|
|
# XXX: Also delete any fdb addresses. This requires, checking mac address
|
|
|
|
# on individual macvlan interfaces and deleting the vlan from that.
|
|
|
|
self.ipcmd.batch_commit()
|
|
|
|
if any(hwaddress):
|
|
|
|
self._remove_addresses_from_bridge(ifaceobj, hwaddress)
|
2014-10-09 16:02:46 -07:00
|
|
|
except Exception, e:
|
2019-01-25 09:58:25 +08:00
|
|
|
import traceback
|
|
|
|
traceback.print_exc()
|
2014-10-09 16:02:46 -07:00
|
|
|
self.log_warn(str(e))
|
|
|
|
|
|
|
|
def _query_check(self, ifaceobj, ifaceobjcurr):
|
2019-01-25 09:58:25 +08:00
|
|
|
|
2014-10-28 23:04:40 -07:00
|
|
|
if not self.ipcmd.link_exists(ifaceobj.name):
|
|
|
|
return
|
2018-07-10 00:18:39 +02:00
|
|
|
|
|
|
|
user_config_address_virtual_ipv6_addr = ifaceobj.get_attr_value_first('address-virtual-ipv6-addrgen')
|
|
|
|
if user_config_address_virtual_ipv6_addr and user_config_address_virtual_ipv6_addr not in utils._string_values:
|
|
|
|
ifaceobjcurr.update_config_with_status('address-virtual-ipv6-addrgen', user_config_address_virtual_ipv6_addr, 1)
|
|
|
|
user_config_address_virtual_ipv6_addr = None
|
2019-01-25 09:58:25 +08:00
|
|
|
|
|
|
|
address_virtual_list = ifaceobj.get_attr_value('address-virtual')
|
|
|
|
|
|
|
|
macvlans_running_ipv6_addr_virtual = self.query_check_macvlan_config(
|
|
|
|
ifaceobj,
|
|
|
|
ifaceobjcurr,
|
|
|
|
"address-virtual",
|
|
|
|
user_config_address_virtual_ipv6_addr,
|
|
|
|
virtual_addr_list_raw=address_virtual_list,
|
|
|
|
macvlan_config_list=self.translate_addrvirtual_user_config_to_list(
|
|
|
|
ifaceobj,
|
|
|
|
address_virtual_list
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
vrr_config_list = ifaceobj.get_attr_value("vrrp")
|
|
|
|
|
|
|
|
macvlans_running_ipv6_addr_vrr = self.query_check_macvlan_config(
|
|
|
|
ifaceobj,
|
|
|
|
ifaceobjcurr,
|
|
|
|
"vrrp",
|
|
|
|
user_config_address_virtual_ipv6_addr,
|
|
|
|
virtual_addr_list_raw=vrr_config_list,
|
|
|
|
macvlan_config_list=self.translate_vrr_user_config_to_list(
|
|
|
|
ifaceobj,
|
|
|
|
vrr_config_list,
|
|
|
|
ifquery=True
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
macvlans_running_ipv6_addr = macvlans_running_ipv6_addr_virtual + macvlans_running_ipv6_addr_vrr
|
|
|
|
if user_config_address_virtual_ipv6_addr:
|
|
|
|
bool_user_ipv6_addrgen = utils.get_boolean_from_string(user_config_address_virtual_ipv6_addr)
|
|
|
|
for running_ipv6_addrgen in macvlans_running_ipv6_addr:
|
|
|
|
if (not bool_user_ipv6_addrgen) != running_ipv6_addrgen:
|
|
|
|
ifaceobjcurr.update_config_with_status('address-virtual-ipv6-addrgen', user_config_address_virtual_ipv6_addr, 1)
|
|
|
|
return
|
|
|
|
ifaceobjcurr.update_config_with_status('address-virtual-ipv6-addrgen', user_config_address_virtual_ipv6_addr, 0)
|
|
|
|
|
|
|
|
def query_check_macvlan_config(self, ifaceobj, ifaceobjcurr, attr_name, user_config_address_virtual_ipv6_addr, virtual_addr_list_raw, macvlan_config_list):
|
|
|
|
"""
|
|
|
|
macvlan_config_list = [
|
|
|
|
{
|
|
|
|
"ifname": "macvlan_ifname",
|
|
|
|
"hwaddress": "macvlan_hwaddress",
|
|
|
|
"ips": [str(IPNetwork), ]
|
|
|
|
},
|
|
|
|
]
|
|
|
|
"""
|
|
|
|
is_vrr = attr_name == "vrrp"
|
2018-07-10 00:18:39 +02:00
|
|
|
macvlans_running_ipv6_addr = []
|
|
|
|
|
2019-01-25 09:58:25 +08:00
|
|
|
if not virtual_addr_list_raw:
|
|
|
|
return macvlans_running_ipv6_addr
|
|
|
|
|
|
|
|
macvlan_config_queue = deque(macvlan_config_list)
|
|
|
|
|
|
|
|
while macvlan_config_queue:
|
|
|
|
|
|
|
|
ip4_config = None
|
|
|
|
ip6_config = None
|
|
|
|
|
|
|
|
config = macvlan_config_queue.popleft()
|
|
|
|
|
|
|
|
if is_vrr:
|
|
|
|
ip4_config = config
|
|
|
|
ip6_config = macvlan_config_queue.popleft()
|
|
|
|
|
|
|
|
macvlan_ifacename = config.get("ifname")
|
2014-10-09 16:02:46 -07:00
|
|
|
|
2014-10-28 23:04:40 -07:00
|
|
|
if not self.ipcmd.link_exists(macvlan_ifacename):
|
2019-01-25 09:58:25 +08:00
|
|
|
ifaceobjcurr.update_config_with_status(attr_name, "", 1)
|
2014-10-28 23:04:40 -07:00
|
|
|
continue
|
2018-07-10 00:18:39 +02:00
|
|
|
|
2019-01-25 09:58:25 +08:00
|
|
|
macvlan_hwaddress = config.get("hwaddress")
|
|
|
|
macvlan_hwaddress_int = config.get("hwaddress_int")
|
|
|
|
|
2018-07-10 00:18:39 +02:00
|
|
|
if user_config_address_virtual_ipv6_addr:
|
|
|
|
macvlans_running_ipv6_addr.append(self.ipcmd.get_ipv6_addrgen_mode(macvlan_ifacename))
|
|
|
|
|
2014-10-28 23:04:40 -07:00
|
|
|
# Check mac and ip address
|
2019-01-25 09:58:25 +08:00
|
|
|
rhwaddress = ip4_macvlan_hwaddress = self.ipcmd.link_get_hwaddress(macvlan_ifacename)
|
|
|
|
raddrs = ip4_running_addrs = self.ipcmd.get_running_addrs(
|
2018-12-13 11:43:32 -08:00
|
|
|
ifname=macvlan_ifacename,
|
|
|
|
details=False,
|
|
|
|
addr_virtual_ifaceobj=ifaceobj
|
|
|
|
)
|
2018-07-10 00:18:39 +02:00
|
|
|
|
2019-01-25 09:58:25 +08:00
|
|
|
if not is_vrr:
|
|
|
|
ips = config.get("ips")
|
|
|
|
|
|
|
|
if not raddrs or not rhwaddress:
|
|
|
|
ifaceobjcurr.update_config_with_status(attr_name, "", 1)
|
|
|
|
continue
|
|
|
|
|
|
|
|
try:
|
|
|
|
if self.mac_str_to_int(rhwaddress) == macvlan_hwaddress_int \
|
|
|
|
and self.ipcmd.compare_user_config_vs_running_state(raddrs, ips) \
|
|
|
|
and self._check_addresses_in_bridge(ifaceobj, macvlan_hwaddress):
|
|
|
|
ifaceobjcurr.update_config_with_status(
|
|
|
|
attr_name,
|
|
|
|
" ".join(virtual_addr_list_raw),
|
|
|
|
0
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
ifaceobjcurr.update_config_with_status(
|
|
|
|
attr_name,
|
|
|
|
'%s %s' % (rhwaddress, ' '.join(raddrs)),
|
|
|
|
1
|
|
|
|
)
|
|
|
|
except:
|
|
|
|
ifaceobjcurr.update_config_with_status(
|
|
|
|
attr_name,
|
|
|
|
'%s %s' % (rhwaddress, ' '.join(raddrs)),
|
|
|
|
1
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
# VRRP
|
|
|
|
|
|
|
|
ok = False
|
|
|
|
# check macvlan ip4 hwaddress (only if ip4 were provided by the user)
|
|
|
|
if not ip4_config.get("ips") or ip4_macvlan_hwaddress == ip4_config.get("hwaddress"):
|
|
|
|
ip6_macvlan_ifname = ip6_config.get("ifname")
|
|
|
|
ip6_macvlan_hwaddress = ip6_config.get("hwaddress")
|
|
|
|
|
|
|
|
# check macvlan ip6 hwaddress (only if ip6 were provided by the user)
|
|
|
|
if not ip6_config.get("ips") or self.ipcmd.link_get_hwaddress(ip6_macvlan_ifname) == ip6_macvlan_hwaddress:
|
|
|
|
|
|
|
|
# check all ip4
|
|
|
|
if self.ipcmd.compare_user_config_vs_running_state(
|
|
|
|
ip4_running_addrs,
|
|
|
|
ip4_config.get("ips")
|
|
|
|
) and self._check_addresses_in_bridge(ifaceobj, ip4_macvlan_hwaddress):
|
|
|
|
ip6_running_addrs = self.ipcmd.get_running_addrs(
|
|
|
|
ifname=ip6_macvlan_ifname,
|
|
|
|
details=False,
|
|
|
|
addr_virtual_ifaceobj=ifaceobj
|
|
|
|
)
|
|
|
|
|
|
|
|
# check all ip6
|
|
|
|
if self.ipcmd.compare_user_config_vs_running_state(
|
|
|
|
ip6_running_addrs,
|
|
|
|
ip6_config.get("ips")
|
|
|
|
) and self._check_addresses_in_bridge(ifaceobj, ip4_macvlan_hwaddress):
|
|
|
|
ifaceobjcurr.update_config_with_status(
|
|
|
|
attr_name,
|
|
|
|
"%s %s" % (ip4_config.get("id"), " ".join(ip4_config.get("ips") + ip6_config.get("ips"))),
|
|
|
|
0
|
|
|
|
)
|
|
|
|
ok = True
|
|
|
|
|
|
|
|
if not ok:
|
|
|
|
ifaceobjcurr.update_config_with_status(
|
|
|
|
attr_name,
|
|
|
|
"%s %s" % (ip4_config.get("id"), " ".join(ip4_config.get("ips") + ip6_config.get("ips"))),
|
|
|
|
1
|
|
|
|
)
|
|
|
|
|
|
|
|
return macvlans_running_ipv6_addr
|
2014-10-09 16:02:46 -07:00
|
|
|
|
[PATCH ifupdown2] addons: addressvirtual: fixup macvlan device enslavements for vrfs
Ticket: CM-12988
Reviewed By: julien, nikhil, dsa
Testing Done: tested ifup and ifdown of vrf devices with address virtual
slaves
This patch fixes up macvlan device enslavements when vrf device
or vrf slave is brought down and up. address virtual macvlan
devices on vrf slaves need to enslaved to the vrf. This
patch checks and fixes up those vrf enslavements for the following
cases:
ifdown <vrf_device> && ifup <vrf_device>
ifdown <vrf_slave> && ifup <vrf_slave>
starting state:
------------
$ip -br link show
myvrf UP 46:c6:44:db:37:60 <NOARP,MASTER,UP,LOWER_UP>
bridge.901@bridge UP 44:38:39:00:77:88 <UP,BROADCAST,MULTICAST,UP>
bridge-901-v0@bridge.901 UP 00:00:5e:00:01:81 <UP,BROADCAST,MULTICAST,UP>
$ifdown myvrf
$ip -br link show
bridge.901@bridge DOWN 44:38:39:00:77:88 <BROADCAST,MULTICAST>
bridge-901-v0@bridge.901 DOWN 00:00:5e:00:01:81 <BROADCAST,MULTICAST,M-DOWN>
before patch (macvlan device bridge-901-v0 did not come up:
----------------------------------------
$ifup myvrf
$ip -br link show
bridge.901@bridge UP 44:38:39:00:77:88 <UP,BROADCAST,MULTICAST,UP>
bridge-901-v0@bridge.901 DOWN 00:00:5e:00:01:81 <BROADCAST,MULTICAST>
myvrf UP ce:a6:e1:85:75:73 <NOARP,MASTER,UP,LOWER_UP>
after patch:
------------
$ifup myvrf
$ip -br link show
bridge.901@bridge UP 44:38:39:00:77:88 <UP,BROADCAST,MULTICAST,UP>
bridge-901-v0@bridge.901 UP 00:00:5e:00:01:81 <UP,BROADCAST,MULTICAST,UP>
myvrf UP ce:a6:e1:85:75:73 <NOARP,MASTER,UP,LOWER_UP>
Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
2016-10-19 10:43:45 -07:00
|
|
|
def _query_running(self, ifaceobjrunning, ifaceobj_getfunc=None):
|
2014-11-08 06:29:26 -08:00
|
|
|
macvlan_prefix = self._get_macvlan_prefix(ifaceobjrunning)
|
2014-11-03 17:55:51 -08:00
|
|
|
address_virtuals = glob.glob("/sys/class/net/%s*" %macvlan_prefix)
|
2018-07-10 00:18:39 +02:00
|
|
|
macvlans_ipv6_addrgen_list = []
|
2014-11-03 17:55:51 -08:00
|
|
|
for av in address_virtuals:
|
|
|
|
macvlan_ifacename = os.path.basename(av)
|
|
|
|
rhwaddress = self.ipcmd.link_get_hwaddress(macvlan_ifacename)
|
2018-10-08 15:18:32 +02:00
|
|
|
|
|
|
|
raddress = []
|
|
|
|
for obj in ifaceobj_getfunc(ifaceobjrunning.name) or []:
|
|
|
|
raddress.extend(self.ipcmd.get_running_addrs(None, macvlan_ifacename, addr_virtual_ifaceobj=obj) or [])
|
|
|
|
|
|
|
|
raddress = list(set(raddress))
|
|
|
|
|
2014-11-03 17:55:51 -08:00
|
|
|
if not raddress:
|
|
|
|
self.logger.warn('%s: no running addresses'
|
|
|
|
%ifaceobjrunning.name)
|
|
|
|
raddress = []
|
|
|
|
ifaceobjrunning.update_config('address-virtual',
|
2018-10-08 15:18:32 +02:00
|
|
|
'%s %s' %(rhwaddress, ' '.join(raddress)))
|
2018-07-10 00:18:39 +02:00
|
|
|
|
|
|
|
macvlans_ipv6_addrgen_list.append((macvlan_ifacename, self.ipcmd.get_ipv6_addrgen_mode(macvlan_ifacename)))
|
|
|
|
|
|
|
|
macvlan_count = len(address_virtuals)
|
|
|
|
if not macvlan_count:
|
|
|
|
return
|
|
|
|
ipv6_addrgen = macvlans_ipv6_addrgen_list[0][1]
|
|
|
|
|
|
|
|
for macvlan_ifname, macvlan_ipv6_addrgen in macvlans_ipv6_addrgen_list:
|
|
|
|
if macvlan_ipv6_addrgen != ipv6_addrgen:
|
|
|
|
# one macvlan has a different ipv6-addrgen configuration
|
|
|
|
# we simply return, ifquery-running will print the macvlan
|
|
|
|
# stanzas with the ipv6-addrgen on/off attribute
|
|
|
|
return
|
|
|
|
ifaceobjrunning.update_config('address-virtual-ipv6-addrgen', 'off' if ipv6_addrgen else 'on')
|
|
|
|
|
2014-10-09 16:02:46 -07:00
|
|
|
|
|
|
|
_run_ops = {'up' : _up,
|
|
|
|
'down' : _down,
|
|
|
|
'query-checkcurr' : _query_check,
|
|
|
|
'query-running' : _query_running}
|
|
|
|
|
|
|
|
def get_ops(self):
|
|
|
|
""" returns list of ops supported by this module """
|
|
|
|
return self._run_ops.keys()
|
|
|
|
|
|
|
|
def _init_command_handlers(self):
|
|
|
|
if not self.ipcmd:
|
2018-12-13 11:43:32 -08:00
|
|
|
self.ipcmd = LinkUtils()
|
2014-10-09 16:02:46 -07:00
|
|
|
|
[PATCH ifupdown2] addons: addressvirtual: fixup macvlan device enslavements for vrfs
Ticket: CM-12988
Reviewed By: julien, nikhil, dsa
Testing Done: tested ifup and ifdown of vrf devices with address virtual
slaves
This patch fixes up macvlan device enslavements when vrf device
or vrf slave is brought down and up. address virtual macvlan
devices on vrf slaves need to enslaved to the vrf. This
patch checks and fixes up those vrf enslavements for the following
cases:
ifdown <vrf_device> && ifup <vrf_device>
ifdown <vrf_slave> && ifup <vrf_slave>
starting state:
------------
$ip -br link show
myvrf UP 46:c6:44:db:37:60 <NOARP,MASTER,UP,LOWER_UP>
bridge.901@bridge UP 44:38:39:00:77:88 <UP,BROADCAST,MULTICAST,UP>
bridge-901-v0@bridge.901 UP 00:00:5e:00:01:81 <UP,BROADCAST,MULTICAST,UP>
$ifdown myvrf
$ip -br link show
bridge.901@bridge DOWN 44:38:39:00:77:88 <BROADCAST,MULTICAST>
bridge-901-v0@bridge.901 DOWN 00:00:5e:00:01:81 <BROADCAST,MULTICAST,M-DOWN>
before patch (macvlan device bridge-901-v0 did not come up:
----------------------------------------
$ifup myvrf
$ip -br link show
bridge.901@bridge UP 44:38:39:00:77:88 <UP,BROADCAST,MULTICAST,UP>
bridge-901-v0@bridge.901 DOWN 00:00:5e:00:01:81 <BROADCAST,MULTICAST>
myvrf UP ce:a6:e1:85:75:73 <NOARP,MASTER,UP,LOWER_UP>
after patch:
------------
$ifup myvrf
$ip -br link show
bridge.901@bridge UP 44:38:39:00:77:88 <UP,BROADCAST,MULTICAST,UP>
bridge-901-v0@bridge.901 UP 00:00:5e:00:01:81 <UP,BROADCAST,MULTICAST,UP>
myvrf UP ce:a6:e1:85:75:73 <NOARP,MASTER,UP,LOWER_UP>
Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
2016-10-19 10:43:45 -07:00
|
|
|
def run(self, ifaceobj, operation, query_ifaceobj=None,
|
|
|
|
ifaceobj_getfunc=None, **extra_args):
|
2014-10-09 16:02:46 -07:00
|
|
|
""" run vlan configuration on the interface object passed as argument
|
|
|
|
|
|
|
|
Args:
|
|
|
|
**ifaceobj** (object): iface object
|
|
|
|
|
|
|
|
**operation** (str): any of 'pre-up', 'post-down', 'query-checkcurr',
|
|
|
|
'query-running'
|
|
|
|
Kwargs:
|
|
|
|
**query_ifaceobj** (object): query check ifaceobject. This is only
|
|
|
|
valid when op is 'query-checkcurr'. It is an object same as
|
|
|
|
ifaceobj, but contains running attribute values and its config
|
|
|
|
status. The modules can use it to return queried running state
|
|
|
|
of interfaces. status is success if the running state is same
|
|
|
|
as user required state in ifaceobj. error otherwise.
|
|
|
|
"""
|
2014-10-24 10:11:07 -07:00
|
|
|
if ifaceobj.type == ifaceType.BRIDGE_VLAN:
|
|
|
|
return
|
2014-10-09 16:02:46 -07:00
|
|
|
op_handler = self._run_ops.get(operation)
|
|
|
|
if not op_handler:
|
|
|
|
return
|
|
|
|
self._init_command_handlers()
|
|
|
|
if operation == 'query-checkcurr':
|
|
|
|
op_handler(self, ifaceobj, query_ifaceobj)
|
|
|
|
else:
|
[PATCH ifupdown2] addons: addressvirtual: fixup macvlan device enslavements for vrfs
Ticket: CM-12988
Reviewed By: julien, nikhil, dsa
Testing Done: tested ifup and ifdown of vrf devices with address virtual
slaves
This patch fixes up macvlan device enslavements when vrf device
or vrf slave is brought down and up. address virtual macvlan
devices on vrf slaves need to enslaved to the vrf. This
patch checks and fixes up those vrf enslavements for the following
cases:
ifdown <vrf_device> && ifup <vrf_device>
ifdown <vrf_slave> && ifup <vrf_slave>
starting state:
------------
$ip -br link show
myvrf UP 46:c6:44:db:37:60 <NOARP,MASTER,UP,LOWER_UP>
bridge.901@bridge UP 44:38:39:00:77:88 <UP,BROADCAST,MULTICAST,UP>
bridge-901-v0@bridge.901 UP 00:00:5e:00:01:81 <UP,BROADCAST,MULTICAST,UP>
$ifdown myvrf
$ip -br link show
bridge.901@bridge DOWN 44:38:39:00:77:88 <BROADCAST,MULTICAST>
bridge-901-v0@bridge.901 DOWN 00:00:5e:00:01:81 <BROADCAST,MULTICAST,M-DOWN>
before patch (macvlan device bridge-901-v0 did not come up:
----------------------------------------
$ifup myvrf
$ip -br link show
bridge.901@bridge UP 44:38:39:00:77:88 <UP,BROADCAST,MULTICAST,UP>
bridge-901-v0@bridge.901 DOWN 00:00:5e:00:01:81 <BROADCAST,MULTICAST>
myvrf UP ce:a6:e1:85:75:73 <NOARP,MASTER,UP,LOWER_UP>
after patch:
------------
$ifup myvrf
$ip -br link show
bridge.901@bridge UP 44:38:39:00:77:88 <UP,BROADCAST,MULTICAST,UP>
bridge-901-v0@bridge.901 UP 00:00:5e:00:01:81 <UP,BROADCAST,MULTICAST,UP>
myvrf UP ce:a6:e1:85:75:73 <NOARP,MASTER,UP,LOWER_UP>
Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
2016-10-19 10:43:45 -07:00
|
|
|
op_handler(self, ifaceobj, ifaceobj_getfunc=ifaceobj_getfunc)
|