This code change does two things:

1) Removes ZEBRA_AFI_XXX #defines since they were redundant information
2) Switches afi_t to an enumerated type so that the compiler
can do a bit more compile time checking.

Signed-off-by: Donald Sharp <[email protected]>
---
 bgpd/bgp_open.c     |   44 +++++++++++++++++++++++---------------------
 bgpd/bgp_open.h     |    1 +
 bgpd/bgp_routemap.c |   14 ++++++--------
 lib/zebra.h         |   19 ++++++++-----------
 4 files changed, 38 insertions(+), 40 deletions(-)

diff --git a/bgpd/bgp_open.c b/bgpd/bgp_open.c
index b9d6e93..a4c84d2 100644
--- a/bgpd/bgp_open.c
+++ b/bgpd/bgp_open.c
@@ -126,23 +126,25 @@ bgp_afi_safi_valid_indices (afi_t afi, safi_t *safi)
 {
   switch (afi)
     {
-      case AFI_IP:
-#ifdef HAVE_IPV6
-      case AFI_IP6:
-#endif
-        switch (*safi)
-          {
-            /* BGP MPLS-labeled VPN SAFI isn't contigious with others, remap */
-            case SAFI_MPLS_LABELED_VPN:
-              *safi = SAFI_MPLS_VPN;
-            case SAFI_UNICAST:
-            case SAFI_MULTICAST:
-            case SAFI_MPLS_VPN:
-              return 1;
-          }
+    case AFI_IP:
+    case AFI_IP6:
+      switch (*safi)
+       {
+         /* BGP MPLS-labeled VPN SAFI isn't contigious with others, remap */
+       case SAFI_MPLS_LABELED_VPN:
+         *safi = SAFI_MPLS_VPN;
+       case SAFI_UNICAST:
+       case SAFI_MULTICAST:
+       case SAFI_MPLS_VPN:
+         return 1;
+       }
+      break;
+    case AFI_MAX:
+      zlog_debug ("unknown afi/safi (%u/%u)", afi, *safi);
+      return 0;
+      break;
     }
-  zlog_debug ("unknown afi/safi (%u/%u)", afi, *safi);
-  
+
   return 0;
 }
 
@@ -230,7 +232,7 @@ bgp_capability_orf_entry (struct peer *peer, struct 
capability_header *hdr)
     }
   
   /* validate number field */
