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"
24 /* from http://www.iana.org/assignments/bgp-parameters/bgp-parameters.xhtml#tunnel-types */
26 BGP_ENCAP_TYPE_RESERVED
=0,
27 BGP_ENCAP_TYPE_L2TPV3_OVER_IP
=1,
29 BGP_ENCAP_TYPE_TRANSMIT_TUNNEL_ENDPOINT
=3,
30 BGP_ENCAP_TYPE_IPSEC_IN_TUNNEL_MODE
=4,
31 BGP_ENCAP_TYPE_IP_IN_IP_TUNNEL_WITH_IPSEC_TRANSPORT_MODE
=5,
32 BGP_ENCAP_TYPE_MPLS_IN_IP_TUNNEL_WITH_IPSEC_TRANSPORT_MODE
=6,
33 BGP_ENCAP_TYPE_IP_IN_IP
=7,
34 BGP_ENCAP_TYPE_VXLAN
=8,
35 BGP_ENCAP_TYPE_NVGRE
=9,
36 BGP_ENCAP_TYPE_MPLS
=10, /* NOTE: Encap SAFI&Attribute not used */
37 BGP_ENCAP_TYPE_MPLS_IN_GRE
=11,
38 BGP_ENCAP_TYPE_VXLAN_GPE
=12,
39 BGP_ENCAP_TYPE_MPLS_IN_UDP
=13,
44 BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION
=1,
45 BGP_ENCAP_SUBTLV_TYPE_PROTO_TYPE
=2,
46 BGP_ENCAP_SUBTLV_TYPE_IPSEC_TA
=3,
47 BGP_ENCAP_SUBTLV_TYPE_COLOR
=4,
48 BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
=6 /* speculative, IANA assignment TBD */
49 } bgp_encap_subtlv_types
;
52 * Tunnel Encapsulation Attribute subtlvs
54 struct bgp_tea_subtlv_encap_l2tpv3_over_ip
{
56 uint8_t cookie_length
;
60 struct bgp_tea_subtlv_encap_gre_key
{
64 struct bgp_tea_subtlv_encap_pbb
{
72 struct bgp_tea_subtlv_proto_type
{
73 uint16_t proto
; /* ether-type */
76 struct bgp_tea_subtlv_color
{
80 /* per draft-rosen-idr-tunnel-encaps */
81 struct bgp_tea_subtlv_remote_endpoint
{
82 u_char family
; /* IPv4 or IPv6 */
87 as_t as4
; /* always 4 bytes */
91 * This is the length of the value part of the ipsec tunnel authenticator
92 * subtlv. Currently we only support the length for authenticator type 1.
94 #define BGP_ENCAP_SUBTLV_IPSEC_TA_SIZE 20
96 struct bgp_tea_subtlv_ipsec_ta
{
97 uint16_t authenticator_type
; /* only type 1 is supported so far */
98 uint8_t authenticator_length
; /* octets in value field */
99 uint8_t value
[BGP_ENCAP_SUBTLV_IPSEC_TA_SIZE
];
104 * TBD change names to add "VALID"
106 #define BGP_TEA_SUBTLV_ENCAP 0x00000001
107 #define BGP_TEA_SUBTLV_PROTO_TYPE 0x00000002
108 #define BGP_TEA_SUBTLV_COLOR 0x00000004
109 #define BGP_TEA_SUBTLV_IPSEC_TA 0x00000008
110 #define BGP_TEA_SUBTLV_REMOTE_ENDPOINT 0x00000010
112 #define CHECK_SUBTLV_FLAG(ptr, flag) CHECK_FLAG((ptr)->valid_subtlvs, (flag))
113 #define SET_SUBTLV_FLAG(ptr, flag) SET_FLAG((ptr)->valid_subtlvs, (flag))
114 #define UNSET_SUBTLV_FLAG(ptr, flag) UNSET_FLAG((ptr)->valid_subtlvs, (flag))
117 * Tunnel Type-specific APIs
119 struct bgp_encap_type_reserved
{
120 uint32_t valid_subtlvs
;
121 struct bgp_tea_subtlv_remote_endpoint st_endpoint
; /* optional */
124 struct bgp_encap_type_l2tpv3_over_ip
{
125 uint32_t valid_subtlvs
;
126 struct bgp_tea_subtlv_encap_l2tpv3_over_ip st_encap
;
127 struct bgp_tea_subtlv_proto_type st_proto
; /* optional */
128 struct bgp_tea_subtlv_color st_color
; /* optional */
129 struct bgp_tea_subtlv_remote_endpoint st_endpoint
; /* optional */
132 struct bgp_encap_type_gre
{
133 uint32_t valid_subtlvs
;
134 struct bgp_tea_subtlv_encap_gre_key st_encap
; /* optional */
135 struct bgp_tea_subtlv_proto_type st_proto
; /* optional */
136 struct bgp_tea_subtlv_color st_color
; /* optional */
137 struct bgp_tea_subtlv_remote_endpoint st_endpoint
; /* optional */
140 struct bgp_encap_type_ip_in_ip
{
141 uint32_t valid_subtlvs
;
142 struct bgp_tea_subtlv_proto_type st_proto
; /* optional */
143 struct bgp_tea_subtlv_color st_color
; /* optional */
144 struct bgp_tea_subtlv_remote_endpoint st_endpoint
; /* optional */
147 struct bgp_encap_type_transmit_tunnel_endpoint
{
148 uint32_t valid_subtlvs
;
149 struct bgp_tea_subtlv_remote_endpoint st_endpoint
; /* optional */
150 /* No subtlvs defined in spec? */
153 struct bgp_encap_type_ipsec_in_tunnel_mode
{
154 uint32_t valid_subtlvs
;
155 struct bgp_tea_subtlv_ipsec_ta st_ipsec_ta
; /* optional */
156 struct bgp_tea_subtlv_remote_endpoint st_endpoint
; /* optional */
159 struct bgp_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode
{
160 uint32_t valid_subtlvs
;
161 struct bgp_tea_subtlv_ipsec_ta st_ipsec_ta
; /* optional */
162 struct bgp_tea_subtlv_remote_endpoint st_endpoint
; /* optional */
165 struct bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode
{
166 uint32_t valid_subtlvs
;
167 struct bgp_tea_subtlv_ipsec_ta st_ipsec_ta
; /* optional */
168 struct bgp_tea_subtlv_remote_endpoint st_endpoint
; /* optional */
171 #define VXLAN_ENCAP_MASK_VNID_VALID 0x80000000
172 #define VXLAN_ENCAP_MASK_MAC_VALID 0x40000000
174 struct bgp_encap_type_vxlan
{
175 uint32_t valid_subtlvs
;
176 struct bgp_tea_subtlv_remote_endpoint st_endpoint
; /* optional */
177 /* draft-ietf-idr-tunnel-encaps-02 */
178 uint32_t vnid
; /* does not include V and M bit */
179 uint8_t *mac_address
; /* optional */
182 struct bgp_encap_type_nvgre
{
183 uint32_t valid_subtlvs
;
184 struct bgp_tea_subtlv_remote_endpoint st_endpoint
; /* optional */
185 /* No subtlvs defined in spec? */
188 struct bgp_encap_type_mpls
{
189 uint32_t valid_subtlvs
;
190 struct bgp_tea_subtlv_remote_endpoint st_endpoint
; /* optional */
191 /* No subtlvs defined in spec? */
194 struct bgp_encap_type_mpls_in_gre
{
195 uint32_t valid_subtlvs
;
196 struct bgp_tea_subtlv_remote_endpoint st_endpoint
; /* optional */
197 /* No subtlvs defined in spec? */
200 struct bgp_encap_type_vxlan_gpe
{
201 uint32_t valid_subtlvs
;
202 struct bgp_tea_subtlv_remote_endpoint st_endpoint
; /* optional */
203 /* No subtlvs defined in spec? */
206 struct bgp_encap_type_mpls_in_udp
{
207 uint32_t valid_subtlvs
;
208 struct bgp_tea_subtlv_remote_endpoint st_endpoint
; /* optional */
209 /* No subtlvs defined in spec? */
212 struct bgp_encap_type_pbb
{
213 uint32_t valid_subtlvs
;
214 struct bgp_tea_subtlv_remote_endpoint st_endpoint
; /* optional */
215 struct bgp_tea_subtlv_encap_pbb st_encap
;
219 encode_encap_extcomm (bgp_encap_types tnl_type
,
220 struct ecommunity_val
*eval
)
222 memset (eval
, 0, sizeof (*eval
));
223 eval
->val
[0] = ECOMMUNITY_ENCODE_OPAQUE
;
224 eval
->val
[1] = ECOMMUNITY_OPAQUE_SUBTYPE_ENCAP
;
225 eval
->val
[6] = ((tnl_type
) >> 8) & 0xff;
226 eval
->val
[7] = (tnl_type
) & 0xff;
229 #endif /* _QUAGGA_BGP_ENCAP_TYPES_H */