2 * Copyright 2015, LabN Consulting, L.L.C.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; see the file COPYING; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 #ifndef _QUAGGA_BGP_ENCAP_TYPES_H
20 #define _QUAGGA_BGP_ENCAP_TYPES_H
22 #include "bgpd/bgp_ecommunity.h"
25 * http://www.iana.org/assignments/bgp-parameters/bgp-parameters.xhtml#tunnel-types
28 BGP_ENCAP_TYPE_RESERVED
= 0,
29 BGP_ENCAP_TYPE_L2TPV3_OVER_IP
= 1,
30 BGP_ENCAP_TYPE_GRE
= 2,
31 BGP_ENCAP_TYPE_TRANSMIT_TUNNEL_ENDPOINT
= 3,
32 BGP_ENCAP_TYPE_IPSEC_IN_TUNNEL_MODE
= 4,
33 BGP_ENCAP_TYPE_IP_IN_IP_TUNNEL_WITH_IPSEC_TRANSPORT_MODE
= 5,
34 BGP_ENCAP_TYPE_MPLS_IN_IP_TUNNEL_WITH_IPSEC_TRANSPORT_MODE
= 6,
35 BGP_ENCAP_TYPE_IP_IN_IP
= 7,
36 BGP_ENCAP_TYPE_VXLAN
= 8,
37 BGP_ENCAP_TYPE_NVGRE
= 9,
38 BGP_ENCAP_TYPE_MPLS
= 10, /* NOTE: Encap SAFI&Attribute not used */
39 BGP_ENCAP_TYPE_MPLS_IN_GRE
= 11,
40 BGP_ENCAP_TYPE_VXLAN_GPE
= 12,
41 BGP_ENCAP_TYPE_MPLS_IN_UDP
= 13,
46 BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION
= 1,
47 BGP_ENCAP_SUBTLV_TYPE_PROTO_TYPE
= 2,
48 BGP_ENCAP_SUBTLV_TYPE_IPSEC_TA
= 3,
49 BGP_ENCAP_SUBTLV_TYPE_COLOR
= 4,
50 BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
=
51 6 /* speculative, IANA assignment TBD */
52 } bgp_encap_subtlv_types
;
55 * Tunnel Encapsulation Attribute subtlvs
57 struct bgp_tea_subtlv_encap_l2tpv3_over_ip
{
59 uint8_t cookie_length
;
63 struct bgp_tea_subtlv_encap_gre_key
{
67 struct bgp_tea_subtlv_encap_pbb
{
68 uint32_t flag_isid
: 1;
69 uint32_t flag_vid
: 1;
75 struct bgp_tea_subtlv_proto_type
{
76 uint16_t proto
; /* ether-type */
79 struct bgp_tea_subtlv_color
{
83 /* per draft-rosen-idr-tunnel-encaps */
84 struct bgp_tea_subtlv_remote_endpoint
{
85 uint8_t family
; /* IPv4 or IPv6 */
90 as_t as4
; /* always 4 bytes */
94 * This is the length of the value part of the ipsec tunnel authenticator
95 * subtlv. Currently we only support the length for authenticator type 1.
97 #define BGP_ENCAP_SUBTLV_IPSEC_TA_SIZE 20
99 struct bgp_tea_subtlv_ipsec_ta
{
100 uint16_t authenticator_type
; /* only type 1 is supported so far */
101 uint8_t authenticator_length
; /* octets in value field */
102 uint8_t value
[BGP_ENCAP_SUBTLV_IPSEC_TA_SIZE
];
107 * TBD change names to add "VALID"
109 #define BGP_TEA_SUBTLV_ENCAP 0x00000001
110 #define BGP_TEA_SUBTLV_PROTO_TYPE 0x00000002
111 #define BGP_TEA_SUBTLV_COLOR 0x00000004
112 #define BGP_TEA_SUBTLV_IPSEC_TA 0x00000008
113 #define BGP_TEA_SUBTLV_REMOTE_ENDPOINT 0x00000010
115 #define CHECK_SUBTLV_FLAG(ptr, flag) CHECK_FLAG((ptr)->valid_subtlvs, (flag))
116 #define SET_SUBTLV_FLAG(ptr, flag) SET_FLAG((ptr)->valid_subtlvs, (flag))
117 #define UNSET_SUBTLV_FLAG(ptr, flag) UNSET_FLAG((ptr)->valid_subtlvs, (flag))
120 * Tunnel Type-specific APIs
122 struct bgp_encap_type_reserved
{
123 uint32_t valid_subtlvs
;
124 struct bgp_tea_subtlv_remote_endpoint st_endpoint
; /* optional */
127 struct bgp_encap_type_l2tpv3_over_ip
{
128 uint32_t valid_subtlvs
;
129 struct bgp_tea_subtlv_encap_l2tpv3_over_ip st_encap
;
130 struct bgp_tea_subtlv_proto_type st_proto
; /* optional */
131 struct bgp_tea_subtlv_color st_color
; /* optional */
132 struct bgp_tea_subtlv_remote_endpoint st_endpoint
; /* optional */
135 struct bgp_encap_type_gre
{
136 uint32_t valid_subtlvs
;
137 struct bgp_tea_subtlv_encap_gre_key st_encap
; /* optional */
138 struct bgp_tea_subtlv_proto_type st_proto
; /* optional */
139 struct bgp_tea_subtlv_color st_color
; /* optional */
140 struct bgp_tea_subtlv_remote_endpoint st_endpoint
; /* optional */
143 struct bgp_encap_type_ip_in_ip
{
144 uint32_t valid_subtlvs
;
145 struct bgp_tea_subtlv_proto_type st_proto
; /* optional */
146 struct bgp_tea_subtlv_color st_color
; /* optional */
147 struct bgp_tea_subtlv_remote_endpoint st_endpoint
; /* optional */
150 struct bgp_encap_type_transmit_tunnel_endpoint
{
151 uint32_t valid_subtlvs
;
152 struct bgp_tea_subtlv_remote_endpoint st_endpoint
; /* optional */
153 /* No subtlvs defined in spec? */
156 struct bgp_encap_type_ipsec_in_tunnel_mode
{
157 uint32_t valid_subtlvs
;
158 struct bgp_tea_subtlv_ipsec_ta st_ipsec_ta
; /* optional */
159 struct bgp_tea_subtlv_remote_endpoint st_endpoint
; /* optional */
162 struct bgp_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode
{
163 uint32_t valid_subtlvs
;
164 struct bgp_tea_subtlv_ipsec_ta st_ipsec_ta
; /* optional */
165 struct bgp_tea_subtlv_remote_endpoint st_endpoint
; /* optional */
168 struct bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode
{
169 uint32_t valid_subtlvs
;
170 struct bgp_tea_subtlv_ipsec_ta st_ipsec_ta
; /* optional */
171 struct bgp_tea_subtlv_remote_endpoint st_endpoint
; /* optional */
174 #define VXLAN_ENCAP_MASK_VNID_VALID 0x80000000
175 #define VXLAN_ENCAP_MASK_MAC_VALID 0x40000000
177 struct bgp_encap_type_vxlan
{
178 uint32_t valid_subtlvs
;
179 struct bgp_tea_subtlv_remote_endpoint st_endpoint
; /* optional */
180 /* draft-ietf-idr-tunnel-encaps-02 */
181 uint32_t vnid
; /* does not include V and M bit */
182 uint8_t *mac_address
; /* optional */
185 struct bgp_encap_type_nvgre
{
186 uint32_t valid_subtlvs
;
187 struct bgp_tea_subtlv_remote_endpoint st_endpoint
; /* optional */
188 /* No subtlvs defined in spec? */
191 struct bgp_encap_type_mpls
{
192 uint32_t valid_subtlvs
;
193 struct bgp_tea_subtlv_remote_endpoint st_endpoint
; /* optional */
194 /* No subtlvs defined in spec? */
197 struct bgp_encap_type_mpls_in_gre
{
198 uint32_t valid_subtlvs
;
199 struct bgp_tea_subtlv_remote_endpoint st_endpoint
; /* optional */
200 /* No subtlvs defined in spec? */
203 struct bgp_encap_type_vxlan_gpe
{
204 uint32_t valid_subtlvs
;
205 struct bgp_tea_subtlv_remote_endpoint st_endpoint
; /* optional */
206 /* No subtlvs defined in spec? */
209 struct bgp_encap_type_mpls_in_udp
{
210 uint32_t valid_subtlvs
;
211 struct bgp_tea_subtlv_remote_endpoint st_endpoint
; /* optional */
212 /* No subtlvs defined in spec? */
215 struct bgp_encap_type_pbb
{
216 uint32_t valid_subtlvs
;
217 struct bgp_tea_subtlv_remote_endpoint st_endpoint
; /* optional */
218 struct bgp_tea_subtlv_encap_pbb st_encap
;
221 static inline void encode_encap_extcomm(bgp_encap_types tnl_type
,
222 struct ecommunity_val
*eval
)
224 memset(eval
, 0, sizeof(*eval
));
225 eval
->val
[0] = ECOMMUNITY_ENCODE_OPAQUE
;
226 eval
->val
[1] = ECOMMUNITY_OPAQUE_SUBTYPE_ENCAP
;
227 eval
->val
[6] = ((tnl_type
) >> 8) & 0xff;
228 eval
->val
[7] = (tnl_type
)&0xff;
231 #endif /* _QUAGGA_BGP_ENCAP_TYPES_H */