-  if (sizeof (struct capability_orf_entry) + (entry.num * 2) > hdr->length)
+  if (CAPABILITY_CODE_ORF_LEN + (entry.num * 2) > hdr->length)
     {
       zlog_info ("%s ORF Capability entry length error,"
                  " Cap length %u, num %u",
@@ -432,14 +434,14 @@ static const int capcode_str_max = 
array_size(capcode_str);
 /* Minimum sizes for length field of each cap (so not inc. the header) */
 static const size_t cap_minsizes[] = 
 {
-  [CAPABILITY_CODE_MP]         = sizeof (struct capability_mp_data),
+  [CAPABILITY_CODE_MP]         = CAPABILITY_CODE_MP_LEN,
   [CAPABILITY_CODE_REFRESH]    = CAPABILITY_CODE_REFRESH_LEN,
-  [CAPABILITY_CODE_ORF]                = sizeof (struct capability_orf_entry),
-  [CAPABILITY_CODE_RESTART]    = sizeof (struct capability_gr),
+  [CAPABILITY_CODE_ORF]                = CAPABILITY_CODE_ORF_LEN,
+  [CAPABILITY_CODE_RESTART]    = 6,
   [CAPABILITY_CODE_AS4]                = CAPABILITY_CODE_AS4_LEN,
   [CAPABILITY_CODE_DYNAMIC]    = CAPABILITY_CODE_DYNAMIC_LEN,
   [CAPABILITY_CODE_REFRESH_OLD]        = CAPABILITY_CODE_REFRESH_LEN,
-  [CAPABILITY_CODE_ORF_OLD]    = sizeof (struct capability_orf_entry),
+  [CAPABILITY_CODE_ORF_OLD]    = CAPABILITY_CODE_ORF_LEN,
 };
 
 /**
diff --git a/bgpd/bgp_open.h b/bgpd/bgp_open.h
index 2b1382d..6233375 100644
--- a/bgpd/bgp_open.h
+++ b/bgpd/bgp_open.h
@@ -82,6 +82,7 @@ struct capability_gr
 #define CAPABILITY_CODE_DYNAMIC_LEN     0
 #define CAPABILITY_CODE_RESTART_LEN     2 /* Receiving only case */
 #define CAPABILITY_CODE_AS4_LEN         4
+#define CAPABILITY_CODE_ORF_LEN         5
 
 /* Cooperative Route Filtering Capability.  */
 
diff --git a/bgpd/bgp_routemap.c b/bgpd/bgp_routemap.c
index 20bf2eb..7555ca7 100644
--- a/bgpd/bgp_routemap.c
+++ b/bgpd/bgp_routemap.c
@@ -2383,14 +2383,12 @@ bgp_route_map_update (const char *unused)
     {
       for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
        {
-         if (bgp->rmap[ZEBRA_FAMILY_IPV4][i].name)
-           bgp->rmap[ZEBRA_FAMILY_IPV4][i].map = 
-             route_map_lookup_by_name (bgp->rmap[ZEBRA_FAMILY_IPV4][i].name);
-#ifdef HAVE_IPV6
-         if (bgp->rmap[ZEBRA_FAMILY_IPV6][i].name)
-           bgp->rmap[ZEBRA_FAMILY_IPV6][i].map =
-             route_map_lookup_by_name (bgp->rmap[ZEBRA_FAMILY_IPV6][i].name);
-#endif /* HAVE_IPV6 */
+         if (bgp->rmap[AFI_IP][i].name)
+           bgp->rmap[AFI_IP][i].map =
+             route_map_lookup_by_name (bgp->rmap[AFI_IP][i].name);
+         if (bgp->rmap[AFI_IP6][i].name)
+           bgp->rmap[AFI_IP6][i].map =
+             route_map_lookup_by_name (bgp->rmap[AFI_IP][i].name);
        }
     }
 }
diff --git a/lib/zebra.h b/lib/zebra.h
index a283f14..c5b767d 100644
--- a/lib/zebra.h
+++ b/lib/zebra.h
@@ -445,11 +445,6 @@ extern int proto_redistnum(int afi, const char *s);
 
 extern const char *zserv_command_string (unsigned int command);
 
-/* Zebra's family types. */
-#define ZEBRA_FAMILY_IPV4                1
-#define ZEBRA_FAMILY_IPV6                2
-#define ZEBRA_FAMILY_MAX                 3
-
 /* Error codes of zebra. */
 #define ZEBRA_ERR_NOERROR                0
 #define ZEBRA_ERR_RTEXIST               -1
@@ -482,11 +477,6 @@ extern const char *zserv_command_string (unsigned int 
command);
 #define        INADDR_LOOPBACK 0x7f000001      /* Internet address 127.0.0.1.  
*/
 #endif
 
-/* Address family numbers from RFC1700. */
-#define AFI_IP                    1
-#define AFI_IP6                   2
-#define AFI_MAX                   3
-
 /* Subsequent Address Family Identifier. */
 #define SAFI_UNICAST              1
 #define SAFI_MULTICAST            2
@@ -517,7 +507,14 @@ extern const char *zserv_command_string (unsigned int 
command);
 #define UNSET_FLAG(V,F)      (V) &= ~(F)
 
 /* AFI and SAFI type. */
-typedef u_int16_t afi_t;
+enum afi {
+  AFI_IP = 1,
+  AFI_IP6,
+  AFI_MAX
+};
+
+typedef enum afi afi_t;
+
 typedef u_int8_t safi_t;
 
 /* Zebra types. Used in Zserv message header. */
-- 
1.7.10.4


_______________________________________________
Quagga-dev mailing list
[email protected]
https://lists.quagga.net/mailman/listinfo/quagga-dev

Reply via email to