summaryrefslogtreecommitdiff
path: root/zebra/zebra_vrf.c
diff options
context:
space:
mode:
Diffstat (limited to 'zebra/zebra_vrf.c')
-rw-r--r--zebra/zebra_vrf.c116
1 files changed, 38 insertions, 78 deletions
diff --git a/zebra/zebra_vrf.c b/zebra/zebra_vrf.c
index 4715f6e12c..6fc41c3a14 100644
--- a/zebra/zebra_vrf.c
+++ b/zebra/zebra_vrf.c
@@ -25,7 +25,9 @@
#include "linklist.h"
#include "command.h"
#include "memory.h"
+#include "srcdest_table.h"
+#include "vty.h"
#include "zebra/debug.h"
#include "zebra/zserv.h"
#include "zebra/rib.h"
@@ -131,7 +133,7 @@ zebra_vrf_static_route_interface_fixup (struct interface *ifp)
(si->ifindex != ifp->ifindex))
{
si->ifindex = ifp->ifindex;
- static_install_route (afi, safi, &rn->p, si);
+ static_install_route (afi, safi, &rn->p, NULL, si);
}
}
}
@@ -175,7 +177,7 @@ zebra_vrf_enable (struct vrf *vrf)
else
continue;
}
- static_install_route (afi, safi, &rn->p, si);
+ static_install_route (afi, safi, &rn->p, NULL, si);
}
}
@@ -206,7 +208,7 @@ zebra_vrf_disable (struct vrf *vrf)
for (rn = route_top (stable); rn; rn = route_next (rn))
for (si = rn->info; si; si = si->next)
- static_uninstall_route(afi, safi, &rn->p, si);
+ static_uninstall_route(afi, safi, &rn->p, NULL, si);
}
return 0;
@@ -217,7 +219,6 @@ zebra_vrf_delete (struct vrf *vrf)
{
struct zebra_vrf *zvrf = vrf->info;
struct route_table *table;
- rib_table_info_t *info;
u_int32_t table_id;
afi_t afi;
safi_t safi;
@@ -271,12 +272,14 @@ zebra_vrf_delete (struct vrf *vrf)
/* release allocated memory */
for (afi = AFI_IP; afi <= AFI_IP6; afi++)
{
+ void *table_info;
+
for (safi = SAFI_UNICAST; safi <= SAFI_MULTICAST; safi++)
{
table = zvrf->table[afi][safi];
- info = table->info;
+ table_info = table->info;
route_table_finish (table);
- XFREE (MTYPE_RIB_TABLE_INFO, info);
+ XFREE (MTYPE_RIB_TABLE_INFO, table_info);
table = zvrf->stable[afi][safi];
route_table_finish (table);
@@ -286,9 +289,9 @@ zebra_vrf_delete (struct vrf *vrf)
if (zvrf->other_table[afi][table_id])
{
table = zvrf->other_table[afi][table_id];
- info = table->info;
+ table_info = table->info;
route_table_finish (table);
- XFREE (MTYPE_RIB_TABLE_INFO, info);
+ XFREE (MTYPE_RIB_TABLE_INFO, table_info);
}
route_table_finish (zvrf->rnh_table[afi]);
@@ -329,8 +332,7 @@ zebra_vrf_table_with_table_id (afi_t afi, safi_t safi,
}
static void
-zebra_rtable_node_destroy (route_table_delegate_t *delegate,
- struct route_table *table, struct route_node *node)
+zebra_rtable_node_cleanup (struct route_table *table, struct route_node *node)
{
struct rib *rib, *next;
@@ -339,13 +341,10 @@ zebra_rtable_node_destroy (route_table_delegate_t *delegate,
if (node->info)
XFREE (MTYPE_RIB_DEST, node->info);
-
- route_node_destroy (delegate, table, node);
}
static void
-zebra_stable_node_destroy (route_table_delegate_t *delegate,
- struct route_table *table, struct route_node *node)
+zebra_stable_node_cleanup (struct route_table *table, struct route_node *node)
{
struct static_route *si, *next;
@@ -355,35 +354,15 @@ zebra_stable_node_destroy (route_table_delegate_t *delegate,
next = si->next;
XFREE (MTYPE_STATIC_ROUTE, si);
}
-
- route_node_destroy (delegate, table, node);
}
static void
-zebra_rnhtable_node_destroy (route_table_delegate_t *delegate,
- struct route_table *table, struct route_node *node)
+zebra_rnhtable_node_cleanup (struct route_table *table, struct route_node *node)
{
if (node->info)
zebra_free_rnh (node->info);
-
- route_node_destroy (delegate, table, node);
}
-route_table_delegate_t zebra_rtable_delegate = {
- .create_node = route_node_create,
- .destroy_node = zebra_rtable_node_destroy
-};
-
-route_table_delegate_t zebra_stable_delegate = {
- .create_node = route_node_create,
- .destroy_node = zebra_stable_node_destroy
-};
-
-route_table_delegate_t zebra_rnhtable_delegate = {
- .create_node = route_node_create,
- .destroy_node = zebra_rnhtable_node_destroy
-};
-
/*
* Create a routing table for the specific AFI/SAFI in the given VRF.
*/
@@ -395,7 +374,11 @@ zebra_vrf_table_create (struct zebra_vrf *zvrf, afi_t afi, safi_t safi)
assert (!zvrf->table[afi][safi]);
- table = route_table_init_with_delegate (&zebra_rtable_delegate);
+ if (afi == AFI_IP6)
+ table = srcdest_table_init();
+ else
+ table = route_table_init();
+ table->cleanup = zebra_rtable_node_cleanup;
zvrf->table[afi][safi] = table;
info = XCALLOC (MTYPE_RIB_TABLE_INFO, sizeof (*info));
@@ -412,22 +395,30 @@ zebra_vrf_alloc (void)
struct zebra_vrf *zvrf;
afi_t afi;
safi_t safi;
+ struct route_table *table;
zvrf = XCALLOC (MTYPE_ZEBRA_VRF, sizeof (struct zebra_vrf));
for (afi = AFI_IP; afi <= AFI_IP6; afi++)
{
for (safi = SAFI_UNICAST; safi <= SAFI_MULTICAST; safi++)
- {
- zebra_vrf_table_create (zvrf, afi, safi);
- zvrf->stable[afi][safi] =
- route_table_init_with_delegate (&zebra_stable_delegate);
- }
+ {
+ zebra_vrf_table_create (zvrf, afi, safi);
+ if (afi == AFI_IP6)
+ table = srcdest_table_init();
+ else
+ table = route_table_init();
+ table->cleanup = zebra_stable_node_cleanup;
+ zvrf->stable[afi][safi] = table;
+ }
+
+ table = route_table_init();
+ table->cleanup = zebra_rnhtable_node_cleanup;
+ zvrf->rnh_table[afi] = table;
- zvrf->rnh_table[afi] =
- route_table_init_with_delegate (&zebra_rnhtable_delegate);
- zvrf->import_check_table[afi] =
- route_table_init_with_delegate (&zebra_rnhtable_delegate);
+ table = route_table_init();
+ table->cleanup = zebra_rnhtable_node_cleanup;
+ zvrf->import_check_table[afi] = table;
}
zebra_mpls_init_tables (zvrf);
@@ -507,7 +498,7 @@ zebra_vrf_other_route_table (afi_t afi, u_int32_t table_id, vrf_id_t vrf_id)
{
if (zvrf->other_table[afi][table_id] == NULL)
{
- table = route_table_init();
+ table = (afi == AFI_IP6) ? srcdest_table_init() : route_table_init();
info = XCALLOC (MTYPE_RIB_TABLE_INFO, sizeof (*info));
info->zvrf = zvrf;
info->afi = afi;
@@ -522,26 +513,6 @@ zebra_vrf_other_route_table (afi_t afi, u_int32_t table_id, vrf_id_t vrf_id)
return zvrf->table[afi][SAFI_UNICAST];
}
-/* Wrapper hook point for zebra daemon so that ifindex can be set
- * DEFUN macro not used as extract.pl HAS to ignore this
- * See also interface_cmd in lib/if.c
- */
-DEFUN_NOSH (zebra_vrf,
- zebra_vrf_cmd,
- "vrf NAME",
- "Select a VRF to configure\n"
- "VRF's name\n")
-{
- // VTY_DECLVAR_CONTEXT (vrf, vrfp);
- int ret;
-
- /* Call lib vrf() */
- if ((ret = vrf_cmd.func (self, vty, argc, argv)) != CMD_SUCCESS)
- return ret;
-
- return ret;
-}
-
static int
vrf_config_write (struct vty *vty)
{
@@ -560,13 +531,6 @@ vrf_config_write (struct vty *vty)
return 0;
}
-struct cmd_node vrf_node =
-{
- VRF_NODE,
- "%s(config-vrf)# ",
- 1
-};
-
/* Zebra VRF initialization. */
void
zebra_vrf_init (void)
@@ -577,9 +541,5 @@ zebra_vrf_init (void)
vrf_add_hook (VRF_DELETE_HOOK, zebra_vrf_delete);
vrf_init ();
-
- install_node (&vrf_node, vrf_config_write);
- install_default (VRF_NODE);
- install_element (CONFIG_NODE, &zebra_vrf_cmd);
- install_element (CONFIG_NODE, &no_vrf_cmd);
+ vrf_cmd_init (vrf_config_write);
}