]> git.proxmox.com Git - mirror_frr.git/blame - lib/iana_afi.h
lib: Add missing enum's to switch statement
[mirror_frr.git] / lib / iana_afi.h
CommitLineData
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
17e38209
RW
24#ifdef __cplusplus
25extern "C" {
26#endif
27
17136bf2
DS
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 */
37typedef 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
44typedef 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
55static inline afi_t afi_iana2int(iana_afi_t afi)
56{
57 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;
bde30e78 64 case IANA_AFI_RESERVED:
17136bf2
DS
65 return AFI_MAX;
66 }
bde30e78
DS
67
68 return AFI_MAX;
17136bf2
DS
69}
70
71static inline iana_afi_t afi_int2iana(afi_t afi)
72{
73 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;
bde30e78
DS
80 case AFI_UNSPEC:
81 case AFI_MAX:
17136bf2
DS
82 return IANA_AFI_RESERVED;
83 }
bde30e78
DS
84
85 return IANA_AFI_RESERVED;
17136bf2
DS
86}
87
88static inline const char *iana_afi2str(iana_afi_t afi)
89{
90 return afi2str(afi_iana2int(afi));
91}
92
93static inline safi_t safi_iana2int(iana_safi_t safi)
94{
95 switch (safi) {
96 case IANA_SAFI_UNICAST:
97 return SAFI_UNICAST;
98 case IANA_SAFI_MULTICAST:
99 return SAFI_MULTICAST;
100 case IANA_SAFI_MPLS_VPN:
101 return SAFI_MPLS_VPN;
102 case IANA_SAFI_ENCAP:
103 return SAFI_ENCAP;
104 case IANA_SAFI_EVPN:
105 return SAFI_EVPN;
106 case IANA_SAFI_LABELED_UNICAST:
107 return SAFI_LABELED_UNICAST;
108 case IANA_SAFI_FLOWSPEC:
109 return SAFI_FLOWSPEC;
bde30e78 110 case IANA_SAFI_RESERVED:
17136bf2
DS
111 return SAFI_MAX;
112 }
bde30e78
DS
113
114 return SAFI_MAX;
17136bf2
DS
115}
116
117static inline iana_safi_t safi_int2iana(safi_t safi)
118{
119 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;
bde30e78
DS
134 case SAFI_UNSPEC:
135 case SAFI_MAX:
17136bf2
DS
136 return IANA_SAFI_RESERVED;
137 }
bde30e78
DS
138
139 return IANA_SAFI_RESERVED;
17136bf2
DS
140}
141
142static inline const char *iana_safi2str(iana_safi_t safi)
143{
144 return safi2str(safi_iana2int(safi));
145}
146
17e38209
RW
147#ifdef __cplusplus
148}
149#endif
150
17136bf2 151#endif