]> git.proxmox.com Git - mirror_ifupdown2.git/commitdiff
addons: vxlan: add support for vxlan-ttl attribute
authorJulien Fortin <julien@cumulusnetworks.com>
Fri, 25 Jan 2019 10:06:39 +0000 (18:06 +0800)
committerJulien Fortin <julien@cumulusnetworks.com>
Mon, 22 Apr 2019 02:48:36 +0000 (10:48 +0800)
New vxlan-ttl attribute: specifies the TTL value to use in outgoing
packets. Valid values: range 1..255 or auto (0)

Signed-off-by: Julien Fortin <julien@cumulusnetworks.com>
debian/changelog
ifupdown2/addons/vxlan.py
ifupdown2/ifupdown/netlink.py
ifupdown2/ifupdownaddons/LinkUtils.py
ifupdown2/nlmanager/nlmanager.py

index 49625acad5be90299907bf7443d01b71793f3cae..928fa90552a315a49ac976bc61673eae46cff36d 100644 (file)
@@ -1,3 +1,9 @@
+ifupdown2 (1.2.6-1) unstable; urgency=medium
+
+  * New: add support for vxlan-ttl attribute
+
+ -- Julien Fortin <julien@cumulusnetworks.com>  Mon, 21 Jan 2019 23:42:43 +8000
+
 ifupdown2 (1.2.5-1) unstable; urgency=medium
 
   * Fix: ifupdown2 scripts: log warning on EACCES exception (Fixes #89)
index 87e6b9de50d4637e7c9bd42d94dcd6827abeb1f6..5f409c8cd0f899a911b65eaf136b9fb48b557ab1 100644 (file)
@@ -79,7 +79,11 @@ class vxlan(moduleBase):
                     'vxlan-physdev':
                         {'help': 'vxlan physical device',
                          'example': ['vxlan-physdev eth1']},
-
+                    "vxlan-ttl": {
+                        "help": "specifies the TTL value to use in outgoing packets (range 1..255)",
+                        "validvals": ['<number>', 'auto'],
+                        "example": ['vxlan-ttl 42'],
+                    }
                 }}
     _clagd_vxlan_anycast_ip = ""
     _vxlan_local_tunnelip = None
@@ -158,7 +162,7 @@ class vxlan(moduleBase):
             purge_remotes = self._purge_remotes
         return purge_remotes
 
