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>
'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
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):
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)
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:
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:
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,
% (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)
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)))
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':
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
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)