BGP: Cleanup interfaces properly on instance delete or exit

Perform interface cleanup as an instance is deleted. This takes care of the
scenario when BGP exits (or is stopped/restarted) too as instances undergo
deletion and the interface cleanup is done as the last step in that.

Signed-off-by: Vivek Venkatraman <vivek@cumulusnetworks.com>
Fixes: 46abd3e3e6

Ticket: CM-9410
Reviewed By: CCR-4143
Testing Done: Reran failed test
This commit is contained in:
vivek 2016-02-22 06:36:37 +00:00
parent ceebe0c4e0
commit 009b18fc80
5 changed files with 29 additions and 25 deletions

View File

@ -234,9 +234,6 @@ bgp_exit (int status)
if (retain_mode)
if_add_hook (IF_DELETE_HOOK, NULL);
/* free interface and connected route information. */
bgp_if_finish ();
/* reverse bgp_master_init */
for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
bgp_delete (bgp);

View File

@ -3058,6 +3058,9 @@ bgp_delete (struct bgp *bgp)
if (IS_BGP_INST_KNOWN_TO_ZEBRA(bgp))
bgp_zebra_instance_deregister (bgp);
/* Free interfaces in this instance. */
bgp_if_finish (bgp);
/* If Default instance or VRF, unlink from the VRF structure. */
vrf = bgp_vrf_lookup_by_instance_type (bgp);
if (vrf)
@ -7158,21 +7161,17 @@ bgp_master_init (void)
}
/*
* Free up connected routes and interfaces; invoked upon bgp_exit()
* Free up connected routes and interfaces for a BGP instance. Invoked upon
* instance delete (non-default only) or BGP exit.
*/
void
bgp_if_finish (void)
{
struct bgp *bgp;
struct listnode *node, *nnode;
for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
bgp_if_finish (struct bgp *bgp)
{
struct listnode *ifnode, *ifnnode;
struct interface *ifp;
if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
continue;
return;
for (ALL_LIST_ELEMENTS (vrf_iflist(bgp->vrf_id), ifnode, ifnnode, ifp))
{
@ -7181,11 +7180,8 @@ bgp_if_finish (void)
for (ALL_LIST_ELEMENTS (ifp->connected, c_node, c_nnode, c))
bgp_connected_delete (bgp, c);
if_delete (ifp);
}
list_free (vrf_iflist(bgp->vrf_id));
}
vrf_iflist_terminate (bgp->vrf_id);
}
void

View File

@ -1174,7 +1174,7 @@ extern char *peer_uptime (time_t, char *, size_t, u_char, json_object *);
extern int bgp_config_write (struct vty *);
extern void bgp_config_write_family_header (struct vty *, afi_t, safi_t, int *);
extern void bgp_if_finish (void);
extern void bgp_if_finish (struct bgp *);
extern void bgp_master_init (void);
extern void bgp_init (void);

View File

@ -495,6 +495,15 @@ vrf_iflist_get (vrf_id_t vrf_id)
return vrf->iflist;
}
/* Free the interface list of the specified VRF. */
void
vrf_iflist_terminate (vrf_id_t vrf_id)
{
struct vrf * vrf = vrf_lookup (vrf_id);
if (vrf && vrf->iflist)
if_terminate (vrf->vrf_id, &vrf->iflist);
}
/*
* VRF bit-map
*/

View File

@ -180,6 +180,8 @@ extern void *vrf_info_lookup (vrf_id_t);
extern struct list *vrf_iflist (vrf_id_t);
/* Get the interface list of the specified VRF. Create one if not find. */
extern struct list *vrf_iflist_get (vrf_id_t);
/* Free the interface list of the specified VRF. */
extern void vrf_iflist_terminate (vrf_id_t vrf_id);
/*
* VRF bit-map: maintaining flags, one bit per VRF ID