]> git.proxmox.com Git - mirror_ifupdown2.git/blobdiff - ifupdown2/ifupdownaddons/LinkUtils.py
LinkUtils: tunnel_change: do not purge the cache on tunnel change
[mirror_ifupdown2.git] / ifupdown2 / ifupdownaddons / LinkUtils.py
index ab1dd6e6d4b1e36d550d56401569bd21f2679958..d05c0103535e2fdd61b9de72712498d8e0493b3d 100644 (file)
@@ -545,6 +545,8 @@ class LinkUtils(utilsBase):
                                 tunattrs['ttl'] = citems[j + 1]
                             elif citems[j] == 'dev':
                                 tunattrs['physdev'] = citems[j + 1]
+                            elif citems[j] in ['vti', 'vti6', 'ip6gre', 'ipip6', 'ip6ip6']:
+                                tunattrs['mode'] = citems[j]
                         linkattrs['linkinfo'] = tunattrs
                         break
                     elif citems[i] == 'link/ppp':
@@ -1113,7 +1115,7 @@ class LinkUtils(utilsBase):
         return self._cache_get('link', [ifacename, 'ifflag'], refresh=True)
 
     @staticmethod
-    def route_add_gateway(ifacename, gateway, vrf=None, metric=None):
+    def route_add_gateway(ifacename, gateway, vrf=None, metric=None, onlink=True):
         if not gateway:
             return
         if not vrf:
@@ -1126,6 +1128,10 @@ class LinkUtils(utilsBase):
         if metric:
             cmd += 'metric %s' % metric
         cmd += ' dev %s' % ifacename
+
+        if onlink:
+            cmd += " onlink"
+
         utils.exec_command(cmd)
 
     @staticmethod
@@ -1266,13 +1272,16 @@ class LinkUtils(utilsBase):
         if '6' in mode:
             cmd = ' -6 '
 
-        cmd += 'tunnel add'
-        cmd += ' %s mode %s' %(tunnelname, mode)
+        if mode in ['gretap']:
+            cmd += 'link add %s type %s' % (tunnelname, mode)
+        else:
+            cmd += 'tunnel add %s mode %s' % (tunnelname, mode)
+
         if attrs:
             for k, v in attrs.iteritems():
-                cmd += ' %s' %k
+                cmd += ' %s' % k
                 if v:
-                    cmd += ' %s' %v
+                    cmd += ' %s' % v
         if self.ipbatch and not self.ipbatch_pause:
             self.add_to_batch(cmd)
         else:
@@ -1294,7 +1303,6 @@ class LinkUtils(utilsBase):
             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,
@@ -1543,11 +1551,40 @@ class LinkUtils(utilsBase):
 
         if not bridgeout: return brvlaninfo
         try:
-            vlan_json_dict = json.loads(bridgeout, encoding="utf-8")
+            vlan_json = json.loads(bridgeout, encoding="utf-8")
         except Exception, e:
             self.logger.info('json loads failed with (%s)' % str(e))
             return {}
-        return vlan_json_dict
+
+        try:
+            if isinstance(vlan_json, list):
+                # newer iproute2 version changed the bridge vlan show output
+                # ifupdown2 relies on the previous format, we have the convert
+                # data into old format
+                bridge_port_vids = dict()
+
+                for intf in vlan_json:
+                    bridge_port_vids[intf["ifname"]] = intf["vlans"]
+
+                return bridge_port_vids
+            else:
+                # older iproute2 version have different ways to dump vlans
+                # ifupdown2 prefers the following syntax:
+                # {
+                #    "vx-1002": [{
+                #        "vlan": 1002,
+                #        "flags": ["PVID", "Egress Untagged"]
+                #    }
+                #    ],
+                #    "vx-1004": [{
+                #        "vlan": 1004,
+                #        "flags": ["PVID", "Egress Untagged"]
+                #    }]
+                # }
+                return vlan_json
+        except Exception as e:
+            self.logger.debug("bridge vlan show: Unknown json output: %s" % str(e))
+            return vlan_json
 
     @staticmethod
     def get_bridge_vlan_nojson():