]> git.proxmox.com Git - mirror_frr.git/commitdiff
2003-04-04 Paul Jakma <paul@dishone.st>
authorpaul <paul>
Fri, 4 Apr 2003 02:44:16 +0000 (02:44 +0000)
committerpaul <paul>
Fri, 4 Apr 2003 02:44:16 +0000 (02:44 +0000)
        * 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

14 files changed:
ChangeLog
bgpd/bgp_snmp.c
lib/smux.c
ospfd/ospf_interface.c
ospfd/ospf_lsa.c
ospfd/ospf_main.c
ospfd/ospf_opaque.c
ospfd/ospf_packet.c
ospfd/ospf_snmp.c
ospfd/ospf_spf.c
ospfd/ospf_vty.c
ospfd/ospf_zebra.c
ospfd/ospfd.c
ospfd/ospfd.h

index 57fdf48a788b0637bdf03dd684882ae4eb252339..8e33624342b8f7c07f8a377d77715e2653751d8b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+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
+
 2003-03-25 Paul Jakma <paul@dishone.st>
 
        * Sync to Zebra CVS
index 822036c1813a28bd345906aa62d2367cdad6a804..8104aefbc7bf8e72381525d6d99edc08fd1406d8 100644 (file)
@@ -45,6 +45,10 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 /* BGP4-MIB described in RFC1657. */
 #define BGP4MIB 1,3,6,1,2,1,15
 
+/* BGP TRAP. */
+#define BGPESTABLISHED                 1
+#define BGPBACKWARDTRANSITION          2       
+
 /* Zebra enterprise BGP MIB.  This variable is used for register
    OSPF MIB to SNMP agent under SMUX protocol.  */
 #define BGPDMIB 1,3,6,1,4,1,3317,1,2,2
@@ -846,7 +850,7 @@ bgpTrapEstablished (struct peer *peer)
   smux_trap (bgp_oid, sizeof bgp_oid / sizeof (oid),
             index, IN_ADDR_SIZE,
             bgpTrapList, sizeof bgpTrapList / sizeof (struct trap_object),
-            bm->start_time - time (NULL));
+            bm->start_time - time (NULL), BGPESTABLISHED);
 }
 
 void
@@ -865,7 +869,7 @@ bgpTrapBackwardTransition (struct peer *peer)
   smux_trap (bgp_oid, sizeof bgp_oid / sizeof (oid),
             index, IN_ADDR_SIZE,
             bgpTrapList, sizeof bgpTrapList / sizeof (struct trap_object),
-            bm->start_time - time (NULL));
+            bm->start_time - time (NULL), BGPBACKWARDTRANSITION);
 }
 
 void
