예제 #1
0
    def _down_vrf_dev(self, ifaceobj, vrf_table, ifaceobj_getfunc=None):

        if not self.ipcmd.link_exists(ifaceobj.name):
            return

        if vrf_table == 'auto':
            vrf_table = self._get_iproute2_vrf_table(ifaceobj.name)

        running_slaves = self.ipcmd.link_get_lowers(ifaceobj.name)
        if running_slaves:
            for s in running_slaves:
                if ifaceobj_getfunc:
                    sobj = ifaceobj_getfunc(s)
                    try:
                        self._handle_existing_connections(
                            sobj[0] if sobj else None, ifaceobj.name)
                    except Exception, e:
                        self.logger.info('%s: %s' % (ifaceobj.name, str(e)))
                        pass
                try:
                    self.ipcmd.addr_flush(s)
                    netlink.link_set_updown(s, "down")
                except Exception, e:
                    self.logger.info('%s: %s' % (ifaceobj.name, str(e)))
                    pass
예제 #2
0
    def _check_settings(self, ifaceobj, attrs):

        linkup = self.ipcmd.is_link_up(ifaceobj.name)
        try:
            if attrs:
                self.ipcmd.tunnel_change(ifaceobj.name, attrs)
        except:
            raise
        finally:
            if attrs and linkup:
                netlink.link_set_updown(ifaceobj.name, 'up')
예제 #3
0
 def _down_vrf_slave(self, ifacename, ifaceobj=None, vrfname=None):
     try:
         self._handle_existing_connections(ifaceobj, vrfname)
         netlink.link_set_nomaster(ifacename)
         # Down this slave only if it is a slave ifupdown2 manages.
         # we dont want to down slaves that maybe up'ed by
         # somebody else. One such example is a macvlan device
         # which ifupdown2 addressvirtual addon module auto creates
         if ifaceobj:
             netlink.link_set_updown(ifacename, "down")
     except Exception, e:
         self.logger.warn('%s: %s' % (ifacename, str(e)))
예제 #4
0
 def _up_vrf_slave(self,
                   ifacename,
                   vrfname,
                   ifaceobj=None,
                   ifaceobj_getfunc=None,
                   vrf_exists=False):
     try:
         master_exists = True
         if vrf_exists or self.ipcmd.link_exists(vrfname):
             uppers = self.ipcmd.link_get_uppers(ifacename)
             if not uppers or vrfname not in uppers:
                 self._handle_existing_connections(ifaceobj, vrfname)
                 netlink.link_set_master(ifacename, vrfname)
         elif ifaceobj:
             vrf_master_objs = ifaceobj_getfunc(vrfname)
             if not vrf_master_objs:
                 # this is the case where vrf is assigned to an interface
                 # but user has not provided a vrf interface.
                 # people expect you to warn them but go ahead with the
                 # rest of the config on that interface
                 netlink.link_set_updown(ifacename, "up")
                 self.log_error('vrf master ifaceobj %s not found' %
                                vrfname)
                 return
             if (ifupdownflags.flags.ALL or ifupdownflags.flags.WITH_DEPENDS
                     or (ifupdownflags.flags.CLASS and ifaceobj.classes
                         and vrf_master_objs[0].classes
                         and Set(ifaceobj.classes).intersection(
                             vrf_master_objs[0].classes))):
                 self._up_vrf_slave_without_master(ifacename, vrfname,
                                                   ifaceobj,
                                                   vrf_master_objs)
             else:
                 master_exists = False
         else:
             master_exists = False
         if master_exists:
             netlink.link_set_updown(ifacename, "up")
         else:
             self.log_error(
                 'vrf %s not around, skipping vrf config' % (vrfname),
                 ifaceobj)
     except Exception, e:
         self.log_error('%s: %s' % (ifacename, str(e)), ifaceobj)
예제 #5
0
    def _up(self, ifaceobj):
        if self._get_batman_ifaces(ifaceobj) == None:
            raise Exception('could not determine batman interfacaes')

        # Verify existance of batman interfaces (should be present already)
        batman_ifaces = []
        for iface in self._get_batman_ifaces(ifaceobj):
            if not self.ipcmd.link_exists(iface):
                self.logger.warn('batman iface %s not present' % iface)
                continue

            batman_ifaces.append(iface)

        if len(batman_ifaces) == 0:
            raise Exception(
                "None of the configured batman interfaces are available!")

        if_ignore_re = self._get_batman_ifaces_ignore_regex(ifaceobj)
        # Is the batman main interface already present?
        if self.ipcmd.link_exists(ifaceobj.name):
            # Verify which member interfaces are present
            members = self._find_member_ifaces(ifaceobj)
            for iface in members:
                if iface not in batman_ifaces:
                    self._batctl_if(ifaceobj.name, iface, 'del')
            for iface in batman_ifaces:
                if iface not in members:
                    self._batctl_if(ifaceobj.name, iface, 'add')

        # Batman interfaces no present, add member interfaces to create it
        else:
            for iface in batman_ifaces:
                self._batctl_if(ifaceobj.name, iface, 'add')

        # Check/set any B.A.T.M.A.N. adv. set within interface configuration
        for attr in self._batman_attrs:
            value_cfg = self._get_batman_attr(ifaceobj, attr)
            if value_cfg and value_cfg != self._read_current_batman_attr(
                    ifaceobj, attr):
                self._set_batman_attr(ifaceobj, attr, value_cfg)

        if ifaceobj.addr_method == 'manual':
            netlink.link_set_updown(ifaceobj.name, "up")
