2003-04-04 Paul Jakma <paul@dishone.st>
* Sync to Zebra CVS
* Fix lib/thread.h leak
* Fix small Opaque LSA leak
* Do not configure OSPF interfaces for secondary addresses
* vtysh fixes from Hasso
* Dave Watson's missing ntohs fix
diff --git a/ospfd/ospfd.c b/ospfd/ospfd.c
index a98d5be..099af55 100644
--- a/ospfd/ospfd.c
+++ b/ospfd/ospfd.c
@@ -52,8 +52,12 @@
#include "ospfd/ospf_route.h"
#include "ospfd/ospf_ase.h"
-/* OSPF instance top. */
-struct ospf *ospf_top;
+
+/* OSPF process wide configuration. */
+static struct ospf_master ospf_master;
+
+/* OSPF process wide configuration pointer to export. */
+struct ospf_master *om;
extern struct zclient *zclient;
@@ -148,7 +152,7 @@
int
ospf_router_id_update_timer (struct thread *thread)
{
- struct ospf *ospf = ospf_top;
+ struct ospf *ospf = THREAD_ARG (thread);
if (IS_DEBUG_OSPF_EVENT)
zlog_info ("Router-ID: Update timer fired!");
@@ -182,7 +186,6 @@
new->router_id_static.s_addr = htonl (0);
new->abr_type = OSPF_ABR_STAND;
- new->iflist = iflist;
new->oiflist = list_new ();
new->vlinks = list_new ();
new->areas = list_new ();
@@ -235,23 +238,44 @@
}
struct ospf *
+ospf_lookup ()
+{
+ if (listcount (om->ospf) == 0)
+ return NULL;
+
+ return getdata (listhead (om->ospf));
+}
+
+void
+ospf_add (struct ospf *ospf)
+{
+ listnode_add (om->ospf, ospf);
+}
+
+void
+ospf_delete (struct ospf *ospf)
+{
+ listnode_delete (om->ospf, ospf);
+}
+
+struct ospf *
ospf_get ()
{
- struct ospf *ospf = ospf_top;
+ struct ospf *ospf;
- if (ospf != NULL)
- return ospf;
+ ospf = ospf_lookup ();
+ if (ospf == NULL)
+ {
+ ospf = ospf_new ();
+ ospf_add (ospf);
- ospf = ospf_new ();
-
- if (ospf->router_id_static.s_addr == 0)
- ospf_router_id_update (ospf);
+ if (ospf->router_id_static.s_addr == 0)
+ ospf_router_id_update (ospf);
#ifdef HAVE_OPAQUE_LSA
- ospf_opaque_type11_lsa_init (ospf);
+ ospf_opaque_type11_lsa_init (ospf);
#endif /* HAVE_OPAQUE_LSA */
-
- ospf_top = ospf;
+ }
return ospf;
}
@@ -271,7 +295,7 @@
/* Unredister redistribution */
for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
- ospf_redistribute_unset (i);
+ ospf_redistribute_unset (ospf, i);
for (node = listhead (ospf->areas); node;)
{
@@ -420,9 +444,9 @@
ospf_distance_reset (ospf);
route_table_finish (ospf->distance_table);
- XFREE (MTYPE_OSPF_TOP, ospf);
+ ospf_delete (ospf);
- ospf_top = NULL;
+ XFREE (MTYPE_OSPF_TOP, ospf);
}
@@ -706,13 +730,12 @@
if (ospf->router_id_static.s_addr == 0)
if (ospf->t_router_id_update == NULL)
{
- ospf->t_router_id_update =
- thread_add_timer (master, ospf_router_id_update_timer, ospf,
- OSPF_ROUTER_ID_UPDATE_DELAY);
+ OSPF_TIMER_ON (ospf->t_router_id_update, ospf_router_id_update_timer,
+ OSPF_ROUTER_ID_UPDATE_DELAY);
}
/* Get target interface. */
- for (node = listhead (ospf->iflist); node; nextnode (node))
+ for (node = listhead (om->iflist); node; nextnode (node))
{
listnode cn;
@@ -845,9 +868,9 @@
if (ospf->router_id_static.s_addr == 0)
if (ospf->t_router_id_update == NULL)
{
- ospf->t_router_id_update =
- thread_add_timer (master, ospf_router_id_update_timer, NULL,
- OSPF_ROUTER_ID_UPDATE_DELAY);
+ OSPF_TIMER_ON (ospf->t_router_id_update,
+ ospf_router_id_update_timer,
+ OSPF_ROUTER_ID_UPDATE_DELAY);
}
/* Find interfaces that not configured already. */
@@ -1586,12 +1609,13 @@
void
ospf_prefix_list_update (struct prefix_list *plist)
{
- struct ospf *ospf = ospf_top;
+ struct ospf *ospf;
struct ospf_area *area;
listnode node;
int abr_inv = 0;
/* If OSPF instatnce does not exist, return right now. */
+ ospf = ospf_lookup ();
if (ospf == NULL)
return;
@@ -1620,16 +1644,24 @@
}
/* Schedule ABR tasks. */
- if (OSPF_IS_ABR && abr_inv)
+ if (IS_OSPF_ABR (ospf) && abr_inv)
ospf_schedule_abr_task (ospf);
}
void
+ospf_master_init ()
+{
+ memset (&ospf_master, 0, sizeof (struct ospf_master));
+
+ om = &ospf_master;
+ om->ospf = list_new ();
+ om->master = thread_master_create ();
+ om->start_time = time (NULL);
+}
+
+void
ospf_init ()
{
- /* Make empty list of ospf list. */
- ospf_top = NULL;
-
prefix_list_add_hook (ospf_prefix_list_update);
prefix_list_delete_hook (ospf_prefix_list_update);
}