]>
Commit | Line | Data |
---|---|---|
17136bf2 DS |
1 | /* |
2 | * iana_afi and safi definitions. | |
3 | * Copyright (C) 2018-2019 Cumulus Networks, Inc. | |
4 | * Donald Sharp | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify it | |
7 | * under the terms of the GNU General Public License as published by the Free | |
8 | * Software Foundation; either version 2 of the License, or (at your option) | |
9 | * any later version. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, but WITHOUT | |
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
14 | * more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License along | |
17 | * with this program; see the file COPYING; if not, write to the Free Software | |
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
19 | */ | |
20 | #ifndef __IANA_AFI_H__ | |
21 | ||
22 | #include <prefix.h> | |
23 | ||
24 | /* | |
25 | * The above AFI and SAFI definitions are for internal use. The protocol | |
26 | * definitions (IANA values) as for example used in BGP protocol packets | |
27 | * are defined below and these will get mapped to/from the internal values | |
28 | * in the appropriate places. | |
29 | * The rationale is that the protocol (IANA) values may be sparse and are | |
30 | * not optimal for use in data-structure sizing. | |
31 | * Note: Only useful (i.e., supported) values are defined below. | |
32 | */ | |
33 | typedef enum { | |
34 | IANA_AFI_RESERVED = 0, | |
35 | IANA_AFI_IPV4 = 1, | |
36 | IANA_AFI_IPV6 = 2, | |
37 | IANA_AFI_L2VPN = 25, | |
38 | } iana_afi_t; | |
39 | ||
40 | typedef enum { | |
41 | IANA_SAFI_RESERVED = 0, | |
42 | IANA_SAFI_UNICAST = 1, | |
43 | IANA_SAFI_MULTICAST = 2, | |
44 | IANA_SAFI_LABELED_UNICAST = 4, | |
45 | IANA_SAFI_ENCAP = 7, | |
46 | IANA_SAFI_EVPN = 70, | |
47 | IANA_SAFI_MPLS_VPN = 128, | |
48 | IANA_SAFI_FLOWSPEC = 133 | |
49 | } iana_safi_t; | |
50 | ||
51 | static inline afi_t afi_iana2int(iana_afi_t afi) | |
52 | { | |
53 | switch (afi) { | |
54 | case IANA_AFI_IPV4: | |
55 | return AFI_IP; | |
56 | case IANA_AFI_IPV6: | |
57 | return AFI_IP6; | |
58 | case IANA_AFI_L2VPN: | |
59 | return AFI_L2VPN; | |
60 | default: | |
61 | return AFI_MAX; | |
62 | } | |
63 | } | |
64 | ||
65 | static inline iana_afi_t afi_int2iana(afi_t afi) | |
66 | { | |
67 | switch (afi) { | |
68 | case AFI_IP: | |
69 | return IANA_AFI_IPV4; | |
70 | case AFI_IP6: | |
71 | return IANA_AFI_IPV6; | |
72 | case AFI_L2VPN: | |
73 | return IANA_AFI_L2VPN; | |
74 | default: | |
75 | return IANA_AFI_RESERVED; | |
76 | } | |
77 | } | |
78 | ||
79 | static inline const char *iana_afi2str(iana_afi_t afi) | |
80 | { | |
81 | return afi2str(afi_iana2int(afi)); | |
82 | } | |
83 | ||
84 | static inline safi_t safi_iana2int(iana_safi_t safi) | |
85 | { | |
86 | switch (safi) { | |
87 | case IANA_SAFI_UNICAST: | |
88 | return SAFI_UNICAST; | |
89 | case IANA_SAFI_MULTICAST: | |
90 | return SAFI_MULTICAST; | |
91 | case IANA_SAFI_MPLS_VPN: | |
92 | return SAFI_MPLS_VPN; | |
93 | case IANA_SAFI_ENCAP: | |
94 | return SAFI_ENCAP; | |
95 | case IANA_SAFI_EVPN: | |
96 | return SAFI_EVPN; | |
97 | case IANA_SAFI_LABELED_UNICAST: | |
98 | return SAFI_LABELED_UNICAST; | |
99 | case IANA_SAFI_FLOWSPEC: | |
100 | return SAFI_FLOWSPEC; | |
101 | default: | |
102 | return SAFI_MAX; | |
103 | } | |
104 | } | |
105 | ||
106 | static inline iana_safi_t safi_int2iana(safi_t safi) | |
107 | { | |
108 | switch (safi) { | |
109 | case SAFI_UNICAST: | |
110 | return IANA_SAFI_UNICAST; | |
111 | case SAFI_MULTICAST: | |
112 | return IANA_SAFI_MULTICAST; | |
113 | case SAFI_MPLS_VPN: | |
114 | return IANA_SAFI_MPLS_VPN; | |
115 | case SAFI_ENCAP: | |
116 | return IANA_SAFI_ENCAP; | |
117 | case SAFI_EVPN: | |
118 | return IANA_SAFI_EVPN; | |
119 | case SAFI_LABELED_UNICAST: | |
120 | return IANA_SAFI_LABELED_UNICAST; | |
121 | case SAFI_FLOWSPEC: | |
122 | return IANA_SAFI_FLOWSPEC; | |
123 | default: | |
124 | return IANA_SAFI_RESERVED; | |
125 | } | |
126 | } | |
127 | ||
128 | static inline const char *iana_safi2str(iana_safi_t safi) | |
129 | { | |
130 | return safi2str(safi_iana2int(safi)); | |
131 | } | |
132 | ||
133 | #endif |