diff options
Diffstat (limited to 'lib/vrf.c')
| -rw-r--r-- | lib/vrf.c | 47 |
1 files changed, 35 insertions, 12 deletions
@@ -582,29 +582,38 @@ void vrf_init(int (*create)(struct vrf *), int (*enable)(struct vrf *), cmd_variable_handler_register(vrf_var_handlers); } +static void vrf_terminate_single(struct vrf *vrf) +{ + /* Clear configured flag and invoke delete. */ + UNSET_FLAG(vrf->status, VRF_CONFIGURED); + vrf_delete(vrf); +} + /* Terminate VRF module. */ void vrf_terminate(void) { - struct vrf *vrf; + struct vrf *vrf, *tmp; if (debug_vrf) zlog_debug("%s: Shutting down vrf subsystem", __func__); - while (!RB_EMPTY(vrf_id_head, &vrfs_by_id)) { - vrf = RB_ROOT(vrf_id_head, &vrfs_by_id); + RB_FOREACH_SAFE (vrf, vrf_id_head, &vrfs_by_id, tmp) { + if (vrf->vrf_id == VRF_DEFAULT) + continue; - /* Clear configured flag and invoke delete. */ - UNSET_FLAG(vrf->status, VRF_CONFIGURED); - vrf_delete(vrf); + vrf_terminate_single(vrf); } - while (!RB_EMPTY(vrf_name_head, &vrfs_by_name)) { - vrf = RB_ROOT(vrf_name_head, &vrfs_by_name); + RB_FOREACH_SAFE (vrf, vrf_name_head, &vrfs_by_name, tmp) { + if (vrf->vrf_id == VRF_DEFAULT) + continue; - /* Clear configured flag and invoke delete. */ - UNSET_FLAG(vrf->status, VRF_CONFIGURED); - vrf_delete(vrf); + vrf_terminate_single(vrf); } + + /* Finally terminate default VRF */ + vrf = vrf_lookup_by_id(VRF_DEFAULT); + vrf_terminate_single(vrf); } int vrf_socket(int domain, int type, int protocol, vrf_id_t vrf_id, @@ -818,10 +827,24 @@ DEFUN_YANG (no_vrf, return CMD_WARNING_CONFIG_FAILED; } + if (vrf_get_backend() == VRF_BACKEND_VRF_LITE) { + /* + * Remove the VRF interface config. Currently, we allow to + * remove only inactive VRFs, so we use VRF_DEFAULT_NAME here, + * because when the VRF is removed from kernel, the interface + * is moved to the default VRF. If we ever allow removing + * active VRFs, this code have to be updated accordingly. + */ + snprintf(xpath_list, sizeof(xpath_list), + "/frr-interface:lib/interface[name='%s'][vrf='%s']", + vrfname, VRF_DEFAULT_NAME); + nb_cli_enqueue_change(vty, xpath_list, NB_OP_DESTROY, NULL); + } + snprintf(xpath_list, sizeof(xpath_list), FRR_VRF_KEY_XPATH, vrfname); nb_cli_enqueue_change(vty, xpath_list, NB_OP_DESTROY, NULL); - return nb_cli_apply_changes(vty, xpath_list); + return nb_cli_apply_changes(vty, NULL); } |
