]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib, bgpd: Fixup afi_t to be an enum and cleanup zebra.h
authorDonald Sharp <sharpd@cumulusnetworks.com>
Thu, 7 Jan 2016 14:33:28 +0000 (09:33 -0500)
committervivek <vivek@cumulusnetworks.com>
Mon, 6 Jun 2016 21:20:24 +0000 (14:20 -0700)
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 <sharpd@cumulusnetworks.com>
(cherry picked from commit f3cfc46450cccc5ac035a5a97c5a1a5484205705)

Conflicts:
bgpd/bgp_open.c
bgpd/bgp_open.h
bgpd/bgp_routemap.c

bgpd/bgp_open.c
bgpd/bgp_open.h
lib/plist.c
lib/zebra.h

index 43b28f9884541c5438c316c4bc7e472cd4c22693..8da052129ed1f7c731e5fb100ecb075cce8c8152 100644 (file)
@@ -175,23 +175,23 @@ 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;
     }
+
   zlog_debug ("unknown afi/safi (%u/%u)", afi, *safi);
-  
+
   return 0;
 }
 
@@ -287,7 +287,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",
@@ -699,17 +699,17 @@ 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_ADDPATH]     = CAPABILITY_CODE_ADDPATH_LEN,
   [CAPABILITY_CODE_DYNAMIC]    = CAPABILITY_CODE_DYNAMIC_LEN,
   [CAPABILITY_CODE_DYNAMIC_OLD]        = CAPABILITY_CODE_DYNAMIC_LEN,
   [CAPABILITY_CODE_ENHE]        = CAPABILITY_CODE_ENHE_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,
   [CAPABILITY_CODE_FQDN]        = CAPABILITY_CODE_MIN_FQDN_LEN,
 };
 
index bc49de54ffb4c9b7727eff458a6ac76311eaa74c..8ec0a5416b1210515e04360440a12513b4520dd1 100644 (file)
@@ -89,7 +89,8 @@ struct capability_gr
 #define CAPABILITY_CODE_AS4_LEN         4
 #define CAPABILITY_CODE_ADDPATH_LEN     4
 #define CAPABILITY_CODE_ENHE_LEN        6 /* NRLI AFI = 2, SAFI = 2, Nexthop AFI = 2 */
-#define CAPABILITY_CODE_MIN_FQDN_LEN 2
+#define CAPABILITY_CODE_MIN_FQDN_LEN    2
+#define CAPABILITY_CODE_ORF_LEN         5
 
 /* Cooperative Route Filtering Capability.  */
 
index 12c71791ce59abaf1f3e1fe41b61173ce88df9b6..a1289801c462fa0903b26319378a85849bfff3f3 100644 (file)
@@ -922,8 +922,9 @@ vty_prefix_list_install (struct vty *vty, afi_t afi, const char *name,
     }
 
   /* "any" is special token for matching any IPv4 addresses.  */
-  if (afi == AFI_IP)
+  switch (afi)
     {
+    case AFI_IP:
       if (strncmp ("any", prefix, strlen (prefix)) == 0)
        {
          ret = str2prefix_ipv4 ("0.0.0.0/0", (struct prefix_ipv4 *) &p);
@@ -939,10 +940,8 @@ vty_prefix_list_install (struct vty *vty, afi_t afi, const char *name,
          vty_out (vty, "%% Malformed IPv4 prefix%s", VTY_NEWLINE);
          return CMD_WARNING;
        }
-    }
-#ifdef HAVE_IPV6
-  else if (afi == AFI_IP6)
-    {
+      break;
+    case AFI_IP6:
       if (strncmp ("any", prefix, strlen (prefix)) == 0)
        {
          ret = str2prefix_ipv6 ("::/0", (struct prefix_ipv6 *) &p);
@@ -958,8 +957,8 @@ vty_prefix_list_install (struct vty *vty, afi_t afi, const char *name,
          vty_out (vty, "%% Malformed IPv6 prefix%s", VTY_NEWLINE);
          return CMD_WARNING;
        }
+      break;
     }
-#endif /* HAVE_IPV6 */
 
   /* ge and le check. */
   if (genum && (genum <= p.prefixlen))
index e3e3b6c71e8fc64dd0dcb260a0bb909158915066..59c154ba46b2f4b2e3e194b8e9d794dd85f290e0 100644 (file)
@@ -475,11 +475,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
@@ -513,9 +508,11 @@ extern const char *zserv_command_string (unsigned int command);
 #endif
 
 /* Address family numbers from RFC1700. */
-#define AFI_IP                    1
-#define AFI_IP6                   2
-#define AFI_MAX                   3
+typedef enum {
+  AFI_IP  = 1,
+  AFI_IP6 = 2,
+#define AFI_MAX 3
+} afi_t;
 
 /* Subsequent Address Family Identifier. */
 #define SAFI_UNICAST              1
@@ -549,8 +546,6 @@ extern const char *zserv_command_string (unsigned int command);
 #define UNSET_FLAG(V,F)      (V) &= ~(F)
 #define RESET_FLAG(V)        (V) = 0
 
-/* AFI and SAFI type. */
-typedef u_int16_t afi_t;
 typedef u_int8_t safi_t;
 
 /* Zebra types. Used in Zserv message header. */