]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: remove vrf-interface config when removing the VRF
authorIgor Ryzhov <iryzhov@nfware.com>
Mon, 21 Jun 2021 15:04:46 +0000 (18:04 +0300)
committermergify-bot <noreply@mergify.io>
Thu, 22 Jul 2021 22:33:16 +0000 (22:33 +0000)
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>
(cherry picked from commit f5eef2d5a8a471fe6e4ec4f6acfa3dbf190eda5d)

14 files changed:
babeld/babeld.c
eigrpd/eigrp_cli.c
isisd/isisd.c
lib/vrf.c
nhrpd/nhrp_main.c
nhrpd/nhrp_vty.c
ospf6d/ospf6_top.c
ospfd/ospf_vty.c
pbrd/pbr_main.c
pbrd/pbr_vty.c
ripd/ripd.c
ripngd/ripngd.c
vrrpd/vrrp_vty.c
vtysh/vtysh.h

index 4d4dd2e19490f651681ccd37eb8b9b5092ca26a1..b9623b64b5fa56dd97f8c21e8028dbc77f70a3af 100644 (file)
@@ -819,6 +819,8 @@ babeld_quagga_init(void)
     install_element(BABEL_NODE, &babel_ipv6_distribute_list_cmd);
     install_element(BABEL_NODE, &babel_no_ipv6_distribute_list_cmd);
 
+    vrf_cmd_init(NULL, &babeld_privs);
+
     babel_if_init();
 
     /* Access list install. */
index 3a978cae33369b24604527b05ce51900dc737d99..47de929fc3cb494f2b4ae9ca69446d42483c39f2 100644 (file)
@@ -919,6 +919,8 @@ eigrp_cli_init(void)
        install_element(EIGRP_NODE, &eigrp_neighbor_cmd);
        install_element(EIGRP_NODE, &eigrp_redistribute_source_metric_cmd);
 
+       vrf_cmd_init(NULL, &eigrpd_privs);
+
        install_node(&eigrp_interface_node);
        if_cmd_init();
 
index 7f56903fc9be3745b6ded94eef59db44c4c6eee0..7e78e0ce69daa5b5eddc89ccc560ea8c3225a5f8 100644 (file)
@@ -716,6 +716,8 @@ void isis_vrf_init(void)
 {
        vrf_init(isis_vrf_new, isis_vrf_enable, isis_vrf_disable,
                 isis_vrf_delete, isis_vrf_enable);
+
+       vrf_cmd_init(NULL, &isisd_privs);
 }
 
 void isis_terminate()
index a04f2ddeb78843b53cc716823426b507d9c9c6dd..03d9a62c0f138b6b5fbde171e42268d83cd09408 100644 (file)
--- a/lib/vrf.c
+++ b/lib/vrf.c
@@ -827,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);
 }
 
 
