lib: remove vrf-interface config when removing the VRF

If we have the following configuration:
```
vrf red
 smth
 exit-vrf
!
interface red vrf red
 smth
```
And we delete the VRF using "no vrf red" command, we end up with:
```
interface red
 smth
```
Interface config is preserved but moved to the default VRF.

This is not an expected behavior. We should remove the interface config
when the VRF is deleted.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
This commit is contained in:
Igor Ryzhov 2021-06-21 18:04:46 +03:00
parent cd551a0fd5
commit f5eef2d5a8
14 changed files with 39 additions and 2 deletions

View File

@ -819,6 +819,8 @@ babeld_quagga_init(void)
install_element(BABEL_NODE, &babel_ipv6_distribute_list_cmd); install_element(BABEL_NODE, &babel_ipv6_distribute_list_cmd);
install_element(BABEL_NODE, &babel_no_ipv6_distribute_list_cmd); install_element(BABEL_NODE, &babel_no_ipv6_distribute_list_cmd);
vrf_cmd_init(NULL, &babeld_privs);
babel_if_init(); babel_if_init();
/* Access list install. */ /* Access list install. */

View File

@ -919,6 +919,8 @@ eigrp_cli_init(void)
install_element(EIGRP_NODE, &eigrp_neighbor_cmd); install_element(EIGRP_NODE, &eigrp_neighbor_cmd);
install_element(EIGRP_NODE, &eigrp_redistribute_source_metric_cmd); install_element(EIGRP_NODE, &eigrp_redistribute_source_metric_cmd);
vrf_cmd_init(NULL, &eigrpd_privs);
install_node(&eigrp_interface_node); install_node(&eigrp_interface_node);
if_cmd_init(); if_cmd_init();

View File

@ -716,6 +716,8 @@ void isis_vrf_init(void)
{ {
vrf_init(isis_vrf_new, isis_vrf_enable, isis_vrf_disable, vrf_init(isis_vrf_new, isis_vrf_enable, isis_vrf_disable,
isis_vrf_delete, isis_vrf_enable); isis_vrf_delete, isis_vrf_enable);
vrf_cmd_init(NULL, &isisd_privs);
} }
void isis_terminate() void isis_terminate()

View File

@ -827,10 +827,24 @@ DEFUN_YANG (no_vrf,
return CMD_WARNING_CONFIG_FAILED; 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); snprintf(xpath_list, sizeof(xpath_list), FRR_VRF_KEY_XPATH, vrfname);
nb_cli_enqueue_change(vty, xpath_list, NB_OP_DESTROY, NULL); 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);
} }

View File

