]> git.proxmox.com Git - mirror_ifupdown2.git/commitdiff
addons: tunnel: add support for vti, ip6gre, ipip6, ip6ip6, vti6 tunnels
authorSven Auhagen <Sven.Auhagen@voleatech.de>
Wed, 4 Apr 2018 17:49:34 +0000 (19:49 +0200)
committerJulien Fortin <julien@cumulusnetworks.com>
Tue, 26 Jun 2018 20:29:19 +0000 (23:29 +0300)
ifupdown2/addons/tunnel.py
ifupdown2/ifupdownaddons/LinkUtils.py

index 56182e44e3c0c109ab6a9b8167284f225b0ed191..caf11c1d3f546931a450bdc2dd52bc79458f8804 100644 (file)
@@ -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):
index 70f1255f38a00f91a89621e42adc5735ce1de9db..58bba508c53108b34aa5f9775366a4184998e9b1 100644 (file)
@@ -528,7 +528,7 @@ class LinkUtils(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,
@@ -1254,6 +1254,40 @@ class LinkUtils(utilsBase):
 
         return cur_peers
 
+    def tunnel_create(self, tunnelname, mode, attrs={}):
+        """ generic link_create function """
+        if self.link_exists(tunnelname):
+            return
+        cmd = 'tunnel add'
+        cmd += ' %s mode %s' %(tunnelname, 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 link_create_vxlan(self, name, vxlanid,
                           localtunnelip=None,
                           svcnodeip=None,