Browse Source

ospf6d/ospfd: refactor some common defines

Rearranging common defs and structures for use betweeen OSPFv2 and
OSPFv3.  Created a new file called libospf.h under lib directory to
hold defines that are common between OSPFv2 and OSPFv3 code bases.

[DL: split of defines refactor from timer refactor]
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Dinesh Dutt 6 years ago
parent
commit
8551e6dadc

+ 1 - 1
lib/Makefile.am

@@ -27,7 +27,7 @@ pkginclude_HEADERS = \
 	str.h stream.h table.h thread.h vector.h version.h vty.h zebra.h \
 	plist.h zclient.h sockopt.h smux.h md5.h if_rmap.h keychain.h \
 	privs.h sigevent.h pqueue.h jhash.h zassert.h memtypes.h \
-	workqueue.h route_types.h
+	workqueue.h route_types.h libospf.h
 
 EXTRA_DIST = \
 	regex.c regex-gnu.h \

+ 82 - 0
lib/libospf.h

@@ -0,0 +1,82 @@
+/*
+ * Defines and structures common to OSPFv2 and OSPFv3
+ * Copyright (C) 1998, 99, 2000 Kunihiro Ishiguro, Toshiaki Takada
+ *
+ * This file is part of GNU Zebra.
+ *
+ * GNU Zebra is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2, or (at your option) any
+ * later version.
+ *
+ * GNU Zebra is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Zebra; see the file COPYING.  If not, write to the Free
+ * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#ifndef _LIBOSPFD_H
+#define _LIBOSPFD_H
+
+/* IP precedence. */
+#ifndef IPTOS_PREC_INTERNETCONTROL
+#define IPTOS_PREC_INTERNETCONTROL	0xC0
+#endif /* IPTOS_PREC_INTERNETCONTROL */
+
+/* Default protocol, port number. */
+#ifndef IPPROTO_OSPFIGP
+#define IPPROTO_OSPFIGP         89
+#endif /* IPPROTO_OSPFIGP */
+
+/* Architectual Constants */
+#ifdef DEBUG
+#define OSPF_LS_REFRESH_TIME                    60
+#else
+#define OSPF_LS_REFRESH_TIME                  1800
+#endif
+#define OSPF_MIN_LS_INTERVAL                     5
+#define OSPF_MIN_LS_ARRIVAL                      1
+#define OSPF_LSA_INITIAL_AGE                     0	/* useful for debug */
+#define OSPF_LSA_MAXAGE                       3600
+#define OSPF_CHECK_AGE                         300
+#define OSPF_LSA_MAXAGE_DIFF                   900
+#define OSPF_LS_INFINITY                  0xffffff
+#define OSPF_DEFAULT_DESTINATION        0x00000000      /* 0.0.0.0 */
+#define OSPF_INITIAL_SEQUENCE_NUMBER    0x80000001
+#define OSPF_MAX_SEQUENCE_NUMBER        0x7fffffff
+
+/* OSPF interface default values. */
+#define OSPF_OUTPUT_COST_DEFAULT           10
+#define OSPF_OUTPUT_COST_INFINITE	   UINT16_MAX
+#define OSPF_ROUTER_DEAD_INTERVAL_DEFAULT  40
+#define OSPF_ROUTER_DEAD_INTERVAL_MINIMAL   1
+#define OSPF_HELLO_INTERVAL_DEFAULT        10
+#define OSPF_ROUTER_PRIORITY_DEFAULT        1
+#define OSPF_RETRANSMIT_INTERVAL_DEFAULT    5
+#define OSPF_TRANSMIT_DELAY_DEFAULT         1
+#define OSPF_DEFAULT_BANDWIDTH		 10000	/* Kbps */
+
+#define OSPF_DEFAULT_REF_BANDWIDTH	100000  /* Kbps */
+
+#define OSPF_POLL_INTERVAL_DEFAULT         60
+#define OSPF_NEIGHBOR_PRIORITY_DEFAULT      0
+
+#define OSPF_MTU_IGNORE_DEFAULT             0
+#define OSPF_FAST_HELLO_DEFAULT             0
+
+#define OSPF_AREA_BACKBONE              0x00000000      /* 0.0.0.0 */
+
+/* SPF Throttling timer values. */
+#define OSPF_SPF_DELAY_DEFAULT              200
+#define OSPF_SPF_HOLDTIME_DEFAULT           1000
+#define OSPF_SPF_MAX_HOLDTIME_DEFAULT	    10000
+
+#define OSPF_LSA_MAXAGE_CHECK_INTERVAL		30
+#define OSFP_LSA_MAXAGE_REMOVE_DELAY_DEFAULT	60
+
+#endif /* _LIBOSPFD_H */

