]> git.proxmox.com Git - mirror_ifupdown2.git/commitdiff
backport: "Add support for setting phys-dev for VXLAN interfaces."
authorJulien Fortin <julien@cumulusnetworks.com>
Mon, 18 Jun 2018 12:19:14 +0000 (14:19 +0200)
committerJulien Fortin <julien@cumulusnetworks.com>
Thu, 13 Dec 2018 22:42:35 +0000 (14:42 -0800)
backporting the following commit to master-next:

commit eb92e5efff776602081b8bbd2cc74462293c4b79
Author: Maximilian Wilhelm <max@rfc2324.org>
Date:   Thu Oct 6 19:22:06 2016 +0200

    Add support for setting phys-dev for VXLAN interfaces.

      Add interface configuration option »vxlan-physdev« to set »dev« attribute
            of VXLAN interfaces and a check for the running configuration.

Signed-off-by: Maximilian Wilhelm <max@rfc2324.org>
This backport also:
 - adds support for ifquery --running
 - uses the netlink cache
 - includes some pep8 fixes

Signed-off-by: Julien Fortin <julien@cumulusnetworks.com>
Signed-off-by: Maximilian Wilhelm <max@rfc2324.org>
Co-authored-by: Julien Fortin <julien@cumulusnetworks.com>
Co-authored-by: Maximilian Wilhelm <max@rfc2324.org>
ifupdown2/addons/vxlan.py
ifupdown2/ifupdown/netlink.py
ifupdown2/ifupdownaddons/LinkUtils.py
ifupdown2/nlmanager/nlmanager.py

index 3148e446e39ab2388e0b3925e40c58eedbc9fcdc..9fce1e14107fb9bfe2fb989a36cda07d2820984b 100644 (file)
@@ -74,7 +74,11 @@ class vxlan(moduleBase):
                         'example': 'vxlan-port 4789',
                         'validrange': ['1', '65536'],
                         'default': '4789',
-                    }
+                    },
+                    'vxlan-physdev':
+                        {'help': 'vxlan physical device',
+                         'example': ['vxlan-physdev eth1']},
+
                 }}
     _clagd_vxlan_anycast_ip = ""
     _vxlan_local_tunnelip = None
@@ -123,6 +127,14 @@ class vxlan(moduleBase):
                 vxlan._clagd_vxlan_anycast_ip = clagd_vxlan_list[0]
 
             self._set_global_local_ip(ifaceobj)
+
+        # If we should use a specific underlay device for the VXLAN
+        # tunnel make sure this device is set up before the VXLAN iface.
+        physdev = ifaceobj.get_attr_value_first('vxlan-physdev')
+
+        if physdev:
+            return [physdev]
+
         return None
 
     def _set_global_local_ip(self, ifaceobj):
@@ -186,6 +198,7 @@ class vxlan(moduleBase):
 
             ageing = ifaceobj.get_attr_value_first('vxlan-ageing')
             vxlan_port = ifaceobj.get_attr_value_first('vxlan-port')
+            physdev = ifaceobj.get_attr_value_first('vxlan-physdev')
             purge_remotes = self._get_purge_remotes(ifaceobj)
 
             link_exists = self.ipcmd.link_exists(ifname)
@@ -291,7 +304,8 @@ class vxlan(moduleBase):
                                            learning=learning,
                                            ageing=ageing,
                                            group=group,
-                                           dstport=vxlan_port)
+                                           dstport=vxlan_port,
+                                           physdev=physdev)
                 except Exception as e_netlink:
                     self.logger.debug('%s: vxlan netlink: %s' % (ifname, str(e_netlink)))
                     try:
@@ -463,6 +477,23 @@ class vxlan(moduleBase):
         self._query_check_n_update(ifaceobj, ifaceobjcurr, 'vxlan-ageing',
                        ageing, vxlanattrs.get('ageing'))
 