@ -118,6 +118,7 @@ static struct quagga_signal_t sighandlers[] = {
static const struct frr_yang_module_info *const nhrpd_yang_modules[] = { static const struct frr_yang_module_info *const nhrpd_yang_modules[] = {
&frr_filter_info, &frr_filter_info,
&frr_interface_info, &frr_interface_info,
&frr_vrf_info,
}; };
FRR_DAEMON_INFO(nhrpd, NHRP, .vty_port = NHRP_VTY_PORT, FRR_DAEMON_INFO(nhrpd, NHRP, .vty_port = NHRP_VTY_PORT,

View File

@ -1260,6 +1260,8 @@ void nhrp_config_init(void)
install_element(CONFIG_NODE, &nhrp_multicast_nflog_group_cmd); install_element(CONFIG_NODE, &nhrp_multicast_nflog_group_cmd);
install_element(CONFIG_NODE, &no_nhrp_multicast_nflog_group_cmd); install_element(CONFIG_NODE, &no_nhrp_multicast_nflog_group_cmd);
vrf_cmd_init(NULL, &nhrpd_privs);
/* interface specific commands */ /* interface specific commands */
install_node(&nhrp_interface_node); install_node(&nhrp_interface_node);

View File

@ -232,6 +232,8 @@ void ospf6_vrf_init(void)
{ {
vrf_init(ospf6_vrf_new, ospf6_vrf_enable, ospf6_vrf_disable, vrf_init(ospf6_vrf_new, ospf6_vrf_enable, ospf6_vrf_disable,
ospf6_vrf_delete, ospf6_vrf_enable); ospf6_vrf_delete, ospf6_vrf_enable);
vrf_cmd_init(NULL, &ospf6d_privs);
} }
static void ospf6_top_lsdb_hook_add(struct ospf6_lsa *lsa) static void ospf6_top_lsdb_hook_add(struct ospf6_lsa *lsa)

View File

@ -12959,6 +12959,8 @@ void ospf_vty_init(void)
install_element(OSPF_NODE, &ospf_max_multipath_cmd); install_element(OSPF_NODE, &ospf_max_multipath_cmd);
install_element(OSPF_NODE, &no_ospf_max_multipath_cmd); install_element(OSPF_NODE, &no_ospf_max_multipath_cmd);
vrf_cmd_init(NULL, &ospfd_privs);
/* Init interface related vty commands. */ /* Init interface related vty commands. */
ospf_vty_if_init(); ospf_vty_if_init();

View File

@ -119,6 +119,7 @@ struct quagga_signal_t pbr_signals[] = {
static const struct frr_yang_module_info *const pbrd_yang_modules[] = { static const struct frr_yang_module_info *const pbrd_yang_modules[] = {
&frr_filter_info, &frr_filter_info,
&frr_interface_info, &frr_interface_info,
&frr_vrf_info,
}; };
FRR_DAEMON_INFO(pbrd, PBR, .vty_port = PBR_VTY_PORT, FRR_DAEMON_INFO(pbrd, PBR, .vty_port = PBR_VTY_PORT,

View File

@ -1143,10 +1143,14 @@ static const struct cmd_variable_handler pbr_map_name[] = {
} }
}; };
extern struct zebra_privs_t pbr_privs;
void pbr_vty_init(void) void pbr_vty_init(void)
{ {
cmd_variable_handler_register(pbr_map_name); cmd_variable_handler_register(pbr_map_name);
vrf_cmd_init(NULL, &pbr_privs);
install_node(&interface_node); install_node(&interface_node);
if_cmd_init(); if_cmd_init();

View File

@ -3690,6 +3690,8 @@ void rip_vrf_init(void)
{ {
vrf_init(rip_vrf_new, rip_vrf_enable, rip_vrf_disable, rip_vrf_delete, vrf_init(rip_vrf_new, rip_vrf_enable, rip_vrf_disable, rip_vrf_delete,
rip_vrf_enable); rip_vrf_enable);
vrf_cmd_init(NULL, &ripd_privs);
} }
void rip_vrf_terminate(void) void rip_vrf_terminate(void)

View File

@ -2691,6 +2691,8 @@ void ripng_vrf_init(void)
{ {
vrf_init(ripng_vrf_new, ripng_vrf_enable, ripng_vrf_disable, vrf_init(ripng_vrf_new, ripng_vrf_enable, ripng_vrf_disable,
ripng_vrf_delete, ripng_vrf_enable); ripng_vrf_delete, ripng_vrf_enable);
vrf_cmd_init(NULL, &ripngd_privs);
} }
void ripng_vrf_terminate(void) void ripng_vrf_terminate(void)

View File

@ -771,6 +771,7 @@ void vrrp_vty_init(void)
install_node(&debug_node); install_node(&debug_node);
install_node(&interface_node); install_node(&interface_node);
install_node(&vrrp_node); install_node(&vrrp_node);
vrf_cmd_init(NULL, &vrrp_privs);
if_cmd_init(); if_cmd_init();
install_element(VIEW_NODE, &vrrp_vrid_show_cmd); install_element(VIEW_NODE, &vrrp_vrid_show_cmd);

View File

@ -56,7 +56,7 @@ DECLARE_MGROUP(MVTYSH);
#define VTYSH_ACL VTYSH_BFDD|VTYSH_BABELD|VTYSH_BGPD|VTYSH_EIGRPD|VTYSH_ISISD|VTYSH_FABRICD|VTYSH_LDPD|VTYSH_NHRPD|VTYSH_OSPF6D|VTYSH_OSPFD|VTYSH_PBRD|VTYSH_PIMD|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_VRRPD|VTYSH_ZEBRA #define VTYSH_ACL VTYSH_BFDD|VTYSH_BABELD|VTYSH_BGPD|VTYSH_EIGRPD|VTYSH_ISISD|VTYSH_FABRICD|VTYSH_LDPD|VTYSH_NHRPD|VTYSH_OSPF6D|VTYSH_OSPFD|VTYSH_PBRD|VTYSH_PIMD|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_VRRPD|VTYSH_ZEBRA
#define VTYSH_RMAP VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ISISD|VTYSH_PIMD|VTYSH_EIGRPD|VTYSH_FABRICD #define VTYSH_RMAP VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ISISD|VTYSH_PIMD|VTYSH_EIGRPD|VTYSH_FABRICD
#define VTYSH_INTERFACE VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_ISISD|VTYSH_PIMD|VTYSH_NHRPD|VTYSH_EIGRPD|VTYSH_BABELD|VTYSH_PBRD|VTYSH_FABRICD|VTYSH_VRRPD #define VTYSH_INTERFACE VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_ISISD|VTYSH_PIMD|VTYSH_NHRPD|VTYSH_EIGRPD|VTYSH_BABELD|VTYSH_PBRD|VTYSH_FABRICD|VTYSH_VRRPD
#define VTYSH_VRF VTYSH_ZEBRA|VTYSH_PIMD|VTYSH_STATICD #define VTYSH_VRF VTYSH_INTERFACE|VTYSH_STATICD
#define VTYSH_KEYS VTYSH_RIPD|VTYSH_EIGRPD #define VTYSH_KEYS VTYSH_RIPD|VTYSH_EIGRPD
/* Daemons who can process nexthop-group configs */ /* Daemons who can process nexthop-group configs */
#define VTYSH_NH_GROUP VTYSH_PBRD|VTYSH_SHARPD #define VTYSH_NH_GROUP VTYSH_PBRD|VTYSH_SHARPD