index c2111a7706ff2cf61804bf33144c9b821d843ad9..54b785020727b8d53cc2b015a73b0adc30bbdaf6 100644 (file)
@@ -118,6 +118,7 @@ static struct quagga_signal_t sighandlers[] = {
 static const struct frr_yang_module_info *const nhrpd_yang_modules[] = {
        &frr_filter_info,
        &frr_interface_info,
+       &frr_vrf_info,
 };
 
 FRR_DAEMON_INFO(nhrpd, NHRP, .vty_port = NHRP_VTY_PORT,
index 420ea12ec1e23c9771370a11aaee54af9d216ed0..963fa4d9957c9cf9f6966e6567146050030fc23e 100644 (file)
@@ -1260,6 +1260,8 @@ void nhrp_config_init(void)
        install_element(CONFIG_NODE, &nhrp_multicast_nflog_group_cmd);
        install_element(CONFIG_NODE, &no_nhrp_multicast_nflog_group_cmd);
 
+       vrf_cmd_init(NULL, &nhrpd_privs);
+
        /* interface specific commands */
        install_node(&nhrp_interface_node);
 
index 1f7d5f3a0b87a5e68ccc22d3fc7de637c7985698..c312b5d2ffc086595d6292eb8e40850465f0fe7c 100644 (file)
@@ -231,6 +231,8 @@ void ospf6_vrf_init(void)
 {
        vrf_init(ospf6_vrf_new, ospf6_vrf_enable, ospf6_vrf_disable,
                 ospf6_vrf_delete, ospf6_vrf_enable);
+
+       vrf_cmd_init(NULL, &ospf6d_privs);
 }
 
 static void ospf6_top_lsdb_hook_add(struct ospf6_lsa *lsa)
index cb64187d723bc13b716c68faadb908d275c075d7..54ce248d89efe5225ffc0ffb9ac7b37bcec52922 100644 (file)
@@ -12959,6 +12959,8 @@ void ospf_vty_init(void)
        install_element(OSPF_NODE, &ospf_max_multipath_cmd);
        install_element(OSPF_NODE, &no_ospf_max_multipath_cmd);
 
+       vrf_cmd_init(NULL, &ospfd_privs);
+
        /* Init interface related vty commands. */
        ospf_vty_if_init();
 
index 1badaf95bddf0a8bd25d71304fab4a89819e3b04..786155903460deb6ea9db6e495863dd6bf4f9c41 100644 (file)
@@ -119,6 +119,7 @@ struct quagga_signal_t pbr_signals[] = {
 static const struct frr_yang_module_info *const pbrd_yang_modules[] = {
        &frr_filter_info,
        &frr_interface_info,
+       &frr_vrf_info,
 };
 
 FRR_DAEMON_INFO(pbrd, PBR, .vty_port = PBR_VTY_PORT,
index 216834fe0c60c6b84ccdc044b6e3c52eb870eb18..3d56fc3daa14ee09d89cc853b20b0e700a4becb3 100644 (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)
 {
        cmd_variable_handler_register(pbr_map_name);
 
+       vrf_cmd_init(NULL, &pbr_privs);
+
        install_node(&interface_node);
        if_cmd_init();
 
index c6c82fb65ac1dfca3a115392103a855f4803cb5c..7d940efd9c615ea19c355f44b1966913c0885231 100644 (file)
@@ -3690,6 +3690,8 @@ void rip_vrf_init(void)
 {
        vrf_init(rip_vrf_new, rip_vrf_enable, rip_vrf_disable, rip_vrf_delete,
                 rip_vrf_enable);
+
+       vrf_cmd_init(NULL, &ripd_privs);
 }
 
 void rip_vrf_terminate(void)
index 3b8d2076f347d2473e323c32072d3d1354b53f91..a0ea18f3e9b801195b869bb3bc0ba4b83ad96d93 100644 (file)
@@ -2691,6 +2691,8 @@ void ripng_vrf_init(void)
 {
        vrf_init(ripng_vrf_new, ripng_vrf_enable, ripng_vrf_disable,
                 ripng_vrf_delete, ripng_vrf_enable);
+
+       vrf_cmd_init(NULL, &ripngd_privs);
 }
 
 void ripng_vrf_terminate(void)
index 6c3863132d69fe73050fbaf3389aa045e1078249..7af9148a8e39f4d7d2ba8b88551b04011052fa38 100644 (file)
@@ -771,6 +771,7 @@ void vrrp_vty_init(void)
        install_node(&debug_node);
        install_node(&interface_node);
        install_node(&vrrp_node);
+       vrf_cmd_init(NULL, &vrrp_privs);
        if_cmd_init();
 
        install_element(VIEW_NODE, &vrrp_vrid_show_cmd);
index 7c8d9315e1d1f25e80b5b6ddd2dc730fb33bf809..927de60615cda1ee988d5a908246591ba155b13f 100644 (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_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_VRF        VTYSH_ZEBRA|VTYSH_PIMD|VTYSH_STATICD
+#define VTYSH_VRF        VTYSH_INTERFACE|VTYSH_STATICD
 #define VTYSH_KEYS        VTYSH_RIPD|VTYSH_EIGRPD
 /* Daemons who can process nexthop-group configs */
 #define VTYSH_NH_GROUP    VTYSH_PBRD|VTYSH_SHARPD