예제 #6
0
    def _apply_master_settings(self, ifaceobj):
        have_attrs_to_set = 0
        linkup = False
        bondcmd_attrmap =  OrderedDict([('bond-mode' , 'mode'),
                                 ('bond-miimon' , 'miimon'),
                                 ('bond-use-carrier', 'use_carrier'),
                                 ('bond-lacp-rate' , 'lacp_rate'),
                                 ('bond-xmit-hash-policy' , 'xmit_hash_policy'),
                                 ('bond-min-links' , 'min_links'),
                                 ('bond-num-grat-arp' , 'num_grat_arp'),
                                 ('bond-num-unsol-na' , 'num_unsol_na'),
                                 ('bond-ad-sys-mac-addr' , 'ad_actor_system'),
                                 ('bond-ad-actor-system' , 'ad_actor_system'),
                                 ('bond-ad-sys-priority' , 'ad_actor_sys_prio'),
                                 ('bond-ad-actor-sys-prio' , 'ad_actor_sys_prio'),
                                 ('bond-lacp-bypass-allow', 'lacp_bypass'),
                                 ('bond-updelay', 'updelay'),
                                 ('bond-downdelay', 'downdelay')])
        linkup = self.ipcmd.is_link_up(ifaceobj.name)
        try:
            # order of attributes set matters for bond, so
            # construct the list sequentially
            attrstoset = OrderedDict()
            for k, dstk in bondcmd_attrmap.items():
                v = self.fetch_attr(ifaceobj, k)
                if v:
                    attrstoset[dstk] = v
            if not attrstoset:
                return

            # support yes/no attrs
            utils.support_yesno_attrs(attrstoset, ['use_carrier', 'lacp_bypass'])

            have_attrs_to_set = 1
            self.bondcmd.set_attrs(ifaceobj.name, attrstoset,
                    self.ipcmd.link_down if linkup else None)
        except:
            raise
        finally:
            if have_attrs_to_set and linkup:
                netlink.link_set_updown(ifaceobj.name, 'up')
예제 #7
0
    def _add_slaves(self, ifaceobj):
        runningslaves = []

        slaves = self._get_slave_list(ifaceobj)
        if not slaves:
            self.logger.debug('%s: no slaves found' %ifaceobj.name)
            return

        if not ifupdownflags.flags.PERFMODE:
            runningslaves = self.bondcmd.get_slaves(ifaceobj.name);

        clag_bond = self._is_clag_bond(ifaceobj)

        for slave in Set(slaves).difference(Set(runningslaves)):
            if (not ifupdownflags.flags.PERFMODE and
                not self.ipcmd.link_exists(slave)):
                    self.log_error('%s: skipping slave %s, does not exist'
                                   %(ifaceobj.name, slave), ifaceobj,
                                     raise_error=False)
                    continue
            link_up = False
            if self.ipcmd.is_link_up(slave):
                netlink.link_set_updown(slave, "down")
                link_up = True
            # If clag bond place the slave in a protodown state; clagd
            # will protoup it when it is ready
            if clag_bond:
                try:
                    netlink.link_set_protodown(slave, "on")
                except Exception, e:
                    self.logger.error('%s: %s' % (ifaceobj.name, str(e)))
            netlink.link_set_master(slave, ifaceobj.name)
            if link_up or ifaceobj.link_type != ifaceLinkType.LINK_NA:
               try:
                    netlink.link_set_updown(slave, "up")
               except Exception, e:
                    self.logger.debug('%s: %s' % (ifaceobj.name, str(e)))
                    pass
예제 #8
0
 def link_down(self, ifacename):
     netlink.link_set_updown(ifacename, "down")
예제 #9
0
 def link_up(self, ifacename):
     netlink.link_set_updown(ifacename, "up")
예제 #10
0
                try:
                    if self._is_address_virtual_slaves(ifaceobj, config_slaves,
                                                       s):
                        continue
                    sobj = None
                    if ifaceobj_getfunc:
                        sobj = ifaceobj_getfunc(s)
                    self._down_vrf_slave(s, sobj[0] if sobj else None,
                                         ifaceobj.name)
                except Exception, e:
                    self.logger.info('%s: %s' % (ifaceobj.name, str(e)))

        if ifaceobj.link_type == ifaceLinkType.LINK_MASTER:
            for s in config_slaves:
                try:
                    netlink.link_set_updown(s, "up")
                except Exception, e:
                    self.logger.debug('%s: %s' % (ifaceobj.name, str(e)))
                    pass

    def _set_vrf_dev_processed_flag(self, ifaceobj):
        ifaceobj.module_flags[self.name] = \
                             ifaceobj.module_flags.setdefault(self.name, 0) | \
                                        vrfPrivFlags.PROCESSED

    def _check_vrf_dev_processed_flag(self, ifaceobj):
        if (ifaceobj.module_flags.get(self.name, 0) & vrfPrivFlags.PROCESSED):
            return True
        return False

    def _create_vrf_dev(self, ifaceobj, vrf_table):
