From: Julien Fortin Date: Fri, 25 Jan 2019 10:06:39 +0000 (+0800) Subject: addons: vxlan: add support for vxlan-ttl attribute X-Git-Tag: 1.2.8-1~39 X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=ec25a08c3a114e5c7a9771d6379bcd02d4addaf1;p=mirror_ifupdown2.git addons: vxlan: add support for vxlan-ttl attribute 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 --- diff --git a/debian/changelog b/debian/changelog index 49625ac..928fa90 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +ifupdown2 (1.2.6-1) unstable; urgency=medium + + * New: add support for vxlan-ttl attribute + + -- Julien Fortin 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) diff --git a/ifupdown2/addons/vxlan.py b/ifupdown2/addons/vxlan.py index 87e6b9d..5f409c8 100644 --- a/ifupdown2/addons/vxlan.py +++ b/ifupdown2/addons/vxlan.py @@ -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": ['', '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 diff --git a/ifupdown2/ifupdown/netlink.py b/ifupdown2/ifupdown/netlink.py index 4152c02..65dacdd 100644 --- a/ifupdown2/ifupdown/netlink.py +++ b/ifupdown2/ifupdown/netlink.py @@ -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))) diff --git a/ifupdown2/ifupdownaddons/LinkUtils.py b/ifupdown2/ifupdownaddons/LinkUtils.py index 509e827..7abc1df 100644 --- a/ifupdown2/ifupdownaddons/LinkUtils.py +++ b/ifupdown2/ifupdownaddons/LinkUtils.py @@ -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) diff --git a/ifupdown2/nlmanager/nlmanager.py b/ifupdown2/nlmanager/nlmanager.py index cb4962c..52f9f62 100644 --- a/ifupdown2/nlmanager/nlmanager.py +++ b/ifupdown2/nlmanager/nlmanager.py @@ -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)