Commit 93f5a398 authored by Martín Ferrari's avatar Martín Ferrari

Link: Fix destroy issues. Propagate up and mtu changes to slave interfaces

parent 86079c84
# vim:ts=4:sw=4:et:ai:sts=4 # vim:ts=4:sw=4:et:ai:sts=4
import os import os, weakref
import netns.iproute import netns.iproute
__all__ = ['NodeInterface', 'P2PInterface', 'ForeignInterface', __all__ = ['NodeInterface', 'P2PInterface', 'ForeignInterface',
...@@ -275,10 +275,9 @@ class ForeignInterface(ExternalInterface): ...@@ -275,10 +275,9 @@ class ForeignInterface(ExternalInterface):
# FIXME: register somewhere for destruction! # FIXME: register somewhere for destruction!
def destroy(self): # override: restore as much as possible def destroy(self): # override: restore as much as possible
if self._slave: if self._original_state:
if self.index in self._slave.get_if_data(): netns.iproute.set_if(self._original_state)
netns.iproute.set_if(self._original_state) self._original_state = None
self._slave = None
# Link is just another interface type # Link is just another interface type
...@@ -295,7 +294,7 @@ class Link(ExternalInterface): ...@@ -295,7 +294,7 @@ class Link(ExternalInterface):
iface = netns.iproute.create_bridge(self._gen_br_name()) iface = netns.iproute.create_bridge(self._gen_br_name())
super(Link, self).__init__(iface.index) super(Link, self).__init__(iface.index)
self._ports = set() self._ports = weakref.WeakValueDictionary()
# FIXME: is this correct/desirable/etc? # FIXME: is this correct/desirable/etc?
self.stp = False self.stp = False
self.forward_delay = 0 self.forward_delay = 0
...@@ -309,33 +308,42 @@ class Link(ExternalInterface): ...@@ -309,33 +308,42 @@ class Link(ExternalInterface):
if name[0] == '_': # forbid anything that doesn't start with a _ if name[0] == '_': # forbid anything that doesn't start with a _
super(Link, self).__setattr__(name, value) super(Link, self).__setattr__(name, value)
return return
# Set ports
if name in ('up', 'mtu'):
for i in self._ports.values():
setattr(i, name, value)
# Set bridge
iface = netns.iproute.bridge(index = self.index) iface = netns.iproute.bridge(index = self.index)
setattr(iface, name, value) setattr(iface, name, value)
return netns.iproute.set_bridge(iface) netns.iproute.set_bridge(iface)
def __del__(self): def __del__(self):
self.destroy() self.destroy()
def destroy(self): def destroy(self):
for p in self._ports: if not self.index:
return
self.up = False
for p in self._ports.values():
try: try:
self.disconnect(p) self.disconnect(p)
except: except:
pass pass
self.up = False self._ports.clear()
netns.iproute.del_bridge(self.index) netns.iproute.del_bridge(self.index)
self._idx = None
def connect(self, iface): def connect(self, iface):
assert iface.control.index not in self._ports assert iface.control.index not in self._ports
netns.iproute.add_bridge_port(self.index, iface.control.index) netns.iproute.add_bridge_port(self.index, iface.control.index)
# FIXME: up/down, mtu, etc should be automatically propagated? # FIXME: up/down, mtu, etc should be automatically propagated?
iface.control.up = True iface.control.up = True
self._ports.add(iface.control.index) self._ports[iface.control.index] = iface.control
def disconnect(self, iface): def disconnect(self, iface):
assert iface.control.index in self._ports assert iface.control.index in self._ports
netns.iproute.del_bridge_port(self.index, iface.control.index) netns.iproute.del_bridge_port(self.index, iface.control.index)
self._ports.remove(iface.control.index) del self._ports[iface.control.index]
# don't look after this :-) # don't look after this :-)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment