]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_encap_types.h
Merge pull request #5793 from ton31337/fix/formatting_show_bgp_summary_failed
[mirror_frr.git] / bgpd / bgp_encap_types.h
CommitLineData
f4c89855
LB
1/*
2 * Copyright 2015, LabN Consulting, L.L.C.
3 *
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.
8 *
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.
13 *
896014f4
DL
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
f4c89855
LB
17 */
18
19#ifndef _QUAGGA_BGP_ENCAP_TYPES_H
20#define _QUAGGA_BGP_ENCAP_TYPES_H
21
86f6f09e 22#include "bgpd/bgp_ecommunity.h"
23
d62a17ae 24/* from
25 * http://www.iana.org/assignments/bgp-parameters/bgp-parameters.xhtml#tunnel-types
26 */
f4c89855 27typedef enum {
d62a17ae 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,
42 BGP_ENCAP_TYPE_PBB
f4c89855
LB
43} bgp_encap_types;
44
45typedef enum {
d62a17ae 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 */
f4c89855
LB
52} bgp_encap_subtlv_types;
53
54/*
55 * Tunnel Encapsulation Attribute subtlvs
56 */
57struct bgp_tea_subtlv_encap_l2tpv3_over_ip {
d62a17ae 58 uint32_t sessionid;
59 uint8_t cookie_length;
60 uint8_t cookie[8];
f4c89855
LB
61};
62
63struct bgp_tea_subtlv_encap_gre_key {
d62a17ae 64 uint32_t gre_key;
f4c89855
LB
65};
66
67struct bgp_tea_subtlv_encap_pbb {
d62a17ae 68 uint32_t flag_isid : 1;
69 uint32_t flag_vid : 1;
70 uint32_t isid : 24;
71 uint16_t vid : 12;
72 uint8_t macaddr[6];
f4c89855
LB
73};
74
75struct bgp_tea_subtlv_proto_type {
d62a17ae 76 uint16_t proto; /* ether-type */
f4c89855
LB
77};
78
79struct bgp_tea_subtlv_color {
d62a17ae 80 uint32_t color;
f4c89855
LB
81};
82
587ff0fd
LB
83/* per draft-rosen-idr-tunnel-encaps */
84struct bgp_tea_subtlv_remote_endpoint {
d7c0a89a 85 uint8_t family; /* IPv4 or IPv6 */
d62a17ae 86 union {
87 struct in_addr v4;
88 struct in6_addr v6;
89 } ip_address;
90 as_t as4; /* always 4 bytes */
587ff0fd
LB
91};
92
f4c89855
LB
93/*
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.
96 */
97#define BGP_ENCAP_SUBTLV_IPSEC_TA_SIZE 20
98
99struct bgp_tea_subtlv_ipsec_ta {
d62a17ae 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];
f4c89855
LB
103};
104
105/*
106 * Subtlv valid flags
107 * TBD change names to add "VALID"
108 */
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
587ff0fd 113#define BGP_TEA_SUBTLV_REMOTE_ENDPOINT 0x00000010
f4c89855 114
587ff0fd
LB
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))
f4c89855
LB
118
119/*
120 * Tunnel Type-specific APIs
121 */
122struct bgp_encap_type_reserved {
d62a17ae 123 uint32_t valid_subtlvs;
124 struct bgp_tea_subtlv_remote_endpoint st_endpoint; /* optional */
f4c89855
LB
125};
126
127struct bgp_encap_type_l2tpv3_over_ip {
d62a17ae 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 */
f4c89855
LB
133};
134
135struct bgp_encap_type_gre {
d62a17ae 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 */
f4c89855
LB
141};
142
143struct bgp_encap_type_ip_in_ip {
d62a17ae 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 */
f4c89855
LB
148};
149
150struct bgp_encap_type_transmit_tunnel_endpoint {
d62a17ae 151 uint32_t valid_subtlvs;
152 struct bgp_tea_subtlv_remote_endpoint st_endpoint; /* optional */
153 /* No subtlvs defined in spec? */
f4c89855
LB
154};
155
156struct bgp_encap_type_ipsec_in_tunnel_mode {
d62a17ae 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 */
f4c89855
LB
160};
161
162struct bgp_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode {
d62a17ae 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 */
f4c89855
LB
166};
167
168struct bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode {
d62a17ae 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 */
f4c89855
LB
172};
173
aee875b5
PG
174#define VXLAN_ENCAP_MASK_VNID_VALID 0x80000000
175#define VXLAN_ENCAP_MASK_MAC_VALID 0x40000000
176
f4c89855 177struct bgp_encap_type_vxlan {
d62a17ae 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 */
f4c89855
LB
183};
184
185struct bgp_encap_type_nvgre {
d62a17ae 186 uint32_t valid_subtlvs;
187 struct bgp_tea_subtlv_remote_endpoint st_endpoint; /* optional */
188 /* No subtlvs defined in spec? */
f4c89855
LB
189};
190
191struct bgp_encap_type_mpls {
d62a17ae 192 uint32_t valid_subtlvs;
193 struct bgp_tea_subtlv_remote_endpoint st_endpoint; /* optional */
194 /* No subtlvs defined in spec? */
f4c89855
LB
195};
196
197struct bgp_encap_type_mpls_in_gre {
d62a17ae 198 uint32_t valid_subtlvs;
199 struct bgp_tea_subtlv_remote_endpoint st_endpoint; /* optional */
200 /* No subtlvs defined in spec? */
f4c89855
LB
201};
202
203struct bgp_encap_type_vxlan_gpe {
d62a17ae 204 uint32_t valid_subtlvs;
205 struct bgp_tea_subtlv_remote_endpoint st_endpoint; /* optional */
206 /* No subtlvs defined in spec? */
f4c89855
LB
207};
208
209struct bgp_encap_type_mpls_in_udp {
d62a17ae 210 uint32_t valid_subtlvs;
211 struct bgp_tea_subtlv_remote_endpoint st_endpoint; /* optional */
212 /* No subtlvs defined in spec? */
f4c89855
LB
213};
214
215struct bgp_encap_type_pbb {
d62a17ae 216 uint32_t valid_subtlvs;
217 struct bgp_tea_subtlv_remote_endpoint st_endpoint; /* optional */
218 struct bgp_tea_subtlv_encap_pbb st_encap;
f4c89855
LB
219};
220
d62a17ae 221static inline void encode_encap_extcomm(bgp_encap_types tnl_type,
222 struct ecommunity_val *eval)
86f6f09e 223{
d62a17ae 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;
86f6f09e 229}
230
f4c89855 231#endif /* _QUAGGA_BGP_ENCAP_TYPES_H */