+ 3 - 3
ospf6d/ospf6_abr.c

@@ -253,7 +253,7 @@ ospf6_abr_originate_summary_to_area (struct ospf6_route *route,
     }
 
   /* do not generate if the route cost is greater or equal to LSInfinity */
-  if (route->path.cost >= LS_INFINITY)
+  if (route->path.cost >= OSPF_LS_INFINITY)
     {
       if (is_debug)
         zlog_debug ("The cost exceeds LSInfinity, withdraw");
@@ -296,7 +296,7 @@ ospf6_abr_originate_summary_to_area (struct ospf6_route *route,
       /* ranges are ignored when originate backbone routes to transit area.
          Otherwise, if ranges are configured, the route is suppressed. */
       if (range && ! CHECK_FLAG (range->flag, OSPF6_ROUTE_REMOVE) &&
-          (route->path.area_id != BACKBONE_AREA_ID ||
+          (route->path.area_id != OSPF_AREA_BACKBONE ||
            ! IS_AREA_TRANSIT (area)))
         {
           if (is_debug)
@@ -604,7 +604,7 @@ ospf6_abr_examin_summary (struct ospf6_lsa *lsa, struct ospf6_area *oa)
     }
 
   /* (1) if cost == LSInfinity or if the LSA is MaxAge */
-  if (cost == LS_INFINITY)
+  if (cost == OSPF_LS_INFINITY)
     {
       if (is_debug)
         zlog_debug ("cost is LS_INFINITY, ignore");

+ 1 - 0
ospf6d/ospf6_area.c

@@ -401,6 +401,7 @@ DEFUN (no_area_range,
     }
 
   ospf6_route_remove (range, oa->range_table);
+
   return CMD_SUCCESS;
 }
 

+ 0 - 2
ospf6d/ospf6_area.h

@@ -105,8 +105,6 @@ struct ospf6_area
 #define OSPF6_AREA_TRANSIT    0x04 /* TransitCapability */
 #define OSPF6_AREA_STUB       0x08
 
-#define BACKBONE_AREA_ID (htonl (0))
-#define IS_AREA_BACKBONE(oa) ((oa)->area_id == BACKBONE_AREA_ID)
 #define IS_AREA_ENABLED(oa) (CHECK_FLAG ((oa)->flag, OSPF6_AREA_ENABLE))
 #define IS_AREA_ACTIVE(oa) (CHECK_FLAG ((oa)->flag, OSPF6_AREA_ACTIVE))
 #define IS_AREA_TRANSIT(oa) (CHECK_FLAG ((oa)->flag, OSPF6_AREA_TRANSIT))

+ 2 - 2
ospf6d/ospf6_asbr.c

@@ -174,7 +174,7 @@ ospf6_asbr_lsa_add (struct ospf6_lsa *lsa)
       return;
     }
 
-  if (OSPF6_ASBR_METRIC (external) == LS_INFINITY)
+  if (OSPF6_ASBR_METRIC (external) == OSPF_LS_INFINITY)
     {
       if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL))
         zlog_debug ("Ignore LSA with LSInfinity Metric");
@@ -890,7 +890,7 @@ ospf6_routemap_rule_set_metric_compile (const char *arg)
   u_int32_t metric;
   char *endp;
   metric = strtoul (arg, &endp, 0);
-  if (metric > LS_INFINITY || *endp != '\0')
+  if (metric > OSPF_LS_INFINITY || *endp != '\0')
     return NULL;
   return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
 }

