]> git.proxmox.com Git - mirror_frr.git/blame - lib/iana_afi.h
*: auto-convert to SPDX License IDs
[mirror_frr.git] / lib / iana_afi.h
CommitLineData
acddc0ed 1// SPDX-License-Identifier: GPL-2.0-or-later
17136bf2
DS
2/*
3 * iana_afi and safi definitions.
4 * Copyright (C) 2018-2019 Cumulus Networks, Inc.
5 * Donald Sharp
17136bf2
DS
6 */
7#ifndef __IANA_AFI_H__
8
9#include <prefix.h>
10
17e38209
RW
11#ifdef __cplusplus
12extern "C" {
13#endif
14
17136bf2
DS
15/*
16 * The above AFI and SAFI definitions are for internal use. The protocol
17 * definitions (IANA values) as for example used in BGP protocol packets
18 * are defined below and these will get mapped to/from the internal values
19 * in the appropriate places.
20 * The rationale is that the protocol (IANA) values may be sparse and are
21 * not optimal for use in data-structure sizing.
22 * Note: Only useful (i.e., supported) values are defined below.
23 */
24typedef enum {
25 IANA_AFI_RESERVED = 0,
26 IANA_AFI_IPV4 = 1,
27 IANA_AFI_IPV6 = 2,
28 IANA_AFI_L2VPN = 25,
29} iana_afi_t;
30
31typedef enum {
32 IANA_SAFI_RESERVED = 0,
33 IANA_SAFI_UNICAST = 1,
34 IANA_SAFI_MULTICAST = 2,
35 IANA_SAFI_LABELED_UNICAST = 4,
36 IANA_SAFI_ENCAP = 7,
37 IANA_SAFI_EVPN = 70,
38 IANA_SAFI_MPLS_VPN = 128,
39 IANA_SAFI_FLOWSPEC = 133
40} iana_safi_t;
41
42static inline afi_t afi_iana2int(iana_afi_t afi)
43{
44 switch (afi) {
45 case IANA_AFI_IPV4:
46 return AFI_IP;
47 case IANA_AFI_IPV6:
48 return AFI_IP6;
49 case IANA_AFI_L2VPN:
50 return AFI_L2VPN;
bde30e78 51 case IANA_AFI_RESERVED:
17136bf2
DS
52 return AFI_MAX;
53 }
bde30e78
DS
54
55 return AFI_MAX;
17136bf2
DS
56}
57
58static inline iana_afi_t afi_int2iana(afi_t afi)
59{
60 switch (afi) {
61 case AFI_IP:
62 return IANA_AFI_IPV4;
63 case AFI_IP6:
64 return IANA_AFI_IPV6;
65 case AFI_L2VPN:
66 return IANA_AFI_L2VPN;
bde30e78
DS
67 case AFI_UNSPEC:
68 case AFI_MAX:
17136bf2
DS
69 return IANA_AFI_RESERVED;
70 }
bde30e78
DS
71
72 return IANA_AFI_RESERVED;
17136bf2
DS
73}
74
75static inline const char *iana_afi2str(iana_afi_t afi)
76{
77 return afi2str(afi_iana2int(afi));
78}
79
80static inline safi_t safi_iana2int(iana_safi_t safi)
81{
82 switch (safi) {
83 case IANA_SAFI_UNICAST:
84 return SAFI_UNICAST;
85 case IANA_SAFI_MULTICAST:
86 return SAFI_MULTICAST;
87 case IANA_SAFI_MPLS_VPN:
88 return SAFI_MPLS_VPN;
89 case IANA_SAFI_ENCAP:
90 return SAFI_ENCAP;
91 case IANA_SAFI_EVPN:
92 return SAFI_EVPN;
93 case IANA_SAFI_LABELED_UNICAST:
94 return SAFI_LABELED_UNICAST;
95 case IANA_SAFI_FLOWSPEC:
96 return SAFI_FLOWSPEC;
bde30e78 97 case IANA_SAFI_RESERVED:
17136bf2
DS
98 return SAFI_MAX;
99 }
bde30e78
DS
100
101 return SAFI_MAX;
17136bf2
DS
102}
103
104static inline iana_safi_t safi_int2iana(safi_t safi)
105{
106 switch (safi) {
107 case SAFI_UNICAST:
108 return IANA_SAFI_UNICAST;
109 case SAFI_MULTICAST:
110 return IANA_SAFI_MULTICAST;
111 case SAFI_MPLS_VPN:
112 return IANA_SAFI_MPLS_VPN;
113 case SAFI_ENCAP:
114 return IANA_SAFI_ENCAP;
115 case SAFI_EVPN:
116 return IANA_SAFI_EVPN;
117 case SAFI_LABELED_UNICAST:
118 return IANA_SAFI_LABELED_UNICAST;
119 case SAFI_FLOWSPEC:
120 return IANA_SAFI_FLOWSPEC;
bde30e78
DS
121 case SAFI_UNSPEC:
122 case SAFI_MAX:
17136bf2
DS
123 return IANA_SAFI_RESERVED;
124 }
bde30e78
DS
125
126 return IANA_SAFI_RESERVED;
17136bf2
DS
127}
128
129static inline const char *iana_safi2str(iana_safi_t safi)
130{
131 return safi2str(safi_iana2int(safi));
132}
133
17e38209
RW
134#ifdef __cplusplus
135}
136#endif
137
17136bf2 138#endif