summaryrefslogtreecommitdiffstats
path: root/zebra/zebra_vrf.c
diff options
context:
space:
mode:
Diffstat (limited to 'zebra/zebra_vrf.c')
-rw-r--r--zebra/zebra_vrf.c153
1 files changed, 8 insertions, 145 deletions
diff --git a/zebra/zebra_vrf.c b/zebra/zebra_vrf.c
index 25e6513..e464e47 100644
--- a/zebra/zebra_vrf.c
+++ b/zebra/zebra_vrf.c
@@ -195,7 +195,7 @@ static int zebra_vrf_disable(struct vrf *vrf)
/* Cleanup Vxlan, MPLS and PW tables. */
zebra_vxlan_cleanup_tables(zvrf);
zebra_mpls_cleanup_tables(zvrf);
- zebra_pw_exit(zvrf);
+ zebra_pw_exit_vrf(zvrf);
/* Remove link-local IPv4 addresses created for BGP unnumbered peering.
*/
@@ -265,6 +265,12 @@ static int zebra_vrf_delete(struct vrf *vrf)
otable_fini(&zvrf->other_tables);
XFREE(MTYPE_ZEBRA_VRF, zvrf);
+
+ if (vrf->ns_ctxt) {
+ ns_delete(vrf->ns_ctxt);
+ vrf->ns_ctxt = NULL;
+ }
+
vrf->info = NULL;
return 0;
@@ -370,7 +376,7 @@ struct zebra_vrf *zebra_vrf_alloc(struct vrf *vrf)
zebra_vxlan_init_tables(zvrf);
zebra_mpls_init_tables(zvrf);
- zebra_pw_init(zvrf);
+ zebra_pw_init_vrf(zvrf);
zvrf->table_id = rt_table_main_id;
/* by default table ID is default one */
@@ -444,141 +450,6 @@ struct route_table *zebra_vrf_table(afi_t afi, safi_t safi, vrf_id_t vrf_id)
return zvrf->table[afi][safi];
}
-static int vrf_config_write(struct vty *vty)
-{
- struct vrf *vrf;
- struct zebra_vrf *zvrf;
-
- RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
- zvrf = vrf->info;
-
- if (!zvrf)
- continue;
-
- if (zvrf_id(zvrf) == VRF_DEFAULT) {
- if (zvrf->l3vni)
- vty_out(vty, "vni %u%s\n", zvrf->l3vni,
- is_l3vni_for_prefix_routes_only(
- zvrf->l3vni)
- ? " prefix-routes-only"
- : "");
-
- if (zvrf->zebra_rnh_ip_default_route !=
- SAVE_ZEBRA_IP_NHT_RESOLVE_VIA_DEFAULT)
- vty_out(vty, "%sip nht resolve-via-default\n",
- zvrf->zebra_rnh_ip_default_route
- ? ""
- : "no ");
-
- if (zvrf->zebra_rnh_ipv6_default_route !=
- SAVE_ZEBRA_IP_NHT_RESOLVE_VIA_DEFAULT)
- vty_out(vty, "%sipv6 nht resolve-via-default\n",
- zvrf->zebra_rnh_ipv6_default_route
- ? ""
- : "no ");
-
- if (zvrf->tbl_mgr
- && (zvrf->tbl_mgr->start || zvrf->tbl_mgr->end))
- vty_out(vty, "ip table range %u %u\n",
- zvrf->tbl_mgr->start,
- zvrf->tbl_mgr->end);
- } else {
- vty_frame(vty, "vrf %s\n", zvrf_name(zvrf));
- if (zvrf->l3vni)
- vty_out(vty, " vni %u%s\n", zvrf->l3vni,
- is_l3vni_for_prefix_routes_only(
- zvrf->l3vni)
- ? " prefix-routes-only"
- : "");
- zebra_ns_config_write(vty, (struct ns *)vrf->ns_ctxt);
- if (zvrf->zebra_rnh_ip_default_route !=
- SAVE_ZEBRA_IP_NHT_RESOLVE_VIA_DEFAULT)
- vty_out(vty, " %sip nht resolve-via-default\n",
- zvrf->zebra_rnh_ip_default_route
- ? ""
- : "no ");
-
- if (zvrf->zebra_rnh_ipv6_default_route !=
- SAVE_ZEBRA_IP_NHT_RESOLVE_VIA_DEFAULT)
- vty_out(vty, " %sipv6 nht resolve-via-default\n",
- zvrf->zebra_rnh_ipv6_default_route
- ? ""
- : "no ");
-
- if (zvrf->tbl_mgr && vrf_is_backend_netns()
- && (zvrf->tbl_mgr->start || zvrf->tbl_mgr->end))
- vty_out(vty, " ip table range %u %u\n",
- zvrf->tbl_mgr->start,
- zvrf->tbl_mgr->end);
- }
-
-
- zebra_routemap_config_write_protocol(vty, zvrf);
- router_id_write(vty, zvrf);
-
- if (zvrf_id(zvrf) != VRF_DEFAULT)
- vty_endframe(vty, "exit-vrf\n!\n");
- else
- vty_out(vty, "!\n");
- }
- return 0;
-}
-
-DEFPY (vrf_netns,
- vrf_netns_cmd,
- "netns NAME$netns_name",
- "Attach VRF to a Namespace\n"
- "The file name in " NS_RUN_DIR ", or a full pathname\n")
-{
- char *pathname = ns_netns_pathname(vty, netns_name);
- int ret;
-
- VTY_DECLVAR_CONTEXT(vrf, vrf);
-
- if (!pathname)
- return CMD_WARNING_CONFIG_FAILED;
-
- frr_with_privs(&zserv_privs) {
- ret = zebra_vrf_netns_handler_create(
- vty, vrf, pathname, NS_UNKNOWN, NS_UNKNOWN, NS_UNKNOWN);
- }
-
- return ret;
-}
-
-DEFUN (no_vrf_netns,
- no_vrf_netns_cmd,
- "no netns [NAME]",
- NO_STR
- "Detach VRF from a Namespace\n"
- "The file name in " NS_RUN_DIR ", or a full pathname\n")
-{
- struct ns *ns = NULL;
-
- VTY_DECLVAR_CONTEXT(vrf, vrf);
-
- if (!vrf_is_backend_netns()) {
- vty_out(vty, "VRF backend is not Netns. Aborting\n");
- return CMD_WARNING_CONFIG_FAILED;
- }
- if (!vrf->ns_ctxt) {
- vty_out(vty, "VRF %s(%u) is not configured with NetNS\n",
- vrf->name, vrf->vrf_id);
- return CMD_WARNING_CONFIG_FAILED;
- }
-
- ns = (struct ns *)vrf->ns_ctxt;
-
- ns->vrf_ctxt = NULL;
- vrf_disable(vrf);
- /* vrf ID from VRF is necessary for Zebra
- * so that propagate to other clients is done
- */
- ns_delete(ns);
- vrf->ns_ctxt = NULL;
- return CMD_SUCCESS;
-}
-
/* if ns_id is different and not VRF_UNKNOWN,
* then update vrf identifier, and enable VRF
*/
@@ -677,12 +548,4 @@ void zebra_vrf_init(void)
zebra_vrf_delete);
hook_register(zserv_client_close, release_daemon_table_chunks);
-
- vrf_cmd_init(vrf_config_write);
-
- if (vrf_is_backend_netns() && ns_have_netns()) {
- /* Install NS commands. */
- install_element(VRF_NODE, &vrf_netns_cmd);
- install_element(VRF_NODE, &no_vrf_netns_cmd);
- }
}