]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib, bgpd: Create iana_afi.h for storing iana_afi/safi enums
authorDonald Sharp <sharpd@cumulusnetworks.com>
Sun, 2 Jun 2019 19:02:07 +0000 (15:02 -0400)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Sun, 2 Jun 2019 19:02:07 +0000 (15:02 -0400)
The iana_afi_t and iana_safi_t were being created in zebra.h
and zebra.h is a bit of a dumping ground.  When the iana_afi2str and
iana_safi2str functions were created, it was correctly pointed out
that we should just use the internal afi_t and safi_t 2str functions
but to do that we would need to include prefix.h in zebra.h.  Which
really is not the right thing to do.  This tells us that we need
to break out this code into it's own header.

Move to iana_afi.h the enums and specific functions and remove
from zebra.  Convert to using the afi2str and safi2str functions.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
bgpd/bgpd.h
lib/iana_afi.h [new file with mode: 0644]
lib/subdir.am
lib/zebra.h

index c600d9f3f36d740ecda0e7f4d145b5e5e450e303..81c741dd6a6fbb8407b9946393f3f13c3a45d7f0 100644 (file)
@@ -28,6 +28,7 @@
 #include "lib/json.h"
 #include "vrf.h"
 #include "vty.h"
+#include "iana_afi.h"
 
 /* For union sockunion.  */
 #include "queue.h"
diff --git a/lib/iana_afi.h b/lib/iana_afi.h
new file mode 100644 (file)
index 0000000..ac03f73
--- /dev/null
@@ -0,0 +1,133 @@
+/*
+ * iana_afi and safi definitions.
+ * Copyright (C) 2018-2019 Cumulus Networks, Inc.
+ * Donald Sharp
+ *
+ * This program 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 of the License, or (at your option)
+ * any later version.
+ *
+ * This program 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 this program; see the file COPYING; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#ifndef __IANA_AFI_H__
+
+#include <prefix.h>
+
+/*
+ * The above AFI and SAFI definitions are for internal use. The protocol
+ * definitions (IANA values) as for example used in BGP protocol packets
+ * are defined below and these will get mapped to/from the internal values
+ * in the appropriate places.
+ * The rationale is that the protocol (IANA) values may be sparse and are
+ * not optimal for use in data-structure sizing.
+ * Note: Only useful (i.e., supported) values are defined below.
+ */
+typedef enum {
+       IANA_AFI_RESERVED = 0,
+       IANA_AFI_IPV4 = 1,
+       IANA_AFI_IPV6 = 2,
+       IANA_AFI_L2VPN = 25,
+} iana_afi_t;
+
+typedef enum {
+       IANA_SAFI_RESERVED = 0,
+       IANA_SAFI_UNICAST = 1,
+       IANA_SAFI_MULTICAST = 2,
+       IANA_SAFI_LABELED_UNICAST = 4,
+       IANA_SAFI_ENCAP = 7,
+       IANA_SAFI_EVPN = 70,
+       IANA_SAFI_MPLS_VPN = 128,
+       IANA_SAFI_FLOWSPEC = 133
+} iana_safi_t;
+
+static inline afi_t afi_iana2int(iana_afi_t afi)
+{
+       switch (afi) {
+       case IANA_AFI_IPV4:
+               return AFI_IP;
+       case IANA_AFI_IPV6:
+               return AFI_IP6;
+       case IANA_AFI_L2VPN:
+               return AFI_L2VPN;
+       default:
+               return AFI_MAX;
+       }
+}
+
+static inline iana_afi_t afi_int2iana(afi_t afi)
+{
+       switch (afi) {
+       case AFI_IP:
+               return IANA_AFI_IPV4;
+       case AFI_IP6:
+               return IANA_AFI_IPV6;
+       case AFI_L2VPN:
+               return IANA_AFI_L2VPN;
+       default:
+               return IANA_AFI_RESERVED;
+       }
+}
+
+static inline const char *iana_afi2str(iana_afi_t afi)
+{
+       return afi2str(afi_iana2int(afi));
+}
+
+static inline safi_t safi_iana2int(iana_safi_t safi)
+{
+       switch (safi) {
+       case IANA_SAFI_UNICAST:
+               return SAFI_UNICAST;
+       case IANA_SAFI_MULTICAST:
+               return SAFI_MULTICAST;
+       case IANA_SAFI_MPLS_VPN:
+               return SAFI_MPLS_VPN;
+       case IANA_SAFI_ENCAP:
+               return SAFI_ENCAP;
+       case IANA_SAFI_EVPN:
+               return SAFI_EVPN;
+       case IANA_SAFI_LABELED_UNICAST:
+               return SAFI_LABELED_UNICAST;
+       case IANA_SAFI_FLOWSPEC:
+               return SAFI_FLOWSPEC;
+       default:
+               return SAFI_MAX;
+       }
+}
+
+static inline iana_safi_t safi_int2iana(safi_t safi)
+{
+       switch (safi) {
+       case SAFI_UNICAST:
+               return IANA_SAFI_UNICAST;
+       case SAFI_MULTICAST:
+               return IANA_SAFI_MULTICAST;
+       case SAFI_MPLS_VPN:
+               return IANA_SAFI_MPLS_VPN;
+       case SAFI_ENCAP:
+               return IANA_SAFI_ENCAP;
+       case SAFI_EVPN:
+               return IANA_SAFI_EVPN;
+       case SAFI_LABELED_UNICAST:
+               return IANA_SAFI_LABELED_UNICAST;
+       case SAFI_FLOWSPEC:
+               return IANA_SAFI_FLOWSPEC;
+       default:
+               return IANA_SAFI_RESERVED;
+       }
+}
+
+static inline const char *iana_safi2str(iana_safi_t safi)
+{
+       return safi2str(safi_iana2int(safi));
+}
+
+#endif
index 4897f5e8e528b7447fe7ca32a8b38b459adf2906..55f5e3a5e6a89f5024f576ae56aed779bb8616d4 100644 (file)
@@ -159,6 +159,7 @@ pkginclude_HEADERS += \
        lib/graph.h \
        lib/hash.h \
        lib/hook.h \
