summaryrefslogtreecommitdiffstats
path: root/zebra/zebra_ns.c
diff options
context:
space:
mode:
authorDonald Sharp <sharpd@cumulusnetworks.com>2018-02-14 02:25:11 +0100
committerDonald Sharp <sharpd@cumulusnetworks.com>2018-02-23 13:08:36 +0100
commit5335613bc741a45a2f307e66b73b4f1303567146 (patch)
tree750eea82e462498314e038778c17532538a23f9f /zebra/zebra_ns.c
parentMerge pull request #1793 from qlyoung/stylechecker (diff)
downloadfrr-5335613bc741a45a2f307e66b73b4f1303567146.tar.xz
frr-5335613bc741a45a2f307e66b73b4f1303567146.zip
zebra: Move zvrf->other_tables into zns
The other_tables data structure does not belong to a vrf. It belongs to the zns. This is because each vrf does not need to have copies of each of other_tables. Additionally move the array into a RB_TREE. This will allow us to sort quickly and easily expand the number of tables we can support to beyond the ZEBRA_KERNEL_TABLE_MAX define. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
Diffstat (limited to 'zebra/zebra_ns.c')
-rw-r--r--zebra/zebra_ns.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/zebra/zebra_ns.c b/zebra/zebra_ns.c
index c48a6f7bd..91dbd3438 100644
--- a/zebra/zebra_ns.c
+++ b/zebra/zebra_ns.c
@@ -34,8 +34,25 @@
DEFINE_MTYPE(ZEBRA, ZEBRA_NS, "Zebra Name Space")
+static __inline int
+zebra_ns_table_entry_compare(const struct zebra_ns_table *e1,
+ const struct zebra_ns_table *e2);
+
+RB_GENERATE(zebra_ns_table_head, zebra_ns_table, zebra_ns_table_entry,
+ zebra_ns_table_entry_compare);
+
static struct zebra_ns *dzns;
+static __inline int
+zebra_ns_table_entry_compare(const struct zebra_ns_table *e1,
+ const struct zebra_ns_table *e2)
+{
+ if (e1->tableid == e2->tableid)
+ return (e1->afi - e2->afi);
+
+ return e1->tableid - e2->tableid;
+}
+
struct zebra_ns *zebra_ns_lookup(ns_id_t ns_id)
{
return dzns;
@@ -57,10 +74,61 @@ int zebra_ns_enable(ns_id_t ns_id, void **info)
return 0;
}
+struct route_table *zebra_ns_get_table(struct zebra_ns *zns,
+ struct zebra_vrf *zvrf, uint32_t tableid,
+ afi_t afi)
+{
+ struct zebra_ns_table finder;
+ struct zebra_ns_table *znst;
+ rib_table_info_t *info;
+
+ memset(&finder, 0, sizeof(finder));
+ finder.afi = afi;
+ finder.tableid = tableid;
+ znst = RB_FIND(zebra_ns_table_head, &zns->ns_tables, &finder);
+
+ if (znst)
+ return znst->table;
+
+ znst = XCALLOC(MTYPE_ZEBRA_NS, sizeof(*znst));
+ znst->tableid = tableid;
+ znst->afi = afi;
+ znst->table =
+ (afi == AFI_IP6) ? srcdest_table_init() : route_table_init();
+
+ info = XCALLOC(MTYPE_RIB_TABLE_INFO, sizeof(*info));
+ info->zvrf = zvrf;
+ info->afi = afi;
+ info->safi = SAFI_UNICAST;
+ znst->table->info = info;
+ znst->table->cleanup = zebra_rtable_node_cleanup;
+
+ RB_INSERT(zebra_ns_table_head, &zns->ns_tables, znst);
+ return znst->table;
+}
+
+static struct zebra_ns_table *zebra_ns_free_table(struct zebra_ns_table *znst)
+{
+ void *table_info;
+ rib_close_table(znst->table);
+
+ table_info = znst->table->info;
+ route_table_finish(znst->table);
+ XFREE(MTYPE_RIB_TABLE_INFO, table_info);
+ XFREE(MTYPE_ZEBRA_NS, znst);
+ return NULL;
+}
+
int zebra_ns_disable(ns_id_t ns_id, void **info)
{
+ struct zebra_ns_table *znst;
struct zebra_ns *zns = (struct zebra_ns *)(*info);
+ while ((znst = RB_ROOT(zebra_ns_table_head, &zns->ns_tables))
+ != NULL) {
+ RB_REMOVE(zebra_ns_table_head, &zns->ns_tables, znst);
+ znst = zebra_ns_free_table(znst);
+ }
route_table_finish(zns->if_table);
zebra_vxlan_ns_disable(zns);
#if defined(HAVE_RTADV)
@@ -72,6 +140,7 @@ int zebra_ns_disable(ns_id_t ns_id, void **info)
return 0;
}
+
int zebra_ns_init(void)
{
dzns = XCALLOC(MTYPE_ZEBRA_NS, sizeof(struct zebra_ns));