-    def should_create_set_vxlan(self, link_exists, ifname, vxlan_id, local, learning, ageing, group):
+    def should_create_set_vxlan(self, link_exists, ifname, vxlan_id, local, learning, ageing, group, ttl):
         """
             should we issue a netlink: ip link add dev %ifname type vxlan ...?
             checking each attribute against the cache
@@ -172,6 +176,9 @@ class vxlan(moduleBase):
         except:
             pass
 
+        if ttl is not None and not self.ipcmd.cache_check((ifname, 'linkinfo', Link.IFLA_VXLAN_TTL), ttl):
+                return True
+
         for attr_list, value in (
             ((ifname, 'linkinfo', Link.IFLA_VXLAN_ID), vxlan_id),
             ((ifname, 'linkinfo', Link.IFLA_VXLAN_AGEING), ageing),
@@ -183,6 +190,15 @@ class vxlan(moduleBase):
                 return True
         return False
 
+    def get_vxlan_ttl_from_string(self, ttl_config):
+        ttl = 0
+        if ttl_config:
+            if ttl_config.lower() == "auto":
+                ttl = 0
+            else:
+                ttl = int(ttl_config)
+        return ttl
+
     def _vxlan_create(self, ifaceobj):
         vxlanid = ifaceobj.get_attr_value_first('vxlan-id')
         if vxlanid:
@@ -194,6 +210,21 @@ class vxlan(moduleBase):
             if not local and vxlan._vxlan_local_tunnelip:
                 local = vxlan._vxlan_local_tunnelip
 
+            ttl_config = ifaceobj.get_attr_value_first('vxlan-ttl')
+            try:
+                if ttl_config:
+                    ttl = self.get_vxlan_ttl_from_string(ttl_config)
+                else:
+                    ttl = self.get_vxlan_ttl_from_string(
+                        policymanager.policymanager_api.get_attr_default(
+                            module_name=self.__class__.__name__,
+                            attr='vxlan-ttl'
+                        )
+                    )
+            except:
+                self.log_error('%s: invalid vxlan-ttl \'%s\'' % (ifname, ttl_config), ifaceobj)
+                return
+
             self.syntax_check_localip_anycastip_equal(ifname, local, anycastip)
             # if both local-ip and anycast-ip are identical the function prints a warning
 
@@ -309,7 +340,7 @@ class vxlan(moduleBase):
                                         % (ifname, cache_port, ifname, ifname))
                     vxlan_port = cache_port
 
-            if self.should_create_set_vxlan(link_exists, ifname, vxlanid, local, learning, ageing, group):
+            if self.should_create_set_vxlan(link_exists, ifname, vxlanid, local, learning, ageing, group, ttl):
                 try:
                     netlink.link_add_vxlan(ifname, vxlanid,
                                            local=local,
@@ -317,7 +348,8 @@ class vxlan(moduleBase):
                                            ageing=ageing,
                                            group=group,
                                            dstport=vxlan_port,
-                                           physdev=physdev)
+                                           physdev=physdev,
+                                           ttl=ttl)
                 except Exception as e_netlink:
                     self.logger.debug('%s: vxlan netlink: %s' % (ifname, str(e_netlink)))
                     try:
@@ -326,7 +358,8 @@ class vxlan(moduleBase):
                                                      svcnodeip=group,
                                                      remoteips=ifaceobj.get_attr_value('vxlan-remoteip'),
                                                      learning='on' if learning else 'off',
-                                                     ageing=ageing)
+                                                     ageing=ageing,
+                                                     ttl=ttl)
                     except Exception as e_iproute2:
                         self.logger.warning('%s: vxlan add/set failed: %s' % (ifname, str(e_iproute2)))
                         return
index 4152c0284ca58b227c961e1c4f9966a25a0141f8..65dacdde87c16ccfbd64c6754656a66d91ec8d12 100644 (file)
@@ -273,7 +273,7 @@ class Netlink(utilsBase):
                             % (ifacename, vlanid, str(e)))
 
     def link_add_vxlan(self, ifacename, vxlanid, local=None, dstport=VXLAN_UDP_PORT,
-                       group=None, learning=True, ageing=None, physdev=None):
+                       group=None, learning=True, ageing=None, physdev=None, ttl=None):
         cmd = 'ip link add %s type vxlan id %s dstport %s' % (ifacename,
                                                               vxlanid,
                                                               dstport)
@@ -282,6 +282,10 @@ class Netlink(utilsBase):
         cmd += ' remote %s' % group if group else ' noremote'
         cmd += ' nolearning' if not learning else ''
         cmd += ' dev %s' % physdev if physdev else ''
+
+        if ttl is not None:
+            cmd += ' ttl %s' % ttl
+
         self.logger.info('%s: netlink: %s' % (ifacename, cmd))
         if ifupdownflags.flags.DRYRUN: return
         try:
@@ -294,7 +298,8 @@ class Netlink(utilsBase):
                                                       group=group,
                                                       learning=learning,
                                                       ageing=ageing,
-                                                      physdev=physdev)
+                                                      physdev=physdev,
+                                                      ttl=ttl)
         except Exception as e:
             raise Exception('netlink: %s: cannot create vxlan %s: %s'
                             % (ifacename, vxlanid, str(e)))
index 509e827bce86e22eeb5e94bd9bbebf726fb20f44..7abc1df50632ac17a87315fb93b4e5774b264cd3 100644 (file)
@@ -1311,7 +1311,8 @@ class LinkUtils(utilsBase):
                           remoteips=None,
                           learning='on',
                           ageing=None,
-                          anycastip=None):
+                          anycastip=None,
+                          ttl=None):
         if svcnodeip and remoteips:
             raise Exception("svcnodeip and remoteip is mutually exclusive")
         args = ''
@@ -1321,6 +1322,8 @@ class LinkUtils(utilsBase):
             args += ' ageing %s' % ageing
         if learning == 'off':
             args += ' nolearning'
+        if ttl is not None:
+            args += ' ttl %s' % ttl
 
         if self.link_exists(name):
             cmd = 'link set dev %s type vxlan dstport %d' % (name, LinkUtils.VXLAN_UDP_PORT)
index cb4962cfa9a2f56b4887d26e1b4c39ec6052cae9..52f9f62ce6f9c09c2fc834f654fc2e1ff5fb2015 100644 (file)
@@ -964,7 +964,7 @@ class NetlinkManager(object):
         return self.tx_nlpacket_get_response(nbr)
 
     def link_add_vxlan(self, ifname, vxlanid, dstport=None, local=None,
-                       group=None, learning=True, ageing=None, physdev=None):
+                       group=None, learning=True, ageing=None, physdev=None, ttl=None):
 
         debug = RTM_NEWLINK in self.debug
 
@@ -977,6 +977,7 @@ class NetlinkManager(object):
             info_data[Link.IFLA_VXLAN_GROUP] = group
 
         info_data[Link.IFLA_VXLAN_LEARNING] = int(learning)
+        info_data[Link.IFLA_VXLAN_TTL] = ttl
 
         if ageing:
             info_data[Link.IFLA_VXLAN_AGEING] = int(ageing)