예제 #11
0
    def _up(self, ifaceobj, ifaceobj_getfunc=None):
        if not self.ipcmd.link_exists(ifaceobj.name):
            return

        alias = ifaceobj.get_attr_value_first('alias')
        current_alias = self.ipcmd.link_get_alias(ifaceobj.name)
        if alias and alias != current_alias:
            self.ipcmd.link_set_alias(ifaceobj.name, alias)
        elif not alias and current_alias:
            self.ipcmd.link_set_alias(ifaceobj.name, '')

        addr_method = ifaceobj.addr_method
        force_reapply = False
        try:
            # release any stale dhcp addresses if present
            if (addr_method not in ["dhcp", "ppp"]
                    and not ifupdownflags.flags.PERFMODE
                    and not (ifaceobj.flags & iface.HAS_SIBLINGS)):
                # if not running in perf mode and ifaceobj does not have
                # any sibling iface objects, kill any stale dhclient
                # processes
                dhclientcmd = dhclient()
                if dhclientcmd.is_running(ifaceobj.name):
                    # release any dhcp leases
                    dhclientcmd.release(ifaceobj.name)
                    force_reapply = True
                elif dhclientcmd.is_running6(ifaceobj.name):
                    dhclientcmd.release6(ifaceobj.name)
                    force_reapply = True
        except:
            pass

        self.ipcmd.batch_start()
        if addr_method not in ["dhcp", "ppp"]:
            self._inet_address_config(ifaceobj, ifaceobj_getfunc,
                                      force_reapply)
        self._process_mtu_config(ifaceobj, ifaceobj_getfunc)

        try:
            self.ipcmd.batch_commit()
        except Exception as e:
            self.log_error('%s: %s' % (ifaceobj.name, str(e)),
                           ifaceobj,
                           raise_error=False)

        try:
            hwaddress = self._get_hwaddress(ifaceobj)
            if hwaddress:
                running_hwaddress = None
                if not ifupdownflags.flags.PERFMODE:  # system is clean
                    running_hwaddress = self.ipcmd.link_get_hwaddress(
                        ifaceobj.name)
                if hwaddress != running_hwaddress:
                    slave_down = False
                    netlink.link_set_updown(ifaceobj.name, "down")
                    if ifaceobj.link_kind & ifaceLinkKind.BOND:
                        # if bond, down all the slaves
                        if ifaceobj.lowerifaces:
                            for l in ifaceobj.lowerifaces:
                                netlink.link_set_updown(l, "down")
                            slave_down = True
                    try:
                        self.ipcmd.link_set(ifaceobj.name, 'address',
                                            hwaddress)
                    finally:
                        netlink.link_set_updown(ifaceobj.name, "up")
                        if slave_down:
                            for l in ifaceobj.lowerifaces:
                                netlink.link_set_updown(l, "up")

            # Handle special things on a bridge
            self._process_bridge(ifaceobj, True)
        except Exception, e:
            self.log_error('%s: %s' % (ifaceobj.name, str(e)), ifaceobj)
예제 #12
0
    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
        macvlan_prefix = self._get_macvlan_prefix(ifaceobj)
        for av in address_virtual_list:
            av_attrs = av.split()
            if len(av_attrs) < 2:
                self.log_error("%s: incorrect address-virtual attrs '%s'" %
                               (ifaceobj.name, av),
                               ifaceobj,
                               raise_error=False)
                av_idx += 1
                continue

            mac = av_attrs[0]
            if not self.check_mac_address(ifaceobj, mac):
                continue
            # Create a macvlan device on this device and set the virtual
            # router mac and ip on it
            link_created = False
            macvlan_ifacename = '%s%d' % (macvlan_prefix, av_idx)
            if not self.ipcmd.link_exists(macvlan_ifacename):
                netlink.link_add_macvlan(ifaceobj.name, macvlan_ifacename)
                link_created = True
            ips = av_attrs[1:]
            if mac != 'None':
                mac = mac.lower()
                # customer could have used UPPERCASE for MAC
                self.ipcmd.link_set_hwaddress(macvlan_ifacename, mac)
                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.name,
                                                              refresh=True)
                    update_mtu = False

                if lower_iface_mtu and lower_iface_mtu != self.ipcmd.link_get_mtu(
                        macvlan_ifacename):
                    try:
                        self.ipcmd.link_set_mtu(macvlan_ifacename,
                                                lower_iface_mtu)
                    except Exception as e:
                        self.logger.info(
                            '%s: failed to set mtu %s: %s' %
                            (macvlan_ifacename, 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_ifacename, "up")

            # 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)
                if self.sysctl_get(syskey) != sysval:
                    self.sysctl_set(syskey, sysval)

            av_idx += 1
        self.ipcmd.batch_commit()

        # 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 hwaddress]
        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, hwaddress)