diff --git a/addons/tunnel.py b/addons/tunnel.py index 56182e4..caf11c1 100644 --- a/addons/tunnel.py +++ b/addons/tunnel.py @@ -7,6 +7,7 @@ from ifupdown.iface import * from ifupdownaddons.modulebase import moduleBase from ifupdownaddons.iproute2 import iproute2 +from ifupdown.netlink import netlink import ifupdown.ifupdownflags as ifupdownflags import logging @@ -18,7 +19,7 @@ class tunnel (moduleBase): 'attrs' : { 'mode' : { 'help' : 'type of tunnel as in \'ip link\' command.', - 'validvals' : ['gre', 'gretap', 'ipip', 'sit'], + 'validvals' : ['gre', 'gretap', 'ipip', 'sit', 'vti', 'ip6gre', 'ipip6', 'ip6ip6', 'vti6'], 'required' : True, 'example' : ['mode gre']}, 'local' : @@ -55,6 +56,17 @@ class tunnel (moduleBase): return True return False + 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') def _up (self, ifaceobj): attr_map = { @@ -75,7 +87,11 @@ class tunnel (moduleBase): if attr_val != None: attrs[iproute_attr] = attr_val - self.ipcmd.link_create (ifaceobj.name, mode, attrs) + if not self.ipcmd.link_exists(ifaceobj.name): + self.ipcmd.tunnel_create (ifaceobj.name, mode, attrs) + else: + attrs['mode'] = mode + self._check_settings(ifaceobj, attrs) def _down (self, ifaceobj): diff --git a/ifupdownaddons/iproute2.py b/ifupdownaddons/iproute2.py index d4b2b11..2f54362 100644 --- a/ifupdownaddons/iproute2.py +++ b/ifupdownaddons/iproute2.py @@ -103,7 +103,7 @@ class iproute2(utilsBase): linkattrs['state'] = citems[i + 1] elif citems[i] == 'link/ether': linkattrs['hwaddress'] = citems[i + 1] - elif citems[i] in [ 'link/gre', 'link/sit', 'gretap' ]: + elif citems[i] in [ 'link/gre', 'link/ipip', 'link/sit', 'link/gre6', 'link/tunnel6', 'gretap' ]: linkattrs['kind'] = 'tunnel' tunattrs = {'mode' : citems[i].split ('/')[-1], 'endpoint' : None, @@ -757,6 +757,40 @@ class iproute2(utilsBase): else: return self._cache_get('link', [ifacename, 'master']) + def tunnel_create(self, tunnelname, mode, attrs={}): + """ generic link_create function """ + if self.link_exists(tunnelname): + return + cmd = 'tunnel add' + cmd += ' %s mode %s' %(ifacename, mode) + if attrs: + for k, v in attrs.iteritems(): + cmd += ' %s' %k + if v: + cmd += ' %s' %v + if self.ipbatch and not self.ipbatch_pause: + self.add_to_batch(cmd) + else: + utils.exec_command('ip %s' % cmd) + self._cache_update([tunnelname], {}) + + def tunnel_change(self, tunnelname, attrs={}): + """ tunnel change function """ + if not self.link_exists(tunnelname): + return + cmd = 'tunnel change' + cmd += ' %s' %(tunnelname) + if attrs: + for k, v in attrs.iteritems(): + cmd += ' %s' %k + if v: + cmd += ' %s' %v + if self.ipbatch and not self.ipbatch_pause: + self.add_to_batch(cmd) + else: + utils.exec_command('ip %s' % cmd) + self._cache_update([tunnelname], {}) + def bridge_port_vids_add(self, bridgeportname, vids): [utils.exec_command('bridge vlan add vid %s dev %s' % (v, bridgeportname)) for v in vids]