]> git.proxmox.com Git - mirror_ifupdown2.git/blobdiff - addons/bridge.py
ifupdown2 loses interfaces on second down of swp port
[mirror_ifupdown2.git] / addons / bridge.py
index 9d317bc3d100ce885e37ff0c770c35e2502bee70..8ce7fd1bba4b9eb4d196077b655eb62ab7b492e5 100644 (file)
@@ -15,6 +15,9 @@ import itertools
 import re
 import time
 
+class bridgeFlags:
+    PORT_PROCESSED = 0x1
+
 class bridge(moduleBase):
     """  ifupdown2 addon module to configure linux bridges """
 
@@ -190,14 +193,10 @@ class bridge(moduleBase):
                           'example' : ['bridge-port-pvids bond0=100 bond1=200']},
                      }}
 
-    # declare some ifaceobj priv_flags.
-    # XXX: This assumes that the priv_flags is owned by this module
-    # which it is not.
-    _BRIDGE_PORT_PROCESSED = 0x1
-
     def __init__(self, *args, **kargs):
         moduleBase.__init__(self, *args, **kargs)
         self.ipcmd = None
+        self.name = self.__class__.__name__
         self.brctlcmd = None
         self._running_vidinfo = {}
         self._running_vidinfo_valid = False
@@ -221,6 +220,7 @@ class bridge(moduleBase):
         if ifaceobj.link_type != ifaceLinkType.LINK_NA:
            ifaceobj.link_type = ifaceLinkType.LINK_MASTER
         ifaceobj.link_kind = ifaceLinkKind.BRIDGE
+        ifaceobj.dependency_type = ifaceDependencyType.MASTER_SLAVE
         return self.parse_port_list(ifaceobj.get_attr_value_first(
                                     'bridge-ports'), ifacenames_all)
 
@@ -282,7 +282,7 @@ class bridge(moduleBase):
                 self.write_file('/proc/sys/net/ipv6/conf/%s' %p +
                                 '/disable_ipv6', enable)
             except Exception, e:
-                self.logger.warn(str(e))
+                self.logger.info(str(e))
                 pass
 
     def _add_ports(self, ifaceobj):
@@ -314,6 +314,12 @@ class bridge(moduleBase):
                                    %(ifaceobj.name, bridgeport))
                     err += 1
                     continue
+                hwaddress = self.ipcmd.link_get_hwaddress(bridgeport)
+                if not self._valid_ethaddr(hwaddress):
+                    self.log_warn('%s: skipping port %s, ' %(ifaceobj.name,
+                                  bridgeport) + 'invalid ether addr %s'
+                                  %hwaddress)
+                    continue
                 self.ipcmd.link_set(bridgeport, 'master', ifaceobj.name)
                 self.ipcmd.addr_flush(bridgeport)
             except Exception, e:
@@ -326,7 +332,7 @@ class bridge(moduleBase):
             pass
 
         # enable ipv6 for ports that were removed
-        self._ports_enable_disable_ipv6(removedbridgeports, '1')
+        self._ports_enable_disable_ipv6(removedbridgeports, '0')
         if err:
             self.log_error('bridge configuration failed (missing ports)')
 
@@ -781,7 +787,8 @@ class bridge(moduleBase):
                continue
             for bportifaceobj in bportifaceobjlist:
                 # Dont process bridge port if it already has been processed
-                if bportifaceobj.priv_flags & self._BRIDGE_PORT_PROCESSED:
+                if (bportifaceobj.module_flags.get(self.name,0x0) & \
+                    bridgeFlags.PORT_PROCESSED):
                     continue
                 try:
                     # Add attributes specific to the vlan aware bridge
@@ -810,7 +817,8 @@ class bridge(moduleBase):
                                                               bridge_vids,
                                                               bridge_pvid)
            self._apply_bridge_port_settings(ifaceobj, bridgename=bridgename)
-           ifaceobj.priv_flags |= self._BRIDGE_PORT_PROCESSED
+           ifaceobj.module_flags[self.name] = ifaceobj.module_flags.setdefault(self.name,0) | \
+                                              bridgeFlags.PORT_PROCESSED
            return
         if not self._is_bridge(ifaceobj):
             return
@@ -844,7 +852,7 @@ class bridge(moduleBase):
             if not running_ports:
                return
             # disable ipv6 for ports that were added to bridge
-            self._ports_enable_disable_ipv6(running_ports, '0')
+            self._ports_enable_disable_ipv6(running_ports, '1')
             self._apply_bridge_port_settings_all(ifaceobj,
                             ifaceobj_getfunc=ifaceobj_getfunc)
         except Exception, e:
@@ -854,8 +862,14 @@ class bridge(moduleBase):
             #self._flush_running_vidinfo()
         finally:
             if ifaceobj.link_type != ifaceLinkType.LINK_NA:
-                [rtnetlink_api.rtnl_api.link_set(p, "up")
-                                    for p in running_ports]
+                for p in running_ports:
+                    try:
+                        rtnetlink_api.rtnl_api.link_set(p, "up")
+                    except Exception, e:
+                        self.logger.debug('%s: %s: link set up (%s)'
+                                          %(ifaceobj.name, p, str(e)))
+                        pass
+
             if ifaceobj.addr_method == 'manual':
                rtnetlink_api.rtnl_api.link_set(ifaceobj.name, "up")
         if err:
@@ -867,12 +881,10 @@ class bridge(moduleBase):
                 ports = self.brctlcmd.get_bridge_ports(ifaceobj.name)
                 self.brctlcmd.delete_bridge(ifaceobj.name)
                 if ports:
-                    for p in ports:
-                        proc_file = ('/proc/sys/net/ipv6/conf/%s' %p +
-                                     '/disable_ipv6')
-                        self.write_file(proc_file, '0')
-                        if ifaceobj.link_type != ifaceLinkType.LINK_NA:
-                           rtnetlink_api.rtnl_api.link_set(p, "down")
+                    self._ports_enable_disable_ipv6(ports, '0')
+                    if ifaceobj.link_type != ifaceLinkType.LINK_NA:
+                        map(lambda p: rtnetlink_api.rtnl_api.link_set(p,
+                                    "down"), ports)
         except Exception, e:
             self.log_error(str(e))