1
0
mirror of https://github.com/CumulusNetworks/ifupdown2.git synced 2024-05-06 15:54:50 +00:00

addons: vrf: close sockets when vrf interface goes down

Ticket: CM-11393
Reviewed By: dsa, julien, nikhil
Testing Done: tested up and down of a vrf interface

$ifdown -v blue
..snip ..
info: executing /usr/lib/vrf/vrf-helper delete blue 1030
info: executing ip link del blue
info: executing /bin/ss -aK "dev == 54"
info: vrf: syncing table map to
/etc/iproute2/rt_tables.d/ifupdown2_vrf_map.conf

Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
This commit is contained in:
Roopa Prabhu
2016-09-15 10:10:39 -07:00
parent dc3f4c4507
commit 6fbd7444db
2 changed files with 25 additions and 1 deletions

View File

@@ -123,7 +123,7 @@ class vrf(moduleBase):
self.vrf_fix_local_table = True self.vrf_fix_local_table = True
self.vrf_count = 0 self.vrf_count = 0
self.vrf_helper = policymanager.policymanager_api.get_module_globals(module_name=self.__class__.__name__, attr='vrf-helper') self.vrf_helper = policymanager.policymanager_api.get_module_globals(module_name=self.__class__.__name__, attr='vrf-helper')
self.vrf_close_socks_on_down = policymanager.policymanager_api.get_module_globals(module_name=self.__class__.__name__, attr='vrf-close-socks-on-down')
self.warn_on_vrf_map_write_err = True self.warn_on_vrf_map_write_err = True
def _iproute2_vrf_map_initialize(self, writetodisk=True): def _iproute2_vrf_map_initialize(self, writetodisk=True):
@@ -805,8 +805,23 @@ class vrf(moduleBase):
vrf_table, vrf_table,
mode)) mode))
def _close_sockets(self, ifaceobj, ifindex):
if not self.vrf_close_socks_on_down:
return
try:
utils.exec_command('/bin/ss -aK \"dev == %s\"'
%ifindex)
except Exception, e:
self.logger.info('%s: closing socks using ss'
' failed (%s)\n' %(ifaceobj.name, str(e)))
pass
def _down_vrf_dev(self, ifaceobj, vrf_table, ifaceobj_getfunc=None): def _down_vrf_dev(self, ifaceobj, vrf_table, ifaceobj_getfunc=None):
if not self.ipcmd.link_exists(ifaceobj.name):
return
if vrf_table == 'auto': if vrf_table == 'auto':
vrf_table = self._get_iproute2_vrf_table(ifaceobj.name) vrf_table = self._get_iproute2_vrf_table(ifaceobj.name)
@@ -841,12 +856,16 @@ class vrf(moduleBase):
self.logger.info('%s: %s' %(ifaceobj.name, str(e))) self.logger.info('%s: %s' %(ifaceobj.name, str(e)))
pass pass
ifindex = self.ipcmd.link_get_ifindex(ifaceobj.name)
try: try:
self.ipcmd.link_delete(ifaceobj.name) self.ipcmd.link_delete(ifaceobj.name)
except Exception, e: except Exception, e:
self.logger.info('%s: %s' %(ifaceobj.name, str(e))) self.logger.info('%s: %s' %(ifaceobj.name, str(e)))
pass pass
self._close_sockets(ifaceobj, ifindex)
try: try:
self._iproute2_vrf_table_entry_del(vrf_table) self._iproute2_vrf_table_entry_del(vrf_table)
except Exception, e: except Exception, e:

View File

@@ -628,6 +628,11 @@ class iproute2(utilsBase):
return True return True
return os.path.exists('/sys/class/net/%s' %ifacename) return os.path.exists('/sys/class/net/%s' %ifacename)
def link_get_ifindex(self, ifacename):
if ifupdownflags.flags.DRYRUN:
return True
return self.read_file_oneline('/sys/class/net/%s/ifindex' %ifacename)
def is_vlan_device_by_name(self, ifacename): def is_vlan_device_by_name(self, ifacename):
if re.search(r'\.', ifacename): if re.search(r'\.', ifacename):
return True return True