+        physdev = ifaceobj.get_attr_value_first('vxlan-physdev')
+
+        if physdev:
+            ifla_vxlan_link = vxlanattrs.get(Link.IFLA_VXLAN_LINK)
+
+            if ifla_vxlan_link:
+                self._query_check_n_update(
+                    ifaceobj,
+                    ifaceobjcurr,
+                    'vxlan-physdev',
+                    physdev,
+                    netlink.get_iface_name(ifla_vxlan_link)
+                )
+            else:
+                ifaceobjcurr.update_config_with_status('vxlan-physdev', physdev, 1)
+
+
     def _query_running(self, ifaceobjrunning):
         vxlanattrs = self.ipcmd.get_vxlandev_attrs(ifaceobjrunning.name)
         if not vxlanattrs:
@@ -497,6 +528,13 @@ class vxlan(moduleBase):
         if attrval:
             ifaceobjrunning.update_config('vxlan-ageing', vxlanattrs.get('ageing'))
 
+        ifla_vxlan_link = vxlanattrs.get(Link.IFLA_VXLAN_LINK)
+        if ifla_vxlan_link:
+            ifaceobjrunning.update_config(
+                'vxlan-physdev',
+                netlink.get_iface_name(ifla_vxlan_link)
+            )
+
     _run_ops = {'pre-up' : _up,
                'post-down' : _down,
                'query-checkcurr' : _query_check,
index 6a29902625cfa6a7e335f4849b79f71539368b0d..65ce356039cc6057ddccf89d4b5ef1e00e514990 100644 (file)
@@ -263,7 +263,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):
+                       group=None, learning=True, ageing=None, physdev=None):
         cmd = 'ip link add %s type vxlan id %s dstport %s' % (ifacename,
                                                               vxlanid,
                                                               dstport)
@@ -271,16 +271,20 @@ class Netlink(utilsBase):
         cmd += ' ageing %s' % ageing if ageing else ''
         cmd += ' remote %s' % group if group else ' noremote'
         cmd += ' nolearning' if not learning else ''
+        cmd += ' dev %s' % physdev if physdev else ''
         self.logger.info('%s: netlink: %s' % (ifacename, cmd))
         if ifupdownflags.flags.DRYRUN: return
         try:
+            if physdev:
+                physdev = self.get_iface_index(physdev)
             return self._nlmanager_api.link_add_vxlan(ifacename,
                                                       vxlanid,
                                                       dstport=dstport,
                                                       local=local,
                                                       group=group,
                                                       learning=learning,
-                                                      ageing=ageing)
+                                                      ageing=ageing,
+                                                      physdev=physdev)
         except Exception as e:
             raise Exception('netlink: %s: cannot create vxlan %s: %s'
                             % (ifacename, vxlanid, str(e)))
index a15ba774e5f487434eb42853cafd207c2c6a0e37..feb513cba2faf3c5a22be45a9c7aa2280a054735 100644 (file)
@@ -551,6 +551,8 @@ class LinkUtils(utilsBase):
                                 vattrs['ageing'] = citems[j + 1]
                             elif citems[j] == 'nolearning':
                                 vattrs['learning'] = 'off'
+                            elif citems[j] == 'dev':
+                                vattrs['physdev'] = citems[j + 1]
                         linkattrs['linkinfo'] = vattrs
                         break
                     elif citems[i] == 'vrf' and citems[i + 1] == 'table':
index e4a5892a94d6d64b0fec79440223ec95f7c860b3..85c5a852cc150dddddc7a3d06fe6e44564de6e7c 100644 (file)
@@ -969,7 +969,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):
+                       group=None, learning=True, ageing=None, physdev=None):
 
         debug = RTM_NEWLINK in self.debug
 
@@ -986,6 +986,9 @@ class NetlinkManager(object):
         if ageing:
             info_data[Link.IFLA_VXLAN_AGEING] = int(ageing)
 
+        if physdev:
+            info_data[Link.IFLA_VXLAN_LINK] = int(physdev)
+
         link = Link(RTM_NEWLINK, debug, use_color=self.use_color)
         link.flags = NLM_F_CREATE | NLM_F_REQUEST | NLM_F_ACK
         link.body = pack('Bxxxiii', socket.AF_UNSPEC, 0, 0, 0)