Line data Source code
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 : #ifdef __cplusplus
25 : extern "C" {
26 : #endif
27 :
28 : /*
29 : * The above AFI and SAFI definitions are for internal use. The protocol
30 : * definitions (IANA values) as for example used in BGP protocol packets
31 : * are defined below and these will get mapped to/from the internal values
32 : * in the appropriate places.
33 : * The rationale is that the protocol (IANA) values may be sparse and are
34 : * not optimal for use in data-structure sizing.
35 : * Note: Only useful (i.e., supported) values are defined below.
36 : */
37 : typedef enum {
38 : IANA_AFI_RESERVED = 0,
39 : IANA_AFI_IPV4 = 1,
40 : IANA_AFI_IPV6 = 2,
41 : IANA_AFI_L2VPN = 25,
42 : } iana_afi_t;
43 :
44 : typedef enum {
45 : IANA_SAFI_RESERVED = 0,
46 : IANA_SAFI_UNICAST = 1,
47 : IANA_SAFI_MULTICAST = 2,
48 : IANA_SAFI_LABELED_UNICAST = 4,
49 : IANA_SAFI_ENCAP = 7,
50 : IANA_SAFI_EVPN = 70,
51 : IANA_SAFI_MPLS_VPN = 128,
52 : IANA_SAFI_FLOWSPEC = 133
53 : } iana_safi_t;
54 :
55 6 : static inline afi_t afi_iana2int(iana_afi_t afi)
56 : {
57 6 : switch (afi) {
58 : case IANA_AFI_IPV4:
59 : return AFI_IP;
60 : case IANA_AFI_IPV6:
61 : return AFI_IP6;
62 : case IANA_AFI_L2VPN:
63 : return AFI_L2VPN;
64 : case IANA_AFI_RESERVED:
65 : return AFI_MAX;
66 : }
67 :
68 : return AFI_MAX;
69 : }
70 :
71 12 : static inline iana_afi_t afi_int2iana(afi_t afi)
72 : {
73 12 : switch (afi) {
74 : case AFI_IP:
75 : return IANA_AFI_IPV4;
76 : case AFI_IP6:
77 : return IANA_AFI_IPV6;
78 : case AFI_L2VPN:
79 : return IANA_AFI_L2VPN;
80 : case AFI_UNSPEC:
81 : case AFI_MAX:
82 : return IANA_AFI_RESERVED;
83 : }
84 :
85 : return IANA_AFI_RESERVED;
86 : }
87 :
88 0 : static inline const char *iana_afi2str(iana_afi_t afi)
89 : {
90 0 : return afi2str(afi_iana2int(afi));
91 : }
92 :
93 6 : static inline safi_t safi_iana2int(iana_safi_t safi)
94 : {
95 6 : switch (safi) {
96 : case IANA_SAFI_UNICAST:
97 : return SAFI_UNICAST;
98 0 : case IANA_SAFI_MULTICAST:
99 0 : return SAFI_MULTICAST;
100 0 : case IANA_SAFI_MPLS_VPN:
101 0 : return SAFI_MPLS_VPN;
102 0 : case IANA_SAFI_ENCAP:
103 0 : return SAFI_ENCAP;
104 0 : case IANA_SAFI_EVPN:
105 0 : return SAFI_EVPN;
106 0 : case IANA_SAFI_LABELED_UNICAST:
107 0 : return SAFI_LABELED_UNICAST;
108 0 : case IANA_SAFI_FLOWSPEC:
109 0 : return SAFI_FLOWSPEC;
110 : case IANA_SAFI_RESERVED:
111 : return SAFI_MAX;
112 : }
113 :
114 : return SAFI_MAX;
115 : }
116 :
117 12 : static inline iana_safi_t safi_int2iana(safi_t safi)
118 : {
119 12 : switch (safi) {
120 : case SAFI_UNICAST:
121 : return IANA_SAFI_UNICAST;
122 : case SAFI_MULTICAST:
123 : return IANA_SAFI_MULTICAST;
124 : case SAFI_MPLS_VPN:
125 : return IANA_SAFI_MPLS_VPN;
126 : case SAFI_ENCAP:
127 : return IANA_SAFI_ENCAP;
128 : case SAFI_EVPN:
129 : return IANA_SAFI_EVPN;
130 : case SAFI_LABELED_UNICAST:
131 : return IANA_SAFI_LABELED_UNICAST;
132 : case SAFI_FLOWSPEC:
133 : return IANA_SAFI_FLOWSPEC;
134 : case SAFI_UNSPEC:
135 : case SAFI_MAX:
136 : return IANA_SAFI_RESERVED;
137 : }
138 :
139 : return IANA_SAFI_RESERVED;
140 : }
141 :
142 0 : static inline const char *iana_safi2str(iana_safi_t safi)
143 : {
144 0 : return safi2str(safi_iana2int(safi));
145 : }
146 :
147 : #ifdef __cplusplus
148 : }
149 : #endif
150 :
151 : #endif
|