summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorharios_niral <hari@niralnetworks.com>2021-05-05 23:17:01 +0300
committerIgor Ryzhov <iryzhov@nfware.com>2021-05-05 23:17:01 +0300
commit4e8ccd9213519aac429036d382c1e64b1f452932 (patch)
tree4035c1e36ab301d9a8750d1c6524f7615607b0ec
parent98d742c6f7c135729879188a6911f88acfafde4d (diff)
ospf6d: add internal support for multiple vrfs
Co-authored-by: Kaushik Nath <kaushiknath.null@gmail.com> Signed-off-by: harios_niral <hari@niralnetworks.com>
-rw-r--r--ospf6d/ospf6_main.c2
-rw-r--r--ospf6d/ospf6_top.c103
-rw-r--r--ospf6d/ospf6_top.h2
3 files changed, 105 insertions, 2 deletions
diff --git a/ospf6d/ospf6_main.c b/ospf6d/ospf6_main.c
index cf61ca7a62..5ffcf8c2fa 100644
--- a/ospf6d/ospf6_main.c
+++ b/ospf6d/ospf6_main.c
@@ -225,7 +225,7 @@ int main(int argc, char *argv[], char *envp[])
/* thread master */
master = om6->master;
- vrf_init(NULL, NULL, NULL, NULL, NULL);
+ ospf6_vrf_init();
access_list_init();
prefix_list_init();
diff --git a/ospf6d/ospf6_top.c b/ospf6d/ospf6_top.c
index 8c6d4b126d..5d26c513f6 100644
--- a/ospf6d/ospf6_top.c
+++ b/ospf6d/ospf6_top.c
@@ -124,6 +124,104 @@ struct ospf6 *ospf6_lookup_by_vrf_name(const char *name)
return NULL;
}
+/* This is hook function for vrf create called as part of vrf_init */
+static int ospf6_vrf_new(struct vrf *vrf)
+{
+ return 0;
+}
+
+/* This is hook function for vrf delete call as part of vrf_init */
+static int ospf6_vrf_delete(struct vrf *vrf)
+{
+ return 0;
+}
+
+static void ospf6_set_redist_vrf_bitmaps(struct ospf6 *ospf6, bool set)
+{
+ int type;
+ struct list *red_list;
+
+ for (type = 0; type < ZEBRA_ROUTE_MAX; type++) {
+ red_list = ospf6->redist[type];
+ if (!red_list)
+ continue;
+ if (IS_OSPF6_DEBUG_ZEBRA(RECV))
+ zlog_debug(
+ "%s: setting redist vrf %d bitmap for type %d",
+ __func__, ospf6->vrf_id, type);
+ if (set)
+ vrf_bitmap_set(zclient->redist[AFI_IP6][type],
+ ospf6->vrf_id);
+ else
+ vrf_bitmap_unset(zclient->redist[AFI_IP6][type],
+ ospf6->vrf_id);
+ }
+}
+
+/* Disable OSPF6 VRF instance */
+static int ospf6_vrf_disable(struct vrf *vrf)
+{
+ struct ospf6 *ospf6 = NULL;
+
+ if (vrf->vrf_id == VRF_DEFAULT)
+ return 0;
+
+ ospf6 = ospf6_lookup_by_vrf_name(vrf->name);
+ if (ospf6) {
+ ospf6_zebra_vrf_deregister(ospf6);
+
+ ospf6_set_redist_vrf_bitmaps(ospf6, false);
+
+ /* We have instance configured, unlink
+ * from VRF and make it "down".
+ */
+ ospf6_vrf_unlink(ospf6, vrf);
+ thread_cancel(&ospf6->t_ospf6_receive);
+ close(ospf6->fd);
+ ospf6->fd = -1;
+ }
+
+ /* Note: This is a callback, the VRF will be deleted by the caller. */
+ return 0;
+}
+
+/* Enable OSPF6 VRF instance */
+static int ospf6_vrf_enable(struct vrf *vrf)
+{
+ struct ospf6 *ospf6 = NULL;
+ vrf_id_t old_vrf_id;
+ int ret = 0;
+
+ ospf6 = ospf6_lookup_by_vrf_name(vrf->name);
+ if (ospf6) {
+ old_vrf_id = ospf6->vrf_id;
+ /* We have instance configured, link to VRF and make it "up". */
+ ospf6_vrf_link(ospf6, vrf);
+
+ if (old_vrf_id != ospf6->vrf_id) {
+ ospf6_set_redist_vrf_bitmaps(ospf6, true);
+
+ /* start zebra redist to us for new vrf */
+ ospf6_zebra_vrf_register(ospf6);
+
+ ret = ospf6_serv_sock(ospf6);
+ if (ret < 0 || ospf6->fd <= 0)
+ return 0;
+ thread_add_read(master, ospf6_receive, ospf6, ospf6->fd,
+ &ospf6->t_ospf6_receive);
+
+ ospf6_router_id_update(ospf6);
+ }
+ }
+
+ return 0;
+}
+
+void ospf6_vrf_init(void)
+{
+ vrf_init(ospf6_vrf_new, ospf6_vrf_enable, ospf6_vrf_disable,
+ ospf6_vrf_delete, ospf6_vrf_enable);
+}
static void ospf6_top_lsdb_hook_add(struct ospf6_lsa *lsa)
{
@@ -292,6 +390,9 @@ struct ospf6 *ospf6_instance_create(const char *name)
if (ospf6->router_id == 0)
ospf6_router_id_update(ospf6);
ospf6_add(ospf6);
+ if (ospf6->fd < 0)
+ return ospf6;
+
thread_add_read(master, ospf6_receive, ospf6, ospf6->fd,
&ospf6->t_ospf6_receive);
@@ -309,6 +410,8 @@ void ospf6_delete(struct ospf6 *o)
ospf6_disable(o);
ospf6_del(o);
+ ospf6_zebra_vrf_deregister(o);
+
ospf6_serv_close(&o->fd);
for (ALL_LIST_ELEMENTS(o->area_list, node, nnode, oa))
diff --git a/ospf6d/ospf6_top.h b/ospf6d/ospf6_top.h
index 08b884f23a..9ba5a0f9a4 100644
--- a/ospf6d/ospf6_top.h
+++ b/ospf6d/ospf6_top.h
@@ -171,5 +171,5 @@ void ospf6_vrf_unlink(struct ospf6 *ospf6, struct vrf *vrf);
struct ospf6 *ospf6_lookup_by_vrf_id(vrf_id_t vrf_id);
struct ospf6 *ospf6_lookup_by_vrf_name(const char *name);
const char *ospf6_vrf_id_to_name(vrf_id_t vrf_id);
-
+void ospf6_vrf_init(void);
#endif /* OSPF6_TOP_H */