+       lib/iana_afi.h \
        lib/id_alloc.h \
        lib/if.h \
        lib/if_rmap.h \
index 336ecb38f3dcd81fa22c48b63658d3132300f2cb..c4c8577943d6af0f84fb0af5044e08e302064ec7 100644 (file)
@@ -442,33 +442,6 @@ typedef enum {
        SAFI_MAX = 8
 } safi_t;
 
-/*
- * The above AFI and SAFI definitions are for internal use. The protocol
- * definitions (IANA values) as for example used in BGP protocol packets
- * are defined below and these will get mapped to/from the internal values
- * in the appropriate places.
- * The rationale is that the protocol (IANA) values may be sparse and are
- * not optimal for use in data-structure sizing.
- * Note: Only useful (i.e., supported) values are defined below.
- */
-typedef enum {
-       IANA_AFI_RESERVED = 0,
-       IANA_AFI_IPV4 = 1,
-       IANA_AFI_IPV6 = 2,
-       IANA_AFI_L2VPN = 25,
-} iana_afi_t;
-
-typedef enum {
-       IANA_SAFI_RESERVED = 0,
-       IANA_SAFI_UNICAST = 1,
-       IANA_SAFI_MULTICAST = 2,
-       IANA_SAFI_LABELED_UNICAST = 4,
-       IANA_SAFI_ENCAP = 7,
-       IANA_SAFI_EVPN = 70,
-       IANA_SAFI_MPLS_VPN = 128,
-       IANA_SAFI_FLOWSPEC = 133
-} iana_safi_t;
-
 /* Default Administrative Distance of each protocol. */
 #define ZEBRA_KERNEL_DISTANCE_DEFAULT      0
 #define ZEBRA_CONNECT_DISTANCE_DEFAULT     0
