summaryrefslogtreecommitdiff
path: root/lib/zebra.h
diff options
context:
space:
mode:
authorvivek <vivek@cumulusnetworks.com>2016-06-15 10:25:35 -0700
committerPhilippe Guibert <philippe.guibert@6wind.com>2017-01-12 09:28:43 +0100
commit9cabb64b320a946b401daa3f6ee7adcefe1548b6 (patch)
tree877ff14ba84c34df0b08515d082e537789925f1a /lib/zebra.h
parentd504ec224a4ddc72177a5ef1aba02cdacb266416 (diff)
Quagga: AFI/SAFI mappings IANA to/from internal values
Introduce internal and IANA defintions for AFI/SAFI and mapping functions and modify code to use these. This refactoring will facilitate adding support for other AFI/SAFI whose IANA values won't be suitable for internal data structure definitions (e.g., they are not contiguous). The commit adds some fixes related to afi/safi testing with 'make check ' command. Signed-off-by: Vivek Venkatraman <vivek@cumulusnetworks.com> Reviewed-by: Donald Sharp <sharpd@cumulusnetworks.com> Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com> Ticket: CM-11416 Reviewed By: CCR-3594 (mpls branch) Testing Done: Not tested now, tested earlier on mpls branch
Diffstat (limited to 'lib/zebra.h')
-rw-r--r--lib/zebra.h67
1 files changed, 65 insertions, 2 deletions
diff --git a/lib/zebra.h b/lib/zebra.h
index 3a9ad15bf4..5a58cf8e6e 100644
--- a/lib/zebra.h
+++ b/lib/zebra.h
@@ -473,9 +473,28 @@ typedef enum {
#define SAFI_MULTICAST 2
#define SAFI_MPLS_VPN 3
#define SAFI_RESERVED_4 4
-#define SAFI_ENCAP 7 /* per IANA */
+#define SAFI_ENCAP 5
#define SAFI_RESERVED_5 5
-#define SAFI_MAX 8
+#define SAFI_MAX 6
+
+/*
+ * 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.
+ */
+#define IANA_AFI_RESERVED 0
+#define IANA_AFI_IPV4 1
+#define IANA_AFI_IPV6 2
+
+#define IANA_SAFI_RESERVED 0
+#define IANA_SAFI_UNICAST 1
+#define IANA_SAFI_MULTICAST 2
+#define IANA_SAFI_ENCAP 7
+#define IANA_SAFI_MPLS_VPN 128
/* Default Administrative Distance of each protocol. */
#define ZEBRA_KERNEL_DISTANCE_DEFAULT 0
@@ -509,4 +528,48 @@ typedef uint32_t route_tag_t;
#define ROUTE_TAG_MAX UINT32_MAX
#define ROUTE_TAG_PRI PRIu32
+static inline afi_t afi_iana2int (afi_t afi)
+{
+ if (afi == IANA_AFI_IPV4)
+ return AFI_IP;
+ if (afi == IANA_AFI_IPV6)
+ return AFI_IP6;
+ return AFI_MAX;
+}
+
+static inline afi_t afi_int2iana (afi_t afi)
+{
+ if (afi == AFI_IP)
+ return IANA_AFI_IPV4;
+ if (afi == AFI_IP6)
+ return IANA_AFI_IPV6;
+ return IANA_AFI_RESERVED;
+}
+
+static inline safi_t safi_iana2int (safi_t safi)
+{
+ if (safi == IANA_SAFI_UNICAST)
+ return SAFI_UNICAST;
+ if (safi == IANA_SAFI_MULTICAST)
+ return SAFI_MULTICAST;
+ if (safi == IANA_SAFI_MPLS_VPN)
+ return SAFI_MPLS_VPN;
+ if (safi == IANA_SAFI_ENCAP)
+ return SAFI_ENCAP;
+ return SAFI_MAX;
+}
+
+static inline safi_t safi_int2iana (safi_t safi)
+{
+ if (safi == SAFI_UNICAST)
+ return IANA_SAFI_UNICAST;
+ if (safi == SAFI_MULTICAST)
+ return IANA_SAFI_MULTICAST;
+ if (safi == SAFI_MPLS_VPN)
+ return IANA_SAFI_MPLS_VPN;
+ if (safi == SAFI_ENCAP)
+ return IANA_SAFI_ENCAP;
+ return IANA_SAFI_RESERVED;
+}
+
#endif /* _ZEBRA_H */