+ 4 - 4
ospf6d/ospf6_flood.c

@@ -113,7 +113,7 @@ ospf6_lsa_originate (struct ospf6_lsa *lsa)
   ospf6_lsdb_add (ospf6_lsa_copy (lsa), lsdb_self);
 
   lsa->refresh = thread_add_timer (master, ospf6_lsa_refresh, lsa,
-                                   LS_REFRESH_TIME);
+                                   OSPF_LS_REFRESH_TIME);
 
   if (IS_OSPF6_DEBUG_LSA_TYPE (lsa->header->type) ||
       IS_OSPF6_DEBUG_ORIGINATE_TYPE (lsa->header->type))
@@ -228,7 +228,7 @@ ospf6_install_lsa (struct ospf6_lsa *lsa)
   quagga_gettime (QUAGGA_CLK_MONOTONIC, &now);
   if (! OSPF6_LSA_IS_MAXAGE (lsa))
     lsa->expire = thread_add_timer (master, ospf6_lsa_expire, lsa,
-                                    MAXAGE + lsa->birth.tv_sec - now.tv_sec);
+                                    OSPF_LSA_MAXAGE + lsa->birth.tv_sec - now.tv_sec);
   else
     lsa->expire = NULL;
 
@@ -837,7 +837,7 @@ ospf6_receive_lsa (struct ospf6_neighbor *from,
           struct timeval now, res;
           quagga_gettime (QUAGGA_CLK_MONOTONIC, &now);
           timersub (&now, &old->installed, &res);
-          if (res.tv_sec < MIN_LS_ARRIVAL)
+          if (res.tv_sec < OSPF_MIN_LS_ARRIVAL)
             {
               if (is_debug)
                 zlog_debug ("LSA can't be updated within MinLSArrival, discard");
@@ -944,7 +944,7 @@ ospf6_receive_lsa (struct ospf6_neighbor *from,
       /* If database copy is in 'Seqnumber Wrapping',
          simply discard the received LSA */
       if (OSPF6_LSA_IS_MAXAGE (old) &&
-          old->header->seqnum == htonl (MAX_SEQUENCE_NUMBER))
+          old->header->seqnum == htonl (OSPF_MAX_SEQUENCE_NUMBER))
         {
           if (is_debug)
             {

+ 3 - 3
ospf6d/ospf6_interface.c

@@ -112,9 +112,9 @@ ospf6_interface_create (struct interface *ifp)
   oi->transdelay = OSPF6_INTERFACE_TRANSDELAY;
   oi->priority = OSPF6_INTERFACE_PRIORITY;
 
-  oi->hello_interval = OSPF6_INTERFACE_HELLO_INTERVAL;
-  oi->dead_interval = OSPF6_INTERFACE_DEAD_INTERVAL;
-  oi->rxmt_interval = OSPF6_INTERFACE_RXMT_INTERVAL;
+  oi->hello_interval = OSPF_HELLO_INTERVAL_DEFAULT;
+  oi->dead_interval = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT;
+  oi->rxmt_interval = OSPF_RETRANSMIT_INTERVAL_DEFAULT;
   oi->cost = OSPF6_INTERFACE_COST;
   oi->state = OSPF6_INTERFACE_DOWN;
   oi->flag = 0;

+ 16 - 16
ospf6d/ospf6_lsa.c

@@ -139,11 +139,11 @@ ospf6_lsa_is_differ (struct ospf6_lsa *lsa1,
 
   ospf6_lsa_age_current (lsa1);
   ospf6_lsa_age_current (lsa2);
-  if (ntohs (lsa1->header->age) == MAXAGE &&
-      ntohs (lsa2->header->age) != MAXAGE)
+  if (ntohs (lsa1->header->age) == OSPF_LSA_MAXAGE &&
+      ntohs (lsa2->header->age) != OSPF_LSA_MAXAGE)
     return 1;
-  if (ntohs (lsa1->header->age) != MAXAGE &&
-      ntohs (lsa2->header->age) == MAXAGE)
+  if (ntohs (lsa1->header->age) != OSPF_LSA_MAXAGE &&
+      ntohs (lsa2->header->age) == OSPF_LSA_MAXAGE)
     return 1;
 
   /* compare body */
@@ -218,19 +218,19 @@ ospf6_lsa_age_current (struct ospf6_lsa *lsa)
     zlog_warn ("LSA: quagga_gettime failed, may fail LSA AGEs: %s",
                safe_strerror (errno));
 
-  if (ntohs (lsa->header->age) >= MAXAGE)
+  if (ntohs (lsa->header->age) >= OSPF_LSA_MAXAGE)
     {
       /* ospf6_lsa_premature_aging () sets age to MAXAGE; when using
          relative time, we cannot compare against lsa birth time, so
          we catch this special case here. */
-      lsa->header->age = htons (MAXAGE);
-      return MAXAGE;
+      lsa->header->age = htons (OSPF_LSA_MAXAGE);
+      return OSPF_LSA_MAXAGE;
     }
   /* calculate age */
   ulage = now.tv_sec - lsa->birth.tv_sec;
 
   /* if over MAXAGE, set to it */
-  age = (ulage > MAXAGE ? MAXAGE : ulage);
+  age = (ulage > OSPF_LSA_MAXAGE ? OSPF_LSA_MAXAGE : ulage);
 
   lsa->header->age = htons (age);
   return age;
@@ -243,8 +243,8 @@ ospf6_lsa_age_update_to_send (struct ospf6_lsa *lsa, u_int32_t transdelay)
   unsigned short age;
 
   age = ospf6_lsa_age_current (lsa) + transdelay;
-  if (age > MAXAGE)
-    age = MAXAGE;
+  if (age > OSPF_LSA_MAXAGE)
+    age = OSPF_LSA_MAXAGE;
   lsa->header->age = htons (age);
 }
 
@@ -258,7 +258,7 @@ ospf6_lsa_premature_aging (struct ospf6_lsa *lsa)
   THREAD_OFF (lsa->expire);
   THREAD_OFF (lsa->refresh);
 
-  lsa->header->age = htons (MAXAGE);
+  lsa->header->age = htons (OSPF_LSA_MAXAGE);
   thread_execute (master, ospf6_lsa_expire, lsa, 0);
 }
 
@@ -297,15 +297,15 @@ ospf6_lsa_compare (struct ospf6_lsa *a, struct ospf6_lsa *b)
   ageb = ospf6_lsa_age_current (b);
 
   /* MaxAge check */
-  if (agea == MAXAGE && ageb != MAXAGE)
+  if (agea == OSPF_LSA_MAXAGE && ageb != OSPF_LSA_MAXAGE)
     return -1;
-  else if (agea != MAXAGE && ageb == MAXAGE)
+  else if (agea != OSPF_LSA_MAXAGE && ageb == OSPF_LSA_MAXAGE)
     return 1;
 
   /* Age check */
-  if (agea > ageb && agea - ageb >= MAX_AGE_DIFF)
+  if (agea > ageb && agea - ageb >= OSPF_LSA_MAXAGE_DIFF)
     return 1;
-  else if (agea < ageb && ageb - agea >= MAX_AGE_DIFF)
+  else if (agea < ageb && ageb - agea >= OSPF_LSA_MAXAGE_DIFF)
     return -1;
 
   /* neither recent */
@@ -653,7 +653,7 @@ ospf6_lsa_refresh (struct thread *thread)
   new = ospf6_lsa_create (self->header);
   new->lsdb = old->lsdb;
   new->refresh = thread_add_timer (master, ospf6_lsa_refresh, new,
-                                   LS_REFRESH_TIME);
+                                   OSPF_LS_REFRESH_TIME);
 
   /* store it in the LSDB for self-originated LSAs */
   ospf6_lsdb_add (ospf6_lsa_copy (new), lsdb_self);

+ 1 - 1
ospf6d/ospf6_lsa.h

@@ -107,7 +107,7 @@ struct ospf6_lsa_header
   ((L)->header->adv_router == (a) && (L)->header->id == (i) && \
    (L)->header->type == (t))
 #define OSPF6_LSA_IS_DIFFER(L1, L2)  ospf6_lsa_is_differ (L1, L2)
-#define OSPF6_LSA_IS_MAXAGE(L) (ospf6_lsa_age_current (L) == MAXAGE)
+#define OSPF6_LSA_IS_MAXAGE(L) (ospf6_lsa_age_current (L) == OSPF_LSA_MAXAGE)
 #define OSPF6_LSA_IS_CHANGED(L1, L2) ospf6_lsa_is_changed (L1, L2)
 
 struct ospf6_lsa

+ 1 - 1
ospf6d/ospf6_lsdb.c

@@ -572,7 +572,7 @@ ospf6_new_ls_seqnum (u_int16_t type, u_int32_t id, u_int32_t adv_router,
   /* if current database copy not found, return InitialSequenceNumber */
   lsa = ospf6_lsdb_lookup (type, id, adv_router, lsdb);
   if (lsa == NULL)
-    seqnum = INITIAL_SEQUENCE_NUMBER;
+    seqnum = OSPF_INITIAL_SEQUENCE_NUMBER;
   else
     seqnum = (signed long) ntohl (lsa->header->seqnum) + 1;
 

+ 1 - 1
ospf6d/ospf6_message.c

@@ -1282,7 +1282,7 @@ ospf6_rxpacket_examin (struct ospf6_interface *oi, struct ospf6_header *oh, cons
   {
     if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
     {
-      if (oh->area_id == BACKBONE_AREA_ID)
+      if (oh->area_id == OSPF_AREA_BACKBONE)
         zlog_debug ("%s: Message may be via Virtual Link: not supported", __func__);
       else
         zlog_debug

+ 1 - 0
ospf6d/ospf6_network.c

@@ -27,6 +27,7 @@
 #include "sockopt.h"
 #include "privs.h"
 
+#include "libospf.h"
 #include "ospf6_proto.h"
 #include "ospf6_network.h"
 

+ 0 - 21
ospf6d/ospf6_proto.h

@@ -26,33 +26,12 @@
 /* OSPF protocol version */
 #define OSPFV3_VERSION           3
 
-/* OSPF protocol number. */
-#ifndef IPPROTO_OSPFIGP
-#define IPPROTO_OSPFIGP         89
-#endif
-
 /* TOS field normaly null */
 #define DEFAULT_TOS_VALUE      0x0
 
-/* Architectural Constants */
-#define LS_REFRESH_TIME                1800  /* 30 min */
-#define MIN_LS_INTERVAL                   5
-#define MIN_LS_ARRIVAL                    1
-#define MAXAGE                         3600  /* 1 hour */
-#define CHECK_AGE                       300  /* 5 min */
-#define MAX_AGE_DIFF                    900  /* 15 min */
-#define LS_INFINITY                0xffffff  /* 24-bit binary value */
-#define INITIAL_SEQUENCE_NUMBER  0x80000001  /* signed 32-bit integer */
-#define MAX_SEQUENCE_NUMBER      0x7fffffff  /* signed 32-bit integer */
-
 #define ALLSPFROUTERS6 "ff02::5"
 #define ALLDROUTERS6   "ff02::6"
 
-/* Configurable Constants */
-
-#define DEFAULT_HELLO_INTERVAL       10
-#define DEFAULT_ROUTER_DEAD_INTERVAL 40
-
 #define OSPF6_ROUTER_BIT_W     (1 << 3)
 #define OSPF6_ROUTER_BIT_V     (1 << 2)
 #define OSPF6_ROUTER_BIT_E     (1 << 1)

+ 3 - 0
ospf6d/ospf6d.h

@@ -24,6 +24,9 @@
 
 #define OSPF6_DAEMON_VERSION    "0.9.7r"
 
+#include "libospf.h"
+#include "thread.h"
+
 /* global variables */
 extern struct thread_master *master;
 

+ 1 - 52
ospfd/ospfd.h

@@ -24,22 +24,13 @@
 #define _ZEBRA_OSPFD_H
 
 #include <zebra.h>
+#include "libospf.h"
 
 #include "filter.h"
 #include "log.h"
 
 #define OSPF_VERSION            2
 
-/* Default protocol, port number. */
-#ifndef IPPROTO_OSPFIGP
-#define IPPROTO_OSPFIGP         89
-#endif /* IPPROTO_OSPFIGP */
-
-/* IP precedence. */
-#ifndef IPTOS_PREC_INTERNETCONTROL
-#define IPTOS_PREC_INTERNETCONTROL	0xC0
-#endif /* IPTOS_PREC_INTERNETCONTROL */
-
 /* VTY port number. */
 #define OSPF_VTY_PORT          2604
 
@@ -50,29 +41,11 @@
 /* Default configuration file name for ospfd. */
 #define OSPF_DEFAULT_CONFIG   "ospfd.conf"
 
-/* Architectual Constants */
-#ifdef DEBUG
-#define OSPF_LS_REFRESH_TIME                    60
-#else
-#define OSPF_LS_REFRESH_TIME                  1800
-#endif
-#define OSPF_MIN_LS_INTERVAL                     5
-#define OSPF_MIN_LS_ARRIVAL                      1
-#define OSPF_LSA_INITIAL_AGE                     0	/* useful for debug */
-#define OSPF_LSA_MAXAGE                       3600
-#define OSPF_CHECK_AGE                         300
-#define OSPF_LSA_MAXAGE_DIFF                   900
-#define OSPF_LS_INFINITY                  0xffffff
-#define OSPF_DEFAULT_DESTINATION        0x00000000      /* 0.0.0.0 */
-#define OSPF_INITIAL_SEQUENCE_NUMBER    0x80000001
-#define OSPF_MAX_SEQUENCE_NUMBER        0x7fffffff
-
 #define OSPF_NSSA_TRANS_STABLE_DEFAULT		40
 
 #define OSPF_ALLSPFROUTERS              0xe0000005      /* 224.0.0.5 */
 #define OSPF_ALLDROUTERS                0xe0000006      /* 224.0.0.6 */
 
-#define OSPF_AREA_BACKBONE              0x00000000      /* 0.0.0.0 */
 
 /* OSPF Authentication Type. */
 #define OSPF_AUTH_NULL                      0
@@ -85,30 +58,6 @@
    been given or not in VLink command handlers */
 #define OSPF_AUTH_CMD_NOTSEEN              -2
 
-/* OSPF SPF timer values. */
-#define OSPF_SPF_DELAY_DEFAULT              200
-#define OSPF_SPF_HOLDTIME_DEFAULT           1000
-#define OSPF_SPF_MAX_HOLDTIME_DEFAULT	    10000
-
-/* OSPF interface default values. */
-#define OSPF_OUTPUT_COST_DEFAULT           10
-#define OSPF_OUTPUT_COST_INFINITE	   UINT16_MAX
-#define OSPF_ROUTER_DEAD_INTERVAL_DEFAULT  40
-#define OSPF_ROUTER_DEAD_INTERVAL_MINIMAL   1
-#define OSPF_HELLO_INTERVAL_DEFAULT        10
-#define OSPF_ROUTER_PRIORITY_DEFAULT        1
-#define OSPF_RETRANSMIT_INTERVAL_DEFAULT    5
-#define OSPF_TRANSMIT_DELAY_DEFAULT         1
-#define OSPF_DEFAULT_BANDWIDTH		 10000	/* Kbps */
-
-#define OSPF_DEFAULT_REF_BANDWIDTH	100000  /* Kbps */
-
-#define OSPF_POLL_INTERVAL_DEFAULT         60
-#define OSPF_NEIGHBOR_PRIORITY_DEFAULT      0
-
-#define OSPF_MTU_IGNORE_DEFAULT             0
-#define OSPF_FAST_HELLO_DEFAULT             0
-
 /* OSPF options. */
 #define OSPF_OPTION_T                    0x01  /* TOS. */
 #define OSPF_OPTION_E                    0x02