1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright 2015, LabN Consulting, L.L.C.
6 #ifndef _QUAGGA_BGP_ENCAP_TYPES_H
7 #define _QUAGGA_BGP_ENCAP_TYPES_H
9 #include "bgpd/bgp_ecommunity.h"
12 * http://www.iana.org/assignments/bgp-parameters/bgp-parameters.xhtml#tunnel-types
15 BGP_ENCAP_TYPE_RESERVED
= 0,
16 BGP_ENCAP_TYPE_L2TPV3_OVER_IP
= 1,
17 BGP_ENCAP_TYPE_GRE
= 2,
18 BGP_ENCAP_TYPE_TRANSMIT_TUNNEL_ENDPOINT
= 3,
19 BGP_ENCAP_TYPE_IPSEC_IN_TUNNEL_MODE
= 4,
20 BGP_ENCAP_TYPE_IP_IN_IP_TUNNEL_WITH_IPSEC_TRANSPORT_MODE
= 5,
21 BGP_ENCAP_TYPE_MPLS_IN_IP_TUNNEL_WITH_IPSEC_TRANSPORT_MODE
= 6,
22 BGP_ENCAP_TYPE_IP_IN_IP
= 7,
23 BGP_ENCAP_TYPE_VXLAN
= 8,
24 BGP_ENCAP_TYPE_NVGRE
= 9,
25 BGP_ENCAP_TYPE_MPLS
= 10, /* NOTE: Encap SAFI&Attribute not used */
26 BGP_ENCAP_TYPE_MPLS_IN_GRE
= 11,
27 BGP_ENCAP_TYPE_VXLAN_GPE
= 12,
28 BGP_ENCAP_TYPE_MPLS_IN_UDP
= 13,
33 BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION
= 1,
34 BGP_ENCAP_SUBTLV_TYPE_PROTO_TYPE
= 2,
35 BGP_ENCAP_SUBTLV_TYPE_IPSEC_TA
= 3,
36 BGP_ENCAP_SUBTLV_TYPE_COLOR
= 4,
37 BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
=
38 6 /* speculative, IANA assignment TBD */
39 } bgp_encap_subtlv_types
;
42 * Tunnel Encapsulation Attribute subtlvs
44 struct bgp_tea_subtlv_encap_l2tpv3_over_ip
{
46 uint8_t cookie_length
;
50 struct bgp_tea_subtlv_encap_gre_key
{
54 struct bgp_tea_subtlv_encap_pbb
{
55 uint32_t flag_isid
: 1;
56 uint32_t flag_vid
: 1;
62 struct bgp_tea_subtlv_proto_type
{
63 uint16_t proto
; /* ether-type */
66 struct bgp_tea_subtlv_color
{
70 /* per draft-rosen-idr-tunnel-encaps */
71 struct bgp_tea_subtlv_remote_endpoint
{
72 uint8_t family
; /* IPv4 or IPv6 */
77 as_t as4
; /* always 4 bytes */
81 * This is the length of the value part of the ipsec tunnel authenticator
82 * subtlv. Currently we only support the length for authenticator type 1.
84 #define BGP_ENCAP_SUBTLV_IPSEC_TA_SIZE 20
86 struct bgp_tea_subtlv_ipsec_ta
{
87 uint16_t authenticator_type
; /* only type 1 is supported so far */
88 uint8_t authenticator_length
; /* octets in value field */
89 uint8_t value
[BGP_ENCAP_SUBTLV_IPSEC_TA_SIZE
];
94 * TBD change names to add "VALID"
96 #define BGP_TEA_SUBTLV_ENCAP 0x00000001
97 #define BGP_TEA_SUBTLV_PROTO_TYPE 0x00000002
98 #define BGP_TEA_SUBTLV_COLOR 0x00000004
99 #define BGP_TEA_SUBTLV_IPSEC_TA 0x00000008
100 #define BGP_TEA_SUBTLV_REMOTE_ENDPOINT 0x00000010
102 #define CHECK_SUBTLV_FLAG(ptr, flag) CHECK_FLAG((ptr)->valid_subtlvs, (flag))
103 #define SET_SUBTLV_FLAG(ptr, flag) SET_FLAG((ptr)->valid_subtlvs, (flag))
104 #define UNSET_SUBTLV_FLAG(ptr, flag) UNSET_FLAG((ptr)->valid_subtlvs, (flag))
107 * Tunnel Type-specific APIs
109 struct bgp_encap_type_reserved
{
110 uint32_t valid_subtlvs
;
111 struct bgp_tea_subtlv_remote_endpoint st_endpoint
; /* optional */
114 struct bgp_encap_type_l2tpv3_over_ip
{
115 uint32_t valid_subtlvs
;
116 struct bgp_tea_subtlv_encap_l2tpv3_over_ip st_encap
;
117 struct bgp_tea_subtlv_proto_type st_proto
; /* optional */
118 struct bgp_tea_subtlv_color st_color
; /* optional */
119 struct bgp_tea_subtlv_remote_endpoint st_endpoint
; /* optional */
122 struct bgp_encap_type_gre
{
123 uint32_t valid_subtlvs
;
124 struct bgp_tea_subtlv_encap_gre_key st_encap
; /* optional */
125 struct bgp_tea_subtlv_proto_type st_proto
; /* optional */
126 struct bgp_tea_subtlv_color st_color
; /* optional */
127 struct bgp_tea_subtlv_remote_endpoint st_endpoint
; /* optional */
130 struct bgp_encap_type_ip_in_ip
{
131 uint32_t valid_subtlvs
;
132 struct bgp_tea_subtlv_proto_type st_proto
; /* optional */
133 struct bgp_tea_subtlv_color st_color
; /* optional */
134 struct bgp_tea_subtlv_remote_endpoint st_endpoint
; /* optional */
137 struct bgp_encap_type_transmit_tunnel_endpoint
{
138 uint32_t valid_subtlvs
;
139 struct bgp_tea_subtlv_remote_endpoint st_endpoint
; /* optional */
140 /* No subtlvs defined in spec? */
143 struct bgp_encap_type_ipsec_in_tunnel_mode
{
144 uint32_t valid_subtlvs
;
145 struct bgp_tea_subtlv_ipsec_ta st_ipsec_ta
; /* optional */
146 struct bgp_tea_subtlv_remote_endpoint st_endpoint
; /* optional */
149 struct bgp_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode
{
150 uint32_t valid_subtlvs
;
151 struct bgp_tea_subtlv_ipsec_ta st_ipsec_ta
; /* optional */
152 struct bgp_tea_subtlv_remote_endpoint st_endpoint
; /* optional */
155 struct bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode
{
156 uint32_t valid_subtlvs
;
157 struct bgp_tea_subtlv_ipsec_ta st_ipsec_ta
; /* optional */
158 struct bgp_tea_subtlv_remote_endpoint st_endpoint
; /* optional */
161 #define VXLAN_ENCAP_MASK_VNID_VALID 0x80000000
162 #define VXLAN_ENCAP_MASK_MAC_VALID 0x40000000
164 struct bgp_encap_type_vxlan
{
165 uint32_t valid_subtlvs
;
166 struct bgp_tea_subtlv_remote_endpoint st_endpoint
; /* optional */
167 /* draft-ietf-idr-tunnel-encaps-02 */
168 uint32_t vnid
; /* does not include V and M bit */
169 uint8_t *mac_address
; /* optional */
172 struct bgp_encap_type_nvgre
{
173 uint32_t valid_subtlvs
;
174 struct bgp_tea_subtlv_remote_endpoint st_endpoint
; /* optional */
175 /* No subtlvs defined in spec? */
178 struct bgp_encap_type_mpls
{
179 uint32_t valid_subtlvs
;
180 struct bgp_tea_subtlv_remote_endpoint st_endpoint
; /* optional */
181 /* No subtlvs defined in spec? */
184 struct bgp_encap_type_mpls_in_gre
{
185 uint32_t valid_subtlvs
;
186 struct bgp_tea_subtlv_remote_endpoint st_endpoint
; /* optional */
187 /* No subtlvs defined in spec? */
190 struct bgp_encap_type_vxlan_gpe
{
191 uint32_t valid_subtlvs
;
192 struct bgp_tea_subtlv_remote_endpoint st_endpoint
; /* optional */
193 /* No subtlvs defined in spec? */
196 struct bgp_encap_type_mpls_in_udp
{
197 uint32_t valid_subtlvs
;
198 struct bgp_tea_subtlv_remote_endpoint st_endpoint
; /* optional */
199 /* No subtlvs defined in spec? */
202 struct bgp_encap_type_pbb
{
203 uint32_t valid_subtlvs
;
204 struct bgp_tea_subtlv_remote_endpoint st_endpoint
; /* optional */
205 struct bgp_tea_subtlv_encap_pbb st_encap
;
208 static inline void encode_encap_extcomm(bgp_encap_types tnl_type
,
209 struct ecommunity_val
*eval
)
211 memset(eval
, 0, sizeof(*eval
));
212 eval
->val
[0] = ECOMMUNITY_ENCODE_OPAQUE
;
213 eval
->val
[1] = ECOMMUNITY_OPAQUE_SUBTYPE_ENCAP
;
214 eval
->val
[6] = ((tnl_type
) >> 8) & 0xff;
215 eval
->val
[7] = (tnl_type
)&0xff;
218 #endif /* _QUAGGA_BGP_ENCAP_TYPES_H */