summaryrefslogtreecommitdiffstats
path: root/zebra
diff options
context:
space:
mode:
Diffstat (limited to 'zebra')
-rw-r--r--zebra/main.c27
-rw-r--r--zebra/redistribute.c9
-rw-r--r--zebra/rib.h22
-rw-r--r--zebra/test_main.c25
-rw-r--r--zebra/zebra_fpm.c2
-rw-r--r--zebra/zebra_fpm_netlink.c2
-rw-r--r--zebra/zebra_rib.c270
-rw-r--r--zebra/zebra_snmp.c11
-rw-r--r--zebra/zebra_vty.c39
9 files changed, 219 insertions, 188 deletions
diff --git a/zebra/main.c b/zebra/main.c
index d7f2a108..a690c9a1 100644
--- a/zebra/main.c
+++ b/zebra/main.c
@@ -32,6 +32,7 @@
#include "plist.h"
#include "privs.h"
#include "sigevent.h"
+#include "vrf.h"
#include "zebra/rib.h"
#include "zebra/zserv.h"
@@ -204,6 +205,29 @@ struct quagga_signal_t zebra_signals[] =
},
};
+/* Callback upon creating a new VRF. */
+static int
+zebra_vrf_new (vrf_id_t vrf_id, void **info)
+{
+ struct zebra_vrf *zvrf = *info;
+
+ if (! zvrf)
+ {
+ zvrf = zebra_vrf_alloc (vrf_id);
+ *info = (void *)zvrf;
+ }
+
+ return 0;
+}
+
+/* Zebra VRF initialization. */
+static void
+zebra_vrf_init (void)
+{
+ vrf_add_hook (VRF_NEW_HOOK, zebra_vrf_new);
+ vrf_init ();
+}
+
/* Main startup routine. */
int
main (int argc, char **argv)
@@ -338,7 +362,8 @@ main (int argc, char **argv)
/* For debug purpose. */
/* SET_FLAG (zebra_debug_event, ZEBRA_DEBUG_EVENT); */
- /* Make kernel routing socket. */
+ /* Initialize VRF module, and make kernel routing socket. */
+ zebra_vrf_init ();
kernel_init ();
interface_list ();
route_read ();
diff --git a/zebra/redistribute.c b/zebra/redistribute.c
index 94330aed..8bf8ea8c 100644
--- a/zebra/redistribute.c
+++ b/zebra/redistribute.c
@@ -30,6 +30,7 @@
#include "zclient.h"
#include "linklist.h"
#include "log.h"
+#include "vrf.h"
#include "zebra/rib.h"
#include "zebra/zserv.h"
@@ -101,7 +102,7 @@ zebra_redistribute_default (struct zserv *client)
p.family = AF_INET;
/* Lookup table. */
- table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
+ table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT);
if (table)
{
rn = route_node_lookup (table, (struct prefix *)&p);
@@ -121,7 +122,7 @@ zebra_redistribute_default (struct zserv *client)
p6.family = AF_INET6;
/* Lookup table. */
- table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);
+ table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT);
if (table)
{
rn = route_node_lookup (table, (struct prefix *)&p6);
@@ -145,7 +146,7 @@ zebra_redistribute (struct zserv *client, int type)
struct route_table *table;
struct route_node *rn;
- table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
+ table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT);
if (table)
for (rn = route_top (table); rn; rn = route_next (rn))
RNODE_FOREACH_RIB (rn, newrib)
@@ -156,7 +157,7 @@ zebra_redistribute (struct zserv *client, int type)
zsend_route_multipath (ZEBRA_IPV4_ROUTE_ADD, client, &rn->p, newrib);
#ifdef HAVE_IPV6
- table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);
+ table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT);
if (table)
for (rn = route_top (table); rn; rn = route_next (rn))
RNODE_FOREACH_RIB (rn, newrib)
diff --git a/zebra/rib.h b/zebra/rib.h
index 94a74194..802d875f 100644
--- a/zebra/rib.h
+++ b/zebra/rib.h
@@ -315,10 +315,10 @@ struct nexthop
: (((recursing) = 0),((tnexthop) = (tnexthop)->next)))
/* Routing table instance. */
-struct vrf
+struct zebra_vrf
{
- /* Identifier. This is same as routing table vector index. */
- u_int32_t id;
+ /* Identifier. */
+ vrf_id_t vrf_id;
/* Routing table name. */
char *name;
@@ -346,9 +346,9 @@ typedef struct rib_table_info_t_
{
/*
- * Back pointer to vrf.
+ * Back pointer to zebra_vrf.
*/
- struct vrf *vrf;
+ struct zebra_vrf *zvrf;
afi_t afi;
safi_t safi;
@@ -367,7 +367,7 @@ typedef enum
*/
typedef struct rib_tables_iter_t_
{
- uint32_t vrf_id;
+ vrf_id_t vrf_id;
int afi_safi_ix;
rib_tables_iter_state_t state;
@@ -415,9 +415,9 @@ extern int rib_lookup_ipv4_route (struct prefix_ipv4 *, union sockunion *);
extern struct nexthop *nexthop_ipv6_add (struct rib *, struct in6_addr *);
#endif /* HAVE_IPV6 */
-extern struct vrf *vrf_lookup (u_int32_t);
-extern struct route_table *vrf_table (afi_t afi, safi_t safi, u_int32_t id);
-extern struct route_table *vrf_static_table (afi_t afi, safi_t safi, u_int32_t id);
+extern struct zebra_vrf *zebra_vrf_alloc (vrf_id_t);
+extern struct route_table *zebra_vrf_table (afi_t, safi_t, vrf_id_t);
+extern struct route_table *zebra_vrf_static_table (afi_t, safi_t, vrf_id_t);
/* NOTE:
* All rib_add_ipv[46]* functions will not just add prefix into RIB, but
@@ -557,10 +557,10 @@ rib_dest_table (rib_dest_t *dest)
/*
* rib_dest_vrf
*/
-static inline struct vrf *
+static inline struct zebra_vrf *
rib_dest_vrf (rib_dest_t *dest)
{
- return rib_table_info (rib_dest_table (dest))->vrf;
+ return rib_table_info (rib_dest_table (dest))->zvrf;
}
/*
diff --git a/zebra/test_main.c b/zebra/test_main.c
index f98bb419..a92cd618 100644
--- a/zebra/test_main.c
+++ b/zebra/test_main.c
@@ -29,6 +29,7 @@
#include "log.h"
#include "privs.h"
#include "sigevent.h"
+#include "vrf.h"
#include "zebra/rib.h"
#include "zebra/zserv.h"
@@ -196,6 +197,29 @@ struct quagga_signal_t zebra_signals[] =
},
};
+/* Callback upon creating a new VRF. */
+static int
+zebra_vrf_new (vrf_id_t vrf_id, void **info)
+{
+ struct zebra_vrf *zvrf = *info;
+
+ if (! zvrf)
+ {
+ zvrf = zebra_vrf_alloc (vrf_id);
+ *info = (void *)zvrf;
+ }
+
+ return 0;
+}
+
+/* Zebra VRF initialization. */
+static void
+zebra_vrf_init (void)
+{
+ vrf_add_hook (VRF_NEW_HOOK, zebra_vrf_new);
+ vrf_init ();
+}
+
/* Main startup routine. */
int
main (int argc, char **argv)
@@ -294,6 +318,7 @@ main (int argc, char **argv)
access_list_init ();
/* Make kernel routing socket. */
+ zebra_vrf_init ();
kernel_init ();
route_read ();
zebra_vty_init();
diff --git a/zebra/zebra_fpm.c b/zebra/zebra_fpm.c
index 896915c2..292dbb63 100644
--- a/zebra/zebra_fpm.c
+++ b/zebra/zebra_fpm.c
@@ -330,7 +330,7 @@ zfpm_is_table_for_fpm (struct route_table *table)
* We only send the unicast tables in the main instance to the FPM
* at this point.
*/
- if (info->vrf->id != 0)
+ if (info->zvrf->vrf_id != 0)
return 0;
if (info->safi != SAFI_UNICAST)
diff --git a/zebra/zebra_fpm_netlink.c b/zebra/zebra_fpm_netlink.c
index b5f2b760..c4a650d6 100644
--- a/zebra/zebra_fpm_netlink.c
+++ b/zebra/zebra_fpm_netlink.c
@@ -245,7 +245,7 @@ netlink_route_info_fill (netlink_route_info_t *ri, int cmd,
ri->af = rib_dest_af (dest);
ri->nlmsg_type = cmd;
- ri->rtm_table = rib_dest_vrf (dest)->id;
+ ri->rtm_table = rib_dest_vrf (dest)->vrf_id;
ri->rtm_protocol = RTPROT_UNSPEC;
/*
diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c
index f247f1d2..f206205b 100644
--- a/zebra/zebra_rib.c
+++ b/zebra/zebra_rib.c
@@ -34,6 +34,7 @@
#include "workqueue.h"
#include "prefix.h"
#include "routemap.h"
+#include "vrf.h"
#include "zebra/rib.h"
#include "zebra/rt.h"
@@ -72,9 +73,6 @@ static const struct
/* no entry/default: 150 */
};
-/* Vector for routing table. */
-static vector vrf_vector;
-
/* RPF lookup behaviour */
static enum multicast_mode ipv4_multicast_mode = MCAST_NO_CONFIG;
@@ -112,108 +110,6 @@ _rnode_zlog(const char *_func, struct route_node *rn, int priority,
_rnode_zlog(__func__, node, LOG_INFO, __VA_ARGS__)
/*
- * vrf_table_create
- */
-static void
-vrf_table_create (struct vrf *vrf, afi_t afi, safi_t safi)
-{
- rib_table_info_t *info;
- struct route_table *table;
-
- assert (!vrf->table[afi][safi]);
-
- table = route_table_init ();
- vrf->table[afi][safi] = table;
-
- info = XCALLOC (MTYPE_RIB_TABLE_INFO, sizeof (*info));
- info->vrf = vrf;
- info->afi = afi;
- info->safi = safi;
- table->info = info;
-}
-
-/* Allocate new VRF. */
-static struct vrf *
-vrf_alloc (const char *name)
-{
- struct vrf *vrf;
-
- vrf = XCALLOC (MTYPE_VRF, sizeof (struct vrf));
-
- /* Put name. */
- if (name)
- vrf->name = XSTRDUP (MTYPE_VRF_NAME, name);
-
- /* Allocate routing table and static table. */
- vrf_table_create (vrf, AFI_IP, SAFI_UNICAST);
- vrf_table_create (vrf, AFI_IP6, SAFI_UNICAST);
- vrf->stable[AFI_IP][SAFI_UNICAST] = route_table_init ();
- vrf->stable[AFI_IP6][SAFI_UNICAST] = route_table_init ();
- vrf_table_create (vrf, AFI_IP, SAFI_MULTICAST);
- vrf_table_create (vrf, AFI_IP6, SAFI_MULTICAST);
- vrf->stable[AFI_IP][SAFI_MULTICAST] = route_table_init ();
- vrf->stable[AFI_IP6][SAFI_MULTICAST] = route_table_init ();
-
-
- return vrf;
-}
-
-/* Lookup VRF by identifier. */
-struct vrf *
-vrf_lookup (u_int32_t id)
-{
- return vector_lookup (vrf_vector, id);
-}
-
-/* Initialize VRF. */
-static void
-vrf_init (void)
-{
- struct vrf *default_table;
-
- /* Allocate VRF vector. */
- vrf_vector = vector_init (1);
-
- /* Allocate default main table. */
- default_table = vrf_alloc ("Default-IP-Routing-Table");
-
- /* Default table index must be 0. */
- vector_set_index (vrf_vector, 0, default_table);
-}
-
-/* Lookup route table. */
-struct route_table *
-vrf_table (afi_t afi, safi_t safi, u_int32_t id)
-{
- struct vrf *vrf;
-
- vrf = vrf_lookup (id);
- if (! vrf)
- return NULL;
-
- if( afi >= AFI_MAX || safi >= SAFI_MAX )
- return NULL;
-
- return vrf->table[afi][safi];
-}
-
-/* Lookup static route table. */
-struct route_table *
-vrf_static_table (afi_t afi, safi_t safi, u_int32_t id)
-{
- struct vrf *vrf;
-
- vrf = vrf_lookup (id);
- if (! vrf)
- return NULL;
-
- if( afi >= AFI_MAX || safi >= SAFI_MAX )
- return NULL;
-
- return vrf->stable[afi][safi];
-}
-
-/*
* nexthop_type_to_str
*/
const char *
@@ -473,7 +369,7 @@ nexthop_active_ipv4 (struct rib *rib, struct nexthop *nexthop, int set,
p.prefix = nexthop->gate.ipv4;
/* Lookup table. */
- table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
+ table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT);
if (! table)
return 0;
@@ -615,7 +511,7 @@ nexthop_active_ipv6 (struct rib *rib, struct nexthop *nexthop, int set,
p.prefix = nexthop->gate.ipv6;
/* Lookup table. */
- table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);
+ table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT);
if (! table)
return 0;
@@ -731,7 +627,7 @@ rib_match_ipv4_safi (struct in_addr addr, safi_t safi, int skip_bgp,
int recursing;
/* Lookup table. */
- table = vrf_table (AFI_IP, safi, 0);
+ table = zebra_vrf_table (AFI_IP, safi, VRF_DEFAULT);
if (! table)
return 0;
@@ -865,7 +761,7 @@ rib_lookup_ipv4 (struct prefix_ipv4 *p)
int recursing;
/* Lookup table. */
- table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
+ table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT);
if (! table)
return 0;
@@ -922,7 +818,7 @@ rib_lookup_ipv4_route (struct prefix_ipv4 *p, union sockunion * qgate)
int nexthops_active;
/* Lookup table. */
- table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
+ table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT);
if (! table)
return ZEBRA_RIB_LOOKUP_ERROR;
@@ -988,7 +884,7 @@ rib_match_ipv6 (struct in6_addr *addr)
int recursing;
/* Lookup table. */
- table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);
+ table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT);
if (! table)
return 0;
@@ -1907,7 +1803,7 @@ rib_add_ipv4 (int type, int flags, struct prefix_ipv4 *p,
struct nexthop *nexthop;
/* Lookup table. */
- table = vrf_table (AFI_IP, safi, 0);
+ table = zebra_vrf_table (AFI_IP, safi, VRF_DEFAULT);
if (! table)
return 0;
@@ -2071,10 +1967,10 @@ void rib_lookup_and_dump (struct prefix_ipv4 * p)
char prefix_buf[INET_ADDRSTRLEN];
/* Lookup table. */
- table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
+ table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT);
if (! table)
{
- zlog_err ("%s: vrf_table() returned NULL", __func__);
+ zlog_err ("%s: zebra_vrf_table() returned NULL", __func__);
return;
}
@@ -2120,9 +2016,9 @@ void rib_lookup_and_pushup (struct prefix_ipv4 * p)
struct rib *rib;
unsigned changed = 0;
- if (NULL == (table = vrf_table (AFI_IP, SAFI_UNICAST, 0)))
+ if (NULL == (table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT)))
{
- zlog_err ("%s: vrf_table() returned NULL", __func__);
+ zlog_err ("%s: zebra_vrf_table() returned NULL", __func__);
return;
}
@@ -2169,7 +2065,7 @@ rib_add_ipv4_multipath (struct prefix_ipv4 *p, struct rib *rib, safi_t safi)
struct nexthop *nexthop;
/* Lookup table. */
- table = vrf_table (AFI_IP, safi, 0);
+ table = zebra_vrf_table (AFI_IP, safi, VRF_DEFAULT);
if (! table)
return 0;
@@ -2248,7 +2144,7 @@ rib_delete_ipv4 (int type, int flags, struct prefix_ipv4 *p,
char buf2[INET_ADDRSTRLEN];
/* Lookup table. */
- table = vrf_table (AFI_IP, safi, 0);
+ table = zebra_vrf_table (AFI_IP, safi, VRF_DEFAULT);
if (! table)
return 0;
@@ -2380,7 +2276,7 @@ static_install_ipv4 (safi_t safi, struct prefix *p, struct static_ipv4 *si)
struct route_table *table;
/* Lookup table. */
- table = vrf_table (AFI_IP, safi, 0);
+ table = zebra_vrf_table (AFI_IP, safi, VRF_DEFAULT);
if (! table)
return;
@@ -2473,7 +2369,7 @@ static_uninstall_ipv4 (safi_t safi, struct prefix *p, struct static_ipv4 *si)
struct route_table *table;
/* Lookup table. */
- table = vrf_table (AFI_IP, safi, 0);
+ table = zebra_vrf_table (AFI_IP, safi, VRF_DEFAULT);
if (! table)
return;
@@ -2538,7 +2434,7 @@ static_add_ipv4_safi (safi_t safi, struct prefix *p, struct in_addr *gate,
struct route_table *stable;
/* Lookup table. */
- stable = vrf_static_table (AFI_IP, safi, vrf_id);
+ stable = zebra_vrf_static_table (AFI_IP, safi, vrf_id);
if (! stable)
return -1;
@@ -2629,7 +2525,7 @@ static_delete_ipv4_safi (safi_t safi, struct prefix *p, struct in_addr *gate,
struct route_table *stable;
/* Lookup table. */
- stable = vrf_static_table (AFI_IP, safi, vrf_id);
+ stable = zebra_vrf_static_table (AFI_IP, safi, vrf_id);
if (! stable)
return -1;
@@ -2695,7 +2591,7 @@ rib_add_ipv6 (int type, int flags, struct prefix_ipv6 *p,
struct nexthop *nexthop;
/* Lookup table. */
- table = vrf_table (AFI_IP6, safi, 0);
+ table = zebra_vrf_table (AFI_IP6, safi, VRF_DEFAULT);
if (! table)
return 0;
@@ -2806,7 +2702,7 @@ rib_delete_ipv6 (int type, int flags, struct prefix_ipv6 *p,
apply_mask_ipv6 (p);
/* Lookup table. */
- table = vrf_table (AFI_IP6, safi, 0);
+ table = zebra_vrf_table (AFI_IP6, safi, VRF_DEFAULT);
if (! table)
return 0;
@@ -2923,7 +2819,7 @@ static_install_ipv6 (struct prefix *p, struct static_ipv6 *si)
struct route_node *rn;
/* Lookup table. */
- table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);
+ table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT);
if (! table)
return;
@@ -3018,7 +2914,7 @@ static_uninstall_ipv6 (struct prefix *p, struct static_ipv6 *si)
struct nexthop *nexthop;
/* Lookup table. */
- table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);
+ table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT);
if (! table)
return;
@@ -3084,7 +2980,7 @@ static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
struct route_table *stable;
/* Lookup table. */
- stable = vrf_static_table (AFI_IP6, SAFI_UNICAST, vrf_id);
+ stable = zebra_vrf_static_table (AFI_IP6, SAFI_UNICAST, vrf_id);
if (! stable)
return -1;
@@ -3169,7 +3065,7 @@ static_delete_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
struct route_table *stable;
/* Lookup table. */
- stable = vrf_static_table (AFI_IP6, SAFI_UNICAST, vrf_id);
+ stable = zebra_vrf_static_table (AFI_IP6, SAFI_UNICAST, vrf_id);
if (! stable)
return -1;
@@ -3220,13 +3116,13 @@ rib_update (void)
struct route_node *rn;
struct route_table *table;
- table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
+ table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT);
if (table)
for (rn = route_top (table); rn; rn = route_next (rn))
if (rnode_to_ribs (rn))
rib_queue_add (&zebrad, rn);
- table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);
+ table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT);
if (table)
for (rn = route_top (table); rn; rn = route_next (rn))
if (rnode_to_ribs (rn))
@@ -3259,8 +3155,8 @@ rib_weed_table (struct route_table *table)
void
rib_weed_tables (void)
{
- rib_weed_table (vrf_table (AFI_IP, SAFI_UNICAST, 0));
- rib_weed_table (vrf_table (AFI_IP6, SAFI_UNICAST, 0));
+ rib_weed_table (zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT));
+ rib_weed_table (zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT));
}
/* Delete self installed routes after zebra is relaunched. */
@@ -3293,8 +3189,8 @@ rib_sweep_table (struct route_table *table)
void
rib_sweep_route (void)
{
- rib_sweep_table (vrf_table (AFI_IP, SAFI_UNICAST, 0));
- rib_sweep_table (vrf_table (AFI_IP6, SAFI_UNICAST, 0));
+ rib_sweep_table (zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT));
+ rib_sweep_table (zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT));
}
/* Remove specific by protocol routes from 'table'. */
@@ -3326,8 +3222,8 @@ rib_score_proto_table (u_char proto, struct route_table *table)
unsigned long
rib_score_proto (u_char proto)
{
- return rib_score_proto_table (proto, vrf_table (AFI_IP, SAFI_UNICAST, 0))
- +rib_score_proto_table (proto, vrf_table (AFI_IP6, SAFI_UNICAST, 0));
+ return rib_score_proto_table (proto, zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT))
+ +rib_score_proto_table (proto, zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT));
}
/* Close RIB and clean up kernel routes. */
@@ -3357,8 +3253,8 @@ rib_close_table (struct route_table *table)
void
rib_close (void)
{
- rib_close_table (vrf_table (AFI_IP, SAFI_UNICAST, 0));
- rib_close_table (vrf_table (AFI_IP6, SAFI_UNICAST, 0));
+ rib_close_table (zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT));
+ rib_close_table (zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT));
}
/* Routing information base initialize. */
@@ -3366,8 +3262,6 @@ void
rib_init (void)
{
rib_queue_init (&zebrad);
- /* VRF initialization. */
- vrf_init ();
}
/*
@@ -3378,15 +3272,19 @@ rib_init (void)
* Returns TRUE if a vrf id was found, FALSE otherwise.
*/
static inline int
-vrf_id_get_next (uint32_t id, uint32_t *next_id_p)
+vrf_id_get_next (vrf_id_t vrf_id, vrf_id_t *next_id_p)
{
- while (++id < vector_active (vrf_vector))
+ vrf_iter_t iter = vrf_iterator (vrf_id);
+ struct zebra_vrf *zvrf = vrf_iter2info (iter);
+
+ /* The same one ? Then find out the next. */
+ if (zvrf && (zvrf->vrf_id == vrf_id))
+ zvrf = vrf_iter2info (vrf_next (iter));
+
+ if (zvrf)
{
- if (vrf_lookup (id))
- {
- *next_id_p = id;
- return 1;
- }
+ *next_id_p = zvrf->vrf_id;
+ return 1;
}
return 0;
@@ -3434,7 +3332,7 @@ rib_tables_iter_next (rib_tables_iter_t *iter)
while (iter->afi_safi_ix < (int) ZEBRA_NUM_OF (afi_safis))
{
- table = vrf_table (afi_safis[iter->afi_safi_ix].afi,
+ table = zebra_vrf_table (afi_safis[iter->afi_safi_ix].afi,
afi_safis[iter->afi_safi_ix].safi,
iter->vrf_id);
if (table)
@@ -3472,3 +3370,79 @@ rib_tables_iter_next (rib_tables_iter_t *iter)
return table;
}
+
+/*
+ * Create a routing table for the specific AFI/SAFI in the given VRF.
+ */
+static void
+zebra_vrf_table_create (struct zebra_vrf *zvrf, afi_t afi, safi_t safi)
+{
+ rib_table_info_t *info;
+ struct route_table *table;
+
+ assert (!zvrf->table[afi][safi]);
+
+ table = route_table_init ();
+ zvrf->table[afi][safi] = table;
+
+ info = XCALLOC (MTYPE_RIB_TABLE_INFO, sizeof (*info));
+ info->zvrf = zvrf;
+ info->afi = afi;
+ info->safi = safi;
+ table->info = info;
+}
+
+/* Allocate new zebra VRF. */
+struct zebra_vrf *
+zebra_vrf_alloc (vrf_id_t vrf_id)
+{
+ struct zebra_vrf *zvrf;
+
+ zvrf = XCALLOC (MTYPE_ZEBRA_VRF, sizeof (struct zebra_vrf));
+
+ /* Allocate routing table and static table. */
+ zebra_vrf_table_create (zvrf, AFI_IP, SAFI_UNICAST);
+ zebra_vrf_table_create (zvrf, AFI_IP6, SAFI_UNICAST);
+ zvrf->stable[AFI_IP][SAFI_UNICAST] = route_table_init ();
+ zvrf->stable[AFI_IP6][SAFI_UNICAST] = route_table_init ();
+ zebra_vrf_table_create (zvrf, AFI_IP, SAFI_MULTICAST);
+ zebra_vrf_table_create (zvrf, AFI_IP6, SAFI_MULTICAST);
+ zvrf->stable[AFI_IP][SAFI_MULTICAST] = route_table_init ();
+ zvrf->stable[AFI_IP6][SAFI_MULTICAST] = route_table_init ();
+
+ /* Set VRF ID */
+ zvrf->vrf_id = vrf_id;
+
+ return zvrf;
+}
+
+/* Lookup the routing table in an enabled VRF. */
+struct route_table *
+zebra_vrf_table (afi_t afi, safi_t safi, vrf_id_t vrf_id)
+{
+ struct zebra_vrf *zvrf = vrf_info_lookup (vrf_id);
+
+ if (!zvrf)
+ return NULL;
+
+ if (afi >= AFI_MAX || safi >= SAFI_MAX)
+ return NULL;
+
+ return zvrf->table[afi][safi];
+}
+
+/* Lookup the static routing table in a VRF. */
+struct route_table *
+zebra_vrf_static_table (afi_t afi, safi_t safi, vrf_id_t vrf_id)
+{
+ struct zebra_vrf *zvrf = vrf_info_lookup (vrf_id);
+
+ if (!zvrf)
+ return NULL;
+
+ if (afi >= AFI_MAX || safi >= SAFI_MAX)
+ return NULL;
+
+ return zvrf->stable[afi][safi];
+}
+
diff --git a/zebra/zebra_snmp.c b/zebra/zebra_snmp.c
index f0d3e7e5..3d005aa5 100644
--- a/zebra/zebra_snmp.c
+++ b/zebra/zebra_snmp.c
@@ -19,6 +19,10 @@
* 02111-1307, USA.
*/
+/*
+ * Currently SNMP is only running properly for MIBs in the default VRF.
+ */
+
#include <zebra.h>
#ifdef HAVE_SNMP
@@ -31,6 +35,7 @@
#include "command.h"
#include "smux.h"
#include "table.h"
+#include "vrf.h"
#include "zebra/rib.h"
#include "zebra/zserv.h"
@@ -143,7 +148,7 @@ ipFwNumber (struct variable *v, oid objid[], size_t *objid_len,
if (smux_header_generic(v, objid, objid_len, exact, val_len, write_method) == MATCH_FAILED)
return NULL;
- table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
+ table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT);
if (! table)
return NULL;
@@ -168,7 +173,7 @@ ipCidrNumber (struct variable *v, oid objid[], size_t *objid_len,
if (smux_header_generic(v, objid, objid_len, exact, val_len, write_method) == MATCH_FAILED)
return NULL;
- table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
+ table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT);
if (! table)
return 0;
@@ -330,7 +335,7 @@ get_fwtable_route_node(struct variable *v, oid objid[], size_t *objid_len,
if (exact && (*objid_len != (unsigned) v->namelen + 10))
return;
- table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
+ table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT);
if (! table)
return;
diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c
index bc453de9..a4e6af78 100644
--- a/zebra/zebra_vty.c
+++ b/zebra/zebra_vty.c
@@ -27,6 +27,7 @@
#include "command.h"
#include "table.h"
#include "rib.h"
+#include "vrf.h"
#include "zebra/zserv.h"
@@ -989,7 +990,7 @@ static int do_show_ip_route(struct vty *vty, safi_t safi) {
struct rib *rib;
int first = 1;
- table = vrf_table (AFI_IP, safi, 0);
+ table = zebra_vrf_table (AFI_IP, safi, VRF_DEFAULT);
if (! table)
return CMD_SUCCESS;
@@ -1030,7 +1031,7 @@ DEFUN (show_ip_route_prefix_longer,
return CMD_WARNING;
}
- table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
+ table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT);
if (! table)
return CMD_SUCCESS;
@@ -1063,7 +1064,7 @@ DEFUN (show_ip_route_supernets,
u_int32_t addr;
int first = 1;
- table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
+ table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT);
if (! table)
return CMD_SUCCESS;
@@ -1109,7 +1110,7 @@ DEFUN (show_ip_route_protocol,
return CMD_WARNING;
}
- table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
+ table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT);
if (! table)
return CMD_SUCCESS;
@@ -1148,7 +1149,7 @@ DEFUN (show_ip_route_addr,
return CMD_WARNING;
}
- table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
+ table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT);
if (! table)
return CMD_SUCCESS;
@@ -1186,7 +1187,7 @@ DEFUN (show_ip_route_prefix,
return CMD_WARNING;
}
- table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
+ table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT);
if (! table)
return CMD_SUCCESS;
@@ -1359,7 +1360,7 @@ DEFUN (show_ip_route_summary,
{
struct route_table *table;
- table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
+ table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT);
if (! table)
return CMD_SUCCESS;
@@ -1380,7 +1381,7 @@ DEFUN (show_ip_route_summary_prefix,
{
struct route_table *table;
- table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
+ table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT);
if (! table)
return CMD_SUCCESS;
@@ -1402,7 +1403,7 @@ static_config_ipv4 (struct vty *vty, safi_t safi, const char *cmd)
write = 0;
/* Lookup table. */
- stable = vrf_static_table (AFI_IP, safi, 0);
+ stable = zebra_vrf_static_table (AFI_IP, safi, VRF_DEFAULT);
if (! stable)
return -1;
@@ -1489,7 +1490,7 @@ DEFUN (show_ip_mroute,
struct rib *rib;
int first = 1;
- table = vrf_table (AFI_IP, SAFI_MULTICAST, 0);
+ table = zebra_vrf_table (AFI_IP, SAFI_MULTICAST, VRF_DEFAULT);
if (! table)
return CMD_SUCCESS;
@@ -1826,7 +1827,7 @@ DEFUN (show_ipv6_route,
struct rib *rib;
int first = 1;
- table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);
+ table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT);
if (! table)
return CMD_SUCCESS;
@@ -1860,7 +1861,7 @@ DEFUN (show_ipv6_route_prefix_longer,
int ret;
int first = 1;
- table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);
+ table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT);
if (! table)
return CMD_SUCCESS;
@@ -1907,7 +1908,7 @@ DEFUN (show_ipv6_route_protocol,
return CMD_WARNING;
}
- table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);
+ table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT);
if (! table)
return CMD_SUCCESS;
@@ -1946,7 +1947,7 @@ DEFUN (show_ipv6_route_addr,
return CMD_WARNING;
}
- table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);
+ table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT);
if (! table)
return CMD_SUCCESS;
@@ -1984,7 +1985,7 @@ DEFUN (show_ipv6_route_prefix,
return CMD_WARNING;
}
- table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);
+ table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT);
if (! table)
return CMD_SUCCESS;
@@ -2015,7 +2016,7 @@ DEFUN (show_ipv6_route_summary,
{
struct route_table *table;
- table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);
+ table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT);
if (! table)
return CMD_SUCCESS;
@@ -2036,7 +2037,7 @@ DEFUN (show_ipv6_route_summary_prefix,
{
struct route_table *table;
- table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);
+ table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT);
if (! table)
return CMD_SUCCESS;
@@ -2062,7 +2063,7 @@ DEFUN (show_ipv6_mroute,
struct rib *rib;
int first = 1;
- table = vrf_table (AFI_IP6, SAFI_MULTICAST, 0);
+ table = zebra_vrf_table (AFI_IP6, SAFI_MULTICAST, VRF_DEFAULT);
if (! table)
return CMD_SUCCESS;
@@ -2093,7 +2094,7 @@ static_config_ipv6 (struct vty *vty)
write = 0;
/* Lookup table. */
- stable = vrf_static_table (AFI_IP6, SAFI_UNICAST, 0);
+ stable = zebra_vrf_static_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT);
if (! stable)
return -1;