From 9cabb64b320a946b401daa3f6ee7adcefe1548b6 Mon Sep 17 00:00:00 2001 From: vivek Date: Wed, 15 Jun 2016 10:25:35 -0700 Subject: 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 Reviewed-by: Donald Sharp Signed-off-by: Philippe Guibert Ticket: CM-11416 Reviewed By: CCR-3594 (mpls branch) Testing Done: Not tested now, tested earlier on mpls branch --- lib/zebra.h | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 65 insertions(+), 2 deletions(-) (limited to 'lib/zebra.h') 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 */ -- cgit v1.2.3