index 047929260d0d966e69855f406577adbc038146d5..952c5a81d68fb89e29242eba49d862140be93676 100644 (file)
@@ -999,7 +999,7 @@ int
 smux_trap (oid *name, size_t namelen,
           oid *iname, size_t inamelen,
           struct trap_object *trapobj, size_t trapobjlen,
-          unsigned int tick)
+          unsigned int tick, u_char sptrap)
 {
   int i;
   u_char buf[BUFSIZ];
@@ -1040,7 +1040,7 @@ smux_trap (oid *name, size_t namelen,
                       &val, sizeof (int));
 
   /* Specific trap integer. */
-  val = 2;
+  val = sptrap;
   ptr = asn_build_int (ptr, &len, 
                       (u_char)(ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER),
                       &val, sizeof (int));
index 551adcf7156d29a41a015f8848787043de629d2a..270b16b97c1b036e2eacab8cd13e874f2fdd7b5a 100644 (file)
@@ -1064,6 +1064,7 @@ ospf_if_init ()
 {
   /* Initialize Zebra interface data structure. */
   if_init ();
+  om->iflist = iflist;
   if_add_hook (IF_NEW_HOOK, ospf_if_new_hook);
   if_add_hook (IF_DELETE_HOOK, ospf_if_delete_hook);
 }
index 45b554fb052258e608daef2ca3310aa3123de797..9c81327e10710e8ff33a0557be7d19713c340099 100644 (file)
@@ -1638,7 +1638,7 @@ ospf_install_flood_nssa (struct ospf *ospf,
       new2->data->type = OSPF_AS_NSSA_LSA;
 
       /* set P-bit if not ABR */
-      if (! OSPF_IS_ABR)
+      if (! IS_OSPF_ABR (ospf))
         {
          SET_FLAG(new2->data->options, OSPF_OPTION_NP);
        
@@ -1799,12 +1799,11 @@ ospf_external_lsa_originate_timer (struct thread *thread)
 }
 
 struct external_info *
-ospf_default_external_info ()
+ospf_default_external_info (struct ospf *ospf)
 {
   int type;
   struct route_node *rn;
   struct prefix_ipv4 p;
-  struct ospf *ospf = ospf_top;
   
   p.family = AF_INET;
   p.prefix.s_addr = 0;
@@ -1834,8 +1833,10 @@ ospf_default_originate_timer (struct thread *thread)
   struct prefix_ipv4 p;
   struct in_addr nexthop;
   struct external_info *ei;
-  struct ospf *ospf = ospf_top;
+  struct ospf *ospf;
   
+  ospf = ospf_lookup ();
+
   /* Get originate flags. */
   origin = THREAD_ARG (thread);
 
@@ -1851,7 +1852,7 @@ ospf_default_originate_timer (struct thread *thread)
       ospf_external_info_add (DEFAULT_ROUTE, p, 0, nexthop);
     }
 
-  if ((ei = ospf_default_external_info ()))
+  if ((ei = ospf_default_external_info (ospf)))
     ospf_external_lsa_originate (ospf, ei);
   
   return 0;
@@ -1911,7 +1912,7 @@ ospf_external_lsa_refresh_default (struct ospf *ospf)
   p.prefixlen = 0;
   p.prefix.s_addr = 0;
 
-  ei = ospf_default_external_info ();
+  ei = ospf_default_external_info (ospf);
   lsa = ospf_external_info_find_lsa (ospf, &p);
 
   if (ei)
@@ -2694,7 +2695,7 @@ ospf_lsa_lookup (struct ospf_area *area, u_int32_t type,
 #ifdef HAVE_OPAQUE_LSA
     case OSPF_OPAQUE_AS_LSA:
 #endif /* HAVE_OPAQUE_LSA */
-      return ospf_lsdb_lookup_by_id (ospf_top->lsdb, type, id, adv_router);
+      return ospf_lsdb_lookup_by_id (area->ospf->lsdb, type, id, adv_router);
       break;
     default:
       break;
@@ -3117,7 +3118,9 @@ int
 ospf_lsa_action (struct thread *t)
 {
   struct lsa_action *data;
-  struct ospf *ospf = ospf_top;
+  struct ospf *ospf;
+
+  ospf = ospf_lookup ();
 
   data = THREAD_ARG (t);
 
index 6f6262aa6f4a97ef34776754c7b516f3939bee5b..dfbf3f6bc6c668e7d7d01a74ad52aff8efdb219c 100644 (file)
@@ -193,6 +193,9 @@ main (int argc, char **argv)
   zlog_default = openzlog (progname, ZLOG_NOLOG, ZLOG_OSPF,
                           LOG_CONS|LOG_NDELAY|LOG_PID, LOG_DAEMON);
 
+  /* OSPF master init. */
+  ospf_master_init ();
+
   while (1) 
     {
       int opt;
@@ -243,7 +246,7 @@ main (int argc, char **argv)
     }
 
   /* Initializations. */
-  master = thread_master_create ();
+  master = om->master;
 
   /* Library inits. */
   signal_init ();
index b8ba51843a6041fe15777c5433148ed8ef1db75f..f1fe783cce3cc556c1e8ee3b0644a576740aab95 100644 (file)
@@ -544,7 +544,7 @@ register_opaque_info_per_type (struct ospf_opaque_functab *functab,
       listnode_add (new->area->opaque_lsa_self, oipt);
       break;
     case OSPF_OPAQUE_AS_LSA:
-      top = ospf_top;
+      top = ospf_lookup ();
       if (new->area != NULL && (top = new->area->ospf) == NULL)
         {
           free_opaque_info_per_type ((void *) oipt);
@@ -652,7 +652,7 @@ lookup_opaque_info_by_type (struct ospf_lsa *lsa)
         zlog_warn ("Type-10 Opaque-LSA: Reference to AREA is missing?");
       break;
     case OSPF_OPAQUE_AS_LSA:
-      top = ospf_top;
+      top = ospf_lookup ();
       if ((area = lsa->area) != NULL && (top = area->ospf) == NULL)
         {
           zlog_warn ("Type-11 Opaque-LSA: Reference to OSPF is missing?");
@@ -1179,7 +1179,8 @@ show_opaque_info_detail (struct vty *vty, struct ospf_lsa *lsa)
   /* Switch output functionality by vty address. */
   if (vty != NULL)
     {
-      vty_out (vty, "  Opaque-Type %u (%s)%s", opaque_type, ospf_opaque_type_name (opaque_type), VTY_NEWLINE);
+      vty_out (vty, "  Opaque-Type %u (%s)%s", opaque_type,
+              ospf_opaque_type_name (opaque_type), VTY_NEWLINE);
       vty_out (vty, "  Opaque-ID   0x%x%s", opaque_id, VTY_NEWLINE);
 
       vty_out (vty, "  Opaque-Info: %u octets of data%s%s",
@@ -1189,7 +1190,8 @@ show_opaque_info_detail (struct vty *vty, struct ospf_lsa *lsa)
     }
   else
     {
-      zlog_info ("    Opaque-Type %u (%s)", opaque_type, ospf_opaque_type_name (opaque_type));
+      zlog_info ("    Opaque-Type %u (%s)", opaque_type,
+                ospf_opaque_type_name (opaque_type));
       zlog_info ("    Opaque-ID   0x%x", opaque_id);
 
       zlog_info ("    Opaque-Info: %u octets of data%s",
@@ -1580,7 +1582,7 @@ ospf_opaque_lsa_install (struct ospf_lsa *lsa, int rt_recalc)
         }
       break;
     case OSPF_OPAQUE_AS_LSA:
-      top = ospf_top;
+      top = ospf_lookup ();
       if (lsa->area != NULL && (top = lsa->area->ospf) == NULL)
         {
           /* Above conditions must have passed. */
@@ -1603,9 +1605,11 @@ out:
 void
 ospf_opaque_lsa_refresh (struct ospf_lsa *lsa)
 {
-  struct ospf *ospf = ospf_top;
+  struct ospf *ospf;
   struct ospf_opaque_functab *functab;
 
+  ospf = ospf_lookup ();
+
   if ((functab = ospf_opaque_functab_lookup (lsa)) == NULL
   ||   functab->lsa_refresher == NULL)
     {
@@ -1948,12 +1952,14 @@ extern int ospf_lsa_refresh_delay (struct ospf_lsa *); /* ospf_lsa.c */
 void
 ospf_opaque_lsa_refresh_schedule (struct ospf_lsa *lsa0)
 {
-  struct ospf *ospf = ospf_top;
+  struct ospf *ospf = ospf;
   struct opaque_info_per_type *oipt;
   struct opaque_info_per_id *oipi;
   struct ospf_lsa *lsa;
   int delay;
 
+  ospf = ospf_lookup ();
+
   if ((oipt = lookup_opaque_info_by_type (lsa0)) == NULL
   ||  (oipi = lookup_opaque_info_by_id (oipt, lsa0)) == NULL)
     {
@@ -2025,11 +2031,13 @@ ospf_opaque_lsa_refresh_timer (struct thread *t)
 void
 ospf_opaque_lsa_flush_schedule (struct ospf_lsa *lsa0)
 {
-  struct ospf *ospf = ospf_top;
+  struct ospf *ospf = ospf;
   struct opaque_info_per_type *oipt;
   struct opaque_info_per_id *oipi;
   struct ospf_lsa *lsa;
 
+  ospf = ospf_lookup ();
+
   if ((oipt = lookup_opaque_info_by_type (lsa0)) == NULL
   ||  (oipi = lookup_opaque_info_by_id (oipt, lsa0)) == NULL)
     {
index ac1f018936e171edc992fc7316dfa23ffd912a53..c4cc07b04d31a316c378eeab348a51445cf49aa7 100644 (file)
@@ -1967,7 +1967,8 @@ ospf_recv_packet (int fd, struct interface **ifp)
 }
 
 struct ospf_interface *
-ospf_associate_packet_vl (struct interface *ifp, struct ospf_interface *oi,
+ospf_associate_packet_vl (struct ospf *ospf,
+                         struct interface *ifp, struct ospf_interface *oi,
                          struct ip *iph, struct ospf_header *ospfh)
 {
   struct ospf_interface *rcv_oi;
@@ -1981,17 +1982,17 @@ ospf_associate_packet_vl (struct interface *ifp, struct ospf_interface *oi,
 
   if ((rcv_oi = oi) == NULL)
     {
-     if ((rcv_oi = ospf_if_lookup_by_local_addr (oi->ospf, ifp,
+     if ((rcv_oi = ospf_if_lookup_by_local_addr (ospf, ifp,
                                                 iph->ip_dst)) == NULL)
        return NULL;
     }
 
-  for (node = listhead (oi->ospf->vlinks); node; nextnode (node))
+  for (node = listhead (ospf->vlinks); node; nextnode (node))
     {
       if ((vl_data = getdata (node)) == NULL)
        continue;
       
-      vl_area = ospf_area_lookup_by_area_id (oi->ospf, vl_data->vl_area_id);
+      vl_area = ospf_area_lookup_by_area_id (ospf, vl_data->vl_area_id);
       if (!vl_area)
        continue;
       
@@ -2242,7 +2243,7 @@ ospf_read (struct thread *thread)
       return 0;
     }
   
-  if ((oi = ospf_associate_packet_vl (ifp, oi, iph, ospfh)) == NULL)
+  if ((oi = ospf_associate_packet_vl (ospf, ifp, oi, iph, ospfh)) == NULL)
     {
       stream_free (ibuf);
       return 0;
@@ -2778,7 +2779,7 @@ ospf_hello_send_sub (struct ospf_interface *oi, struct in_addr *addr)
   ospf_packet_add (oi, op);
 
   /* Hook thread to write packet. */
-  OSPF_ISM_WRITE_ON ();
+  OSPF_ISM_WRITE_ON (oi->ospf);
 }
 
 void
@@ -2913,7 +2914,7 @@ ospf_hello_send (struct ospf_interface *oi)
                  /* Add packet to the interface output queue. */
                  ospf_packet_add (oi, op_dup);
 
-                 OSPF_ISM_WRITE_ON ();
+                 OSPF_ISM_WRITE_ON (oi->ospf);
                }
 
              }
@@ -2931,7 +2932,7 @@ ospf_hello_send (struct ospf_interface *oi)
       ospf_packet_add (oi, op);
 
       /* Hook thread to write packet. */
-      OSPF_ISM_WRITE_ON ();
+      OSPF_ISM_WRITE_ON (oi->ospf);
     }
 }
 
@@ -2965,7 +2966,7 @@ ospf_db_desc_send (struct ospf_neighbor *nbr)
   ospf_packet_add (oi, op);
 
   /* Hook thread to write packet. */
-  OSPF_ISM_WRITE_ON ();
+  OSPF_ISM_WRITE_ON (oi->ospf);
 
   /* Remove old DD packet, then copy new one and keep in neighbor structure. */
   if (nbr->last_send)
@@ -2986,7 +2987,7 @@ ospf_db_desc_resend (struct ospf_neighbor *nbr)
   ospf_packet_add (oi, ospf_packet_dup (nbr->last_send));
 
   /* Hook thread to write packet. */
-  OSPF_ISM_WRITE_ON ();
+  OSPF_ISM_WRITE_ON (oi->ospf);
 }
 
 /* Send Link State Request. */
@@ -3024,7 +3025,7 @@ ospf_ls_req_send (struct ospf_neighbor *nbr)
   ospf_packet_add (oi, op);
 
   /* Hook thread to write packet. */
-  OSPF_ISM_WRITE_ON ();
+  OSPF_ISM_WRITE_ON (oi->ospf);
 
   /* Add Link State Request Retransmission Timer. */
   OSPF_NSM_TIMER_ON (nbr->t_ls_req, ospf_ls_req_timer, nbr->v_ls_req);
@@ -3077,7 +3078,7 @@ ospf_ls_upd_queue_send (struct ospf_interface *oi, list update,
   ospf_packet_add (oi, op);
 
   /* Hook thread to write packet. */
-  OSPF_ISM_WRITE_ON ();
+  OSPF_ISM_WRITE_ON (oi->ospf);
 }
 
 static int
@@ -3186,7 +3187,7 @@ ospf_ls_ack_send_list (struct ospf_interface *oi, list ack, struct in_addr dst)
   ospf_packet_add (oi, op);
 
   /* Hook thread to write packet. */
-  OSPF_ISM_WRITE_ON ();
+  OSPF_ISM_WRITE_ON (oi->ospf);
 }
 
 static int
index c3e34681eaa3dbbdb3c3fb260f92380f194dae6c..2e1a9b3c0574792672d3756dcb3594af31dbc917 100644 (file)
@@ -518,7 +518,9 @@ static u_char *
 ospfGeneralGroup (struct variable *v, oid *name, size_t *length,
                  int exact, size_t *var_len, WriteMethod **write_method)
 {
-  struct ospf *ospf = ospf_top;
+  struct ospf *ospf;
+
+  ospf = ospf_lookup ();
 
   /* Check whether the instance identifier is valid */
   if (smux_header_generic (v, name, length, exact, var_len, write_method)
@@ -619,7 +621,7 @@ ospf_area_lookup_next (struct ospf *ospf, struct in_addr *area_id, int first)
   struct ospf_area *area;
   listnode node;
 
-  if (! ospf_top)
+  if (ospf == NULL)
     return NULL;
 
   if (first)
@@ -650,10 +652,11 @@ struct ospf_area *
 ospfAreaLookup (struct variable *v, oid name[], size_t *length,
                struct in_addr *addr, int exact)
 {
-  struct ospf *ospf = ospf_top;
+  struct ospf *ospf;
   struct ospf_area *area;
   int len;
 
+  ospf = ospf_lookup ();
   if (ospf == NULL)
     return NULL;
 
@@ -753,11 +756,13 @@ ospf_stub_area_lookup_next (struct in_addr *area_id, int first)
 {
   struct ospf_area *area;
   listnode node;
+  struct ospf *ospf;
 
-  if (! ospf_top)
+  ospf = ospf_lookup ();
+  if (ospf == NULL)
     return NULL;
 
-  for (node = listhead (ospf_top->areas); node; nextnode (node))
+  for (node = listhead (ospf->areas); node; nextnode (node))
     {
       area = getdata (node);
 
@@ -782,11 +787,12 @@ struct ospf_area *
 ospfStubAreaLookup (struct variable *v, oid name[], size_t *length,
                    struct in_addr *addr, int exact)
 {
-  struct ospf *ospf = ospf_top;
+  struct ospf *ospf;
   struct ospf_area *area;
   int len;
 
-  if (! ospf_top)
+  ospf = ospf_lookup ();
+  if (ospf == NULL)
     return NULL;
 
   /* Exact lookup. */
@@ -910,7 +916,7 @@ ospfLsdbLookup (struct variable *v, oid *name, size_t *length,
                struct in_addr *area_id, u_char *type,
                struct in_addr *ls_id, struct in_addr *router_id, int exact)
 {
-  struct ospf *ospf = ospf_top;
+  struct ospf *ospf;
   struct ospf_area *area;
   struct ospf_lsa *lsa;
   int len;
@@ -920,6 +926,8 @@ ospfLsdbLookup (struct variable *v, oid *name, size_t *length,
   oid *offset;
   int offsetlen;
 
+  ospf = ospf_lookup ();
+
 #define OSPF_LSDB_ENTRY_OFFSET \
           (IN_ADDR_SIZE + 1 + IN_ADDR_SIZE + IN_ADDR_SIZE)
 
@@ -1058,6 +1066,7 @@ ospfLsdbEntry (struct variable *v, oid *name, size_t *length, int exact,
   u_char type;
   struct in_addr ls_id;
   struct in_addr router_id;
+  struct ospf *ospf;
 
   /* INDEX { ospfLsdbAreaId, ospfLsdbType,
      ospfLsdbLsid, ospfLsdbRouterId } */
@@ -1068,7 +1077,8 @@ ospfLsdbEntry (struct variable *v, oid *name, size_t *length, int exact,
   memset (&router_id, 0, sizeof (struct in_addr));
 
   /* Check OSPF instance. */
-  if (! ospf_top)
+  ospf = ospf_lookup ();
+  if (ospf == NULL)
     return NULL;
 
   lsa = ospfLsdbLookup (v, name, length, &area_id, &type, &ls_id, &router_id,
@@ -1121,13 +1131,15 @@ ospfAreaRangeLookup (struct variable *v, oid *name, size_t *length,
   oid *offset;
   int offsetlen;
   int len;
-  struct ospf *ospf = ospf_top;
+  struct ospf *ospf;
   struct ospf_area *area;
   struct ospf_area_range *range;
   struct prefix_ipv4 p;
   p.family = AF_INET;
   p.prefixlen = IPV4_MAX_BITLEN;
 
+  ospf = ospf_lookup ();
+
   if (exact) 
     {
       /* Area ID + Range Network. */
@@ -1216,9 +1228,10 @@ ospfAreaRangeEntry (struct variable *v, oid *name, size_t *length, int exact,
   struct in_addr area_id;
   struct in_addr range_net;
   struct in_addr mask;
-  struct ospf *ospf = ospf_top;
+  struct ospf *ospf;
   
   /* Check OSPF instance. */
+  ospf = ospf_lookup ();
   if (ospf == NULL)
     return NULL;
 
@@ -1265,8 +1278,9 @@ ospfHostLookup (struct variable *v, oid *name, size_t *length,
 {
   int len;
   struct ospf_nbr_nbma *nbr_nbma;
-  struct ospf *ospf = ospf_top;
+  struct ospf *ospf;
 
+  ospf = ospf_lookup ();
   if (ospf == NULL)
     return NULL;
 
@@ -1318,9 +1332,10 @@ ospfHostEntry (struct variable *v, oid *name, size_t *length, int exact,
   struct ospf_nbr_nbma *nbr_nbma;
   struct ospf_interface *oi;
   struct in_addr addr;
-  struct ospf *ospf = ospf_top;
+  struct ospf *ospf;
 
   /* Check OSPF instance. */
+  ospf = ospf_lookup ();
   if (ospf == NULL)
     return NULL;
 
@@ -1609,12 +1624,13 @@ ospfIfEntry (struct variable *v, oid *name, size_t *length, int exact,
   unsigned int ifindex;
   struct in_addr ifaddr;
   struct ospf_interface *oi;
-  struct ospf *ospf = ospf_top;
+  struct ospf *ospf;
 
   ifindex = 0;
   memset (&ifaddr, 0, sizeof (struct in_addr));
 
   /* Check OSPF instance. */
+  ospf = ospf_lookup ();
   if (ospf == NULL)
     return NULL;
 
@@ -1781,12 +1797,13 @@ ospfIfMetricEntry (struct variable *v, oid *name, size_t *length, int exact,
   unsigned int ifindex;
   struct in_addr ifaddr;
   struct ospf_interface *oi;
-  struct ospf *ospf = ospf_top;
+  struct ospf *ospf;
 
   ifindex = 0;
   memset (&ifaddr, 0, sizeof (struct in_addr));
 
   /* Check OSPF instance. */
+  ospf = ospf_lookup ();
   if (ospf == NULL)
     return NULL;
 
@@ -2071,8 +2088,9 @@ ospf_snmp_nbr_lookup_next (struct in_addr *nbr_addr, unsigned int *ifindex,
   struct ospf_neighbor *nbr;
   struct route_node *rn;
   struct ospf_neighbor *min = NULL;
-  struct ospf *ospf = ospf_top;
+  struct ospf *ospf = ospf;
 
+  ospf = ospf_lookup ();
   LIST_LOOP (ospf->oiflist, oi, nn)
     {
       for (rn = route_top (oi->nbrs); rn; rn = route_next (rn))
@@ -2113,7 +2131,9 @@ ospfNbrLookup (struct variable *v, oid *name, size_t *length,
   int len;
   int first;
   struct ospf_neighbor *nbr;
-  struct ospf *ospf = ospf_top;
+  struct ospf *ospf;
+
+  ospf = ospf_lookup ();
 
   if (exact)
     {
@@ -2224,12 +2244,13 @@ ospfVirtNbrEntry (struct variable *v, oid *name, size_t *length, int exact,
   struct ospf_vl_data *vl_data;
   struct in_addr area_id;
   struct in_addr neighbor;
-  struct ospf *ospf = ospf_top;
+  struct ospf *ospf;
 
   memset (&area_id, 0, sizeof (struct in_addr));
   memset (&neighbor, 0, sizeof (struct in_addr));
 
   /* Check OSPF instance. */
+  ospf = ospf_lookup ();
   if (ospf == NULL)
     return NULL;
 
@@ -2281,8 +2302,9 @@ ospfExtLsdbLookup (struct variable *v, oid *name, size_t *length, u_char *type,
   u_char lsa_type;
   int len;
   struct ospf_lsa *lsa;
-  struct ospf *ospf = ospf_top;
+  struct ospf *ospf;
 
+  ospf = ospf_lookup ();
   if (exact)
     {
       if (*length != v->namelen + 1 + IN_ADDR_SIZE + IN_ADDR_SIZE)
@@ -2370,13 +2392,14 @@ ospfExtLsdbEntry (struct variable *v, oid *name, size_t *length, int exact,
   u_char type;
   struct in_addr ls_id;
   struct in_addr router_id;
-  struct ospf *ospf = ospf_top;
+  struct ospf *ospf;
 
   type = OSPF_AS_EXTERNAL_LSA;
   memset (&ls_id, 0, sizeof (struct in_addr));
   memset (&router_id, 0, sizeof (struct in_addr));
 
   /* Check OSPF instance. */
+  ospf = ospf_lookup ();
   if (ospf == NULL)
     return NULL;
 
index 1586a3a57704e0a4ad5c5c9f93df9415c2223ae9..33616d8375e36035778bfbf97df0996da3d4664a 100644 (file)
@@ -1056,7 +1056,7 @@ ospf_spf_calculate_timer (struct thread *thread)
   ospf->old_rtrs = ospf->new_rtrs;
   ospf->new_rtrs = new_rtrs;
 
-  if (OSPF_IS_ABR
+  if (IS_OSPF_ABR (ospf)
     ospf_abr_task (ospf);
 
   if (IS_DEBUG_OSPF_EVENT)
index fff6f65961ade6302adefa792946925966d43d72..4100860bdf24acd1bafdfe05ed36869f83cbd008 100644 (file)
@@ -181,13 +181,16 @@ DEFUN (no_router_ospf,
        "Enable a routing process\n"
        "Start OSPF configuration\n")
 {
-  if (ospf_top == NULL)
+  struct ospf *ospf;
+
+  ospf = ospf_lookup ();
+  if (ospf == NULL)
     {
-      vty_out (vty, "There isn't active ospf instance.%s", VTY_NEWLINE);
+      vty_out (vty, "There isn't active ospf instance%s", VTY_NEWLINE);
       return CMD_WARNING;
     }
 
-  ospf_finish (ospf_top);
+  ospf_finish (ospf);
 
   return CMD_SUCCESS;
 }
@@ -213,9 +216,8 @@ DEFUN (ospf_router_id,
   ospf->router_id_static = router_id;
 
   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);
 
   return CMD_SUCCESS;
 }
@@ -2298,8 +2300,8 @@ DEFUN (auto_cost_reference_bandwidth,
   vty_out (vty, "%% OSPF: Reference bandwidth is changed.%s", VTY_NEWLINE);
   vty_out (vty, "        Please ensure reference bandwidth is consistent across all routers%s", VTY_NEWLINE);
       
-  for (node = listhead (ospf->iflist); node; nextnode (node))
-      ospf_if_recalculate_output_cost (getdata (node));
+  for (node = listhead (om->iflist); node; nextnode (node))
+    ospf_if_recalculate_output_cost (getdata (node));
   
   return CMD_SUCCESS;
 }
@@ -2321,8 +2323,8 @@ DEFUN (no_auto_cost_reference_bandwidth,
   vty_out (vty, "%% OSPF: Reference bandwidth is changed.%s", VTY_NEWLINE);
   vty_out (vty, "        Please ensure reference bandwidth is consistent across all routers%s", VTY_NEWLINE);
 
-    for (node = listhead (ospf->iflist); node; nextnode (node))
-      ospf_if_recalculate_output_cost (getdata (node));
+  for (node = listhead (om->iflist); node; nextnode (node))
+    ospf_if_recalculate_output_cost (getdata (node));
       
   return CMD_SUCCESS;
 }
@@ -2386,7 +2388,7 @@ show_ip_ospf_area (struct vty *vty, struct ospf_area *area)
   if (area->external_routing == OSPF_AREA_NSSA)
     {
       vty_out (vty, "   It is an NSSA configuration. %s   Elected NSSA/ABR performs type-7/type-5 LSA translation. %s", VTY_NEWLINE, VTY_NEWLINE);
-      if (! OSPF_IS_ABR)
+      if (! IS_OSPF_ABR (area->ospf))
        vty_out (vty, "   It is not ABR, therefore not Translator. %s",
                 VTY_NEWLINE);
       else
@@ -2435,9 +2437,10 @@ DEFUN (show_ip_ospf,
 {
   listnode node;
   struct ospf_area * area;
-  struct ospf *ospf = ospf_top;
+  struct ospf *ospf;
 
   /* Check OSPF is enable. */
+  ospf = ospf_lookup ();
   if (ospf == NULL)
     {
       vty_out (vty, " OSPF Routing Process not enabled%s", VTY_NEWLINE);
@@ -2618,9 +2621,11 @@ DEFUN (show_ip_ospf_interface,
        "Interface name\n")
 {
   struct interface *ifp;
-  struct ospf *ospf = ospf_top;
+  struct ospf *ospf;
   listnode node;
 
+  ospf = ospf_lookup ();
+
   /* Show All Interfaces. */
   if (argc == 0)
     for (node = listhead (iflist); node; nextnode (node))
@@ -2678,9 +2683,10 @@ DEFUN (show_ip_ospf_neighbor,
        "OSPF information\n"
        "Neighbor list\n")
 {
-  struct ospf *ospf = ospf_top;
+  struct ospf *ospf;
   listnode node;
 
+  ospf = ospf_lookup ();
   if (ospf == NULL)
     {
       vty_out (vty, " OSPF Routing Process not enabled%s", VTY_NEWLINE);
@@ -2693,7 +2699,7 @@ DEFUN (show_ip_ospf_neighbor,
            "RqstL DBsmL%s", VTY_NEWLINE, VTY_NEWLINE);
 
   for (node = listhead (ospf->oiflist); node; nextnode (node))
-      show_ip_ospf_neighbor_sub (vty, getdata (node));
+    show_ip_ospf_neighbor_sub (vty, getdata (node));
 
   return CMD_SUCCESS;
 }
@@ -2759,17 +2765,11 @@ DEFUN (show_ip_ospf_neighbor_int,
        "Neighbor list\n"
        "Interface name\n")
 {
-  struct ospf *ospf = ospf_top;
+  struct ospf *ospf;
   struct ospf_interface *oi;
   struct in_addr addr;
   int ret;
   
-  if (ospf == NULL)
-    {
-      vty_out (vty, " OSPF Routing Process not enabled%s", VTY_NEWLINE);
-      return CMD_SUCCESS;
-    }
-
   ret = inet_aton (argv[0], &addr);
   if (!ret)
     {
@@ -2778,6 +2778,13 @@ DEFUN (show_ip_ospf_neighbor_int,
       return CMD_WARNING;
     }
 
+  ospf = ospf_lookup ();
+  if (ospf == NULL)
+    {
+      vty_out (vty, " OSPF Routing Process not enabled%s", VTY_NEWLINE);
+      return CMD_SUCCESS;
+    }
+
   if ((oi = ospf_if_is_configured (ospf, &addr)) == NULL)
     vty_out (vty, "No such interface address%s", VTY_NEWLINE);
   else
@@ -2890,7 +2897,7 @@ DEFUN (show_ip_ospf_neighbor_id,
        "Neighbor list\n"
        "Neighbor ID\n")
 {
-  struct ospf *ospf = ospf_top;
+  struct ospf *ospf;
   listnode node;
   struct ospf_neighbor *nbr;
   struct in_addr router_id;
@@ -2903,6 +2910,13 @@ DEFUN (show_ip_ospf_neighbor_id,
       return CMD_WARNING;
     }
 
+  ospf = ospf_lookup ();
+  if (ospf == NULL)
+    {
+      vty_out (vty, " OSPF Routing Process not enabled%s", VTY_NEWLINE);
+      return CMD_SUCCESS;
+    }
+
   for (node = listhead (ospf->oiflist); node; nextnode (node))
     {
       struct ospf_interface *oi = getdata (node);
@@ -2927,11 +2941,15 @@ DEFUN (show_ip_ospf_neighbor_detail,
        "Neighbor list\n"
        "detail of all neighbors\n")
 {
-  struct ospf *ospf = ospf_top;
+  struct ospf *ospf;
   listnode node;
 
+  ospf = ospf_lookup ();
   if (ospf == NULL)
-    return CMD_SUCCESS;
+    {
+      vty_out (vty, " OSPF Routing Process not enabled%s", VTY_NEWLINE);
+      return CMD_SUCCESS;
+    }
 
   for (node = listhead (ospf->oiflist); node; nextnode (node))
     {
@@ -2959,11 +2977,15 @@ DEFUN (show_ip_ospf_neighbor_detail_all,
        "detail of all neighbors\n"
        "include down status neighbor\n")
 {
-  struct ospf *ospf = ospf_top;
+  struct ospf *ospf;
   listnode node;
 
+  ospf = ospf_lookup ();
   if (ospf == NULL)
-    return CMD_SUCCESS;
+    {
+      vty_out (vty, " OSPF Routing Process not enabled%s", VTY_NEWLINE);
+      return CMD_SUCCESS;
+    }
 
   for (node = listhead (ospf->oiflist); node; nextnode (node))
     {
@@ -3004,6 +3026,7 @@ DEFUN (show_ip_ospf_neighbor_int_detail,
        "Interface address\n"
        "detail of all neighbors")
 {
+  struct ospf *ospf;
   struct ospf_interface *oi;
   struct in_addr addr;
   int ret;
@@ -3016,10 +3039,14 @@ DEFUN (show_ip_ospf_neighbor_int_detail,
       return CMD_WARNING;
     }
 
-  if (ospf_top == NULL)
-    return CMD_WARNING;
+  ospf = ospf_lookup ();
+  if (ospf == NULL)
+    {
+      vty_out (vty, " OSPF Routing Process not enabled%s", VTY_NEWLINE);
+      return CMD_SUCCESS;
+    }
 
-  if ((oi = ospf_if_is_configured (ospf_top, &addr)) == NULL)
+  if ((oi = ospf_if_is_configured (ospf, &addr)) == NULL)
     vty_out (vty, "No such interface address%s", VTY_NEWLINE);
   else
     {
@@ -3039,9 +3066,8 @@ DEFUN (show_ip_ospf_neighbor_int_detail,
 \f
 /* Show functions */
 int
-show_lsa_summary (struct ospf_lsa *lsa, void *v, int self)
+show_lsa_summary (struct vty *vty, struct ospf_lsa *lsa, int self)
 {
-  struct vty *vty = (struct vty *) v;
   struct router_lsa *rl;
   struct summary_lsa *sl;
   struct as_external_lsa *asel;
@@ -3500,10 +3526,9 @@ show_lsa_detail_proc (struct vty *vty, struct route_table *rt,
 /* Show detail LSA information
    -- if id is NULL then show all LSAs. */
 void
-show_lsa_detail (struct vty *vty, int type,
+show_lsa_detail (struct vty *vty, struct ospf *ospf, int type,
                 struct in_addr *id, struct in_addr *adv_router)
 {
-  struct ospf *ospf = ospf_top;
   listnode node;
 
   switch (type)
@@ -3552,10 +3577,9 @@ show_lsa_detail_adv_router_proc (struct vty *vty, struct route_table *rt,
 
 /* Show detail LSA information. */
 void
-show_lsa_detail_adv_router (struct vty *vty, int type,
+show_lsa_detail_adv_router (struct vty *vty, struct ospf *ospf, int type,
                            struct in_addr *adv_router)
 {
-  struct ospf *ospf = ospf_top;
   listnode node;
 
   switch (type)
@@ -3585,9 +3609,10 @@ show_lsa_detail_adv_router (struct vty *vty, int type,
 }
 
 void
-show_ip_ospf_database_summary (struct vty *vty, int self)
+show_ip_ospf_database_summary (struct vty *vty, struct ospf *ospf, int self)
 {
-  struct ospf *ospf = ospf_top;
+  struct ospf_lsa *lsa;
+  struct route_node *rn;
   listnode node;
   int type;
 
@@ -3615,7 +3640,8 @@ show_ip_ospf_database_summary (struct vty *vty, int self)
                        VTY_NEWLINE, VTY_NEWLINE);
               vty_out (vty, "%s%s", show_database_header[type], VTY_NEWLINE);
 
-              foreach_lsa (AREA_LSDB (area, type), vty, self, show_lsa_summary);
+             LSDB_LOOP (AREA_LSDB (area, type), rn, lsa)
+               show_lsa_summary (vty, lsa, self);
 
               vty_out (vty, "%s", VTY_NEWLINE);
          }
@@ -3642,7 +3668,10 @@ show_ip_ospf_database_summary (struct vty *vty, int self)
               VTY_NEWLINE, VTY_NEWLINE);
           vty_out (vty, "%s%s", show_database_header[type],
               VTY_NEWLINE);
-          foreach_lsa (AS_LSDB (ospf, type), vty, self, show_lsa_summary);
+
+         LSDB_LOOP (AS_LSDB (ospf, type), rn, lsa)
+           show_lsa_summary (vty, lsa, self);
+
           vty_out (vty, "%s", VTY_NEWLINE);
         }
     }
@@ -3651,9 +3680,8 @@ show_ip_ospf_database_summary (struct vty *vty, int self)
 }
 
 void
-show_ip_ospf_database_maxage (struct vty *vty)
+show_ip_ospf_database_maxage (struct vty *vty, struct ospf *ospf)
 {
-  struct ospf *ospf = ospf_top;
   listnode node;
   struct ospf_lsa *lsa;
 
@@ -3717,10 +3745,11 @@ DEFUN (show_ip_ospf_database,
        "OSPF information\n"
        "Database summary\n")
 {
-  struct ospf *ospf = ospf_top;
+  struct ospf *ospf;
   int type, ret;
   struct in_addr id, adv_router;
 
+  ospf = ospf_lookup ();
   if (ospf == NULL)
     return CMD_SUCCESS;
 
@@ -3730,7 +3759,7 @@ DEFUN (show_ip_ospf_database,
   /* Show all LSA. */
   if (argc == 0)
     {
-      show_ip_ospf_database_summary (vty, 0);
+      show_ip_ospf_database_summary (vty, ospf, 0);
       return CMD_SUCCESS;
     }
 
@@ -3751,12 +3780,12 @@ DEFUN (show_ip_ospf_database,
     type = OSPF_AS_EXTERNAL_LSA;
   else if (strncmp (argv[0], "se", 2) == 0)
     {
-      show_ip_ospf_database_summary (vty, 1);
+      show_ip_ospf_database_summary (vty, ospf, 1);
       return CMD_SUCCESS;
     }
   else if (strncmp (argv[0], "m", 1) == 0)
     {
-      show_ip_ospf_database_maxage (vty);
+      show_ip_ospf_database_maxage (vty, ospf);
       return CMD_SUCCESS;
     }
 #ifdef HAVE_OPAQUE_LSA
@@ -3772,7 +3801,7 @@ DEFUN (show_ip_ospf_database,
 
   /* `show ip ospf database LSA'. */
   if (argc == 1)
-    show_lsa_detail (vty, type, NULL, NULL);
+    show_lsa_detail (vty, ospf, type, NULL, NULL);
   else if (argc >= 2)
     {
       ret = inet_aton (argv[1], &id);
@@ -3781,7 +3810,7 @@ DEFUN (show_ip_ospf_database,
       
       /* `show ip ospf database LSA ID'. */
       if (argc == 2)
-       show_lsa_detail (vty, type, &id, NULL);
+       show_lsa_detail (vty, ospf, type, &id, NULL);
       /* `show ip ospf database LSA ID adv-router ADV_ROUTER'. */
       else if (argc == 3)
        {
@@ -3793,7 +3822,7 @@ DEFUN (show_ip_ospf_database,
              if (!ret)
                return CMD_WARNING;
            }
-         show_lsa_detail (vty, type, &id, &adv_router);
+         show_lsa_detail (vty, ospf, type, &id, &adv_router);
        }
     }
 
@@ -3856,10 +3885,11 @@ DEFUN (show_ip_ospf_database_type_adv_router,
        "Advertising Router link states\n"
        "Advertising Router (as an IP address)\n")
 {
-  struct ospf *ospf = ospf_top;
+  struct ospf *ospf;
   int type, ret;
   struct in_addr adv_router;
 
+  ospf = ospf_lookup ();
   if (ospf == NULL)
     return CMD_SUCCESS;
 
@@ -3905,7 +3935,7 @@ DEFUN (show_ip_ospf_database_type_adv_router,
        return CMD_WARNING;
     }
 
-  show_lsa_detail_adv_router (vty, type, &adv_router);
+  show_lsa_detail_adv_router (vty, ospf, type, &adv_router);
 
   return CMD_SUCCESS;
 }
@@ -4488,8 +4518,10 @@ DEFUN (ip_ospf_dead_interval,
   struct ospf_if_params *params;
   struct ospf_interface *oi;
   struct route_node *rn;
-  struct ospf *ospf = ospf_top;
+  struct ospf *ospf;
       
+  ospf = ospf_lookup ();
+
   params = IF_DEF_PARAMS (ifp);
 
   seconds = strtol (argv[0], NULL, 10);
@@ -4568,8 +4600,10 @@ DEFUN (no_ip_ospf_dead_interval,
   struct ospf_if_params *params;
   struct ospf_interface *oi;
   struct route_node *rn;
-  struct ospf *ospf = ospf_top;
+  struct ospf *ospf;
   
+  ospf = ospf_lookup ();
+
   ifp = vty->index;
   params = IF_DEF_PARAMS (ifp);
 
@@ -5262,6 +5296,7 @@ DEFUN (ospf_redistribute_source_metric_type,
        "Route map reference\n"
        "Pointer to route-map entries\n")
 {
+  struct ospf *ospf = vty->index;
   int source;
   int type = -1;
   int metric = -1;
@@ -5281,11 +5316,11 @@ DEFUN (ospf_redistribute_source_metric_type,
       return CMD_WARNING;
 
   if (argc == 4)
-    ospf_routemap_set (source, argv[3]);
+    ospf_routemap_set (ospf, source, argv[3]);
   else
-    ospf_routemap_unset (source);
+    ospf_routemap_unset (ospf, source);
   
-  return ospf_redistribute_set (source, type, metric);
+  return ospf_redistribute_set (ospf, source, type, metric);
 }
 
 ALIAS (ospf_redistribute_source_metric_type,
@@ -5332,6 +5367,7 @@ DEFUN (ospf_redistribute_source_type_metric,
        "Route map reference\n"
        "Pointer to route-map entries\n")
 {
+  struct ospf *ospf = vty->index;
   int source;
   int type = -1;
   int metric = -1;
@@ -5351,11 +5387,11 @@ DEFUN (ospf_redistribute_source_type_metric,
       return CMD_WARNING;
 
   if (argc == 4)
-    ospf_routemap_set (source, argv[3]);
+    ospf_routemap_set (ospf, source, argv[3]);
   else
-    ospf_routemap_unset (source);
+    ospf_routemap_unset (ospf, source);
 
-  return ospf_redistribute_set (source, type, metric);
+  return ospf_redistribute_set (ospf, source, type, metric);
 }
 
 ALIAS (ospf_redistribute_source_type_metric,
@@ -5410,6 +5446,7 @@ DEFUN (ospf_redistribute_source_metric_routemap,
        "Route map reference\n"
        "Pointer to route-map entries\n")
 {
+  struct ospf *ospf = vty->index;
   int source;
   int metric = -1;
 
@@ -5423,11 +5460,11 @@ DEFUN (ospf_redistribute_source_metric_routemap,
       return CMD_WARNING;
 
   if (argc == 3)
-    ospf_routemap_set (source, argv[2]);
+    ospf_routemap_set (ospf, source, argv[2]);
   else
-    ospf_routemap_unset (source);
+    ospf_routemap_unset (ospf, source);
   
-  return ospf_redistribute_set (source, -1, metric);
+  return ospf_redistribute_set (ospf, source, -1, metric);
 }
 
 DEFUN (ospf_redistribute_source_type_routemap,
@@ -5445,6 +5482,7 @@ DEFUN (ospf_redistribute_source_type_routemap,
        "Route map reference\n"
        "Pointer to route-map entries\n")
 {
+  struct ospf *ospf = vty->index;
   int source;
   int type = -1;
 
@@ -5458,11 +5496,11 @@ DEFUN (ospf_redistribute_source_type_routemap,
       return CMD_WARNING;
 
   if (argc == 3)
-    ospf_routemap_set (source, argv[2]);
+    ospf_routemap_set (ospf, source, argv[2]);
   else
-    ospf_routemap_unset (source);
+    ospf_routemap_unset (ospf, source);
 
-  return ospf_redistribute_set (source, type, -1);
+  return ospf_redistribute_set (ospf, source, type, -1);
 }
 
 DEFUN (ospf_redistribute_source_routemap,
@@ -5477,6 +5515,7 @@ DEFUN (ospf_redistribute_source_routemap,
        "Route map reference\n"
        "Pointer to route-map entries\n")
 {
+  struct ospf *ospf = vty->index;
   int source;
 
   /* Get distribute source. */
@@ -5484,11 +5523,11 @@ DEFUN (ospf_redistribute_source_routemap,
     return CMD_WARNING;
 
   if (argc == 2)
-    ospf_routemap_set (source, argv[1]);
+    ospf_routemap_set (ospf, source, argv[1]);
   else
-    ospf_routemap_unset (source);
+    ospf_routemap_unset (ospf, source);
 
-  return ospf_redistribute_set (source, -1, -1);
+  return ospf_redistribute_set (ospf, source, -1, -1);
 }
 
 DEFUN (no_ospf_redistribute_source,
@@ -5502,13 +5541,14 @@ DEFUN (no_ospf_redistribute_source,
        "Routing Information Protocol (RIP)\n"
        "Border Gateway Protocol (BGP)\n")
 {
+  struct ospf *ospf = vty->index;
   int source;
 
   if (!str2distribute_source (argv[0], &source))
     return CMD_WARNING;
 
-  ospf_routemap_unset (source);
-  return ospf_redistribute_unset (source);
+  ospf_routemap_unset (ospf, source);
+  return ospf_redistribute_unset (ospf, source);
 }
 
 DEFUN (ospf_distribute_list_out,
@@ -5569,6 +5609,7 @@ DEFUN (ospf_default_information_originate_metric_type_routemap,
        "Route map reference\n"
        "Pointer to route-map entries\n")
 {
+  struct ospf *ospf = vty->index;
   int type = -1;
   int metric = -1;
 
@@ -5583,11 +5624,12 @@ DEFUN (ospf_default_information_originate_metric_type_routemap,
       return CMD_WARNING;
 
   if (argc == 3)
-    ospf_routemap_set (DEFAULT_ROUTE, argv[2]);
+    ospf_routemap_set (ospf, DEFAULT_ROUTE, argv[2]);
   else
-    ospf_routemap_unset (DEFAULT_ROUTE);
+    ospf_routemap_unset (ospf, DEFAULT_ROUTE);
 
-  return ospf_redistribute_default_set (DEFAULT_ORIGINATE_ZEBRA, type, metric);
+  return ospf_redistribute_default_set (ospf, DEFAULT_ORIGINATE_ZEBRA,
+                                       type, metric);
 }
 
 ALIAS (ospf_default_information_originate_metric_type_routemap,
@@ -5626,6 +5668,7 @@ DEFUN (ospf_default_information_originate_metric_routemap,
        "Route map reference\n"
        "Pointer to route-map entries\n")
 {
+  struct ospf *ospf = vty->index;
   int metric = -1;
 
   /* Get metric value. */
@@ -5634,11 +5677,12 @@ DEFUN (ospf_default_information_originate_metric_routemap,
       return CMD_WARNING;
 
   if (argc == 2)
-    ospf_routemap_set (DEFAULT_ROUTE, argv[1]);
+    ospf_routemap_set (ospf, DEFAULT_ROUTE, argv[1]);
   else
-    ospf_routemap_unset (DEFAULT_ROUTE);
+    ospf_routemap_unset (ospf, DEFAULT_ROUTE);
 
-  return ospf_redistribute_default_set (DEFAULT_ORIGINATE_ZEBRA, -1, metric);
+  return ospf_redistribute_default_set (ospf, DEFAULT_ORIGINATE_ZEBRA,
+                                       -1, metric);
 }
 
 /* Default information originate. */
@@ -5650,12 +5694,14 @@ DEFUN (ospf_default_information_originate_routemap,
        "Route map reference\n"
        "Pointer to route-map entries\n")
 {
+  struct ospf *ospf = vty->index;
+
   if (argc == 1)
-    ospf_routemap_set (DEFAULT_ROUTE, argv[0]);
+    ospf_routemap_set (ospf, DEFAULT_ROUTE, argv[0]);
   else
-    ospf_routemap_unset (DEFAULT_ROUTE);
+    ospf_routemap_unset (ospf, DEFAULT_ROUTE);
 
-  return ospf_redistribute_default_set (DEFAULT_ORIGINATE_ZEBRA, -1, -1);
+  return ospf_redistribute_default_set (ospf, DEFAULT_ORIGINATE_ZEBRA, -1, -1);
 }
 
 DEFUN (ospf_default_information_originate_type_metric_routemap,
@@ -5671,6 +5717,7 @@ DEFUN (ospf_default_information_originate_type_metric_routemap,
        "Route map reference\n"
        "Pointer to route-map entries\n")
 {
+  struct ospf *ospf = vty->index;
   int type = -1;
   int metric = -1;
 
@@ -5685,11 +5732,12 @@ DEFUN (ospf_default_information_originate_type_metric_routemap,
       return CMD_WARNING;
 
   if (argc == 3)
-    ospf_routemap_set (DEFAULT_ROUTE, argv[2]);
+    ospf_routemap_set (ospf, DEFAULT_ROUTE, argv[2]);
   else
-    ospf_routemap_unset (DEFAULT_ROUTE);
+    ospf_routemap_unset (ospf, DEFAULT_ROUTE);
 
-  return ospf_redistribute_default_set (DEFAULT_ORIGINATE_ZEBRA, type, metric);
+  return ospf_redistribute_default_set (ospf, DEFAULT_ORIGINATE_ZEBRA,
+                                       type, metric);
 }
 
 ALIAS (ospf_default_information_originate_type_metric_routemap,
@@ -5723,6 +5771,7 @@ DEFUN (ospf_default_information_originate_type_routemap,
        "Route map reference\n"
        "Pointer to route-map entries\n")
 {
+  struct ospf *ospf = vty->index;
   int type = -1;
 
   /* Get metric type. */
@@ -5731,11 +5780,12 @@ DEFUN (ospf_default_information_originate_type_routemap,
       return CMD_WARNING;
 
   if (argc == 2)
-    ospf_routemap_set (DEFAULT_ROUTE, argv[1]);
+    ospf_routemap_set (ospf, DEFAULT_ROUTE, argv[1]);
   else
-    ospf_routemap_unset (DEFAULT_ROUTE);
+    ospf_routemap_unset (ospf, DEFAULT_ROUTE);
 
-  return ospf_redistribute_default_set (DEFAULT_ORIGINATE_ZEBRA, type, -1);
+  return ospf_redistribute_default_set (ospf, DEFAULT_ORIGINATE_ZEBRA,
+                                       type, -1);
 }
 
 DEFUN (ospf_default_information_originate_always_metric_type_routemap,
@@ -5752,6 +5802,7 @@ DEFUN (ospf_default_information_originate_always_metric_type_routemap,
        "Route map reference\n"
        "Pointer to route-map entries\n")
 {
+  struct ospf *ospf = vty->index;
   int type = -1;
   int metric = -1;
 
@@ -5766,11 +5817,11 @@ DEFUN (ospf_default_information_originate_always_metric_type_routemap,
       return CMD_WARNING;
 
   if (argc == 3)
-    ospf_routemap_set (DEFAULT_ROUTE, argv[2]);
+    ospf_routemap_set (ospf, DEFAULT_ROUTE, argv[2]);
   else
-    ospf_routemap_unset (DEFAULT_ROUTE);
+    ospf_routemap_unset (ospf, DEFAULT_ROUTE);
 
-  return ospf_redistribute_default_set (DEFAULT_ORIGINATE_ALWAYS,
+  return ospf_redistribute_default_set (ospf, DEFAULT_ORIGINATE_ALWAYS,
                                        type, metric);
 }
 
@@ -5814,6 +5865,7 @@ DEFUN (ospf_default_information_originate_always_metric_routemap,
        "Route map reference\n"
        "Pointer to route-map entries\n")
 {
+  struct ospf *ospf = vty->index;
   int metric = -1;
 
   /* Get metric value. */
@@ -5822,11 +5874,12 @@ DEFUN (ospf_default_information_originate_always_metric_routemap,
       return CMD_WARNING;
 
   if (argc == 2)
-    ospf_routemap_set (DEFAULT_ROUTE, argv[1]);
+    ospf_routemap_set (ospf, DEFAULT_ROUTE, argv[1]);
   else
-    ospf_routemap_unset (DEFAULT_ROUTE);
+    ospf_routemap_unset (ospf, DEFAULT_ROUTE);
 
-  return ospf_redistribute_default_set (DEFAULT_ORIGINATE_ALWAYS, -1, metric);
+  return ospf_redistribute_default_set (ospf, DEFAULT_ORIGINATE_ALWAYS,
+                                       -1, metric);
 }
 
 DEFUN (ospf_default_information_originate_always_routemap,
@@ -5838,12 +5891,14 @@ DEFUN (ospf_default_information_originate_always_routemap,
        "Route map reference\n"
        "Pointer to route-map entries\n")
 {
+  struct ospf *ospf = vty->index;
+
   if (argc == 1)
-    ospf_routemap_set (DEFAULT_ROUTE, argv[0]);
+    ospf_routemap_set (ospf, DEFAULT_ROUTE, argv[0]);
   else
-    ospf_routemap_unset (DEFAULT_ROUTE);
+    ospf_routemap_unset (ospf, DEFAULT_ROUTE);
 
-  return ospf_redistribute_default_set (DEFAULT_ORIGINATE_ALWAYS, -1, -1);
+  return ospf_redistribute_default_set (ospf, DEFAULT_ORIGINATE_ALWAYS, -1, -1);
 }
 
 DEFUN (ospf_default_information_originate_always_type_metric_routemap,
@@ -5860,6 +5915,7 @@ DEFUN (ospf_default_information_originate_always_type_metric_routemap,
        "Route map reference\n"
        "Pointer to route-map entries\n")
 {
+  struct ospf *ospf = vty->index;
   int type = -1;
   int metric = -1;
 
@@ -5874,11 +5930,11 @@ DEFUN (ospf_default_information_originate_always_type_metric_routemap,
       return CMD_WARNING;
 
   if (argc == 3)
-    ospf_routemap_set (DEFAULT_ROUTE, argv[2]);
+    ospf_routemap_set (ospf, DEFAULT_ROUTE, argv[2]);
   else
-    ospf_routemap_unset (DEFAULT_ROUTE);
+    ospf_routemap_unset (ospf, DEFAULT_ROUTE);
 
-  return ospf_redistribute_default_set (DEFAULT_ORIGINATE_ALWAYS,
+  return ospf_redistribute_default_set (ospf, DEFAULT_ORIGINATE_ALWAYS,
                                        type, metric);
 }
 
@@ -5916,6 +5972,7 @@ DEFUN (ospf_default_information_originate_always_type_routemap,
        "Route map reference\n"
        "Pointer to route-map entries\n")
 {
+  struct ospf *ospf = vty->index;
   int type = -1;
 
   /* Get metric type. */
@@ -5924,11 +5981,11 @@ DEFUN (ospf_default_information_originate_always_type_routemap,
       return CMD_WARNING;
 
   if (argc == 2)
-    ospf_routemap_set (DEFAULT_ROUTE, argv[1]);
+    ospf_routemap_set (ospf, DEFAULT_ROUTE, argv[1]);
   else
-    ospf_routemap_unset (DEFAULT_ROUTE);
+    ospf_routemap_unset (ospf, DEFAULT_ROUTE);
 
-  return ospf_redistribute_default_set (DEFAULT_ORIGINATE_ALWAYS,
+  return ospf_redistribute_default_set (ospf, DEFAULT_ORIGINATE_ALWAYS,
                                        type, -1);
 }
 
@@ -5955,8 +6012,8 @@ DEFUN (no_ospf_default_information_originate,
     EXTERNAL_INFO (DEFAULT_ROUTE) = NULL;
   }
 
-  ospf_routemap_unset (DEFAULT_ROUTE);
-  return ospf_redistribute_default_unset ();
+  ospf_routemap_unset (ospf, DEFAULT_ROUTE);
+  return ospf_redistribute_default_unset (ospf);
 }
 
 DEFUN (ospf_default_metric,
@@ -6326,7 +6383,9 @@ DEFUN (ospf_distance_source,
        "Distance value\n"
        "IP source prefix\n")
 {
-  ospf_distance_set (vty, argv[0], argv[1], NULL);
+  struct ospf *ospf = vty->index;
+
+  ospf_distance_set (vty, ospf, argv[0], argv[1], NULL);
 
   return CMD_SUCCESS;
 }
@@ -6339,7 +6398,10 @@ DEFUN (no_ospf_distance_source,
        "Distance value\n"
        "IP source prefix\n")
 {
-  ospf_distance_unset (vty, argv[0], argv[1], NULL);
+  struct ospf *ospf = vty->index;
+
+  ospf_distance_unset (vty, ospf, argv[0], argv[1], NULL);
+
   return CMD_SUCCESS;
 }
 
@@ -6351,7 +6413,10 @@ DEFUN (ospf_distance_source_access_list,
        "IP source prefix\n"
        "Access list name\n")
 {
-  ospf_distance_set (vty, argv[0], argv[1], argv[2]);
+  struct ospf *ospf = vty->index;
+
+  ospf_distance_set (vty, ospf, argv[0], argv[1], argv[2]);
+
   return CMD_SUCCESS;
 }
 
@@ -6364,7 +6429,10 @@ DEFUN (no_ospf_distance_source_access_list,
        "IP source prefix\n"
        "Access list name\n")
 {
-  ospf_distance_unset (vty, argv[0], argv[1], argv[2]);
+  struct ospf *ospf = vty->index;
+
+  ospf_distance_unset (vty, ospf, argv[0], argv[1], argv[2]);
+
   return CMD_SUCCESS;
 }
 
@@ -6527,8 +6595,9 @@ DEFUN (show_ip_ospf_border_routers,
        "show all the ABR's and ASBR's\n"
        "for this area\n")
 {
-  struct ospf *ospf = ospf_top;
+  struct ospf *ospf;
 
+  ospf = ospf_lookup ();
   if (ospf == NULL)
     {
       vty_out (vty, "OSPF is not enabled%s", VTY_NEWLINE);
@@ -6542,7 +6611,7 @@ DEFUN (show_ip_ospf_border_routers,
     }
 
   /* Show Network routes.
-  show_ip_ospf_route_network (vty, ospf_top->new_table);   */
+  show_ip_ospf_route_network (vty, ospf->new_table);   */
 
   /* Show Router routes. */
   show_ip_ospf_route_router (vty, ospf->new_rtrs);
@@ -6559,8 +6628,9 @@ DEFUN (show_ip_ospf_route,
        "OSPF information\n"
        "OSPF routing table\n")
 {
-  struct ospf *ospf = ospf_top;
+  struct ospf *ospf;
 
+  ospf = ospf_lookup ();
   if (ospf == NULL)
     {
       vty_out (vty, "OSPF is not enabled%s", VTY_NEWLINE);
@@ -7032,13 +7102,13 @@ config_write_ospf_redistribute (struct vty *vty, struct ospf *ospf)
       {
         vty_out (vty, " redistribute %s", distribute_str[type]);
        if (ospf->dmetric[type].value >= 0)
-         vty_out (vty, " metric %d", ospf_top->dmetric[type].value);
+         vty_out (vty, " metric %d", ospf->dmetric[type].value);
        
         if (ospf->dmetric[type].type == EXTERNAL_METRIC_TYPE_1)
          vty_out (vty, " metric-type 1");
 
-       if (ROUTEMAP_NAME (type))
-         vty_out (vty, " route-map %s", ROUTEMAP_NAME (type));
+       if (ROUTEMAP_NAME (ospf, type))
+         vty_out (vty, " route-map %s", ROUTEMAP_NAME (ospf, type));
        
         vty_out (vty, "%s", VTY_NEWLINE);
       }
@@ -7083,8 +7153,9 @@ config_write_ospf_distribute (struct vty *vty, struct ospf *ospf)
          if (ospf->dmetric[DEFAULT_ROUTE].type == EXTERNAL_METRIC_TYPE_1)
            vty_out (vty, " metric-type 1");
 
-         if (ROUTEMAP_NAME (DEFAULT_ROUTE))
-           vty_out (vty, " route-map %s", ROUTEMAP_NAME (DEFAULT_ROUTE));
+         if (ROUTEMAP_NAME (ospf, DEFAULT_ROUTE))
+           vty_out (vty, " route-map %s",
+                    ROUTEMAP_NAME (ospf, DEFAULT_ROUTE));
          
          vty_out (vty, "%s", VTY_NEWLINE);
        }
@@ -7134,10 +7205,11 @@ config_write_ospf_distance (struct vty *vty, struct ospf *ospf)
 int
 ospf_config_write (struct vty *vty)
 {
-  struct ospf *ospf = ospf_top;
+  struct ospf *ospf;
   listnode node;
   int write = 0;
 
+  ospf = ospf_lookup ();
   if (ospf != NULL)
     {
       /* `router ospf' print. */
@@ -7182,7 +7254,7 @@ ospf_config_write (struct vty *vty)
       config_write_ospf_redistribute (vty, ospf);
 
       /* passive-interface print. */
-      for (node = listhead (ospf->iflist); node; nextnode (node))
+      for (node = listhead (om->iflist); node; nextnode (node))
         {
           struct interface *ifp = getdata (node);
 
@@ -7642,5 +7714,3 @@ ospf_vty_init ()
   /* Init zebra related vty commands. */
   ospf_vty_zebra_init ();
 }
-
-
index baba11d731dbee9a856c8502a6af8fc4cc831fdf..bdb0c0f5acf77fe69993a3e9051b61c6f5b56303 100644 (file)
@@ -59,7 +59,7 @@ int
 ospf_interface_add (int command, struct zclient *zclient, zebra_size_t length)
 {
   struct interface *ifp;
-  struct ospf *ospf = ospf_top;
+  struct ospf *ospf;
 
   ifp = zebra_interface_add_read (zclient->ibuf);
 
@@ -82,7 +82,9 @@ ospf_interface_add (int command, struct zclient *zclient, zebra_size_t length)
        IF_DEF_PARAMS (ifp)->type = OSPF_IFTYPE_LOOPBACK;
     }
 
-  ospf_if_update (ospf);
+  ospf = ospf_lookup ();
+  if (ospf != NULL)
+    ospf_if_update (ospf);
 
 #ifdef HAVE_SNMP
   ospf_snmp_if_update (ifp);
@@ -246,7 +248,7 @@ int
 ospf_interface_address_add (int command, struct zclient *zclient,
                            zebra_size_t length)
 {
-  struct ospf *ospf = ospf_top;
+  struct ospf *ospf;
   struct connected *c;
 
   c = zebra_interface_address_add_read (zclient->ibuf);
@@ -254,7 +256,9 @@ ospf_interface_address_add (int command, struct zclient *zclient,
   if (c == NULL)
     return 0;
 
-  ospf_if_update (ospf);
+  ospf = ospf_lookup ();
+  if (ospf != NULL)
+    ospf_if_update (ospf);
 
 #ifdef HAVE_SNMP
   ospf_snmp_if_update (c->ifp);
@@ -267,7 +271,7 @@ int
 ospf_interface_address_delete (int command, struct zclient *zclient,
                               zebra_size_t length)
 {
-  struct ospf *ospf = ospf_top;
+  struct ospf *ospf;
   struct connected *c;
   struct interface *ifp;
   struct ospf_interface *oi;
@@ -299,7 +303,9 @@ ospf_interface_address_delete (int command, struct zclient *zclient,
 
   connected_free (c);
 
-  ospf_if_update (ospf);
+  ospf = ospf_lookup ();
+  if (ospf != NULL)
+    ospf_if_update (ospf);
 
   return 0;
 }
@@ -471,9 +477,8 @@ ospf_is_type_redistributed (int type)
 }
 
 int
-ospf_redistribute_set (int type, int mtype, int mvalue)
+ospf_redistribute_set (struct ospf *ospf, int type, int mtype, int mvalue)
 {
-  struct ospf *ospf = ospf_top;
   int force = 0;
   
   if (ospf_is_type_redistributed (type))
@@ -515,10 +520,8 @@ ospf_redistribute_set (int type, int mtype, int mvalue)
 }
 
 int
-ospf_redistribute_unset (int type)
+ospf_redistribute_unset (struct ospf *ospf, int type)
 {
-  struct ospf *ospf = ospf_top;
-
   if (type == zclient->redist_default)
     return CMD_SUCCESS;
 
@@ -543,11 +546,11 @@ ospf_redistribute_unset (int type)
 }
 
 int
-ospf_redistribute_default_set (int originate, int mtype, int mvalue)
+ospf_redistribute_default_set (struct ospf *ospf, int originate,
+                              int mtype, int mvalue)
 {
-  struct ospf *ospf = ospf_top;
-
   int force = 0;
+
   if (ospf_is_type_redistributed (DEFAULT_ROUTE))
     {
       if (mtype != ospf->dmetric[DEFAULT_ROUTE].type)
@@ -594,10 +597,8 @@ ospf_redistribute_default_set (int originate, int mtype, int mvalue)
 }
 
 int
-ospf_redistribute_default_unset ()
+ospf_redistribute_default_unset (struct ospf *ospf)
 {
-  struct ospf *ospf = ospf_top;
-
   if (!ospf_is_type_redistributed (DEFAULT_ROUTE))
     return CMD_SUCCESS;
 
@@ -616,10 +617,9 @@ ospf_redistribute_default_unset ()
 }
 
 int
-ospf_external_lsa_originate_check (struct external_info *ei)
+ospf_external_lsa_originate_check (struct ospf *ospf,
+                                  struct external_info *ei)
 {
-  struct ospf *ospf = ospf_top;
-
   /* If prefix is multicast, then do not originate LSA. */
   if (IN_MULTICAST (htonl (ei->p.prefix.s_addr)))
     {
@@ -670,7 +670,7 @@ ospf_redistribute_check (struct ospf *ospf,
   if (changed)
     *changed = 0;
 
-  if (!ospf_external_lsa_originate_check (ei))
+  if (!ospf_external_lsa_originate_check (ospf, ei))
     return 0;
 
   /* Take care connected route. */
@@ -678,10 +678,10 @@ ospf_redistribute_check (struct ospf *ospf,
       !ospf_distribute_check_connected (ospf, ei))
     return 0;
 
-  if (!DEFAULT_ROUTE_TYPE (type) && DISTRIBUTE_NAME (type))
+  if (!DEFAULT_ROUTE_TYPE (type) && DISTRIBUTE_NAME (ospf, type))
     /* distirbute-list exists, but access-list may not? */
-    if (DISTRIBUTE_LIST (type))
-      if (access_list_apply (DISTRIBUTE_LIST (type), p) == FILTER_DENY)
+    if (DISTRIBUTE_LIST (ospf, type))
+      if (access_list_apply (DISTRIBUTE_LIST (ospf, type), p) == FILTER_DENY)
        {
          if (IS_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE))
            zlog_info ("Redistribute[%s]: %s/%d filtered by ditribute-list.",
@@ -694,11 +694,11 @@ ospf_redistribute_check (struct ospf *ospf,
   ospf_reset_route_map_set_values (&ei->route_map_set);
   
   /* apply route-map if needed */
-  if (ROUTEMAP_NAME (type))
+  if (ROUTEMAP_NAME (ospf, type))
     {
       int ret;
 
-      ret = route_map_apply (ROUTEMAP (type), (struct prefix *)p,
+      ret = route_map_apply (ROUTEMAP (ospf, type), (struct prefix *)p,
                             RMAP_OSPF, ei);
 
       if (ret == RMAP_DENYMATCH)
@@ -722,23 +722,23 @@ ospf_redistribute_check (struct ospf *ospf,
 
 /* OSPF route-map set for redistribution */
 void
-ospf_routemap_set (int type, char *name)
+ospf_routemap_set (struct ospf *ospf, int type, char *name)
 {
-  if (ROUTEMAP_NAME (type))
-    free (ROUTEMAP_NAME (type));
+  if (ROUTEMAP_NAME (ospf, type))
+    free (ROUTEMAP_NAME (ospf, type));
 
-  ROUTEMAP_NAME (type) = strdup (name);
-  ROUTEMAP (type) = route_map_lookup_by_name (name);
+  ROUTEMAP_NAME (ospf, type) = strdup (name);
+  ROUTEMAP (ospf, type) = route_map_lookup_by_name (name);
 }
 
 void
-ospf_routemap_unset (int type)
+ospf_routemap_unset (struct ospf *ospf, int type)
 {
-  if (ROUTEMAP_NAME (type))
-    free (ROUTEMAP_NAME (type));
+  if (ROUTEMAP_NAME (ospf, type))
+    free (ROUTEMAP_NAME (ospf, type));
 
-  ROUTEMAP_NAME (type) = NULL;
-  ROUTEMAP (type) = NULL;
+  ROUTEMAP_NAME (ospf, type) = NULL;
+  ROUTEMAP (ospf, type) = NULL;
 }
 
 /* Zebra route add and delete treatment. */
@@ -752,7 +752,7 @@ ospf_zebra_read_ipv4 (int command, struct zclient *zclient,
   struct in_addr nexthop;
   struct prefix_ipv4 p;
   struct external_info *ei;
-  struct ospf *ospf = ospf_top;
+  struct ospf *ospf;
 
   s = zclient->ibuf;
   ifindex = 0;
@@ -785,6 +785,10 @@ ospf_zebra_read_ipv4 (int command, struct zclient *zclient,
   if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC))
     api.metric = stream_getl (s);
 
+  ospf = ospf_lookup ();
+  if (ospf == NULL)
+    return 0;
+
   if (command == ZEBRA_IPV4_ROUTE_ADD)
     {
       ei = ospf_external_info_add (api.type, p, ifindex, nexthop);
@@ -833,17 +837,17 @@ int
 ospf_distribute_list_out_set (struct ospf *ospf, int type, char *name)
 {
   /* Lookup access-list for distribute-list. */
-  DISTRIBUTE_LIST (type) = access_list_lookup (AFI_IP, name);
+  DISTRIBUTE_LIST (ospf, type) = access_list_lookup (AFI_IP, name);
 
   /* Clear previous distribute-name. */
-  if (DISTRIBUTE_NAME (type))
-    free (DISTRIBUTE_NAME (type));
+  if (DISTRIBUTE_NAME (ospf, type))
+    free (DISTRIBUTE_NAME (ospf, type));
 
   /* Set distribute-name. */
-  DISTRIBUTE_NAME (type) = strdup (name);
+  DISTRIBUTE_NAME (ospf, type) = strdup (name);
 
   /* If access-list have been set, schedule update timer. */
-  if (DISTRIBUTE_LIST (type))
+  if (DISTRIBUTE_LIST (ospf, type))
     ospf_distribute_list_update (ospf, type);
 
   return CMD_SUCCESS;
@@ -853,17 +857,17 @@ int
 ospf_distribute_list_out_unset (struct ospf *ospf, int type, char *name)
 {
   /* Schedule update timer. */
-  if (DISTRIBUTE_LIST (type))
+  if (DISTRIBUTE_LIST (ospf, type))
     ospf_distribute_list_update (ospf, type);
 
   /* Unset distribute-list. */
-  DISTRIBUTE_LIST (type) = NULL;
+  DISTRIBUTE_LIST (ospf, type) = NULL;
 
   /* Clear distribute-name. */
-  if (DISTRIBUTE_NAME (type))
-    free (DISTRIBUTE_NAME (type));
+  if (DISTRIBUTE_NAME (ospf, type))
+    free (DISTRIBUTE_NAME (ospf, type));
   
-  DISTRIBUTE_NAME (type) = NULL;
+  DISTRIBUTE_NAME (ospf, type) = NULL;
 
   return CMD_SUCCESS;
 }
@@ -877,11 +881,15 @@ ospf_distribute_list_update_timer (struct thread *thread)
   struct route_table *rt;
   struct ospf_lsa *lsa;
   u_char type;
-  struct ospf *ospf = ospf_top;
+  struct ospf *ospf;
 
   type = (int) THREAD_ARG (thread);
   rt = EXTERNAL_INFO (type);
 
+  ospf = ospf_lookup ();
+  if (ospf == NULL)
+    return 0;
+
   ospf->t_distribute_update = NULL;
 
   zlog_info ("Zebra[Redistribute]: distribute-list update timer fired!");
@@ -927,20 +935,21 @@ ospf_distribute_list_update (struct ospf *ospf, int type)
 void
 ospf_filter_update (struct access_list *access)
 {
-  struct ospf *ospf = ospf_top;
+  struct ospf *ospf;
   int type;
   int abr_inv = 0;
   struct ospf_area *area;
   listnode node;
 
   /* If OSPF instatnce does not exist, return right now. */
+  ospf = ospf_lookup ();
   if (ospf == NULL)
     return;
 
   /* Update distribute-list, and apply filter. */
   for (type = 0; type < ZEBRA_ROUTE_MAX; type++)
     {
-      if (ROUTEMAP (type) != NULL)
+      if (ROUTEMAP (ospf, type) != NULL)
        {
          /* if route-map is not NULL it may be using this access list */
          ospf_distribute_list_update (ospf, type);
@@ -948,22 +957,22 @@ ospf_filter_update (struct access_list *access)
        }
       
 
-      if (DISTRIBUTE_NAME (type))
+      if (DISTRIBUTE_NAME (ospf, type))
        {
          /* Keep old access-list for distribute-list. */
-         struct access_list *old = DISTRIBUTE_LIST (type);
+         struct access_list *old = DISTRIBUTE_LIST (ospf, type);
          
          /* Update access-list for distribute-list. */
-         DISTRIBUTE_LIST (type) =
-           access_list_lookup (AFI_IP, DISTRIBUTE_NAME (type));
+         DISTRIBUTE_LIST (ospf, type) =
+           access_list_lookup (AFI_IP, DISTRIBUTE_NAME (ospf, type));
          
          /* No update for this distribute type. */
-         if (old == NULL && DISTRIBUTE_LIST (type) == NULL)
+         if (old == NULL && DISTRIBUTE_LIST (ospf, type) == NULL)
            continue;
          
          /* Schedule distribute-list update timer. */
-         if (DISTRIBUTE_LIST (type) == NULL ||
-             strcmp (DISTRIBUTE_NAME (type), access->name) == 0)
+         if (DISTRIBUTE_LIST (ospf, type) == NULL ||
+             strcmp (DISTRIBUTE_NAME (ospf, type), access->name) == 0)
            ospf_distribute_list_update (ospf, type);
        }
     }
@@ -986,7 +995,7 @@ ospf_filter_update (struct access_list *access)
       }
 
   /* Schedule ABR tasks -- this will be changed -- takada. */
-  if (OSPF_IS_ABR && abr_inv)
+  if (IS_OSPF_ABR (ospf) && abr_inv)
     ospf_schedule_abr_task (ospf);
 }
 
@@ -1007,15 +1016,14 @@ ospf_distance_free (struct ospf_distance *odistance)
 }
 
 int
-ospf_distance_set (struct vty *vty, char *distance_str, char *ip_str,
-                  char *access_list_str)
+ospf_distance_set (struct vty *vty, struct ospf *ospf, char *distance_str,
+                  char *ip_str, char *access_list_str)
 {
   int ret;
   struct prefix_ipv4 p;
   u_char distance;
   struct route_node *rn;
   struct ospf_distance *odistance;
-  struct ospf *ospf = ospf_top;
 
   ret = str2prefix_ipv4 (ip_str, &p);
   if (ret == 0)
@@ -1055,15 +1063,14 @@ ospf_distance_set (struct vty *vty, char *distance_str, char *ip_str,
 }
 
 int
-ospf_distance_unset (struct vty *vty, char *distance_str, char *ip_str,
-                    char *access_list_str)
+ospf_distance_unset (struct vty *vty, struct ospf *ospf, char *distance_str,
+                    char *ip_str, char *access_list_str)
 {
   int ret;
   struct prefix_ipv4 p;
   u_char distance;
   struct route_node *rn;
   struct ospf_distance *odistance;
-  struct ospf *ospf = ospf_top;
 
   ret = str2prefix_ipv4 (ip_str, &p);
   if (ret == 0)
@@ -1114,8 +1121,9 @@ ospf_distance_reset (struct ospf *ospf)
 u_char
 ospf_distance_apply (struct prefix_ipv4 *p, struct ospf_route *or)
 {
-  struct ospf *ospf = ospf_top;
+  struct ospf *ospf;
 
+  ospf = ospf_lookup ();
   if (ospf == NULL)
     return 0;
 
index a98d5be044d0e60fb015e5a84b766de016eaebe2..099af5587b2eb61070f4d608156e8b9c92c720c5 100644 (file)
@@ -52,8 +52,12 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 #include "ospfd/ospf_route.h"
 #include "ospfd/ospf_ase.h"
 
-/* OSPF instance top. */
-struct ospf *ospf_top;
+\f
+/* 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 @@ ospf_router_id_update (struct ospf *ospf)
 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 @@ ospf_new ()
   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 @@ ospf_new ()
 }
 
 struct ospf *
-ospf_get ()
+ospf_lookup ()
 {
-  struct ospf *ospf = ospf_top;
+  if (listcount (om->ospf) == 0)
+    return NULL;
 
-  if (ospf != NULL)
-    return ospf;
+  return getdata (listhead (om->ospf));
+}
+
+void
+ospf_add (struct ospf *ospf)
+{
+  listnode_add (om->ospf, ospf);
+}
 
-  ospf = ospf_new ();
+void
+ospf_delete (struct ospf *ospf)
+{
+  listnode_delete (om->ospf, ospf);
+}
 
-  if (ospf->router_id_static.s_addr == 0)
-    ospf_router_id_update (ospf);
+struct ospf *
+ospf_get ()
+{
+  struct ospf *ospf;
+
+  ospf = ospf_lookup ();
+  if (ospf == NULL)
+    {
+      ospf = ospf_new ();
+      ospf_add (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 @@ ospf_finish (struct ospf *ospf)
 
   /* 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_finish (struct ospf *ospf)
   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);
 }
 
 \f
@@ -706,13 +730,12 @@ ospf_network_run (struct ospf *ospf, struct prefix *p, struct ospf_area *area)
   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 @@ ospf_if_update (struct ospf *ospf)
       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 @@ ospf_nbr_nbma_poll_interval_unset (struct ospf *ospf, struct in_addr addr)
 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 @@ ospf_prefix_list_update (struct prefix_list *plist)
     }
 
   /* Schedule ABR tasks. */
-  if (OSPF_IS_ABR && abr_inv)
+  if (IS_OSPF_ABR (ospf) && abr_inv)
     ospf_schedule_abr_task (ospf);
 }
 
 void
-ospf_init ()
+ospf_master_init ()
 {
-  /* Make empty list of ospf list. */
-  ospf_top = NULL;
+  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 ()
+{
   prefix_list_add_hook (ospf_prefix_list_update);
   prefix_list_delete_hook (ospf_prefix_list_update);
 }
index be806212c4488b6950f995593e0fd48ddc9cad15..f842486e85e3b77cf57716c6b80ec7e381f6ebb5 100644 (file)
 #define OSPF_LS_REFRESH_SHIFT       (60 * 15)
 #define OSPF_LS_REFRESH_JITTER      60
 
+/* OSPF master for system wide configuration and variables. */
+struct ospf_master
+{
+  /* OSPF instance. */
+  struct list *ospf;
+
+  /* OSPF thread master. */
+  struct thread_master *master;
+
+  /* Zebra interface list. */
+  struct list *iflist;
+
+  /* Redistributed external information. */
+  struct route_table *external_info[ZEBRA_ROUTE_MAX + 1];
+#define EXTERNAL_INFO(T)      om->external_info[T]
+
+  /* OSPF start time. */
+  time_t start_time;
+
+  /* Various OSPF global configuration. */
+  u_char options;
+};
+
 /* OSPF instance structure. */
 struct ospf
 {
@@ -175,16 +198,11 @@ struct ospf
   struct route_table *nbr_nbma;
   struct ospf_area *backbone;           /* Pointer to the Backbone Area. */
 
-  list iflist;                          /* Zebra derived interfaces. */
   list oiflist;                         /* ospf interfaces */
 
   /* LSDB of AS-external-LSAs. */
   struct ospf_lsdb *lsdb;
   
-  /* Redistributed external information. */
-  struct route_table *external_info[ZEBRA_ROUTE_MAX + 1];
-#define EXTERNAL_INFO(T)      ospf_top->external_info[T]
-
   /* Flags. */
   int external_origin;                 /* AS-external-LSA origin flag. */
   int ase_calc;                                /* ASE calculation flag. */
@@ -238,8 +256,8 @@ struct ospf
     char *name;
     struct access_list *list;
   } dlist[ZEBRA_ROUTE_MAX];
-#define DISTRIBUTE_NAME(T)    ospf_top->dlist[T].name
-#define DISTRIBUTE_LIST(T)    ospf_top->dlist[T].list
+#define DISTRIBUTE_NAME(O,T)    (O)->dlist[T].name
+#define DISTRIBUTE_LIST(O,T)    (O)->dlist[T].list
 
   /* Redistribute metric info. */
   struct 
@@ -255,8 +273,8 @@ struct ospf
     char *name;
     struct route_map *map;
   } route_map [ZEBRA_ROUTE_MAX + 1]; /* +1 is for default-information */
-#define ROUTEMAP_NAME(T)   ospf_top->route_map[T].name
-#define ROUTEMAP(T)        ospf_top->route_map[T].map
+#define ROUTEMAP_NAME(O,T)   (O)->route_map[T].name
+#define ROUTEMAP(O,T)        (O)->route_map[T].map
   
   int default_metric;          /* Default metric for redistribute. */
 
@@ -438,8 +456,8 @@ struct ospf_nbr_nbma
 #define OSPF_AREA_SAME(X,Y) \
         (memcmp ((X->area_id), (Y->area_id), IPV4_MAX_BYTELEN) == 0)
 
-#define OSPF_IS_ABR            (ospf_top->flags & OSPF_FLAG_ABR)
-#define OSPF_IS_ASBR           (ospf_top->flags & OSPF_FLAG_ASBR)
+#define IS_OSPF_ABR(O)         ((O)->flags & OSPF_FLAG_ABR)
+#define IS_OSPF_ASBR(O)                ((O)->flags & OSPF_FLAG_ASBR)
 
 #define OSPF_IS_AREA_ID_BACKBONE(I) ((I).s_addr == OSPF_AREA_BACKBONE)
 #define OSPF_IS_AREA_BACKBONE(A) OSPF_IS_AREA_ID_BACKBONE ((A)->area_id)
@@ -487,7 +505,8 @@ struct ospf_nbr_nbma
         }                                                                     \
     } while (0)
 
-/* Messages */
+/* Extern variables. */
+extern struct ospf_master *om;
 extern struct message ospf_ism_state_msg[];
 extern struct message ospf_nsm_state_msg[];
 extern struct message ospf_lsa_type_msg[];
@@ -502,10 +521,10 @@ extern int ospf_redistributed_proto_max;
 extern int ospf_network_type_msg_max;
 extern struct zclient *zclient;
 extern struct thread_master *master;
-extern struct ospf *ospf_top;
 extern int ospf_zlog;
 
 /* Prototypes. */
+struct ospf *ospf_lookup ();
 struct ospf *ospf_get ();
 void ospf_finish (struct ospf *);
 int ospf_router_id_update_timer (struct thread *);
@@ -556,4 +575,6 @@ void ospf_area_del_if (struct ospf_area *, struct ospf_interface *);
 void ospf_route_map_init ();
 void ospf_snmp_init ();
 
+void ospf_master_init ();
+
 #endif /* _ZEBRA_OSPFD_H */