@@ -510,116 +483,4 @@ typedef uint32_t route_tag_t;
 #define ROUTE_TAG_MAX UINT32_MAX
 #define ROUTE_TAG_PRI PRIu32
 
-static inline const char *iana_afi2str(iana_afi_t afi)
-{
-       switch (afi) {
-       case IANA_AFI_RESERVED:
-               return "Reserved";
-       case IANA_AFI_IPV4:
-               return "IPv4";
-       case IANA_AFI_IPV6:
-               return "IPv6";
-       case IANA_AFI_L2VPN:
-               return "L2VPN";
-       }
-
-       return "Unknown";
-}
-
-static inline afi_t afi_iana2int(iana_afi_t afi)
-{
-       switch (afi) {
-       case IANA_AFI_IPV4:
-               return AFI_IP;
-       case IANA_AFI_IPV6:
-               return AFI_IP6;
-       case IANA_AFI_L2VPN:
-               return AFI_L2VPN;
-       default:
-               return AFI_MAX;
-       }
-}
-
-static inline iana_afi_t afi_int2iana(afi_t afi)
-{
-       switch (afi) {
-       case AFI_IP:
-               return IANA_AFI_IPV4;
-       case AFI_IP6:
-               return IANA_AFI_IPV6;
-       case AFI_L2VPN:
-               return IANA_AFI_L2VPN;
-       default:
-               return IANA_AFI_RESERVED;
-       }
-}
-
-static inline const char *iana_safi2str(iana_safi_t safi)
-{
-       switch (safi) {
-       case IANA_SAFI_RESERVED:
-               return "Reserved";
-       case IANA_SAFI_UNICAST:
-               return "Unicast";
-       case IANA_SAFI_MULTICAST:
-               return "Multicast";
-       case IANA_SAFI_LABELED_UNICAST:
-               return "Labeled Unicast";
-       case IANA_SAFI_ENCAP:
-               return "Encap";
-       case IANA_SAFI_EVPN:
-               return "EVPN";
-       case IANA_SAFI_MPLS_VPN:
-               return "MPLS VPN";
-       case IANA_SAFI_FLOWSPEC:
-               return "FlowSpec";
-       }
-
-       return "Unknown";
-}
-
-static inline safi_t safi_iana2int(iana_safi_t safi)
-{
-       switch (safi) {
-       case IANA_SAFI_UNICAST:
-               return SAFI_UNICAST;
-       case IANA_SAFI_MULTICAST:
-               return SAFI_MULTICAST;
-       case IANA_SAFI_MPLS_VPN:
-               return SAFI_MPLS_VPN;
-       case IANA_SAFI_ENCAP:
-               return SAFI_ENCAP;
-       case IANA_SAFI_EVPN:
-               return SAFI_EVPN;
-       case IANA_SAFI_LABELED_UNICAST:
-               return SAFI_LABELED_UNICAST;
-       case IANA_SAFI_FLOWSPEC:
-               return SAFI_FLOWSPEC;
-       default:
-               return SAFI_MAX;
-       }
-}
-
-static inline iana_safi_t safi_int2iana(safi_t safi)
-{
-       switch (safi) {
-       case SAFI_UNICAST:
-               return IANA_SAFI_UNICAST;
-       case SAFI_MULTICAST:
-               return IANA_SAFI_MULTICAST;
-       case SAFI_MPLS_VPN:
-               return IANA_SAFI_MPLS_VPN;
-       case SAFI_ENCAP:
-               return IANA_SAFI_ENCAP;
-       case SAFI_EVPN:
-               return IANA_SAFI_EVPN;
-       case SAFI_LABELED_UNICAST:
-               return IANA_SAFI_LABELED_UNICAST;
-       case SAFI_FLOWSPEC:
-               return IANA_SAFI_FLOWSPEC;
-       default:
-               return IANA_SAFI_RESERVED;
-       }
-}
-
 #endif /* _ZEBRA_H */