except Exception as e:
self.log_error('%s: %s' % (ifaceobj.name, str(e)), ifaceobj, raise_error=False)
+ self.up_hwaddress(ifaceobj)
+
+ gateways = ifaceobj.get_attr_value('gateway')
+ if not gateways:
+ gateways = []
+ prev_gw = self._get_prev_gateway(ifaceobj, gateways)
+ self._add_delete_gateway(ifaceobj, gateways, prev_gw)
+
+ def up_hwaddress(self, ifaceobj):
try:
hwaddress = self._get_hwaddress(ifaceobj)
+
if hwaddress:
- running_hwaddress = None
- if not ifupdownflags.flags.PERFMODE: # system is clean
+ if not ifupdownflags.flags.PERFMODE: # system is clean
running_hwaddress = self.ipcmd.link_get_hwaddress(ifaceobj.name)
- if hwaddress != running_hwaddress:
+ else:
+ running_hwaddress = None
+
+ if self.ipcmd.mac_str_to_int(running_hwaddress) != self.ipcmd.mac_str_to_int(hwaddress):
slave_down = False
netlink.link_set_updown(ifaceobj.name, "down")
if ifaceobj.link_kind & ifaceLinkKind.BOND:
netlink.link_set_updown(l, "down")
slave_down = True
try:
- self.ipcmd.link_set(ifaceobj.name, 'address', hwaddress)
+ self.ipcmd.link_set_hwaddress(ifaceobj.name, hwaddress, force=True)
finally:
netlink.link_set_updown(ifaceobj.name, "up")
if slave_down:
# Handle special things on a bridge
self._process_bridge(ifaceobj, True)
except Exception, e:
- self.log_error('%s: %s' %(ifaceobj.name, str(e)), ifaceobj)
-
- gateways = ifaceobj.get_attr_value('gateway')
- if not gateways:
- gateways = []
- prev_gw = self._get_prev_gateway(ifaceobj, gateways)
- self._add_delete_gateway(ifaceobj, gateways, prev_gw)
+ self.log_error('%s: %s' % (ifaceobj.name, str(e)), ifaceobj)
def _down(self, ifaceobj, ifaceobj_getfunc=None):
try:
bridgename = ifaceobj.lowerifaces[0]
vlan = self._get_vlan_id(ifaceobj)
if self.ipcmd.bridge_is_vlan_aware(bridgename):
- fdb_addrs = self._get_bridge_fdbs(bridgename, str(vlan))
- if not fdb_addrs or hwaddress not in fdb_addrs:
- return False
+ fdb_addrs = [self.ipcmd.mac_str_to_int(fdb_addr) for fdb_addr in self._get_bridge_fdbs(bridgename, str(vlan))]
+ if not fdb_addrs:
+ return False
+ hwaddress_int = self.ipcmd.mac_str_to_int(hwaddress)
+ if hwaddress_int not in fdb_addrs:
+ return False
return True
def _query_sysctl(self, ifaceobj, ifaceobjcurr):
hwaddress = self._get_hwaddress(ifaceobj)
if hwaddress:
rhwaddress = self.ipcmd.link_get_hwaddress(ifaceobj.name)
- if not rhwaddress or rhwaddress != hwaddress:
+ if not rhwaddress or self.ipcmd.mac_str_to_int(rhwaddress) != self.ipcmd.mac_str_to_int(hwaddress):
ifaceobjcurr.update_config_with_status('hwaddress', rhwaddress,
1)
elif not self._check_addresses_in_bridge(ifaceobj, hwaddress):
import os
import glob
-from string import maketrans
from collections import deque
from ipaddr import IPNetwork, IPv6Network
)
self.address_virtual_ipv6_addrgen_value_dict = {'on': 0, 'yes': 0, '0': 0, 'off': 1, 'no': 1, '1': 1}
- self.mac_translate_tab = maketrans(":.-,", " ")
def get_dependent_ifacenames(self, ifaceobj, ifacenames_all=None):
if ifaceobj.get_attr_value('address-virtual') or ifaceobj.get_attr_value("vrrp"):
fdb_addrs = self._get_bridge_fdbs(bridgename, str(vlan))
if not fdb_addrs:
return False
- hwaddress_int = self.mac_str_to_int(hwaddress)
+ hwaddress_int = self.ipcmd.mac_str_to_int(hwaddress)
for mac in fdb_addrs:
- if self.mac_str_to_int(mac) == hwaddress_int:
+ if self.ipcmd.mac_str_to_int(mac) == hwaddress_int:
return True
return False
return True
self.ipcmd.link_set(u, 'master', vrfname,
state='up')
- 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, vrrp=False):
"""
intf_config_list = [
if ip4 or ifquery:
merged_with_existing_obj = False
macvlan_ip4_mac = "00:00:5e:00:01:%s" % hex_id
- macvlan_ip4_mac_int = self.mac_str_to_int(macvlan_ip4_mac)
+ macvlan_ip4_mac_int = self.ipcmd.mac_str_to_int(macvlan_ip4_mac)
# 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:
if ip6 or ifquery:
merged_with_existing_obj = False
macvlan_ip6_mac = "00:00:5e:00:02:%s" % hex_id
- macvlan_ip6_mac_int = self.mac_str_to_int(macvlan_ip6_mac)
+ macvlan_ip6_mac_int = self.ipcmd.mac_str_to_int(macvlan_ip6_mac)
# 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:
if mac != "none":
config["hwaddress"] = mac
- config["hwaddress_int"] = self.mac_str_to_int(mac)
+ config["hwaddress_int"] = self.ipcmd.mac_str_to_int(mac)
ip_network_obj_list = []
for ip in av_attrs[1:]:
continue
try:
- if self.mac_str_to_int(rhwaddress) == macvlan_hwaddress_int \
+ if self.ipcmd.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(
# and compare the ints, it will increase perfs and be safer.
cached_value = self.ipcmd.cache_get('link', [ifname, 'hwaddress'])
self.logger.debug('%s: cached hwaddress value: %s' % (ifname, cached_value))
- if cached_value and cached_value == bridge_mac:
+ if cached_value and self.ipcmd.mac_str_to_int(cached_value) == self.ipcmd.mac_str_to_int(bridge_mac):
# the bridge mac is already set to the bridge_mac_intf's mac
return
import socket
import subprocess
+from string import maketrans
from ipaddr import IPNetwork, IPv6Network
try:
DEFAULT_IP_METRIC = 1024
ADDR_METRIC_SUPPORT = None
+ mac_translate_tab = maketrans(":.-,", " ")
+
def __init__(self, *args, **kargs):
utilsBase.__init__(self, *args, **kargs)
LinkUtils.ADDR_METRIC_SUPPORT = False
self.logger.info('address metric support: KO')
+ @classmethod
+ def mac_str_to_int(cls, mac):
+ mac_int = 0
+ if mac:
+ for n in mac.translate(cls.mac_translate_tab).split():
+ mac_int += int(n, 16)
+ return mac_int
+
@classmethod
def addr_metric_support(cls):
return cls.ADDR_METRIC_SUPPORT
def link_set_hwaddress(self, ifacename, hwaddress, force=False):
if not force:
- if self._cache_check('link', [ifacename, 'hwaddress'], hwaddress):
- return
+ link_hwaddress = self.link_get_hwaddress(ifacename)
+
+ if self.mac_str_to_int(link_hwaddress) == self.mac_str_to_int(hwaddress):
+ return False
+
self.link_down(ifacename)
cmd = 'link set dev %s address %s' % (ifacename, hwaddress)
if LinkUtils.ipbatch:
utils.exec_command('%s %s' % (utils.ip_cmd, cmd))
self.link_up(ifacename)
self._cache_update([ifacename, 'hwaddress'], hwaddress)
+ return True
def link_set_mtu(self, ifacename, mtu):
if ifupdownflags.flags.DRYRUN: